No Description

app.config.component.ts 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. import {Component, OnInit, ViewChild} from '@angular/core';
  2. import { AppComponent } from './app.component';
  3. import { AppMainComponent } from './app.main.component';
  4. @Component({
  5. selector: 'app-config',
  6. template: `
  7. <p-sidebar #sidebar [(visible)]="configActive" [position]="app.isRTL ? 'left' : 'right'" [blockScroll]="true" [showCloseIcon]="false" [baseZIndex]="1000" styleClass="layout-config p-sidebar-sm fs-small p-0">
  8. <div class="layout-config-panel flex flex-column">
  9. <div class="px-3 pt-3">
  10. <h5>Theme Customization</h5>
  11. <span>Ultima offers different themes for layout, topbar, menu etc.</span>
  12. </div>
  13. <hr class="mb-0" />
  14. <div class="layout-config-options p-3">
  15. <h6>Layout/Theme Scale</h6>
  16. <div class="flex align-items-center">
  17. <button pButton pRipple type="button" icon="pi pi-minus" (click)="decrementScale()" class="p-button-rounded p-button-text" [disabled]="scale === scales[0]"></button>
  18. <i class="pi pi-circle-on m-1 scale-icon" *ngFor="let s of scales" [ngClass]="{'scale-active': s === scale}"></i>
  19. <button pButton pRipple type="button" icon="pi pi-plus" (click)="incrementScale()" class="p-button-rounded p-button-text" [disabled]="scale === scales[scales.length - 1]"></button>
  20. </div>
  21. <h6>Layout Mode</h6>
  22. <div class="flex">
  23. <div class="flex align-items-center">
  24. <p-radioButton name="layoutMode" value="light" [(ngModel)]="app.layoutMode" inputId="layoutMode1" (onClick)="onLayoutModeChange($event, 'light')"></p-radioButton>
  25. <label for="layoutMode1" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Light</label>
  26. </div>
  27. <div class="flex align-items-center" [ngClass]="{'ml-4': !app.isRTL, 'mr-4': app.isRTL}">
  28. <p-radioButton name="layoutMode" value="dark" [(ngModel)]="app.layoutMode" inputId="layoutMode2" (onClick)="onLayoutModeChange($event, 'dark')"></p-radioButton>
  29. <label for="layoutMode2" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Dark</label>
  30. </div>
  31. </div>
  32. <h6>Menu Mode</h6>
  33. <div class="flex">
  34. <div class="flex flex-column">
  35. <div class="flex align-items-center">
  36. <p-radioButton name="menuMode" value="static" [(ngModel)]="app.menuMode" inputId="menuMode1"></p-radioButton>
  37. <label for="menuMode1" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Static</label>
  38. </div>
  39. <div class="flex align-items-center mt-3">
  40. <p-radioButton name="menuMode" value="horizontal" [(ngModel)]="app.menuMode" inputId="menuMode2"></p-radioButton>
  41. <label for="menuMode2" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Horizontal</label>
  42. </div>
  43. </div>
  44. <div class="flex flex-column" [ngClass]="{'ml-4': !app.isRTL, 'mr-4': app.isRTL}">
  45. <div class="flex align-items-center">
  46. <p-radioButton name="menuMode" value="overlay" [(ngModel)]="app.menuMode" inputId="menuMode4"></p-radioButton>
  47. <label for="menuMode4" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Overlay</label>
  48. </div>
  49. <div class="flex align-items-center mt-3">
  50. <p-radioButton name="menuMode" value="slim" [(ngModel)]="app.menuMode" inputId="menuMode3"></p-radioButton>
  51. <label for="menuMode3" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Slim</label>
  52. </div>
  53. </div>
  54. </div>
  55. <h6>Inline Menu Position</h6>
  56. <div class="flex">
  57. <div class="flex align-items-center">
  58. <p-radioButton name="inlineMenuPosition" value="top" [(ngModel)]="app.inlineMenuPosition" inputId="inlineMenuPosition1"></p-radioButton>
  59. <label for="inlineMenuPosition1" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Top</label>
  60. </div>
  61. <div class="flex align-items-center" [ngClass]="{'ml-4': !app.isRTL, 'mr-4': app.isRTL}">
  62. <p-radioButton name="inlineMenuPosition" value="bottom" [(ngModel)]="app.inlineMenuPosition" inputId="inlineMenuPosition2"></p-radioButton>
  63. <label for="inlineMenuPosition2" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Bottom</label>
  64. </div>
  65. <div class="flex align-items-center" [ngClass]="{'ml-4': !app.isRTL, 'mr-4': app.isRTL}">
  66. <p-radioButton name="inlineMenuPosition" value="both" [(ngModel)]="app.inlineMenuPosition" inputId="inlineMenuPosition3"></p-radioButton>
  67. <label for="inlineMenuPosition3" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Both</label>
  68. </div>
  69. </div>
  70. <h6>Input Background</h6>
  71. <div class="flex">
  72. <div class="flex align-items-center">
  73. <p-radioButton name="inputStyle" value="outlined" [(ngModel)]="app.inputStyle" inputId="inputStyle1" (onClick)="onInputStyleClick()"></p-radioButton>
  74. <label for="inputStyle1" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Outlined</label>
  75. </div>
  76. <div class="flex align-items-center" [ngClass]="{'ml-4': !app.isRTL, 'mr-4': app.isRTL}">
  77. <p-radioButton name="inputStyle" value="filled" [(ngModel)]="app.inputStyle" inputId="inputStyle2" (onClick)="onInputStyleClick()"></p-radioButton>
  78. <label for="inputStyle2" [ngClass]="{'ml-2': !app.isRTL, 'mr-2': app.isRTL}">Filled</label>
  79. </div>
  80. </div>
  81. <h6>Ripple Effect</h6>
  82. <p-inputSwitch [ngModel]="app.ripple" (onChange)="appMain.onRippleChange($event)"></p-inputSwitch>
  83. <h6>RTL</h6>
  84. <p-inputSwitch [ngModel]="app.isRTL" (onChange)="appMain.onRTLChange($event)" styleClass="block"></p-inputSwitch>
  85. <h6>Menu Themes</h6>
  86. <div *ngIf="app.layoutMode!=='dark'" class="grid">
  87. <div *ngFor="let t of menuThemes" class="col col-fixed">
  88. <a style="cursor: pointer" (click)="changeMenuTheme(t)" class="layout-config-color-option" [title]="t.name">
  89. <span class="color" [ngStyle]="{'background-color': t.color}"></span>
  90. <span class="check flex align-items-center justify-content-center" *ngIf="app.menuTheme === t.name">
  91. <i class="pi pi-check" style="color: var(--menu-text-color)"></i>
  92. </span>
  93. </a>
  94. </div>
  95. </div>
  96. <p *ngIf="app.layoutMode==='dark'">Menu themes are only available in light mode by design as large surfaces can emit too much brightness in dark mode.</p>
  97. <h6>Topbar Themes</h6>
  98. <div class="grid">
  99. <div *ngFor="let t of topbarThemes" class="col col-fixed">
  100. <a style="cursor: pointer" (click)="changeTopbarTheme(t)" class="layout-config-color-option" [title]="t.name">
  101. <span class="color" [ngStyle]="{'background-color': t.color}"></span>
  102. <span class="check flex align-items-center justify-content-center" *ngIf="app.topbarTheme === t.name">
  103. <i class="pi pi-check" style="color: var(--topbar-text-color)"></i>
  104. </span>
  105. </a>
  106. </div>
  107. </div>
  108. <h6>Component Themes</h6>
  109. <div class="grid">
  110. <div *ngFor="let t of themes" class="col col-fixed">
  111. <a style="cursor: pointer" (click)="changeTheme(t.name)" class="layout-config-color-option" [title]="t.name">
  112. <span class="color" [ngStyle]="{'background-color': t.color}"></span>
  113. <span class="check flex align-items-center justify-content-center" *ngIf="theme === t.name">
  114. <i class="pi pi-check" style="color: var(--primary-color-text)"></i>
  115. </span>
  116. </a>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </p-sidebar>
  122. <p-button type="button" (click)="configActive = true" icon="pi pi-cog" *ngIf="!configActive" styleClass="layout-config-button"></p-button>
  123. `
  124. })
  125. export class AppConfigComponent implements OnInit {
  126. scale = 14;
  127. scales: number[] = [12, 13, 14, 15, 16];
  128. themes: any[];
  129. menuThemes: any[];
  130. menuTheme = 'light';
  131. topbarThemes: any[];
  132. topbarTheme = 'blue';
  133. theme = 'indigo';
  134. matchingMenuTheme = false;
  135. matchingTopbarTheme = false;
  136. selectedMenuTheme: any;
  137. selectedTopbarTheme: any;
  138. configActive = false;
  139. isInputBackgroundChanged = false;
  140. constructor(public appMain: AppMainComponent, public app: AppComponent) {}
  141. ngOnInit() {
  142. this.themes = [
  143. {name: 'indigo', color: '#3F51B5'},
  144. {name: 'pink', color: '#E91E63'},
  145. {name: 'purple', color: '#9C27B0'},
  146. {name: 'deeppurple', color: '#673AB7'},
  147. {name: 'blue', color: '#2196F3'},
  148. {name: 'lightblue', color: '#03A9F4'},
  149. {name: 'cyan', color: '#00BCD4'},
  150. {name: 'teal', color: '#009688'},
  151. {name: 'green', color: '#4CAF50'},
  152. {name: 'lightgreen', color: '#8BC34A'},
  153. {name: 'lime', color: '#CDDC39'},
  154. {name: 'yellow', color: '#FFEB3B'},
  155. {name: 'amber', color: '#FFC107'},
  156. {name: 'orange', color: '#FF9800'},
  157. {name: 'deeporange', color: '#FF5722'},
  158. {name: 'brown', color: '#795548'},
  159. {name: 'bluegrey', color: '#607D8B'}
  160. ];
  161. this.menuThemes = [
  162. {name: 'light', color: '#FDFEFF'},
  163. {name: 'dark', color: '#434B54'},
  164. {name: 'indigo', color: '#1A237E'},
  165. {name: 'bluegrey', color: '#37474F'},
  166. {name: 'brown', color: '#4E342E'},
  167. {name: 'cyan', color: '#006064'},
  168. {name: 'green', color: '#2E7D32'},
  169. {name: 'deeppurple', color: '#4527A0'},
  170. {name: 'deeporange', color: '#BF360C'},
  171. {name: 'pink', color: '#880E4F'},
  172. {name: 'purple', color: '#6A1B9A'},
  173. {name: 'teal', color: '#00695C'}
  174. ];
  175. this.topbarThemes = [
  176. {name: 'lightblue', color: '#2E88FF'},
  177. {name: 'dark', color: '#363636'},
  178. {name: 'white', color: '#FDFEFF'},
  179. {name: 'blue', color: '#1565C0'},
  180. {name: 'deeppurple', color: '#4527A0'},
  181. {name: 'purple', color: '#6A1B9A'},
  182. {name: 'pink', color: '#AD1457'},
  183. {name: 'cyan', color: '#0097A7'},
  184. {name: 'teal', color: '#00796B'},
  185. {name: 'green', color: '#43A047'},
  186. {name: 'lightgreen', color: '#689F38'},
  187. {name: 'lime', color: '#AFB42B'},
  188. {name: 'yellow', color: '#FBC02D'},
  189. {name: 'amber', color: '#FFA000'},
  190. {name: 'orange', color: '#FB8C00'},
  191. {name: 'deeporange', color: '#D84315'},
  192. {name: 'brown', color: '#5D4037'},
  193. {name: 'grey', color: '#616161'},
  194. {name: 'bluegrey', color: '#546E7A'},
  195. {name: 'indigo', color: '#3F51B5'}
  196. ];
  197. this.selectedMenuTheme = this.menuThemes.find(theme => theme.name === this.menuTheme);
  198. this.selectedTopbarTheme = this.topbarThemes.find(theme => theme.name === this.topbarTheme);
  199. }
  200. decrementScale() {
  201. this.scale--;
  202. this.applyScale();
  203. }
  204. incrementScale() {
  205. this.scale++;
  206. this.applyScale();
  207. }
  208. applyScale() {
  209. document.documentElement.style.fontSize = this.scale + 'px';
  210. }
  211. onInputStyleClick() {
  212. this.isInputBackgroundChanged = true;
  213. }
  214. onLayoutModeChange(event, mode) {
  215. const appLogoLink: HTMLImageElement = document.getElementById('app-logo') as HTMLImageElement;
  216. this.app.layoutMode = mode;
  217. if (!this.isInputBackgroundChanged) {
  218. this.app.inputStyle = mode === 'dark' ? 'filled' : 'outlined';
  219. }
  220. if (mode === 'dark') {
  221. this.app.menuTheme = 'dark';
  222. this.app.topbarTheme = 'dark';
  223. appLogoLink.src = 'assets/layout/images/logo-light.png';
  224. }
  225. else {
  226. this.app.menuTheme = 'light';
  227. this.app.topbarTheme = 'blue';
  228. appLogoLink.src = 'assets/layout/images/logo-light.png';
  229. }
  230. const layoutLink: HTMLLinkElement = document.getElementById('layout-css') as HTMLLinkElement;
  231. const layoutHref = 'assets/layout/css/layout-' + this.app.layoutMode + '.css';
  232. this.replaceLink(layoutLink, layoutHref);
  233. const themeLink = document.getElementById('theme-css');
  234. const urlTokens = themeLink.getAttribute('href').split('/');
  235. urlTokens[urlTokens.length - 1] = 'theme-' + this.app.layoutMode + '.css';
  236. const newURL = urlTokens.join('/');
  237. this.replaceLink(themeLink, newURL, this.appMain['refreshChart']);
  238. }
  239. changeTheme(theme) {
  240. this.theme = theme;
  241. const themeLink: HTMLLinkElement = document.getElementById('theme-css') as HTMLLinkElement;
  242. const themeHref = 'assets/theme/' + theme + '/theme-' + this.app.layoutMode + '.css';
  243. this.replaceLink(themeLink, themeHref);
  244. }
  245. changeMenuTheme(theme) {
  246. this.selectedMenuTheme = theme;
  247. this.app.menuTheme = theme.name;
  248. }
  249. changeTopbarTheme(theme) {
  250. this.selectedTopbarTheme = theme;
  251. this.app.topbarTheme = theme.name;
  252. const appLogoLink: HTMLImageElement = document.getElementById('app-logo') as HTMLImageElement;
  253. if (theme.name === 'white' || theme.name === 'yellow' || theme.name === 'amber'
  254. || theme.name === 'orange' || theme.name === 'lime') {
  255. appLogoLink.src = 'assets/layout/images/logo-dark.png';
  256. }
  257. else {
  258. appLogoLink.src = 'assets/layout/images/logo-light.png';
  259. }
  260. }
  261. isIE() {
  262. return /(MSIE|Trident\/|Edge\/)/i.test(window.navigator.userAgent);
  263. }
  264. replaceLink(linkElement, href, callback?) {
  265. if (this.isIE()) {
  266. linkElement.setAttribute('href', href);
  267. if (callback) {
  268. callback();
  269. }
  270. } else {
  271. const id = linkElement.getAttribute('id');
  272. const cloneLinkElement = linkElement.cloneNode(true);
  273. cloneLinkElement.setAttribute('href', href);
  274. cloneLinkElement.setAttribute('id', id + '-clone');
  275. linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling);
  276. cloneLinkElement.addEventListener('load', () => {
  277. linkElement.remove();
  278. cloneLinkElement.setAttribute('id', id);
  279. if (callback) {
  280. callback();
  281. }
  282. });
  283. }
  284. }
  285. }

Powered by TurnKey Linux.