mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Merge branch 'feature/PushNotification_Cordova' into developer
This commit is contained in:
@@ -29,6 +29,8 @@ import { adapterFactory } from 'angular-calendar/date-adapters/date-fns';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { MessagesPage } from './pages/chat/messages/messages.page';
|
||||
|
||||
import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx'
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [AppComponent,MessagesPage,],
|
||||
@@ -55,6 +57,7 @@ import { MessagesPage } from './pages/chat/messages/messages.page';
|
||||
//File,
|
||||
WebView,
|
||||
FilePath,
|
||||
FCM
|
||||
],
|
||||
bootstrap: [AppComponent],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
|
||||
+205
-163
@@ -1,11 +1,20 @@
|
||||
///<reference path="../../../plugins/cordova-plugin-mfp/typings/worklight.d.ts" />
|
||||
import { Component, OnInit, NgZone } from '@angular/core';
|
||||
import { EventsService } from '../services/events.service';
|
||||
import { Event } from '../models/event.model';
|
||||
import { ProcessesService } from '../services/processes.service';
|
||||
import { ModalController } from '@ionic/angular';
|
||||
import { ModalController, AlertController, AnimationController } from '@ionic/angular';
|
||||
//import { AlertController } from 'ionic-angular';
|
||||
/* import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed, Modals } from '@capacitor/core'; */
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx';
|
||||
import { ViewEventPage } from '../pages/agenda/view-event/view-event.page';
|
||||
import { ApproveEventModalPage } from '../pages/agenda/approve-event-modal/approve-event-modal.page';
|
||||
import { ExpedienteDetailPage } from '../pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page';
|
||||
import { PublicationDetailPage } from '../pages/publications/publication-detail/publication-detail.page';
|
||||
import { ViewPublicationsPage } from '../pages/publications/view-publications/view-publications.page';
|
||||
|
||||
/* const { PushNotifications, LocalNotifications, LocalNotificationAction } = Plugins; */
|
||||
|
||||
@Component({
|
||||
@@ -22,133 +31,163 @@ export class HomePage implements OnInit {
|
||||
totalExpediente = 0;
|
||||
profile: string;
|
||||
|
||||
constructor(private zone: NgZone,private eventService: EventsService, private processesbackend: ProcessesService, private router: Router, private modalController: ModalController) {
|
||||
|
||||
adding: "intervenient" | "CC" = "intervenient";
|
||||
mobileComponent = {
|
||||
showAddNewEvent: false,
|
||||
showEditEvent: false,
|
||||
showEventDetails: false,
|
||||
showEventList: false,
|
||||
transparentEventList: false,
|
||||
transparentEventToApprove: false,
|
||||
showEventToApprove: false,
|
||||
showAttendees: false,
|
||||
showAttendeeModal: false
|
||||
}
|
||||
eventToaprove: any = {
|
||||
back: false,
|
||||
serialNumber: "",
|
||||
saveData: {}
|
||||
}
|
||||
selectedEvent: Event;
|
||||
postEvent: any;
|
||||
folderId: string;
|
||||
|
||||
constructor(private zone: NgZone, private eventService: EventsService, private processesbackend: ProcessesService, private router: Router, private modalController: ModalController, public modalCtrl: AlertController, private fcm: FCM, private animationController: AnimationController,) {
|
||||
|
||||
router.events.subscribe((val) => {
|
||||
document.querySelectorAll('ion-modal').forEach((e)=>e.remove())
|
||||
document.querySelectorAll('ion-modal').forEach((e) => e.remove())
|
||||
});
|
||||
|
||||
|
||||
{
|
||||
//this.folderId = this.navParams.get('folderId');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
//Initialize profile as mdgpr
|
||||
|
||||
let date = new Date();
|
||||
date.setMonth(date.getMonth() + 1);
|
||||
let start = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds();
|
||||
let end = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" 23:59:59";
|
||||
|
||||
this.profile = "mdgpr";
|
||||
if (this.profile == "mdgpr") {
|
||||
this.eventService.getAllMdEvents(start, end).subscribe(res => {
|
||||
this.eventsList = res;
|
||||
this.totalEvent = this.eventsList.length;
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.eventService.getAllPrEvents(start, end).subscribe(res => {
|
||||
this.eventsList = res;
|
||||
this.totalEvent = this.eventsList.length;
|
||||
});
|
||||
|
||||
}
|
||||
this.processesbackend.GetTasksList("Expediente", true).subscribe(result => {
|
||||
this.totalExpediente = result;
|
||||
});
|
||||
this.pushCordova()
|
||||
/* //Initialize profile as mdgpr
|
||||
|
||||
/*
|
||||
PushNotifications.addListener('registrationError', (error: any) => {
|
||||
alert('Error on registration: ' + JSON.stringify(error));
|
||||
});
|
||||
|
||||
PushNotifications.addListener('pushNotificationReceived', notification => {
|
||||
|
||||
//const isPushNotification = !!notification.title || !!notification.body;
|
||||
|
||||
// if this is a push notification received when the app is in the foreground on Android
|
||||
//if (isAndroid && isPushNotification) {
|
||||
|
||||
// We schedule a LocalNotification 1 second later since Capacitor for Android doesn't show anything in this case
|
||||
console.log('Recived: ', notification)
|
||||
//}
|
||||
});
|
||||
|
||||
|
||||
PushNotifications.addListener(
|
||||
'pushNotificationActionPerformed',
|
||||
(notification: PushNotificationActionPerformed) => {
|
||||
let service = notification.notification.data.Service;
|
||||
let object = notification.notification.data.Object;
|
||||
let idObject = notification.notification.data.IdObject;
|
||||
|
||||
console.log('Complete Object: ', notification.notification )
|
||||
|
||||
console.log('Service: ', service);
|
||||
console.log('Object: ', object);
|
||||
console.log('idObject: ', idObject);
|
||||
|
||||
if (service === "agenda") {
|
||||
//this.router.navigate(['/home/', service, idObject, 'home']);
|
||||
this.viewEventDetail(idObject)
|
||||
}
|
||||
else if (service === "gabinete-digital" && object === "expediente") {
|
||||
this.viewExpedientDetail(idObject)
|
||||
}
|
||||
else if (service === "gabinete-digital" && object === "event-list") {
|
||||
// this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', idObject])})
|
||||
this.openApproveModal(idObject);
|
||||
}
|
||||
else if (service === "accoes" && object === "accao") {
|
||||
this.viewPublications(idObject)
|
||||
}
|
||||
else if (service === "accoes" && object === "publicacao") {
|
||||
this.viewPublicationDetail(idObject)
|
||||
}
|
||||
|
||||
},
|
||||
); */
|
||||
let date = new Date();
|
||||
date.setMonth(date.getMonth() + 1);
|
||||
let start = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds();
|
||||
let end = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" 23:59:59";
|
||||
|
||||
this.profile = "mdgpr";
|
||||
if (this.profile == "mdgpr") {
|
||||
this.eventService.getAllMdEvents(start, end).subscribe(res => {
|
||||
this.eventsList = res;
|
||||
this.totalEvent = this.eventsList.length;
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.eventService.getAllPrEvents(start, end).subscribe(res => {
|
||||
this.eventsList = res;
|
||||
this.totalEvent = this.eventsList.length;
|
||||
});
|
||||
|
||||
}
|
||||
this.processesbackend.GetTasksList("Expediente", true).subscribe(result => {
|
||||
this.totalExpediente = result;
|
||||
});
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
/* mobileFirstTest() {
|
||||
this.zone.run(() => {
|
||||
alert("Hello MobileFirst");
|
||||
alert("Connecting to Server...");
|
||||
pushCordova() {
|
||||
|
||||
this.fcm.onNotification().subscribe(data => {
|
||||
this.viewEventDetail(data.idObject)
|
||||
if (data.click_action) {
|
||||
console.log("Received in background: ", data);
|
||||
|
||||
if (data.service === "agenda") {
|
||||
//this.router.navigate(['/home/', service, idObject, 'home']);
|
||||
this.viewEventDetail(data.idObject)
|
||||
}
|
||||
else if (data.service === "gabinete-digital" && data.object === "expediente") {
|
||||
this.viewExpedientDetail(data.idObject)
|
||||
}
|
||||
else if (data.service === "gabinete-digital" && data.object === "event-list") {
|
||||
// this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', idObject])})
|
||||
this.openApproveModal(data.idObject);
|
||||
}
|
||||
else if (data.service === "accoes" && data.object === "accao") {
|
||||
//this.viewPublications(data.idObject)
|
||||
alert(data.idObject)
|
||||
}
|
||||
else if (data.service === "accoes" && data.object === "publicacao") {
|
||||
this.viewPublicationDetail(data.idObject)
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("Received in foreground: ", data);
|
||||
if (data.service === "agenda") {
|
||||
//this.router.navigate(['/home/', service, idObject, 'home']);
|
||||
this.viewEventDetail(data.idObject)
|
||||
}
|
||||
else if (data.service === "gabinete-digital" && data.object === "expediente") {
|
||||
this.viewExpedientDetail(data.idObject)
|
||||
}
|
||||
else if (data.service === "gabinete-digital" && data.object === "event-list") {
|
||||
// this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', idObject])})
|
||||
this.openApproveModal(data.idObject);
|
||||
}
|
||||
else if (data.service === "accoes" && data.object === "accao") {
|
||||
this.viewPublications(data.idObject)
|
||||
}
|
||||
else if (data.service === "accoes" && data.object === "publicacao") {
|
||||
this.viewPublicationDetail(data.idObject)
|
||||
}
|
||||
};
|
||||
});
|
||||
WLAuthorizationManager.obtainAccessToken("").then(
|
||||
(token) => {
|
||||
console.log('--> pingMFP(): Success ', token);
|
||||
this.zone.run(() => {
|
||||
alert("Yay!");
|
||||
alert("Connected 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.
|
||||
alert("Success: " + response.responseText);
|
||||
},
|
||||
(error) => {
|
||||
alert("Failure: " + JSON.stringify(error));
|
||||
}
|
||||
);
|
||||
}, (error) => {
|
||||
console.log('--> pingMFP(): failure ', error.responseText);
|
||||
this.zone.run(() => {
|
||||
alert("Bummer...");
|
||||
alert("Failed to connect to MobileFirst Server");
|
||||
});
|
||||
this.fcm.onTokenRefresh().subscribe(token => {
|
||||
// Register your new token in your back-end if you want
|
||||
// backend.registerToken(token);
|
||||
});
|
||||
|
||||
this.ubscribeToTopic()
|
||||
this.getToken()
|
||||
|
||||
}
|
||||
|
||||
ubscribeToTopic() {
|
||||
this.fcm.subscribeToTopic('enappd');
|
||||
}
|
||||
getToken() {
|
||||
this.fcm.getToken().then(token => {
|
||||
console.log('token: ', token)
|
||||
// Register your new token in your back-end if you want
|
||||
// backend.registerToken(token);
|
||||
});
|
||||
}
|
||||
|
||||
async viewEventDetail(eventId: any) {
|
||||
console.log(this.profile);
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewEventPage,
|
||||
componentProps: {
|
||||
eventId: eventId,
|
||||
adding: this.adding
|
||||
},
|
||||
cssClass: 'modal modal-desktop',
|
||||
backdropDismiss: false
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then((res) => {
|
||||
if (res) {
|
||||
//this.viewEventDetailDismiss(res);
|
||||
}
|
||||
);
|
||||
} */
|
||||
});
|
||||
}
|
||||
|
||||
/* async openApproveModal(eventSerialNumber){
|
||||
async openApproveModal(eventSerialNumber) {
|
||||
const modal = await this.modalController.create({
|
||||
component: ApproveEventModalPage,
|
||||
componentProps:{
|
||||
componentProps: {
|
||||
serialNumber: eventSerialNumber,
|
||||
},
|
||||
cssClass: 'cal-modal',
|
||||
@@ -157,46 +196,17 @@ export class HomePage implements OnInit {
|
||||
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
} */
|
||||
|
||||
/* async viewEventDetail(eventId:any) {
|
||||
console.log(this.profile);
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewEventPage,
|
||||
componentProps:{
|
||||
eventId: eventId,
|
||||
},
|
||||
cssClass: 'modal',
|
||||
backdropDismiss: false
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
} */
|
||||
|
||||
/* async viewExpedientDetail(serialNumber:any) {
|
||||
console.log(this.profile);
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewEventPage,
|
||||
componentProps: {
|
||||
eventId: eventId,
|
||||
},
|
||||
cssClass: 'modal',
|
||||
backdropDismiss: false
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then((res) => {
|
||||
if (res) {
|
||||
console.log(res);
|
||||
//this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async viewExpedientDetail(serialNumber: any) {
|
||||
console.log(this.profile);
|
||||
console.log("Expediente id: ", serialNumber);
|
||||
let classs;
|
||||
if (window.innerWidth <= 800) {
|
||||
classs = 'modal'
|
||||
} else {
|
||||
classs = 'modal modal-desktop showAsideOptions'
|
||||
}
|
||||
/* console.log(this.profile);
|
||||
console.log(serialNumber); */
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
component: ExpedienteDetailPage,
|
||||
@@ -204,43 +214,75 @@ export class HomePage implements OnInit {
|
||||
serialNumber: serialNumber,
|
||||
profile: this.profile,
|
||||
},
|
||||
cssClass: 'modal',
|
||||
backdropDismiss: false
|
||||
cssClass: classs,
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
} */
|
||||
modal.onDidDismiss().then((res) => {
|
||||
if (res) {
|
||||
console.log(res);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* async viewPublicationDetail(folderId) {
|
||||
async viewPublicationDetail(publicationId: string) {
|
||||
const modal = await this.modalController.create({
|
||||
component: PublicationDetailPage,
|
||||
componentProps: {
|
||||
folderId: folderId,
|
||||
publicationId: publicationId,
|
||||
folderId: this.folderId,
|
||||
},
|
||||
cssClass: 'publication-detail',
|
||||
backdropDismiss: false
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
} */
|
||||
modal.onDidDismiss().then(() => {
|
||||
//this.getPublications();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async viewPublications(folderId) {
|
||||
|
||||
const enterAnimation = (baseEl: any) => {
|
||||
const backdropAnimation = this.animationController.create()
|
||||
.addElement(baseEl.querySelector('ion-backdrop')!)
|
||||
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
|
||||
|
||||
const wrapperAnimation = this.animationController.create()
|
||||
.addElement(baseEl.querySelector('.modal-wrapper')!)
|
||||
.keyframes([
|
||||
{ offset: 0, opacity: '0', transform: 'scale(0)' },
|
||||
{ offset: 1, opacity: '0.99', transform: 'scale(1)' }
|
||||
]);
|
||||
|
||||
return this.animationController.create()
|
||||
.addElement(baseEl)
|
||||
.easing('ease-out')
|
||||
.duration(500)
|
||||
.addAnimation([backdropAnimation, wrapperAnimation]);
|
||||
}
|
||||
|
||||
const leaveAnimation = (baseEl: any) => {
|
||||
return enterAnimation(baseEl).direction('reverse');
|
||||
}
|
||||
|
||||
/* async viewPublications(folderId) {
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewPublicationsPage,
|
||||
enterAnimation,
|
||||
leaveAnimation,
|
||||
componentProps: {
|
||||
item: folderId,
|
||||
folderId: folderId,
|
||||
},
|
||||
cssClass: 'new-action',
|
||||
backdropDismiss: false
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
} */
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user