*
* @requires app.core
* @requires app.welcome
+ * @requires app.rest
*
* @description
* # app
'app.core',
/* Feature areas */
- 'app.welcome'
+ 'app.welcome',
+ 'app.rest'
]);
}());
--- /dev/null
+(function () {
+ 'use strict';
+
+ angular
+ .module('app.rest')
+ .controller('Rest', Rest);
+
+ /**
+ * @ngdoc controller
+ * @name app.rest.controller:Rest
+ *
+ * @requires $location
+ *
+ * <p>
+ * <br>
+ * {@link https://docs.angularjs.org/api/ng/service/$location $location}
+ * </p>
+ *
+ * @description
+ * Rest controller.
+ */
+ /* @ngInject */
+ function Rest($location) {
+ var vm = this;
+ vm.example = {
+ text: 'try to send data',
+ word: /^\s*\w*\s*$/,
+ singleModel: 1
+ };
+ }
+
+})();
--- /dev/null
+<!DOCTYPE html>
+<div class="container">
+
+ <form name="myForm" ng-controller="Rest as vm">
+ <label>Single word:</label>
+ <input type="text" name="input" ng-model="vm.example.text"
+ ng-pattern="vm.example.word" required ng-trim="false">
+ <div role="alert">
+ <span class="error" ng-show="myForm.input.$error.required">
+ Required!</span>
+ <span class="error" ng-show="myForm.input.$error.pattern">
+ Single word only!</span>
+ </div>
+ <span>text = {{vm.example.text}}</span><br/>
+ <span>myForm.input.$valid = {{myForm.input.$valid}}</span><br/>
+ <span>myForm.input.$error = {{myForm.input.$error}}</span><br/>
+ <span>myForm.$valid = {{myForm.$valid}}</span><br/>
+ <span>myForm.$error.required = {{!!myForm.$error.required}}</span><br/>
+ <button type="button" class="btn btn-primary" ng-model="vm.singleModel" ng-disabled="myForm.input.$invalid">
+ Single Toggle
+ </button>
+ </form>
+
+
+
+
+</div>
\ No newline at end of file
--- /dev/null
+(function() {
+ 'use strict';
+
+ /**
+ * @ngdoc overview
+ * @name app.rest
+ *
+ * @requires app.core
+ *
+ * @description
+ * # app.welcome
+ *
+ * ## Module welcome.
+ * Module in charge of sending REST requests.
+ */
+ angular.module('app.rest', [
+ 'app.core'
+ ]);
+
+})();
--- /dev/null
+(function() {
+ 'use strict';
+
+ angular
+ .module('app.rest')
+ .config(configure);
+
+ /**
+ * @ngdoc service
+ * @name app.rest.configure
+ *
+ * @requires $stateProvider
+ * @requires $urlRouterProvider
+ *
+ * <p>
+ * <br>
+ * {@link http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider $stateProvider} <br>
+ * {@link http://angular-ui.github.io/ui-router/site/#/api/ui.router.router.$urlRouterProvider $urlRouterProvider}
+ * </p>
+ *
+ *
+ * @description
+ * Router configuration for rest application.
+ */
+ /* @ngInject */
+ function configure($stateProvider, $urlRouterProvider) {
+ var state = 'rest';
+ var config = {
+ abstract: false,
+ url: '/rest',
+ templateUrl: 'app/rest/rest.html'
+ };
+
+ $urlRouterProvider.otherwise(state);
+ $stateProvider.state(state, config);
+ }
+}());
--- /dev/null
+describe('app.rest', function() {
+ 'use strict';
+
+ describe('state', function() {
+ var view = {
+ rest: 'app/rest/rest.html'
+ };
+ var $state;
+
+ beforeEach(function() {
+ module('app.rest');
+
+ inject(function(_$state_) {
+ $state = _$state_;
+ });
+ });
+
+ it('should map /rest route to rest View template', function() {
+ expect($state.get('rest').templateUrl). toEqual(view.rest);
+ });
+
+ });
+
+});
--- /dev/null
+(function () {
+ 'use strict';
+
+ angular
+ .module('app.rest')
+ .factory('cars', cars);
+
+ /**
+ * @ngdoc service
+ * @name app.rest.cars
+ *
+ * @requires $http
+ * @requires $log
+ *
+ * <p>
+ * <br>
+ * {@link https://docs.angularjs.org/api/ng/service/$http $http} <br>
+ * {@link https://docs.angularjs.org/api/ng/service/$log $log}
+ * </p>
+ *
+ * @description
+ * Rest service.
+ */
+ /* @ngInject */
+ function cars($http, $log) {
+ return {
+ getAll: getAll
+ };
+
+ /**
+ * @ngdoc method
+ * @name getAll
+ * @methodOf app.rest.cars
+ *
+ * @description
+ * Get cars from API REST.
+ */
+ function getAll() {
+ return $http.get('/api/cars')
+ .then(getAllCompleted)
+ .catch(getAllFailed);
+
+ function getAllCompleted(response) {
+ return response.data.results;
+ }
+
+ function getAllFailed(error) {
+ $log.debug('XHR Failed for sendData.' + error.data);
+ }
+ }
+ }
+
+}());
--- /dev/null
+describe('app.rest', function() {
+ 'use strict';
+
+ var $httpBackend;
+ var $log;
+ var cars;
+
+ beforeEach(function() {
+ module('app.rest');
+
+ inject(function(_$httpBackend_, _$log_, _cars_) {
+ $httpBackend = _$httpBackend_;
+ $log = _$log_;
+ cars = _cars_;
+ });
+ });
+
+ describe('cars service', function () {
+
+ it('should invoke GET all cars', function () {
+ $httpBackend.expectGET('/api/cars').respond({});
+
+ cars.getAll();
+
+ $httpBackend.flush();
+ });
+ });
+
+ afterEach(function() {
+ $httpBackend.verifyNoOutstandingExpectation();
+ $httpBackend.verifyNoOutstandingRequest();
+ });
+
+});
<!DOCTYPE html>
-<div class="container" ng-controller="Welcome as welcome">
+<div class="container" ng-controller="Welcome as vm">
<div class="row">
- {{ welcome.hello }}
+ {{ vm.hello }}
<div class="col-md-2">
</div>
* # app.welcome
*
* ## Module welcome.
- * Module in charge of displaying a nice welcome page. LOL ROLF
+ * Module in charge of displaying a nice welcome page.
*/
angular.module('app.welcome', [
'app.core'
});
it('should map /welcome route to welcome View template', function() {
- expect($state.get('welcome').templateUrl). toEqual(view.welcome);
+ expect($state.get('welcome').templateUrl).toEqual(view.welcome);
});
});
<script src="/src/showcase/app/welcome/welcome.module.js"></script>
<script src="/src/showcase/app/welcome/welcome.route.js"></script>
<script src="/src/showcase/app/welcome/welcome.controller.js"></script>
+ <script src="/src/showcase/app/rest/rest.module.js"></script>
+ <script src="/src/showcase/app/rest/rest.service.js"></script>
+ <script src="/src/showcase/app/rest/rest.route.js"></script>
+ <script src="/src/showcase/app/rest/rest.controller.js"></script>
<script src="/src/showcase/app/core/core.module.js"></script>
<script src="/src/showcase/app/app.module.js"></script>
<!-- endinject -->