New config service with more clear format.

stable
Andrey Antukh 2014-10-08 11:58:55 +02:00
parent d6583381a9
commit f8c1740744
5 changed files with 23 additions and 56 deletions

2
.gitignore vendored
View File

@ -8,4 +8,6 @@ app/coffee/modules/locales/locale*.coffee
*.swp
*.swo
tags
tmp/
conf/
app/config/main.coffee

View File

@ -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",

View File

@ -16,35 +16,20 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# 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])

View File

@ -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)

8
conf/main.example.json Normal file
View File

@ -0,0 +1,8 @@
{
"api": "http://localhost:8000/api/v1/",
"eventsUrl": "ws://localhost:8888/events",
"debug": "true",
"publicRegisterEnabled": true,
"privacyPolicyUrl": null,
"termsOfServiceUrl": null
}