refractor: shell (#287)
* Refractor components. * Shift theme picker component to shared module. * Shift progress bar service into its own folder. * Add footer to app shell. * Replace mat-icon by font-awesome icons. * Fix sidenav visibility bug for handsets. * Add comments. Closes #286, Fixes #285
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/** Angular Imports */
|
||||
import {Injectable, EventEmitter} from '@angular/core';
|
||||
|
||||
/** Custom Model */
|
||||
import { Theme } from './theme.model';
|
||||
|
||||
/** Custom Services */
|
||||
import { ThemeManagerService } from './theme-manager.service';
|
||||
|
||||
/**
|
||||
* Theme storage service.
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ThemeStorageService {
|
||||
|
||||
/** Key to store current theme of application in local storage. */
|
||||
private themeStorageKey = 'mifosXTheme';
|
||||
/** Theme update event. */
|
||||
onThemeUpdate: EventEmitter<Theme>;
|
||||
|
||||
/**
|
||||
* Initializes theme update event.
|
||||
* @param {ThemeManagerService} themeManagerService
|
||||
*/
|
||||
constructor(public themeManagerService: ThemeManagerService) {
|
||||
this.onThemeUpdate = new EventEmitter<Theme>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores current theme in local storage and emits a theme update event.
|
||||
* @param mifosXTheme
|
||||
*/
|
||||
storeTheme(mifosXTheme: Theme) {
|
||||
localStorage.setItem(this.themeStorageKey, JSON.stringify(mifosXTheme));
|
||||
this.onThemeUpdate.emit(mifosXTheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns current theme from local storage
|
||||
*/
|
||||
getTheme(): Theme {
|
||||
return JSON.parse(localStorage.getItem(this.themeStorageKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes current theme from local storage.
|
||||
*/
|
||||
clearTheme() {
|
||||
localStorage.removeItem(this.themeStorageKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new theme for the application and stores in local storage.
|
||||
* @param {Theme} theme
|
||||
*/
|
||||
installTheme(theme: Theme) {
|
||||
if (theme.isDefault) {
|
||||
this.themeManagerService.removeTheme();
|
||||
} else {
|
||||
this.themeManagerService.setTheme(`theme/${theme.href}`);
|
||||
}
|
||||
this.storeTheme(theme);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user