This commit is contained in:
piotrpekala7 2021-08-24 17:07:47 +02:00
parent b33a01e225
commit 1619c3ec05
3 changed files with 27 additions and 2 deletions

View File

@ -11,6 +11,7 @@
<div> <div>
<mat-checkbox [(ngModel)]="settings.crash_reports">Send anonymous crash reports</mat-checkbox><br /> <mat-checkbox [(ngModel)]="settings.crash_reports">Send anonymous crash reports</mat-checkbox><br />
<mat-checkbox [(ngModel)]="settings.anonymous_statistics">Send anonymous usage statistics</mat-checkbox><br />
<mat-checkbox [(ngModel)]="integrateLinksLabelsToLinks">Integrate link labels to links</mat-checkbox><br /> <mat-checkbox [(ngModel)]="integrateLinksLabelsToLinks">Integrate link labels to links</mat-checkbox><br />
<mat-checkbox [(ngModel)]="openConsolesInWidget">Open consoles in the widget instead of in new tabs after clicking start consoles for all nodes</mat-checkbox> <mat-checkbox [(ngModel)]="openConsolesInWidget">Open consoles in the widget instead of in new tabs after clicking start consoles for all nodes</mat-checkbox>
</div> </div>

View File

@ -1,14 +1,17 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router'; import { NavigationEnd, Router } from '@angular/router';
import { environment } from '../../environments/environment'; import { environment } from '../../environments/environment';
import { SettingsService } from './settings.service';
declare var gtag: Function; declare var gtag: Function;
@Injectable() @Injectable()
export class GoogleAnalyticsService { export class GoogleAnalyticsService {
constructor(router: Router) { private settingsService: SettingsService;
constructor(router: Router, settingsService: SettingsService) {
if (!environment.production) return; if (!environment.production) return;
router.events.subscribe((event) => { router.events.subscribe((event) => {
if (event instanceof NavigationEnd) { if (settingsService.getStatisticsSettings() && event instanceof NavigationEnd) {
gtag('set', 'page', event.url); gtag('set', 'page', event.url);
gtag('send', 'pageview'); gtag('send', 'pageview');
} }

View File

@ -4,6 +4,7 @@ import { BehaviorSubject } from 'rxjs';
export interface Settings { export interface Settings {
crash_reports: boolean; crash_reports: boolean;
console_command: string; console_command: string;
anonymous_statistics: boolean;
} }
@Injectable({ @Injectable({
@ -13,10 +14,12 @@ export class SettingsService {
private settings: Settings = { private settings: Settings = {
crash_reports: true, crash_reports: true,
console_command: undefined, console_command: undefined,
anonymous_statistics: true
}; };
private readonly reportsSettings: string = 'crash_reports'; private readonly reportsSettings: string = 'crash_reports';
private readonly consoleSettings: string = 'console_command'; private readonly consoleSettings: string = 'console_command';
private readonly statisticsSettings: string = 'statistics_command';
constructor() { constructor() {
if (this.getItem(this.reportsSettings)) if (this.getItem(this.reportsSettings))
@ -24,6 +27,9 @@ export class SettingsService {
if (this.getItem(this.consoleSettings)) if (this.getItem(this.consoleSettings))
this.settings.console_command = this.getItem(this.consoleSettings); this.settings.console_command = this.getItem(this.consoleSettings);
if (this.getItem(this.statisticsSettings))
this.settings.anonymous_statistics = this.getItem(this.statisticsSettings) === 'true' ? true : false;
} }
setReportsSettings(value: boolean) { setReportsSettings(value: boolean) {
@ -36,10 +42,24 @@ export class SettingsService {
} }
} }
setStatisticsSettings(value: boolean) {
this.settings.anonymous_statistics = value;
this.removeItem(this.statisticsSettings);
if (value) {
this.setItem(this.statisticsSettings, 'true');
} else {
this.setItem(this.statisticsSettings, 'false');
}
}
getReportsSettings() { getReportsSettings() {
return this.getItem(this.reportsSettings) === 'true' ? true : false; return this.getItem(this.reportsSettings) === 'true' ? true : false;
} }
getStatisticsSettings() {
return this.getItem(this.statisticsSettings) === 'true' ? true : false;
}
setConsoleSettings(value: string) { setConsoleSettings(value: string) {
this.settings.console_command = value; this.settings.console_command = value;
this.removeItem(this.consoleSettings); this.removeItem(this.consoleSettings);
@ -70,5 +90,6 @@ export class SettingsService {
this.settings = settings; this.settings = settings;
this.setConsoleSettings(settings.console_command); this.setConsoleSettings(settings.console_command);
this.setReportsSettings(settings.crash_reports); this.setReportsSettings(settings.crash_reports);
this.setStatisticsSettings(settings.anonymous_statistics);
} }
} }