item crud model refactor #372
This commit is contained in:
parent
4cf5777b4e
commit
75d7c79af1
|
@ -1,28 +1,41 @@
|
|||
<mg-ajax path="/item/api/ItemLogs/getLog" options="vnIndexNonAuto"></mg-ajax>
|
||||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="/item/api/ItemLogs"
|
||||
filter="::$ctrl.filter"
|
||||
link="{originFk: $ctrl.$stateParams.id}"
|
||||
limit="20"
|
||||
data="logs">
|
||||
</vn-crud-model>
|
||||
|
||||
<vn-vertical>
|
||||
<vn-card pad-large>
|
||||
<vn-vertical>
|
||||
<vn-title>Item history</vn-title>
|
||||
<vn-grid-header on-order="$ctrl.onOrder(field, order)">
|
||||
<vn-column-header vn-two pad-medium-h field="description" text="Description"></vn-column-header>
|
||||
<vn-column-header vn-one pad-medium-h field="action" text="Action"></vn-column-header>
|
||||
<vn-column-header vn-one pad-medium-h field="userFk" text="Changed by"></vn-column-header>
|
||||
<vn-column-header vn-one pad-medium-h field="creationDate" text="Date" default-order="ASC"></vn-column-header>
|
||||
</vn-grid-header>
|
||||
<vn-one class="list list-content">
|
||||
<vn-horizontal
|
||||
class="list list-element text-center"
|
||||
pad-small-bottom
|
||||
ng-repeat="itemLog in index.model.instances track by itemLog.id">
|
||||
<vn-two pad-medium-h>{{::itemLog.description}}</vn-two>
|
||||
<vn-one pad-medium-h>{{::itemLog.action}}</vn-one>
|
||||
<vn-one pad-medium-h>{{::itemLog.user.name}}</vn-one>
|
||||
<vn-one pad-medium-h>{{::itemLog.creationDate | date:'dd/MM/yyyy HH:mm'}}</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 text-center"></vn-horizontal>
|
||||
<vn-table model="model">
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th field="description">Description</vn-th>
|
||||
<vn-th field="action">Action</vn-th>
|
||||
<vn-th field="userFk">Changed by</vn-th>
|
||||
<vn-th field="creationDate" default-order="DESC">Date</vn-th>
|
||||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="itemLog in logs">
|
||||
<vn-td>{{::itemLog.description}}</vn-td>
|
||||
<vn-td>{{::itemLog.action}}</vn-td>
|
||||
<vn-td>{{::itemLog.user.name}}</vn-td>
|
||||
<vn-td>{{::itemLog.creationDate | date:'dd/MM/yyyy HH:mm'}}</vn-td>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
<vn-empty-rows ng-if="model.data.length === 0" translate>
|
||||
No results
|
||||
</vn-empty-rows>
|
||||
</vn-table>
|
||||
</vn-vertical>
|
||||
<vn-pagination
|
||||
model="model"
|
||||
scroll-selector="ui-view">
|
||||
</vn-pagination>
|
||||
</vn-card>
|
||||
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
|
||||
</vn-vertical>
|
||||
|
|
|
@ -1,7 +1,25 @@
|
|||
import ngModule from '../module';
|
||||
import FilterItemList from '../filter-item-list';
|
||||
|
||||
class Controller {
|
||||
constructor($stateParams) {
|
||||
this.$stateParams = $stateParams;
|
||||
this.filter = {
|
||||
include: [{
|
||||
relation: "item"
|
||||
},
|
||||
{
|
||||
relation: "user",
|
||||
scope: {
|
||||
fields: ["name"]
|
||||
}
|
||||
}]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$stateParams'];
|
||||
|
||||
ngModule.component('vnItemHistory', {
|
||||
template: require('./index.html'),
|
||||
controller: FilterItemList
|
||||
controller: Controller
|
||||
});
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="/item/api/Items/getLastEntries"
|
||||
filter="::$ctrl.filter"
|
||||
data="entries">
|
||||
</vn-crud-model>
|
||||
<vn-vertical>
|
||||
<vn-card pad-large>
|
||||
<vn-vertical>
|
||||
|
@ -6,62 +12,65 @@
|
|||
<vn-date-picker
|
||||
vn-one
|
||||
label="Since"
|
||||
model="$ctrl.entriesDate"
|
||||
model="$ctrl.date"
|
||||
ini-options="{dateFormat: 'd-m-Y'}">
|
||||
</vn-date-picker>
|
||||
<!--datepicker-->
|
||||
</vn-horizontal>
|
||||
<table class="vn-grid">
|
||||
<thead>
|
||||
<tr>
|
||||
<th number vn-tooltip="Ignored">Ig</th>
|
||||
<th number translate>Warehouse</th>
|
||||
<th number translate>Landed</th>
|
||||
<th number translate>Entry</th>
|
||||
<th number vn-tooltip="Price Per Unit">P.P.U</th>
|
||||
<th number vn-tooltip="Price Per Package">P.P.P</th>
|
||||
<th number class="expendable" translate>Label</th>
|
||||
<th number>Packing</th>
|
||||
<th number>Grouping</th>
|
||||
<th number class="expendable" translate>Stems</th>
|
||||
<th number translate>Quantity</th>
|
||||
<th number class="expendable" translate>Cost</th>
|
||||
<th number translate>Cube</th>
|
||||
<th number class="expendable" translate>Provider</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="entries in $ctrl.entries">
|
||||
<td number>
|
||||
<vn-table model="model">
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th number vn-tooltip="Ignored">Ig</vn-th>
|
||||
<vn-th number>Warehouse</vn-th>
|
||||
<vn-th number>Landed</vn-th>
|
||||
<vn-th number>Entry</vn-th>
|
||||
<vn-th number vn-tooltip="Price Per Unit">P.P.U</vn-th>
|
||||
<vn-th number vn-tooltip="Price Per Package">P.P.P</vn-th>
|
||||
<vn-th number class="expendable">Label</vn-th>
|
||||
<vn-th number>Packing</vn-th>
|
||||
<vn-th number>Grouping</vn-th>
|
||||
<vn-th number class="expendable">Stems</vn-th>
|
||||
<vn-th number>Quantity</vn-th>
|
||||
<vn-th number class="expendable">Cost</vn-th>
|
||||
<vn-th number>Cube</vn-th>
|
||||
<vn-th number class="expendable">Provider</vn-th>
|
||||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="entry in entries">
|
||||
<vn-td number>
|
||||
<vn-check
|
||||
field="entries.isIgnored"
|
||||
disabled="true">
|
||||
</vn-check>
|
||||
</td>
|
||||
<td number>{{entries.warehouse| dashIfEmpty}}</td>
|
||||
<td number>{{entries.landed | date:'dd/MM/yyyy HH:mm'}}</td>
|
||||
<td number>{{entries.entryFk | dashIfEmpty}}</td>
|
||||
<td number>{{entries.price2 | dashIfEmpty}}</td>
|
||||
<td number>{{entries.price3 | dashIfEmpty}}</td>
|
||||
<td number class="expendable">{{entries.stickers | dashIfEmpty}}</td>
|
||||
<td number>
|
||||
<div ng-class="{'round': entries.groupingMode == 2}">{{entries.packing | dashIfEmpty}}</div>
|
||||
</td>
|
||||
<td number>
|
||||
<div ng-class="{'round': entries.groupingMode == 1}">{{entries.grouping | dashIfEmpty}}</div>
|
||||
</td>
|
||||
<td number class="expendable">{{entries.stems | dashIfEmpty}}</td>
|
||||
<td number>{{entries.quantity}}</td>
|
||||
<td number class="expendable">{{entries.buyingValue | dashIfEmpty}}</td>
|
||||
<td number>{{entries.packageFk | dashIfEmpty}}</td>
|
||||
<td number class="expendable">{{entries.supplier | dashIfEmpty}}</td>
|
||||
</tr>
|
||||
<tr ng-if="$ctrl.entries.length === 0" class="list list-element">
|
||||
<td colspan="14" style="text-align: center" translate>No results</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</vn-td>
|
||||
<vn-td number>{{entry.warehouse| dashIfEmpty}}</vn-td>
|
||||
<vn-td number>{{entry.landed | date:'dd/MM/yyyy HH:mm'}}</vn-td>
|
||||
<vn-td number>{{entry.entryFk | dashIfEmpty}}</vn-td>
|
||||
<vn-td number>{{entry.price2 | dashIfEmpty}}</vn-td>
|
||||
<vn-td number>{{entry.price3 | dashIfEmpty}}</vn-td>
|
||||
<vn-td number class="expendable">{{entry.stickers | dashIfEmpty}}</vn-td>
|
||||
<vn-td number>
|
||||
<div ng-class="{'counter': entry.groupingMode == 2}">{{entry.packing | dashIfEmpty}}</div>
|
||||
</vn-td>
|
||||
<vn-td number>
|
||||
<span ng-class="{'counter': entry.groupingMode == 1}">{{entry.grouping | dashIfEmpty}}</span>
|
||||
</vn-td>
|
||||
<vn-td number class="expendable">{{entry.stems | dashIfEmpty}}</vn-td>
|
||||
<vn-td number>{{entry.quantity}}</vn-td>
|
||||
<vn-td number class="expendable">{{entry.buyingValue | dashIfEmpty}}</vn-td>
|
||||
<vn-td number>{{entry.packageFk | dashIfEmpty}}</vn-td>
|
||||
<vn-td number class="expendable">{{entry.supplier | dashIfEmpty}}</vn-td>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
<vn-empty-rows ng-if="model.data.length === 0" translate>
|
||||
No results
|
||||
</vn-empty-rows>
|
||||
</vn-table>
|
||||
</vn-vertical>
|
||||
<vn-pagination
|
||||
model="model"
|
||||
scroll-selector="ui-view">
|
||||
</vn-pagination>
|
||||
</vn-card>
|
||||
<vn-paging margin-large-top vn-one index="$ctrl.entries" total="$ctrl.entries.count"></vn-paging>
|
||||
</vn-vertical>
|
||||
|
|
|
@ -2,50 +2,38 @@ import ngModule from '../module';
|
|||
import './style.scss';
|
||||
|
||||
class Controller {
|
||||
constructor($scope, $http) {
|
||||
this.$ = $scope;
|
||||
this.$http = $http;
|
||||
this.entries = [];
|
||||
}
|
||||
constructor($scope, $stateParams) {
|
||||
this.$scope = $scope;
|
||||
this.$stateParams = $stateParams;
|
||||
|
||||
set item(value) {
|
||||
this._item = value;
|
||||
this._defaultEntriesDate();
|
||||
this._getLastEntries();
|
||||
}
|
||||
|
||||
get item() {
|
||||
return this._item;
|
||||
}
|
||||
|
||||
set entriesDate(value) {
|
||||
this._entriesDate = value;
|
||||
this._getLastEntries();
|
||||
}
|
||||
|
||||
get entriesDate() {
|
||||
return this._entriesDate;
|
||||
}
|
||||
|
||||
_defaultEntriesDate() {
|
||||
let defaultDate;
|
||||
defaultDate = new Date();
|
||||
let defaultDate = new Date();
|
||||
defaultDate.setDate(defaultDate.getDate() - 75);
|
||||
defaultDate.setHours(0, 0, 0, 0);
|
||||
this._entriesDate = defaultDate;
|
||||
|
||||
this.filter = {
|
||||
where: {
|
||||
itemFk: $stateParams.id,
|
||||
date: defaultDate
|
||||
}
|
||||
};
|
||||
this._date = defaultDate;
|
||||
}
|
||||
|
||||
_getLastEntries() {
|
||||
if (!this.entriesDate || !this.item)
|
||||
return;
|
||||
let filter = {itemFk: this.item.id, date: this.entriesDate};
|
||||
this.$http.get(`/item/api/Items/getLastEntries?filter=${JSON.stringify(filter)}`).then(res => {
|
||||
this.entries = res.data;
|
||||
});
|
||||
set date(value) {
|
||||
this._date = value;
|
||||
|
||||
if (!value) return;
|
||||
|
||||
this.filter.where.date = value;
|
||||
this.$scope.model.refresh();
|
||||
}
|
||||
|
||||
get date() {
|
||||
return this._date;
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$scope', '$http'];
|
||||
Controller.$inject = ['$scope', '$stateParams'];
|
||||
|
||||
ngModule.component('vnItemLastEntries', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
import './index.js';
|
||||
|
||||
describe('Item', () => {
|
||||
describe('Component vnItemLastEntries', () => {
|
||||
let $componentController;
|
||||
let $scope;
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let defaultDate;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('item');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
|
||||
$componentController = _$componentController_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||
$scope = $rootScope.$new();
|
||||
controller = $componentController('vnItemLastEntries', {$scope: $scope});
|
||||
controller.item = {id: 3};
|
||||
}));
|
||||
|
||||
describe('set item()', () => {
|
||||
it(`should set item and call _defaultEntriesDate() and _getLastEntries()`, () => {
|
||||
spyOn(controller, '_defaultEntriesDate');
|
||||
spyOn(controller, '_getLastEntries');
|
||||
controller.item = [];
|
||||
|
||||
expect(controller._defaultEntriesDate).toHaveBeenCalledWith();
|
||||
expect(controller._getLastEntries).toHaveBeenCalledWith();
|
||||
expect(controller.item).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('set entriesDate()', () => {
|
||||
it(`should set entriesDate and call _getLastEntries()`, () => {
|
||||
spyOn(controller, '_getLastEntries');
|
||||
controller.item = [];
|
||||
controller.entriesDate = new Date();
|
||||
|
||||
expect(controller._getLastEntries).toHaveBeenCalledWith();
|
||||
expect(controller.item).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('_defaultEntriesDate()', () => {
|
||||
it(`should set entriesDate to a date 75 days ago`, () => {
|
||||
defaultDate = new Date();
|
||||
defaultDate.setDate(defaultDate.getDate() - 75);
|
||||
defaultDate.setHours(0, 0, 0, 0);
|
||||
controller._defaultEntriesDate();
|
||||
|
||||
expect(controller.entriesDate).toEqual(defaultDate);
|
||||
});
|
||||
});
|
||||
|
||||
describe('_getLastEntries()', () => {
|
||||
it(`should make a GET if entriesDate and item are defined`, () => {
|
||||
controller._defaultEntriesDate();
|
||||
let filter = {itemFk: controller.item.id, date: controller.entriesDate};
|
||||
$httpBackend.whenGET(`/item/api/Items/getLastEntries?filter=${JSON.stringify(filter)}`).respond([]);
|
||||
$httpBackend.expectGET(`/item/api/Items/getLastEntries?filter=${JSON.stringify(filter)}`);
|
||||
controller._getLastEntries();
|
||||
$httpBackend.flush();
|
||||
// expect(controller.entriesDate).toEqual(defaultDate);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -19,8 +19,9 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.getLastEntries = async filter => {
|
||||
let where = filter.where;
|
||||
let query = `CALL vn.itemLastEntries(?, ?)`;
|
||||
let [lastEntries] = await Self.rawSql(query, [filter.itemFk, filter.date]);
|
||||
let [lastEntries] = await Self.rawSql(query, [where.itemFk, where.date]);
|
||||
return lastEntries;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -19,6 +19,7 @@ module.exports = {
|
|||
* @return {String} Cuenta bancaria formateada
|
||||
*/
|
||||
accountAddress: function(addressNumber) {
|
||||
if (!addressNumber) return;
|
||||
var formattedAccountAddress = addressNumber.replace(/(.{4})/g, '$1-');
|
||||
return formattedAccountAddress.substring(0, formattedAccountAddress.length - 1);
|
||||
},
|
||||
|
@ -29,6 +30,7 @@ module.exports = {
|
|||
* @return {String} Cuenta bancaria formateada
|
||||
*/
|
||||
partialAccountAddress: function(addressNumber) {
|
||||
if (!addressNumber) return;
|
||||
let address = this.accountAddress(addressNumber);
|
||||
return address.substring(0, 19).replace(/[0-9]/g, 'X') + address.substring(19, 24);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue