2023-09-18 05:41:33 +01:00
|
|
|
import { Component, OnInit, ChangeDetectorRef, NgZone } from '@angular/core';
|
2021-11-05 15:59:12 +01:00
|
|
|
import { AnimationController, ModalController, Platform } from '@ionic/angular';
|
2021-01-07 10:54:11 +01:00
|
|
|
import { SearchPage } from 'src/app/pages/search/search.page';
|
2021-03-01 15:45:30 +01:00
|
|
|
import { Router } from '@angular/router';
|
2021-08-27 15:21:15 +01:00
|
|
|
import { LoginUserRespose } from 'src/app/models/user.model';
|
2021-07-29 15:59:03 +01:00
|
|
|
import { ProfilePage } from 'src/app/modals/profile/profile.page';
|
2021-08-19 18:28:00 +01:00
|
|
|
import { StorageService } from '../../services/storage.service';
|
2021-08-27 15:21:15 +01:00
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
2021-08-30 10:24:46 +01:00
|
|
|
import { environment } from 'src/environments/environment';
|
2021-10-21 15:05:37 +01:00
|
|
|
import { ThemeService } from '../../services/theme.service';
|
2022-02-16 15:52:59 +01:00
|
|
|
import { RouteService } from 'src/app/services/route.service';
|
2022-03-30 15:08:23 +01:00
|
|
|
import { PermissionList } from 'src/app/models/permission/permissionList';
|
2022-03-28 20:48:21 +01:00
|
|
|
import { PermissionService } from 'src/app/services/permission.service';
|
2023-02-02 18:24:26 +01:00
|
|
|
import { EventTrigger } from 'src/app/services/eventTrigger.service'
|
2023-02-08 10:17:12 +01:00
|
|
|
import { ActiveTabService } from 'src/app/services/active-tab.service';
|
2023-06-26 11:12:57 +01:00
|
|
|
import { NotificationsService } from 'src/app/services/notifications.service';
|
2023-09-18 05:41:33 +01:00
|
|
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
2023-08-31 16:37:11 +01:00
|
|
|
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
|
2024-03-02 12:21:00 +01:00
|
|
|
import { HeaderSettingsService } from "src/app/services/header-settings.service"
|
2020-12-10 11:22:06 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-header',
|
|
|
|
|
templateUrl: './header.page.html',
|
|
|
|
|
styleUrls: ['./header.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class HeaderPage implements OnInit {
|
|
|
|
|
|
2021-03-05 14:54:10 +01:00
|
|
|
searchSubject: string = '';
|
2021-08-19 18:28:00 +01:00
|
|
|
showSearch = false;
|
2021-08-27 15:21:15 +01:00
|
|
|
loggeduser: LoginUserRespose;
|
2021-08-19 18:28:00 +01:00
|
|
|
hideSearchBtn: boolean = false;
|
|
|
|
|
notificationdata: any[] = [];
|
|
|
|
|
DataArray: Array<object> = [];
|
2023-06-26 11:12:57 +01:00
|
|
|
notificationLength: number = 0;
|
2021-08-27 15:21:15 +01:00
|
|
|
SessionStore = SessionStore
|
2021-11-09 17:23:39 +01:00
|
|
|
check: boolean;
|
2021-07-29 15:59:03 +01:00
|
|
|
|
2021-08-30 10:24:46 +01:00
|
|
|
production = environment.production
|
2022-09-23 11:23:24 +01:00
|
|
|
environment = environment
|
2022-10-11 14:53:48 +01:00
|
|
|
canOpenSearch = false
|
2022-12-13 17:21:48 +01:00
|
|
|
showProfileModal = false
|
|
|
|
|
permissionList = new PermissionList();
|
2023-06-26 11:12:57 +01:00
|
|
|
notificationCount: number = 0;
|
2023-08-29 16:05:32 +01:00
|
|
|
profilePicture = "";
|
2023-08-22 11:52:16 +01:00
|
|
|
|
2021-11-05 15:59:12 +01:00
|
|
|
|
2021-03-02 18:53:37 +01:00
|
|
|
constructor(
|
2021-05-18 14:37:43 +01:00
|
|
|
private router: Router,
|
|
|
|
|
private modalController: ModalController,
|
2021-05-12 11:34:28 +01:00
|
|
|
private animationController: AnimationController,
|
2021-08-19 18:28:00 +01:00
|
|
|
private storageservice: StorageService,
|
2022-04-08 12:31:23 +01:00
|
|
|
public platform: Platform,
|
2022-02-16 15:52:59 +01:00
|
|
|
public ThemeService: ThemeService,
|
2022-03-28 20:48:21 +01:00
|
|
|
public RouteService: RouteService,
|
|
|
|
|
public p: PermissionService,
|
2023-02-02 18:24:26 +01:00
|
|
|
private eventTriger: EventTrigger,
|
2023-06-26 11:12:57 +01:00
|
|
|
public ActiveTabService: ActiveTabService,
|
2023-08-22 11:52:16 +01:00
|
|
|
private notificationService: NotificationsService,
|
2023-08-29 16:05:32 +01:00
|
|
|
private cdRef: ChangeDetectorRef,
|
|
|
|
|
private storageService: StorageService,
|
2023-09-18 05:41:33 +01:00
|
|
|
private zone: NgZone,
|
2023-09-22 15:27:43 +01:00
|
|
|
private attachmentService: AttachmentsService,
|
2024-03-02 12:21:00 +01:00
|
|
|
public NotificationHolderService: NotificationHolderService,
|
2024-03-04 09:11:06 +01:00
|
|
|
public HeaderSettingsService: HeaderSettingsService,
|
2021-08-19 18:28:00 +01:00
|
|
|
) {
|
2021-08-27 15:21:15 +01:00
|
|
|
this.loggeduser = SessionStore.user;
|
2021-08-19 18:28:00 +01:00
|
|
|
router.events.subscribe((val) => {
|
2023-03-07 11:48:38 +01:00
|
|
|
this.hideSearch();
|
2021-08-19 18:28:00 +01:00
|
|
|
this.showSearch = false;
|
2022-10-06 15:45:38 +01:00
|
|
|
this.canOpenSearch = true;
|
2022-12-13 17:21:48 +01:00
|
|
|
this.showProfileModal = false
|
2021-08-19 18:28:00 +01:00
|
|
|
});
|
2022-10-05 16:16:31 +01:00
|
|
|
|
2023-08-22 11:52:16 +01:00
|
|
|
this.updateReciveNotification();
|
2023-09-18 05:41:33 +01:00
|
|
|
this.updateDeleteNotification();
|
2022-10-05 16:16:31 +01:00
|
|
|
|
2023-06-26 11:12:57 +01:00
|
|
|
/* this.notificationService.notificationReceived.subscribe(() => {
|
|
|
|
|
console.log('header', 'event.notification')
|
|
|
|
|
this.notificationLengthData()
|
|
|
|
|
}); */
|
|
|
|
|
|
2023-08-22 11:52:16 +01:00
|
|
|
|
2021-08-19 18:28:00 +01:00
|
|
|
}
|
2020-12-10 11:22:06 +01:00
|
|
|
|
2023-09-18 05:41:33 +01:00
|
|
|
ngOnInit() {
|
2021-07-30 14:11:19 +01:00
|
|
|
this.hideSearch();
|
2023-09-18 05:41:33 +01:00
|
|
|
|
|
|
|
|
console.log('Profile picture guid ', this.SessionStore.user.UserPhoto)
|
|
|
|
|
this.getProfilpicture();
|
2023-08-22 11:52:16 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-18 05:41:33 +01:00
|
|
|
reloadComponent(self: boolean, urlToNavigateTo?: string) {
|
|
|
|
|
//skipLocationChange:true means dont update the url to / when navigating
|
|
|
|
|
console.log("Current route I am on header:", this.router.url);
|
|
|
|
|
const url = self ? this.router.url : urlToNavigateTo;
|
|
|
|
|
this.zone.run(() => this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
|
|
|
|
|
this.zone.run(() => this.router.navigate([`/${url}`]).then(() => {
|
|
|
|
|
console.log(`After navigation I am on header:${this.router.url}`)
|
|
|
|
|
}))
|
|
|
|
|
}))
|
|
|
|
|
}
|
2023-09-14 11:58:24 +01:00
|
|
|
|
|
|
|
|
|
2023-08-29 16:05:32 +01:00
|
|
|
getProfilpicture() {
|
2023-09-18 05:41:33 +01:00
|
|
|
|
2023-11-15 15:14:08 +01:00
|
|
|
if (this.SessionStore.user.UserPhoto) {
|
2023-10-26 13:28:54 +01:00
|
|
|
this.attachmentService.getUserProfilePhoto(this.SessionStore.user.UserPhoto).subscribe((base) => {
|
|
|
|
|
|
|
|
|
|
this.storageService.store(this.SessionStore.user.RoleID.toString(), 'data:image/jpeg;base64,' + base).then((value) => {
|
|
|
|
|
this.profilePicture = 'data:image/jpeg;base64,' + base;
|
2023-11-15 15:14:08 +01:00
|
|
|
|
2023-11-09 10:28:58 +01:00
|
|
|
console.log('picture saved')
|
2023-10-26 13:28:54 +01:00
|
|
|
}).catch((error) => {
|
|
|
|
|
console.log('picture not saved')
|
|
|
|
|
});
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.log('profile picture errro: ', error)
|
|
|
|
|
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
|
2023-11-09 10:28:58 +01:00
|
|
|
/* console.log(picture) */
|
2023-10-26 13:28:54 +01:00
|
|
|
this.profilePicture = picture
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
this.profilePicture = "";
|
|
|
|
|
})
|
2023-09-18 05:41:33 +01:00
|
|
|
})
|
|
|
|
|
|
2023-10-26 13:28:54 +01:00
|
|
|
} else {
|
|
|
|
|
this.profilePicture = "";
|
|
|
|
|
}
|
2023-09-18 05:41:33 +01:00
|
|
|
|
2023-08-29 16:05:32 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-22 11:52:16 +01:00
|
|
|
updateReciveNotification() {
|
|
|
|
|
this.eventTriger.getObservable().subscribe((event) => {
|
|
|
|
|
if (event.notification == "recive") {
|
|
|
|
|
console.log('header', event.notification)
|
2023-09-09 14:40:08 +01:00
|
|
|
this.notificationLengthData()
|
2023-08-22 11:52:16 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateDeleteNotification() {
|
|
|
|
|
this.eventTriger.getObservable().subscribe((event) => {
|
|
|
|
|
if (event.notification == "deleted") {
|
|
|
|
|
console.log('header', event.notification)
|
2023-09-09 14:40:08 +01:00
|
|
|
this.notificationLengthData()
|
2023-08-22 11:52:16 +01:00
|
|
|
}
|
|
|
|
|
});
|
2021-11-05 15:59:12 +01:00
|
|
|
}
|
2021-09-21 06:08:01 +01:00
|
|
|
|
2021-08-30 14:55:24 +01:00
|
|
|
|
2021-11-08 15:53:28 +01:00
|
|
|
async notificationLengthData() {
|
2023-09-09 14:40:08 +01:00
|
|
|
console.log('Call notification data')
|
2021-11-08 15:53:28 +01:00
|
|
|
await this.storageservice.get("Notifications").then((value) => {
|
2023-08-22 11:52:16 +01:00
|
|
|
|
2023-09-18 05:41:33 +01:00
|
|
|
console.log('Get notification data',)
|
|
|
|
|
|
2023-09-19 10:40:39 +01:00
|
|
|
this.zone.run(() => {
|
|
|
|
|
this.notificationLength = value.length;
|
|
|
|
|
console.log('Call notification data', this.notificationLength)
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-18 05:41:33 +01:00
|
|
|
|
2023-08-22 11:52:16 +01:00
|
|
|
|
2023-01-04 15:03:29 +01:00
|
|
|
}).catch((error) => {
|
2023-08-22 11:52:16 +01:00
|
|
|
if (!error) {
|
2023-09-19 10:40:39 +01:00
|
|
|
this.zone.run(() => {
|
|
|
|
|
console.error('header storage get notification', error)
|
|
|
|
|
this.notificationLength = 0;
|
|
|
|
|
});
|
2023-01-04 15:03:29 +01:00
|
|
|
} else {
|
|
|
|
|
console.error('header storage get notification', error)
|
|
|
|
|
}
|
2021-08-19 18:28:00 +01:00
|
|
|
})
|
2021-07-30 14:11:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 18:28:00 +01:00
|
|
|
hideSearch() {
|
2023-03-07 11:48:38 +01:00
|
|
|
if (this.router.url.startsWith('/home/events') || this.router.url.startsWith('/home/chat')) {
|
2021-07-30 14:11:19 +01:00
|
|
|
this.hideSearchBtn = true;
|
2023-03-07 11:48:38 +01:00
|
|
|
} else {
|
|
|
|
|
this.hideSearchBtn = false;
|
2021-07-30 14:11:19 +01:00
|
|
|
}
|
2020-12-10 11:22:06 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 14:46:38 +01:00
|
|
|
|
2021-01-07 10:54:11 +01:00
|
|
|
async openSearch() {
|
2021-04-08 19:25:59 +01:00
|
|
|
|
2021-04-29 15:25:14 +01:00
|
|
|
let classs, showSearchInput, type;
|
2021-08-19 18:28:00 +01:00
|
|
|
if (window.innerWidth < 1366) {
|
2021-07-08 15:54:03 +01:00
|
|
|
classs = 'modal modal-width-100'
|
2021-04-29 15:25:14 +01:00
|
|
|
showSearchInput = true
|
2021-04-23 14:30:18 +01:00
|
|
|
} else {
|
2021-06-24 11:08:17 +01:00
|
|
|
classs = 'modal modal-desktop desktop-search'
|
2021-04-29 15:25:14 +01:00
|
|
|
showSearchInput = false
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 18:28:00 +01:00
|
|
|
if (window.location.pathname.startsWith('/home/agenda')) {
|
2021-04-29 15:25:14 +01:00
|
|
|
type = "Agenda"
|
2021-08-10 13:22:33 +01:00
|
|
|
} else if (window.location.pathname.startsWith('/home/gabinete-digital')) {
|
2021-04-29 15:25:14 +01:00
|
|
|
type = "AccoesPresidenciais & ArquivoDespachoElect"
|
|
|
|
|
|
2021-08-10 13:22:33 +01:00
|
|
|
} else if (window.location.pathname.startsWith('/home/publications')) {
|
2021-04-29 15:25:14 +01:00
|
|
|
type = "AccoesPresidenciais"
|
2021-04-23 14:30:18 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-22 11:52:16 +01:00
|
|
|
if (this.canOpenSearch) {
|
2022-10-06 15:45:38 +01:00
|
|
|
this.canOpenSearch = false
|
2023-08-22 11:52:16 +01:00
|
|
|
|
2022-10-06 15:45:38 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: SearchPage,
|
|
|
|
|
cssClass: classs,
|
|
|
|
|
componentProps: {
|
|
|
|
|
type: type,
|
|
|
|
|
showSearchInput: showSearchInput,
|
|
|
|
|
select: false
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-08-22 11:52:16 +01:00
|
|
|
|
2022-10-06 15:45:38 +01:00
|
|
|
|
|
|
|
|
modal.onDidDismiss().then(() => {
|
|
|
|
|
|
|
|
|
|
this.canOpenSearch = true;
|
|
|
|
|
|
|
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
await modal.present();
|
2022-10-06 15:45:38 +01:00
|
|
|
|
|
|
|
|
}
|
2021-01-07 10:54:11 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 18:28:00 +01:00
|
|
|
changeRoute(path) {
|
2021-03-01 15:45:30 +01:00
|
|
|
this.router.navigateByUrl(path)
|
|
|
|
|
}
|
2021-03-02 18:53:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
async openProfile() {
|
|
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
}
|
2021-07-29 15:59:03 +01:00
|
|
|
|
2023-08-22 11:52:16 +01:00
|
|
|
if (!this.showProfileModal) {
|
2022-12-13 17:21:48 +01:00
|
|
|
this.showProfileModal = true
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: ProfilePage,
|
|
|
|
|
cssClass: 'model profile-modal search-submodal',
|
|
|
|
|
componentProps: {
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-08-22 11:52:16 +01:00
|
|
|
|
|
|
|
|
|
2022-12-13 17:21:48 +01:00
|
|
|
modal.onDidDismiss().then(() => {
|
|
|
|
|
this.notificationLengthData()
|
2023-11-15 15:14:08 +01:00
|
|
|
this.getProfilePictureSorage()
|
2022-12-13 17:21:48 +01:00
|
|
|
this.showProfileModal = false
|
|
|
|
|
})
|
2023-07-15 11:01:09 +01:00
|
|
|
|
|
|
|
|
await modal.present();
|
2022-12-13 17:21:48 +01:00
|
|
|
}
|
2023-08-22 11:52:16 +01:00
|
|
|
|
2021-03-02 18:53:37 +01:00
|
|
|
}
|
2021-03-02 19:00:55 +01:00
|
|
|
|
2021-08-19 18:28:00 +01:00
|
|
|
async dynamicSearch() {
|
2022-10-13 14:37:03 +01:00
|
|
|
|
2023-08-22 11:52:16 +01:00
|
|
|
if (window['dynamicSearch']) {
|
2023-01-04 11:11:30 +01:00
|
|
|
window['dynamicSearch'](this.searchSubject)
|
2022-10-13 14:37:03 +01:00
|
|
|
} else {
|
2023-08-22 11:52:16 +01:00
|
|
|
setTimeout(() => {
|
2022-10-13 14:37:03 +01:00
|
|
|
this.dynamicSearch()
|
|
|
|
|
}, 100)
|
|
|
|
|
}
|
2021-03-05 14:54:10 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 19:00:55 +01:00
|
|
|
|
2021-08-19 18:28:00 +01:00
|
|
|
async closeSearch() {
|
2021-03-11 10:31:46 +01:00
|
|
|
this.modalController.dismiss()
|
2021-03-05 14:54:10 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 18:28:00 +01:00
|
|
|
/**
|
|
|
|
|
* @description set empty value to searchSubject
|
|
|
|
|
*/
|
|
|
|
|
clearSearchInput() {
|
2021-03-05 14:54:10 +01:00
|
|
|
this.searchSubject = "";
|
|
|
|
|
window['dynamicSearch'](this.searchSubject)
|
2021-08-19 18:28:00 +01:00
|
|
|
}
|
2021-03-05 14:54:10 +01:00
|
|
|
|
2021-08-19 18:28:00 +01:00
|
|
|
async basicSearch() {
|
2023-08-22 11:52:16 +01:00
|
|
|
|
|
|
|
|
if (window['searchTriger']) {
|
2022-10-13 14:37:03 +01:00
|
|
|
window['searchTriger']()
|
2021-08-06 12:19:38 +01:00
|
|
|
} else {
|
2023-08-22 11:52:16 +01:00
|
|
|
setTimeout(() => {
|
2022-10-13 14:37:03 +01:00
|
|
|
this.basicSearch()
|
|
|
|
|
}, 100)
|
2021-08-06 12:19:38 +01:00
|
|
|
}
|
2022-10-13 14:37:03 +01:00
|
|
|
|
2021-08-06 12:19:38 +01:00
|
|
|
}
|
2022-10-13 14:37:03 +01:00
|
|
|
|
2023-11-15 15:14:08 +01:00
|
|
|
getProfilePictureSorage() {
|
|
|
|
|
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
|
|
|
|
|
/* console.log(picture) */
|
|
|
|
|
this.profilePicture = picture
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
this.profilePicture = "";
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-29 15:59:03 +01:00
|
|
|
}
|