From 02f3904cd141fd761fdd6c1e88dc4494b1a12458 Mon Sep 17 00:00:00 2001 From: Vit Brunner Date: Sun, 28 Dec 2014 14:02:48 +0100 Subject: [PATCH] Better meta attributes listing --- source/includes/comparison.html.jade | 4 ++-- source/scripts/controllers.js.coffee | 1 + source/scripts/services/poems.js.coffee | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/source/includes/comparison.html.jade b/source/includes/comparison.html.jade index 8ab368d..ee6a794 100644 --- a/source/includes/comparison.html.jade +++ b/source/includes/comparison.html.jade @@ -11,9 +11,9 @@ .pick-in table tr - th(ng-repeat="(attribute, value) in all[0].meta" ng-if="attribute != 'Active'" ng-bind-html="attribute") + th(ng-repeat="attribute in metaKeys" ng-if="attribute != 'Active'" ng-bind-html="attribute") tr(ng-repeat="poem in all" class="switch" ng-class="{disabled: !poem.meta.Active}" ng-click="switchActive(poem)") - td(ng-repeat="(attribute, value) in poem.meta" ng-if="attribute != 'Active'" ng-bind-html="value") + td(ng-repeat="attribute in metaKeys" ng-if="attribute != 'Active'" ng-bind-html="poem.meta[attribute]") // verses #content diff --git a/source/scripts/controllers.js.coffee b/source/scripts/controllers.js.coffee index 3024c96..f811b4d 100644 --- a/source/scripts/controllers.js.coffee +++ b/source/scripts/controllers.js.coffee @@ -41,6 +41,7 @@ angular.module("sideBySide.controllers", []) headingKey = poems.config.heading or "Author" $scope.headings = (version[headingKey] for version in transformed.meta) + $scope.metaKeys = poems.getMetaKeys() $scope.all = poems.all scroll() diff --git a/source/scripts/services/poems.js.coffee b/source/scripts/services/poems.js.coffee index 26b46ef..2cbe2dd 100644 --- a/source/scripts/services/poems.js.coffee +++ b/source/scripts/services/poems.js.coffee @@ -23,4 +23,9 @@ angular.module("sideBySide").service "poems", -> @getInactive = -> (poem for poem in @all when poem.meta.Active != true) + @getMetaKeys = -> + @all.reduce (all, one) -> + _.uniq all.concat (key for key of one.meta) + , [] + @