Merge branch 'max_dev' of Software_Engineering_I/greenvironment-frontend into master

master
Trivernis 5 years ago committed by Gitea
commit 10c71cbc16

@ -3,7 +3,6 @@ import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators'; import { map, shareReplay } from 'rxjs/operators';
import { DatasharingService } from '../../services/datasharing.service'; import { DatasharingService } from '../../services/datasharing.service';
import { SelfService } from '../../services/selfservice/self.service';
import { RequestService } from '../../services/request/request.service'; import { RequestService } from '../../services/request/request.service';
import { SettingsService } from '../../services/settings/settings.service'; import { SettingsService } from '../../services/settings/settings.service';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
@ -23,7 +22,6 @@ export class MainNavigationComponent implements OnInit {
constructor( constructor(
public overlayContainer: OverlayContainer, public overlayContainer: OverlayContainer,
private data: DatasharingService, private data: DatasharingService,
private selfservice: SelfService,
private settingsService: SettingsService, private settingsService: SettingsService,
private requestservice: RequestService, private requestservice: RequestService,
private breakpointObserver: BreakpointObserver, private breakpointObserver: BreakpointObserver,
@ -75,6 +73,8 @@ export class MainNavigationComponent implements OnInit {
if (this.user.darkmode === true && this.lighttheme) { if (this.user.darkmode === true && this.lighttheme) {
this.toggleTheme(); this.toggleTheme();
this.darkModeButtonChecked = true; this.darkModeButtonChecked = true;
} else if (!this.user.darkmode && !this.lighttheme) {
this.settingsService.setDarkModeActive(true);
} }
this.updateLinks(); this.updateLinks();
}); });
@ -86,30 +86,21 @@ export class MainNavigationComponent implements OnInit {
this.overlay.classList.add('light-theme'); this.overlay.classList.add('light-theme');
this.onSetTheme('light-theme'); this.onSetTheme('light-theme');
this.lighttheme = true; this.lighttheme = true;
this.setDarkModeActive(false); this.settingsService.setDarkModeActive(false);
} else if (this.overlay.classList.contains('light-theme')) { } else if (this.overlay.classList.contains('light-theme')) {
this.overlay.classList.remove('light-theme'); this.overlay.classList.remove('light-theme');
this.overlay.classList.add('dark-theme'); this.overlay.classList.add('dark-theme');
this.onSetTheme('dark-theme'); this.onSetTheme('dark-theme');
this.lighttheme = false; this.lighttheme = false;
this.setDarkModeActive(true); this.settingsService.setDarkModeActive(true);
} else { } else {
this.overlay.classList.add('dark-theme'); this.overlay.classList.add('dark-theme');
this.onSetTheme('dark-theme'); this.onSetTheme('dark-theme');
this.lighttheme = false; this.lighttheme = false;
this.setDarkModeActive(true); this.settingsService.setDarkModeActive(true);
} }
} }
setDarkModeActive(active: boolean) {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = this.settingsService.buildJsonDarkMode('darkmode: ' + '\'' + active + '\'');
this.http.post(url, body).subscribe(response => {
console.log(response.text()); });
}
updateLinks() { updateLinks() {
this.navLinksLoggedIn = [ this.navLinksLoggedIn = [
{ path: '', label: 'Home' }, { path: '', label: 'Home' },

@ -1,6 +1,7 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Http} from '@angular/http'; import {Http} from '@angular/http';
import { User } from 'src/app/models/user'; import { User } from 'src/app/models/user';
import { environment } from 'src/environments/environment';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -11,6 +12,15 @@ export class SettingsService {
constructor(private http: Http) { constructor(private http: Http) {
} }
setDarkModeActive(active: boolean) {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = this.buildJsonDarkMode('darkmode: ' + '\'' + active + '\'');
this.http.post(url, body).subscribe(response => {
console.log(response.text()); });
}
public buildJsonDarkMode(setting_: string): any { public buildJsonDarkMode(setting_: string): any {
const body = { const body = {
query: `mutation($setting: String!) { query: `mutation($setting: String!) {

Loading…
Cancel
Save