Files
doneit-web/src/app/home/home.page.ts
T
2021-07-07 15:28:29 +01:00

139 lines
4.5 KiB
TypeScript

///<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';
import { EventsService } from '../services/events.service';
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 { ToastService } from '../services/toast.service';
@Component({
selector: 'app-home',
templateUrl: './home.page.html',
styleUrls: ['./home.page.scss'],
})
export class HomePage implements OnInit {
eventsList: Event[];
prEventList: Event[];
mdEventList: Event[];
totalEvent = 0;
totalExpediente = 0;
profile: string;
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 toastService: ToastService,
private animationController: AnimationController,
private notificatinsservice: NotificationsService,
private platform: Platform,
private activeroute: ActivatedRoute) {
router.events.subscribe((val) => {
document.querySelectorAll('ion-modal').forEach((e) => e.remove())
});
{
//this.folderId = this.navParams.get('folderId');
}
}
ngOnInit() {
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.count();
}
async count() {
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") {
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 {
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;
}
}
mobilefirstConnect() {
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) => {
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");
}); */
}
);
}
}