From 10387ee40b260ff10720eb1f17bf67c536dc56e2 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 18 May 2021 08:41:36 +0200 Subject: [PATCH 1/5] #2913, #2914 - Changes to sales monitors --- front/core/components/table/style.scss | 15 +++++- .../methods/sales-monitor/deleteOrders.js | 47 +++++++++++++++++ .../sales-monitor/specs/deleteOrders.spec.js | 21 ++++++++ modules/monitor/back/models/sales-monitor.js | 1 + .../monitor/front/index/clients/index.html | 5 +- modules/monitor/front/index/index.html | 4 +- modules/monitor/front/index/locale/es.yml | 4 +- modules/monitor/front/index/orders/index.html | 34 +++++++++++-- modules/monitor/front/index/orders/index.js | 26 +++++++++- .../monitor/front/index/orders/index.spec.js | 50 +++++++++++++++++++ modules/monitor/front/index/orders/style.scss | 22 ++++---- modules/monitor/front/index/style.scss | 5 ++ .../monitor/front/index/tickets/index.html | 8 ++- 13 files changed, 214 insertions(+), 28 deletions(-) create mode 100644 modules/monitor/back/methods/sales-monitor/deleteOrders.js create mode 100644 modules/monitor/back/methods/sales-monitor/specs/deleteOrders.spec.js create mode 100644 modules/monitor/front/index/orders/index.spec.js diff --git a/front/core/components/table/style.scss b/front/core/components/table/style.scss index 258061f1b..7da20fe82 100644 --- a/front/core/components/table/style.scss +++ b/front/core/components/table/style.scss @@ -25,10 +25,12 @@ vn-table { } } & > vn-tbody, + & > a.vn-tbody, & > tbody { display: table-row-group; } - & > vn-tfoot, + & > vn-tfoot, + & > .vn-tfoot, & > tfoot { border-top: 2px solid $color-spacer; display: table-footer-group @@ -39,7 +41,9 @@ vn-table { display: table-row; height: 48px; } - vn-thead, vn-tbody, vn-tfoot, + vn-thead, .vn-thead, + vn-tbody, .vn-tbody, + vn-tfoot, .vn-tfoot, thead, tbody, tfoot { & > * { display: table-row; @@ -126,7 +130,13 @@ vn-table { color: inherit; } } + a.vn-tbody { + &.clickable { + @extend %clickable; + } + } vn-tbody > *, + .vn-tbody > *, tbody > * { border-bottom: 1px solid $color-spacer-light; @@ -206,6 +216,7 @@ vn-table.scrollable > .vn-table, border-bottom: 2px solid $color-spacer; background-color: #FFF; position: sticky; + z-index: 9; top: 0 } } diff --git a/modules/monitor/back/methods/sales-monitor/deleteOrders.js b/modules/monitor/back/methods/sales-monitor/deleteOrders.js new file mode 100644 index 000000000..9b15f75e5 --- /dev/null +++ b/modules/monitor/back/methods/sales-monitor/deleteOrders.js @@ -0,0 +1,47 @@ +module.exports = Self => { + Self.remoteMethod('deleteOrders', { + description: 'Deletes the selected orders', + accessType: 'WRITE', + accepts: [{ + arg: 'deletes', + type: ['number'], + required: true, + description: 'The order ids to delete' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/deleteOrders`, + verb: 'POST' + } + }); + + Self.deleteOrders = async(deletes, options) => { + const models = Self.app.models; + + let tx; + let myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const deleted = models.Order.destroyAll({ + id: {inq: deletes} + }, myOptions); + + if (tx) await tx.commit(); + return deleted; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/monitor/back/methods/sales-monitor/specs/deleteOrders.spec.js b/modules/monitor/back/methods/sales-monitor/specs/deleteOrders.spec.js new file mode 100644 index 000000000..70394d082 --- /dev/null +++ b/modules/monitor/back/methods/sales-monitor/specs/deleteOrders.spec.js @@ -0,0 +1,21 @@ +const app = require('vn-loopback/server/server'); + +describe('SalesMonitor deleteOrders()', () => { + it('should return the deleted orders', async() => { + const tx = await app.models.Order.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const deletes = [1, 2]; + const result = await app.models.SalesMonitor.deleteOrders(deletes, options); + + expect(result.count).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/monitor/back/models/sales-monitor.js b/modules/monitor/back/models/sales-monitor.js index 63479cb9a..2750156de 100644 --- a/modules/monitor/back/models/sales-monitor.js +++ b/modules/monitor/back/models/sales-monitor.js @@ -2,4 +2,5 @@ module.exports = Self => { require('../methods/sales-monitor/salesFilter')(Self); require('../methods/sales-monitor/clientsFilter')(Self); require('../methods/sales-monitor/ordersFilter')(Self); + require('../methods/sales-monitor/deleteOrders')(Self); }; diff --git a/modules/monitor/front/index/clients/index.html b/modules/monitor/front/index/clients/index.html index bfa496199..f0c1b8f93 100644 --- a/modules/monitor/front/index/clients/index.html +++ b/modules/monitor/front/index/clients/index.html @@ -1,8 +1,9 @@ - + order="dated DESC" + auto-load="true"> diff --git a/modules/monitor/front/index/index.html b/modules/monitor/front/index/index.html index 937464891..e37dbd270 100644 --- a/modules/monitor/front/index/index.html +++ b/modules/monitor/front/index/index.html @@ -3,10 +3,8 @@ - - - + diff --git a/modules/monitor/front/index/locale/es.yml b/modules/monitor/front/index/locale/es.yml index b709d0922..1f69de222 100644 --- a/modules/monitor/front/index/locale/es.yml +++ b/modules/monitor/front/index/locale/es.yml @@ -1,4 +1,6 @@ Tickets monitor: Monitor de tickets Clients on website: Clientes activos en la web Recent order actions: Acciones recientes en pedidos -Search tickets: Buscar tickets \ No newline at end of file +Search tickets: Buscar tickets +Delete selected elements: Eliminar los elementos seleccionados +All the selected elements will be deleted. Are you sure you want to continue?: Todos los elementos seleccionados serán eliminados. ¿Seguro que quieres continuar? \ No newline at end of file diff --git a/modules/monitor/front/index/orders/index.html b/modules/monitor/front/index/orders/index.html index 9bb4d3608..3dd510dc8 100644 --- a/modules/monitor/front/index/orders/index.html +++ b/modules/monitor/front/index/orders/index.html @@ -9,6 +9,12 @@ Recent order actions + + - + + + + + Date Client Import - + + + + + {{::order.date_send | date: 'dd/MM/yyyy'}} @@ -42,7 +61,8 @@ {{::order.import | currency: 'EUR':2}} - + + {{::order.date_make | date: 'dd/MM/yyyy HH:mm'}} @@ -62,7 +82,7 @@ - +
+ + \ No newline at end of file diff --git a/modules/monitor/front/index/orders/index.js b/modules/monitor/front/index/orders/index.js index 0a4c8c04f..8b9489a9d 100644 --- a/modules/monitor/front/index/orders/index.js +++ b/modules/monitor/front/index/orders/index.js @@ -2,7 +2,31 @@ import ngModule from '../../module'; import Section from 'salix/components/section'; import './style.scss'; +export default class Controller extends Section { + get checked() { + const rows = this.$.model.data || []; + const checkedRows = []; + for (let row of rows) { + if (row.checked) + checkedRows.push(row.id); + } + + return checkedRows; + } + + get totalChecked() { + return this.checked.length; + } + + onDelete() { + const params = {deletes: this.checked}; + const query = `SalesMonitors/deleteOrders`; + this.$http.post(query, params).then( + () => this.$.model.refresh()); + } +} + ngModule.vnComponent('vnMonitorSalesOrders', { template: require('./index.html'), - controller: Section + controller: Controller }); diff --git a/modules/monitor/front/index/orders/index.spec.js b/modules/monitor/front/index/orders/index.spec.js new file mode 100644 index 000000000..109925358 --- /dev/null +++ b/modules/monitor/front/index/orders/index.spec.js @@ -0,0 +1,50 @@ +import './index.js'; +import crudModel from 'core/mocks/crud-model'; + +describe('Component vnMonitorSalesOrders', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('monitor')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + const $element = angular.element(''); + controller = $componentController('vnMonitorSalesOrders', {$element}); + controller.$.model = crudModel; + controller.$.model.data = [ + {id: 1, name: 'My item 1'}, + {id: 2, name: 'My item 2'}, + {id: 3, name: 'My item 3'} + ]; + })); + + describe('checked() getter', () => { + it('should return a the selected rows', () => { + const modelData = controller.$.model.data; + modelData[0].checked = true; + modelData[1].checked = true; + + const result = controller.checked; + + expect(result).toEqual(expect.arrayContaining([1, 2])); + }); + }); + + describe('onDelete()', () => { + it('should make a query and then call to the model refresh() method', () => { + jest.spyOn(controller.$.model, 'refresh'); + + const modelData = controller.$.model.data; + modelData[0].checked = true; + modelData[1].checked = true; + + const expectedParams = {deletes: [1, 2]}; + $httpBackend.expect('POST', 'SalesMonitors/deleteOrders', expectedParams).respond(200); + controller.onDelete(); + $httpBackend.flush(); + + expect(controller.$.model.refresh).toHaveBeenCalledWith(); + }); + }); +}); diff --git a/modules/monitor/front/index/orders/style.scss b/modules/monitor/front/index/orders/style.scss index 5f80472fe..f4d56010c 100644 --- a/modules/monitor/front/index/orders/style.scss +++ b/modules/monitor/front/index/orders/style.scss @@ -1,16 +1,18 @@ @import "variables"; vn-monitor-sales-orders { - .dark-row { - background-color: lighten($color-marginal, 15%); - color: gray; - - vn-td { - border-bottom: 2px solid $color-marginal + vn-table.scrollable { + height: 350px + } + + vn-table a.vn-tbody { + & > vn-tr:nth-child(2) { + color: gray; + + & > vn-td { + border-bottom: 2px solid $color-marginal; + font-size: 13px; + } } } - - vn-tbody vn-tr:nth-child(3) { - height: inherit - } } \ No newline at end of file diff --git a/modules/monitor/front/index/style.scss b/modules/monitor/front/index/style.scss index 4e0d9df2f..0cadc88db 100644 --- a/modules/monitor/front/index/style.scss +++ b/modules/monitor/front/index/style.scss @@ -17,4 +17,9 @@ vn-monitor-index { color: $color-font-secondary; text-align: center; } + + vn-vertical { + position: fixed; + width: 400px + } } \ No newline at end of file diff --git a/modules/monitor/front/index/tickets/index.html b/modules/monitor/front/index/tickets/index.html index 8fc3e09d9..e410be4e5 100644 --- a/modules/monitor/front/index/tickets/index.html +++ b/modules/monitor/front/index/tickets/index.html @@ -30,7 +30,7 @@ - + @@ -49,7 +49,7 @@ + ui-sref="ticket.card.summary({id: {{::ticket.id}}})" target="_blank"> + class="vn-pt-xs"> Date: Tue, 18 May 2021 09:12:47 +0200 Subject: [PATCH 2/5] Responsive --- modules/monitor/front/index/style.scss | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/modules/monitor/front/index/style.scss b/modules/monitor/front/index/style.scss index 0cadc88db..c020f60c7 100644 --- a/modules/monitor/front/index/style.scss +++ b/modules/monitor/front/index/style.scss @@ -22,4 +22,35 @@ vn-monitor-index { position: fixed; width: 400px } + + vn-horizontal { + flex-wrap: wrap + } +} + +@media (max-width:1500px) { + vn-monitor-index { + & > vn-horizontal { + flex-direction: column-reverse; + } + + & > vn-horizontal > vn-one { + flex: none; + width: 100%; + + & > vn-vertical { + position: initial; + flex-direction: row; + width: 100%; + + vn-monitor-sales-clients { + margin-right: 15px + } + + vn-table.scrollable { + height: 300px + } + } + } + } } \ No newline at end of file From 5d278f416f4bd5b9d7f9a255c7fd0a082c0bc38b Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 18 May 2021 10:04:01 +0200 Subject: [PATCH 3/5] Removed transaction block --- modules/monitor/back/methods/sales-monitor/deleteOrders.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/monitor/back/methods/sales-monitor/deleteOrders.js b/modules/monitor/back/methods/sales-monitor/deleteOrders.js index 9b15f75e5..11fbf2c35 100644 --- a/modules/monitor/back/methods/sales-monitor/deleteOrders.js +++ b/modules/monitor/back/methods/sales-monitor/deleteOrders.js @@ -27,11 +27,6 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - try { const deleted = models.Order.destroyAll({ id: {inq: deletes} From 400bf7b4f28b9141962bf5b0c49ce2b878a77b76 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 18 May 2021 10:05:13 +0200 Subject: [PATCH 4/5] Changes --- .../back/methods/sales-monitor/deleteOrders.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/modules/monitor/back/methods/sales-monitor/deleteOrders.js b/modules/monitor/back/methods/sales-monitor/deleteOrders.js index 11fbf2c35..15a8d862a 100644 --- a/modules/monitor/back/methods/sales-monitor/deleteOrders.js +++ b/modules/monitor/back/methods/sales-monitor/deleteOrders.js @@ -21,22 +21,13 @@ module.exports = Self => { Self.deleteOrders = async(deletes, options) => { const models = Self.app.models; - let tx; let myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - try { - const deleted = models.Order.destroyAll({ - id: {inq: deletes} - }, myOptions); - - if (tx) await tx.commit(); - return deleted; - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } + return models.Order.destroyAll({ + id: {inq: deletes} + }, myOptions); }; }; From ce96e92389f521c75997d706d35b40b9865f8748 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 18 May 2021 10:20:15 +0200 Subject: [PATCH 5/5] Updated z-index --- front/core/components/scroll-up/style.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/front/core/components/scroll-up/style.scss b/front/core/components/scroll-up/style.scss index 5f316e58c..c6dae16ef 100644 --- a/front/core/components/scroll-up/style.scss +++ b/front/core/components/scroll-up/style.scss @@ -6,4 +6,5 @@ vn-scroll-up { margin: $float-spacing; display: none; position: fixed; + z-index: 10 } \ No newline at end of file