Files
doneit-web/src/app/shared/header/header.page.ts
T
Peter Maquiran 38313e3260 Fix
2021-07-30 22:12:50 +01:00

138 lines
3.5 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { AnimationController, ModalController } from '@ionic/angular';
import { SearchPage } from 'src/app/pages/search/search.page';
import { Router } from '@angular/router';
import { ProfileComponent } from '../headers/header-no-search/profile/profile.page';
import { AuthService } from 'src/app/services/auth.service';
import { User } from 'src/app/models/user.model';
import { ProfilePage } from 'src/app/modals/profile/profile.page';
@Component({
selector: 'app-header',
templateUrl: './header.page.html',
styleUrls: ['./header.page.scss'],
})
export class HeaderPage implements OnInit {
searchSubject: string = '';
showSearch=false;
loggeduser: User;
constructor(
private router: Router,
private modalController: ModalController,
private animationController: AnimationController,
authService: AuthService
) {
this.loggeduser = authService.ValidatedUser;
router.events.subscribe((val) => {
this.showSearch=false;
//this.modalController.dismiss();
});
}
ngOnInit() {
}
locationPathname(): string {
return window.location.pathname
}
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 == '/home/agenda') {
type = "Agenda"
} else if (window.location.pathname =='/home/gabinete-digital') {
type = "AccoesPresidenciais & ArquivoDespachoElect"
} else if (window.location.pathname == '/home/publications') {
type = "AccoesPresidenciais"
}
const modal = await this.modalController.create({
component: SearchPage,
cssClass: classs,
componentProps: {
type: type,
showSearchInput: showSearchInput,
select: false
}
});
return 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');
}
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
component: ProfilePage,
cssClass: 'model profile-modal search-submodal',
componentProps: {
}
});
return await modal.present();
}
async dynamicSearch(){
window['dynamicSearch'](this.searchSubject)
}
async closeSearch(){
this.modalController.dismiss()
}
/**
* @description set empty value to searchSubject
*/
clearSearchInput(){
this.searchSubject = "";
window['dynamicSearch'](this.searchSubject)
}
async basicSearch() {
window['searchTriger']()
}
}