2020-12-10 11:22:06 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-08-20 18:22:56 +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-11-04 06:39:39 +01:00
|
|
|
//import { NotificationsService } from '../../services/notifications.service';
|
2021-08-30 10:24:46 +01:00
|
|
|
import { environment } from 'src/environments/environment';
|
2021-09-21 06:08:01 +01:00
|
|
|
import { EventTrigger } from '../../services/eventTrigger.service';
|
2021-10-21 15:05:37 +01:00
|
|
|
import { ThemeService } from '../../services/theme.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> = [];
|
|
|
|
|
notificationLength: 0;
|
2021-08-27 15:21:15 +01:00
|
|
|
SessionStore = SessionStore
|
2021-07-29 15:59:03 +01:00
|
|
|
|
2021-08-30 10:24:46 +01:00
|
|
|
production = environment.production
|
|
|
|
|
|
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,
|
2021-08-20 18:22:56 +01:00
|
|
|
private platform: Platform,
|
2021-11-04 06:39:39 +01:00
|
|
|
//private notificationsService: NotificationsService,
|
2021-10-21 15:05:37 +01:00
|
|
|
private eventrigger: EventTrigger,
|
|
|
|
|
public ThemeService: ThemeService
|
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) => {
|
|
|
|
|
this.showSearch = false;
|
|
|
|
|
//this.modalController.dismiss();
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-12-10 11:22:06 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-07-30 14:11:19 +01:00
|
|
|
this.hideSearch();
|
2021-08-31 09:11:41 +01:00
|
|
|
this.notificationLengthData();
|
|
|
|
|
|
2021-09-21 06:08:01 +01:00
|
|
|
/* if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
2021-08-20 18:22:56 +01:00
|
|
|
console.log('Notifications not supported')
|
2021-08-31 09:00:33 +01:00
|
|
|
this.UpdateNotificationCount();
|
2021-08-20 18:22:56 +01:00
|
|
|
} else {
|
2021-08-30 14:55:24 +01:00
|
|
|
this.UpdateNotificationCount();
|
2021-09-21 06:08:01 +01:00
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
this.eventrigger.getObservable().subscribe((data)=>{
|
|
|
|
|
if(data.notification == "delete" || "recive"){
|
|
|
|
|
this.notificationLengthData();
|
|
|
|
|
console.log('Deleted notification',data )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
2021-08-19 18:28:00 +01:00
|
|
|
|
|
|
|
|
}
|
2021-08-31 09:00:33 +01:00
|
|
|
|
2021-11-04 06:39:39 +01:00
|
|
|
/* UpdateNotificationCount() {
|
2021-08-30 14:55:24 +01:00
|
|
|
this.notificationsService.registerCallback(
|
|
|
|
|
'any',
|
|
|
|
|
() => {
|
2021-08-31 09:00:33 +01:00
|
|
|
setTimeout(()=>{
|
|
|
|
|
this.notificationLengthData();
|
|
|
|
|
}, 100)
|
2021-08-30 14:55:24 +01:00
|
|
|
}
|
|
|
|
|
)
|
2021-11-04 06:39:39 +01:00
|
|
|
} */
|
2021-08-30 14:55:24 +01:00
|
|
|
|
|
|
|
|
notificationLengthData() {
|
2021-08-19 18:28:00 +01:00
|
|
|
this.storageservice.get("Notifications").then((value) => {
|
|
|
|
|
console.log("Init get store", value)
|
|
|
|
|
|
2021-08-30 14:55:24 +01:00
|
|
|
/* var data = JSON.parse(value); */
|
|
|
|
|
this.notificationLength = value.length;
|
2021-08-19 18:28:00 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
console.log('Timer badge count')
|
2021-07-30 14:11:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 18:28:00 +01:00
|
|
|
hideSearch() {
|
|
|
|
|
if (this.router.url == '/home/events' || this.router.url == '/home/chat') {
|
2021-07-30 14:11:19 +01:00
|
|
|
this.hideSearchBtn = true;
|
|
|
|
|
}
|
2020-12-10 11:22:06 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 14:46:38 +01:00
|
|
|
locationPathname(): string {
|
|
|
|
|
return window.location.pathname
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-01-07 10:54:11 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: SearchPage,
|
2021-04-23 14:30:18 +01:00
|
|
|
cssClass: classs,
|
2021-01-07 10:54:11 +01:00
|
|
|
componentProps: {
|
2021-07-26 11:34:46 +01:00
|
|
|
type: type,
|
2021-04-30 14:12:45 +01:00
|
|
|
showSearchInput: showSearchInput,
|
|
|
|
|
select: false
|
2021-01-07 10:54:11 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return await modal.present();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2021-03-02 18:53:37 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
enterAnimation,
|
|
|
|
|
leaveAnimation,
|
2021-07-29 15:59:03 +01:00
|
|
|
component: ProfilePage,
|
2021-03-11 10:31:46 +01:00
|
|
|
cssClass: 'model profile-modal search-submodal',
|
2021-03-02 18:53:37 +01:00
|
|
|
componentProps: {
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-08-30 12:07:14 +01:00
|
|
|
await modal.present();
|
2021-08-31 09:00:33 +01:00
|
|
|
|
|
|
|
|
modal.onDidDismiss().then(()=>{
|
|
|
|
|
this.notificationLengthData()
|
|
|
|
|
})
|
2021-08-30 12:07:14 +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() {
|
2021-03-05 14:54:10 +01:00
|
|
|
window['dynamicSearch'](this.searchSubject)
|
|
|
|
|
}
|
|
|
|
|
|
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() {
|
2021-03-05 14:54:10 +01:00
|
|
|
window['searchTriger']()
|
2021-08-19 18:28:00 +01:00
|
|
|
}
|
2021-08-06 12:19:38 +01:00
|
|
|
|
2021-08-19 18:28:00 +01:00
|
|
|
profileLabel(text) {
|
2021-08-06 12:19:38 +01:00
|
|
|
if (text == 'MDGPR') {
|
|
|
|
|
return 'MD'
|
|
|
|
|
} else if (text == 'PR') {
|
|
|
|
|
return text
|
|
|
|
|
} else {
|
|
|
|
|
return 'UN'
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-29 15:59:03 +01:00
|
|
|
}
|