From f8c1740744dc8452230f322859af885277f1f8b9 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 8 Oct 2014 11:58:55 +0200 Subject: [PATCH] New config service with more clear format. --- .gitignore | 2 + app/coffee/app.coffee | 4 -- .../base/conf.coffee} | 46 ++++++------------- app/config/main.coffee.example | 19 -------- conf/main.example.json | 8 ++++ 5 files changed, 23 insertions(+), 56 deletions(-) rename app/coffee/{config.coffee => modules/base/conf.coffee} (52%) delete mode 100644 app/config/main.coffee.example create mode 100644 conf/main.example.json diff --git a/.gitignore b/.gitignore index 96dfdec9..91e8a0b3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ app/coffee/modules/locales/locale*.coffee *.swp *.swo tags +tmp/ +conf/ app/config/main.coffee diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index bfdec816..ce17976f 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -193,14 +193,10 @@ init = ($log, $i18n, $config, $rootscope, $auth, $events) -> if $auth.isAuthenticated() $events.setupConnection() -# Default Value for taiga local config module. -angular.module("taigaLocalConfig", []).value("localconfig", {}) - modules = [ # Main Global Modules "taigaBase", "taigaCommon", - "taigaConfig", "taigaResources", "taigaLocales", "taigaAuth", diff --git a/app/coffee/config.coffee b/app/coffee/modules/base/conf.coffee similarity index 52% rename from app/coffee/config.coffee rename to app/coffee/modules/base/conf.coffee index 43ea197b..2caaeee4 100644 --- a/app/coffee/config.coffee +++ b/app/coffee/modules/base/conf.coffee @@ -16,35 +16,20 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # -# File: config.coffee +# File: modules/base/conf.coffee ### -taiga = @.taiga +defaults = { + api: "http://localhost:8000/api/v1/" + debug: true + lang: "en" +} -class ConfigService extends taiga.Service - defaults: { - host: "localhost:8000" - scheme: "http" +class ConfigurationService + @.$inject = ["localconf"] - debug: false - - defaultLanguage: "en" - languageOptions: { - "es": "Spanish" - "en": "English" - } - - publicRegisterEnabled: false - - termsOfServiceUrl: null - privacyPolicyUrl: null - - feedbackEnabled: true - } - - initialize: (localconfig) -> - defaults = _.clone(@.defaults, true) - @.config = _.merge(defaults, localconfig) + constructor: (localconf) -> + @.config = _.merge(_.clone(defaults, true), localconf) get: (key, defaultValue=null) -> if _.has(@.config, key) @@ -52,12 +37,7 @@ class ConfigService extends taiga.Service return defaultValue -# Initialize config loading local configuration. -init = ($log, localconfig, config) -> - $log.debug("Initializing configuration", localconfig) - config.initialize(localconfig) +module = angular.module("taigaBase") +module.service("$tgConfig", ConfigurationService) +module.value("localconf", null) - -module = angular.module("taigaConfig", ["taigaLocalConfig"]) -module.service("$tgConfig", ConfigService) -module.run(["$log", "localconfig", "$tgConfig", init]) diff --git a/app/config/main.coffee.example b/app/config/main.coffee.example deleted file mode 100644 index fc68f1da..00000000 --- a/app/config/main.coffee.example +++ /dev/null @@ -1,19 +0,0 @@ -config = { - host: "localhost:8000" - scheme: "http" - - debug: true - - defaultLanguage: "en" - languageOptions: { - "en": "English" - } - - publicRegisterEnabled: true - privacyPolicyUrl: null - termsOfServiceUrl: null - - feedbackEnabled: true -} - -angular.module("taigaLocalConfig", []).value("localconfig", config) diff --git a/conf/main.example.json b/conf/main.example.json new file mode 100644 index 00000000..3585e04a --- /dev/null +++ b/conf/main.example.json @@ -0,0 +1,8 @@ +{ + "api": "http://localhost:8000/api/v1/", + "eventsUrl": "ws://localhost:8888/events", + "debug": "true", + "publicRegisterEnabled": true, + "privacyPolicyUrl": null, + "termsOfServiceUrl": null +}