diff --git a/src/app/home/home-routing.module.ts b/src/app/home/home-routing.module.ts index 014635651..564db5b3e 100644 --- a/src/app/home/home-routing.module.ts +++ b/src/app/home/home-routing.module.ts @@ -382,6 +382,16 @@ const routes: Routes = [ ], canActivate: [InactivityGuard] }, + { + path: 'login', + children: [ + { + path:'', + loadChildren: ()=> import('../pages/inactivity/inactivity.module').then(m => m.InactivityPageModule) + }, + ], + canActivate: [InactivityGuard] + }, { path: 'pin', children: [ diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 912061afe..99dfec1bc 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -18,6 +18,7 @@ import { ExpedienteGdStore } from '../store/expedientegd-store.service'; import { InativityService } from '../services/inativity.service'; import { SessionStore } from '../store/session.service'; import { StorageService } from '../services/storage.service'; +import { WebNotificationPopupService } from '../services/notification/web-notification-popup.service'; @Component({ selector: 'app-home', @@ -72,7 +73,10 @@ export class HomePage implements OnInit { public documentCounterService: DocumentCounterService, private despachoRule: DespachoService, private inativityService: InativityService, - private storageService: StorageService,) { + private storageService: StorageService, + private webNotificationPopupService: WebNotificationPopupService) { + + this.webNotificationPopupService.askNotificationPermission() this.router.events.subscribe((val) => { document.querySelectorAll('ion-modal').forEach((e: any) => e.remove()) @@ -159,11 +163,35 @@ export class HomePage implements OnInit { 'despachos', () => { this.despachoRule.getList({updateStore: true}) + } ) - synchro.registerCallback('Notification', (notification)=> { - console.log('notification====== £=======£==========£======', notification) + + synchro.registerCallback('Online',()=>{ + + }) + + + synchro.registerCallback('Offline',()=>{ + + }) + + + synchro.registerCallback('Notification', (DataArray)=> { + + this.webNotificationPopupService.sendNotification(DataArray.Object) + + this.storageService.get('Notifications').then((data)=>{ + data.push(DataArray) + this.storageService.store("Notifications", data) + }).catch(()=>{ + + const a = [] + a.push(DataArray) + this.storageService.store("Notifications",a) + }) + }, 'any') } diff --git a/src/app/modals/profile/profile.page.ts b/src/app/modals/profile/profile.page.ts index aaf8562af..33ec61cff 100644 --- a/src/app/modals/profile/profile.page.ts +++ b/src/app/modals/profile/profile.page.ts @@ -11,6 +11,7 @@ import { JsonStore } from '../../services/jsonStore.service'; import { StorageService } from '../../services/storage.service'; import { NotificationsService } from '../../services/notifications.service'; import { SessionStore } from 'src/app/store/session.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; @Component({ selector: 'app-profile', @@ -42,24 +43,35 @@ export class ProfilePage implements OnInit { private zone: NgZone, private notificationservice: NotificationsService, private platform: Platform, + private notificationsService: NotificationsService, ) { this.loggeduser = authService.ValidatedUser; console.log(this.loggeduser.RoleDescription) - this.checkState() } ngOnInit() { if (this.platform.is('desktop') || this.platform.is('mobileweb')) { console.log('Notifications not supported') + this.getNotificationData(); } else { - this.getNotificationData(); + this.getNotificationData(); } + this.notificationsService.registerCallback( + 'any', + () => { + setTimeout(()=>{ + this.getNotificationData(); + }, 100) + } + ) + } + close() { this.modalController.dismiss(); } @@ -68,7 +80,7 @@ export class ProfilePage implements OnInit { asyncNotification(){} - async getNotificationData(){ + async getNotificationData() { this.storageservice.get("Notifications").then((value) => { console.log("Init get store", value) @@ -78,6 +90,8 @@ export class ProfilePage implements OnInit { value = JSON.parse(value) console.log("CSDfdvdf",value) } + + this.DataArray = [] value.forEach((element,i) => { console.log("ARaaAA", element) let notificationObject; @@ -208,23 +222,11 @@ export class ProfilePage implements OnInit { SessionStore.setInativity(false) setTimeout(() => { - this.router.navigate(['/inactivity']); + this.router.navigate(['/login']); }, 100) } - checkState() { - - let userData = this.localstoreService.get('UserData', {}) - - if (userData.hasOwnProperty('loginPreference')) { - this.userLoginPreference = userData.loginPreference - } else { - this.userLoginPreference = '' - } - - } - async editProfile() { const enterAnimation = (baseEl: any) => { diff --git a/src/app/models/agenda/AgendaEventList.ts b/src/app/models/agenda/AgendaEventList.ts new file mode 100644 index 000000000..63a798d4a --- /dev/null +++ b/src/app/models/agenda/AgendaEventList.ts @@ -0,0 +1,37 @@ +export interface EventList { + HasAttachments: boolean; + IsAllDayEvent: boolean; + EventId: string; + Subject: string; + Location: string; + CalendarId: string; + CalendarName: string; + StartDate: string; + EndDate: string; + HumanDate: string; +} + +export interface EventListStore { + title: string + startTime: Date + endTime: Date + allDay: boolean, + event: EventList, + calendarName: string + profile: "md" | "pr", + id: string +} + + +export interface CustomCalendarEvent { + start: Date + end: Date + color: { + primary: string, + secondary: string + }, + id: string + index: number, + CalendarName: string + event: EventListStore +} \ No newline at end of file diff --git a/src/app/pages/agenda/eventListBox.ts b/src/app/pages/agenda/eventListBox.ts index 83a03759e..72f7b295b 100644 --- a/src/app/pages/agenda/eventListBox.ts +++ b/src/app/pages/agenda/eventListBox.ts @@ -1,5 +1,7 @@ import { eventSource } from 'src/app/models/agenda/eventSource'; import { setHours, setMinutes } from 'date-fns'; +import { CustomCalendarEvent, EventList, EventListStore } from 'src/app/models/agenda/AgendaEventList'; +import { CalendarEvent } from 'angular-calendar'; export class eventListBox { @@ -24,11 +26,11 @@ export class eventListBox { } - filterProfile(eventSource: eventSource[], profile: 'md' | 'pr' | 'all') { + filterProfile(eventSource: EventListStore[], profile: 'md' | 'pr' | 'all') { return eventSource.filter((e) => e.profile == profile) } - getEventInsideRange(eventSource: eventSource[], rangeStartDate, randEndDate) { + getEventInsideRange(eventSource: EventListStore[], rangeStartDate, randEndDate) { return eventSource.filter((e)=> { if(new Date(rangeStartDate).getTime() <= new Date(e.startTime).getTime() && new Date(randEndDate).getTime() >= new Date(e.endTime).getTime()) { @@ -40,7 +42,7 @@ export class eventListBox { daysBetween(){ } - list(eventSource: eventSource[], profile: 'md' | 'pr' | 'all', rangeStartDate, randEndDate, calendarDate) { + list(eventSource: EventListStore[], profile: 'md' | 'pr' | 'all', rangeStartDate, randEndDate, calendarDate) { if(profile != 'all') { eventSource = this.filterProfile(eventSource, profile) @@ -48,19 +50,21 @@ export class eventListBox { eventSource = this.getEventInsideRange(eventSource, rangeStartDate, randEndDate) + let newStracture:CustomCalendarEvent[]; if(profile == 'md') { - eventSource = this.encapsulation(eventSource, 'mdgpr'); + newStracture = this.encapsulation(eventSource, 'mdgpr'); } else { - eventSource = this.encapsulation(eventSource, 'pr'); + newStracture = this.encapsulation(eventSource, 'pr'); } - return this.display(eventSource) + return this.display(newStracture) } display(list) { let days = {}; + console.log(list) - list.forEach( (event:any, index)=> { + list.forEach( (event, index)=> { var startDate: any = new Date(event.start); @@ -215,27 +219,28 @@ export class eventListBox { return days } - encapsulation(eventsList, profile) { + encapsulation(eventsList, profile): CustomCalendarEvent[] { // remove all event - let events = []; + let events: CustomCalendarEvent[] = []; eventsList.forEach((element, eventIndex) => { events.push({ - start: new Date(element.StartDate || element.startTime), - end: new Date(element.EndDate || element.endTime), + start: new Date(element.startTime), + end: new Date(element.endTime), color: { primary: '#0000', secondary: '#0000' }, - id: element.EventId || element.id, + id: element.id, index: eventIndex, - profile: profile, CalendarName: element.calendarName, event: element.event, }); + console.log('element.event', element.event) + }); return events; diff --git a/src/app/pages/events/events.page.ts b/src/app/pages/events/events.page.ts index c2643fe1c..a3a986157 100644 --- a/src/app/pages/events/events.page.ts +++ b/src/app/pages/events/events.page.ts @@ -53,7 +53,7 @@ export class EventsPage implements OnInit { customText = false; totalEvent=0; - currentHoursMinutes: Date; + currentHoursMinutes: Date | string; showLoader: boolean; diff --git a/src/app/pages/inactivity/inactivity.page.ts b/src/app/pages/inactivity/inactivity.page.ts index bcccf0249..74437d4ea 100644 --- a/src/app/pages/inactivity/inactivity.page.ts +++ b/src/app/pages/inactivity/inactivity.page.ts @@ -77,8 +77,8 @@ export class InactivityPage implements OnInit { // if current attemp is equal to the current user if (attempt.UserId == SessionStore.user.UserId) { await this.authService.SetSession(attempt, this.userattempt); - await this.authService.loginChat(this.userattempt); - await this.getToken(); + this.authService.loginChat(this.userattempt); + this.getToken(); SessionStore.setInativity(true) this.goback() @@ -131,9 +131,14 @@ export class InactivityPage implements OnInit { const code = this.code.join('') if( SessionStore.validatePin(code)) { - + + SessionStore.setInativity(true) this.goback() - this.clearCode() + + setTimeout(()=>{ + this.clearCode() + }, 1000) + } else { this.toastService.badRequest('Pin incorreto') this.code = [] @@ -143,7 +148,12 @@ export class InactivityPage implements OnInit { goback() { const pathName = this.SessionStore.user.UrlBeforeInactivity - this.router.navigate([pathName]); + if(pathName) { + this.router.navigate([pathName]); + } else { + this.router.navigate(['/home/events']); + } + } storePin() { diff --git a/src/app/services/events.service.ts b/src/app/services/events.service.ts index 79769d4c7..a3a0d8983 100644 --- a/src/app/services/events.service.ts +++ b/src/app/services/events.service.ts @@ -5,6 +5,7 @@ import { Observable } from 'rxjs'; import { environment } from 'src/environments/environment'; import { AuthService } from '../services/auth.service'; import { LoginUserRespose } from '../models/user.model'; +import { EventList } from '../models/agenda/AgendaEventList'; @Injectable({ @@ -107,7 +108,7 @@ export class EventsService { } */ - getAllPrOficialEvents(startdate:string, enddate:string): Observable{ + getAllPrOficialEvents(startdate:string, enddate:string): Observable{ let geturl = environment.apiURL + 'calendar/pr'; geturl = geturl.replace('/V4/','/V5/') @@ -120,10 +121,10 @@ export class EventsService { headers: this.headersPrOficial, params: params }; - return this.http.get(`${geturl}`, options); + return this.http.get(`${geturl}`, options); } - getAllPrPessoalEvents(startdate:string, enddate:string): Observable{ + getAllPrPessoalEvents(startdate:string, enddate:string): Observable{ let geturl = environment.apiURL + 'calendar/pr'; geturl = geturl.replace('/V4/','/V5/') @@ -136,10 +137,10 @@ export class EventsService { headers: this.headersPrPessoal, params: params }; - return this.http.get(`${geturl}`, options); + return this.http.get(`${geturl}`, options); } - async getAllPrEvents(startdate:string, enddate:string){ + async getAllPrEvents(startdate:string, enddate:string): Promise{ let prO = await this.getAllPrOficialEvents(startdate, enddate).toPromise(); let prP = await this.getAllPrPessoalEvents(startdate, enddate).toPromise(); const resFinal = prO.concat(prP); @@ -148,7 +149,7 @@ export class EventsService { }) } - getAllMdOficialEvents(startdate:string, enddate:string): any{ + getAllMdOficialEvents(startdate:string, enddate:string): Observable{ let geturl = environment.apiURL + 'calendar/md'; let params = new HttpParams(); @@ -160,7 +161,7 @@ export class EventsService { headers: this.headersMdOficial, params: params }; - return this.http.get(`${geturl}`, options); + return this.http.get(`${geturl}`, options); } getAllMdPessoalEvents(startdate:string, enddate:string): any{ diff --git a/src/app/services/notification/web-notification-popup.service.spec.ts b/src/app/services/notification/web-notification-popup.service.spec.ts new file mode 100644 index 000000000..e45f02163 --- /dev/null +++ b/src/app/services/notification/web-notification-popup.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { WebNotificationPopupService } from './web-notification-popup.service'; + +describe('WebNotificationPopupService', () => { + let service: WebNotificationPopupService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(WebNotificationPopupService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/notification/web-notification-popup.service.ts b/src/app/services/notification/web-notification-popup.service.ts new file mode 100644 index 000000000..9520630a9 --- /dev/null +++ b/src/app/services/notification/web-notification-popup.service.ts @@ -0,0 +1,47 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class WebNotificationPopupService { + + constructor() { } + + + askNotificationPermission() { + + // function to actually ask the permissions + function handlePermission(permission) {} + + // Let's check if the browser supports notifications + if (!('Notification' in window)) { + console.log("This browser does not support notifications."); + } else { + if(this.checkNotificationPromise()) { + Notification.requestPermission() + .then((permission) => { + handlePermission(permission); + }) + } else { + Notification.requestPermission(function(permission) { + handlePermission(permission); + }); + } + } + } + + + private checkNotificationPromise() { + try { + Notification.requestPermission().then(); + } catch(e) { + return false; + } + + return true; + } + + sendNotification(message) { + var n = new Notification(message); + } +} diff --git a/src/app/services/socket/synchro.service.ts b/src/app/services/socket/synchro.service.ts index 8d9d4fbf6..8881a2829 100644 --- a/src/app/services/socket/synchro.service.ts +++ b/src/app/services/socket/synchro.service.ts @@ -79,13 +79,18 @@ class SynchroService { private onopen = () =>{ - this.BackgroundService.online() - this.callBacks.forEach((e)=>{ - if(e.type == 'Online') { - e.funx() - } - }) + + if(!this.conected) { + + this.BackgroundService.online() + this.callBacks.forEach((e)=>{ + if(e.type == 'Online') { + e.funx() + } + }) + + } console.log('open ======================= welcome to socket server') this._connected = true @@ -130,7 +135,8 @@ class SynchroService { if(window['platform'].is('desktop') || this.platform.is('mobileweb')) {} else return false - if(environment.production) return false + + // if(environment.production) return false this.callBacks.forEach((e)=> { @@ -169,13 +175,16 @@ class SynchroService { console.log('[close] Connection died'); console.log('Reconnect') - this.BackgroundService.offline(); + - this.callBacks.forEach((e)=>{ - if(e.type == 'Offline') { - e.funx() - } - }) + if(this._connected) { + this.BackgroundService.offline(); + this.callBacks.forEach((e)=>{ + if(e.type == 'Offline') { + e.funx() + } + }) + } // status this._connected = false diff --git a/src/app/services/storage.service.ts b/src/app/services/storage.service.ts index 884c6407c..4371edbda 100644 --- a/src/app/services/storage.service.ts +++ b/src/app/services/storage.service.ts @@ -1,30 +1,65 @@ import { Injectable } from '@angular/core'; import { Storage } from '@ionic/storage'; +import { AnimationController, ModalController,Platform } from '@ionic/angular'; +import { SHA1 } from 'crypto-js' +import { localstoreService } from '../store/localstore.service'; /* import { Plugins } from '@capacitor/core'; const { Storage } = Plugins; */ @Injectable({ providedIn: 'root' }) export class StorageService { - constructor(private storage:Storage,) {} + private keyName: string; + + + constructor(private storage:Storage, + private platform: Platform + ) {} + + key(key) { + this.keyName = (SHA1('service'+this.constructor.name+'key')).toString() + } // Store the value - async store(key: string, value: any){ - const encryptedValue = btoa(escape(JSON.stringify(value))); - await this.storage.set(key, encryptedValue); + 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); + } + } // Get the value async get(key: string) { - const ret = await this.storage.get(key).then((val) => { return val; }); - try { - return JSON.parse(unescape(atob(ret))); - } catch (error) { - return unescape(atob(ret)) + + + 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) { + return unescape(atob(ret)) + } } + + } async remove(key: string){ - await this.storage.remove(key); + + if (this.platform.is('desktop') || this.platform.is('mobileweb')) { + await localstoreService.delete(this.key(key)) + } else { + await this.storage.remove(key); + } + } diff --git a/src/app/shared/header/header.page.html b/src/app/shared/header/header.page.html index 055e9eabb..6c0d2b66c 100644 --- a/src/app/shared/header/header.page.html +++ b/src/app/shared/header/header.page.html @@ -82,7 +82,7 @@
{{profileLabel(loggeduser.Profile)}} -
{{this.notificationLength}}
+
{{notificationLength}}
diff --git a/src/app/shared/header/header.page.ts b/src/app/shared/header/header.page.ts index c7aad3f17..2c2ac03be 100644 --- a/src/app/shared/header/header.page.ts +++ b/src/app/shared/header/header.page.ts @@ -44,19 +44,24 @@ export class HeaderPage implements OnInit { ngOnInit() { this.hideSearch(); + this.notificationLengthData(); + if (this.platform.is('desktop') || this.platform.is('mobileweb')) { console.log('Notifications not supported') + this.UpdateNotificationCount(); } else { this.UpdateNotificationCount(); } } - + UpdateNotificationCount() { this.notificationsService.registerCallback( 'any', () => { - this.notificationLengthData(); + setTimeout(()=>{ + this.notificationLengthData(); + }, 100) } ) } @@ -65,6 +70,8 @@ export class HeaderPage implements OnInit { this.storageservice.get("Notifications").then((value) => { console.log("Init get store", value) + if(value == 'žée') return false + /* var data = JSON.parse(value); */ this.notificationLength = value.length; }) @@ -146,7 +153,6 @@ export class HeaderPage implements OnInit { return enterAnimation(baseEl).direction('reverse'); } - const modal = await this.modalController.create({ enterAnimation, leaveAnimation, @@ -156,6 +162,10 @@ export class HeaderPage implements OnInit { } }); await modal.present(); + + modal.onDidDismiss().then(()=>{ + this.notificationLengthData() + }) } diff --git a/src/app/store/calendar.service.ts b/src/app/store/calendar.service.ts index 9028b36bf..0559532e6 100644 --- a/src/app/store/calendar.service.ts +++ b/src/app/store/calendar.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { eventSource } from '../models/agenda/eventSource'; import { SHA1, SHA256, AES, enc } from 'crypto-js' import { LocalstoreService } from './localstore.service' +import { EventList, EventListStore } from '../models/agenda/AgendaEventList'; @Injectable({ providedIn: 'root' @@ -9,7 +10,7 @@ import { LocalstoreService } from './localstore.service' export class CalendarService { - private _eventSource : eventSource[] = [] + private _eventSource : EventListStore[] = [] private keyName: string; constructor(private localstoreService: LocalstoreService) { @@ -19,7 +20,7 @@ export class CalendarService { let restore = localstoreService.get(this.keyName, []) setTimeout(()=>{ - restore.forEach((element, eventIndex) => { + restore.forEach((element:EventListStore, eventIndex) => { this._eventSource.push({ title: element.title, startTime: new Date(element.startTime), @@ -36,7 +37,7 @@ export class CalendarService { } - ResetList(eventSource: eventSource[]) { + ResetList(eventSource: EventListStore[]) { this._eventSource = eventSource setTimeout(() => { @@ -61,7 +62,7 @@ export class CalendarService { }) } - pushEvent(eventsList, profile: 'pr' | 'md') { + pushEvent(eventsList: EventList[], profile: 'pr' | 'md') { let news = [] eventsList.forEach((element, eventIndex) => { diff --git a/src/app/store/despacho-store.service.ts b/src/app/store/despacho-store.service.ts index 1cd097920..6f19a114d 100644 --- a/src/app/store/despacho-store.service.ts +++ b/src/app/store/despacho-store.service.ts @@ -36,13 +36,13 @@ export class DespachoStoreService { // (update:customTask) => update.Folio = 'Formação 5' // ) - // this.Query().Update( - // (select:customTask): boolean => select.Folio == 'Formação', - // (update:customTask) => { - // update.Folio = 'Formação 7'; - // update.DocumentURL = 'peter'; - // } - // ) + // this.Query().Update( + // (select:customTask): boolean => select.Folio == 'Formação', + // (update:customTask) => { + // update.Folio = 'Formação 7'; + // update.DocumentURL = 'peter'; + // } + // ) // this.Query().Update( // (select:customTask): boolean => select.Folio == 'Formação', diff --git a/src/app/store/to-day-event-storage.service.ts b/src/app/store/to-day-event-storage.service.ts index 70f1fa2ad..0868c059d 100644 --- a/src/app/store/to-day-event-storage.service.ts +++ b/src/app/store/to-day-event-storage.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { Event } from '../models/event.model'; import { localstoreService } from './localstore.service' import { AES, enc, SHA1 } from 'crypto-js' +import { EventList } from '../models/agenda/AgendaEventList'; @Injectable({ providedIn: 'root' @@ -10,7 +11,7 @@ import { AES, enc, SHA1 } from 'crypto-js' export class ToDayEventStorageService { // main data - private _eventsList: Event[] = [] + private _eventsList:EventList[] = [] // local storage keyName private keyName: string; private _count = 0 @@ -39,7 +40,7 @@ export class ToDayEventStorageService { this.save() } - reset(eventsList: Event[]) { + reset(eventsList: EventList[]) { this._eventsList = eventsList this.count = this._eventsList.length