forked from Ficodes/BAE-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.component.ts
More file actions
113 lines (103 loc) · 4.24 KB
/
Copy pathapp.component.ts
File metadata and controls
113 lines (103 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import {Component, OnInit} from '@angular/core';
import { initFlowbite } from 'flowbite';
import { TranslateService } from '@ngx-translate/core';
import {LocalStorageService} from "./services/local-storage.service";
import {Category} from "./models/interfaces";
import {EventMessageService} from "./services/event-message.service";
import { ActivatedRoute, NavigationEnd } from '@angular/router';
import { Router } from '@angular/router';
import { LoginInfo } from 'src/app/models/interfaces';
import { ApiServiceService } from 'src/app/services/product-service.service';
import { RefreshLoginServiceService } from "src/app/services/refresh-login-service.service";
import * as moment from 'moment';
import {ThemeService} from "./services/theme.service";
import {environment} from "../environments/environment";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'DOME Marketplace';
showPanel = false;
providerThemeName=environment.providerThemeName;
isProduction:boolean = environment.isProduction;
constructor(private translate: TranslateService,
private localStorage: LocalStorageService,
private eventMessage: EventMessageService,
private route: ActivatedRoute,
private router: Router,
private api: ApiServiceService,
private themeService: ThemeService,
private refreshApi: RefreshLoginServiceService) {
this.translate.addLangs(['en', 'es']);
this.translate.setDefaultLang('es');
let currLang = this.localStorage.getItem('current_language')
if(!currLang || currLang == null) {
this.localStorage.setItem('current_language', '');
this.translate.use('es');
} else {
this.translate.use(currLang);
}
if(!this.localStorage.getObject('selected_categories'))
this.localStorage.setObject('selected_categories', []);
/*this.eventMessage.messages$.subscribe(ev => {
if(ev.type === 'AddedFilter' || ev.type === 'RemovedFilter') {
this.checkPanel();
}
})*/
}
ngOnInit(): void {
const providerThemeName = environment.providerThemeName;
this.themeService.initializeProviderTheme(providerThemeName);
initFlowbite();
if(!this.localStorage.getObject('selected_categories'))
this.localStorage.setObject('selected_categories', []);
if(!this.localStorage.getObject('cart_items'))
this.localStorage.setObject('cart_items', []);
if(!this.localStorage.getObject('login_items'))
this.localStorage.setObject('login_items', {});
if(!this.localStorage.getObject('feedback'))
this.localStorage.setObject('feedback', {});
//this.checkPanel();
this.eventMessage.messages$.subscribe(ev => {
if(ev.type === 'LoginProcess') {
this.refreshApi.stopInterval();
let info = ev.value as LoginInfo;
console.log('STARTING INTERVAL')
console.log(info.expire)
console.log(((info.expire - moment().unix()) - 4))
this.refreshApi.startInterval(((info.expire - moment().unix())-4)*1000, ev);
initFlowbite();
//this.refreshApi.startInterval(3000, ev.value);
}
})
let aux = this.localStorage.getObject('login_items') as LoginInfo;
if(JSON.stringify(aux) === '{}'){
//this.siopInfo.getSiopInfo().subscribe((data)=>{
// environment.SIOP_INFO = data
//})
}
else if (((aux.expire - moment().unix())-4) > 0) {
this.refreshApi.stopInterval();
this.refreshApi.startInterval(((aux.expire - moment().unix())-4)*1000, aux);
console.log('token')
console.log(aux.token)
initFlowbite();
}
this.router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
window.scrollTo({ top: 0, behavior: 'smooth' }); // or just window.scrollTo(0, 0);
}
});
}
/*checkPanel() {
const filters = this.localStorage.getObject('selected_categories') as Category[] || [] ;
const oldState = this.showPanel;
this.showPanel = filters.length > 0;
if(this.showPanel != oldState) {
this.eventMessage.emitFilterShown(this.showPanel);
this.localStorage.setItem('is_filter_panel_shown', this.showPanel.toString())
}
}*/
}