mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
Remove IBM push notification and jsonstore, added cordova notifications
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
///<reference path="../../../plugins/cordova-plugin-mfp/typings/worklight.d.ts" />
|
||||
///<reference path="../../../plugins/cordova-plugin-mfp-jsonstore/typings/jsonstore.d.ts" />
|
||||
/* ///<reference path="../../../plugins/cordova-plugin-mfp-jsonstore/typings/jsonstore.d.ts" /> */
|
||||
import { Injectable } from "@angular/core";
|
||||
|
||||
@Injectable({
|
||||
@@ -8,7 +8,7 @@ import { Injectable } from "@angular/core";
|
||||
|
||||
export class JsonStore {
|
||||
|
||||
createCollection(name, data) {
|
||||
/* createCollection(name, data) {
|
||||
|
||||
var collectionName = name;
|
||||
var addOptions = {
|
||||
@@ -108,7 +108,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) {
|
||||
@@ -119,12 +119,12 @@ 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)
|
||||
}).fail(function (error) {
|
||||
console.log("JsonStore remove document erro: ", error)
|
||||
});
|
||||
}
|
||||
} */
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable */
|
||||
/* tslint:disable */
|
||||
///<reference path="../../../plugins/cordova-plugin-mfp-push/typings/mfppush.d.ts" />
|
||||
/* ///<reference path="../../../plugins/cordova-plugin-mfp-push/typings/mfppush.d.ts" /> */
|
||||
import { Injectable, NgZone } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router'
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
@@ -17,6 +17,8 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
import { EventTrigger } from '../services/eventTrigger.service';
|
||||
import { SessionStore } from '../store/session.service';
|
||||
|
||||
import { FCM } from '@ionic-native/fcm/ngx';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -45,7 +47,8 @@ export class NotificationsService {
|
||||
private activeroute: ActivatedRoute,
|
||||
private jsonstore: JsonStore,
|
||||
private eventtrigger: EventTrigger,
|
||||
private backgroundservice: BackgroundService) {
|
||||
private backgroundservice: BackgroundService,
|
||||
private fcm: FCM) {
|
||||
|
||||
this.storageService.get("Notifications").then((value) => {
|
||||
|
||||
@@ -85,6 +88,67 @@ export class NotificationsService {
|
||||
}
|
||||
|
||||
getAndpostToken(username) {
|
||||
if(this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
console.log('Notifications not supported')
|
||||
} else {
|
||||
|
||||
const geturl = environment.apiURL + 'notifications/token';
|
||||
|
||||
return this.fcm.getToken().then(token => {
|
||||
console.log('token: ', token)
|
||||
this.storageService.store(username, token);
|
||||
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,
|
||||
Status: 1,
|
||||
Service: 1
|
||||
};
|
||||
|
||||
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
|
||||
console.log('TOKEN USER MIDLE', data);
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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.openApproveModal(data.IdObject);
|
||||
|
||||
}; */
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
/* 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')
|
||||
@@ -144,13 +208,13 @@ export class NotificationsService {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} */
|
||||
|
||||
tempClearArray(){
|
||||
this.DataArray = [];
|
||||
}
|
||||
|
||||
async onReceviNotification() {
|
||||
/* async onReceviNotification() {
|
||||
|
||||
if(window['WLAuthorizationManager']) {
|
||||
if(window['WLAuthorizationManager'].obtainAccessToken) {
|
||||
@@ -188,7 +252,7 @@ export class NotificationsService {
|
||||
if(message.actionName){
|
||||
this.notificatinsRoutes(data);
|
||||
} else {
|
||||
/* this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data); */
|
||||
/* this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
|
||||
//this.notificatinsRoutes(data);
|
||||
console.log(data)
|
||||
}
|
||||
@@ -209,7 +273,7 @@ export class NotificationsService {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} */
|
||||
|
||||
notificatinsRoutes = (data) => {
|
||||
if (data.Service === "agenda") {
|
||||
|
||||
@@ -34,6 +34,7 @@ export class SqliteService {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user