Files
doneit-web/src/app/modals/profile/profile.page.ts
T

250 lines
8.2 KiB
TypeScript
Raw Normal View History

2021-08-18 17:36:40 +01:00
import { Component, OnInit, NgZone } from '@angular/core';
2022-10-12 17:01:09 +01:00
import { Router } from '@angular/router';
2021-11-09 08:11:05 +01:00
import { AnimationController, ModalController, Platform } from '@ionic/angular';
2021-08-27 15:21:15 +01:00
import { LoginUserRespose } from 'src/app/models/user.model';
2021-07-28 09:34:11 +01:00
import { AuthService } from 'src/app/services/auth.service';
2021-07-28 16:27:10 +01:00
import { EditProfilePage } from './edit-profile/edit-profile.page';
2021-07-31 22:04:09 +01:00
import { StorageService } from '../../services/storage.service';
2021-11-09 17:23:39 +01:00
import { NotificationsService } from '../../services/notifications.service';
2021-08-30 10:59:58 +01:00
import { SessionStore } from 'src/app/store/session.service';
2021-09-21 06:08:01 +01:00
import { EventTrigger } from '../../services/eventTrigger.service';
2021-10-25 13:54:34 +01:00
import { ThemeService } from 'src/app/services/theme.service'
@Component({
selector: 'app-profile',
templateUrl: './profile.page.html',
styleUrls: ['./profile.page.scss'],
})
export class ProfilePage implements OnInit {
2021-08-27 15:21:15 +01:00
loggeduser: LoginUserRespose;
2021-07-28 09:34:11 +01:00
userLoginPreference = ''
2021-08-09 14:51:29 +01:00
notificationdata: any[] = [];
DataArray: Array<Object> = [];
2021-07-28 09:34:11 +01:00
2021-08-23 17:34:12 +01:00
service: "agenda";
typeagenda: "official";
typeagenda2: "pessoal";
pr: "100000014";
md: "100000011";
2021-11-09 08:11:05 +01:00
date: "60:20";
2021-08-23 17:34:12 +01:00
location: "Gabinete";
2022-10-05 16:16:31 +01:00
isProfileOpen = false
hideImage = false
2021-08-23 17:34:12 +01:00
2021-07-31 22:04:09 +01:00
constructor(private modalController: ModalController,
2021-07-28 09:34:11 +01:00
private authService: AuthService,
private animationController: AnimationController,
private router: Router,
2021-08-01 21:38:27 +01:00
private storageservice: StorageService,
private zone: NgZone,
2021-11-09 17:23:39 +01:00
private notificationservice: NotificationsService,
2021-08-20 18:22:56 +01:00
private platform: Platform,
2021-10-25 13:54:34 +01:00
private eventtrigger: EventTrigger,
2021-11-24 14:44:33 +01:00
public ThemeService: ThemeService,
2021-07-31 22:04:09 +01:00
) {
2021-07-28 09:34:11 +01:00
2022-10-12 17:01:09 +01:00
this.loggeduser = SessionStore.user;
2022-10-05 16:16:31 +01:00
router.events.subscribe((val) => {
this.isProfileOpen = false
});
2021-07-28 09:34:11 +01:00
2022-10-05 16:16:31 +01:00
setTimeout(()=>{
this.hideImage = true
}, 2000)
2021-07-28 09:34:11 +01:00
}
2021-07-31 22:04:09 +01:00
ngOnInit() {
2021-08-20 18:22:56 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2022-06-29 15:51:28 +01:00
// console.log('Notifications not supported')
2021-08-31 09:00:33 +01:00
this.getNotificationData();
2021-08-20 18:22:56 +01:00
} else {
2021-08-31 09:00:33 +01:00
this.getNotificationData();
2021-08-20 18:22:56 +01:00
}
2021-08-19 18:28:00 +01:00
}
2021-08-31 09:00:33 +01:00
2021-08-19 18:28:00 +01:00
close() {
this.modalController.dismiss();
}
notImplemented() { }
2021-11-09 08:11:05 +01:00
asyncNotification() { }
2021-08-30 10:24:46 +01:00
2021-08-31 09:00:33 +01:00
async getNotificationData() {
2021-07-31 22:04:09 +01:00
this.storageservice.get("Notifications").then((value) => {
2021-08-31 09:00:33 +01:00
this.DataArray = []
2021-11-09 08:11:05 +01:00
value.forEach((element, i) => {
let notificationObject;
if (element.data) {
2021-08-19 13:58:43 +01:00
notificationObject = {
2021-11-09 08:11:05 +01:00
index: i,
title: element.title,
Service: element.data.Service,
Object: element.data.Object,
IdObject: element.data.IdObject,
FolderId: element.data.FolderId,
body: element.body,
dateInit: this.getFormatedTime(element.data.dateInit),
dateEnd: this.getFormatedTime(element.data.dateEnd),
Location: element.data.Location,
TypeAgenda: element.data.TypeAgenda,
Role: element.data.Role,
Status: element.data.Status
2021-08-19 13:58:43 +01:00
}
} else {
notificationObject = {
FolderId: element.FolderId,
2021-11-09 08:11:05 +01:00
IdObject: element.IdObject,
2021-08-19 13:58:43 +01:00
Location: element.Location,
2021-11-09 08:11:05 +01:00
Object: element.Object,
2021-08-20 16:43:17 +01:00
Role: element.Role,
2021-11-09 08:11:05 +01:00
Service: element.Service,
Status: element.Status,
TypeAgenda: element.TypeAgenda,
body: element.body,
dateEnd: element.dateEnd,
dateInit: element.dateInit,
index: element.index,
title: element.title
}
}
this.DataArray.push(notificationObject)
});
this.notificationdata = this.DataArray
2021-07-31 22:04:09 +01:00
})
2021-08-19 18:28:00 +01:00
/* await new Promise(resolve => setTimeout(resolve, 1000));
await this.getNotificationData(); */
2021-07-28 09:34:11 +01:00
}
2021-08-23 17:34:12 +01:00
2021-11-09 08:11:05 +01:00
getFormatedTime(dateString) {
2021-08-20 16:43:17 +01:00
var date = new Date(dateString);
2021-11-10 18:18:35 +01:00
var hours = date.getHours() /* > 12 ? date.getHours() - 12 : date.getHours() */;
2021-08-20 16:43:17 +01:00
var am_pm = date.getHours() >= 12 ? "pm" : "am";
var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
let time = hours + ":" + minutes /* + " " + am_pm */;
return time;
2021-11-09 08:11:05 +01:00
}
2021-08-20 16:43:17 +01:00
2021-08-18 17:36:40 +01:00
notificatinsRoutes = (index, Service, Object, IdObject, FolderId) => {
2022-06-29 15:51:28 +01:00
// console.log(index, Service, Object, IdObject, FolderId)
2022-05-04 16:45:38 +01:00
if (Service === "agenda" && IdObject.length > 10) {
2021-08-01 21:38:27 +01:00
this.zone.run(() => this.router.navigate(['/home/agenda', IdObject, 'agenda']));
}
else if (Service === "gabinete-digital" && Object === "expediente") {
2021-08-18 17:36:40 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', IdObject, 'gabinete-digital']));
2021-08-01 21:38:27 +01:00
}
else if (Service === "agenda" && Object === "event-list") {
//this.zone.run(() => this.router.navigate(['/home/gabinete-digital/event-list/approve-event',IdObject, 'agenda']));
2021-11-09 08:11:05 +01:00
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', IdObject, 'agenda']));
2021-11-04 10:41:43 +01:00
2021-08-18 17:36:40 +01:00
} else if (Service === "gabinete-digital" && Object === "despachos") {
2021-08-18 17:36:40 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', IdObject, 'gabinete-digital'], { replaceUrl: true }));
2021-08-01 21:38:27 +01:00
}
else if (Service === "gabinete-digital" && Object === "parecer") {
2021-08-18 17:36:40 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', IdObject, 'gabinete-digital']));
2021-08-01 21:38:27 +01:00
}
else if (Service === "gabinete-digital" && Object === "deferimento") {
2021-08-18 17:36:40 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', IdObject, 'gabinete-digital']));
2021-08-01 21:38:27 +01:00
}
else if (Service === "gabinete-digital" && Object === "despachos-pr") {
2021-11-09 08:11:05 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', IdObject, 'gabinete-digital']));
2021-08-01 21:38:27 +01:00
}
else if (Service === "accoes" && Object === "accao") {
2021-08-18 17:36:40 +01:00
this.zone.run(() => this.router.navigate(['/home/publications', IdObject]));
2021-08-01 21:38:27 +01:00
}
else if (Service === "accoes" && Object === "publicacao") {
2021-08-18 17:36:40 +01:00
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', FolderId, IdObject]));
2021-08-01 21:38:27 +01:00
}
else if (Service === "gabinete-digital" && Object === "diplomas") {
2021-08-18 17:36:40 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', IdObject, 'gabinete-digital']));
2021-08-01 21:38:27 +01:00
}
else if (Service === "gabinete-digital" && Object === "diplomas-assinar") {
2021-11-04 10:41:43 +01:00
2021-11-09 08:11:05 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', IdObject, 'gabinete-digital']));
2021-08-01 21:38:27 +01:00
}
else if (Service === "gabinete-digital" && Object === "expedientes-pr") {
2021-08-18 17:36:40 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', IdObject, 'gabinete-digital']));
}
2022-12-19 17:04:21 +01:00
// this.notificationservice.tempClearArray();
2021-08-20 16:59:44 +01:00
this.deleteNotification(index);
2021-09-21 06:08:01 +01:00
this.eventtrigger.publishSomeData({
notification: "deleted"
})
2021-08-18 17:36:40 +01:00
2021-08-19 13:58:43 +01:00
}
2021-11-09 08:11:05 +01:00
deleteNotification(index) {
this.notificationdata = this.notificationdata.filter(item => item.index != index);
2021-11-04 10:41:43 +01:00
2021-11-09 08:11:05 +01:00
this.storageservice.store("Notifications", JSON.stringify(this.notificationdata)).then(() => {
this.storageservice.get("Notifications").then((value) => {
2021-08-19 13:58:43 +01:00
});
});
2021-08-18 17:36:40 +01:00
2021-08-01 21:38:27 +01:00
}
2021-07-28 09:34:11 +01:00
2021-07-28 16:27:10 +01:00
logout() {
2022-10-05 16:16:31 +01:00
this.authService.logout();
2021-07-28 16:27:10 +01:00
}
2021-07-28 09:34:11 +01:00
2021-07-28 16:27:10 +01:00
async editProfile() {
2021-07-28 09:34:11 +01:00
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');
}
2022-10-05 16:16:31 +01:00
if(this.isProfileOpen == false) {
this.isProfileOpen = true;
const modal = await this.modalController.create({
2022-10-11 14:53:48 +01:00
component: EditProfilePage,
2022-10-05 16:16:31 +01:00
cssClass: 'model profile-modal search-submodal',
componentProps: {
}
});
await modal.present();
modal.onDidDismiss().then(() => {
this.isProfileOpen = false;
})
}
}
}