This commit is contained in:
Peter Maquiran
2021-11-07 20:57:51 +01:00
31 changed files with 1370 additions and 398 deletions
@@ -1,16 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { JsonStore } from './jsonStore.service';
describe('JsonStore', () => {
let service: JsonStore;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(JsonStore);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+2 -3
View File
@@ -1,4 +1,3 @@
import { Injectable } from "@angular/core";
@Injectable({
@@ -107,7 +106,7 @@ export class JsonStore {
replaceDocument(collectionName: string, document: any) {
/* var document = { Example of how identify the document to replace
_id: 1, json: {name: 'chevy', age: 23}
}; */
};
var options = {};
/* WL.JSONStore.get(collectionName).replace(document, options).then(function (numberOfDocsReplaced) {
@@ -118,7 +117,7 @@ export class JsonStore {
}
removeDocument(collectionName: any,query: any,) {
/* var query = { _id: 1 }; Exemple of query*/
/* var query = { _id: 1 }; Exemple of query
var options = { exact: true };
/* WL.JSONStore.get(collectionName).remove(query, options).then(function (numberOfDocsRemoved) {
console.log("JsonStore remove document sucess: ", numberOfDocsRemoved)
+262 -148
View File
@@ -6,15 +6,15 @@ import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { StorageService } from 'src/app/services/storage.service';
import { AuthConnstants } from 'src/app/config/auth-constants';
import { Token } from '../models/token.model';
import { Tokenn } from '../models/token.model';
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
import { NavigationExtras,Router } from '@angular/router';
import { NavigationExtras, Router } from '@angular/router';
import { ToastService } from '../services/toast.service';
import { JsonStore } from './jsonStore.service';
import { BackgroundService } from './background.service';
import { v4 as uuidv4 } from 'uuid';
import { EventTrigger } from '../services/eventTrigger.service';
import { SessionStore } from '../store/session.service';
import { ActionPerformed, PushNotificationSchema, PushNotifications, Token, } from '@capacitor/push-notifications';
@Injectable({
providedIn: 'root'
@@ -23,7 +23,7 @@ export class NotificationsService {
adding: "intervenient" | "CC" = "intervenient";
folderId: string;
DataArray: Array<String> = [];
DataArray = new Array();
callbacks: {
type: string,
@@ -38,37 +38,39 @@ export class NotificationsService {
public modalCtrl: AlertController,
private animationController: AnimationController,
private platform: Platform,
private router: Router,
private router: Router,
private toastService: ToastService,
private zone: NgZone,
private activeroute: ActivatedRoute,
private jsonstore: JsonStore,
private eventtrigger: EventTrigger,
private backgroundservice: BackgroundService) {
private backgroundservice: BackgroundService,
/* private fcm: FCM */) {
this.storageService.get("Notifications").then((value) => {
}).catch(()=>{
this.storageService.store("Notifications",[])
})
}).catch(() => {
}
this.storageService.store("Notifications", [])
})
registerCallback(type: string, funx: Function, object: any = {} ) {
}
registerCallback(type: string, funx: Function, object: any = {}) {
const id = uuidv4()
this.callbacks.push({type, funx, id})
if(!object.hasOwnProperty('desktop') && object['desktop'] != false) {
this.backgroundservice.registerBackService('Notification',funx, type)
this.callbacks.push({ type, funx, id })
if (!object.hasOwnProperty('desktop') && object['desktop'] != false) {
this.backgroundservice.registerBackService('Notification', funx, type)
}
return id;
}
deleteCallback(id) {
this.callbacks.forEach((e, index)=>{
if(e.id == id) {
this.callbacks.forEach((e, index) => {
if (e.id == id) {
if (index > -1) {
this.callbacks.splice(index, 1);
}
@@ -80,59 +82,237 @@ export class NotificationsService {
getTokenByUserIdAndId(user, userID) {
const geturl = environment.apiURL + 'notifications/user/' + userID;
return this.http.get<Token[]>(`${geturl}`);
return this.http.get<Tokenn[]>(`${geturl}`);
}
requestPermissions() {
PushNotifications.requestPermissions().then(result => {
if (result.receive === 'granted') {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
}
getAndpostToken(username) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
//console.log('Notifications not supported')
console.log('Notifications not supported')
} else {
const geturl = environment.apiURL + 'notifications/token';
PushNotifications.addListener('registration',
(token: Token) => {
console.log('token: ', token.value)
this.storageService.store(username, token.value);
this.storageService.get(username).then(value => {
console.log('STORAGE TOKEN', value)
this.storageService.get(AuthConnstants.USER).then(res => {
console.log('USERID', res);
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
const body = {
UserId: res.UserId,
TokenId: token.value,
Status: 1,
Service: 1
};
this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
console.log('TOKEN USER MIDLE', data);
}, (error) => {
console.log('Post token to backend', error)
})
});
});
}
);
}
}
registrationError() {
PushNotifications.addListener('registrationError',
(error: any) => {
console.log('Error on registration: ' + JSON.stringify(error));
}
);
}
onReciveForeground() {
PushNotifications.addListener('pushNotificationReceived',
(notification: PushNotificationSchema) => {
console.log('Push received: ' + JSON.stringify(notification));
this.DataArray.push(notification)
console.log("On ReceiveNotification", this.DataArray)
this.storageService.store("Notifications", this.DataArray)
this.eventtrigger.publishSomeData({
notification: "recive"
})
}
);
}
onReciveBackground() {
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: ActionPerformed) => {
console.log('Push action performed: ' + JSON.stringify(notification));
this.notificatinsRoutes(notification)
}
);
}
/*
async onReceviNotification() {
this.fcm.onNotification().subscribe(data => {
if (data.click_action) {
console.log("Received in background: ", data);
this.notificatinsRoutes(data)
} else {
console.log("Received in foreground: ", data);
console.log(data.Service)
console.log(data.Object)
console.log(data.IdObject)
this.DataArray.push(data)
console.log("On ReceiveNotification", this.DataArray)
this.storageService.store("Notifications", this.DataArray)
};
});
} */
/////////////////////////////////////////////////////
/* getTokenByUserIdAndId(user, userID) {
const geturl = environment.apiURL + 'notifications/user/' + userID;
return this.http.get<Token[]>(`${geturl}`);
}
*/
/* getAndpostToken(username) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
//console.log('Notifications not supported')
} else {
const geturl = environment.apiURL + 'notifications/token';
if(window['WLAuthorizationManager']) {
if(window['WLAuthorizationManager'].obtainAccessToken) {
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
console.log('Push Notification: Success ' + token);
window['MFPPush'].initialize(
function (successResponse) {
console.log("Push notification Successfully Service intialized: " + successResponse);
},
function (failureResponse) {
console.log("Push notification failure Service intialized: " + failureResponse);
}
);
window['MFPPush'].registerDevice(null, async (successResponse) => {
console.log("Successfully registered: " + JSON.stringify(successResponse));
console.log('token: ', successResponse.deviceId)
await this.storageService.store(username, successResponse.deviceId).then((tokennoti) => {
console.log('token store',tokennoti)
});
await this.storageService.get(username).then(value => {
console.log('STORAGE TOKEN', value)
this.storageService.get(AuthConnstants.USER).then(res => {
console.log('USERID', res);
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
const body = {
UserId: res.UserId,
TokenId: successResponse.deviceId,
Status: 1,
Service: 1
};
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
console.log('TOKEN USER MIDLE', data);
})
});
});
},
function (failureResponse) {
console.log("Successfully failue: " + JSON.stringify(failureResponse));
}
);
}, (error) => {
console.log('Push notification recived: failure ' + error.responseText);
console.log(JSON.stringify(error));
}
);
}
}
}
} */
tempClearArray() {
this.DataArray = new Array;
}
/* async onReceviNotification() {
if(window['WLAuthorizationManager']) {
if(window['WLAuthorizationManager'].obtainAccessToken) {
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
console.log('Push Notification: Success ' + token);
window['MFPPush'].initialize(
function (successResponse) {
console.log("Push notification Successfully Service intialized: " + successResponse);
console.log("Push notification Successfully intialized: " + successResponse);
window['MFPPush'].registerNotificationsCallback(notificationReceived);
},
function (failureResponse) {
console.log("Push notification failure Service intialized: " + failureResponse);
console.log("Push notification failure intialized: " + failureResponse);
}
);
window['MFPPush'].registerDevice(null, async (successResponse) => {
console.log("Successfully registered: " + JSON.stringify(successResponse));
console.log('token: ', successResponse.deviceId)
await this.storageService.store(username, successResponse.deviceId).then((tokennoti) => {
console.log('token store',tokennoti)
});
await this.storageService.get(username).then(value => {
console.log('STORAGE TOKEN', value)
this.storageService.get(AuthConnstants.USER).then(res => {
console.log('USERID', res);
const headers = { 'Authorization': SessionStore.user.BasicAuthKey };
const body = {
UserId: res.UserId,
TokenId: successResponse.deviceId,
Status: 1,
Service: 1
};
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
console.log('TOKEN USER MIDLE', data);
})
});
});
},
function (failureResponse) {
console.log("Successfully failue: " + JSON.stringify(failureResponse));
var notificationReceived = (message) => {
//this.jsonstore.createCollection('Notifications',message);
this.DataArray.push(message)
console.log("On ReceiveNotification", this.DataArray)
this.storageService.store("Notifications",this.DataArray)
console.log(message);
this.eventtrigger.publishSomeData({
notification: "recive"
})
var data = JSON.parse(message.payload);
//synchro.$send(data)
console.log('data.Service', data.Service); // module
console.log('data.IdObject', data.IdObject); // Object id
console.log('data.Object', data.Object); // details
if(message.actionName){
this.notificatinsRoutes(data);
} else {
/* this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
//this.notificatinsRoutes(data);
console.log(data)
}
);
this.callbacks.forEach( e=> {
if(e.type == data.Object || e.type == "any") {
e.funx()
}
})
}
}, (error) => {
console.log('Push notification recived: failure ' + error.responseText);
console.log(JSON.stringify(error));
@@ -140,120 +320,54 @@ export class NotificationsService {
);
}
}
} */
notificatinsRoutes = (notification) => {
if (notification.data.Service === "agenda") {
this.zone.run(() => this.router.navigate(['/home/agenda', notification.data.IdObject, 'agenda']));
}
}
tempClearArray(){
this.DataArray = [];
}
async onReceviNotification() {
if(window['WLAuthorizationManager']) {
if(window['WLAuthorizationManager'].obtainAccessToken) {
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
console.log('Push Notification: Success ' + token);
window['MFPPush'].initialize(
function (successResponse) {
console.log("Push notification Successfully intialized: " + successResponse);
window['MFPPush'].registerNotificationsCallback(notificationReceived);
},
function (failureResponse) {
console.log("Push notification failure intialized: " + failureResponse);
}
);
var notificationReceived = (message) => {
//this.jsonstore.createCollection('Notifications',message);
this.DataArray.push(message)
console.log("On ReceiveNotification", this.DataArray)
this.storageService.store("Notifications",this.DataArray)
console.log(message);
this.eventtrigger.publishSomeData({
notification: "recive"
})
var data = JSON.parse(message.payload);
//synchro.$send(data)
console.log('data.Service', data.Service); // module
console.log('data.IdObject', data.IdObject); // Object id
console.log('data.Object', data.Object); // details
if(message.actionName){
this.notificatinsRoutes(data);
} else {
/* this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data); */
//this.notificatinsRoutes(data);
console.log(data)
}
this.callbacks.forEach( e=> {
if(e.type == data.Object || e.type == "any") {
e.funx()
}
})
}
}, (error) => {
console.log('Push notification recived: failure ' + error.responseText);
console.log(JSON.stringify(error));
}
);
}
else if (notification.data.Service === "gabinete-digital" && notification.data.Object === "expediente") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.data.Service === "agenda" && notification.data.Object === "event-list") {
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', notification.data.IdObject, 'agenda']));
} else if (notification.data.Service === "gabinete-digital" && notification.data.Object === "despachos") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', notification.data.IdObject, 'gabinete-digital'], { replaceUrl: true }));
}
else if (notification.data.Service === "gabinete-digital" && notification.data.Object === "parecer") {
}
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.data.IdObject, 'gabinete-digital']));
}
else if (notification.data.Service === "gabinete-digital" && notification.data.Object === "deferimento") {
notificatinsRoutes = (data) => {
if (data.Service === "agenda") {
this.zone.run(() => this.router.navigate(['/home/agenda', data.IdObject, 'agenda']));
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.data.IdObject, 'gabinete-digital']));
}
else if (data.Service === "gabinete-digital" && data.Object === "expediente") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente',data.IdObject,'gabinete-digital']));
}
else if (data.Service === "agenda" && data.Object === "event-list") {
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event',data.IdObject, 'agenda']));
}else if (data.Service === "gabinete-digital" && data.Object === "despachos") {
else if (notification.data.Service === "gabinete-digital" && notification.data.Object === "despachos-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos',data.IdObject,'gabinete-digital'],{replaceUrl: true}));
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', notification.data.IdObject, 'gabinete-digital']));
}
else if (data.Service === "gabinete-digital" && data.Object === "parecer") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos',data.IdObject,'gabinete-digital']));
else if (notification.data.Service === "accoes" && notification.data.Object === "accao") {
this.zone.run(() => this.router.navigate(['/home/publications', notification.data.IdObject]));
}
else if (data.Service === "gabinete-digital" && data.Object === "deferimento") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos',data.IdObject,'gabinete-digital']));
else if (notification.data.Service === "accoes" && notification.data.Object === "publicacao") {
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', notification.data.FolderId, notification.data.IdObject]));
}
else if (data.Service === "gabinete-digital" && data.Object === "despachos-pr") {
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/despachos-pr',data.IdObject,'gabinete-digital']));
else if (notification.data.Service === "gabinete-digital" && notification.data.Object === "diplomas") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', notification.data.IdObject, 'gabinete-digital']));
}
else if (data.Service === "accoes" && data.Object === "accao") {
this.zone.run(() => this.router.navigate(['/home/publications',data.IdObject]));
}
else if (data.Service === "accoes" && data.Object === "publicacao") {
this.zone.run(() => this.router.navigate(['/home/publications/view-publications',data.FolderId,data.IdObject]));
}
else if (data.Service === "gabinete-digital" && data.Object === "diplomas") {
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/diplomas', data.IdObject, 'gabinete-digital']));
}
else if (data.Service === "gabinete-digital" && data.Object === "diplomas-assinar") {
else if (notification.data.Service === "gabinete-digital" && notification.data.Object === "diplomas-assinar") {
let navigationExtras: NavigationExtras = {
queryParams: {
"serialNumber": data.IdObject,
"serialNumber": notification.data.IdObject,
}
};
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/diplomas-assinar/diploma-assinar'], navigationExtras));
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar/diploma-assinar'], navigationExtras));
}
else if (data.Service === "gabinete-digital" && data.Object === "expedientes-pr") {
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/expedientes-pr',data.IdObject,'gabinete-digital']));
else if (notification.data.Service === "gabinete-digital" && notification.data.Object === "expedientes-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', notification.data.IdObject, 'gabinete-digital']));
}
}
+8 -2
View File
@@ -25,15 +25,19 @@ export class SqliteService {
this.databaseConn();
}
databaseConn() {
databaseConn() {
console.log('SQLDBConnect')
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
console.log('SQLDBConnect22')
this.platform.ready().then(async () => {
await this.sqlite.create({
console.log('SQLDBConnect33')
this.sqlite.create({
name: this.db_name,
location: 'default'
}).then(async (sqLite: SQLiteObject) => {
this.dbInstance = sqLite;
console.log('SQLITE INSTACE ',this.dbInstance);
await sqLite.executeSql(`
CREATE TABLE IF NOT EXISTS ${this.events} (
EventId varchar(255) PRIMARY KEY,
@@ -125,6 +129,8 @@ export class SqliteService {
.catch((error) => console.log(JSON.stringify(error)));
})
.catch((error) => console.log(JSON.stringify(error)));
}).catch((error) => {
console.log('Platform ready error', error)
});
}
}
+1 -1
View File
@@ -3,7 +3,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { StorageService } from 'src/app/services/storage.service';
import { AuthConnstants } from 'src/app/config/auth-constants';
import { Token } from '../models/token.model';
import { Tokenn } from '../models/token.model';
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
import { NavigationExtras, Router } from '@angular/router';
import { ToastService } from './toast.service';