From 12ada8eb00b67c98852d7d0056df65ebbb4522e4 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Sun, 21 Jan 2018 10:37:00 -0600 Subject: [PATCH] Cleanup themeManager --- .../javascripts/app/controllers/home.js | 1 - .../app/services/componentManager.js | 4 - .../javascripts/app/services/themeManager.js | 73 +------------------ 3 files changed, 1 insertion(+), 77 deletions(-) diff --git a/app/assets/javascripts/app/controllers/home.js b/app/assets/javascripts/app/controllers/home.js index ab2f2e20d..427afa393 100644 --- a/app/assets/javascripts/app/controllers/home.js +++ b/app/assets/javascripts/app/controllers/home.js @@ -57,7 +57,6 @@ angular.module('app') authManager.loadInitialData(); syncManager.loadLocalItems(function(items) { $scope.allTag.didLoad = true; - themeManager.activateInitialTheme(); $scope.$apply(); $rootScope.$broadcast("initial-data-loaded"); diff --git a/app/assets/javascripts/app/services/componentManager.js b/app/assets/javascripts/app/services/componentManager.js index 71979c82e..627ad5119 100644 --- a/app/assets/javascripts/app/services/componentManager.js +++ b/app/assets/javascripts/app/services/componentManager.js @@ -20,10 +20,6 @@ class ComponentManager { this.handlers = []; - // $rootScope.$on("theme-changed", function(){ - // this.postThemeToAllComponents(); - // }.bind(this)) - window.addEventListener("message", function(event){ if(this.loggingEnabled) { console.log("Web app: received message", event); diff --git a/app/assets/javascripts/app/services/themeManager.js b/app/assets/javascripts/app/services/themeManager.js index 5f7d745c8..74dad17ff 100644 --- a/app/assets/javascripts/app/services/themeManager.js +++ b/app/assets/javascripts/app/services/themeManager.js @@ -1,10 +1,6 @@ class ThemeManager { - constructor(modelManager, syncManager, $rootScope, storageManager, componentManager) { - this.syncManager = syncManager; - this.modelManager = modelManager; - this.$rootScope = $rootScope; - this.storageManager = storageManager; + constructor(componentManager) { this.componentManager = componentManager; componentManager.registerHandler({identifier: "themeManager", areas: ["themes"], activationHandler: (component) => { @@ -16,48 +12,8 @@ class ThemeManager { }}); } - get themes() { - return this.modelManager.itemsForContentType("SN|Theme"); - } - - - /* - activeTheme: computed property that returns saved theme - currentTheme: stored variable that allows other classes to watch changes - */ - - // get activeTheme() { - // var activeThemeId = this.storageManager.getItem("activeTheme"); - // if(!activeThemeId) { - // return null; - // } - // - // var theme = _.find(this.themes, {uuid: activeThemeId}); - // return theme; - // } - - activateInitialTheme() { - // var theme = this.activeTheme; - // if(theme) { - // this.activateTheme(theme); - // } - } - - // submitTheme(url) { - // var name = this.displayNameForThemeFile(this.fileNameFromPath(url)); - // var theme = this.modelManager.createItem({content_type: "SN|Theme", url: url, name: name}); - // this.modelManager.addItem(theme); - // theme.setDirty(true); - // this.syncManager.sync(); - // } - activateTheme(theme) { - if(this.activeTheme && this.activeTheme !== theme) { - this.deactivateTheme(this.activeTheme); - } - var url = this.componentManager.urlForComponent(theme); - var link = document.createElement("link"); link.href = url; link.type = "text/css"; @@ -65,42 +21,15 @@ class ThemeManager { link.media = "screen,print"; link.id = theme.uuid; document.getElementsByTagName("head")[0].appendChild(link); - this.storageManager.setItem("activeTheme", theme.uuid); - - this.currentTheme = theme; - this.$rootScope.$broadcast("theme-changed"); } deactivateTheme(theme) { - this.storageManager.removeItem("activeTheme"); var element = document.getElementById(theme.uuid); if(element) { element.disabled = true; element.parentNode.removeChild(element); } - - this.currentTheme = null; - this.$rootScope.$broadcast("theme-changed"); } - - fileNameFromPath(filePath) { - return filePath.replace(/^.*[\\\/]/, ''); - } - - capitalizeString(string) { - return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); }); - } - - displayNameForThemeFile(fileName) { - let fromParam = getParameterByName("name", fileName); - if(fromParam) { - return fromParam; - } - let name = fileName.split(".")[0]; - let cleaned = name.split("-").join(" "); - return this.capitalizeString(cleaned); - } - } angular.module('app').service('themeManager', ThemeManager);