Permalink
Browse files

Render storylines as array in seed data

Unify interface to allow generic handling of storylines just like any
other collection.
  • Loading branch information...
1 parent 0024e05 commit 3cea2634075606255e58280271191eb9effecff7 @tf tf committed Dec 13, 2016
View
@@ -6,6 +6,7 @@
"maxlen": 100,
"unused": "vars",
"expr": true,
+ "camelcase": false,
"predef": [
"jQuery",
"$",
@@ -2,7 +2,10 @@ pageflow.SeedEntryData = pageflow.EntryData.extend({
initialize: function(options) {
this.theming = options.theming;
- this.storylineConfigurations = options.storyline_configurations;
+ this.storylineConfigurations = _(options.storylines).reduce(function(memo, storyline) {
+ memo[storyline.id] = storyline.configuration;
+ return memo;
+ }, {});
this.storylineIdsByChapterIds = _(options.chapters).reduce(function(memo, chapter) {
memo[chapter.id] = chapter.storyline_id;
@@ -13,7 +13,7 @@ def entry_json_seed(entry)
def entry_seed(entry)
common_entry_seed(entry).merge(
theming: entry_theming_seed(entry),
- storyline_configurations: entry_storyline_configurations_seed(entry),
+ storylines: entry_storylines_seed(entry),
chapters: entry_chapters_seed(entry),
pages: entry_pages_seed(entry),
file_ids: entry_file_ids_seed(entry)
@@ -28,10 +28,9 @@ def entry_theming_seed(entry)
}
end
- def entry_storyline_configurations_seed(entry)
- entry.storylines.each_with_object({}) do |storyline, result|
- result[storyline.id] = storyline.configuration
- end
+ def entry_storylines_seed(entry)
+ attributes = [:id, :configuration]
+ entry.storylines.as_json(only: attributes)
end
def entry_chapters_seed(entry)
@@ -28,20 +28,21 @@ module Pageflow
end
end
- describe '#entry_storyline_configurations_seed' do
- it 'indexed configurations by id' do
+ describe '#entry_storylines_seed' do
+ it 'includes id and configuration' do
revision = create(:revision, :published)
storyline = create(:storyline, revision: revision, configuration: {text: 'some text'})
entry = PublishedEntry.new(create(:entry, published_revision: revision))
- result = helper.entry_storyline_configurations_seed(entry)
+ result = helper.entry_storylines_seed(entry)
- expect(result[storyline.id]['text']).to eq('some text')
+ expect(result[0]['id']).to eq(storyline.id)
+ expect(result[0]['configuration']['text']).to eq('some text')
end
end
describe '#entry_chapters_seed' do
- it 'indexed configurations by id' do
+ it 'includes id and configuration' do
revision = create(:revision, :published)
storyline = create(:storyline, revision: revision)
chapter = create(:chapter,
@@ -5,9 +5,12 @@ describe('pageflow.ChapterFilter', function() {
describe('with default strategy', function() {
it('return true for chapters of same storyline', function() {
var chapterFilter = new p.ChapterFilter(new p.SeedEntryData({
- storyline_configurations: {
- 10: {}
- },
+ storylines: [
+ {
+ id: 10,
+ configuration: {}
+ }
+ ],
chapters: [
{
id: 1,
@@ -33,12 +36,15 @@ describe('pageflow.ChapterFilter', function() {
describe('with inherit_from_parent strategy', function() {
it('returns true only for chapters visible from parent chapter', function() {
var chapterFilter = new p.ChapterFilter(new p.SeedEntryData({
- storyline_configurations: {
- 10: {
- navigation_bar_mode: 'inherit_from_parent',
- parent_page_perma_id: 100
+ storylines: [
+ {
+ id: 10,
+ configuration: {
+ navigation_bar_mode: 'inherit_from_parent',
+ parent_page_perma_id: 100
+ }
}
- },
+ ],
chapters: [
{
id: 1,
@@ -67,11 +73,14 @@ describe('pageflow.ChapterFilter', function() {
describe('with non strategy', function() {
it('returns false', function() {
var chapterFilter = new p.ChapterFilter(new p.SeedEntryData({
- storyline_configurations: {
- 10: {
- navigation_bar_mode: 'non'
+ storylines: [
+ {
+ id: 10,
+ configuration: {
+ navigation_bar_mode: 'non'
+ }
}
- },
+ ],
chapters: [
{
id: 1,
@@ -16,11 +16,12 @@ describe('pageflow.EntryData', function() {
id: 100,
storyline_id: 1000
}],
- storyline_configurations: {
- 1000: {
+ storylines: [{
+ id: 1000,
+ configuration: {
parent_page_perma_id: 6
}
- }
+ }]
});
var result = entryData.getParentPagePermaIdByPagePermaId(5);
@@ -67,12 +68,17 @@ describe('pageflow.EntryData', function() {
storyline_id: 1001
}
],
- storyline_configurations: {
- 1000: {},
- 1001: {
- parent_page_perma_id: 5
+ storylines: [
+ {
+ id: 1000
+ },
+ {
+ id: 1001,
+ configuration: {
+ parent_page_perma_id: 5
+ }
}
- }
+ ]
});
var result = entryData.getParentStorylineId(1001);
@@ -82,9 +88,9 @@ describe('pageflow.EntryData', function() {
it('returns undefined if there is no parent page', function() {
var entryData = new createEntryData({
- storyline_configurations: {
- 1001: {}
- }
+ storylines: [{
+ id: 1001
+ }]
});
var result = entryData.getParentStorylineId(1001);
@@ -100,11 +106,12 @@ describe('pageflow.EntryData', function() {
id: 100,
storyline_id: 1000
}],
- storyline_configurations: {
- 1000: {
+ storylines: [{
+ id: 1000,
+ configuration: {
parent_page_perma_id: 6
}
- },
+ }],
pages: [{
perma_id: 6,
chapter_id: 101
@@ -120,11 +127,12 @@ describe('pageflow.EntryData', function() {
describe('#getParentPagePermaId', function() {
it('returns perma id of storyline`s parent page', function() {
var entryData = new createEntryData({
- storyline_configurations: {
- 1000: {
+ storylines: [{
+ id: 1000,
+ configuration: {
parent_page_perma_id: 6
}
- }
+ }]
});
var result = entryData.getParentPagePermaId(1000);
@@ -156,15 +164,23 @@ describe('pageflow.EntryData', function() {
storyline_id: 1001
}
],
- storyline_configurations: {
- 1000: {},
- 1001: {
- parent_page_perma_id: 5
+ storylines: [
+ {
+ id: 1000,
},
- 1002: {
- parent_page_perma_id: 6
+ {
+ id: 1001,
+ configuration: {
+ parent_page_perma_id: 5
+ },
+ },
+ {
+ id: 1002,
+ configuration: {
+ parent_page_perma_id: 6
+ }
}
- }
+ ]
});
expect(entryData.getStorylineLevel(1000)).to.eq(0);
@@ -5,9 +5,12 @@ describe('pageflow.HighlightedPage', function() {
describe('for storylines with own navigation bar', function() {
it('returns perma id of same page if page is displayed in navigation', function() {
var outline = new p.HighlightedPage(new p.SeedEntryData({
- storyline_configurations: {
- 10: {}
- },
+ storylines: [
+ {
+ id: 10,
+ configuration: {}
+ }
+ ],
chapters: [{
id: 1,
storyline_id: 10
@@ -27,9 +30,12 @@ describe('pageflow.HighlightedPage', function() {
it('returns perma id of previous page if page is not displayed in navigation', function() {
var outline = new p.HighlightedPage(new p.SeedEntryData({
- storyline_configurations: {
- 10: {}
- },
+ storylines: [
+ {
+ id: 10,
+ configuration: {}
+ }
+ ],
chapters: [{
id: 1,
storyline_id: 10
@@ -58,12 +64,15 @@ describe('pageflow.HighlightedPage', function() {
describe('for chapter with inherited navigation bar', function() {
it('returns perma id of parent page', function() {
var outline = new p.HighlightedPage(new p.SeedEntryData({
- storyline_configurations: {
- 10: {
- navigation_bar_mode: 'inherit_from_parent',
- parent_page_perma_id: 101
+ storylines: [
+ {
+ id: 10,
+ configuration: {
+ navigation_bar_mode: 'inherit_from_parent',
+ parent_page_perma_id: 101
+ }
},
- },
+ ],
chapters: [
{
id: 1,
@@ -91,16 +100,22 @@ describe('pageflow.HighlightedPage', function() {
describe('for chapter with inherited navigation bar over multiple levels', function() {
it('returns perma id of parent page', function() {
var outline = new p.HighlightedPage(new p.SeedEntryData({
- storyline_configurations: {
- 10: {
- navigation_bar_mode: 'inherit_from_parent',
- parent_page_perma_id: 101
+ storylines: [
+ {
+ id: 10,
+ configuration: {
+ navigation_bar_mode: 'inherit_from_parent',
+ parent_page_perma_id: 101
+ }
},
- 20: {
- navigation_bar_mode: 'inherit_from_parent',
- parent_page_perma_id: 102
+ {
+ id: 20,
+ configuration: {
+ navigation_bar_mode: 'inherit_from_parent',
+ parent_page_perma_id: 102
+ }
}
- },
+ ],
chapters: [
{id: 1, storyline_id: 10},
{id: 2, storyline_id: 20},
@@ -122,17 +137,26 @@ describe('pageflow.HighlightedPage', function() {
describe('with customNavigationBarMode option', function() {
it('uses navigation bar modes returned by option', function() {
var entryData = new p.SeedEntryData({
- storyline_configurations: {
- 10: {
- parent_page_perma_id: 101
+ storylines: [
+ {
+ id: 10,
+ configuration: {
+ parent_page_perma_id: 101
+ }
},
- 20: {
- parent_page_perma_id: 102,
+ {
+ id: 20,
+ configuration: {
+ parent_page_perma_id: 102,
+ }
},
- 30: {
- main: true
+ {
+ id: 30,
+ configuration: {
+ main: true
+ }
}
- },
+ ],
chapters: [
{id: 1, storyline_id: 10},
{id: 2, storyline_id: 20},
@@ -19,9 +19,12 @@ describe('pageflow.SeedEntryData', function() {
it('returns configruation by chapter id', function() {
var configuration = {};
var entryData = new p.SeedEntryData({
- storyline_configurations: {
- 1: configuration
- }
+ storylines: [
+ {
+ id: 1,
+ configuration: configuration
+ }
+ ]
});
var result = entryData.getStorylineConfiguration(1);

0 comments on commit 3cea263

Please sign in to comment.