Add fetcher

This commit is contained in:
Vit Brunner
2013-06-18 00:00:59 +01:00
parent 73cea13621
commit b65460d74e
4 changed files with 37 additions and 38 deletions
+1
View File
@@ -4,6 +4,7 @@ script(src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.5/angular.js")
// TODO use cdnjs.com once they serve marked
script(src="//raw.github.com/chjj/marked/master/lib/marked.js")
script(src="scripts/app.js")
script(src="scripts/services/fetch.js")
script(src="scripts/services/reader/_factory.js")
script(src="scripts/services/reader/markdown.js")
script(src="scripts/services/reader/json.js")
+1 -1
View File
@@ -16,7 +16,7 @@ html(ng-app="sideBySide")
.version-outer
.version-inner
.section {{ version.section }}
.text {{ version.text }}
.text(ng-bind-html-unsafe="version.text")
//// debugging cascade
//hr
+19 -37
View File
@@ -1,41 +1,23 @@
angular.module("sideBySide.controllers", [])
.controller "comparisonController", ['$scope', ($scope) ->
$scope.columns = 2
$scope.verses = [
[
{
section: 'first'
text: 'a'
}, {
section: 'I'
text: '1'
}
], [
{
section: 'second'
text: 'b'
}, {
section: 'II'
text: '2'
}
], [
{
section: 'third'
text: 'c'
}, {
section: 'III'
text: '3'
}
], [
{
section: 'fourth'
text: 'd'
}, {
section: 'IV'
text: '4'
}
]
]
.controller "comparisonController", [
'$location', '$q', '$scope', 'fetch', 'transformer'
($location, $q, $scope, fetch, transformer) ->
$scope.columns = 1
$scope.verses = [[{
section: 'Loading...'
text: 'Please be patient!'
}]]
update = (config) ->
fetch(config).then((promises) ->
$q.all(promises).then((results) ->
$scope.columns = results.length
transformed = transformer(results)
$scope.verses = transformed.verses
)
)
update($location.path() + "/config.json")
]
#.controller "notificationController", ['$scope', '$timeout', ($scope, $timeout) ->
@@ -0,0 +1,16 @@
angular.module("sideBySide").factory "fetch", ['$http', 'readerFactory', ($http, readerFactory) ->
# Fetch
#
# @param file [String] Path to config file
# @return TODO
return (file = "config.json") ->
$http.get(file).then((response) ->
promises = []
for poem in response.data.files
promises.push($http.get(poem).then((response) ->
reader = readerFactory(poem)
return reader(response.data)
))
return promises
)
]