From 2cc9c5e9510190dcbb91bf54788debdc636769bc Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Mon, 9 Dec 2019 12:15:19 +0100 Subject: [PATCH] create section travel create --- db/changes/10100-allSaints/00-travelLog.sql | 4 +- modules/travel/front/create/index.html | 60 +++++++++++++++++++++ modules/travel/front/create/index.js | 15 ++++++ modules/travel/front/create/index.spec.js | 30 +++++++++++ modules/travel/front/index.js | 1 + modules/travel/front/index/index.html | 7 +++ modules/travel/front/locale/es.yml | 2 +- modules/travel/front/routes.json | 5 ++ 8 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 modules/travel/front/create/index.html create mode 100644 modules/travel/front/create/index.js create mode 100644 modules/travel/front/create/index.spec.js diff --git a/db/changes/10100-allSaints/00-travelLog.sql b/db/changes/10100-allSaints/00-travelLog.sql index bd7035fd1..fe9d03274 100644 --- a/db/changes/10100-allSaints/00-travelLog.sql +++ b/db/changes/10100-allSaints/00-travelLog.sql @@ -1,5 +1,5 @@ CREATE TABLE `vn`.`travelLog` ( - `id` int(11) NOT NULL AUTO_INCREMENT, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `originFk` int(10) unsigned NOT NULL, `userFk` int(10) unsigned DEFAULT NULL, `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, @@ -13,6 +13,6 @@ CREATE TABLE `vn`.`travelLog` ( PRIMARY KEY (`id`), KEY `originFk` (`originFk`), KEY `userFk` (`userFk`), - CONSTRAINT `travelLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `travelLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn`.`travel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `travelLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; \ No newline at end of file diff --git a/modules/travel/front/create/index.html b/modules/travel/front/create/index.html new file mode 100644 index 000000000..586689ff7 --- /dev/null +++ b/modules/travel/front/create/index.html @@ -0,0 +1,60 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js new file mode 100644 index 000000000..02be34ca7 --- /dev/null +++ b/modules/travel/front/create/index.js @@ -0,0 +1,15 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +class Controller extends Section { + onSubmit() { + return this.$.watcher.submit().then( + res => this.$state.go('travel.card.summary', {id: res.data.id}) + ); + } +} + +ngModule.component('vnTravelCreate', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js new file mode 100644 index 000000000..88152120e --- /dev/null +++ b/modules/travel/front/create/index.spec.js @@ -0,0 +1,30 @@ +import './index'; +import watcher from 'core/mocks/watcher'; + +describe('Travel Component vnTravelCreate', () => { + let $element; + let $scope; + let $state; + let controller; + + beforeEach(ngModule('travel')); + + beforeEach(angular.mock.inject(($componentController, $rootScope, _$state_) => { + $scope = $rootScope.$new(); + $state = _$state_; + $scope.watcher = watcher; + $element = angular.element('
'); + controller = $componentController('vnTravelCreate', {$element, $scope}); + })); + + describe('onSubmit()', () => { + it(`should call submit() on the watcher then expect a callback`, () => { + spyOn($state, 'go'); + + controller.onSubmit(); + + expect(controller.$state.go).toHaveBeenCalledWith('travel.card.summary', {id: 1234}); + }); + }); +}); + diff --git a/modules/travel/front/index.js b/modules/travel/front/index.js index d9e1fa07e..02bbb997b 100644 --- a/modules/travel/front/index.js +++ b/modules/travel/front/index.js @@ -8,3 +8,4 @@ import './card'; import './summary'; import './basic-data'; import './log'; +import './create'; diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index 1989a1262..044f1ca8f 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -58,4 +58,11 @@ travel="$ctrl.travelSelected"> + + + \ No newline at end of file diff --git a/modules/travel/front/locale/es.yml b/modules/travel/front/locale/es.yml index 54feab876..454cfa58f 100644 --- a/modules/travel/front/locale/es.yml +++ b/modules/travel/front/locale/es.yml @@ -12,7 +12,7 @@ Delivered: Enviado Received: Recibido Travel id: Id envío Search travels by id: Buscar envios por identificador - +New travel: Nuevo travel # Sections Travels: Envíos Log: Historial \ No newline at end of file diff --git a/modules/travel/front/routes.json b/modules/travel/front/routes.json index f540d532f..357ffffc2 100644 --- a/modules/travel/front/routes.json +++ b/modules/travel/front/routes.json @@ -53,6 +53,11 @@ "state": "travel.card.log", "component": "vn-travel-log", "description": "Log" + }, { + "url": "/create", + "state": "travel.create", + "component": "vn-travel-create", + "description": "New travel" } ] } \ No newline at end of file