From a482f278872c7b270d4ec7ca718acebb2431d04b Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sat, 29 Aug 2015 21:57:50 +0200 Subject: [PATCH] showcase: renaming subapplication from rest to cars --- angularjs/showcase/src/showcase/app/app.module.js | 4 +- .../app/cars/cars-error-modal.controller.js | 37 ++++ .../src/showcase/app/cars/cars-error-modal.html | 19 ++ .../src/showcase/app/cars/cars.constants.js | 13 ++ .../src/showcase/app/cars/cars.controller.js | 104 +++++++++++ .../src/showcase/app/cars/cars.controller.spec.js | 40 +++++ angularjs/showcase/src/showcase/app/cars/cars.html | 30 ++++ .../showcase/src/showcase/app/cars/cars.module.js | 20 +++ .../showcase/src/showcase/app/cars/cars.route.js | 37 ++++ .../src/showcase/app/cars/cars.route.spec.js | 24 +++ .../showcase/src/showcase/app/cars/cars.service.js | 198 +++++++++++++++++++++ .../src/showcase/app/cars/cars.service.spec.js | 36 ++++ .../app/rest/rest-error-modal.controller.js | 37 ---- .../src/showcase/app/rest/rest-error-modal.html | 19 -- .../src/showcase/app/rest/rest.constants.js | 13 -- .../src/showcase/app/rest/rest.controller.js | 98 ---------- .../src/showcase/app/rest/rest.controller.spec.js | 40 ----- angularjs/showcase/src/showcase/app/rest/rest.html | 30 ---- .../showcase/src/showcase/app/rest/rest.module.js | 20 --- .../showcase/src/showcase/app/rest/rest.route.js | 37 ---- .../src/showcase/app/rest/rest.route.spec.js | 24 --- .../showcase/src/showcase/app/rest/rest.service.js | 198 --------------------- .../src/showcase/app/rest/rest.service.spec.js | 36 ---- angularjs/showcase/src/showcase/index.html | 12 +- 24 files changed, 566 insertions(+), 560 deletions(-) create mode 100644 angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.js create mode 100644 angularjs/showcase/src/showcase/app/cars/cars-error-modal.html create mode 100644 angularjs/showcase/src/showcase/app/cars/cars.constants.js create mode 100644 angularjs/showcase/src/showcase/app/cars/cars.controller.js create mode 100644 angularjs/showcase/src/showcase/app/cars/cars.controller.spec.js create mode 100644 angularjs/showcase/src/showcase/app/cars/cars.html create mode 100644 angularjs/showcase/src/showcase/app/cars/cars.module.js create mode 100644 angularjs/showcase/src/showcase/app/cars/cars.route.js create mode 100644 angularjs/showcase/src/showcase/app/cars/cars.route.spec.js create mode 100644 angularjs/showcase/src/showcase/app/cars/cars.service.js create mode 100644 angularjs/showcase/src/showcase/app/cars/cars.service.spec.js delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest-error-modal.controller.js delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest-error-modal.html delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest.constants.js delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest.controller.js delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest.controller.spec.js delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest.html delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest.module.js delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest.route.js delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest.route.spec.js delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest.service.js delete mode 100644 angularjs/showcase/src/showcase/app/rest/rest.service.spec.js diff --git a/angularjs/showcase/src/showcase/app/app.module.js b/angularjs/showcase/src/showcase/app/app.module.js index e20f31d..70266f7 100644 --- a/angularjs/showcase/src/showcase/app/app.module.js +++ b/angularjs/showcase/src/showcase/app/app.module.js @@ -8,7 +8,7 @@ * * @requires app.core * @requires app.welcome - * @requires app.rest + * @requires app.cars * * @description * # app @@ -22,7 +22,7 @@ /* Feature areas */ 'app.welcome', - 'app.rest' + 'app.cars' ]); }()); diff --git a/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.js b/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.js new file mode 100644 index 0000000..b710cba --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.js @@ -0,0 +1,37 @@ +(function () { + 'use strict'; + + angular + .module('app.cars') + .controller('CarsErrorModal', CarsErrorModal); + + /** + * @ngdoc controller + * @name app.cars.controller:CarsErrorModal + * + * @description + * Controller for error modal in cars application. + */ + /* @ngInject */ + function CarsErrorModal($modalInstance, cars) { + var vm = this; + + vm.cars = cars; + vm.selected = { + car: vm.cars[0] + }; + + vm.ok = function () { + var isAllowedEvent = $modalInstance.close(vm.selected.car); + console.log('close: broadcasted event to the modal scope before the modal closes. ' + + 'Was it allowed?' + isAllowedEvent); + }; + + vm.cancel = function () { + var isAllowedEvent = $modalInstance.dismiss('cancel'); + console.log('dismiss: broadcasted event to the modal scope before the modal closes. ' + + 'Was it allowed?' + isAllowedEvent); + }; + } + +})(); diff --git a/angularjs/showcase/src/showcase/app/cars/cars-error-modal.html b/angularjs/showcase/src/showcase/app/cars/cars-error-modal.html new file mode 100644 index 0000000..8981d43 --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars-error-modal.html @@ -0,0 +1,19 @@ + + + + \ No newline at end of file diff --git a/angularjs/showcase/src/showcase/app/cars/cars.constants.js b/angularjs/showcase/src/showcase/app/cars/cars.constants.js new file mode 100644 index 0000000..b127b85 --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars.constants.js @@ -0,0 +1,13 @@ +(function () { + 'use strict'; + + var prefix = '/'; + + angular + .module('app.cars') + .constant('API', { + CARS: prefix + 'api/cars', + CAR: prefix + 'api/cars/:carId' + }); + +})(); diff --git a/angularjs/showcase/src/showcase/app/cars/cars.controller.js b/angularjs/showcase/src/showcase/app/cars/cars.controller.js new file mode 100644 index 0000000..0d07859 --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars.controller.js @@ -0,0 +1,104 @@ +(function () { + 'use strict'; + + angular + .module('app.cars') + .controller('Cars', Cars); + + /** + * @ngdoc controller + * @name app.cars.controller:Cars + * + * @requires $modal + * @requires $timeout + * @requires app.cars.cars + * + *

+ *
+ * {@link http://angular-ui.github.io/bootstrap/#/modal $modal} + * {@link https://docs.angularjs.org/api/ng/service/$timeout $timeout} + *

+ * + * @description + * Cars controller. + */ + /* @ngInject */ + function Cars($modal, $timeout, cars) { + var vm = this; + vm.example = { + text: 'try to send data', + word: /^\s*\w*\s*$/, + singleModel: 1 + }; + vm.getCars = getCars; + + function getCars() { + // ES6 way. success and error are deprecated because they are not following the ES6 way. + cars.getAll().then( + // Success + function (value) { + vm.cars = value; + }, + // Error + function(reason) { + console.log('Cars controller error: ' + reason); + doModal('lg'); + } + ); + } + + function doModal(size) { + var cars = ['car1', 'car2', 'car3']; + var modalInstance = $modal.open({ + animation: true, + templateUrl: 'app/cars/cars-error-modal.html', + controller: 'CarsErrorModal as vm', + size: size, + backdrop: 'static', + keyboard: false, + resolve: { + cars: function () { + return cars; + } + } + }); + + modalInstance.result.then(function (selectedItem) { + vm.selected = selectedItem; + }, function (reason) { + if (reason === '$uibUnscheduledDestruction') { + console.log('Modal\'s scope destroyed by unexpected mechanism'); + } + console.log('Modal dismissed at: ' + new Date()); + console.log('Modal dismissed reason: ' + reason); + }); + + modalInstance.opened.then(function(value) { + console.log('Modal opened success at: ' + new Date()); + console.log('Modal opened success value: ' + value); + }, function(reason) { + console.log('Modal opened error at: ' + new Date()); + console.log('Modal opened error value: ' + reason); + }); + + modalInstance.rendered.then(function(value) { + console.log('Modal rendered success at: ' + new Date()); + console.log('Modal rendered success value: ' + value); + }, function(reason) { + console.log('Modal rendered error at: ' + new Date()); + console.log('Modal rendered error value: ' + reason); + }); + + $timeout(function() { + console.log('closed by tiemout at: ' + new Date()); + modalInstance.close('closed by tiemout'); + }, 5000); + + $timeout(function() { + console.log('dismissed by tiemout at: ' + new Date()); + modalInstance.dismiss('dismissed by tiemout'); + }, 10000); + } + } + +})(); diff --git a/angularjs/showcase/src/showcase/app/cars/cars.controller.spec.js b/angularjs/showcase/src/showcase/app/cars/cars.controller.spec.js new file mode 100644 index 0000000..74c8cc8 --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars.controller.spec.js @@ -0,0 +1,40 @@ +describe('app.cars', function() { + 'use strict'; + + var Cars; + var cars = { + getAll: function() { + return {}; + } + }; + var $q; + + beforeEach(function() { + module('app.cars'); + + inject(function($controller, $location, _$q_) { + Cars = $controller('Cars', { + $location: $location, + cars: cars + }); + $q = _$q_; + }); + }); + + describe('Cars controller', function () { + + it('should invoke GET all cars in service', function () { + + spyOn(cars, 'getAll') + .and.callFake(function() { + var deferred = $q.defer(); + return deferred.promise; + }); + + Cars.getCars(); + + expect(cars.getAll).toHaveBeenCalled(); + }); + }); + +}); diff --git a/angularjs/showcase/src/showcase/app/cars/cars.html b/angularjs/showcase/src/showcase/app/cars/cars.html new file mode 100644 index 0000000..960e253 --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars.html @@ -0,0 +1,30 @@ + +
+ +
+ + +
+ + Required! + + Single word only! +
+ text = {{vm.example.text}}
+ myForm.input.$valid = {{myForm.input.$valid}}
+ myForm.input.$error = {{myForm.input.$error}}
+ myForm.$valid = {{myForm.$valid}}
+ myForm.$error.required = {{!!myForm.$error.required}}
+ +
    +
  • {{ car.content }}
  • +
+ +
+
\ No newline at end of file diff --git a/angularjs/showcase/src/showcase/app/cars/cars.module.js b/angularjs/showcase/src/showcase/app/cars/cars.module.js new file mode 100644 index 0000000..02916bb --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars.module.js @@ -0,0 +1,20 @@ +(function() { + 'use strict'; + + /** + * @ngdoc overview + * @name app.cars + * + * @requires app.core + * + * @description + * # app.cars + * + * ## Module cars. + * Module in charge of sending REST requests. + */ + angular.module('app.cars', [ + 'app.core' + ]); + +})(); diff --git a/angularjs/showcase/src/showcase/app/cars/cars.route.js b/angularjs/showcase/src/showcase/app/cars/cars.route.js new file mode 100644 index 0000000..57e339e --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars.route.js @@ -0,0 +1,37 @@ +(function() { + 'use strict'; + + angular + .module('app.cars') + .config(configure); + + /** + * @ngdoc service + * @name app.cars.configure + * + * @requires $stateProvider + * @requires $urlRouterProvider + * + *

+ *
+ * {@link http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider $stateProvider}
+ * {@link http://angular-ui.github.io/ui-router/site/#/api/ui.router.router.$urlRouterProvider $urlRouterProvider} + *

+ * + * + * @description + * Router configuration for cars application. + */ + /* @ngInject */ + function configure($stateProvider, $urlRouterProvider) { + var state = 'cars'; + var config = { + abstract: false, + url: '/cars', + templateUrl: 'app/cars/cars.html' + }; + + $urlRouterProvider.otherwise(state); + $stateProvider.state(state, config); + } +}()); diff --git a/angularjs/showcase/src/showcase/app/cars/cars.route.spec.js b/angularjs/showcase/src/showcase/app/cars/cars.route.spec.js new file mode 100644 index 0000000..f8c7b33 --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars.route.spec.js @@ -0,0 +1,24 @@ +describe('app.cars', function() { + 'use strict'; + + describe('state', function() { + var view = { + cars: 'app/cars/cars.html' + }; + var $state; + + beforeEach(function() { + module('app.cars'); + + inject(function(_$state_) { + $state = _$state_; + }); + }); + + it('should map /cars route to cars View template', function() { + expect($state.get('cars').templateUrl). toEqual(view.cars); + }); + + }); + +}); diff --git a/angularjs/showcase/src/showcase/app/cars/cars.service.js b/angularjs/showcase/src/showcase/app/cars/cars.service.js new file mode 100644 index 0000000..79e721e --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars.service.js @@ -0,0 +1,198 @@ +(function () { + 'use strict'; + + angular + .module('app.cars') + .factory('cars', cars); + + /** + * @ngdoc service + * @name app.cars.cars + * + * @requires $http + * @requires $q + * + *

+ *
+ * {@link https://docs.angularjs.org/api/ng/service/$http $http}
+ * {@link https://docs.angularjs.org/api/ng/service/$q $q} + *

+ * + * @description + * cars service. + */ + /* @ngInject */ + function cars($http, $q, API) { + return { + getAll: getAll + }; + + /** + * @ngdoc method + * @name getAll + * @methodOf app.cars.cars + * + * @description + * Get cars from API REST. + */ + function getAll() { + return $http.get(API.CARS) + // a) Using success and error from promise. They are deprecated because it is not the ES6 way. DO NOT USE THEM! + // https://github.com/angular/angular.js/commit/a8f7e9cfde82ed7eaba3a868d8acafdf57f2d76f + // .success(successAlternative) + // .error(errorAlternative) + // b) Using then from promise. ES6 way. + .then(success, error, notify) + // Pattern: either use error callback or catch but not both of them as the same time!!!! + // .catch(failed) + .finally(finalizer); + + function success(resp) { + /** + * resp, object containing: + * + * config: Object + * headers: Object + * Accept: "application/json, text/plain, *!/!*" + * method: "GET" + * paramSerializer: ngParamSerializer(params) + * transformRequest: Array[1] + * transformResponse: Array[1] + * url: "/api/cars" + * data: Array[3] + * 0: Object + * content: "Car: 1" + * id: 4 + * 1: Object + * content: "Car: 2" + * id: 5 + * length: 2 + * headers: function(name) + * status: 200 + * statusText: "OK" + */ + + // In this way, then next chained promise will use just its success callback. :( + // What means, promise will be resolved immediately!!! If it is what you want go ahead. + // return resp.data; + + // Better return promise. :) Two options: + + // a) ES6 way (it doesn't have notify :( + // return $q(function(resolve) { + // resolve(resp.data); + // }) + + // b) The CommonJS Promise way. It has the notify method (which I am not using here) + var deferred = $q.defer(); + deferred.resolve(resp.data); + return deferred.promise; + } + + // DO NOT USE IT!!! This way has been deprecated because it is not the ES6 way. + function successAlternative(data, status, headers, config) { + console.log('XHR SuccessAlternative for getAll. SuccessAlternative, data: ' + data); + console.log('XHR SuccessAlternative for getAll. SuccessAlternative, status: ' + status); + console.log('XHR SuccessAlternative for getAll. SuccessAlternative, headers (it is a function): ' + headers); + console.log('XHR SuccessAlternative for getAll. SuccessAlternative, config: ' + config); + } + + function error(reason) { + /** + * resp, object containing: + * + * config: Object + * headers: Object + * Accept: "application/json, text/plain, *!/!*" + * method: "GET" + * paramSerializer: ngParamSerializer(params) + * transformRequest: Array[1] + * transformResponse: Array[1] + * url: "/api/cars" + * data: "Error: connect ECONNREFUSED" + * headers: function(name) + * status: 500 + * statusText: "Internal Server Error" + */ + console.log('XHR Error for getAll. Error: ' + reason.data); + + // In this way, then next chained promise will use just its success callback. :( + // What means, promise will be resolved immediately!!! If it is what you want go ahead. + // return reason.data; + + // Better return promise. :) Three options: + + // a) ES6 way, it doesn't have notify :( + // return $q(function(resolve, reject) { + // reject(reason.data); + // }) + + // b) The CommonJS Promise way. It has the notify method (which I am not using here) + // var deferred = $q.defer(); + // deferred.reject(reason.data); + // return deferred.promise; + + // c) The CommonJS Promise way. The same as b) but with less code :) + return $q.reject(reason.data); + } + + // DO NOT USE IT!!! This way has been deprecated because it is not the ES6 way. + function errorAlternative(data, status, headers, config) { + console.log('XHR ErrorAlternative for getAll. ErrorAlternative, data: ' + data); + console.log('XHR ErrorAlternative for getAll. ErrorAlternative, status: ' + status); + console.log('XHR ErrorAlternative for getAll. ErrorAlternative, headers (it is a function): ' + headers); + console.log('XHR ErrorAlternative for getAll. ErrorAlternative, config: ' + config); + } + + function notify(notification) { + console.log('XHR Notification for getAll. Notification: ' + notification); + } + + function failed(reason) { + /** + * reason, object containing (the same as resp object for error function): + * + * config: Object + * headers: Object + * Accept: "application/json, text/plain, *!/!*" + * method: "GET" + * paramSerializer: ngParamSerializer(params) + * transformRequest: Array[1] + * transformResponse: Array[1] + * url: "/api/cars" + * data: "Error: connect ECONNREFUSED" + * headers: function(name) + * status: 500 + * statusText: "Internal Server Error" + */ + console.log('XHR Failed for getAll. Reason: ' + reason); + + // In this way, then next chained promise will use just its success callback. + // What means, promise will be resolved immediately!!! If it is what you want go ahead. + // return reason.data; + + // Better return promise. :) Three options: + + // a) ES6 way, it doesn't have notify :( + // return $q(function(resolve, reject) { + // reject(reason.data); + // }) + + // b) The CommonJS Promise way. It has the notify method (which I am not using here) + // var deferred = $q.defer(); + // deferred.reject(reason.data); + // return deferred.promise; + + // c) The CommonJS Promise way. The same as b) but with less code :) + return $q.reject(reason.data); + + } + + function finalizer() { + // This callback doesn't have any input parameter :( + console.log('XHR Finalizer for getAll.'); + } + } + } + +}()); diff --git a/angularjs/showcase/src/showcase/app/cars/cars.service.spec.js b/angularjs/showcase/src/showcase/app/cars/cars.service.spec.js new file mode 100644 index 0000000..846e416 --- /dev/null +++ b/angularjs/showcase/src/showcase/app/cars/cars.service.spec.js @@ -0,0 +1,36 @@ +describe('app.cars', function() { + 'use strict'; + + var $httpBackend; + var $log; + var cars; + var API; + + beforeEach(function() { + module('app.cars'); + + inject(function(_$httpBackend_, _$log_, _cars_, _API_) { + $httpBackend = _$httpBackend_; + $log = _$log_; + cars = _cars_; + API = _API_; + }); + }); + + 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(); + }); + +}); diff --git a/angularjs/showcase/src/showcase/app/rest/rest-error-modal.controller.js b/angularjs/showcase/src/showcase/app/rest/rest-error-modal.controller.js deleted file mode 100644 index 30b1b0a..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest-error-modal.controller.js +++ /dev/null @@ -1,37 +0,0 @@ -(function () { - 'use strict'; - - angular - .module('app.rest') - .controller('RestErrorModal', RestErrorModal); - - /** - * @ngdoc controller - * @name app.rest.controller:RestErrorModal - * - * @description - * Controller for error modal in rest application. - */ - /* @ngInject */ - function RestErrorModal($modalInstance, cars) { - var vm = this; - - vm.cars = cars; - vm.selected = { - car: vm.cars[0] - }; - - vm.ok = function () { - var isAllowedEvent = $modalInstance.close(vm.selected.car); - console.log('close: broadcasted event to the modal scope before the modal closes. ' + - 'Was it allowed?' + isAllowedEvent); - }; - - vm.cancel = function () { - var isAllowedEvent = $modalInstance.dismiss('cancel'); - console.log('dismiss: broadcasted event to the modal scope before the modal closes. ' + - 'Was it allowed?' + isAllowedEvent); - }; - } - -})(); diff --git a/angularjs/showcase/src/showcase/app/rest/rest-error-modal.html b/angularjs/showcase/src/showcase/app/rest/rest-error-modal.html deleted file mode 100644 index c197706..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest-error-modal.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - \ No newline at end of file diff --git a/angularjs/showcase/src/showcase/app/rest/rest.constants.js b/angularjs/showcase/src/showcase/app/rest/rest.constants.js deleted file mode 100644 index 0a8591c..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest.constants.js +++ /dev/null @@ -1,13 +0,0 @@ -(function () { - 'use strict'; - - var prefix = '/'; - - angular - .module('app.rest') - .constant('API', { - CARS: prefix + 'api/cars', - CAR: prefix + 'api/cars/:carId' - }); - -})(); diff --git a/angularjs/showcase/src/showcase/app/rest/rest.controller.js b/angularjs/showcase/src/showcase/app/rest/rest.controller.js deleted file mode 100644 index 5ff3313..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest.controller.js +++ /dev/null @@ -1,98 +0,0 @@ -(function () { - 'use strict'; - - angular - .module('app.rest') - .controller('Rest', Rest); - - /** - * @ngdoc controller - * @name app.rest.controller:Rest - * - * @requires $modal - * @requires $timeout - * @requires app.rest.rest - * - *

- *
- * {@link http://angular-ui.github.io/bootstrap/#/modal $modal} - * {@link https://docs.angularjs.org/api/ng/service/$timeout $timeout} - *

- * - * @description - * Rest controller. - */ - /* @ngInject */ - function Rest($modal, $timeout, rest) { - var vm = this; - vm.example = { - text: 'try to send data', - word: /^\s*\w*\s*$/, - singleModel: 1 - }; - vm.getCars = getCars; - - function getCars() { - // ES6 way. success and error are deprecated because they are not following the ES6 way. - rest.getAll().then( - // Success - function (value) { - vm.cars = value; - }, - // Error - function(reason) { - console.log('Rest controller error: ' + reason); - doModal('lg'); - } - ); - } - - function doModal(size) { - var cars = ['car1', 'car2', 'car3']; - var modalInstance = $modal.open({ - animation: true, - templateUrl: 'app/rest/rest-error-modal.html', - controller: 'RestErrorModal as vm', - size: size, - backdrop: 'static', - keyboard: false, - resolve: { - cars: function () { - return cars; - } - } - }); - - modalInstance.result.then(function (selectedItem) { - vm.selected = selectedItem; - }, function (reason) { - if (reason === '$uibUnscheduledDestruction') { - console.log('Modal\'s scope destroyed by unexpected mechanism'); - } - console.log('Modal dismissed at: ' + new Date()); - console.log('Modal dismissed reason: ' + reason); - }); - - modalInstance.opened.then(function(value) { - console.log('Modal opened success at: ' + new Date()); - console.log('Modal opened success value: ' + value); - }, function(reason) { - console.log('Modal opened error at: ' + new Date()); - console.log('Modal opened error value: ' + reason); - }); - - modalInstance.rendered.then(function(value) { - console.log('Modal rendered success at: ' + new Date()); - console.log('Modal rendered success value: ' + value); - }, function(reason) { - console.log('Modal rendered error at: ' + new Date()); - console.log('Modal rendered error value: ' + reason); - }); - - $timeout(modalInstance.close('closed by tiemout'), 5000); - - $timeout(modalInstance.dismiss('closed by tiemout'), 10000); - } - } - -})(); diff --git a/angularjs/showcase/src/showcase/app/rest/rest.controller.spec.js b/angularjs/showcase/src/showcase/app/rest/rest.controller.spec.js deleted file mode 100644 index 62f1b3a..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest.controller.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -describe('app.rest', function() { - 'use strict'; - - var Rest; - var cars = { - getAll: function() { - return {}; - } - }; - var $q; - - beforeEach(function() { - module('app.rest'); - - inject(function($controller, $location, _$q_) { - Rest = $controller('Rest', { - $location: $location, - cars: cars - }); - $q = _$q_; - }); - }); - - describe('Rest controller', function () { - - it('should invoke GET all cars in service', function () { - - spyOn(cars, 'getAll') - .and.callFake(function() { - var deferred = $q.defer(); - return deferred.promise; - }); - - Rest.getCars(); - - expect(cars.getAll).toHaveBeenCalled(); - }); - }); - -}); diff --git a/angularjs/showcase/src/showcase/app/rest/rest.html b/angularjs/showcase/src/showcase/app/rest/rest.html deleted file mode 100644 index 47d2136..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest.html +++ /dev/null @@ -1,30 +0,0 @@ - -
- -
- - -
- - Required! - - Single word only! -
- text = {{vm.example.text}}
- myForm.input.$valid = {{myForm.input.$valid}}
- myForm.input.$error = {{myForm.input.$error}}
- myForm.$valid = {{myForm.$valid}}
- myForm.$error.required = {{!!myForm.$error.required}}
- -
    -
  • {{ car.content }}
  • -
- -
-
\ No newline at end of file diff --git a/angularjs/showcase/src/showcase/app/rest/rest.module.js b/angularjs/showcase/src/showcase/app/rest/rest.module.js deleted file mode 100644 index 0ca5bc1..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest.module.js +++ /dev/null @@ -1,20 +0,0 @@ -(function() { - 'use strict'; - - /** - * @ngdoc overview - * @name app.rest - * - * @requires app.core - * - * @description - * # app.rest - * - * ## Module rest. - * Module in charge of sending REST requests. - */ - angular.module('app.rest', [ - 'app.core' - ]); - -})(); diff --git a/angularjs/showcase/src/showcase/app/rest/rest.route.js b/angularjs/showcase/src/showcase/app/rest/rest.route.js deleted file mode 100644 index 5add5b9..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest.route.js +++ /dev/null @@ -1,37 +0,0 @@ -(function() { - 'use strict'; - - angular - .module('app.rest') - .config(configure); - - /** - * @ngdoc service - * @name app.rest.configure - * - * @requires $stateProvider - * @requires $urlRouterProvider - * - *

- *
- * {@link http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider $stateProvider}
- * {@link http://angular-ui.github.io/ui-router/site/#/api/ui.router.router.$urlRouterProvider $urlRouterProvider} - *

- * - * - * @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); - } -}()); diff --git a/angularjs/showcase/src/showcase/app/rest/rest.route.spec.js b/angularjs/showcase/src/showcase/app/rest/rest.route.spec.js deleted file mode 100644 index 91459f7..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest.route.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -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); - }); - - }); - -}); diff --git a/angularjs/showcase/src/showcase/app/rest/rest.service.js b/angularjs/showcase/src/showcase/app/rest/rest.service.js deleted file mode 100644 index 3a7b54a..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest.service.js +++ /dev/null @@ -1,198 +0,0 @@ -(function () { - 'use strict'; - - angular - .module('app.rest') - .factory('rest', rest); - - /** - * @ngdoc service - * @name app.rest.rest - * - * @requires $http - * @requires $q - * - *

- *
- * {@link https://docs.angularjs.org/api/ng/service/$http $http}
- * {@link https://docs.angularjs.org/api/ng/service/$q $q} - *

- * - * @description - * Rest service. - */ - /* @ngInject */ - function rest($http, $q, API) { - return { - getAll: getAll - }; - - /** - * @ngdoc method - * @name getAll - * @methodOf app.rest.rest - * - * @description - * Get cars from API REST. - */ - function getAll() { - return $http.get(API.CARS) - // a) Using success and error from promise. They are deprecated because it is not the ES6 way. DO NOT USE THEM! - // https://github.com/angular/angular.js/commit/a8f7e9cfde82ed7eaba3a868d8acafdf57f2d76f - // .success(successAlternative) - // .error(errorAlternative) - // b) Using then from promise. ES6 way. - .then(success, error, notify) - // Pattern: either use error callback or catch but not both of them as the same time!!!! - // .catch(failed) - .finally(finalizer); - - function success(resp) { - /** - * resp, object containing: - * - * config: Object - * headers: Object - * Accept: "application/json, text/plain, *!/!*" - * method: "GET" - * paramSerializer: ngParamSerializer(params) - * transformRequest: Array[1] - * transformResponse: Array[1] - * url: "/api/cars" - * data: Array[3] - * 0: Object - * content: "Car: 1" - * id: 4 - * 1: Object - * content: "Car: 2" - * id: 5 - * length: 2 - * headers: function(name) - * status: 200 - * statusText: "OK" - */ - - // In this way, then next chained promise will use just its success callback. :( - // What means, promise will be resolved immediately!!! If it is what you want go ahead. - // return resp.data; - - // Better return promise. :) Two options: - - // a) ES6 way (it doesn't have notify :( - // return $q(function(resolve) { - // resolve(resp.data); - // }) - - // b) The CommonJS Promise way. It has the notify method (which I am not using here) - var deferred = $q.defer(); - deferred.resolve(resp.data); - return deferred.promise; - } - - // DO NOT USE IT!!! This way has been deprecated because it is not the ES6 way. - function successAlternative(data, status, headers, config) { - console.log('XHR SuccessAlternative for getAll. SuccessAlternative, data: ' + data); - console.log('XHR SuccessAlternative for getAll. SuccessAlternative, status: ' + status); - console.log('XHR SuccessAlternative for getAll. SuccessAlternative, headers (it is a function): ' + headers); - console.log('XHR SuccessAlternative for getAll. SuccessAlternative, config: ' + config); - } - - function error(reason) { - /** - * resp, object containing: - * - * config: Object - * headers: Object - * Accept: "application/json, text/plain, *!/!*" - * method: "GET" - * paramSerializer: ngParamSerializer(params) - * transformRequest: Array[1] - * transformResponse: Array[1] - * url: "/api/cars" - * data: "Error: connect ECONNREFUSED" - * headers: function(name) - * status: 500 - * statusText: "Internal Server Error" - */ - console.log('XHR Error for getAll. Error: ' + reason.data); - - // In this way, then next chained promise will use just its success callback. :( - // What means, promise will be resolved immediately!!! If it is what you want go ahead. - // return reason.data; - - // Better return promise. :) Three options: - - // a) ES6 way, it doesn't have notify :( - // return $q(function(resolve, reject) { - // reject(reason.data); - // }) - - // b) The CommonJS Promise way. It has the notify method (which I am not using here) - // var deferred = $q.defer(); - // deferred.reject(reason.data); - // return deferred.promise; - - // c) The CommonJS Promise way. The same as b) but with less code :) - return $q.reject(reason.data); - } - - // DO NOT USE IT!!! This way has been deprecated because it is not the ES6 way. - function errorAlternative(data, status, headers, config) { - console.log('XHR ErrorAlternative for getAll. ErrorAlternative, data: ' + data); - console.log('XHR ErrorAlternative for getAll. ErrorAlternative, status: ' + status); - console.log('XHR ErrorAlternative for getAll. ErrorAlternative, headers (it is a function): ' + headers); - console.log('XHR ErrorAlternative for getAll. ErrorAlternative, config: ' + config); - } - - function notify(notification) { - console.log('XHR Notification for getAll. Notification: ' + notification); - } - - function failed(reason) { - /** - * reason, object containing (the same as resp object for error function): - * - * config: Object - * headers: Object - * Accept: "application/json, text/plain, *!/!*" - * method: "GET" - * paramSerializer: ngParamSerializer(params) - * transformRequest: Array[1] - * transformResponse: Array[1] - * url: "/api/cars" - * data: "Error: connect ECONNREFUSED" - * headers: function(name) - * status: 500 - * statusText: "Internal Server Error" - */ - console.log('XHR Failed for getAll. Reason: ' + reason); - - // In this way, then next chained promise will use just its success callback. - // What means, promise will be resolved immediately!!! If it is what you want go ahead. - // return reason.data; - - // Better return promise. :) Three options: - - // a) ES6 way, it doesn't have notify :( - // return $q(function(resolve, reject) { - // reject(reason.data); - // }) - - // b) The CommonJS Promise way. It has the notify method (which I am not using here) - // var deferred = $q.defer(); - // deferred.reject(reason.data); - // return deferred.promise; - - // c) The CommonJS Promise way. The same as b) but with less code :) - return $q.reject(reason.data); - - } - - function finalizer() { - // This callback doesn't have any input parameter :( - console.log('XHR Finalizer for getAll.'); - } - } - } - -}()); diff --git a/angularjs/showcase/src/showcase/app/rest/rest.service.spec.js b/angularjs/showcase/src/showcase/app/rest/rest.service.spec.js deleted file mode 100644 index 7449f84..0000000 --- a/angularjs/showcase/src/showcase/app/rest/rest.service.spec.js +++ /dev/null @@ -1,36 +0,0 @@ -describe('app.rest', function() { - 'use strict'; - - var $httpBackend; - var $log; - var cars; - var API; - - beforeEach(function() { - module('app.rest'); - - inject(function(_$httpBackend_, _$log_, _cars_, _API_) { - $httpBackend = _$httpBackend_; - $log = _$log_; - cars = _cars_; - API = _API_; - }); - }); - - 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(); - }); - -}); diff --git a/angularjs/showcase/src/showcase/index.html b/angularjs/showcase/src/showcase/index.html index bfc7a9e..69e370e 100644 --- a/angularjs/showcase/src/showcase/index.html +++ b/angularjs/showcase/src/showcase/index.html @@ -54,12 +54,12 @@ - - - - - - + + + + + + -- 2.1.4