Files
doneit-web/src/app/home/home.page.ts
T

412 lines
12 KiB
TypeScript
Raw Normal View History

2021-06-11 17:27:31 +01:00
///<reference path="../../../plugins/cordova-plugin-mfp/typings/worklight.d.ts" />
///<reference path="../../../plugins/cordova-plugin-mfp-push/typings/mfppush.d.ts" />
import { Component, OnInit, NgZone } from '@angular/core';
2020-09-08 11:17:07 +01:00
import { EventsService } from '../services/events.service';
import { Event } from '../models/event.model';
2020-09-08 11:25:00 +01:00
import { ProcessesService } from '../services/processes.service';
2021-04-12 08:34:17 +01:00
import { NotificationsService } from '../services/notifications.service';
2021-04-12 15:39:44 +01:00
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
2021-04-07 09:13:07 +01:00
//import { AlertController } from 'ionic-angular';
2021-02-23 16:10:14 +01:00
/* 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';
2021-04-08 22:54:15 +01:00
import { ViewEventPage } from '../pages/agenda/view-event/view-event.page';
import { ExpedienteDetailPage } from '../pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page';
import { ViewPublicationsPage } from '../pages/publications/view-publications/view-publications.page';
2021-04-09 14:20:05 +01:00
import { ApproveEventModalPage } from '../pages/gabinete-digital/event-list/approve-event-modal/approve-event-modal.page';
2021-04-13 15:43:44 +01:00
import { PublicationDetailPage } from '../pages/publications/view-publications/publication-detail/publication-detail.page';
import { ToastService } from '../services/toast.service';
import { SuccessMessagePage } from '../shared/popover/success-message/success-message.page';
2021-04-08 11:27:53 +01:00
2021-02-23 16:10:14 +01:00
/* const { PushNotifications, LocalNotifications, LocalNotificationAction } = Plugins; */
2020-08-05 15:39:16 +01:00
@Component({
selector: 'app-home',
templateUrl: './home.page.html',
styleUrls: ['./home.page.scss'],
})
export class HomePage implements OnInit {
2020-09-08 11:17:07 +01:00
eventsList: Event[];
prEventList: Event[];
mdEventList: Event[];
totalEvent = 0;
totalExpediente = 0;
profile: string;
2020-08-05 15:39:16 +01:00
2021-04-08 22:54:15 +01:00
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;
2021-04-12 08:34:17 +01:00
constructor(private zone: NgZone,
private eventService: EventsService,
private processesbackend: ProcessesService,
private router: Router,
private modalController: ModalController,
public modalCtrl: AlertController,
private toastService: ToastService,
2021-04-12 08:34:17 +01:00
private animationController: AnimationController,
2021-04-12 15:39:44 +01:00
private notificatinsservice: NotificationsService,
private platform: Platform) {
2021-04-08 22:54:15 +01:00
2021-03-04 16:07:09 +01:00
router.events.subscribe((val) => {
2021-04-08 22:54:15 +01:00
document.querySelectorAll('ion-modal').forEach((e) => e.remove())
2021-03-04 16:07:09 +01:00
});
2021-04-08 22:54:15 +01:00
{
//this.folderId = this.navParams.get('folderId');
}
2021-03-04 16:07:09 +01:00
}
2020-08-05 15:39:16 +01:00
ngOnInit() {
2021-06-11 17:27:31 +01:00
this.wlCommonInit();
2021-04-09 00:10:07 +01:00
2021-04-13 15:27:46 +01:00
//Add a test
2021-04-13 11:42:54 +01:00
//this.pushCordova();
2021-04-13 15:52:19 +01:00
//Initialize profile as mdgpr
2021-02-10 13:51:39 +01:00
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";
2020-11-26 09:04:22 +01:00
this.profile = "mdgpr";
if (this.profile == "mdgpr") {
2021-02-10 13:51:39 +01:00
this.eventService.getAllMdEvents(start, end).subscribe(res => {
this.eventsList = res;
this.totalEvent = this.eventsList.length;
});
}
else {
2021-02-10 13:51:39 +01:00
this.eventService.getAllPrEvents(start, end).subscribe(res => {
2020-11-24 15:01:16 +01:00
this.eventsList = res;
this.totalEvent = this.eventsList.length;
});
}
}
2021-06-11 17:27:31 +01:00
wlCommonInit() {
this.mobileFirstTest();
this.mobileFirstPush();
2021-06-11 17:27:31 +01:00
}
mobileFirstTest() {
WLAuthorizationManager.obtainAccessToken("").then(
(token) => {
console.log('MobileFirst Server connect: Success '+ token);
2021-06-11 17:27:31 +01:00
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);
2021-06-11 17:27:31 +01:00
//this.MFPushNotification();
},
(error) => {
alert("Connect with JavaAdapter Failure: " + JSON.stringify(error));
2021-06-11 17:27:31 +01:00
}
);
}, (error) => {
console.log('MobileFirst Server connect: failure '+ error.responseText);
console.log(JSON.stringify(error))
/* this.zone.run(() => {
2021-06-11 17:27:31 +01:00
alert("Bummer...");
alert("Failed to connect to MobileFirst Server");
}); */
2021-06-11 17:27:31 +01:00
}
);
}
mobileFirstPush() {
WLAuthorizationManager.obtainAccessToken("push.mobileclient").then(
(token) => {
console.log('Push Notification: Success '+ token);
2021-06-11 17:27:31 +01:00
MFPPush.initialize (
function(successResponse) {
console.log("Push notification Successfully intialized: " + successResponse);
MFPPush.registerNotificationsCallback(notificationReceived);
2021-06-11 17:27:31 +01:00
},
function(failureResponse) {
console.log("Push notification failure intialized: " + failureResponse);
2021-06-11 17:27:31 +01:00
}
);
MFPPush.registerDevice(null, function(successResponse) {
console.log("Successfully registered: "+ successResponse);
},
function(failureResponse) {
console.log("Successfully failue: "+ failureResponse);
}
);
async function notificationReceived(message) {
alert(message.alert);
console.log(message)
var jsonObject = JSON.parse(message.payload);
console.log(jsonObject.service);
console.log(jsonObject.IdObject);
console.log(jsonObject.object);
}
2021-06-11 17:27:31 +01:00
}, (error) => {
console.log('Push notification recived: failure '+ error.responseText);
console.log(JSON.stringify(error))
2021-06-11 17:27:31 +01:00
}
);
}
async successMessage(message?: any, callback?) {
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: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
component: SuccessMessagePage,
componentProps: {
message: message || 'Processo efetuado' ,
},
cssClass: 'notification-modal'
});
modal.present()
setTimeout(()=>{
if (callback) {
callback()
}
modal.dismiss()
},7000)
}
// pushCordova() {
2021-04-09 00:10:07 +01:00
// if(this.platform.is('desktop')) {
// console.log('Notifications not supported')
// } else {
2021-04-12 15:39:44 +01:00
// this.fcm.onNotification().subscribe(data => {
// this.viewEventDetail(data.IdObject)
// if (data.wasTapped === true) {
// console.log("Received in background: ", data);
2021-04-12 15:39:44 +01:00
// if (data.Service === "agenda") {
// //this.router.navigate(['/home/', service, IdObject, 'home']);
// this.viewEventDetail(data.IdObject)
// }
// else if (data.Service === "gabinete-digital" && data.Object === "expediente") {
// console.log('expediante 1')
// 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)
// }
2021-04-12 15:39:44 +01:00
// } else {
// console.log("Received in foreground: ", data);
2021-04-12 15:39:44 +01:00
// console.log(data.Service)
// console.log(data.Object)
// console.log(data.IdObject)
2021-04-12 15:39:44 +01:00
// };
// });
// }
2021-04-09 09:48:14 +01:00
2021-04-12 15:39:44 +01:00
2021-04-09 00:10:07 +01:00
// }
2021-04-09 00:10:07 +01:00
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);
2021-02-25 09:42:06 +01:00
}
2021-04-09 00:10:07 +01:00
});
2021-04-05 14:17:11 +01:00
}
2021-04-09 14:20:05 +01:00
async openApproveModal(eventSerialNumber){
let classs;
if( window.innerWidth <= 1024){
classs = 'cal-modal modal modal-desktop'
} else {
classs = 'gabinete-digital-mobile-modal-to-Desktop'
}
2021-04-09 00:10:07 +01:00
const modal = await this.modalController.create({
component: ApproveEventModalPage,
2021-04-09 14:20:05 +01:00
componentProps:{
2021-04-09 00:10:07 +01:00
serialNumber: eventSerialNumber,
},
2021-04-09 14:20:05 +01:00
cssClass: 'event-list',
2021-04-09 00:10:07 +01:00
backdropDismiss: false
});
2021-04-05 14:17:11 +01:00
2021-04-09 00:10:07 +01:00
await modal.present();
2021-04-09 14:20:05 +01:00
2021-04-09 00:10:07 +01:00
modal.onDidDismiss();
}
async viewExpedientDetail(serialNumber: any) {
let classs;
if (window.innerWidth <= 800) {
2021-05-07 16:57:53 +01:00
classs = 'modal modal-desktop'
2021-04-09 00:10:07 +01:00
} else {
classs = 'modal modal-desktop showAsideOptions'
}
2021-04-12 08:34:17 +01:00
console.log(this.profile);
console.log(serialNumber);
2021-04-09 14:20:05 +01:00
console.log('expediante 2')
2021-04-09 00:10:07 +01:00
const modal = await this.modalController.create({
component: ExpedienteDetailPage,
componentProps: {
serialNumber: serialNumber,
2021-04-09 14:20:05 +01:00
profile: "MDGPR",
2021-04-09 00:10:07 +01:00
},
cssClass: classs,
});
await modal.present();
modal.onDidDismiss().then((res) => {
if (res) {
console.log(res);
2021-04-05 14:17:11 +01:00
}
2021-04-09 00:10:07 +01:00
});
}
2021-04-05 14:17:11 +01:00
2021-04-09 00:10:07 +01:00
async viewPublicationDetail(publicationId: string) {
const modal = await this.modalController.create({
component: PublicationDetailPage,
componentProps: {
publicationId: publicationId,
folderId: this.folderId,
},
2021-04-29 19:46:40 +01:00
cssClass: 'publication-detail modal modal-desktop',
//backdropDismiss: false
2021-04-09 00:10:07 +01:00
});
await modal.present();
modal.onDidDismiss().then(() => {
2021-04-12 08:34:17 +01:00
2021-04-09 00:10:07 +01:00
});
2021-04-05 14:17:11 +01:00
}
2021-02-25 09:42:06 +01:00
2021-04-07 09:13:07 +01:00
2021-04-09 00:10:07 +01:00
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');
}
const modal = await this.modalController.create({
component: ViewPublicationsPage,
enterAnimation,
leaveAnimation,
componentProps: {
folderId: folderId,
},
cssClass: 'new-action',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
2021-04-07 09:13:07 +01:00
2021-04-09 00:06:17 +01:00
2021-02-26 15:29:05 +01:00
2020-09-08 11:17:07 +01:00
2020-08-05 15:39:16 +01:00
}