This commit is contained in:
parent
974bf67e8d
commit
8fc76b49c9
|
@ -1,8 +1,3 @@
|
|||
<vn-crud-model auto-load="true"
|
||||
url="Zones/{{$ctrl.$params.id}}/warehouses"
|
||||
include="{relation: 'warehouse'}"
|
||||
data="zoneWarehouses">
|
||||
</vn-crud-model>
|
||||
<vn-card class="summary">
|
||||
<h5>#{{$ctrl.summary.id}} - {{$ctrl.summary.name}}</h5>
|
||||
<vn-horizontal class="vn-pa-md">
|
||||
|
@ -34,14 +29,14 @@
|
|||
<vn-horizontal class="vn-pa-md">
|
||||
<vn-auto>
|
||||
<h4 translate>Warehouses</h4>
|
||||
<vn-table model="model">
|
||||
<vn-table model="model" auto-load="false">
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th>Name</vn-th>
|
||||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="zoneWarehouse in zoneWarehouses">
|
||||
<vn-tr ng-repeat="zoneWarehouse in $ctrl.zoneWarehouses">
|
||||
<vn-td>{{zoneWarehouse.warehouse.name}}</vn-td>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
|
|
|
@ -2,6 +2,11 @@ import ngModule from '../module';
|
|||
import Component from 'core/lib/component';
|
||||
|
||||
class Controller extends Component {
|
||||
constructor($element, $, $httpParamSerializer) {
|
||||
super($element, $);
|
||||
|
||||
this.$httpParamSerializer = $httpParamSerializer;
|
||||
}
|
||||
get zone() {
|
||||
return this._zone;
|
||||
}
|
||||
|
@ -12,21 +17,45 @@ class Controller extends Component {
|
|||
if (!value) return;
|
||||
|
||||
this.getSummary();
|
||||
this.getWarehouses();
|
||||
}
|
||||
|
||||
getSummary() {
|
||||
let filter = {
|
||||
include: {relation: 'agencyMode', fields: ['name']},
|
||||
where: {id: this.zone.id}
|
||||
const params = {
|
||||
filter: {
|
||||
include: {
|
||||
relation: 'agencyMode',
|
||||
fields: ['name']
|
||||
},
|
||||
where: {
|
||||
id: this.zone.id
|
||||
}
|
||||
}
|
||||
};
|
||||
filter = encodeURIComponent(JSON.stringify((filter)));
|
||||
this.$http.get(`Zones/findOne?filter=${filter}`).then(res => {
|
||||
if (res && res.data)
|
||||
this.summary = res.data;
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
this.$http.get(`Zones/findOne?${serializedParams}`).then(res => {
|
||||
this.summary = res.data;
|
||||
});
|
||||
}
|
||||
|
||||
getWarehouses() {
|
||||
const params = {
|
||||
filter: {
|
||||
include: {
|
||||
relation: 'warehouse',
|
||||
fields: ['name']
|
||||
}
|
||||
}
|
||||
};
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
this.$http.get(`Zones/${this.zone.id}/warehouses?${serializedParams}`).then(res => {
|
||||
this.zoneWarehouses = res.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
|
||||
|
||||
ngModule.component('vnZoneSummary', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller,
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
import './index';
|
||||
|
||||
describe('component vnZoneSummary', () => {
|
||||
let $element;
|
||||
let $scope;
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $httpParamSerializer;
|
||||
|
||||
beforeEach(ngModule('agency'));
|
||||
|
||||
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
$scope = $rootScope.$new();
|
||||
$element = angular.element(`<vn-zone-summary></vn-zone-summary>`);
|
||||
controller = $componentController('vnZoneSummary', {$element, $scope});
|
||||
}));
|
||||
|
||||
describe('zone setter', () => {
|
||||
it('should set the zone and then call both getSummary() and getWarehouses()', () => {
|
||||
spyOn(controller, 'getSummary');
|
||||
spyOn(controller, 'getWarehouses');
|
||||
|
||||
controller.zone = {id: 1};
|
||||
|
||||
expect(controller.getSummary).toHaveBeenCalledWith();
|
||||
expect(controller.getWarehouses).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSummary()', () => {
|
||||
it('should perform a get and then store data on the controller', () => {
|
||||
controller._zone = {id: 1};
|
||||
let params = {
|
||||
filter: {
|
||||
include: {
|
||||
relation: 'agencyMode',
|
||||
fields: ['name']
|
||||
},
|
||||
where: {
|
||||
id: controller._zone.id
|
||||
}
|
||||
}
|
||||
};
|
||||
const serializedParams = $httpParamSerializer(params);
|
||||
const query = `Zones/findOne?${serializedParams}`;
|
||||
$httpBackend.expectGET(query).respond({id: 1});
|
||||
controller.getSummary();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.summary).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
xdescribe('getEntries()', () => {
|
||||
it('should call the getEntries method to get the entries data', () => {
|
||||
controller._travel = {id: 999};
|
||||
|
||||
const query = `/api/Travels/${controller._travel.id}/getEntries`;
|
||||
$httpBackend.expectGET(query).respond('I am the entries');
|
||||
controller.getEntries();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.entries).toEqual('I am the entries');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -18,8 +18,8 @@ class Controller {
|
|||
this._claim = value;
|
||||
|
||||
// Get DMS on summary load
|
||||
/* if (value)
|
||||
this.$.$applyAsync(() => this.loadDms()); */
|
||||
if (value)
|
||||
this.$.$applyAsync(() => this.loadDms());
|
||||
}
|
||||
|
||||
loadDms() {
|
||||
|
|
Loading…
Reference in New Issue