Almost configurable base

This commit is contained in:
Vit Brunner
2014-11-11 09:09:01 +01:00
parent 81d5f664b8
commit 6c4a600270
9 changed files with 60 additions and 34 deletions
+2 -5
View File
@@ -1,7 +1,4 @@
angular.module('sideBySide', ['sideBySide.controllers', 'ngRoute', 'ngSanitize'])
.config [ '$routeProvider', ($routeProvider) ->
$routeProvider.when '/:base?/:section?', {
templateUrl: 'partials/comparison.html'
controller: 'ComparisonController'
}
.config [ '$locationProvider', ($locationProvider) ->
$locationProvider.html5Mode true
]
+15 -11
View File
@@ -2,21 +2,25 @@ angular.module("sideBySide.controllers", [])
.controller "AppController", [
'$location', '$scope', 'poems'
($location, $scope, poems) ->
$scope.$on "$routeChangeSuccess", ($currentRoute, $previousRoute) ->
$scope.base = if $previousRoute.params.base \
then '/' + $previousRoute.params.base
else ''
urlParams = $location.url()
.split('/')
.filter((item) -> item)
.map (item) ->
item.split(':')
.reduce((prev, current) ->
prev[current[0]] = current[1]
prev
, {})
if 'base' of urlParams
urlParams.base = urlParams.base.replace(/\./g, '/')
else
urlParams.base = ''
appUrl = $location.absUrl()
.substring(0, $location.absUrl().length - $location.url().length)
.replace(/[^\/]*?#$/, '')
base = appUrl + $location.url()
.slice(1)
.replace(/(.*)\/.*/, '$1')
.replace(/\./g, '/')
poems.load base
poems.load appUrl + '/' + urlParams.base
]
.controller "ComparisonController", [
+4 -3
View File
@@ -1,12 +1,13 @@
angular.module("sideBySide").factory "fetch", ['$http', '$q', 'readerFactory', ($http, $q, readerFactory) ->
# Fetch
#
# @param file [String] Path to config file
# @param base [String] Path to config file directory
# @return [Object] Promises and heading
(file = "/config.json") ->
(base) ->
file = base + '/config.json'
$http.get(file).then (config) ->
promises = config.data.files.map (poem) ->
$http.get(poem).then (response) ->
$http.get(base + '/' + poem).then (response) ->
readerFactory(poem) response.data
{
+2 -2
View File
@@ -32,8 +32,8 @@ angular.module("sideBySide").service "poems", ['fetch', (fetch) ->
# Load poems
#
# @param base [String]
@load = (base = '') =>
fetch(base + "/config.json").then (config) =>
@load = (base) =>
fetch(base).then (config) =>
config.fetchPoems.then (poems) =>
@all = (activize(poem, config.active) for poem in poems)
@heading = config.heading