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';
|
|
|
|
|
|
|
|
@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-07-07 14:48:52 +03:30
|
|
|
public UserProfileModalVisible:boolean;
|
|
|
|
public error:any=false;
|
|
|
|
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,
|
|
|
|
|
|
|
|
) {
|
|
|
|
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-07-13 10:36:07 +03:30
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
show_user_modal(){
|
|
|
|
this.UserProfileModalVisible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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){
|
|
|
|
//do nothing
|
|
|
|
}
|
|
|
|
else if('pro' in item.attributes && _self.ispro){
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2024-07-07 14:48:52 +03:30
|
|
|
_self.data_provider.get_front_version().then((res:any) => {
|
|
|
|
if(res['version']!=this.version){
|
|
|
|
console.dir("New version is available. Please refresh the page.");
|
|
|
|
window.location.href = window.location.href.replace(/#.*$/, '');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|