Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Add Preferences UI #1538

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Preferences UI, Electron integration
Signed-off-by: Milan Klanjsek <[email protected]>
  • Loading branch information
mklanjsek committed Feb 3, 2021
commit 607eecc654ae9a6173e21b6ff2bc90716289aae1
9 changes: 8 additions & 1 deletion web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ const errLogPath = path.join(tmpPath, 'api.err-' + date + '.log');
const template: Electron.MenuItemConstructorOptions[] = [
{
label: 'File',
submenu: [{ label: 'Quit Octant', role: 'close' }],
submenu: [
{ label: 'Preferences',
click(){
win.webContents.send('openPreferences');
} },
{ type: 'separator' },
{ label: 'Quit Octant', role: 'close' }
],
},
{
label: 'Edit',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Injectable } from '@angular/core';
import { ipcRenderer, webFrame } from 'electron';
import * as childProcess from 'child_process';
import * as fs from 'fs';
import { PreferencesService } from '../preferences/preferences.service';

@Injectable({
providedIn: 'root',
Expand All @@ -18,7 +19,7 @@ export class ElectronService {
fs: typeof fs;

public portNumber: number;
constructor() {
constructor(private preferencesService: PreferencesService) {
if (this.isElectron()) {
this.ipcRenderer = window.require('electron').ipcRenderer;
this.webFrame = window.require('electron').webFrame;
Expand All @@ -28,6 +29,12 @@ export class ElectronService {
this.ipcRenderer.once('port-message', (event, message) => {
this.portNumber = message;
});

this.ipcRenderer.on('openPreferences', () => {
if (!this.preferencesService.preferencesOpened.value) {
this.preferencesService.preferencesOpened.next(true);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ export class NavigationService {
current = new BehaviorSubject<Navigation>(emptyNavigation);
modules = new BehaviorSubject<Module[]>([]);
selectedItem = new BehaviorSubject<Selection>({ module: 0, index: -1 });
public showLabels: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(
true
);
activeUrl = new BehaviorSubject<string>('');

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,17 @@ describe('PreferencesService', () => {
it('should be created', () => {
expect(service).toBeTruthy();
});

it('collapsed set properly', () => {
const defaultPrefs = service.getPreferences();
const defaultElement = defaultPrefs.panels[0].sections[1].elements[0];
expect(defaultElement.name).toEqual('general.navigation');
expect(defaultElement.value).toEqual('expanded');

service.navCollapsed.next(true);
const newPrefs = service.getPreferences();
const newElement = newPrefs.panels[0].sections[1].elements[0];
expect(newElement.name).toEqual('general.navigation');
expect(newElement.value).toEqual('collapsed');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,29 @@ import { ThemeService } from '../theme/theme.service';
providedIn: 'root',
})
export class PreferencesService {
public preferencesOpened: BehaviorSubject<boolean> = new BehaviorSubject<
boolean
>(false);
public preferencesOpened: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(
false
);

public navCollapsed: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(
false
);

public showLabels: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(
true
);

constructor(private themeService: ThemeService) {}

public preferencesChanged(update: any) {
public preferencesChanged(update: Preferences) {
const collapsed = update['general.navigation'] === 'collapsed';
const showLabels = update['general.labels'] === 'show';
const isLightTheme = update['general.theme'] === 'light';

if (this.showLabels.value !== showLabels) {
this.showLabels.next(showLabels);
}

if (this.navCollapsed.value !== collapsed) {
this.navCollapsed.next(collapsed);
}
Expand Down Expand Up @@ -89,6 +98,28 @@ export class PreferencesService {
},
],
},
{
name: 'Navigation labels',
elements: [
{
name: 'general.labels',
type: 'radio',
value: this.showLabels.value ? 'show' : 'hide',
config: {
values: [
{
label: 'Show Labels',
value: 'show',
},
{
label: 'Hide Labels',
value: 'hide',
},
],
},
},
],
},
],
},
],
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/modules/shared/services/theme/theme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ThemeService implements OnDestroy {

const themeType = localStorage.getItem('theme') as ThemeType;
this.themeType = themeType || defaultTheme.type;

this.renderer = rendererFactory.createRenderer(null, null);

this.storageEventHandler = (e: StorageEvent): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@
}

.module-tabs {
width: 56px;
width: 48px;
margin-right: 0px;

::ng-deep ul {
padding-left: 0rem;
padding-top: 0.4rem;
}
}

.module-tabs-labels {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class NavigationComponent implements OnInit, OnDestroy {
}
);

this.subscriptionShowLabels = this.navigationService.showLabels.subscribe(
this.subscriptionShowLabels = this.preferencesService.showLabels.subscribe(
col => {
if (this.showLabels !== col) {
this.showLabels = col;
Expand All @@ -109,7 +109,7 @@ export class NavigationComponent implements OnInit, OnDestroy {
} else if (event.key === 'L' && event.ctrlKey) {
event.preventDefault();
event.cancelBubble = true;
this.navigationService.showLabels.next(!this.showLabels);
this.preferencesService.showLabels.next(!this.showLabels);
}
}

Expand Down