Commit c8bd2e8b authored by alish's avatar alish
Browse files

feat: admin app settings #1097

parent 137ee5ae
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -52,6 +52,22 @@ export class Store {
		localStorage.setItem('serverConnection', val);
	}

	get adminPasswordReset() {
		return localStorage.getItem('adminPasswordReset');
	}

	set adminPasswordReset(val: string) {
		localStorage.setItem('adminPasswordReset', val);
	}

	get fakeDataGenerator() {
		return localStorage.getItem('fakeDataGenerator');
	}

	set fakeDataGenerator(val: string) {
		localStorage.setItem('fakeDataGenerator', val);
	}

	clearMaintenanceMode() {
		localStorage.removeItem('maintenanceMode');
	}
+48 −0
Original line number Diff line number Diff line
import { Injectable } from '@angular/core';
import { Store } from '../data/store.service';
import { Apollo } from 'apollo-angular';
import { IAdminAppSettings } from '@modules/server.common/interfaces/IAppsSettings';
import gql from 'graphql-tag';
import { take, map } from 'rxjs/operators';

@Injectable({
	providedIn: 'root',
})
export class ServerSettingsService {
	constructor(
		private readonly _apollo: Apollo,
		private readonly store: Store
	) {}

	async load() {
		return new Promise(async (resolve, reject) => {
			const res = await this.getAdminAppSettings();

			if (res) {
				this.store.adminPasswordReset = res.adminPasswordReset;
				this.store.fakeDataGenerator = res.fakeDataGenerator;
			}

			resolve(true);
		});
	}

	getAdminAppSettings() {
		return this._apollo
			.query<{ settings: IAdminAppSettings }>({
				query: gql`
					query adminAppSettings {
						adminAppSettings {
							adminPasswordReset
							fakeDataGenerator
						}
					}
				`,
			})
			.pipe(
				take(1),
				map((res) => res.data['adminAppSettings'])
			)
			.toPromise();
	}
}
+12 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import { MaintenanceService } from '@modules/client.common.angular2/services/mai
import { AppModuleGuard } from './app.module.guard';
import { MaintenanceModuleGuard } from './pages/+maintenance-info/maintenance-info.module.guard';
import { ServerConnectionService } from '@modules/client.common.angular2/services/server-connection.service';
import { ServerSettingsService } from './@core/services/server-settings.service';

// It's more 'standard' way to use Font-Awesome module and special package,
// but for some reason ngx-admin works without it. So we leave next line commented for now.
@@ -80,6 +81,13 @@ import { ServerConnectionService } from '@modules/client.common.angular2/service
			deps: [MaintenanceService],
			multi: true,
		},
		ServerSettingsService,
		{
			provide: APP_INITIALIZER,
			useFactory: serverSettingsFactory,
			deps: [ServerSettingsService],
			multi: true,
		},
		{ provide: APP_BASE_HREF, useValue: '/' },
		SimpleTimer,
		AppModuleGuard,
@@ -171,3 +179,7 @@ export function maintenanceFactory(provider: MaintenanceService) {
			environment['SETTINGS_MAINTENANCE_API_URL']
		);
}

export function serverSettingsFactory(provider: ServerSettingsService) {
	return () => provider.load();
}
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@

	<nb-card-body>
		<button
			*ngIf="fakeDataGenerator"
			nbButton
			status="primary"
			class="mr-3"
+12 −3
Original line number Diff line number Diff line
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { environment } from 'environments/environment';
import { Store } from '@app/@core/data/store.service';

@Component({
	styleUrls: ['./setup.component.scss'],
	templateUrl: './setup.component.html',
})
export class SetupComponent {
export class SetupComponent implements OnInit {
	public loading: boolean;
	public fakeDataGenerator: boolean;

	constructor(private readonly _router: Router) {}
	constructor(
		private readonly _router: Router,
		private readonly _store: Store
	) {}
	ngOnInit(): void {
		this.fakeDataGenerator = !!this._store.fakeDataGenerator;
	}

	navigateToFakeDataPage() {
		this.loading = true;
Loading