mirror of
https://github.com/wassname/side-by-side.git
synced 2026-09-09 11:34:24 +08:00
Split poem loading
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
angular.module("sideBySide").factory "load", ['fetch', 'poems', (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.heading = config.data.heading
|
||||
]
|
||||
Reference in New Issue
Block a user