From 40a6a4d37a0fc4692f32ea7b4cf07af73d597191 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Tue, 31 Aug 2021 16:44:03 +0100 Subject: [PATCH 1/5] reduz repeated code --- src/app/pages/agenda/agenda.page.ts | 32 +++--- src/app/services/ageanda/list-box.service.ts | 106 ++++++------------- 2 files changed, 49 insertions(+), 89 deletions(-) diff --git a/src/app/pages/agenda/agenda.page.ts b/src/app/pages/agenda/agenda.page.ts index 6af359567..eb2b3f70c 100644 --- a/src/app/pages/agenda/agenda.page.ts +++ b/src/app/pages/agenda/agenda.page.ts @@ -464,7 +464,7 @@ export class AgendaPage implements OnInit { // loop this.calendarService.pushEvent(response, 'md'); - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {}) this.myCal.update(); this.myCal.loadEvents(); @@ -485,7 +485,7 @@ export class AgendaPage implements OnInit { // calendar this.calendarService.pushEvent(response, 'pr'); - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {}) this.myCal.update(); this.myCal.loadEvents(); @@ -511,7 +511,7 @@ export class AgendaPage implements OnInit { this.calendarService.pushEvent(response, 'pr'); - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {}) this.myCal.update(); @@ -539,7 +539,7 @@ export class AgendaPage implements OnInit { this.calendarService.pushEvent(eventsList, 'md'); - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {}) this.myCal.update(); this.myCal.loadEvents(); @@ -553,17 +553,13 @@ export class AgendaPage implements OnInit { } else{ this.eventService.getAllPrEvents(momentG(new Date(startTime),'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime),'yyyy-MM-dd 23:59:59')).then((response:any) => { - //this.eventSource=[]; - // clear the current month only this.calendarService.removeRange(startTime, endTime, 'pr') const eventsList = response.filter(data => data.CalendarName == "Pessoal"); this.calendarService.pushEvent(eventsList, 'pr'); - - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date') - + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {}) this.myCal.update(); this.myCal.loadEvents(); @@ -592,7 +588,7 @@ export class AgendaPage implements OnInit { this.calendarService.pushEvent(eventsList, 'md'); - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {}) this.myCal.update(); this.myCal.loadEvents(); @@ -614,7 +610,7 @@ export class AgendaPage implements OnInit { this.calendarService.pushEvent(eventsList, 'pr'); - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {}) this.myCal.update(); this.myCal.loadEvents(); @@ -645,7 +641,7 @@ export class AgendaPage implements OnInit { // loop this.calendarService.pushEvent(eventsList, 'md'); - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {}) this.myCal.update(); this.myCal.loadEvents(); @@ -674,7 +670,7 @@ export class AgendaPage implements OnInit { this.calendarService.pushEvent(eventsList, 'pr'); - this.TimelinePRList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelinePRList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {}) this.myCal.update(); this.myCal.loadEvents(); @@ -712,7 +708,7 @@ export class AgendaPage implements OnInit { this.calendarService.pushEvent(eventsList, 'pr'); - this.TimelinePRList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelinePRList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {}) this.myCal.update(); @@ -739,8 +735,8 @@ export class AgendaPage implements OnInit { updateEventListBox() { - this.TimelinePRList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date') - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelinePRList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {}) + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {}) } @@ -939,13 +935,13 @@ export class AgendaPage implements OnInit { if(this.profile == "mdgpr") { this.profile ="pr"; this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate); - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, {}) } else { this.profile ="mdgpr"; this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate); - this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, 'date') + this.TimelineMDList = this.listBoxService.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, {}) } } diff --git a/src/app/services/ageanda/list-box.service.ts b/src/app/services/ageanda/list-box.service.ts index c514470e8..6e5458ae2 100644 --- a/src/app/services/ageanda/list-box.service.ts +++ b/src/app/services/ageanda/list-box.service.ts @@ -28,7 +28,7 @@ export class ListBoxService { daysBetween(){ } - list(eventSource: EventListStore[], profile: 'md' | 'pr' | 'all', rangeStartDate, randEndDate, calendarDate) { + list(eventSource: EventListStore[], profile: 'md' | 'pr' | 'all', rangeStartDate, randEndDate, {segment = 'todo'}) { console.log('eventSource: EventListStore[]',eventSource) @@ -71,8 +71,7 @@ export class ListBoxService { days[day] = [] } - if (new Date(startDate).toLocaleDateString() != new Date(endDate).toLocaleDateString()) { - + if (this.dateService.notSameDate(startDate, endDate)) { const diffDays = this.dateService.deferenceBetweenDays(endDate, startDate) @@ -80,27 +79,8 @@ export class ListBoxService { if (diffDays >= 1) { - const StartEvent = Object.assign({}, { - title: event.event.Subject, - start: event.start, - end: event.end, - color: event.color, - id: event.id, - index: event.index, - CalendarName: event.CalendarName, - event: { - Subject: event.event.Subject, - StartDate: event.event.StartDate, - EndDate: event.event.EndDate, - Location: event.event.Location, - EventId: event.event.EventId, - CalendarName: event.event.CalendarName - }, - startMany: true, - endMany: false, - middle: false - }) - + const StartEvent = this.transForm(event, {startMany: true,endMany: false, middle: false}) + days[day].push(StartEvent) let i = 1; @@ -126,53 +106,12 @@ export class ListBoxService { startDate.getDate() != endDate.getDate())) { // last push - const EndEvent = Object.assign({}, { - title: event.event.Subject, - start: event.start, - end: event.end, - color: event.color, - id: event.id, - index: event.index, - CalendarName: event.CalendarName, - event: { - Subject: event.event.Subject, - StartDate: event.event.StartDate, - EndDate: event.event.EndDate, - Location: event.event.Location, - EventId: event.event.EventId, - CalendarName: event.event.CalendarName - }, - Subject: event.event.Subject, - startMany: false, - endMany: true, - middle: false - }) - + const EndEvent = this.transForm(event, {startMany: false,endMany: true, middle: false}) days[otherDays].push(EndEvent) } else { - const EndEvent = Object.assign({}, { - title: event.event.Subject, - start: event.start, - end: event.end, - color: event.color, - id: event.id, - index: event.index, - profile: event, - CalendarName: event.CalendarName, - event: { - Subject: event.event.Subject, - StartDate: event.event.StartDate, - EndDate: event.event.EndDate, - Location: event.event.Location, - EventId: event.event.EventId, - CalendarName: event.event.CalendarName - }, - Subject: event.event.Subject, - startMany: false, - endMany: true, - middle: true - }) + + const EndEvent = this.transForm(event, {startMany: false,endMany: true, middle: true}) days[otherDays].push(EndEvent) } @@ -180,13 +119,10 @@ export class ListBoxService { } else { days[day].push(event) - } } else { days[day].push(event) - } - } days[day].push(event) @@ -231,4 +167,32 @@ export class ListBoxService { return events; } + + + transForm(event: CustomCalendarEvent, {startMany, endMany, middle}) { + return Object.assign({}, { + title: event.event.Subject, + start: event.start, + end: event.end, + color: event.color, + id: event.id, + index: event.index, + profile: event, + CalendarName: event.CalendarName, + event: { + Subject: event.event.Subject, + StartDate: event.event.StartDate, + EndDate: event.event.EndDate, + Location: event.event.Location, + EventId: event.event.EventId, + CalendarName: event.event.CalendarName + }, + Subject: event.event.Subject, + startMany: false, + endMany: true, + middle: true + }) + } + + } From 82a601ccecfad2a8b42e562b3f5ad39369b5ca2f Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Tue, 31 Aug 2021 19:30:08 +0100 Subject: [PATCH 2/5] Fix storage service --- src/app/home/home.page.ts | 2 +- src/app/services/ageanda/list-box.service.ts | 2 - .../web-notification-popup.service.ts | 3 ++ src/app/services/notifications.service.ts | 4 +- src/app/services/socket/synchro.service.ts | 4 +- src/app/services/storage.service.ts | 42 ++++--------------- 6 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index b759fa172..4a358eb41 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -184,7 +184,7 @@ export class HomePage implements OnInit { this.webNotificationPopupService.sendNotification(DataArray.Object) - this.storageService.get('Notifications').then((data)=>{ + this.storageService.get('Notifications').then((data:any)=>{ data.push(DataArray) this.storageService.store("Notifications", data) }).catch(()=>{ diff --git a/src/app/services/ageanda/list-box.service.ts b/src/app/services/ageanda/list-box.service.ts index 6e5458ae2..5dff546f9 100644 --- a/src/app/services/ageanda/list-box.service.ts +++ b/src/app/services/ageanda/list-box.service.ts @@ -30,8 +30,6 @@ export class ListBoxService { list(eventSource: EventListStore[], profile: 'md' | 'pr' | 'all', rangeStartDate, randEndDate, {segment = 'todo'}) { - console.log('eventSource: EventListStore[]',eventSource) - if(profile != 'all') { eventSource = this.filterProfile(eventSource, profile) } diff --git a/src/app/services/notification/web-notification-popup.service.ts b/src/app/services/notification/web-notification-popup.service.ts index e4e89dc64..4dac3fe48 100644 --- a/src/app/services/notification/web-notification-popup.service.ts +++ b/src/app/services/notification/web-notification-popup.service.ts @@ -45,6 +45,9 @@ export class WebNotificationPopupService { } sendNotification(message) { + if (this.platform.is('desktop') || this.platform.is('mobileweb')) {} + else {return false} + var n = new Notification(message); } } diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts index d04433176..cf7d3197c 100644 --- a/src/app/services/notifications.service.ts +++ b/src/app/services/notifications.service.ts @@ -54,9 +54,7 @@ export class NotificationsService { registerCallback(type: string, funx: Function, object: any = {} ) { this.callbacks.push({type, funx}) - if(!object.hasOwnProperty('desktop') && object['desktop'] != false) { - synchro.registerCallback('Notification',funx, type) - } + synchro.registerCallback('Notification',funx, type) } diff --git a/src/app/services/socket/synchro.service.ts b/src/app/services/socket/synchro.service.ts index dd19ac1f2..88eb2d374 100644 --- a/src/app/services/socket/synchro.service.ts +++ b/src/app/services/socket/synchro.service.ts @@ -133,8 +133,8 @@ class SynchroService { if(idConnection != this.id ) { - if(window['platform'].is('desktop') || this.platform.is('mobileweb')) {} - else return false + //if(window['platform'].is('desktop') || this.platform.is('mobileweb')) {} + //else return false if(environment.production) return false diff --git a/src/app/services/storage.service.ts b/src/app/services/storage.service.ts index 37bb2b92b..31efdf205 100644 --- a/src/app/services/storage.service.ts +++ b/src/app/services/storage.service.ts @@ -11,7 +11,6 @@ const { Storage } = Plugins; */ export class StorageService { private keyName: string; - constructor(private storage:Storage, private platform: Platform ) {} @@ -22,50 +21,27 @@ const { Storage } = Plugins; */ // Store the value async store(key: string, value: any) { - if (this.platform.is('desktop') || this.platform.is('mobileweb')) { - await localstoreService.set(this.key(key), value) - } else { - const encryptedValue = btoa(escape(JSON.stringify(value))); - await this.storage.set(key, encryptedValue); - } + + await localstoreService.set(this.key(key), value) } // Get the value - async get(key: string) { - - - if (this.platform.is('desktop') || this.platform.is('mobileweb')) { - return new Promise((resolve, reject)=>{ - const data = localstoreService.get(this.key(key), false) - if(data) resolve(data) - else reject(data) - }) - } else { - const ret = await this.storage.get(key).then((val) => { return val; }); - try { - return JSON.parse(unescape(atob(ret))); - } catch (error) { - if(ret == 'žée') { - throw(key+' not found') - } - return unescape(atob(ret)) - } - } + async get(key: string): Promise { + return new Promise((resolve, reject)=>{ + const data = localstoreService.get(this.key(key), false) + if(data) resolve(data) + else reject(data) + }) } async remove(key: string){ - if (this.platform.is('desktop') || this.platform.is('mobileweb')) { - await localstoreService.delete(this.key(key)) - } else { - await this.storage.remove(key); - } + await localstoreService.delete(this.key(key)) } - /* // Get the value async get(storageKey: string) { From 3437c190274e05cbd343ec10fad7e89963593d94 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Tue, 31 Aug 2021 19:31:46 +0100 Subject: [PATCH 3/5] remove notification for mobile --- src/app/services/notifications.service.ts | 4 +++- src/app/services/socket/synchro.service.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts index cf7d3197c..d04433176 100644 --- a/src/app/services/notifications.service.ts +++ b/src/app/services/notifications.service.ts @@ -54,7 +54,9 @@ export class NotificationsService { registerCallback(type: string, funx: Function, object: any = {} ) { this.callbacks.push({type, funx}) - synchro.registerCallback('Notification',funx, type) + if(!object.hasOwnProperty('desktop') && object['desktop'] != false) { + synchro.registerCallback('Notification',funx, type) + } } diff --git a/src/app/services/socket/synchro.service.ts b/src/app/services/socket/synchro.service.ts index 88eb2d374..dd19ac1f2 100644 --- a/src/app/services/socket/synchro.service.ts +++ b/src/app/services/socket/synchro.service.ts @@ -133,8 +133,8 @@ class SynchroService { if(idConnection != this.id ) { - //if(window['platform'].is('desktop') || this.platform.is('mobileweb')) {} - //else return false + if(window['platform'].is('desktop') || this.platform.is('mobileweb')) {} + else return false if(environment.production) return false From fb22023c5d7b9d3e6cfd854f030d30cc35a011d3 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Tue, 31 Aug 2021 22:49:37 +0100 Subject: [PATCH 4/5] Improve notification --- src/app/home/home.page.ts | 2 +- src/app/services/notification/sw.js | 17 ++++++++ .../web-notification-popup.service.ts | 42 +++++++++++++++++-- 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/app/services/notification/sw.js diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 4a358eb41..71a17b5a8 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -182,7 +182,7 @@ export class HomePage implements OnInit { synchro.registerCallback('Notification', (DataArray)=> { - this.webNotificationPopupService.sendNotification(DataArray.Object) + this.webNotificationPopupService.sendNotification(DataArray) this.storageService.get('Notifications').then((data:any)=>{ data.push(DataArray) diff --git a/src/app/services/notification/sw.js b/src/app/services/notification/sw.js new file mode 100644 index 000000000..79be69284 --- /dev/null +++ b/src/app/services/notification/sw.js @@ -0,0 +1,17 @@ + +self.addEventListener('install', function() { + self.skipWaiting(); +}); + +self.addEventListener('activate', function(event) { + event.waitUntil(clients.claim()); +}); + +self.addEventListener('notificationclick', function(event) { + // Close the notification when it is clicked + event.notification.close(); + console.log(event) +}); + + + \ No newline at end of file diff --git a/src/app/services/notification/web-notification-popup.service.ts b/src/app/services/notification/web-notification-popup.service.ts index 4dac3fe48..c3f35da11 100644 --- a/src/app/services/notification/web-notification-popup.service.ts +++ b/src/app/services/notification/web-notification-popup.service.ts @@ -1,11 +1,20 @@ import { Injectable } from '@angular/core'; import { AlertController, Platform } from '@ionic/angular'; +import { v4 as uuidv4 } from 'uuid' @Injectable({ providedIn: 'root' }) export class WebNotificationPopupService { - constructor( private platform: Platform) { } + constructor( private platform: Platform) { + + var myWorker = new Worker( new URL('./sw.js', import.meta.url)); + + myWorker.onmessage = function(oEvent) { + console.log('Worker said : ' + oEvent.data); + } + + } askNotificationPermission() { @@ -44,10 +53,37 @@ export class WebNotificationPopupService { return true; } - sendNotification(message) { + cc = 0; + + sendNotification(e) { if (this.platform.is('desktop') || this.platform.is('mobileweb')) {} else {return false} + + Notification.requestPermission((result) => { + if (result === 'granted') { + navigator.serviceWorker.ready.then((registration)=> { + + registration.showNotification(e.Object+ this.cc, { + body: e.Service, + icon: 'assets/icon/favicon.png', + requireInteraction: true, + tag: 'require-interaction'+uuidv4(), + // actions: [ + // {action: 'like', title: 'Like', icon: 'https://example/like.png'}, + // {action: 'reply', title: 'Reply', icon: 'https://example/reply.png'} + // ] + }).then(e =>{ + console.log(e) + }) + + }); + + + + } + }); + + - var n = new Notification(message); } } From 36fa6b1d2ab98885e739396ed32410a38d9f79ef Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Tue, 31 Aug 2021 22:53:07 +0100 Subject: [PATCH 5/5] Improve notification --- .../notification/web-notification-popup.service.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/app/services/notification/web-notification-popup.service.ts b/src/app/services/notification/web-notification-popup.service.ts index c3f35da11..406761332 100644 --- a/src/app/services/notification/web-notification-popup.service.ts +++ b/src/app/services/notification/web-notification-popup.service.ts @@ -8,11 +8,7 @@ export class WebNotificationPopupService { constructor( private platform: Platform) { - var myWorker = new Worker( new URL('./sw.js', import.meta.url)); - - myWorker.onmessage = function(oEvent) { - console.log('Worker said : ' + oEvent.data); - } + navigator.serviceWorker.register(new URL('./sw.js', import.meta.url)); } @@ -53,8 +49,6 @@ export class WebNotificationPopupService { return true; } - cc = 0; - sendNotification(e) { if (this.platform.is('desktop') || this.platform.is('mobileweb')) {} else {return false} @@ -63,7 +57,7 @@ export class WebNotificationPopupService { if (result === 'granted') { navigator.serviceWorker.ready.then((registration)=> { - registration.showNotification(e.Object+ this.cc, { + registration.showNotification(e.Object, { body: e.Service, icon: 'assets/icon/favicon.png', requireInteraction: true,