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:
@@ -3,8 +3,8 @@ angular.module("sideBySide.controllers", [])
|
||||
() -> null
|
||||
]
|
||||
.controller "ComparisonController", [
|
||||
'$document', '$rootScope', '$scope', 'route', 'poems', 'transformer'
|
||||
($document, $rootScope, $scope, route, poems, transformer) ->
|
||||
'$document', '$rootScope', '$scope', 'load', 'poems', 'route', 'transformer'
|
||||
($document, $rootScope, $scope, load, poems, route, transformer) ->
|
||||
min = 1
|
||||
max = 5
|
||||
|
||||
@@ -49,5 +49,8 @@ angular.module("sideBySide.controllers", [])
|
||||
|
||||
$scope.pick = false
|
||||
|
||||
poems.load route.appUrl + '/' + route.params.base.replace(/\./g, '/')
|
||||
load(
|
||||
route.appUrl + '/' + route.params.base.replace(/\./g, '/')
|
||||
route.params.display
|
||||
)
|
||||
]
|
||||
|
||||
@@ -2,7 +2,7 @@ angular.module("sideBySide").factory "fetch", ['$http', '$q', 'readerFactory', (
|
||||
# Fetch
|
||||
#
|
||||
# @param base [String] Path to config file directory
|
||||
# @return [Object] Promises and heading
|
||||
# @return [Object] Promises and config data
|
||||
(base) ->
|
||||
file = base + '/config.json'
|
||||
$http.get(file).then (config) ->
|
||||
@@ -11,8 +11,7 @@ angular.module("sideBySide").factory "fetch", ['$http', '$q', 'readerFactory', (
|
||||
readerFactory(poem) response.data
|
||||
|
||||
{
|
||||
fetchPoems: $q.all promises
|
||||
heading: config.data.heading
|
||||
display: config.data.display
|
||||
fetchedPoems: $q.all promises
|
||||
data: config.data
|
||||
}
|
||||
]
|
||||
|
||||
@@ -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
|
||||
]
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("sideBySide").service "poems", ['fetch', 'route', (fetch, route) ->
|
||||
angular.module("sideBySide").service "poems", () ->
|
||||
@all = [{
|
||||
meta: {
|
||||
Active: true
|
||||
@@ -23,28 +23,4 @@ angular.module("sideBySide").service "poems", ['fetch', 'route', (fetch, route)
|
||||
@getInactive = () ->
|
||||
(poem for poem in @all when poem.meta.Active is not true)
|
||||
|
||||
# Activize poem based on passed rules
|
||||
#
|
||||
# @param poem [Object]
|
||||
# @param active [Object] { meta: [ 'active', 'values' ] }
|
||||
# @return poem
|
||||
activize = (poem, active) ->
|
||||
poem.meta.Active = true if !active
|
||||
|
||||
for metaKey,values of active
|
||||
poem.meta.Active = true if poem.meta[metaKey] in values
|
||||
|
||||
poem
|
||||
|
||||
# Load poems
|
||||
#
|
||||
# @param base [String]
|
||||
@load = (base) =>
|
||||
fetch(base).then (config) =>
|
||||
config.fetchPoems.then (poems) =>
|
||||
display = route.params.display or config.display
|
||||
@all = (activize(poem, display) for poem in poems)
|
||||
@heading = config.heading
|
||||
|
||||
@
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user