mirror of
https://github.com/wassname/side-by-side.git
synced 2026-08-21 11:21:53 +08:00
29 lines
808 B
CoffeeScript
29 lines
808 B
CoffeeScript
angular.module("sideBySide").factory "load",
|
|
['filter', 'fetch', 'poems'
|
|
(filter, fetch, poems) ->
|
|
# Load poems
|
|
#
|
|
# @param base [String] Path to config file directory
|
|
# @param display [Object] Eg: { Language: [ 'English', 'Czech' ] }
|
|
(base, display) ->
|
|
# Activize poem based on passed rules
|
|
#
|
|
# @param poem [Object]
|
|
# @param display [Object] { meta: [ 'active', 'values' ] }
|
|
# @return poem
|
|
activize = (poem, display) ->
|
|
poem.meta.Active = true if !display
|
|
|
|
for metaKey,values of display
|
|
poem.meta.Active = true if poem.meta[metaKey] in values
|
|
|
|
poem
|
|
|
|
fetch(base).then (config) ->
|
|
config.fetchedPoems.then (poemList) ->
|
|
disp = display or config.data.display
|
|
poems.all = (activize(poem, disp) for poem in poemList)
|
|
poems.config = config.data
|
|
filter.update()
|
|
]
|