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

469 lines
16 KiB
TypeScript
Raw Normal View History

2021-08-18 17:36:40 +01:00
import { Component, OnInit, NgZone } from '@angular/core';
2023-02-02 18:24:26 +01:00
import { NavigationExtras, 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'
2023-01-24 15:56:47 +01:00
import { environment } from 'src/environments/environment';
2023-07-31 16:39:35 +01:00
import { ProcessesService } from 'src/app/services/processes.service';
import { EventsService } from 'src/app/services/events.service';
2023-08-31 16:37:11 +01:00
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
@Component({
selector: 'app-profile',
templateUrl: './profile.page.html',
styleUrls: ['./profile.page.scss'],
})
export class ProfilePage implements OnInit {
2021-07-28 09:34:11 +01:00
userLoginPreference = ''
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
2023-01-04 14:45:17 +01:00
logoutOut = false
2023-01-04 15:03:29 +01:00
notificationStatus = '';
2023-01-25 15:49:16 +01:00
environment = environment
2023-07-31 16:39:35 +01:00
taskExist = true;
taskNotExist = false;
2023-08-21 17:52:04 +01:00
isloading = false;
2023-08-29 16:05:32 +01:00
profilePicture = "";
2023-07-31 16:39:35 +01:00
2021-08-23 17:34:12 +01:00
2023-01-25 15:49:16 +01:00
SessionStore = SessionStore;
constructor(
private modalController: ModalController,
2021-07-28 09:34:11 +01:00
private animationController: AnimationController,
private router: Router,
2021-08-01 21:38:27 +01:00
private storageservice: StorageService,
private zone: NgZone,
2021-08-20 18:22:56 +01:00
private platform: Platform,
2023-02-03 14:40:09 +01:00
private eventTriger: EventTrigger,
2021-11-24 14:44:33 +01:00
public ThemeService: ThemeService,
2023-07-31 16:39:35 +01:00
private notificationService: NotificationsService,
private processesService: ProcessesService,
2023-08-29 16:05:32 +01:00
private eventsService: EventsService,
private storageService: StorageService,
2023-11-29 12:17:52 +01:00
public NotificationHolderService: NotificationHolderService,
private authservice: AuthService
2021-07-31 22:04:09 +01:00
) {
2021-07-28 09:34:11 +01:00
2023-09-22 16:16:35 +01:00
window['e'] = () => {
console.log(
this.zone.run(() => this.router.navigate(['/home/chat']))
)
}
2023-06-26 11:12:57 +01:00
2022-10-05 16:16:31 +01:00
router.events.subscribe((val) => {
this.isProfileOpen = false
2023-01-04 14:45:17 +01:00
this.logoutOut = true
2022-10-05 16:16:31 +01:00
});
2021-07-28 09:34:11 +01:00
2023-08-29 16:05:32 +01:00
/* this.eventTriger.getObservable().subscribe((event) => {
2023-06-26 11:12:57 +01:00
if (event.notification == "recive") {
this.getNotificationData();
2023-08-22 17:51:32 +01:00
} else if (event.notification == "deleted") {
2023-06-26 11:12:57 +01:00
console.log('header', event.notification)
2023-02-03 14:40:09 +01:00
this.getNotificationData();
}
2023-08-29 16:05:32 +01:00
}); */
2023-02-03 14:40:09 +01:00
2023-08-29 16:05:32 +01:00
/* this.notificationService.notificationReceived.subscribe(() => {
2023-06-26 11:12:57 +01:00
this.getNotificationData();
2023-08-29 16:05:32 +01:00
}); */
2023-06-26 11:12:57 +01:00
2023-01-25 15:49:16 +01:00
setTimeout(() => {
2022-10-05 16:16:31 +01:00
this.hideImage = true
}, 2000)
2021-07-28 09:34:11 +01:00
}
2021-07-31 22:04:09 +01:00
ngOnInit() {
2023-06-26 11:12:57 +01:00
2023-08-31 16:37:11 +01:00
// this.getNotificationData();
2023-08-29 16:05:32 +01:00
this.getProfilpicture();
}
2021-08-19 18:28:00 +01:00
2023-08-29 16:05:32 +01:00
getProfilpicture() {
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
2023-10-26 13:28:54 +01:00
if(picture) {
this.profilePicture = picture
} else {
this.profilePicture = "";
}
/* console.log(picture) */
2023-08-29 16:05:32 +01:00
}).catch((error ) => {
this.profilePicture = "";
})
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
2023-08-31 16:37:11 +01:00
// async getNotificationData() {
// //const keyExist = await this.storageservice.keyExist("Notifications")
// //if(keyExist) {
// await this.storageservice.get("Notifications").then((value) => {
// console.log('Getnotifications 111', value)
// this.DataArray = []
// value.forEach((element, i) => {
// console.log('Getnotifications', element, i)
// let notificationObject;
// if (element.notification) {
// notificationObject = {
// index: i,
// title: element.notification.title,
// Service: element.data.Service,
// Object: element.data.Object,
// IdObject: element.data.IdObject,
// FolderId: element.data.FolderId,
// body: element.notification.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,
// read: false,
// }
// } else if (element.data) {
// notificationObject = {
// 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,
// read: false,
// }
// } else {
// {
// notificationObject = {
// FolderId: element.FolderId,
// IdObject: element.IdObject,
// Location: element.Location,
// Object: element.Object,
// Role: element.Role,
// Service: element.Service,
// Status: element.Status,
// TypeAgenda: element.TypeAgenda,
// body: element.body,
// dateEnd: element.dateEnd,
// dateInit: element.dateInit,
// index: element.index,
// title: element.title,
// read: false,
// }
// }
// }
// this.DataArray.push(notificationObject)
// });
// this.notificationdata = this.DataArray.reverse();
// }).catch((error) => {
// console.error('storage getnotification: ', error)
// })
// // }
// }
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
2023-08-22 17:51:32 +01:00
notificatinsRoutes = (index, Service, Object, IdObject, FolderId, i) => {
2023-07-31 16:39:35 +01:00
console.log(index, i)
2023-08-22 17:51:32 +01:00
if (Service === "agenda") {
2023-08-21 17:52:04 +01:00
this.isloading = true
2023-08-22 17:51:32 +01:00
if (Service === "agenda" && IdObject.length > 10) {
this.eventsService.getEvent(IdObject).subscribe((task) => {
2023-07-31 16:39:35 +01:00
this.zone.run(() => this.router.navigate(['/home/agenda', IdObject, 'agenda']));
2023-08-22 17:51:32 +01:00
this.deleteNotification(index);
this.isloading = false
}, (error) => {
2023-08-31 16:37:11 +01:00
this.NotificationHolderService.notificationList[i].read = true;
2023-08-22 17:51:32 +01:00
this.isloading = false
})
}
if (Service === "agenda" && Object === "event-list") {
this.isloading = true
this.processesService.GetTask(IdObject).subscribe((task) => {
2023-08-29 16:05:32 +01:00
console.log('evento exist')
2023-07-31 16:39:35 +01:00
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', IdObject, 'agenda']));
2023-08-22 17:51:32 +01:00
this.deleteNotification(index);
this.isloading = false
2023-07-31 16:39:35 +01:00
2023-08-22 17:51:32 +01:00
}, (error) => {
2023-08-29 16:05:32 +01:00
console.log('evento não existe')
2023-08-31 16:37:11 +01:00
this.NotificationHolderService.notificationList[i].read = true;
2023-08-22 17:51:32 +01:00
this.isloading = false
})
2023-07-31 16:39:35 +01:00
2023-08-22 17:51:32 +01:00
}
2023-07-31 16:39:35 +01:00
} else if (Service === "gabinete-digital") {
2023-08-21 17:52:04 +01:00
this.isloading = true
2023-07-31 16:39:35 +01:00
this.processesService.GetTask(IdObject).subscribe((task) => {
if (Service === "gabinete-digital" && Object === "expedientes") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', IdObject, 'gabinete-digital']));
} else if (Service === "gabinete-digital" && Object === "despachos") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', IdObject, 'gabinete-digital'], { replaceUrl: true }));
2023-08-22 17:51:32 +01:00
} else if (Service === "gabinete-digital" && Object === "parecer") {
2023-07-31 16:39:35 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "deferimento") {
2023-08-22 17:51:32 +01:00
2023-07-31 16:39:35 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "despachos-pr") {
2023-08-22 17:51:32 +01:00
2023-07-31 16:39:35 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', IdObject, 'gabinete-digital']));
2023-09-09 14:40:08 +01:00
}else if (Service === "gabinete-digital" && Object === "diplomas") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "diplomas-assinar") {
2023-09-19 10:21:23 +01:00
2023-09-09 14:40:08 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "diploma-revisao") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "expedientes-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', IdObject, 'gabinete-digital']));
2023-07-31 16:39:35 +01:00
}
this.deleteNotification(index);
2023-08-21 17:52:04 +01:00
this.isloading = false
2023-08-22 17:51:32 +01:00
2023-07-31 16:39:35 +01:00
}, (error) => {
2023-08-31 16:37:11 +01:00
this.NotificationHolderService.notificationList[i].read = true;
2023-08-21 17:52:04 +01:00
this.isloading = false
2023-07-31 16:39:35 +01:00
})
2023-08-22 17:51:32 +01:00
} else if (Service === "accoes") {
2023-07-31 16:39:35 +01:00
if (Service === "accoes" && Object === "accao") {
this.zone.run(() => this.router.navigate(['/home/publications', IdObject]));
this.deleteNotification(index);
}
else if (Service === "accoes" && Object === "publicacao") {
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', FolderId, IdObject]));
this.deleteNotification(index);
}
} else if (Service === "chat") {
2023-09-22 15:27:43 +01:00
2023-07-31 16:39:35 +01:00
let navigationExtras: NavigationExtras = { queryParams: { "roomId": IdObject, } };
2023-09-22 15:27:43 +01:00
this.zone.run(() => this.router.navigate(['/home/chat']));
2023-09-22 16:16:35 +01:00
setTimeout(() => {
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
}, 200);
2023-09-22 15:27:43 +01:00
2023-07-31 16:39:35 +01:00
this.deleteNotification(index);
}
2022-05-04 16:45:38 +01:00
2023-08-22 17:51:32 +01:00
/* if (Service === "agenda" && IdObject.length > 10) {
this.zone.run(() => this.router.navigate(['/home/agenda', IdObject, 'agenda']));
}
else if (Service === "gabinete-digital" && Object === "expedientes") {
this.processesService.GetTask(IdObject).subscribe((task) => {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', IdObject, 'gabinete-digital']));
}, (error) => {
this.notificationdata[i].read = true;
})
}
else if (Service === "agenda" && Object === "event-list") {
//this.zone.run(() => this.router.navigate(['/home/gabinete-digital/event-list/approve-event',IdObject, 'agenda']));
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', IdObject, 'agenda']));
2023-09-19 10:21:23 +01:00
2023-08-22 17:51:32 +01:00
} else if (Service === "gabinete-digital" && Object === "despachos") {
this.processesService.GetTask(IdObject).subscribe((task) => {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', IdObject, 'gabinete-digital'], { replaceUrl: true }));
}, (error) => {
this.notificationdata[i].read = true;
})
2023-09-19 10:21:23 +01:00
2023-08-22 17:51:32 +01:00
}
else if (Service === "gabinete-digital" && Object === "parecer") {
2023-09-19 10:21:23 +01:00
2023-08-22 17:51:32 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "deferimento") {
2023-09-19 10:21:23 +01:00
2023-08-22 17:51:32 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "despachos-pr") {
2023-09-19 10:21:23 +01:00
2023-08-22 17:51:32 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', IdObject, 'gabinete-digital']));
}
else if (Service === "accoes" && Object === "accao") {
this.zone.run(() => this.router.navigate(['/home/publications', IdObject]));
}
else if (Service === "accoes" && Object === "publicacao") {
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', FolderId, IdObject]));
}
else if (Service === "gabinete-digital" && Object === "diplomas") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "diplomas-assinar") {
2023-09-19 10:21:23 +01:00
2023-08-22 17:51:32 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "expedientes-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', IdObject, 'gabinete-digital']));
} else if (Service === "chat") {
let navigationExtras: NavigationExtras = { queryParams: { "roomId": IdObject, } };
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
} */
2021-08-18 17:36:40 +01:00
2022-12-19 17:04:21 +01:00
// this.notificationservice.tempClearArray();
2023-08-22 17:51:32 +01:00
2021-09-21 06:08:01 +01:00
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) {
2023-08-31 16:37:11 +01:00
const notificationdata = this.NotificationHolderService.notificationList.find(item => item.index == index);
this.NotificationHolderService.removeNotification(notificationdata)
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() {
2023-11-29 12:17:52 +01:00
this.authservice.logoutUser();
2022-12-30 14:31:19 +01:00
SessionStore.setInativity(false)
SessionStore.setUrlBeforeInactivity(this.router.url);
2023-01-04 14:45:17 +01:00
this.logoutOut == false
2023-06-26 11:12:57 +01:00
if (environment.production) {
2023-01-24 15:56:47 +01:00
window.location.pathname = '/auth'
2023-09-19 10:21:23 +01:00
this.notificationService.DeletePostToken()
2023-01-24 15:56:47 +01:00
} else {
2023-01-12 15:27:09 +01:00
const pathBeforeGoOut = window.location.pathname
2023-01-05 12:11:50 +01:00
this.router.navigateByUrl('/auth', { replaceUrl: true });
2023-09-19 10:21:23 +01:00
this.notificationService.DeletePostToken()
2023-06-26 11:12:57 +01:00
2023-01-09 10:49:58 +01:00
setTimeout(() => {
2023-06-26 11:12:57 +01:00
if (this.logoutOut == false || pathBeforeGoOut == window.location.pathname) {
2023-01-05 12:11:50 +01:00
window.location.pathname = '/auth'
2023-09-19 10:21:23 +01:00
this.notificationService.DeletePostToken()
2023-01-12 15:27:09 +01:00
} else {
2023-05-26 14:23:37 +01:00
2023-01-04 14:45:17 +01:00
}
}, 500)
2023-01-24 15:56:47 +01:00
}
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');
}
2023-06-26 11:12:57 +01:00
if (this.isProfileOpen == false) {
2022-10-05 16:16:31 +01:00
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: {
}
});
2023-07-15 11:01:09 +01:00
2023-06-26 11:12:57 +01:00
2022-10-05 16:16:31 +01:00
modal.onDidDismiss().then(() => {
this.isProfileOpen = false;
2023-08-30 14:02:14 +01:00
this.getProfilpicture()
2023-07-14 10:19:33 +01:00
}, (error) => {
console.log(error)
2022-10-05 16:16:31 +01:00
})
2023-06-26 11:12:57 +01:00
2023-07-15 11:01:09 +01:00
await modal.present();
2022-10-05 16:16:31 +01:00
}
}
2023-07-31 16:39:35 +01:00
keppNotification(index) {
2023-08-31 16:37:11 +01:00
this.NotificationHolderService.notificationList[index].read = false;
2023-07-31 16:39:35 +01:00
}
doNotKeppNotification(index) {
this.deleteNotification(index);
}
}