2020-08-18 12:37:27 +02:00
|
|
|
import {Component, isDevMode, OnInit} from '@angular/core';
|
2020-06-19 08:43:22 +02:00
|
|
|
import {LoginService} from './services/login.service';
|
2020-08-28 16:58:35 +02:00
|
|
|
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
|
2020-08-20 10:42:02 +02:00
|
|
|
import {ModalService} from '@inst-iot/bosch-angular-ui-components';
|
|
|
|
import {HelpComponent} from './help/help.component';
|
|
|
|
import {DataService} from './services/data.service';
|
2020-06-19 08:43:22 +02:00
|
|
|
|
2020-07-27 17:52:03 +02:00
|
|
|
|
2020-01-14 13:41:28 +01:00
|
|
|
@Component({
|
2021-01-25 12:34:23 +01:00
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: './app.component.html',
|
|
|
|
styleUrls: ['./app.component.scss']
|
2020-01-14 13:41:28 +01:00
|
|
|
})
|
2020-08-18 12:37:27 +02:00
|
|
|
export class AppComponent implements OnInit{
|
2020-05-22 12:52:17 +02:00
|
|
|
|
2021-01-25 12:34:23 +01:00
|
|
|
bugReport = {do: '', work: ''}; // Data from bug report inputs
|
|
|
|
isDocumentation = false; // True if user is on documentation pages
|
2021-02-22 14:18:52 +01:00
|
|
|
devMode = false;
|
|
|
|
testMode = false;
|
2020-08-06 08:18:57 +02:00
|
|
|
|
2021-01-25 12:34:23 +01:00
|
|
|
constructor(
|
|
|
|
public login: LoginService,
|
|
|
|
public router: Router,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
public window: Window,
|
|
|
|
private modal: ModalService,
|
|
|
|
public d: DataService
|
|
|
|
) {
|
|
|
|
this.devMode = isDevMode();
|
2021-02-22 14:18:52 +01:00
|
|
|
|
|
|
|
// The site is considered to be in test mode when it is deployed inside the definma-test container
|
|
|
|
this.testMode = window.location.hostname === 'definma-test.apps.de1.bosch-iot-cloud.com';
|
2021-01-25 12:34:23 +01:00
|
|
|
this.router.events.subscribe(event => {
|
|
|
|
if (event instanceof NavigationStart) {
|
|
|
|
this.isDocumentation = /\/documentation/.test(event.url);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-07-14 09:39:37 +02:00
|
|
|
|
2021-01-25 12:34:23 +01:00
|
|
|
ngOnInit() {
|
|
|
|
// Try to log in user
|
|
|
|
this.login.login().then(res => {
|
|
|
|
// Return to home page if log failed, except when on documentation pages
|
|
|
|
if (!res && !(/\/documentation/.test(this.router.url))) {
|
|
|
|
this.router.navigate(['/']);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-08-18 12:37:27 +02:00
|
|
|
|
2021-01-25 12:34:23 +01:00
|
|
|
logout() {
|
|
|
|
this.login.logout();
|
|
|
|
this.router.navigate(['/']);
|
|
|
|
}
|
2020-08-06 08:18:57 +02:00
|
|
|
|
2021-01-25 12:34:23 +01:00
|
|
|
help() {
|
|
|
|
this.modal.openComponent(HelpComponent);
|
|
|
|
}
|
2020-08-20 10:42:02 +02:00
|
|
|
|
2021-01-25 12:34:23 +01:00
|
|
|
bugReportContent() {
|
|
|
|
return `mailto:${this.d.contact.mail}?subject=Bug report&body=Thanks for sending the report! Your bug will be
|
|
|
|
(hopefully) fixed soon.
|
|
|
|
%0D%0A%0D%0A--- REPORT DATA ---
|
|
|
|
%0D%0A%0D%0ATime: ${new Date().toString()}%0D%0A
|
|
|
|
URL: ${this.window.location}%0D%0A%0D%0AWhat did you do?%0D%0A${encodeURIComponent(this.bugReport.do)}
|
|
|
|
%0D%0A%0D%0AWhat did not work?%0D%0A${encodeURIComponent(this.bugReport.work)}%0D%0A%0D%0ABrowser:%0D%0A
|
|
|
|
%0D%0AappCodeName: ${navigator.appCodeName}
|
|
|
|
%0D%0AappVersion: ${navigator.appVersion}
|
|
|
|
%0D%0Alanguage: ${navigator.language}
|
|
|
|
%0D%0AonLine: ${navigator.onLine}
|
|
|
|
%0D%0Aoscpu: ${navigator.oscpu}
|
|
|
|
%0D%0Aplatform: ${navigator.platform}
|
|
|
|
%0D%0AuserAgent: ${navigator.userAgent}
|
|
|
|
%0D%0AinnerWidth: ${this.window.innerWidth}
|
|
|
|
%0D%0AinnerHeight: ${this.window.innerHeight}`;
|
|
|
|
}
|
2020-08-06 08:18:57 +02:00
|
|
|
|
2021-01-25 12:34:23 +01:00
|
|
|
closeBugReport(close) {
|
|
|
|
setTimeout(() => close(), 1);
|
|
|
|
}
|
2020-08-11 17:08:47 +02:00
|
|
|
|
2021-01-25 12:34:23 +01:00
|
|
|
toTheTop() {
|
|
|
|
this.window.scroll(0, 0);
|
|
|
|
}
|
2020-01-14 13:41:28 +01:00
|
|
|
}
|
2020-08-06 08:18:57 +02:00
|
|
|
|