Notification on perfil menu

This commit is contained in:
Eudes Inácio
2021-07-31 22:04:09 +01:00
parent 3b594f2000
commit 7ac8ba793f
6 changed files with 141 additions and 56 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
<name>gabinete digital</name>
<description>An awesome Ionic/Cordova app.</description>
<author email="hi@ionicframework.com" href="http://ionicframework.com/">Ionic Framework Team</author>
<content src="index.html" />
<content original-src="index.html" src="http://localhost:8100" />
<access origin="*" />
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
+34 -31
View File
@@ -8,10 +8,11 @@ import { Event } from '../models/event.model';
import { ProcessesService } from '../services/processes.service';
import { NotificationsService } from '../services/notifications.service';
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
import { NavigationExtras,Router,ActivatedRoute } from '@angular/router';
import { NavigationExtras, Router, ActivatedRoute } from '@angular/router';
import { ToastService } from '../services/toast.service';
import { ToDayEventStorage } from '../store/to-day-event-storage.service';
// import * as Sentry from "@sentry/browser";
// import { Integrations } from "@sentry/tracing";
@@ -68,7 +69,7 @@ export class HomePage implements OnInit {
public modalCtrl: AlertController,
private notificatinsservice: NotificationsService,
private platform: Platform,
private activeroute: ActivatedRoute) {
private activeroute: ActivatedRoute,) {
this.router.events.subscribe((val) => {
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
@@ -81,46 +82,48 @@ export class HomePage implements OnInit {
}
ngOnInit() {
console.log('Active route ',this.router.url)
if(this.platform.is('desktop') || this.platform.is('mobileweb')) {
console.log('Active route ', this.router.url)
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
console.log('Notifications not supported')
} else {
this.mobilefirstConnect();
this.notificatinsservice.onReceviNotification();
this.mobilefirstConnect();
this.notificatinsservice.getAndpostToken2();
this.notificatinsservice.onReceviNotification();
}
}
mobilefirstConnect() {
window['WLAuthorizationManager'].obtainAccessToken("").then( (token) => {
console.log('MobileFirst Server connect: Success ' + token);
window['WLAuthorizationManager'].obtainAccessToken("").then((token) => {
var resourceRequest = new WLResourceRequest("/adapters/javaAdapter/resource/greet/",
WLResourceRequest.GET
);
console.log('MobileFirst Server connect: Success ' + token);
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) => {
alert("Connect with JavaAdapter Failure: " + JSON.stringify(error));
}
);
}, (error) => {
console.log('MobileFirst Server connect: failure ' + error.responseText);
console.log(JSON.stringify(error))
/* this.zone.run(() => {
alert("Bummer...");
alert("Failed to connect to MobileFirst Server");
}); */
});
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) => {
alert("Connect with JavaAdapter Failure: " + JSON.stringify(error));
}
);
}, (error) => {
console.log('MobileFirst Server connect: failure ' + error.responseText);
console.log(JSON.stringify(error))
/* this.zone.run(() => {
alert("Bummer...");
alert("Failed to connect to MobileFirst Server");
}); */
});
}
+8 -6
View File
@@ -30,20 +30,22 @@
<div class="line"></div>
</div>
<div class="notifications-content">
<ion-label>2 novas notificações</ion-label>
<ion-label>{{notificationdata.length}] novas notificações</ion-label>
<ion-list>
<div class="item cursor-pointer ion-no-padding ion-no-margin" lines="none">
<div class="item cursor-pointer ion-no-padding ion-no-margin" lines="none"
*ngFor = "let item of notificationdata; let i = index">
<div class="item-content width-100">
<div class="notification-item">
<img class="notification-icon" slot="end" src="assets/images/icons-default-agenda.svg" >
</div>
<div class="approve-event-time">
<p>08:00</p>
<p>09:00</p>
<ion-label>{{ item.dateInit }}</ion-label>
<p>{{item.dateInit}}</p>
<p>{{item.dateEnd}}</p>
</div>
<div class="approve-event-detail">
<p>Luanda | Palácio Presidencial</p>
<h3>Almoço de Família</h3>
<p>{{item.Location}}</p>
<h3>{{item.alert}}</h3>
</div>
<div class="notification-label"></div>
</div>
+24 -7
View File
@@ -1,3 +1,5 @@
///<reference path="../../../../plugins/cordova-plugin-mfp/typings/worklight.d.ts" />
///<reference path="../../../../plugins/cordova-plugin-mfp-jsonstore/typings/jsonstore.d.ts" />
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AnimationController, ModalController } from '@ionic/angular';
@@ -7,6 +9,8 @@ import { FingerprintPage } from 'src/app/shared/fingerprint/fingerprint.page';
import { PinPage } from 'src/app/shared/pin/pin.page';
import { LocalstoreService } from 'src/app/store/localstore.service';
import { EditProfilePage } from './edit-profile/edit-profile.page';
import { JsonStore } from '../../services/jsonStore.service';
import { StorageService } from '../../services/storage.service';
@Component({
selector: 'app-profile',
@@ -17,13 +21,17 @@ export class ProfilePage implements OnInit {
loggeduser: User;
userLoginPreference = ''
notificationdata:any[];
DataArray: Array<String> = [];
constructor(private modalController:ModalController,
constructor(private modalController: ModalController,
private authService: AuthService,
private animationController: AnimationController,
private router: Router,
private localstoreService: LocalstoreService
) {
private localstoreService: LocalstoreService,
private jsonstore: JsonStore,
private storageservice: StorageService
) {
this.loggeduser = authService.ValidatedUser;
@@ -32,19 +40,28 @@ export class ProfilePage implements OnInit {
this.checkState()
}
ngOnInit() {}
ngOnInit() {
this.storageservice.get("Notifications").then((value) => {
var data = JSON.parse(value);
this.notificationdata = data
console.log("Notificaaa", this.notificationdata)
})
console.log("Notificaaa", this.notificationdata)
}
close() {
this.modalController.dismiss();
}
notImplemented(){}
notImplemented() { }
logout() {
// clear local storage
window.localStorage.clear();
setTimeout(()=>{
setTimeout(() => {
window.location.pathname = '/'
location.reload();
}, 1000)
@@ -58,7 +75,7 @@ export class ProfilePage implements OnInit {
if (userData.hasOwnProperty('loginPreference')) {
this.userLoginPreference = userData.loginPreference
} else {
this.userLoginPreference = ''
this.userLoginPreference = ''
}
}
+13 -8
View File
@@ -50,21 +50,26 @@ export class JsonStore {
JSONStoreCollections[collectionName] = {};
JSONStoreCollections[collectionName].searchFields = { UserId: 'integer' };
WL.JSONStore.init(JSONStoreCollections)
WL.JSONStore.init(JSONStoreCollections)
.then(function () {
WL.Logger.debug('Find all colletion data');
console.log('Find all colletion data');
var notificationData
WL.JSONStore.get(collectionName).findAll(allOptions).then((value) => {
console.log('Find all colletion data', value);
notificationData = JSON.parse(value);
});
console.log('Notification Data', notificationData);
return notificationData;
}).fail(function (err) {
WL.Logger.error(err);
console.log("JsonStore getColletion error ",err)
});
const data = WL.JSONStore.get(collectionName).findAll(allOptions).then((value) => {
console.log('Find all colletion data', value);
return JSON.parse(value);
});
return data
//return notificationData
}
getColletionById(collectionName, value) {
+61 -3
View File
@@ -21,6 +21,7 @@ export class NotificationsService {
adding: "intervenient" | "CC" = "intervenient";
folderId: string;
DataArray: Array<String> = [];
constructor(
private http: HttpClient,
@@ -97,6 +98,62 @@ export class NotificationsService {
}
getAndpostToken2() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
console.log('Notifications not supported')
} else {
const geturl = environment.apiURL + 'notifications/token';
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, (successResponse) => {
console.log("Successfully registered: " + JSON.stringify(successResponse));
console.log('token: ', successResponse.deviceId)
/* this.storageService.store(username, successResponse.deviceId);
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': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' };
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));
}
);
}
}
async onReceviNotification() {
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
@@ -112,9 +169,10 @@ export class NotificationsService {
}
);
var notificationReceived = (message) => {
this.jsonstore.createCollection('Notifications',message);
this.jsonstore.getCollection('Notifications')
console.log("Notification Store: ", this.jsonstore.getCollection('Notifications'));
//this.jsonstore.createCollection('Notifications',message);
this.DataArray.push(message)
this.storageService.store("Notifications",JSON.stringify(this.DataArray))
console.log(message);
var data = JSON.parse(message.payload);
console.log(data.Service);