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

440 lines
15 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';
2024-06-28 07:44:43 +01:00
import { AnimationController, ModalController } from '@ionic/angular';
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-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';
2023-08-31 16:37:11 +01:00
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
2024-07-31 11:29:26 +01:00
import { AgendaDataRepositoryService } from 'src/app/module/agenda/data/repository/agenda-data-repository.service';
import { ToastService } from 'src/app/services/toast.service';
2024-06-27 16:53:45 +01:00
import { NotificationRepositoryService } from 'src/app/module/notification/data/notification-repository.service';
import { Observable } from 'rxjs';
import { NotificationTable } from 'src/app/module/notification/data/infra/db/notification.db';
import { isHttpError } from 'src/app/services/http.service';
import { UserRepositoryService } from 'src/app/module/user/data/user-repository.service';
import { UserProfilePicture } from 'src/app/module/user/data/datasource/user-local-repository.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;
2024-06-27 16:53:45 +01:00
notificationList$: Observable<NotificationTable[]>
2024-06-27 17:43:44 +01:00
objectRead = {}
profilePictureSubject: Observable<UserProfilePicture>
2024-06-27 17:43:44 +01:00
2023-01-25 15:49:16 +01:00
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 zone: NgZone,
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 storageService: StorageService,
2023-11-29 12:17:52 +01:00
public NotificationHolderService: NotificationHolderService,
private authservice: AuthService,
private agendaDataRepository: AgendaDataRepositoryService,
private toastService: ToastService,
private notificationRepositoryService: NotificationRepositoryService,
private UserRepositoryService: UserRepositoryService
2021-07-31 22:04:09 +01:00
) {
2021-07-28 09:34:11 +01:00
this.profilePictureSubject = this.UserRepositoryService.getProfilePictureLive() as any
2023-09-22 16:16:35 +01:00
window['e'] = () => {
console.log(
this.zone.run(() => this.router.navigate(['/home/chat']))
)
}
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-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)
2024-06-27 16:53:45 +01:00
this.notificationRepositoryService.init()
2024-06-28 07:44:43 +01:00
this.subscribe()
}
subscribe() {
this.notificationList$ = this.notificationRepositoryService.getNotificationLive()
2021-07-28 09:34:11 +01:00
}
2021-07-31 22:04:09 +01:00
ngOnInit() {
2023-08-29 16:05:32 +01:00
this.getProfilpicture();
2024-06-27 16:53:45 +01:00
}
toDateString(e) {
return new Date(e).toDateString()
}
2023-08-29 16:05:32 +01:00
2024-06-27 16:53:45 +01:00
isValidDate(dateString) {
const date = new Date(dateString);
return !isNaN(date.getTime());
2023-08-29 16:05:32 +01:00
}
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
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
2024-07-30 15:52:07 +01:00
@XTracerAsync({name:'profile/notificationClick', bugPrint: true, module:'notification', autoFinish: false})
2024-06-27 16:53:45 +01:00
async notificatinsRoutes (index, item: NotificationTable, tracing?: TracingType) {
2023-07-31 16:39:35 +01:00
2024-06-20 15:40:08 +01:00
try {
2024-06-27 16:53:45 +01:00
if (item.service === "agenda") {
2024-06-20 15:40:08 +01:00
this.isloading = true
2024-06-27 16:53:45 +01:00
if (item.service === "agenda") {
2023-07-31 16:39:35 +01:00
2024-07-30 15:52:07 +01:00
tracing.addEvent('start getEventById')
2024-06-27 16:53:45 +01:00
let res = await this.agendaDataRepository.getEventById(item.idObject, tracing)
2024-07-30 15:52:07 +01:00
tracing.addEvent('end getEventById')
2023-08-22 17:51:32 +01:00
2024-06-27 16:53:45 +01:00
if(item.idObject) {
if(res.isOk()) {
2024-06-28 07:44:43 +01:00
if(res.value.Status == 'Pending') {
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', item.idObject, 'agenda']));
} else {
this.zone.run(() => this.router.navigate(['/home/agenda', item.idObject, 'agenda']));
}
2024-06-27 17:43:44 +01:00
this.deleteNotification(item);
tracing.setAttribute('outcome', 'success')
} else {
2024-06-27 16:53:45 +01:00
2024-07-30 15:52:07 +01:00
tracing.setAttribute('data.exist', 'false')
tracing.setAttribute('outcome', 'success')
2024-06-27 16:53:45 +01:00
2024-06-27 17:43:44 +01:00
if (isHttpError(res.error)) {
2024-06-27 16:53:45 +01:00
if(res.error.status == 404) {
2024-06-27 17:43:44 +01:00
// this.toastService._badRequest('Este evento já não existe')
this.objectRead[item.notificationId] = true
2024-06-27 16:53:45 +01:00
}
}
}
} else {
tracing.setAttribute('data.IdObject', 'false')
this.toastService._badRequest('Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico. #01')
}
this.isloading = false
2024-06-20 15:40:08 +01:00
2024-06-28 07:44:43 +01:00
} else if (item.service === "event-list" || item.object === "event-list") {
2024-06-20 15:40:08 +01:00
this.isloading = true
2023-08-22 17:51:32 +01:00
2024-06-27 16:53:45 +01:00
if(item.idObject) {
2024-06-27 16:53:45 +01:00
let res = await this.agendaDataRepository.getEventById(item.idObject, tracing)
if(res.isOk()) {
console.log('evento exist')
tracing.setAttribute('outcome', 'success')
2024-06-27 16:53:45 +01:00
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', item.idObject, 'agenda']));
2024-06-27 17:43:44 +01:00
this.deleteNotification(item);
this.isloading = false
} else {
2024-07-30 15:52:07 +01:00
console.log('evento não existe')
tracing.setAttribute('data.exist', 'false')
2024-07-30 15:52:07 +01:00
tracing.setAttribute('outcome', 'success')
2024-06-27 17:43:44 +01:00
this.objectRead[item.notificationId] = true
this.isloading = false
}
} else {
tracing.setAttribute('data.IdObject', 'false')
this.toastService._badRequest('Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico. #01')
}
this.isloading = false
} else {
tracing.setAttribute('notification.route', 'false')
tracing.setAttribute('outcome', 'failed')
2024-06-27 16:53:45 +01:00
tracing.setAttribute('parameters', JSON.stringify({Service:item.service, Object:item.object, IdObject:item.idObject, FolderId:item.folderId}))
2024-06-20 15:40:08 +01:00
}
2024-06-27 16:53:45 +01:00
} else if (item.service === "gabinete-digital") {
2023-08-22 17:51:32 +01:00
this.isloading = true
2024-07-30 15:52:07 +01:00
tracing.addEvent('start getTask')
2024-06-27 16:53:45 +01:00
this.processesService.GetTask(item.idObject).subscribe((task) => {
2024-06-20 15:40:08 +01:00
2024-07-30 15:52:07 +01:00
tracing.addEvent('end getTask')
2024-06-27 16:53:45 +01:00
if (item.service === "gabinete-digital" && item.object === "expedientes") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', item.idObject, 'gabinete-digital']));
} else if (item.service === "gabinete-digital" && item.object === "despachos") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', item.idObject, 'gabinete-digital'], { replaceUrl: true }));
} else if (item.service === "gabinete-digital" && item.object === "parecer") {
2024-06-20 15:40:08 +01:00
2024-06-27 16:53:45 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', item.idObject, 'gabinete-digital']));
2024-06-20 15:40:08 +01:00
}
2024-06-27 16:53:45 +01:00
else if (item.service === "gabinete-digital" && item.object === "deferimento") {
2024-06-20 15:40:08 +01:00
2024-06-27 16:53:45 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', item.idObject, 'gabinete-digital']));
2024-06-20 15:40:08 +01:00
}
2024-06-27 16:53:45 +01:00
else if (item.service === "gabinete-digital" && item.object === "despachos-pr") {
2024-06-20 15:40:08 +01:00
2024-06-27 16:53:45 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', item.idObject, 'gabinete-digital']));
}else if (item.service === "gabinete-digital" && item.object === "diplomas") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', item.idObject, 'gabinete-digital']));
2024-06-20 15:40:08 +01:00
}
2024-06-27 16:53:45 +01:00
else if (item.service === "gabinete-digital" && item.object === "diplomas-assinar") {
2024-06-20 15:40:08 +01:00
2024-06-27 16:53:45 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', item.idObject, 'gabinete-digital']));
2024-06-20 15:40:08 +01:00
}
2024-06-27 16:53:45 +01:00
else if (item.service === "gabinete-digital" && item.object === "diploma-revisao") {
2024-06-20 15:40:08 +01:00
2024-06-27 16:53:45 +01:00
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', item.idObject, 'gabinete-digital']));
2024-06-20 15:40:08 +01:00
}
2024-06-27 16:53:45 +01:00
else if (item.service === "gabinete-digital" && item.object === "expedientes-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', item.idObject, 'gabinete-digital']));
2024-06-20 15:40:08 +01:00
}
2024-06-27 17:43:44 +01:00
this.deleteNotification(item);
2023-08-22 17:51:32 +01:00
this.isloading = false
2023-07-31 16:39:35 +01:00
2024-07-30 15:52:07 +01:00
tracing.setAttribute('outcome', 'success')
2023-08-22 17:51:32 +01:00
}, (error) => {
2024-07-30 15:52:07 +01:00
tracing.addEvent('end getTask')
tracing.log('gabinete notification not found', {
notificationObject: item
})
2024-06-27 17:43:44 +01:00
this.objectRead[item.notificationId] = true
2023-08-22 17:51:32 +01:00
this.isloading = false
2024-07-30 15:52:07 +01:00
if(isHttpError(error)) {
tracing.setAttribute('getTask.http.status.code', error.status?.toString())
if(error.status == 400) {
tracing.setAttribute('outcome', 'failed')
} else {
tracing.setAttribute('outcome', 'success')
}
} else {
tracing.setAttribute('outcome', 'failed')
}
2023-08-22 17:51:32 +01:00
})
2023-07-31 16:39:35 +01:00
2024-06-27 16:53:45 +01:00
} else if (item.service === "accoes") {
if (item.service === "accoes" && item.idObject === "accao") {
this.zone.run(() => this.router.navigate(['/home/publications', item.idObject]));
2024-06-27 17:43:44 +01:00
this.deleteNotification(item);
2024-07-30 15:52:07 +01:00
tracing.setAttribute('outcome', 'success')
2023-07-31 16:39:35 +01:00
}
2024-06-27 16:53:45 +01:00
else if (item.service === "accoes" && item.idObject === "publicacao") {
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', item.folderId, item.idObject]));
2024-06-27 17:43:44 +01:00
this.deleteNotification(item);
2024-07-30 15:52:07 +01:00
tracing.setAttribute('outcome', 'success')
2023-09-09 14:40:08 +01:00
}
2023-09-19 10:21:23 +01:00
2024-06-27 16:53:45 +01:00
} else if (item.service === "chat") {
2023-09-09 14:40:08 +01:00
2024-06-27 16:53:45 +01:00
let navigationExtras: NavigationExtras = { queryParams: { "roomId": item.idObject, } };
2023-07-31 16:39:35 +01:00
2024-06-20 15:40:08 +01:00
this.zone.run(() => this.router.navigate(['/home/chat']));
2023-08-22 17:51:32 +01:00
2024-06-20 15:40:08 +01:00
setTimeout(() => {
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
}, 200);
2023-07-31 16:39:35 +01:00
2024-07-30 15:52:07 +01:00
tracing.setAttribute('outcome', 'success')
2024-06-27 17:43:44 +01:00
this.deleteNotification(item);
2024-06-20 15:40:08 +01:00
} else {
2023-09-22 15:27:43 +01:00
2024-06-27 16:53:45 +01:00
console.log({service:item.service, Object, IdObject:item.idObject, FolderId:item.folderId})
2023-09-22 16:16:35 +01:00
2024-07-30 15:52:07 +01:00
tracing.log('click notification no route', {
notificationObject: item
})
2024-06-20 15:40:08 +01:00
tracing.setAttribute('notification.route', 'false')
2024-06-27 16:53:45 +01:00
tracing.setAttribute('parameters', JSON.stringify({Service:item.service, Object, IdObject:item.idObject, FolderId:item.folderId}))
2024-07-30 15:52:07 +01:00
tracing.setAttribute('outcome', 'failed')
2024-06-20 15:40:08 +01:00
}
2023-09-22 16:16:35 +01:00
2024-06-20 15:40:08 +01:00
} catch(error) {
2024-06-27 16:53:45 +01:00
console.log({service:item.service, Object, IdObject:item.idObject, FolderId: item.folderId})
2023-09-22 15:27:43 +01:00
2024-07-30 15:52:07 +01:00
tracing.log('click notification catch', {
notificationObject: item
})
2024-06-27 16:53:45 +01:00
tracing.setAttribute('parameters', JSON.stringify({service:item.service, Object, IdObject:item.idObject, FolderId:item.folderId}))
2024-06-20 15:40:08 +01:00
tracing.setAttribute('error', JSON.stringify(error))
2024-07-30 15:52:07 +01:00
tracing.setAttribute('outcome', 'failed')
2023-07-31 16:39:35 +01:00
}
2022-05-04 16:45:38 +01:00
2021-08-19 13:58:43 +01:00
}
2024-06-27 17:43:44 +01:00
deleteNotification(item: NotificationTable) {
this.objectRead[item.notificationId] = false
this.notificationRepositoryService.RemoveNotificationStatus(item)
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
2024-06-27 17:43:44 +01:00
keppNotification(item: NotificationTable) {
// this.NotificationHolderService.notificationList[index].read = false;
this.objectRead[item.notificationId] = false
this.notificationRepositoryService.localNotificationStatus(item)
2023-07-31 16:39:35 +01:00
}
2024-06-27 17:43:44 +01:00
doNotKeppNotification(item: NotificationTable) {
this.objectRead[item.notificationId] = false
this.deleteNotification(item);
2023-07-31 16:39:35 +01:00
}
}