From 9ef3eac480920f92ca8d89eb0e9a66512b211b61 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 28 Feb 2019 13:50:39 +0100 Subject: [PATCH] =?UTF-8?q?#1136=20item.buscador=20Avanzado=20a=C3=B1adir?= =?UTF-8?q?=20campo=20visible=20y=20isActive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/item/back/methods/item/filter.js | 38 +++++++++++++++++-- modules/item/front/fetched-tags/index.html | 37 ++++++++++++++++-- modules/item/front/fetched-tags/index.js | 44 ---------------------- modules/item/front/index/index.js | 12 +++++- modules/item/front/search-panel/index.html | 13 +++++++ 5 files changed, 90 insertions(+), 54 deletions(-) diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index 4f8cbd36e..6a8eac680 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -33,6 +33,16 @@ module.exports = Self => { type: 'Integer', description: 'Type id', http: {source: 'query'} + }, { + arg: 'hasVisible', + type: 'Boolean', + description: 'Whether the the item has o not visible', + http: {source: 'query'} + }, { + arg: 'isActive', + type: 'Boolean', + description: 'Whether the the item is o not active', + http: {source: 'query'} } ], returns: { @@ -45,7 +55,7 @@ module.exports = Self => { } }); - Self.filter = async(ctx, filter, tags) => { + Self.filter = async(ctx, filter) => { let conn = Self.dataSource.connector; let where = buildFilter(ctx.args, (param, value) => { @@ -62,15 +72,23 @@ module.exports = Self => { return {'ic.id': value}; case 'typeFk': return {'t.id': value}; + case 'isActive': + return {'i.isActive': value}; } }); filter = mergeFilters(ctx.args.filter, {where}); - let stmt = new ParameterizedSQL( + let stmts = []; + let stmt; + if (ctx.args.hasVisible === true) + stmts.push('CALL cache.visible_refresh(@visibleCalc, true, 1)'); + + stmt = new ParameterizedSQL( `SELECT i.id, i.image, i.name, i.description, i.size, i.tag5, i.value5, i.tag6, i.value6, - i.tag7, i.value7, i.tag8, i.value8, i.isActive, + i.tag7, i.value7, i.tag8, i.value8, + i.tag9, i.value9, i.tag10, i.value10, i.isActive, t.name type, u.nickname userNickname, t.name type, u.id userId, intr.description AS intrastat, i.stems, @@ -90,6 +108,14 @@ module.exports = Self => { LEFT JOIN vn.buy b ON b.id = lb.buy_id` ); + if (ctx.args.hasVisible === true) { + let joinAvailable = new ParameterizedSQL( + `JOIN cache.visible v + ON v.item_id = i.id AND v.calc_id = @visibleCalc` + ); + stmt.merge(joinAvailable); + } + if (ctx.args.tags) { let i = 1; for (let tag of ctx.args.tags) { @@ -104,6 +130,10 @@ module.exports = Self => { } } stmt.merge(conn.makeSuffix(filter)); - return Self.rawStmt(stmt); + let itemsIndex = stmts.push(stmt) - 1; + + let sql = ParameterizedSQL.join(stmts, ';'); + let result = await conn.executeStmt(sql); + return itemsIndex === 0 ? result : result[itemsIndex]; }; }; diff --git a/modules/item/front/fetched-tags/index.html b/modules/item/front/fetched-tags/index.html index 546e5d67d..818296a80 100644 --- a/modules/item/front/fetched-tags/index.html +++ b/modules/item/front/fetched-tags/index.html @@ -3,10 +3,39 @@
- {{::fetchedTag.value}} + ng-class="::{empty: !$ctrl.item.value5}" + title="{{::$ctrl.item.tag5}}: {{::$ctrl.item.value5}}"> + {{::$ctrl.item.value5}} +
+
+ {{::$ctrl.item.value6}} +
+
+ {{::$ctrl.item.value7}} +
+
+ {{::$ctrl.item.value8}} +
+
+ {{::$ctrl.item.value9}} +
+
+ {{::$ctrl.item.value10}}
\ No newline at end of file diff --git a/modules/item/front/fetched-tags/index.js b/modules/item/front/fetched-tags/index.js index 508764c9e..8774fc4b0 100644 --- a/modules/item/front/fetched-tags/index.js +++ b/modules/item/front/fetched-tags/index.js @@ -1,52 +1,8 @@ import ngModule from '../module'; import './style.scss'; -export default class FetchedTags { - set item(value) { - if (value) { - let tags = []; - for (let i = 5; i < 5 + this.maxLength; i++) { - if (value['tag' + i]) { - let tagValue = value['value' + i]; - let tagKey = value['tag' + i]; - tags.push({name: tagKey, value: tagValue, position: i - 5}); - } - } - this.tags = tags; - } - this._item = value; - } - - get item() { - return this._item; - } - - set tags(value) { - if (value) { - let organizedTags = new Array(parseInt(this.maxLength)); - for (let i = 0; i < this.maxLength; i++) { - let organizedTag = {}; - for (let j = 0; j < value.length; j++) { - if (value[j].position === i) { - organizedTag.name = value[j].name; - organizedTag.value = value[j].value; - } - organizedTags[i] = JSON.parse(JSON.stringify(organizedTag)); - } - } - this._tags = organizedTags; - } - } - - get tags() { - return this._tags; - } -} - - ngModule.component('vnFetchedTags', { template: require('./index.html'), - controller: FetchedTags, bindings: { maxLength: '<', item: '<', diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js index 7a5adc600..e31cbaa08 100644 --- a/modules/item/front/index/index.js +++ b/modules/item/front/index/index.js @@ -2,7 +2,7 @@ import ngModule from '../module'; import './style.scss'; class Controller { - constructor($http, $state, $scope) { + constructor($http, $state, $scope, $stateParams) { this.$http = $http; this.$state = $state; this.$ = $scope; @@ -13,6 +13,14 @@ class Controller { id: false, actions: false }; + + if (!$stateParams.q) + this.filter = {hasVisible: true, isActive: true}; + } + + $postLink() { + if (this.filter) + this.onSearch(this.filter); } stopEvent(event) { @@ -83,7 +91,7 @@ class Controller { this.$.preview.show(); } } -Controller.$inject = ['$http', '$state', '$scope']; +Controller.$inject = ['$http', '$state', '$scope', '$stateParams']; ngModule.component('vnItemIndex', { template: require('./index.html'), diff --git a/modules/item/front/search-panel/index.html b/modules/item/front/search-panel/index.html index abbb56627..e3cb1f3d2 100644 --- a/modules/item/front/search-panel/index.html +++ b/modules/item/front/search-panel/index.html @@ -47,6 +47,19 @@ model="filter.description"> + + + + + +