From 9a0672270546dc531ff59b06fe5a27f5e8d01fd7 Mon Sep 17 00:00:00 2001 From: Vit Brunner Date: Sun, 12 Oct 2014 15:37:47 +0200 Subject: [PATCH] Activize poems based on config --- .../scripts/services/fetch.js.coffee | 7 ++++--- .../scripts/services/poems.js.coffee | 21 ++++++++++++------- source/documents/tests/the_raven/config.json | 5 ++++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/source/documents/scripts/services/fetch.js.coffee b/source/documents/scripts/services/fetch.js.coffee index e083037..812ff2d 100644 --- a/source/documents/scripts/services/fetch.js.coffee +++ b/source/documents/scripts/services/fetch.js.coffee @@ -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 } ) ] diff --git a/source/documents/scripts/services/poems.js.coffee b/source/documents/scripts/services/poems.js.coffee index a0a55cc..3def26f 100644 --- a/source/documents/scripts/services/poems.js.coffee +++ b/source/documents/scripts/services/poems.js.coffee @@ -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 @ ] diff --git a/source/documents/tests/the_raven/config.json b/source/documents/tests/the_raven/config.json index 98fbfdf..4363b36 100644 --- a/source/documents/tests/the_raven/config.json +++ b/source/documents/tests/the_raven/config.json @@ -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" ] + } }