Files
doneit-web/src/app/shared/headers/header-no-search/profile/profile.page.ts
T
Peter Maquiran 43db3c2193 Improve
2021-07-05 11:27:10 +01:00

151 lines
3.9 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AnimationController, ModalController } from '@ionic/angular';
import { User } from 'src/app/models/user.model';
import { AuthService } from 'src/app/services/auth.service';
import { FingerprintPage } from 'src/app/shared/fingerprint/fingerprint.page';
import { PinPage } from 'src/app/shared/pin/pin.page';
@Component({
selector: 'app-profile',
templateUrl: './profile.page.html',
styleUrls: ['./profile.page.scss'],
})
export class ProfileComponent implements OnInit {
loggeduser: User;
userLoginPreference = ''
constructor(private modalController:ModalController,
private authService: AuthService,
private animationController: AnimationController,
private router: Router) {
this.loggeduser = authService.ValidatedUser;
console.log(this.loggeduser.RoleDescription)
this.checkState()
}
ngOnInit() {}
close() {
this.modalController.dismiss();
}
async addPin() {
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: PinPage,
cssClass: 'model profile-modal',
componentProps: {
}
});
modal.present();
}
async addFingerprint() {
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: FingerprintPage,
cssClass: 'model profile-modal',
componentProps: {
}
});
modal.present();
}
logout() {
// clear local storage
window.localStorage.clear();
this.router.navigate(['/']);
}
LoginPreferenceMethod(type: string) {
let userData = JSON.parse(localStorage.getItem('UserData')) || {}
if (userData.hasOwnProperty('loginPreference')) {
if (userData.loginPreference != type) {
if (type) {
userData.loginPreference = type
}
} else {
userData.loginPreference = 'none'
}
} else {
userData.loginPreference = 'none'
}
localStorage.setItem('UserData', JSON.stringify(userData) )
}
checkState() {
let userData = JSON.parse(localStorage.getItem('UserData')) || {}
if (userData.hasOwnProperty('loginPreference')) {
this.userLoginPreference = userData.loginPreference
} else {
this.userLoginPreference = ''
}
}
}