mirror of
https://github.com/wassname/side-by-side.git
synced 2026-09-09 11:34:24 +08:00
Activize poems based on config
This commit is contained in:
@@ -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
|
||||
|
||||
@
|
||||
]
|
||||
|
||||
@@ -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" ]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user