2024-07-07 14:48:52 +03:30
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { Router, NavigationEnd } from "@angular/router";
|
|
|
|
import { loginChecker } from '../../providers/login_checker';
|
|
|
|
import { User } from '../../providers/mikrowizard/user';
|
|
|
|
import { navItems } from './_nav';
|
|
|
|
import { dataProvider } from '../../providers/mikrowizard/data';
|
2024-08-26 11:13:31 +03:30
|
|
|
import { arch } from 'os';
|
|
|
|
import { DomSanitizer } from '@angular/platform-browser';
|
2025-01-02 20:20:59 +03:00
|
|
|
import { disconnect } from 'process';
|
2024-07-07 14:48:52 +03:30
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-dashboard',
|
|
|
|
templateUrl: './default-layout.component.html',
|
|
|
|
styleUrls: ['./default-layout.component.scss'],
|
|
|
|
})
|
|
|
|
export class DefaultLayoutComponent implements OnInit {
|
|
|
|
|
|
|
|
public navItems = navItems;
|
|
|
|
public current_user: User;
|
|
|
|
public uid: number;
|
|
|
|
public uname: string;
|
|
|
|
public fname: string;
|
|
|
|
public lname: string;
|
2024-07-13 10:36:07 +03:30
|
|
|
public ispro: boolean=false;
|
2024-08-26 11:13:31 +03:30
|
|
|
public action: string="password";
|
2024-07-07 14:48:52 +03:30
|
|
|
public UserProfileModalVisible:boolean;
|
2025-01-02 20:20:59 +03:00
|
|
|
public ConfirmModalVisible:boolean;
|
2024-07-07 14:48:52 +03:30
|
|
|
public error:any=false;
|
2024-08-26 11:13:31 +03:30
|
|
|
public currentStep:number=1;
|
|
|
|
public qrCode:any=false;
|
|
|
|
public totpCode:string='';
|
|
|
|
public errorMessage:any=false;
|
2025-01-02 20:20:59 +03:00
|
|
|
public data:any={};
|
|
|
|
public timer:any;
|
2024-07-07 14:48:52 +03:30
|
|
|
public password:any={
|
|
|
|
'cupass':'',
|
|
|
|
'pass1':'',
|
|
|
|
'pass2':''
|
|
|
|
};
|
|
|
|
|
|
|
|
public passvalid:any={
|
|
|
|
'cupass':false,
|
|
|
|
'pass1':false,
|
|
|
|
'pass2':false
|
|
|
|
};
|
|
|
|
version=require('../../../../package.json').version;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
private login_checker: loginChecker,
|
|
|
|
private data_provider: dataProvider,
|
2024-08-26 11:13:31 +03:30
|
|
|
private _sanitizer: DomSanitizer
|
2024-07-07 14:48:52 +03:30
|
|
|
|
|
|
|
) {
|
|
|
|
var _self = this;
|
|
|
|
var session_info: string = localStorage.getItem('current_user') || "[]";
|
|
|
|
this.current_user = JSON.parse(session_info);
|
|
|
|
this.router.events.subscribe((ev) => {
|
|
|
|
if (ev instanceof NavigationEnd) {
|
|
|
|
if (!this.login_checker.isLoggedIn()) {
|
|
|
|
setTimeout(function () {
|
|
|
|
_self.router.navigate(['login']);
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2024-08-26 11:13:31 +03:30
|
|
|
}
|
2024-07-13 10:36:07 +03:30
|
|
|
|
2024-08-26 11:13:31 +03:30
|
|
|
otpwizard(step:number){
|
|
|
|
var _self=this;
|
|
|
|
if(step==1){
|
|
|
|
if(this.qrCode)
|
|
|
|
this.currentStep=2;
|
|
|
|
else
|
|
|
|
this.currentStep=3;
|
|
|
|
}
|
|
|
|
if(step==2){
|
|
|
|
this.currentStep=3;
|
|
|
|
}
|
|
|
|
if(step==3){
|
|
|
|
if(this.qrCode!=false)
|
|
|
|
this.data_provider.mytotp('enable',this.totpCode).then(res => {
|
|
|
|
if(res['status']=='success'){
|
|
|
|
_self.UserProfileModalVisible = false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.errorMessage=res['err'];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
else
|
|
|
|
this.data_provider.mytotp('disable',this.totpCode).then(res => {
|
|
|
|
if(res['status']=='success'){
|
|
|
|
_self.UserProfileModalVisible = false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.errorMessage=res['err'];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2024-07-07 14:48:52 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
password_changed(variable:string,value:any){
|
|
|
|
var _self=this;
|
|
|
|
this.password[variable]=value;
|
2024-07-13 10:36:07 +03:30
|
|
|
if(this.password['pass1']==this.password['pass2']){
|
2024-07-07 14:48:52 +03:30
|
|
|
_self.passvalid['pass2']=true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
_self.passvalid['pass2']=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-26 11:13:31 +03:30
|
|
|
show_user_modal(action:string){
|
|
|
|
this.currentStep=1;
|
|
|
|
this.errorMessage=false;
|
|
|
|
this.totpCode='';
|
|
|
|
this.qrCode=false;
|
|
|
|
this.action=action;
|
|
|
|
if(action=='otp')
|
|
|
|
this.data_provider.mytotp('enable').then(res => {
|
|
|
|
if(res['status']=='success'){
|
|
|
|
this.currentStep=1;
|
|
|
|
this.qrCode=this._sanitizer.bypassSecurityTrustResourceUrl('data:image/jpg;base64,'+ res.otp);
|
|
|
|
this.UserProfileModalVisible = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.qrCode=false;
|
|
|
|
this.currentStep=1;
|
|
|
|
this.UserProfileModalVisible = true;
|
|
|
|
|
|
|
|
this.errorMessage=res['err'];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
else
|
|
|
|
this.UserProfileModalVisible = true;
|
2024-07-07 14:48:52 +03:30
|
|
|
}
|
2025-01-02 20:20:59 +03:00
|
|
|
show_confirm_modal(data:any){
|
|
|
|
this.data={};
|
|
|
|
if (data.action=='CancelTask'){
|
|
|
|
this.action=data.action;
|
|
|
|
this.data=data.data;
|
|
|
|
console.dir(this.data);
|
|
|
|
console.dir(this.action);
|
|
|
|
//disable submit button
|
|
|
|
this.data['SubmitDisable']=false;
|
|
|
|
this.ConfirmModalVisible = true;
|
|
|
|
}
|
|
|
|
if (data.action=='update'){
|
|
|
|
this.action='update';
|
|
|
|
this.data={};
|
|
|
|
this.ConfirmModalVisible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConfirmAction(){
|
|
|
|
var _self=this;
|
|
|
|
if(this.action=='CancelTask'){
|
|
|
|
this.data_provider.stop_task(this.data['signal']).then(res => {
|
|
|
|
//disable submit button
|
|
|
|
if(res['status']=='success'){
|
|
|
|
setTimeout(function () {
|
|
|
|
_self.ConfirmModalVisible = false;
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
this.data['SubmitDisable']=true;
|
|
|
|
//wait 5 seconds before hiding the modal
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if(this.action=='update'){
|
|
|
|
window.location.href = window.location.href.replace(/#.*$/, '')
|
|
|
|
}
|
|
|
|
}
|
2024-07-07 14:48:52 +03:30
|
|
|
submit(){
|
|
|
|
var _self=this;
|
|
|
|
if(!_self.passvalid['pass2']){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.data_provider.change_password(this.password['cupass'], this.password['pass1']).then(res => {
|
|
|
|
if(res['status']=='success'){
|
|
|
|
_self.logout();
|
|
|
|
setTimeout(function () {
|
|
|
|
_self.router.navigate(['login']);
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
_self.error=res['err'];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(err) => {
|
|
|
|
console.dir(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get_user_info() {
|
|
|
|
var _self = this;
|
|
|
|
this.uid = this.current_user.partner_id;
|
|
|
|
this.uname = this.current_user.name;
|
|
|
|
this.fname = this.current_user.firstname;
|
|
|
|
this.lname = this.current_user.lastname;
|
|
|
|
}
|
|
|
|
|
|
|
|
logout() {
|
|
|
|
this.data_provider.logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
var _self = this;
|
|
|
|
this.get_user_info();
|
2024-07-13 10:36:07 +03:30
|
|
|
this.data_provider.getSessionInfo().then((res) => {
|
|
|
|
_self.ispro=res['ISPRO']
|
|
|
|
_self.navItems=_self.navItems.filter((item:any) => {
|
|
|
|
if (item.attributes){
|
|
|
|
if('free' in item.attributes && _self.ispro){
|
2024-07-20 16:12:29 +03:30
|
|
|
return ;
|
2024-07-13 10:36:07 +03:30
|
|
|
}
|
|
|
|
else if('pro' in item.attributes && _self.ispro){
|
|
|
|
return item;
|
|
|
|
}
|
2024-07-20 16:12:29 +03:30
|
|
|
else if('pro' in item.attributes && !_self.ispro){
|
|
|
|
return ;
|
|
|
|
}
|
2024-07-13 10:36:07 +03:30
|
|
|
else
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2025-01-02 20:20:59 +03:00
|
|
|
// check first time after 10 seconds
|
|
|
|
setTimeout(function(){
|
|
|
|
_self.data_provider.get_front_version().then((res:any) => {
|
|
|
|
if(res['version']!=_self.version){
|
|
|
|
console.log("New version is available. Please refresh the page.");
|
|
|
|
_self.show_confirm_modal({action:'update'});
|
|
|
|
// window.location.href = window.location.href.replace(/#.*$/, '');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 10000);
|
|
|
|
// check for new version every 5 seconds
|
|
|
|
this.timer=setInterval(function(){
|
|
|
|
_self.data_provider.get_front_version().then((res:any) => {
|
|
|
|
if(res['version']!=_self.version){
|
|
|
|
console.log("New version is available. Please refresh the page.");
|
|
|
|
_self.show_confirm_modal({action:'update'});
|
|
|
|
// window.location.href = window.location.href.replace(/#.*$/, '');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 60000);
|
|
|
|
|
2024-07-07 14:48:52 +03:30
|
|
|
}
|
2025-01-02 20:20:59 +03:00
|
|
|
clearTimer() { clearInterval(this.timer); }
|
2024-07-07 14:48:52 +03:30
|
|
|
|
|
|
|
}
|