button for insert rows
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2022-03-15 09:36:48 +01:00
parent 7f5b30aa87
commit ec41123772
8 changed files with 252 additions and 8 deletions

View File

@ -0,0 +1,75 @@
<vn-watcher
vn-id="watcher"
url="SupplierAgencyTerms"
primary-key="agencyFk"
data="$ctrl.supplierAgencyTerm"
insert-mode="true"
form="form">
</vn-watcher>
<vn-crud-model
auto-load="true"
url="Agencies"
filter="$ctrl.filter"
data="agencies">
</vn-crud-model>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-horizontal>
<vn-autocomplete vn-id="agency" vn-one
label="Agency"
ng-model="$ctrl.supplierAgencyTerm.agencyFk"
data="agencies"
show-field="name"
value-field="id"
rule>
</vn-autocomplete>
<vn-input-number
type="number"
label="Minimum M3"
ng-model="$ctrl.supplierAgencyTerm.minimumM3"
rule>
</vn-input-number>
</vn-horizontal>
<vn-horizontal>
<vn-input-number
type="number"
label="Package Price"
ng-model="$ctrl.supplierAgencyTerm.packagePrice"
rule>
</vn-input-number>
<vn-input-number
type="number"
label="Km Price"
ng-model="$ctrl.supplierAgencyTerm.kmPrice"
rule>
</vn-input-number>
<vn-input-number
type="number"
label="M3 Price"
ng-model="$ctrl.supplierAgencyTerm.m3Price"
rule>
</vn-input-number>
</vn-horizontal>
<vn-horizontal>
<vn-input-number
type="number"
label="Route Price"
ng-model="$ctrl.supplierAgencyTerm.routePrice"
rule>
</vn-input-number>
<vn-input-number
type="number"
label="Minimum Km"
ng-model="$ctrl.supplierAgencyTerm.minimumKm"
rule>
</vn-input-number>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button
label="Cancel"
ui-sref="supplier.card.agencyTerm.index">
</vn-button>
</vn-button-bar>
</form>

View File

@ -0,0 +1,34 @@
import ngModule from '../../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.filter = {
fields: [
'name'
],
include: [{
relation: 'supplierAgencyTerm',
where: {
supplierFk: 1
}
}],
};
}
onSubmit() {
this.$.watcher.submit().then(res => {
this.$state.go('supplier.card.address.index');
});
}
}
ngModule.vnComponent('vnSupplierAgencyTermCreate', {
template: require('./index.html'),
controller: Controller,
bindings: {
supplier: '<'
}
});

View File

@ -0,0 +1,102 @@
import './index';
import watcher from 'core/mocks/watcher';
describe('Supplier', () => {
describe('Component vnSupplierAddressCreate', () => {
let $scope;
let controller;
let $element;
let $state;
beforeEach(ngModule('supplier'));
beforeEach(inject(($componentController, $rootScope, _$state_) => {
$scope = $rootScope.$new();
$state = _$state_;
$state.params.id = '1234';
$element = angular.element('<vn-supplier-address-create></vn-supplier-address-create>');
controller = $componentController('vnSupplierAddressCreate', {$element, $scope});
controller.$.watcher = watcher;
controller.$.watcher.submit = () => {
return {
then: callback => {
callback({data: {id: 124}});
}
};
};
controller.supplier = {id: 1};
}));
describe('onSubmit()', () => {
it('should perform a PATCH and then redirect to the main section', () => {
jest.spyOn(controller.$state, 'go');
controller.onSubmit();
expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.address.index');
});
});
describe('town() setter', () => {
it(`should set provinceFk property`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: []
};
expect(controller.address.provinceFk).toEqual(1);
});
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: [{code: '46001'}]
};
expect(controller.address.provinceFk).toEqual(1);
expect(controller.address.postalCode).toEqual('46001');
});
});
describe('postcode() setter', () => {
it(`should set the town and province properties`, () => {
controller.postcode = {
townFk: 1,
code: 46001,
town: {
id: 1,
name: 'New York',
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
}
}
};
expect(controller.address.city).toEqual('New York');
expect(controller.address.provinceFk).toEqual(1);
});
});
});
});

View File

@ -15,7 +15,7 @@
<vn-card class="vn-pa-lg">
<vn-horizontal ng-repeat="supplierAgencyTerm in $ctrl.supplierAgencyTerms">
<vn-autocomplete
vn-id="text"
vn-id="agency"
label="Agency"
ng-model="supplierAgencyTerm.agencyFk"
url="Agencies"
@ -84,3 +84,11 @@
</vn-submit>
</vn-button-bar>
</form>
<vn-float-button
vn-bind="+"
fixed-bottom-right
vn-tooltip="New row"
ui-sref="supplier.card.agencyTerm.create"
icon="add"
label="Add">
</vn-float-button>

View File

@ -1,4 +1,4 @@
import ngModule from '../module';
import ngModule from '../../module';
import Section from 'salix/components/section';
class Controller extends Section {
@ -15,7 +15,7 @@ class Controller extends Section {
}
}
ngModule.vnComponent('vnSupplierAgencyTerm', {
ngModule.vnComponent('vnSupplierAgencyTermIndex', {
template: require('./index.html'),
controller: Controller,
bindings: {

View File

@ -18,4 +18,5 @@ import './billing-data';
import './address/index';
import './address/create';
import './address/edit';
import './agency-term';
import './agency-term/index';
import './agency-term/create';

View File

@ -15,7 +15,7 @@
{"state": "supplier.card.address.index", "icon": "icon-delivery"},
{"state": "supplier.card.account", "icon": "icon-account"},
{"state": "supplier.card.contact", "icon": "contact_phone"},
{"state": "supplier.card.agencyTerm", "icon": "contact_support"},
{"state": "supplier.card.agencyTerm.index", "icon": "contact_support"},
{"state": "supplier.card.log", "icon": "history"},
{"state": "supplier.card.consumption", "icon": "show_chart"}
]
@ -90,9 +90,26 @@
{
"url": "/agency-term",
"state": "supplier.card.agencyTerm",
"component": "vn-supplier-agency-term",
"component": "ui-view",
"abstract": true
},
{
"url": "/index?q",
"state": "supplier.card.agencyTerm.index",
"component": "vn-supplier-agency-term-index",
"description": "Autonomous",
"acl": ["administrative"]
"params": {
"supplier": "$ctrl.supplier"
}
},
{
"url": "/create",
"state": "supplier.card.agencyTerm.create",
"component": "vn-supplier-agency-term-create",
"description": "New autonomous",
"params": {
"supplier": "$ctrl.supplier"
}
},
{
"url": "/consumption?q",

View File

@ -16,5 +16,12 @@
"type": "string",
"required": false
}
},
"relations": {
"supplierAgencyTerm": {
"type": "belongsTo",
"model": "SupplierAgencyTerm",
"foreignKey": "agencyFk"
}
}
}