Bug #422 refactorizar el card de item y añadir el visible y el available

This commit is contained in:
gerard 2018-08-08 14:40:01 +02:00
parent 1468c60a3a
commit 7625f7806b
3 changed files with 11 additions and 88 deletions

View File

@ -3,9 +3,7 @@
<vn-auto class="left-block"> <vn-auto class="left-block">
<vn-item-descriptor <vn-item-descriptor
margin-medium-v margin-medium-v
item="$ctrl.item" item="$ctrl.item">
item-tags="$ctrl.itemTags"
tags="$ctrl.tags">
</vn-item-descriptor> </vn-item-descriptor>
<vn-left-menu></vn-left-menu> <vn-left-menu></vn-left-menu>
</vn-auto> </vn-auto>

View File

@ -1,73 +1,24 @@
import ngModule from '../module'; import ngModule from '../module';
class Controller { class Controller {
constructor($http, $state, $timeout) { constructor($http, $state) {
this.$http = $http; this.$http = $http;
this.$state = $state; this.$state = $state;
this.$timeout = $timeout;
this.item = null; this.item = null;
this.tags = {};
this.itemTags = null;
} }
_getItemTags() { _getCard() {
let filter = { this.$http.get(`/item/api/Items/${this.$state.params.id}/getCard`).then(response => {
where: {itemFk: this.$state.params.id}, this.item = response.data;
order: "priority ASC",
include: {relation: "tag"}
};
this.$http.get(`/item/api/ItemTags?filter=${JSON.stringify(filter)}`).then(response => {
this.itemTags = response.data;
}); });
} }
_getTags() {
this.$http.get(`/item/api/Tags`).then(response => {
response.data.forEach(tag => {
this.tags[tag.id] = Object.assign({}, tag);
});
});
}
_getItem() {
let filter = {
include: [
{relation: "itemType",
scope: {
fields: ['name', 'workerFk', 'warehouseFk'],
include: {
relation: 'worker',
fields: ['firstName', 'name']
}
}
},
{relation: "origin"},
{relation: "ink"},
{relation: "producer"},
{relation: "intrastat"},
{relation: "expence"}
]
};
this.$http.get(`/item/api/Items/${this.$state.params.id}?filter=${JSON.stringify(filter)}`)
.then(res => {
if (res.data && res.data.id) {
this.$timeout(() => {
this.item = res.data;
});
}
}
);
}
$onInit() { $onInit() {
this._getItem(); this._getCard();
this._getTags();
this._getItemTags();
} }
} }
Controller.$inject = ['$http', '$state', '$timeout']; Controller.$inject = ['$http', '$state'];
ngModule.component('vnItemCard', { ngModule.component('vnItemCard', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -23,36 +23,10 @@ describe('Item', () => {
controller = $componentController('vnItemCard', {$state: $state}); controller = $componentController('vnItemCard', {$state: $state});
})); }));
describe('_getItemTags()', () => { describe('_getCard()', () => {
it('should request to get the ItemTags', () => { it('should request to get the card', () => {
$httpBackend.whenGET('/item/api/ItemTags?filter={"where":{"itemFk":123},"order":"priority ASC","include":{"relation":"tag"}}').respond({data: 'data'}); $httpBackend.expectGET('/item/api/Items/123/getCard').respond();
$httpBackend.expectGET('/item/api/ItemTags?filter={"where":{"itemFk":123},"order":"priority ASC","include":{"relation":"tag"}}'); controller._getCard();
controller._getItemTags();
$httpBackend.flush();
});
});
describe('_getTags()', () => {
it('should request to get the Tags and store them in the controller using id as keys', () => {
let response = [{id: 5, name: "Diámetro", isFree: true, sourceTable: null, unit: "mm"}];
let result = {5: {id: 5, name: "Diámetro", isFree: true, sourceTable: null, unit: "mm"}};
expect(controller.tags).toEqual({});
$httpBackend.whenGET('/item/api/Tags').respond(response);
$httpBackend.expectGET('/item/api/Tags');
controller._getTags();
$httpBackend.flush();
expect(controller.tags).toEqual(result);
});
});
describe('_getItem()', () => {
it('should request to get the item', () => {
$httpBackend.whenGET('/item/api/Items/123?filter={"include":[{"relation":"itemType","scope":{"fields":["name","workerFk","warehouseFk"],"include":{"relation":"worker","fields":["firstName","name"]}}},{"relation":"origin"},{"relation":"ink"},{"relation":"producer"},{"relation":"intrastat"},{"relation":"expence"}]}').respond({data: 'item'});
$httpBackend.expectGET('/item/api/Items/123?filter={"include":[{"relation":"itemType","scope":{"fields":["name","workerFk","warehouseFk"],"include":{"relation":"worker","fields":["firstName","name"]}}},{"relation":"origin"},{"relation":"ink"},{"relation":"producer"},{"relation":"intrastat"},{"relation":"expence"}]}');
controller._getItem();
$httpBackend.flush(); $httpBackend.flush();
}); });
}); });