create section travel create
gitea/salix/1900travelCreate This commit looks good Details

This commit is contained in:
Bernat Exposito Domenech 2019-12-09 12:15:19 +01:00
parent 966c02a0e1
commit 2cc9c5e951
8 changed files with 121 additions and 3 deletions

View File

@ -1,5 +1,5 @@
CREATE TABLE `vn`.`travelLog` ( 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, `originFk` int(10) unsigned NOT NULL,
`userFk` int(10) unsigned DEFAULT NULL, `userFk` int(10) unsigned DEFAULT NULL,
`action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
@ -13,6 +13,6 @@ CREATE TABLE `vn`.`travelLog` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `originFk` (`originFk`), KEY `originFk` (`originFk`),
KEY `userFk` (`userFk`), 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 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; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

View File

@ -0,0 +1,60 @@
<mg-ajax path="Travels" options="vnPost"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.travel"
form="form"
save="post">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-horizontal>
<vn-textfield
vn-one
label="Reference"
ng-model="$ctrl.travel.ref">
</vn-textfield>
<vn-autocomplete
vn-one
ng-model="$ctrl.travel.agencyModeFk"
url="AgencyModes"
show-field="name"
value-field="id"
label="Agency">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-date-picker
vn-one
label="Shipped"
ng-model="$ctrl.travel.shipped">
</vn-date-picker>
<vn-date-picker
vn-one
label="Landed"
ng-model="$ctrl.travel.landed">
</vn-date-picker>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
ng-model="$ctrl.travel.warehouseOutFk"
url="Warehouses"
show-field="name"
value-field="id"
label="Warehouse Out">
</vn-autocomplete>
<vn-autocomplete
vn-one
ng-model="$ctrl.travel.warehouseInFk"
url="Warehouses"
show-field="name"
value-field="id"
label="Warehouse In">
</vn-autocomplete>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button label="Undo changes" ng-if="watcher.dataChanged()" ng-click="watcher.loadOriginalData()"></vn-button>
</vn-button-bar>
</form>

View File

@ -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
});

View File

@ -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('<div></div>');
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});
});
});
});

View File

@ -8,3 +8,4 @@ import './card';
import './summary'; import './summary';
import './basic-data'; import './basic-data';
import './log'; import './log';
import './create';

View File

@ -58,4 +58,11 @@
travel="$ctrl.travelSelected"> travel="$ctrl.travelSelected">
</vn-travel-summary> </vn-travel-summary>
</vn-popup> </vn-popup>
<a ui-sref="travel.create"
vn-tooltip="New travel"
vn-bind="+"
vn-acl="buyer"
fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
</a>
<vn-scroll-up></vn-scroll-up> <vn-scroll-up></vn-scroll-up>

View File

@ -12,7 +12,7 @@ Delivered: Enviado
Received: Recibido Received: Recibido
Travel id: Id envío Travel id: Id envío
Search travels by id: Buscar envios por identificador Search travels by id: Buscar envios por identificador
New travel: Nuevo travel
# Sections # Sections
Travels: Envíos Travels: Envíos
Log: Historial Log: Historial

View File

@ -53,6 +53,11 @@
"state": "travel.card.log", "state": "travel.card.log",
"component": "vn-travel-log", "component": "vn-travel-log",
"description": "Log" "description": "Log"
}, {
"url": "/create",
"state": "travel.create",
"component": "vn-travel-create",
"description": "New travel"
} }
] ]
} }