entidad recovery con list, create y tests

This commit is contained in:
Javi Gallego 2018-03-01 11:55:28 +01:00
parent 241c360c54
commit f3b00f4b47
13 changed files with 188 additions and 2 deletions

View File

@ -179,6 +179,31 @@
"description": "Mandate",
"icon": "pan_tool"
}
},
{
"url": "/recovery",
"abstract": true,
"state": "clientCard.recovery",
"component": "ui-view"
},
{
"url": "/list",
"state": "clientCard.recovery.list",
"component": "vn-client-recovery-list",
"params": {
"client": "$ctrl.client"
},
"menu": {
"description": "Recovery",
"icon": "credit_card"
}
}, {
"url": "/create",
"state": "clientCard.recovery.create",
"component": "vn-client-recovery-create",
"params": {
"client": "$ctrl.client"
}
}
]
}

View File

@ -19,3 +19,5 @@ import './credit-create/credit-create';
import './greuge-list/greuge-list';
import './greuge-create/greuge-create';
import './mandate/mandate';
import './recovery-list/recovery-list';
import './recovery-create/recovery-create';

View File

@ -15,8 +15,7 @@
<vn-date-picker vn-one
label="Date"
model="$ctrl.greuge.shipped"
ini-options="{enableTime: true, dateFormat: 'd-m-Y h:i', time_24hr: true}"
>
ini-options="{enableTime: true, dateFormat: 'd-m-Y h:i', time_24hr: true}">
</vn-date-picker>
</vn-horizontal>
<vn-horizontal>

View File

@ -0,0 +1,2 @@
Add recovery: Añadir recobro
Period: Periodo

View File

@ -0,0 +1,34 @@
<mg-ajax path="/client/api/recoveries" options="vnPost"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.recovery"
form="form"
save="post">
</vn-watcher>
<form pad-medium name="form" ng-submit="$ctrl.onSubmit()">
<vn-card>
<vn-vertical pad-large>
<vn-title>Add recovery</vn-title>
<vn-horizontal>
<vn-date-picker vn-one
label="Since"
model="$ctrl.recovery.started"
ini-options="{dateFormat: 'd-m-Y'}"
vn-focus>
</vn-date-picker>
<vn-date-picker vn-one
label="To"
model="$ctrl.recovery.finished"
ini-options="{dateFormat: 'd-m-Y'}">
</vn-date-picker>
<vn-textfield vn-one label="Amount" field="$ctrl.recovery.amount" type="number"></vn-textfield>
<vn-textfield vn-one label="Period" field="$ctrl.recovery.period" type="number"></vn-textfield>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -0,0 +1,25 @@
import ngModule from '../module';
class ClientRecoveryCreate {
constructor($scope, $state, $filter) {
this.$ = $scope;
this.$state = $state;
this.recovery = {
started: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm')
};
}
onSubmit() {
this.recovery.clientFk = this.$state.params.id;
this.$.watcher.submit().then(
() => {
this.$state.go('clientCard.recovery.list');
}
);
}
}
ClientRecoveryCreate.$inject = ['$scope', '$state', '$filter'];
ngModule.component('vnClientRecoveryCreate', {
template: require('./recovery-create.html'),
controller: ClientRecoveryCreate
});

View File

@ -0,0 +1,39 @@
import './recovery-create.js';
describe('Client', () => {
describe('Component vnClientRecoveryCreate', () => {
let $componentController;
let $scope;
let $state;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$state = _$state_;
$scope.watcher = {
submit: () => {
return {
then: callback => {
callback();
}
};
}
};
controller = $componentController('vnClientRecoveryCreate', {$scope: $scope});
}));
describe('onSubmit()', () => {
it('should call the function go() on $state to go to the recovery list', () => {
spyOn($state, 'go');
controller.onSubmit();
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.recovery.list');
});
});
});
});

View File

@ -0,0 +1,4 @@
Since: Desde
Employee: Empleado
No results: Sin resultados
To: Hasta

View File

@ -0,0 +1,29 @@
<mg-ajax path="/client/api/Recoveries/filter" options="vnIndexNonAuto"></mg-ajax>
<vn-card pad-medium>
<vn-vertical pad-large>
<vn-title vn-one margin-large-bottom>Recovery</vn-title>
<vn-grid-header on-order="$ctrl.onOrder(field, order)">
<vn-column-header vn-one pad-medium-h field="started" text="Since" default-order="DESC"></vn-column-header>
<vn-column-header vn-one pad-medium-h field="finished" text="To"></vn-column-header>
<vn-column-header vn-one pad-medium-h field="amount" text="Amount"></vn-column-header>
<vn-column-header vn-one pad-medium-h field="period" text="Period"></vn-column-header>
</vn-grid-header>
<vn-one class="list list-content">
<vn-horizontal
vn-one class="list list-element text-center"
pad-small-bottom
ng-repeat="recovery in index.model.instances track by recovery.id">
<vn-one pad-medium-h>{{::recovery.started | date:'dd/MM/yyyy' }}</vn-one>
<vn-one pad-medium-h>{{::recovery.finished | date:'dd/MM/yyyy' }}</vn-one>
<vn-one pad-medium-h>{{::recovery.amount | currency:'€':0}}</vn-one>
<vn-one pad-medium-h>{{::recovery.period}}</vn-one>
</vn-horizontal>
</vn-one>
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one>
<vn-horizontal vn-one class="list list-footer"></vn-horizontal>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-vertical>
</vn-card>
<a ui-sref="clientCard.recovery.create" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
</a>

View File

@ -0,0 +1,7 @@
import ngModule from '../module';
import FilterClientList from '../filter-client-list';
ngModule.component('vnClientRecoveryList', {
template: require('./recovery-list.html'),
controller: FilterClientList
});

View File

@ -0,0 +1,14 @@
module.exports = Self => {
Self.installMethod('filter', filterParams);
function filterParams(params) {
return {
where: {
clientFk: params.clientFk
},
skip: (params.page - 1) * params.size,
limit: params.size,
order: params.order
};
}
};

View File

@ -0,0 +1,3 @@
module.exports = function(Self) {
require('../methods/recovery/filter.js')(Self);
};

View File

@ -25,5 +25,8 @@
},
"ObservationType": {
"dataSource": "vn"
},
"Recovery": {
"dataSource": "vn"
}
}