shamrickus commented on code in PR #6753:
URL: https://github.com/apache/trafficcontrol/pull/6753#discussion_r878468626


##########
experimental/traffic-portal/src/app/shared/theme-manager/theme-manager.service.ts:
##########
@@ -0,0 +1,154 @@
+/*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import {EventEmitter, Injectable} from "@angular/core";
+
+/**
+ * Defines a theme. If fileName is null, it is the default theme
+ */
+export interface Theme {
+       fileName?: string;
+       name: string;
+}
+
+/**
+ *
+ */
+@Injectable({
+       providedIn: "root"
+})
+export class ThemeManagerService {
+       private static readonly STORAGE_KEY = "current-theme-name";
+       private static readonly LINK_KEY = "themer";
+
+       public themeChanged = new EventEmitter<Theme>();
+
+       /**
+        * Initialize the theme service
+        */
+       public initTheme(): void {
+               const themeName = ThemeManagerService.loadStoredTheme();
+               if(themeName) {
+                       this.loadTheme(themeName);
+               }
+       }
+
+       public readonly themes: Array<Theme> = [{
+               name: "Default"
+       },
+       {
+               fileName: "dark-default-theme.css",
+               name: "Dark"
+       }
+       ];
+
+       /**
+        * Given a themes bundle name, load the theme and cache the value
+        *
+        * @param theme Theme to load
+        */
+       public loadTheme(theme: Theme): void {
+               if(theme.fileName === undefined) {
+                       this.clearTheme();
+                       return;
+               }
+               ThemeManagerService.getThemeLinkElement().setAttribute("href", 
theme.fileName);
+               ThemeManagerService.storeTheme(theme);
+               this.themeChanged.emit(theme);
+       }
+
+       /**
+        * Revert to the default theme
+        */
+       public clearTheme(): void {
+               const linkEl = 
ThemeManagerService.getExistingThemeLinkElement();
+               if(linkEl) {
+                       document.head.removeChild(linkEl);
+                       ThemeManagerService.clearStoredTheme();
+                       this.themeChanged.emit(this.themes[0]);
+               }
+       }
+
+       /**
+        * Stores theme in localStorage
+        *
+        * @param theme Theme to be stored
+        * @private

Review Comment:
   My IDE must've generated them, they don't appear to serve any purpose



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to