From d7745a1ed3797d9a16f459bdc0ba222f16a16538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Wed, 3 Nov 2021 12:21:19 +0100 Subject: [PATCH] Some changes --- config.xml | 2 + package-lock.json | 128 ++++++++- package.json | 42 ++- src/app/app.module.ts | 3 + src/app/home/home.page.ts | 93 ++++--- src/app/home/nice.worker.js | 4 +- src/app/pages/events/events.page.ts | 6 + src/app/services/notifications.service.ts | 323 +++++++++++----------- src/app/services/sqlite.service.ts | 9 +- 9 files changed, 392 insertions(+), 218 deletions(-) diff --git a/config.xml b/config.xml index bd410ebfa..9b098f8e2 100644 --- a/config.xml +++ b/config.xml @@ -20,6 +20,7 @@ + @@ -91,4 +92,5 @@ 2 + diff --git a/package-lock.json b/package-lock.json index ae4d69471..a683b2ea7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2235,6 +2235,21 @@ "resolved": "https://registry.npmjs.org/@ionic-native/fingerprint-aio/-/fingerprint-aio-4.20.0.tgz", "integrity": "sha512-DhdXVG7gdBtCwYHDAsNazIcMlyt6X968ilA/5Rt8uFd+xN4Un5gZteOJCVn9xWDC/ZqhO/QAq2M0BIGyEhzW0g==" }, + "@ionic-native/firebase-x": { + "version": "5.36.0", + "resolved": "https://registry.npmjs.org/@ionic-native/firebase-x/-/firebase-x-5.36.0.tgz", + "integrity": "sha512-h6jfTFqvABwugir5tsAzyvUWdu0EZg1PnWW0EkQy3CRg/qQlcjiDJW8pqyq1l84UDJQ7fxiTvbmX0Jod2BFE3w==", + "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/http": { "version": "5.36.0", "resolved": "https://registry.npmjs.org/@ionic-native/http/-/http-5.36.0.tgz", @@ -5288,6 +5303,15 @@ } } }, + "bplist-creator": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/bplist-creator/-/bplist-creator-0.1.0.tgz", + "integrity": "sha512-sXaHZicyEEmY86WyueLTQesbeoH/mquvarJaQNbjuOQO+7gbFcDEWqKmcWA4cOTLzFlfgvkiVxolk1k5bBIpmg==", + "dev": true, + "requires": { + "stream-buffers": "2.2.x" + } + }, "bplist-parser": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/bplist-parser/-/bplist-parser-0.2.0.tgz", @@ -6963,10 +6987,9 @@ "integrity": "sha1-C8ZXVyduvZIMASzpIOJ0F3V2Nz4=", "dev": true }, - "cordova-plugin-crosswalk-webview": { - "version": "git+https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview.git#58dda06c97609c6a0699b8d0691ad603901625ce", - "from": "git+https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview.git", - "dev": true + "cordova-plugin-dbcopy": { + "version": "git+https://github.com/an-rahulpandey/cordova-plugin-dbcopy.git#861f585e4313db828d6b8c7d354c32c83373d0d2", + "from": "git+https://github.com/an-rahulpandey/cordova-plugin-dbcopy.git" }, "cordova-plugin-device": { "version": "2.0.3", @@ -6981,12 +7004,20 @@ "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==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/cordova-plugin-fcm-with-dependecy-updated/-/cordova-plugin-fcm-with-dependecy-updated-7.2.0.tgz", + "integrity": "sha512-Iv1gOeoQ4l/1ztBLemgLOCS4iaVemHezfpa5/X+iqS4apfvUVLJ47Vw6KO7deBO2d2ElvrGZ2ayZX7j3uhtsRw==", "dev": true, "requires": { - "typescript": "^4.1.3" + "typescript": "^3.9.6" + }, + "dependencies": { + "typescript": { + "version": "3.9.10", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", + "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", + "dev": true + } } }, "cordova-plugin-file": { @@ -7006,6 +7037,18 @@ "integrity": "sha512-Mmm/Ee85s4JH7qL3yikQ2J2I2vY2XbNi1fttoEK2kI++YHr/WeqPHWGREFL7bmFYjZTph/JovhfWHPGV924WjQ==", "dev": true }, + "cordova-plugin-firebasex": { + "version": "13.0.1", + "resolved": "https://registry.npmjs.org/cordova-plugin-firebasex/-/cordova-plugin-firebasex-13.0.1.tgz", + "integrity": "sha512-p9V8tJzT5ouRKhfz9Vo6uEdv0BvMJldXBrrw61H/0smT5JzJFcHu/BekhbIsF5yrpBSIwdSK15JA04JA4EtL3w==", + "dev": true, + "requires": { + "plist": "^3.0.1", + "semver": "^7.3.2", + "xcode": "^3.0.1", + "xml-js": "^1.6.11" + } + }, "cordova-plugin-globalization": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/cordova-plugin-globalization/-/cordova-plugin-globalization-1.11.0.tgz", @@ -10139,6 +10182,12 @@ "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", "dev": true }, + "es6-promise-plugin": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/es6-promise-plugin/-/es6-promise-plugin-4.2.2.tgz", + "integrity": "sha512-uoA4aVplXI9oqUYJFBAVRwAqIN9/n9JgrTAUGX3qPbnSZVE5yY1+6/MsoN5f4xsaPO62WjPHOdtts6okMN6tNA==", + "dev": true + }, "es6-promisify": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", @@ -21053,6 +21102,28 @@ } } }, + "simple-plist": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/simple-plist/-/simple-plist-1.3.0.tgz", + "integrity": "sha512-uYWpeGFtZtVt2NhG4AHgpwx323zxD85x42heMJBan1qAiqqozIlaGrwrEt6kRjXWRWIXsuV1VLCvVmZan2B5dg==", + "dev": true, + "requires": { + "bplist-creator": "0.1.0", + "bplist-parser": "0.3.0", + "plist": "^3.0.4" + }, + "dependencies": { + "bplist-parser": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/bplist-parser/-/bplist-parser-0.3.0.tgz", + "integrity": "sha512-zgmaRvT6AN1JpPPV+S0a1/FAtoxSreYDccZGIqEMSvZl9DMe70mJ7MFzpxa1X+gHVdkToE2haRUHHMiW1OdejA==", + "dev": true, + "requires": { + "big-integer": "1.6.x" + } + } + } + }, "simple-swizzle": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", @@ -21624,6 +21695,12 @@ "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" }, + "stream-buffers": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/stream-buffers/-/stream-buffers-2.2.0.tgz", + "integrity": "sha1-kdX1Ew0c75bc+n9yaUUYh0HQnuQ=", + "dev": true + }, "stream-throttle": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/stream-throttle/-/stream-throttle-0.1.3.tgz", @@ -25031,11 +25108,46 @@ "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz", "integrity": "sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w==" }, + "xcode": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/xcode/-/xcode-3.0.1.tgz", + "integrity": "sha512-kCz5k7J7XbJtjABOvkc5lJmkiDh8VhjVCGNiqdKCscmVpdVUpEAyXv1xmCLkQJ5dsHqx3IPO4XW+NTDhU/fatA==", + "dev": true, + "requires": { + "simple-plist": "^1.1.0", + "uuid": "^7.0.3" + }, + "dependencies": { + "uuid": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.3.tgz", + "integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==", + "dev": true + } + } + }, "xdg-basedir": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==" }, + "xml-js": { + "version": "1.6.11", + "resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz", + "integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==", + "dev": true, + "requires": { + "sax": "^1.2.4" + }, + "dependencies": { + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", + "dev": true + } + } + }, "xml-name-validator": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", diff --git a/package.json b/package.json index 980b14a9c..1fcb3461e 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@ionic-native/file": "^5.36.0", "@ionic-native/file-path": "^5.30.0", "@ionic-native/fingerprint-aio": "^4.20.0", + "@ionic-native/firebase-x": "^5.36.0", "@ionic-native/http": "^5.31.1", "@ionic-native/image-picker": "^5.36.0", "@ionic-native/in-app-browser": "^5.28.0", @@ -79,6 +80,7 @@ "build": "0.1.4", "ci": "^2.1.1", "cordova": "^10.0.0", + "cordova-plugin-dbcopy": "git+https://github.com/an-rahulpandey/cordova-plugin-dbcopy.git", "cordova-plugin-filepath": "^1.5.8", "cordova-plugin-okhttp": "^2.0.0", "cordova-res": "^0.15.3", @@ -141,12 +143,12 @@ "cordova-plugin-androidx": "^3.0.0", "cordova-plugin-androidx-adapter": "^1.1.3", "cordova-plugin-compat": "^1.2.0", - "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-fcm-with-dependecy-updated": "^7.2.0", "cordova-plugin-file": "^6.0.2", "cordova-plugin-fingerprint-aio": "^4.0.2", + "cordova-plugin-firebasex": "^13.0.1", "cordova-plugin-globalization": "^1.11.0", "cordova-plugin-inappbrowser": "^4.0.0", "cordova-plugin-ionic-keyboard": "^2.2.0", @@ -161,6 +163,7 @@ "cordova-plugin-streaming-media": "^2.3.0", "cordova-plugin-telerik-imagepicker": "^2.3.6", "cordova-plugin-whitelist": "^1.3.4", + "es6-promise-plugin": "^4.2.2", "jasmine-core": "~3.6.0", "jasmine-spec-reporter": "~5.0.0", "jest": "^27.0.6", @@ -195,13 +198,36 @@ "cordova-plugin-screen-orientation": {}, "cordova-plugin-network-information": {}, "cordova-plugin-file": {}, + "cordova-plugin-firebasex": { + "FIREBASE_ANALYTICS_COLLECTION_ENABLED": "true", + "FIREBASE_PERFORMANCE_COLLECTION_ENABLED": "true", + "FIREBASE_CRASHLYTICS_COLLECTION_ENABLED": "true", + "ANDROID_ICON_ACCENT": "#FF00FFFF", + "ANDROID_FIREBASE_PERFORMANCE_MONITORING": "false", + "ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION": "17.0.0", + "ANDROID_PLAY_SERVICES_AUTH_VERSION": "19.0.0", + "ANDROID_FIREBASE_ANALYTICS_VERSION": "19.0.0", + "ANDROID_FIREBASE_MESSAGING_VERSION": "22.0.0", + "ANDROID_FIREBASE_CONFIG_VERSION": "21.0.0", + "ANDROID_FIREBASE_PERF_VERSION": "20.0.2", + "ANDROID_FIREBASE_AUTH_VERSION": "21.0.1", + "ANDROID_FIREBASE_INAPPMESSAGING_VERSION": "20.0.0", + "ANDROID_FIREBASE_FIRESTORE_VERSION": "23.0.2", + "ANDROID_FIREBASE_FUNCTIONS_VERSION": "20.0.0", + "ANDROID_FIREBASE_IID_VERSION": "21.1.0", + "ANDROID_FIREBASE_INSTALLATIONS_VERSION": "17.0.0", + "ANDROID_FIREBASE_CRASHLYTICS_VERSION": "18.1.0", + "ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION": "18.1.0", + "ANDROID_GSON_VERSION": "2.8.7", + "ANDROID_FIREBASE_PERF_GRADLE_PLUGIN_VERSION": "1.4.0" + }, "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" - } + "ANDROID_FCM_VERSION": "19.0.0", + "ANDROID_GRADLE_TOOLS_VERSION": "3.5.3", + "ANDROID_GOOGLE_SERVICES_VERSION": "4.3.3", + "ANDROID_DEFAULT_NOTIFICATION_ICON": "@mipmap/ic_launcher" + }, + "cordova-plugin-dbcopy": {} }, "platforms": [ "browser", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 780a22405..22ca48f4a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -66,6 +66,8 @@ import { StreamingMedia } from '@ionic-native/streaming-media/ngx'; import { PhotoViewer } from '@ionic-native/photo-viewer/ngx'; import { FCM } from '@ionic-native/fcm/ngx'; +import { FirebaseX } from '@ionic-native/firebase-x/ngx'; +//import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx'; @NgModule({ declarations: [AppComponent], @@ -114,6 +116,7 @@ import { FCM } from '@ionic-native/fcm/ngx'; WebView, FilePath, FCM, + FirebaseX, WebsocketService, ChatService, ScreenOrientation, diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index dee9340a9..f989804a9 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -26,6 +26,8 @@ import { Storage } from '@ionic/storage'; import { EventsService } from 'src/app/services/events.service'; import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx'; +import { FirebaseX } from '@ionic-native/firebase-x/ngx'; + @Component({ selector: 'app-home', @@ -86,7 +88,8 @@ export class HomePage implements OnInit { private offlinemanager: OfflineManagerService, private storage: Storage, private eventservice: EventsService, - private screenOrientation: ScreenOrientation) { + private screenOrientation: ScreenOrientation, + private firebaseX: FirebaseX) { this.webNotificationPopupService.askNotificationPermission() @@ -116,6 +119,18 @@ export class HomePage implements OnInit { ngOnInit() { + this.notificationsService.onReceviNotification(); + + this.firebaseX.getToken() + .then(token => console.log(`The token is ${token}`)) // save the token server-side and use it to push notifications to this device + .catch(error => console.error('Error getting token', error)); + + this.firebaseX.onMessageReceived() + .subscribe(data => console.log(`User opened a notification ${data}`)); + + this.firebaseX.onTokenRefresh() + .subscribe((token: string) => console.log(`Got a new token ${token}`)); + window.addEventListener('online', () => { console.log('Became online') this.backgroundservice.online() @@ -136,51 +151,51 @@ export class HomePage implements OnInit { this.updateList() - var myWorker = new Worker(new URL('./nice.worker.js', import.meta.url)); + /* var myWorker = new Worker(new URL('./nice.worker.js', import.meta.url)); myWorker.onmessage = function (oEvent) { console.log('Worker said : ' + oEvent.data); } - myWorker.postMessage('ali'); + myWorker.postMessage('ali'); */ } - /* mobilefirstConnect() { - - console.log("Mobileconecct"); - - if (window['WLAuthorizationManager']) { - if (window['WLAuthorizationManager'].obtainAccessToken) { - window['WLAuthorizationManager'].obtainAccessToken("").then((token) => { - - console.log('MobileFirst Server connect: Success ' + token); - - var resourceRequest = new WLResourceRequest("/adapters/javaAdapter/resource/greet/", - WLResourceRequest.GET - ); - - resourceRequest.setQueryParameter("name", "world"); - resourceRequest.send().then( - (response) => { - // Will display "Hello world" in an alert dialog. - console.log("Connect with JavaAdapter Success: " + response.responseText); - //this.MFPushNotification(); - }, - (error) => { - console.log("Connect with JavaAdapter Failure: " + JSON.stringify(error)); - } - ); - }, (error) => { - console.log('MobileFirst Server connect: failure ' + error.responseText); - console.log(JSON.stringify(error)) - /* this.zone.run(() => { - console.log("Bummer..."); - console.log("Failed to connect to MobileFirst Server"); - }); - }); - } - } - } */ + /* mobilefirstConnect() { + + console.log("Mobileconecct"); + + if (window['WLAuthorizationManager']) { + if (window['WLAuthorizationManager'].obtainAccessToken) { + window['WLAuthorizationManager'].obtainAccessToken("").then((token) => { + + console.log('MobileFirst Server connect: Success ' + token); + + var resourceRequest = new WLResourceRequest("/adapters/javaAdapter/resource/greet/", + WLResourceRequest.GET + ); + + resourceRequest.setQueryParameter("name", "world"); + resourceRequest.send().then( + (response) => { + // Will display "Hello world" in an alert dialog. + console.log("Connect with JavaAdapter Success: " + response.responseText); + //this.MFPushNotification(); + }, + (error) => { + console.log("Connect with JavaAdapter Failure: " + JSON.stringify(error)); + } + ); + }, (error) => { + console.log('MobileFirst Server connect: failure ' + error.responseText); + console.log(JSON.stringify(error)) + /* this.zone.run(() => { + console.log("Bummer..."); + console.log("Failed to connect to MobileFirst Server"); + }); + }); + } + } + } */ diff --git a/src/app/home/nice.worker.js b/src/app/home/nice.worker.js index ce71defff..508e44345 100644 --- a/src/app/home/nice.worker.js +++ b/src/app/home/nice.worker.js @@ -1,5 +1,5 @@ -postMessage("I\'m working before postMessage(\'ali\')."); +/* postMessage("I\'m working before postMessage(\'ali\')."); onmessage = function(oEvent) { postMessage('Hi ' + oEvent.data); -}; \ No newline at end of file +}; */ \ No newline at end of file diff --git a/src/app/pages/events/events.page.ts b/src/app/pages/events/events.page.ts index bae0452a5..5648ca0f7 100644 --- a/src/app/pages/events/events.page.ts +++ b/src/app/pages/events/events.page.ts @@ -121,6 +121,12 @@ export class EventsPage implements OnInit { ngOnInit() { + try { + this.sqliteservice.databaseConn(); + } catch (error) { + console.log("Error creating local database: ", error) + } + this.segment = "Combinada"; this.profile = "mdgpr"; diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts index 4cb62c7cb..b24689d0b 100644 --- a/src/app/services/notifications.service.ts +++ b/src/app/services/notifications.service.ts @@ -9,7 +9,7 @@ import { StorageService } from 'src/app/services/storage.service'; import { AuthConnstants } from 'src/app/config/auth-constants'; import { Token } 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'; @@ -18,6 +18,7 @@ import { EventTrigger } from '../services/eventTrigger.service'; import { SessionStore } from '../store/session.service'; import { FCM } from '@ionic-native/fcm/ngx'; +//import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx'; @Injectable({ providedIn: 'root' @@ -41,38 +42,38 @@ 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 fcm: FCM) { + private fcm: FCM) { - this.storageService.get("Notifications").then((value) => { - - }).catch(()=>{ + this.storageService.get("Notifications").then((value) => { - 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); } @@ -88,36 +89,36 @@ export class NotificationsService { } getAndpostToken(username) { - if(this.platform.is('desktop') || this.platform.is('mobileweb')) { + 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 - }; + 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); + }) + }); - this.http.post(`${geturl}`, body, { headers }).subscribe(data => { - console.log('TOKEN USER MIDLE', data); - }) }); - }); - }); } - + } async onReceviNotification() { @@ -127,15 +128,19 @@ export class NotificationsService { this.notificatinsRoutes(data) - } /* else { + } else { console.log("Received in foreground: ", data); console.log(data.Service) console.log(data.Object) console.log(data.IdObject) - this.openApproveModal(data.IdObject); - - }; */ + + /* this.DataArray.push(data) + console.log("On ReceiveNotification", this.DataArray) + this.storageService.store("Notifications", this.DataArray) */ + + + }; }); } @@ -148,56 +153,122 @@ export class NotificationsService { return this.http.get(`${geturl}`); } */ -/* getAndpostToken(username) { + /* 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(`${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)); + } + ); + } + } + + } + + } */ - if (this.platform.is('desktop') || this.platform.is('mobileweb')) { - //console.log('Notifications not supported') - } else { + tempClearArray() { + this.DataArray = []; + } - const geturl = environment.apiURL + 'notifications/token'; + /* 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(`${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)); @@ -205,120 +276,54 @@ export class NotificationsService { ); } } - - } - - } */ - - 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)); - } - ); - } - } - - - } */ + + + } */ notificatinsRoutes = (data) => { if (data.Service === "agenda") { this.zone.run(() => this.router.navigate(['/home/agenda', data.IdObject, 'agenda'])); } else if (data.Service === "gabinete-digital" && data.Object === "expediente") { - this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente',data.IdObject,'gabinete-digital'])); + 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") { + this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', data.IdObject, 'agenda'])); + } else if (data.Service === "gabinete-digital" && data.Object === "despachos") { - 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', data.IdObject, 'gabinete-digital'], { replaceUrl: true })); } else if (data.Service === "gabinete-digital" && data.Object === "parecer") { - this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos',data.IdObject,'gabinete-digital'])); + this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', data.IdObject, 'gabinete-digital'])); } else if (data.Service === "gabinete-digital" && data.Object === "deferimento") { - this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos',data.IdObject,'gabinete-digital'])); + this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', data.IdObject, 'gabinete-digital'])); } 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'])); + this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', data.IdObject, 'gabinete-digital'])); } else if (data.Service === "accoes" && data.Object === "accao") { - this.zone.run(() => this.router.navigate(['/home/publications',data.IdObject])); + 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])); + 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'])); + this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', data.IdObject, 'gabinete-digital'])); } else if (data.Service === "gabinete-digital" && data.Object === "diplomas-assinar") { let navigationExtras: NavigationExtras = { queryParams: { - "serialNumber": data.IdObject, + "serialNumber": 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'])); + this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', data.IdObject, 'gabinete-digital'])); } } diff --git a/src/app/services/sqlite.service.ts b/src/app/services/sqlite.service.ts index 2330d7aaf..c7ef44e7a 100644 --- a/src/app/services/sqlite.service.ts +++ b/src/app/services/sqlite.service.ts @@ -25,11 +25,14 @@ 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) => { @@ -126,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) }); } }