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-item-descriptor
margin-medium-v
item="$ctrl.item"
item-tags="$ctrl.itemTags"
tags="$ctrl.tags">
item="$ctrl.item">
</vn-item-descriptor>
<vn-left-menu></vn-left-menu>
</vn-auto>

View File

@ -1,73 +1,24 @@
import ngModule from '../module';
class Controller {
constructor($http, $state, $timeout) {
constructor($http, $state) {
this.$http = $http;
this.$state = $state;
this.$timeout = $timeout;
this.item = null;
this.tags = {};
this.itemTags = null;
}
_getItemTags() {
let filter = {
where: {itemFk: this.$state.params.id},
order: "priority ASC",
include: {relation: "tag"}
};
this.$http.get(`/item/api/ItemTags?filter=${JSON.stringify(filter)}`).then(response => {
this.itemTags = response.data;
_getCard() {
this.$http.get(`/item/api/Items/${this.$state.params.id}/getCard`).then(response => {
this.item = 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() {
this._getItem();
this._getTags();
this._getItemTags();
this._getCard();
}
}
Controller.$inject = ['$http', '$state', '$timeout'];
Controller.$inject = ['$http', '$state'];
ngModule.component('vnItemCard', {
template: require('./index.html'),

View File

@ -23,36 +23,10 @@ describe('Item', () => {
controller = $componentController('vnItemCard', {$state: $state});
}));
describe('_getItemTags()', () => {
it('should request to get the ItemTags', () => {
$httpBackend.whenGET('/item/api/ItemTags?filter={"where":{"itemFk":123},"order":"priority ASC","include":{"relation":"tag"}}').respond({data: 'data'});
$httpBackend.expectGET('/item/api/ItemTags?filter={"where":{"itemFk":123},"order":"priority ASC","include":{"relation":"tag"}}');
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();
describe('_getCard()', () => {
it('should request to get the card', () => {
$httpBackend.expectGET('/item/api/Items/123/getCard').respond();
controller._getCard();
$httpBackend.flush();
});
});