This commit is contained in:
tiago.kayaya
2021-08-31 11:29:37 +01:00
17 changed files with 297 additions and 85 deletions
+10
View File
@@ -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: [
+31 -3
View File
@@ -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')
}
+18 -16
View File
@@ -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) => {
+37
View File
@@ -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
}
+18 -13
View File
@@ -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;
+1 -1
View File
@@ -53,7 +53,7 @@ export class EventsPage implements OnInit {
customText = false;
totalEvent=0;
currentHoursMinutes: Date;
currentHoursMinutes: Date | string;
showLoader: boolean;
+15 -5
View File
@@ -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() {
+8 -7
View File
@@ -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<Event[]>{
getAllPrOficialEvents(startdate:string, enddate:string): Observable<EventList[]>{
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<Event[]>(`${geturl}`, options);
return this.http.get<EventList[]>(`${geturl}`, options);
}
getAllPrPessoalEvents(startdate:string, enddate:string): Observable<Event[]>{
getAllPrPessoalEvents(startdate:string, enddate:string): Observable<EventList[]>{
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<Event[]>(`${geturl}`, options);
return this.http.get<EventList[]>(`${geturl}`, options);
}
async getAllPrEvents(startdate:string, enddate:string){
async getAllPrEvents(startdate:string, enddate:string): Promise<EventList[]>{
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<EventList[]>{
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<any>(`${geturl}`, options);
return this.http.get<EventList[]>(`${geturl}`, options);
}
getAllMdPessoalEvents(startdate:string, enddate:string): any{
@@ -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();
});
});
@@ -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);
}
}
+22 -13
View File
@@ -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
+45 -10
View File
@@ -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);
}
}
+1 -1
View File
@@ -82,7 +82,7 @@
<div class="profile-text">
<ion-label>{{profileLabel(loggeduser.Profile)}}</ion-label>
<div *ngIf="this.notificationLength > 0 && !production" class="icon-badge" style="right: -18px;top: -9px;" >{{this.notificationLength}}</div>
<div *ngIf="this.notificationLength > 0 && !production" class="icon-badge" style="right: -18px;top: -9px;" >{{notificationLength}}</div>
</div>
</div>
+13 -3
View File
@@ -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()
})
}
+5 -4
View File
@@ -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) => {
+7 -7
View File
@@ -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',
@@ -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