Remove IBM push notification and jsonstore, added cordova notifications

This commit is contained in:
Eudes Inácio
2021-10-30 16:51:29 +01:00
parent cd88f49469
commit f61723599e
13 changed files with 165 additions and 473 deletions
+15 -1
View File
@@ -8,6 +8,7 @@ import * as _rollupMoment from 'moment';
import { NgxMatDateFormats } from '@angular-material-components/datetime-picker';
const moment = _rollupMoment || _moment;
import { NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker';
import { SqliteService } from 'src/app/services/sqlite.service';
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
@@ -37,7 +38,8 @@ export class AppComponent {
private platform: Platform,
/* private splashScreen: SplashScreen, */
private statusBar: StatusBar,
private screenOrientation: ScreenOrientation
private screenOrientation: ScreenOrientation,
private sqliteservice: SqliteService
) {
this.initializeApp();
}
@@ -51,7 +53,19 @@ export class AppComponent {
this.screenOrientation.unlock();
} else if( this.platform.is("mobile")) {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT_PRIMARY);
console.log('Orientation locked')
}
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
try {
this.sqliteservice.databaseConn();
} catch (error) {
console.log("Error creating local database: ", error)
}
}
});
}
}
+3 -1
View File
@@ -65,6 +65,8 @@ import { Media } from '@ionic-native/media/ngx';
import { StreamingMedia } from '@ionic-native/streaming-media/ngx';
import { PhotoViewer } from '@ionic-native/photo-viewer/ngx';
import { FCM } from '@ionic-native/fcm/ngx';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
@@ -111,7 +113,7 @@ import { PhotoViewer } from '@ionic-native/photo-viewer/ngx';
//File,
WebView,
FilePath,
//FCM,
FCM,
WebsocketService,
ChatService,
ScreenOrientation,
+6 -5
View File
@@ -1,7 +1,7 @@
/* eslint-disable */
/* tslint:disable */
///<reference path="../../../plugins/cordova-plugin-mfp/typings/worklight.d.ts" />
///<reference path="../../../plugins/cordova-plugin-mfp-push/typings/mfppush.d.ts" />
/* ///<reference path="../../../plugins/cordova-plugin-mfp-push/typings/mfppush.d.ts" /> */
import { Component, OnInit, NgZone } from '@angular/core';
import { Event } from '../models/event.model';
import { NotificationsService } from '../services/notifications.service';
@@ -123,8 +123,9 @@ export class HomePage implements OnInit {
this.webnotification.webconnection();
this.webnotification.register();
} else {
this.mobilefirstConnect();
this.notificationsService.onReceviNotification();
//this.mobilefirstConnect();
//this.notificationsService.onReceviNotification();
this.offlinemanager.synchnize()
}
});
@@ -144,7 +145,7 @@ export class HomePage implements OnInit {
myWorker.postMessage('ali');
}
mobilefirstConnect() {
/* mobilefirstConnect() {
console.log("Mobileconecct");
@@ -175,11 +176,11 @@ export class HomePage implements OnInit {
/* this.zone.run(() => {
console.log("Bummer...");
console.log("Failed to connect to MobileFirst Server");
}); */
});
});
}
}
}
} */
+1 -1
View File
@@ -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 { Component, OnInit, NgZone } from '@angular/core';
import { Router, NavigationExtras } from '@angular/router';
import { AnimationController, ModalController,Platform } from '@ionic/angular';
+1
View File
@@ -735,6 +735,7 @@ export class AgendaPage implements OnInit {
Profile: profile
}
this.sqliteservice.addEvent(event)
});
}
}
+25 -26
View File
@@ -78,7 +78,7 @@ export class EventsPage implements OnInit {
loggeduser: LoginUserRespose;
existingScreenOrientation: string;
/* existingScreenOrientation: string; */
constructor(
private eventService: EventsService,
@@ -97,8 +97,8 @@ export class EventsPage implements OnInit {
private backgroundservice: BackgroundService,
public ThemeService: ThemeService
) {
this.existingScreenOrientation = this.screenOrientation.type;
console.log(this.existingScreenOrientation);
/* this.existingScreenOrientation = this.screenOrientation.type;
console.log(this.existingScreenOrientation); */
this.loggeduser = authService.ValidatedUser;
@@ -109,13 +109,7 @@ export class EventsPage implements OnInit {
// console.log('Resize event detected');
});
try {
this.sqliteservice.databaseConn();
} catch (error) {
console.log("Error creating local database: ", error)
}
window['zipPhoneCallback'] = function (zipphone) {
var frame = document.getElementById('home-iframe');
if(frame) {
@@ -172,22 +166,22 @@ export class EventsPage implements OnInit {
}
// Lock to portrait
lockToPortrait() {
/* lockToPortrait() {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
console.log('set');
}
} */
// Lock to landscape
lockToLandscape() {
/* lockToLandscape() {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
}
} */
// Unlock screen orientation
unlockScreenOrientation() {
/* unlockScreenOrientation() {
this.screenOrientation.unlock();
}
} */
checkScreenOrientation() {
/* checkScreenOrientation() {
if (window.innerWidth < 701) {
this.lockToPortrait();
console.log('was here');
@@ -196,7 +190,7 @@ export class EventsPage implements OnInit {
else {
this.unlockScreenOrientation();
}
}
} */
async RefreshEvents() {
this.currentEvent = "";
@@ -329,6 +323,18 @@ export class EventsPage implements OnInit {
}
}
addProcessToDb(list) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
if (list.length > 0) {
list.forEach(element => {
this.sqliteservice.addProcess(element)
});
}
}
}
getEventsFromLocalDb() {
let date = new Date();
@@ -463,14 +469,7 @@ export class EventsPage implements OnInit {
LoadList() {
this.processes.GetTaskListExpediente(false).subscribe(result => {
console.log("Expediente", result);
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
result.forEach((element) => {
this.sqliteservice.addProcess(element)
})
}
this.addProcessToDb(result);
const ExpedienteTask = result.map(e => this.expedienteTaskPipe.transform(e))
+1 -1
View File
@@ -141,7 +141,7 @@ export class InactivityPage implements OnInit {
}
getToken() {
this.notificatinsservice.getAndpostToken(this.username);
//this.notificatinsservice.getAndpostToken(this.username);
}
setCode(code: string) {
+5 -5
View File
@@ -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)
});
}
} */
}
+70 -6
View File
@@ -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") {
+1
View File
@@ -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,