From 971a2ab8913edaf7916c3cf85c56449210717cd0 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 3 Apr 2019 15:16:32 +0200 Subject: [PATCH] #1270 ticket.index advanced search mostrar dias en el futuro --- db/install/changes/00-ticketConfig.sql | 5 ++ db/install/dump/fixtures.sql | 5 ++ front/core/components/searchbar/searchbar.js | 2 +- .../components/searchbar/searchbar.spec.js | 4 +- modules/ticket/back/model-config.json | 3 + modules/ticket/back/models/sale.json | 6 +- modules/ticket/back/models/ticket-config.json | 19 +++++ modules/ticket/front/index/index.html | 1 + modules/ticket/front/index/index.js | 57 +++++++++----- modules/ticket/front/search-panel/index.html | 76 ++++++++++--------- .../ticket/front/search-panel/locale/es.yml | 3 +- 11 files changed, 118 insertions(+), 63 deletions(-) create mode 100644 db/install/changes/00-ticketConfig.sql create mode 100644 modules/ticket/back/models/ticket-config.json diff --git a/db/install/changes/00-ticketConfig.sql b/db/install/changes/00-ticketConfig.sql new file mode 100644 index 000000000..f4f7d6e94 --- /dev/null +++ b/db/install/changes/00-ticketConfig.sql @@ -0,0 +1,5 @@ +DROP TABLE IF EXISTS `vn`.`ticketConfig`; + +CREATE TABLE `vn`.`ticketConfig` (`id` INT NOT NULL AUTO_INCREMENT, `scopeDays` TINYINT(3) NULL, PRIMARY KEY (`id`)); + +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('TicketConfig', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/install/dump/fixtures.sql b/db/install/dump/fixtures.sql index 32c904bce..8cba0ade1 100644 --- a/db/install/dump/fixtures.sql +++ b/db/install/dump/fixtures.sql @@ -6,6 +6,10 @@ ALTER TABLE `vn2008`.`Consignatarios` AUTO_INCREMENT = 1; INSERT INTO `util`.`config` ( `dbVersion`, `hasTriggersDisabled`, `environment`) VALUES ('1.0.0', '0', 'development'); +INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`) + VALUES + ('1', '6'); + INSERT INTO `account`.`mailConfig` (`id`, `domain`) VALUES ('1', 'verdnatura.es'); @@ -1318,3 +1322,4 @@ INSERT INTO `postgresql`.`calendar_employee` (`business_id`, `calendar_state_id` (107, 2, DATE_ADD(CURDATE(), INTERVAL -10 DAY)), (107, 1, DATE_ADD(CURDATE(), INTERVAL -12 DAY)), (107, 2, DATE_ADD(CURDATE(), INTERVAL -20 DAY)); + diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index f5ead38a4..ed9f34899 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -38,7 +38,7 @@ export default class Controller extends Component { set filter(value) { this._filter = value; - this.$state.go('.', {q: JSON.stringify(value)}); + this.$state.go('.', {q: JSON.stringify(value)}, {location: 'replace'}); } get filter() { diff --git a/front/core/components/searchbar/searchbar.spec.js b/front/core/components/searchbar/searchbar.spec.js index 9e28d0a98..eae9c5be9 100644 --- a/front/core/components/searchbar/searchbar.spec.js +++ b/front/core/components/searchbar/searchbar.spec.js @@ -35,13 +35,13 @@ describe('Component vnSearchbar', () => { }); describe('filter() setter', () => { - it(`should call $state.go()`, () => { + it(`should call $state.go() to replace the current state location instead of creating a new one`, () => { controller._filter = {}; spyOn(controller.$state, 'go'); controller.filter = {expected: 'filter'}; expect(controller._filter).toEqual(controller.filter); - expect(controller.$state.go).toHaveBeenCalledWith('.', Object({q: '{"expected":"filter"}'})); + expect(controller.$state.go).toHaveBeenCalledWith('.', Object({q: '{"expected":"filter"}'}), Object({location: 'replace'})); }); }); diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 22c750a4f..06ba9bd45 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -64,5 +64,8 @@ }, "TicketWeekly": { "dataSource": "vn" + }, + "TicketConfig": { + "dataSource": "vn" } } diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index 44b7c2b9c..17a8c604e 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -8,9 +8,9 @@ }, "properties": { "id": { - "id": true, - "type": "Number", - "description": "Identifier" + "id": true, + "type": "Number", + "description": "Identifier" }, "concept": { "type": "String" diff --git a/modules/ticket/back/models/ticket-config.json b/modules/ticket/back/models/ticket-config.json new file mode 100644 index 000000000..ff6818bb5 --- /dev/null +++ b/modules/ticket/back/models/ticket-config.json @@ -0,0 +1,19 @@ +{ + "name": "TicketConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "ticketConfig" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "scopeDays": { + "type": "Number" + } + } +} diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index 249baf815..70aabd729 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -11,6 +11,7 @@ { + if (res.data) { + this.filter = { + scopeDays: res.data.scopeDays + }; + } + }); + } + + buildFilterDates() { + let today = new Date(); + this.today = today.setHours(0, 0, 0, 0); + + let buildDate = new Date(today); + buildDate.setDate(today.getDate() + this.scopeDays); + buildDate.setHours(23, 59, 59, 999); + + this.daysOnward = buildDate; + } + + defaultFilter() { + this.buildFilterDates(); + this.$scope.ticketSearchbar.filter = Object.assign({}, {mine: true, from: this.today, to: this.daysOnward}); } onSearch(params) { - if (params) + if (params) { + if (params.scopeDays) { + this.scopeDays = params.scopeDays; + this.buildFilterDates(); + params = Object.assign(params, {from: this.today, to: this.daysOnward}); + } + this.$.model.applyFilter(null, params); - else + } else this.$.model.clear(); } @@ -111,7 +128,7 @@ export default class Controller { } } -Controller.$inject = ['$scope', '$state', '$stateParams', '$translate']; +Controller.$inject = ['$scope', '$state', '$stateParams', '$translate', '$http']; ngModule.component('vnTicketIndex', { template: require('./index.html'), diff --git a/modules/ticket/front/search-panel/index.html b/modules/ticket/front/search-panel/index.html index 2cbad130d..35802bc7c 100644 --- a/modules/ticket/front/search-panel/index.html +++ b/modules/ticket/front/search-panel/index.html @@ -11,31 +11,19 @@ + label="Client id" + model="filter.clientFk"> - - + label="Order id" + model="filter.orderFk"> - - {{firstName}} {{name}} - + + + + + + + + {{firstName}} {{name}} + + + - - - - - - - - - - + +