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

140 lines
4.5 KiB
TypeScript
Raw Normal View History

2021-07-08 14:02:38 +01:00
/* eslint no-use-before-define: 0 */ // --> OFF
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" />
2021-07-08 10:43:40 +01:00
import { Component, OnInit, NgZone, Inject } 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-07-07 15:28:29 +01:00
import { NavigationExtras,Router,ActivatedRoute } from '@angular/router';
import { ToastService } from '../services/toast.service';
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-06-16 08:37:31 +01:00
constructor(private zone: NgZone,
private eventService: EventsService,
private processesbackend: ProcessesService,
2021-07-08 10:43:40 +01:00
private router: Router,
2021-06-16 08:37:31 +01:00
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,
2021-07-07 15:28:29 +01:00
private platform: Platform,
private activeroute: ActivatedRoute) {
2021-04-08 22:54:15 +01:00
2021-07-08 10:43:40 +01:00
this.router.events.subscribe((val) => {
document.querySelectorAll('ion-modal').forEach((e: any) => 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-07-07 15:28:29 +01:00
console.log('Active route ',this.router.url)
2021-06-25 14:37:52 +01:00
if(this.platform.is('desktop') || this.platform.is('mobileweb')) {
console.log('Notifications not supported')
} else {
2021-06-25 10:04:41 +01:00
this.mobilefirstConnect();
2021-06-25 09:35:50 +01:00
this.notificatinsservice.onReceviNotification();
2021-06-25 14:37:52 +01:00
}
2021-06-15 17:42:51 +01:00
this.count();
2021-04-09 00:10:07 +01:00
2021-06-15 17:42:51 +01:00
}
2021-06-18 11:08:55 +01:00
async count() {
2021-02-10 13:51:39 +01:00
let date = new Date();
date.setMonth(date.getMonth() + 1);
2021-06-16 08:37:31 +01:00
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";
2021-02-10 13:51:39 +01:00
2020-11-26 09:04:22 +01:00
this.profile = "mdgpr";
if (this.profile == "mdgpr") {
2021-06-15 17:42:51 +01:00
let mdOficialEvents = await this.eventService.getAllPrOficialEvents(start, end).toPromise();
let mdPessoalEvents = await this.eventService.getAllPrPessoalEvents(start, end).toPromise();
this.eventsList = mdOficialEvents.concat(mdPessoalEvents)
this.totalEvent = this.eventsList.length;
}
else {
2021-06-15 17:42:51 +01:00
let prOficialEvents = await this.eventService.getAllPrOficialEvents(start, end).toPromise();
let prPessoalEvents = await this.eventService.getAllPrPessoalEvents(start, end).toPromise();
this.eventsList = prOficialEvents.concat(prPessoalEvents)
this.totalEvent = this.eventsList.length;
}
}
2021-06-25 10:04:41 +01:00
mobilefirstConnect() {
2021-07-08 10:43:40 +01:00
window['WLAuthorizationManager'].obtainAccessToken("").then(
2021-06-25 10:04:41 +01:00
(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) => {
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");
}); */
}
);
}
2020-08-05 15:39:16 +01:00
}