From f61723599e753d40cf7afbbaaf13bea677bd9477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Sat, 30 Oct 2021 16:51:29 +0100 Subject: [PATCH] Remove IBM push notification and jsonstore, added cordova notifications --- config.xml | 4 +- package-lock.json | 443 ++------------------ package.json | 17 +- src/app/app.component.ts | 16 +- src/app/app.module.ts | 4 +- src/app/home/home.page.ts | 11 +- src/app/modals/profile/profile.page.ts | 2 +- src/app/pages/agenda/agenda.page.ts | 1 + src/app/pages/events/events.page.ts | 51 ++- src/app/pages/inactivity/inactivity.page.ts | 2 +- src/app/services/jsonStore.service.ts | 10 +- src/app/services/notifications.service.ts | 76 +++- src/app/services/sqlite.service.ts | 1 + 13 files changed, 165 insertions(+), 473 deletions(-) diff --git a/config.xml b/config.xml index d778d7312..bd410ebfa 100644 --- a/config.xml +++ b/config.xml @@ -47,7 +47,7 @@ - 1109370933 + 3077110622 3619450036 @@ -81,7 +81,7 @@ 0 - 8.0.0.00-20210308-063916 + 8.0.0.00-20210905-154328 diff --git a/package-lock.json b/package-lock.json index a8bc50374..ae4d69471 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2192,6 +2192,21 @@ "@types/cordova": "^0.0.34" } }, + "@ionic-native/fcm": { + "version": "5.36.0", + "resolved": "https://registry.npmjs.org/@ionic-native/fcm/-/fcm-5.36.0.tgz", + "integrity": "sha512-hToPT/4lqdaCc99sUYgnHM+DSFTe4WphF7Ia00QtwsNGW5/pS8w9iZSgppij5OJtwe67dNsuf2+PkxS4r7av/g==", + "requires": { + "@types/cordova": "^0.0.34" + }, + "dependencies": { + "@types/cordova": { + "version": "0.0.34", + "resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-0.0.34.tgz", + "integrity": "sha1-6nrd907Ow9dimCegw54smt3HPQQ=" + } + } + }, "@ionic-native/file": { "version": "5.36.0", "resolved": "https://registry.npmjs.org/@ionic-native/file/-/file-5.36.0.tgz", @@ -6965,6 +6980,15 @@ "integrity": "sha512-FUHI6eEVeoz2VkxbF0P56QlUQLGzXcvw3i4xuXyM9gEct6Y+FA3Xzgl2pJTZcTg5wRqLWzN08kgNoHPkom15pw==", "dev": true }, + "cordova-plugin-fcm-with-dependecy-updated": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/cordova-plugin-fcm-with-dependecy-updated/-/cordova-plugin-fcm-with-dependecy-updated-7.8.0.tgz", + "integrity": "sha512-p2pbY1oqQ2UDbaWOWA2z84uMXmdDGYmK2O+mrufj1bZyoFodt7WqrtiB9oDnUuSSinMrdNFrupiWEDMSBSNVeQ==", + "dev": true, + "requires": { + "typescript": "^4.1.3" + } + }, "cordova-plugin-file": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/cordova-plugin-file/-/cordova-plugin-file-6.0.2.tgz", @@ -8524,425 +8548,6 @@ } } }, - "cordova-plugin-mfp-jsonstore": { - "version": "8.0.2021090603", - "resolved": "https://registry.npmjs.org/cordova-plugin-mfp-jsonstore/-/cordova-plugin-mfp-jsonstore-8.0.2021090603.tgz", - "integrity": "sha512-a8IqMSTkkGXe3bq0n8OamufVhcTHRX5EgZlA6kS+uy4m40h3BeaL78LglyW8Y5BJOVI5evJyTNt8FqI8qPPgdw==", - "dev": true, - "requires": { - "ibm-strings": "~0.1.0", - "mfp-config-xml": "0.0.5", - "npmlog": "0.0.6", - "shelljs": "0.3.0", - "xcode": "0.8.7" - }, - "dependencies": { - "abbrev": { - "version": "1.1.1", - "bundled": true, - "dev": true - }, - "ansi": { - "version": "0.3.1", - "bundled": true, - "dev": true - }, - "are-we-there-yet": { - "version": "1.0.6", - "bundled": true, - "dev": true, - "requires": { - "delegates": "^1.0.0", - "readable-stream": "^2.0.0 || ^1.1.13" - } - }, - "balanced-match": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "base64-js": { - "version": "0.0.6", - "bundled": true, - "dev": true - }, - "bplist-creator": { - "version": "0.0.4", - "bundled": true, - "dev": true, - "requires": { - "stream-buffers": "~0.2.3" - } - }, - "bplist-parser": { - "version": "0.0.6", - "bundled": true, - "dev": true - }, - "brace-expansion": { - "version": "1.1.11", - "bundled": true, - "dev": true, - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "colors": { - "version": "1.1.2", - "bundled": true, - "dev": true - }, - "concat-map": { - "version": "0.0.1", - "bundled": true, - "dev": true - }, - "core-util-is": { - "version": "1.0.3", - "bundled": true, - "dev": true - }, - "delegates": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "elementtree": { - "version": "0.1.6", - "bundled": true, - "dev": true, - "requires": { - "sax": "0.3.5" - } - }, - "extsprintf": { - "version": "1.2.0", - "bundled": true, - "dev": true - }, - "findup-sync": { - "version": "0.3.0", - "bundled": true, - "dev": true, - "requires": { - "glob": "~5.0.0" - }, - "dependencies": { - "glob": { - "version": "5.0.15", - "bundled": true, - "dev": true, - "requires": { - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "2 || 3", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - } - } - }, - "gauge": { - "version": "1.2.7", - "bundled": true, - "dev": true, - "requires": { - "ansi": "^0.3.0", - "has-unicode": "^2.0.0", - "lodash.pad": "^4.1.0", - "lodash.padend": "^4.1.0", - "lodash.padstart": "^4.1.0" - } - }, - "glob": { - "version": "7.0.3", - "bundled": true, - "dev": true, - "requires": { - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "2 || 3", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "has-unicode": { - "version": "2.0.1", - "bundled": true, - "dev": true - }, - "ibm-strings": { - "version": "0.1.4", - "bundled": true, - "dev": true, - "requires": { - "colors": "1.1.2", - "nopt": "3.0.6" - } - }, - "inflight": { - "version": "1.0.6", - "bundled": true, - "dev": true, - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "inherits": { - "version": "2.0.4", - "bundled": true, - "dev": true - }, - "isarray": { - "version": "1.0.0", - "bundled": true, - "dev": true - }, - "lodash-node": { - "version": "2.4.1", - "bundled": true, - "dev": true - }, - "lodash.pad": { - "version": "4.5.1", - "bundled": true, - "dev": true - }, - "lodash.padend": { - "version": "4.6.1", - "bundled": true, - "dev": true - }, - "lodash.padstart": { - "version": "4.6.1", - "bundled": true, - "dev": true - }, - "mfp-config-xml": { - "version": "0.0.5", - "bundled": true, - "dev": true, - "requires": { - "elementtree": "0.1.6", - "findup-sync": "0.3.0", - "glob": "7.0.3", - "ibm-strings": "0.1.4", - "npmlog": "2.0.2", - "q": "1.4.1", - "underscore": "1.8.3", - "verror": "1.6.1" - }, - "dependencies": { - "npmlog": { - "version": "2.0.2", - "bundled": true, - "dev": true, - "requires": { - "ansi": "~0.3.1", - "are-we-there-yet": "~1.0.6", - "gauge": "~1.2.5" - } - } - } - }, - "minimatch": { - "version": "3.0.4", - "bundled": true, - "dev": true, - "requires": { - "brace-expansion": "^1.1.7" - } - }, - "node-uuid": { - "version": "1.4.7", - "bundled": true, - "dev": true - }, - "nopt": { - "version": "3.0.6", - "bundled": true, - "dev": true, - "requires": { - "abbrev": "1" - } - }, - "npmlog": { - "version": "0.0.6", - "bundled": true, - "dev": true, - "requires": { - "ansi": "~0.2.1" - }, - "dependencies": { - "ansi": { - "version": "0.2.1", - "bundled": true, - "dev": true - } - } - }, - "once": { - "version": "1.4.0", - "bundled": true, - "dev": true, - "requires": { - "wrappy": "1" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "bundled": true, - "dev": true - }, - "pegjs": { - "version": "0.6.2", - "bundled": true, - "dev": true - }, - "plist": { - "version": "1.1.0", - "bundled": true, - "dev": true, - "requires": { - "base64-js": "0.0.6", - "util-deprecate": "1.0.0", - "xmlbuilder": "2.2.1", - "xmldom": "0.1.x" - }, - "dependencies": { - "util-deprecate": { - "version": "1.0.0", - "bundled": true, - "dev": true - } - } - }, - "process-nextick-args": { - "version": "2.0.1", - "bundled": true, - "dev": true - }, - "q": { - "version": "1.4.1", - "bundled": true, - "dev": true - }, - "readable-stream": { - "version": "2.3.7", - "bundled": true, - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "safe-buffer": { - "version": "5.1.2", - "bundled": true, - "dev": true - }, - "sax": { - "version": "0.3.5", - "bundled": true, - "dev": true - }, - "shelljs": { - "version": "0.3.0", - "bundled": true, - "dev": true - }, - "simple-plist": { - "version": "0.0.4", - "bundled": true, - "dev": true, - "requires": { - "bplist-creator": "0.0.4", - "bplist-parser": "0.0.6", - "plist": "1.1.0" - } - }, - "stream-buffers": { - "version": "0.2.6", - "bundled": true, - "dev": true - }, - "string_decoder": { - "version": "1.1.1", - "bundled": true, - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - }, - "underscore": { - "version": "1.8.3", - "bundled": true, - "dev": true - }, - "util-deprecate": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "verror": { - "version": "1.6.1", - "bundled": true, - "dev": true, - "requires": { - "core-util-is": "1.0.2", - "extsprintf": "1.2.0" - }, - "dependencies": { - "core-util-is": { - "version": "1.0.2", - "bundled": true, - "dev": true - } - } - }, - "wrappy": { - "version": "1.0.2", - "bundled": true, - "dev": true - }, - "xcode": { - "version": "0.8.7", - "bundled": true, - "dev": true, - "requires": { - "node-uuid": "1.4.7", - "pegjs": "0.6.2", - "simple-plist": "0.0.4" - } - }, - "xmlbuilder": { - "version": "2.2.1", - "bundled": true, - "dev": true, - "requires": { - "lodash-node": "~2.4.1" - } - }, - "xmldom": { - "version": "0.1.31", - "bundled": true, - "dev": true - } - } - }, - "cordova-plugin-mfp-push": { - "version": "8.0.2021062405", - "resolved": "https://registry.npmjs.org/cordova-plugin-mfp-push/-/cordova-plugin-mfp-push-8.0.2021062405.tgz", - "integrity": "sha512-OOSV4TCkZVNfwQzjfbsD0ycNcZyokKdBPJnEK/QrtrGtEA+Ah1R86FphXFNJtCWEQYybCCHvCVXgor4Pgf11xQ==", - "dev": true - }, "cordova-plugin-network-information": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/cordova-plugin-network-information/-/cordova-plugin-network-information-3.0.0.tgz", diff --git a/package.json b/package.json index dd62807a4..980b14a9c 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@fullcalendar/interaction": "^5.3.0", "@ionic-native/camera": "^5.31.1", "@ionic-native/core": "^5.0.7", + "@ionic-native/fcm": "^5.36.0", "@ionic-native/file": "^5.36.0", "@ionic-native/file-path": "^5.30.0", "@ionic-native/fingerprint-aio": "^4.20.0", @@ -143,6 +144,7 @@ "cordova-plugin-crosswalk-webview": "git+https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview.git", "cordova-plugin-device": "^2.0.2", "cordova-plugin-dialogs": "^2.0.2", + "cordova-plugin-fcm-with-dependecy-updated": "^7.8.0", "cordova-plugin-file": "^6.0.2", "cordova-plugin-fingerprint-aio": "^4.0.2", "cordova-plugin-globalization": "^1.11.0", @@ -152,8 +154,6 @@ "cordova-plugin-media": "^5.0.3", "cordova-plugin-media-capture": "^3.0.3", "cordova-plugin-mfp": "^8.0.2021031007", - "cordova-plugin-mfp-jsonstore": "^8.0.2021062408", - "cordova-plugin-mfp-push": "^8.0.2021062405", "cordova-plugin-network-information": "^3.0.0", "cordova-plugin-screen-orientation": "^3.0.2", "cordova-plugin-splashscreen": "^5.0.2", @@ -191,12 +191,17 @@ "cordova-plugin-androidx": {}, "cordova-plugin-androidx-adapter": {}, "cordova-plugin-fingerprint-aio": {}, - "cordova-plugin-mfp-push": {}, - "cordova-plugin-mfp-jsonstore": {}, "cordova-plugin-ionic-webview": {}, "cordova-plugin-screen-orientation": {}, "cordova-plugin-network-information": {}, - "cordova-plugin-file": {} + "cordova-plugin-file": {}, + "cordova-plugin-fcm-with-dependecy-updated": { + "ANDROID_GRADLE_TOOLS_VERSION": "4.1.0", + "ANDROID_GOOGLE_SERVICES_VERSION": "4.3.4", + "ANDROID_DEFAULT_NOTIFICATION_ICON": "@mipmap/ic_launcher", + "ANDROID_FCM_VERSION": "21.0.0", + "ANDROID_FIREBASE_BOM_VERSION": "26.0.0" + } }, "platforms": [ "browser", @@ -209,4 +214,4 @@ "url": "git+https://Kayaya@bitbucket.org/equilibriumito/gabinete-digital.git" }, "license": "ISC" -} +} \ No newline at end of file diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 05cf78fd0..447d26c0d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -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) + } + } + }); } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d2048b241..780a22405 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -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, diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 29b5a962a..dee9340a9 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -1,7 +1,7 @@ /* eslint-disable */ /* tslint:disable */ /// -/// +/* /// */ 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"); - }); */ + }); }); } } - } + } */ diff --git a/src/app/modals/profile/profile.page.ts b/src/app/modals/profile/profile.page.ts index 218084254..57f7bffcb 100644 --- a/src/app/modals/profile/profile.page.ts +++ b/src/app/modals/profile/profile.page.ts @@ -1,5 +1,5 @@ /// -/// +/* /// */ import { Component, OnInit, NgZone } from '@angular/core'; import { Router, NavigationExtras } from '@angular/router'; import { AnimationController, ModalController,Platform } from '@ionic/angular'; diff --git a/src/app/pages/agenda/agenda.page.ts b/src/app/pages/agenda/agenda.page.ts index f1d47b0f3..54cace2f4 100644 --- a/src/app/pages/agenda/agenda.page.ts +++ b/src/app/pages/agenda/agenda.page.ts @@ -735,6 +735,7 @@ export class AgendaPage implements OnInit { Profile: profile } this.sqliteservice.addEvent(event) + }); } } diff --git a/src/app/pages/events/events.page.ts b/src/app/pages/events/events.page.ts index b431827ee..bae0452a5 100644 --- a/src/app/pages/events/events.page.ts +++ b/src/app/pages/events/events.page.ts @@ -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)) diff --git a/src/app/pages/inactivity/inactivity.page.ts b/src/app/pages/inactivity/inactivity.page.ts index 7ae1e66c6..20b3a67c4 100644 --- a/src/app/pages/inactivity/inactivity.page.ts +++ b/src/app/pages/inactivity/inactivity.page.ts @@ -141,7 +141,7 @@ export class InactivityPage implements OnInit { } getToken() { - this.notificatinsservice.getAndpostToken(this.username); + //this.notificatinsservice.getAndpostToken(this.username); } setCode(code: string) { diff --git a/src/app/services/jsonStore.service.ts b/src/app/services/jsonStore.service.ts index 59a25bd7b..a87920299 100644 --- a/src/app/services/jsonStore.service.ts +++ b/src/app/services/jsonStore.service.ts @@ -1,5 +1,5 @@ /// -/// +/* /// */ 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) }); - } + } */ } \ No newline at end of file diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts index 6f7fec31e..4cb62c7cb 100644 --- a/src/app/services/notifications.service.ts +++ b/src/app/services/notifications.service.ts @@ -1,6 +1,6 @@ /* eslint-disable */ /* tslint:disable */ -/// +/* /// */ 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(`${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(`${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") { diff --git a/src/app/services/sqlite.service.ts b/src/app/services/sqlite.service.ts index c1f13cde1..2330d7aaf 100644 --- a/src/app/services/sqlite.service.ts +++ b/src/app/services/sqlite.service.ts @@ -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,