mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
440 lines
15 KiB
TypeScript
440 lines
15 KiB
TypeScript
import { Component, OnInit, NgZone } from '@angular/core';
|
|
import { NavigationExtras, Router } from '@angular/router';
|
|
import { AnimationController, ModalController } from '@ionic/angular';
|
|
import { AuthService } from 'src/app/services/auth.service';
|
|
import { EditProfilePage } from './edit-profile/edit-profile.page';
|
|
import { StorageService } from '../../services/storage.service';
|
|
import { NotificationsService } from '../../services/notifications.service';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { environment } from 'src/environments/environment';
|
|
import { ProcessesService } from 'src/app/services/processes.service';
|
|
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
|
|
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
|
import { AgendaDataRepositoryService } from 'src/app/module/agenda/data/repository/agenda-data-repository.service';
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
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 {
|
|
|
|
userLoginPreference = ''
|
|
DataArray: Array<Object> = [];
|
|
|
|
service: "agenda";
|
|
typeagenda: "official";
|
|
typeagenda2: "pessoal";
|
|
pr: "100000014";
|
|
md: "100000011";
|
|
date: "60:20";
|
|
location: "Gabinete";
|
|
isProfileOpen = false
|
|
hideImage = false
|
|
logoutOut = false
|
|
notificationStatus = '';
|
|
environment = environment
|
|
taskExist = true;
|
|
taskNotExist = false;
|
|
isloading = false;
|
|
profilePicture = "";
|
|
|
|
|
|
SessionStore = SessionStore;
|
|
|
|
notificationList$: Observable<NotificationTable[]>
|
|
|
|
objectRead = {}
|
|
profilePictureSubject: Observable<UserProfilePicture>
|
|
|
|
constructor(
|
|
private modalController: ModalController,
|
|
private animationController: AnimationController,
|
|
private router: Router,
|
|
private zone: NgZone,
|
|
public ThemeService: ThemeService,
|
|
private notificationService: NotificationsService,
|
|
private processesService: ProcessesService,
|
|
private storageService: StorageService,
|
|
public NotificationHolderService: NotificationHolderService,
|
|
private authservice: AuthService,
|
|
private agendaDataRepository: AgendaDataRepositoryService,
|
|
private toastService: ToastService,
|
|
private notificationRepositoryService: NotificationRepositoryService,
|
|
private UserRepositoryService: UserRepositoryService
|
|
) {
|
|
|
|
this.profilePictureSubject = this.UserRepositoryService.getProfilePictureLive() as any
|
|
window['e'] = () => {
|
|
console.log(
|
|
this.zone.run(() => this.router.navigate(['/home/chat']))
|
|
)
|
|
}
|
|
|
|
router.events.subscribe((val) => {
|
|
this.isProfileOpen = false
|
|
this.logoutOut = true
|
|
});
|
|
|
|
|
|
setTimeout(() => {
|
|
this.hideImage = true
|
|
}, 2000)
|
|
|
|
|
|
this.notificationRepositoryService.init()
|
|
this.subscribe()
|
|
}
|
|
|
|
subscribe() {
|
|
this.notificationList$ = this.notificationRepositoryService.getNotificationLive()
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.getProfilpicture();
|
|
}
|
|
|
|
|
|
toDateString(e) {
|
|
return new Date(e).toDateString()
|
|
}
|
|
|
|
isValidDate(dateString) {
|
|
const date = new Date(dateString);
|
|
return !isNaN(date.getTime());
|
|
}
|
|
|
|
getProfilpicture() {
|
|
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
|
|
if(picture) {
|
|
this.profilePicture = picture
|
|
} else {
|
|
this.profilePicture = "";
|
|
}
|
|
/* console.log(picture) */
|
|
}).catch((error ) => {
|
|
this.profilePicture = "";
|
|
})
|
|
}
|
|
|
|
|
|
close() {
|
|
this.modalController.dismiss();
|
|
}
|
|
|
|
notImplemented() { }
|
|
|
|
asyncNotification() { }
|
|
|
|
getFormatedTime(dateString) {
|
|
var date = new Date(dateString);
|
|
var hours = date.getHours() /* > 12 ? date.getHours() - 12 : date.getHours() */;
|
|
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;
|
|
}
|
|
|
|
@XTracerAsync({name:'profile/notificationClick', bugPrint: true, module:'notification', autoFinish: false})
|
|
async notificatinsRoutes (index, item: NotificationTable, tracing?: TracingType) {
|
|
|
|
try {
|
|
if (item.service === "agenda") {
|
|
this.isloading = true
|
|
if (item.service === "agenda") {
|
|
|
|
tracing.addEvent('start getEventById')
|
|
let res = await this.agendaDataRepository.getEventById(item.idObject, tracing)
|
|
tracing.addEvent('end getEventById')
|
|
|
|
if(item.idObject) {
|
|
|
|
if(res.isOk()) {
|
|
|
|
|
|
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']));
|
|
}
|
|
|
|
this.deleteNotification(item);
|
|
tracing.setAttribute('outcome', 'success')
|
|
} else {
|
|
|
|
tracing.setAttribute('data.exist', 'false')
|
|
tracing.setAttribute('outcome', 'success')
|
|
|
|
if (isHttpError(res.error)) {
|
|
if(res.error.status == 404) {
|
|
// this.toastService._badRequest('Este evento já não existe')
|
|
|
|
this.objectRead[item.notificationId] = true
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
} 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 if (item.service === "event-list" || item.object === "event-list") {
|
|
this.isloading = true
|
|
|
|
if(item.idObject) {
|
|
|
|
let res = await this.agendaDataRepository.getEventById(item.idObject, tracing)
|
|
if(res.isOk()) {
|
|
console.log('evento exist')
|
|
tracing.setAttribute('outcome', 'success')
|
|
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', item.idObject, 'agenda']));
|
|
this.deleteNotification(item);
|
|
this.isloading = false
|
|
} else {
|
|
|
|
console.log('evento não existe')
|
|
tracing.setAttribute('data.exist', 'false')
|
|
tracing.setAttribute('outcome', 'success')
|
|
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')
|
|
tracing.setAttribute('parameters', JSON.stringify({Service:item.service, Object:item.object, IdObject:item.idObject, FolderId:item.folderId}))
|
|
}
|
|
|
|
} else if (item.service === "gabinete-digital") {
|
|
this.isloading = true
|
|
|
|
tracing.addEvent('start getTask')
|
|
this.processesService.GetTask(item.idObject).subscribe((task) => {
|
|
|
|
tracing.addEvent('end getTask')
|
|
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") {
|
|
|
|
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', item.idObject, 'gabinete-digital']));
|
|
}
|
|
else if (item.service === "gabinete-digital" && item.object === "deferimento") {
|
|
|
|
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', item.idObject, 'gabinete-digital']));
|
|
}
|
|
else if (item.service === "gabinete-digital" && item.object === "despachos-pr") {
|
|
|
|
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']));
|
|
}
|
|
else if (item.service === "gabinete-digital" && item.object === "diplomas-assinar") {
|
|
|
|
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', item.idObject, 'gabinete-digital']));
|
|
}
|
|
else if (item.service === "gabinete-digital" && item.object === "diploma-revisao") {
|
|
|
|
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', item.idObject, 'gabinete-digital']));
|
|
}
|
|
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']));
|
|
}
|
|
|
|
this.deleteNotification(item);
|
|
this.isloading = false
|
|
|
|
tracing.setAttribute('outcome', 'success')
|
|
|
|
}, (error) => {
|
|
tracing.addEvent('end getTask')
|
|
tracing.log('gabinete notification not found', {
|
|
notificationObject: item
|
|
})
|
|
|
|
this.objectRead[item.notificationId] = true
|
|
this.isloading = false
|
|
|
|
|
|
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')
|
|
}
|
|
|
|
})
|
|
|
|
|
|
} else if (item.service === "accoes") {
|
|
if (item.service === "accoes" && item.idObject === "accao") {
|
|
this.zone.run(() => this.router.navigate(['/home/publications', item.idObject]));
|
|
this.deleteNotification(item);
|
|
|
|
tracing.setAttribute('outcome', 'success')
|
|
}
|
|
else if (item.service === "accoes" && item.idObject === "publicacao") {
|
|
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', item.folderId, item.idObject]));
|
|
this.deleteNotification(item);
|
|
|
|
tracing.setAttribute('outcome', 'success')
|
|
}
|
|
|
|
} else if (item.service === "chat") {
|
|
|
|
let navigationExtras: NavigationExtras = { queryParams: { "roomId": item.idObject, } };
|
|
|
|
this.zone.run(() => this.router.navigate(['/home/chat']));
|
|
|
|
setTimeout(() => {
|
|
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
|
|
}, 200);
|
|
|
|
|
|
|
|
tracing.setAttribute('outcome', 'success')
|
|
this.deleteNotification(item);
|
|
} else {
|
|
|
|
console.log({service:item.service, Object, IdObject:item.idObject, FolderId:item.folderId})
|
|
|
|
tracing.log('click notification no route', {
|
|
notificationObject: item
|
|
})
|
|
tracing.setAttribute('notification.route', 'false')
|
|
tracing.setAttribute('parameters', JSON.stringify({Service:item.service, Object, IdObject:item.idObject, FolderId:item.folderId}))
|
|
tracing.setAttribute('outcome', 'failed')
|
|
}
|
|
|
|
} catch(error) {
|
|
console.log({service:item.service, Object, IdObject:item.idObject, FolderId: item.folderId})
|
|
|
|
tracing.log('click notification catch', {
|
|
notificationObject: item
|
|
})
|
|
tracing.setAttribute('parameters', JSON.stringify({service:item.service, Object, IdObject:item.idObject, FolderId:item.folderId}))
|
|
tracing.setAttribute('error', JSON.stringify(error))
|
|
tracing.setAttribute('outcome', 'failed')
|
|
}
|
|
|
|
|
|
}
|
|
|
|
deleteNotification(item: NotificationTable) {
|
|
this.objectRead[item.notificationId] = false
|
|
this.notificationRepositoryService.RemoveNotificationStatus(item)
|
|
}
|
|
|
|
logout() {
|
|
this.authservice.logoutUser();
|
|
SessionStore.setInativity(false)
|
|
SessionStore.setUrlBeforeInactivity(this.router.url);
|
|
this.logoutOut == false
|
|
|
|
if (environment.production) {
|
|
window.location.pathname = '/auth'
|
|
this.notificationService.DeletePostToken()
|
|
} else {
|
|
const pathBeforeGoOut = window.location.pathname
|
|
this.router.navigateByUrl('/auth', { replaceUrl: true });
|
|
this.notificationService.DeletePostToken()
|
|
|
|
setTimeout(() => {
|
|
if (this.logoutOut == false || pathBeforeGoOut == window.location.pathname) {
|
|
window.location.pathname = '/auth'
|
|
this.notificationService.DeletePostToken()
|
|
} else {
|
|
|
|
}
|
|
}, 500)
|
|
}
|
|
|
|
}
|
|
|
|
async editProfile() {
|
|
|
|
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');
|
|
}
|
|
|
|
|
|
if (this.isProfileOpen == false) {
|
|
this.isProfileOpen = true;
|
|
|
|
const modal = await this.modalController.create({
|
|
component: EditProfilePage,
|
|
cssClass: 'model profile-modal search-submodal',
|
|
componentProps: {
|
|
}
|
|
});
|
|
|
|
|
|
modal.onDidDismiss().then(() => {
|
|
this.isProfileOpen = false;
|
|
this.getProfilpicture()
|
|
}, (error) => {
|
|
console.log(error)
|
|
})
|
|
|
|
await modal.present();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
keppNotification(item: NotificationTable) {
|
|
// this.NotificationHolderService.notificationList[index].read = false;
|
|
this.objectRead[item.notificationId] = false
|
|
this.notificationRepositoryService.localNotificationStatus(item)
|
|
}
|
|
|
|
doNotKeppNotification(item: NotificationTable) {
|
|
this.objectRead[item.notificationId] = false
|
|
this.deleteNotification(item);
|
|
}
|
|
|
|
}
|