From 1c51d34f7dadf8be45df34dc870776900fef15c4 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Wed, 20 Oct 2021 14:40:08 +0200 Subject: [PATCH] feat(monitors): added auto-refresh feature to ticket monitors --- modules/monitor/front/index/index.html | 2 +- modules/monitor/front/index/index.js | 15 +++++++- modules/monitor/front/index/index.spec.js | 38 +++++++++++++++++++ modules/monitor/front/index/locale/es.yml | 4 +- .../monitor/front/index/tickets/index.html | 5 +++ modules/monitor/front/index/tickets/index.js | 9 +++++ 6 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 modules/monitor/front/index/index.spec.js diff --git a/modules/monitor/front/index/index.html b/modules/monitor/front/index/index.html index 7b393e722..85987ac20 100644 --- a/modules/monitor/front/index/index.html +++ b/modules/monitor/front/index/index.html @@ -1,4 +1,4 @@ - + diff --git a/modules/monitor/front/index/index.js b/modules/monitor/front/index/index.js index 2e1b3b1a1..72ca9dae9 100644 --- a/modules/monitor/front/index/index.js +++ b/modules/monitor/front/index/index.js @@ -3,14 +3,25 @@ import Section from 'salix/components/section'; import './style.scss'; export default class Controller extends Section { + constructor($element, $) { + super($element, $); + + const isTopPanelHidden = localStorage.getItem('ticketTopPanelHidden'); + if (isTopPanelHidden === 'true') + this.isTopPanelHidden = true; + } + toggle() { const monitor = this.element.querySelector('vn-horizontal'); const isHidden = monitor.classList.contains('hidden'); - if (!isHidden) + if (!isHidden) { monitor.classList.add('hidden'); - else + localStorage.setItem('ticketTopPanelHidden', true); + } else { monitor.classList.remove('hidden'); + localStorage.setItem('ticketTopPanelHidden', false); + } } } diff --git a/modules/monitor/front/index/index.spec.js b/modules/monitor/front/index/index.spec.js new file mode 100644 index 000000000..506e75720 --- /dev/null +++ b/modules/monitor/front/index/index.spec.js @@ -0,0 +1,38 @@ +import './index.js'; +describe('Component vnMonitorIndex', () => { + let controller; + let $element; + + beforeEach(ngModule('monitor')); + + beforeEach(inject(($compile, $rootScope) => { + $element = $compile('')($rootScope); + controller = $element.controller('vnMonitorIndex'); + })); + + describe('toggle()', () => { + it('should add the hidden class to the horizontal contaning the panel to hide', () => { + controller.toggle(); + + const targetElement = $element[0].querySelector('vn-horizontal'); + const firstClass = targetElement.classList[0]; + + const isTopPanelHidden = localStorage.getItem('ticketTopPanelHidden'); + + expect(firstClass).toEqual('hidden'); + expect(isTopPanelHidden).toEqual('true'); + }); + + it('should remove the hidden class to the horizontal contaning the panel to hide', () => { + const targetElement = $element[0].querySelector('vn-horizontal'); + targetElement.classList.add('hidden'); + controller.toggle(); + const firstClass = targetElement.classList[0]; + + const isTopPanelHidden = localStorage.getItem('ticketTopPanelHidden'); + + expect(firstClass).toBeUndefined(); + expect(isTopPanelHidden).toEqual('false'); + }); + }); +}); diff --git a/modules/monitor/front/index/locale/es.yml b/modules/monitor/front/index/locale/es.yml index 4eef3c93f..b17861e9f 100644 --- a/modules/monitor/front/index/locale/es.yml +++ b/modules/monitor/front/index/locale/es.yml @@ -8,4 +8,6 @@ Component lack: Faltan componentes Minimize/Maximize: Minimizar/Maximizar Problems: Problemas Theoretical: Teórica -Practical: Práctica \ No newline at end of file +Practical: Práctica +Auto-refresh: Auto-refresco +Toggle auto-refresh every 2 minutes: Conmuta el refresco automático cada 2 minutos \ 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 4a166d51a..04f7f339f 100644 --- a/modules/monitor/front/index/tickets/index.html +++ b/modules/monitor/front/index/tickets/index.html @@ -21,6 +21,11 @@ Tickets monitor + + this.$.model.refresh(), 120000); + else { + clearInterval(this.refreshTimer); + this.refreshTimer = null; + } + } } ngModule.vnComponent('vnMonitorSalesTickets', { -- 2.40.1