Activize poems based on config

This commit is contained in:
Vit Brunner
2014-10-12 15:37:47 +02:00
parent 8d1a0d2773
commit 9a06722705
3 changed files with 21 additions and 12 deletions
@@ -4,9 +4,9 @@ angular.module("sideBySide").factory "fetch", ['$http', 'readerFactory', ($http,
# @param file [String] Path to config file
# @return [Object] Promises and heading
(file = "/config.json") ->
$http.get(file).then((response) ->
$http.get(file).then((config) ->
promises = []
for poem in response.data.files
for poem in config.data.files
promises.push($http.get(poem).then((response) ->
reader = readerFactory(poem)
reader(response.data)
@@ -14,7 +14,8 @@ angular.module("sideBySide").factory "fetch", ['$http', 'readerFactory', ($http,
{
promises: promises
heading: response.data.heading
heading: config.data.heading
active: config.data.active
}
)
]
@@ -13,18 +13,23 @@ angular.module("sideBySide").service "poems", ['$q', 'fetch', ($q, fetch) ->
@getActive = () ->
(poem for poem in @all when poem.meta.Active is true)
@load = (base = '') =>
config = base + "/config.json"
activize = (poem, active) ->
if !active
poem.meta.Active = true
fetch(config).then (result) =>
$q.all(result.promises).then (results) =>
for metaKey,values of active
if poem.meta[metaKey] in values
poem.meta.Active = true
poem
@load = (base = '') =>
fetch(base + "/config.json").then (config) =>
$q.all(config.promises).then (results) =>
@all = []
for poem in results
if not poem.meta.Active?
poem.meta.Active = true
@all.push poem
@all.push activize(poem, config.active)
@heading = result.heading
@heading = config.heading
@
]
+4 -1
View File
@@ -7,5 +7,8 @@
, "tests/the_raven/1900-zenon-przesmycki.md"
, "tests/the_raven/1910-barbara-beaupre.md"
, "tests/the_raven/1970-baranczak.md"
]
],
"active": {
"Language": [ "Czech" ]
}
}