From 7625f7806bd4cbee2221b18071a1f943d13ee9a9 Mon Sep 17 00:00:00 2001 From: gerard Date: Wed, 8 Aug 2018 14:40:01 +0200 Subject: [PATCH] =?UTF-8?q?Bug=20#422=20refactorizar=20el=20card=20de=20it?= =?UTF-8?q?em=20y=20a=C3=B1adir=20el=20visible=20y=20el=20available?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/item/src/card/index.html | 4 +- client/item/src/card/index.js | 61 +++--------------------------- client/item/src/card/index.spec.js | 34 ++--------------- 3 files changed, 11 insertions(+), 88 deletions(-) diff --git a/client/item/src/card/index.html b/client/item/src/card/index.html index 40d69c8b3..c3411e2d7 100644 --- a/client/item/src/card/index.html +++ b/client/item/src/card/index.html @@ -3,9 +3,7 @@ + item="$ctrl.item"> diff --git a/client/item/src/card/index.js b/client/item/src/card/index.js index 440c498b8..0be6be0f0 100644 --- a/client/item/src/card/index.js +++ b/client/item/src/card/index.js @@ -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'), diff --git a/client/item/src/card/index.spec.js b/client/item/src/card/index.spec.js index 0c3970294..2e654661d 100644 --- a/client/item/src/card/index.spec.js +++ b/client/item/src/card/index.spec.js @@ -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(); }); });