From f5394534f77cb155f10711116be303e3368fd269 Mon Sep 17 00:00:00 2001 From: jendib Date: Sun, 8 May 2016 15:38:47 +0200 Subject: [PATCH] #79: Change custom CSS and app name --- .../docs/rest/resource/ThemeResource.java | 2 ++ docs-web/src/main/webapp/src/app/docs/app.js | 10 +++++-- .../docs/controller/settings/SettingsTheme.js | 29 ++++++++++--------- docs-web/src/main/webapp/src/app/share/app.js | 8 ++++- docs-web/src/main/webapp/src/index.html | 4 +-- .../src/partial/docs/settings.security.html | 6 ++-- .../src/partial/docs/settings.theme.html | 22 ++++++++++++-- docs-web/src/main/webapp/src/share.html | 4 +-- .../sismics/docs/rest/TestThemeResource.java | 4 +++ 9 files changed, 62 insertions(+), 27 deletions(-) diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/ThemeResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/ThemeResource.java index abf6ee13..6e3f96a1 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/ThemeResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/ThemeResource.java @@ -56,6 +56,8 @@ public class ThemeResource extends BaseResource { JsonObject themeConfig = getThemeConfig(); JsonObjectBuilder json = Json.createObjectBuilder(); json.add("name", themeConfig.getString("name", "Sismics Docs")); + json.add("color", themeConfig.getString("color", "#263238")); + json.add("css", themeConfig.getString("css", "")); return Response.ok().entity(json.build()).build(); } diff --git a/docs-web/src/main/webapp/src/app/docs/app.js b/docs-web/src/main/webapp/src/app/docs/app.js index 8c9d4fca..f68b8b72 100644 --- a/docs-web/src/main/webapp/src/app/docs/app.js +++ b/docs-web/src/main/webapp/src/app/docs/app.js @@ -13,7 +13,6 @@ angular.module('docs', * Configuring modules. */ .config(function($stateProvider, $httpProvider, RestangularProvider) { - // Configuring UI Router $stateProvider .state('main', { @@ -381,10 +380,15 @@ angular.module('docs', /** * Application initialization. */ -.run(function($rootScope, $state, $stateParams) { +.run(function($rootScope, $state, $stateParams, Restangular) { $rootScope.$state = $state; $rootScope.$stateParams = $stateParams; - $rootScope.pageTitle = 'Sismics Docs'; + + // Fetch the current theme configuration + $rootScope.appName = ''; + Restangular.one('theme').get().then(function(data) { + $rootScope.appName = data.name; + }); }) /** * Redirection support for ui-router. diff --git a/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsTheme.js b/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsTheme.js index 405d0066..02a06f9d 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsTheme.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsTheme.js @@ -3,19 +3,20 @@ /** * Settings theme page controller. */ -angular.module('docs').controller('SettingsTheme', function($scope, Restangular) { - // Fetch the current theme configuration - $scope.theme = { - color: $('.navbar').css('background-color') - }; +angular.module('docs').controller('SettingsTheme', function($scope, $rootScope, Restangular) { + // Fetch the current theme configuration + Restangular.one('theme').get().then(function(data) { + $scope.theme = data; + $rootScope.appName = $scope.theme.name; + }); - // Update the main color - $scope.updateColor = function(color) { - Restangular.one('theme').post('color', { - color: color - }).then(function() { - var stylesheet = $('#theme-stylesheet')[0]; - stylesheet.href = stylesheet.href.replace(/\?.*|$/, '?' + new Date().getTime()); - }); - } + // Update the theme + $scope.update = function() { + $scope.theme.name = $scope.theme.name.length == 0 ? 'Sismics Docs' : $scope.theme.name; + Restangular.one('theme').post('', $scope.theme).then(function() { + var stylesheet = $('#theme-stylesheet')[0]; + stylesheet.href = stylesheet.href.replace(/\?.*|$/, '?' + new Date().getTime()); + $rootScope.appName = $scope.theme.name; + }); + } }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/app/share/app.js b/docs-web/src/main/webapp/src/app/share/app.js index 9fe7cdfb..e9c69b98 100644 --- a/docs-web/src/main/webapp/src/app/share/app.js +++ b/docs-web/src/main/webapp/src/app/share/app.js @@ -95,7 +95,13 @@ angular.module('share', /** * Application initialization. */ -.run(function($rootScope, $state, $stateParams) { +.run(function($rootScope, $state, $stateParams, Restangular) { $rootScope.$state = $state; $rootScope.$stateParams = $stateParams; + + // Fetch the current theme configuration + $rootScope.appName = ''; + Restangular.one('theme').get().then(function(data) { + $rootScope.appName = data.name; + }); }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/index.html b/docs-web/src/main/webapp/src/index.html index 5b92a0b1..d4cce917 100644 --- a/docs-web/src/main/webapp/src/index.html +++ b/docs-web/src/main/webapp/src/index.html @@ -1,7 +1,7 @@ - Sismics Docs + Sismics Docs @@ -103,7 +103,7 @@ - Sismics Docs + {{ appName }} - Sismics Docs + {{ appName }} diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestThemeResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestThemeResource.java index 61c06cef..79039e9d 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestThemeResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestThemeResource.java @@ -31,6 +31,8 @@ public class TestThemeResource extends BaseJerseyTest { JsonObject json = target().path("/theme").request() .get(JsonObject.class); Assert.assertEquals("Sismics Docs", json.getString("name")); + Assert.assertEquals("#263238", json.getString("color")); + Assert.assertEquals("", json.getString("css")); // Update the main color as admin target().path("/theme").request() @@ -50,5 +52,7 @@ public class TestThemeResource extends BaseJerseyTest { json = target().path("/theme").request() .get(JsonObject.class); Assert.assertEquals("My App", json.getString("name")); + Assert.assertEquals("#ff0000", json.getString("color")); + Assert.assertEquals(".body { content: 'Custom CSS'; }", json.getString("css")); } } \ No newline at end of file