mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
272 lines
7.0 KiB
TypeScript
272 lines
7.0 KiB
TypeScript
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
|
|
import { AnimationController, ModalController, Platform } from '@ionic/angular';
|
|
import { SearchPage } from 'src/app/pages/search/search.page';
|
|
import { Router } from '@angular/router';
|
|
import { LoginUserRespose } from 'src/app/models/user.model';
|
|
import { ProfilePage } from 'src/app/modals/profile/profile.page';
|
|
import { StorageService } from '../../services/storage.service';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { environment } from 'src/environments/environment';
|
|
import { ThemeService } from '../../services/theme.service';
|
|
import { RouteService } from 'src/app/services/route.service';
|
|
import { PermissionList } from 'src/app/models/permission/permissionList';
|
|
import { PermissionService } from 'src/app/services/permission.service';
|
|
import { EventTrigger } from 'src/app/services/eventTrigger.service'
|
|
import { ActiveTabService } from 'src/app/services/active-tab.service';
|
|
import { NotificationsService } from 'src/app/services/notifications.service';
|
|
|
|
@Component({
|
|
selector: 'app-header',
|
|
templateUrl: './header.page.html',
|
|
styleUrls: ['./header.page.scss'],
|
|
})
|
|
export class HeaderPage implements OnInit {
|
|
|
|
searchSubject: string = '';
|
|
showSearch = false;
|
|
loggeduser: LoginUserRespose;
|
|
hideSearchBtn: boolean = false;
|
|
notificationdata: any[] = [];
|
|
DataArray: Array<object> = [];
|
|
notificationLength: number = 0;
|
|
SessionStore = SessionStore
|
|
check: boolean;
|
|
|
|
production = environment.production
|
|
environment = environment
|
|
canOpenSearch = false
|
|
showProfileModal = false
|
|
permissionList = new PermissionList();
|
|
notificationCount: number = 0;
|
|
profilePicture = "";
|
|
|
|
|
|
constructor(
|
|
private router: Router,
|
|
private modalController: ModalController,
|
|
private animationController: AnimationController,
|
|
private storageservice: StorageService,
|
|
public platform: Platform,
|
|
public ThemeService: ThemeService,
|
|
public RouteService: RouteService,
|
|
public p: PermissionService,
|
|
private eventTriger: EventTrigger,
|
|
public ActiveTabService: ActiveTabService,
|
|
private notificationService: NotificationsService,
|
|
private cdRef: ChangeDetectorRef,
|
|
private storageService: StorageService,
|
|
) {
|
|
this.loggeduser = SessionStore.user;
|
|
router.events.subscribe((val) => {
|
|
this.hideSearch();
|
|
this.showSearch = false;
|
|
this.canOpenSearch = true;
|
|
this.showProfileModal = false
|
|
});
|
|
|
|
this.updateReciveNotification();
|
|
this.updateDeleteNotification();
|
|
|
|
/* this.notificationService.notificationReceived.subscribe(() => {
|
|
console.log('header', 'event.notification')
|
|
this.notificationLengthData()
|
|
}); */
|
|
|
|
|
|
}
|
|
|
|
async ngOnInit() {
|
|
this.hideSearch();
|
|
/* this.notificationLengthData(); */
|
|
this.getProfilpicture();
|
|
|
|
}
|
|
|
|
getProfilpicture() {
|
|
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
|
|
console.log(picture)
|
|
this.profilePicture = picture
|
|
}).catch((error ) => {
|
|
this.profilePicture = "";
|
|
})
|
|
}
|
|
|
|
updateReciveNotification() {
|
|
this.eventTriger.getObservable().subscribe((event) => {
|
|
if (event.notification == "recive") {
|
|
console.log('header', event.notification)
|
|
this.notificationLength++
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
updateDeleteNotification() {
|
|
this.eventTriger.getObservable().subscribe((event) => {
|
|
if (event.notification == "deleted") {
|
|
console.log('header', event.notification)
|
|
this.notificationLength--
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
async notificationLengthData() {
|
|
await this.storageservice.get("Notifications").then((value) => {
|
|
|
|
|
|
|
|
this.notificationLength = value.length;
|
|
|
|
}).catch((error) => {
|
|
if (!error) {
|
|
this.notificationLength = 0;
|
|
} else {
|
|
console.error('header storage get notification', error)
|
|
}
|
|
})
|
|
}
|
|
|
|
hideSearch() {
|
|
if (this.router.url.startsWith('/home/events') || this.router.url.startsWith('/home/chat')) {
|
|
this.hideSearchBtn = true;
|
|
} else {
|
|
this.hideSearchBtn = false;
|
|
}
|
|
}
|
|
|
|
|
|
async openSearch() {
|
|
|
|
let classs, showSearchInput, type;
|
|
if (window.innerWidth < 1366) {
|
|
classs = 'modal modal-width-100'
|
|
showSearchInput = true
|
|
} else {
|
|
classs = 'modal modal-desktop desktop-search'
|
|
showSearchInput = false
|
|
}
|
|
|
|
if (window.location.pathname.startsWith('/home/agenda')) {
|
|
type = "Agenda"
|
|
} else if (window.location.pathname.startsWith('/home/gabinete-digital')) {
|
|
type = "AccoesPresidenciais & ArquivoDespachoElect"
|
|
|
|
} else if (window.location.pathname.startsWith('/home/publications')) {
|
|
type = "AccoesPresidenciais"
|
|
}
|
|
|
|
if (this.canOpenSearch) {
|
|
this.canOpenSearch = false
|
|
|
|
const modal = await this.modalController.create({
|
|
component: SearchPage,
|
|
cssClass: classs,
|
|
componentProps: {
|
|
type: type,
|
|
showSearchInput: showSearchInput,
|
|
select: false
|
|
}
|
|
});
|
|
|
|
|
|
|
|
modal.onDidDismiss().then(() => {
|
|
|
|
this.canOpenSearch = true;
|
|
|
|
});
|
|
await modal.present();
|
|
|
|
}
|
|
}
|
|
|
|
changeRoute(path) {
|
|
this.router.navigateByUrl(path)
|
|
}
|
|
|
|
|
|
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');
|
|
}
|
|
|
|
if (!this.showProfileModal) {
|
|
this.showProfileModal = true
|
|
const modal = await this.modalController.create({
|
|
component: ProfilePage,
|
|
cssClass: 'model profile-modal search-submodal',
|
|
componentProps: {
|
|
}
|
|
});
|
|
|
|
|
|
modal.onDidDismiss().then(() => {
|
|
this.notificationLengthData()
|
|
this.getProfilpicture()
|
|
this.showProfileModal = false
|
|
})
|
|
|
|
await modal.present();
|
|
}
|
|
|
|
}
|
|
|
|
async dynamicSearch() {
|
|
|
|
if (window['dynamicSearch']) {
|
|
window['dynamicSearch'](this.searchSubject)
|
|
} else {
|
|
setTimeout(() => {
|
|
this.dynamicSearch()
|
|
}, 100)
|
|
}
|
|
}
|
|
|
|
|
|
async closeSearch() {
|
|
this.modalController.dismiss()
|
|
}
|
|
|
|
/**
|
|
* @description set empty value to searchSubject
|
|
*/
|
|
clearSearchInput() {
|
|
this.searchSubject = "";
|
|
window['dynamicSearch'](this.searchSubject)
|
|
}
|
|
|
|
async basicSearch() {
|
|
|
|
if (window['searchTriger']) {
|
|
window['searchTriger']()
|
|
} else {
|
|
setTimeout(() => {
|
|
this.basicSearch()
|
|
}, 100)
|
|
}
|
|
|
|
}
|
|
|
|
}
|