Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Entry theme selection #764

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1610f04
Integrate themes with features
aviav Mar 15, 2017
c750128
Use more specific config where needed
aviav Mar 16, 2017
3ff4194
Adjust specs to themes as features
aviav Mar 16, 2017
490d835
Test that themes registered in disabled features cannot be used
aviav May 19, 2017
805bdeb
Placate Hound
aviav May 22, 2017
6b317c6
Add theme name to revisions on database
aviav Mar 15, 2017
0191ddb
On creating an entry, set theme_name on its revision
aviav Mar 15, 2017
20e061e
Add preview_image_path theme attribute
aviav Mar 14, 2017
f6b0c4e
Add themes to editor seeds
aviav Mar 14, 2017
28fcd49
Add theme_name to PublishedEntry
aviav May 5, 2017
cb2f6d2
Add default images to theme generator
aviav May 29, 2017
9829d74
Make selectable themes a feature to keep API intact
aviav May 29, 2017
49c183c
Make themes as features configurable per entry
aviav May 30, 2017
a7454ed
Include themes according to entry config in their own seed section
aviav Mar 16, 2017
0cbfb5b
Add current theme name and button to appearance tab
aviav Mar 17, 2017
4a5c064
Add current theme name to entry seed and config
aviav Mar 17, 2017
75e73a7
Add styling
aviav Apr 10, 2017
cbf594b
Add theme picker dialog
aviav Apr 10, 2017
b125db7
Add hover and select functionality
aviav Apr 10, 2017
9c2be51
Update stylesheet when theme is picked
aviav Apr 10, 2017
6ed1829
Set up themes for editor
aviav Apr 10, 2017
bb7943a
Fix typos
aviav Apr 10, 2017
2f0b93f
Rework styling
aviav Apr 10, 2017
12a7420
Update chosen theme in ChangeThemeView on theme change
aviav May 11, 2017
7ad88be
Introduce editor model and collection for themes
aviav May 12, 2017
f43c7ba
Use Backbone `get` instead of reaching into attributes
aviav May 12, 2017
559e197
Refactor stylesheet utils
aviav May 12, 2017
ad29bd3
Display labelText current value in separate element
aviav May 12, 2017
03d7478
Reuse ReferenceInputView and ModelThumbnailView
aviav May 18, 2017
8724482
Fix page title hysteresis
aviav May 18, 2017
98fb650
Introduce dedicated preview thumbnails for themes
aviav May 23, 2017
36ad364
Add editor specs
aviav May 28, 2017
8684d9e
Add inline documentation to ReferenceInputView#chooseValue
aviav May 29, 2017
9c87845
Allow changing themes if selectable themes are enabled
aviav May 29, 2017
efb03b7
Add some inline documentation to ReferenceInputView
aviav May 29, 2017
936ea61
Use theming factory in updated specs
aviav May 30, 2017
d83ec1a
Introduce dedicated preview thumbnails for themes
aviav May 23, 2017
7e45b84
Add default image assets to default theme
aviav May 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion app/assets/javascripts/pageflow/editor/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pageflow.EditorApi = pageflow.Object.extend(
this.failures = new pageflow.FailuresAPI();

/**
* Setup editor integration for page types.
* Set up editor integration for page types.
* @alias pageTypes
* @memberof module:pageflow/editor.pageflow.editor
*/
Expand All @@ -37,6 +37,7 @@ pageflow.EditorApi = pageflow.Object.extend(
/**
* @alias fileTypes
* @memberof module:pageflow/editor.pageflow.editor
* Set up editor integration for file types
*/
this.fileTypes = new pageflow.FileTypes();
},
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/pageflow/editor/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
//= require ./initializers/setup_page_types
//= require ./initializers/setup_hotkeys
//= require ./initializers/setup_file_uploader
//= require ./initializers/setup_themes
//= require ./initializers/edit_lock
//= require ./initializers/files_polling
//= require ./initializers/stylesheet_reloading
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pageflow.ThemesCollection = Backbone.Collection.extend({
model: pageflow.Theme,

findByName: function(name) {
return this.findWhere({name: name});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pageflow.app.addInitializer(function(options) {
pageflow.editor.themes = new pageflow.ThemesCollection(options.themes);
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
pageflow.app.addInitializer(function(options) {
pageflow.entry.on('change:pending_files_count', function(model, value) {
if (value < pageflow.entry.previous('pending_files_count')) {
pageflow.reloadStylesheet('entry');
pageflow.stylesheet.reload('entry');
}
});

pageflow.entry.on('use:files', function() {
pageflow.reloadStylesheet('entry');
pageflow.stylesheet.reload('entry');
});
});
});
4 changes: 3 additions & 1 deletion app/assets/javascripts/pageflow/editor/models/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ pageflow.Page = Backbone.Model.extend({
},

title: function() {
return this.configuration.get('title') || this.configuration.get('additional_title');
return this.configuration.get('title') ||
this.configuration.get('additional_title') ||
'';
},

thumbnailFile: function() {
Expand Down
13 changes: 13 additions & 0 deletions app/assets/javascripts/pageflow/editor/models/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pageflow.Theme = Backbone.Model.extend({
initialize: function(attributes, options) {
this.options = options || {};
},

title: function() {
return I18n.t('pageflow.' + this.get('name') + '_theme.name');
},

thumbnailUrl: function() {
return this.options.thumbnailUrl || this.get('preview_thumbnail_url');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="box">
<div class="content">
<div>
<h2 class="themes_header"><%= I18n.t('pageflow.editor.templates.change_theme_dialog.header') %></h2>
<div class="themes_panel">
</div>
<div class="preview_panel">
<h2 class="preview_header"><%= I18n.t('pageflow.editor.templates.change_theme_dialog.preview_header_prefix') %>
<span class="preview_header_theme_name"></span><%= I18n.t('pageflow.editor.templates.change_theme_dialog.preview_header_suffix') %>
</h2>
<div class="preview_image_region">
<img class="preview_image" src="default_template.png">
</div>
</div>
</div>
</div>

<div class="footer">
<a href="" class="close">
<%= I18n.t('pageflow.editor.templates.change_theme_dialog.close') %>
</a>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<span class="theme_name"></span>
<span class="button_or_checkmark">
<p class="theme_in_use"></p>
<a class="use_theme"><%= I18n.t('pageflow.editor.templates.theme.use') %></a>
</span>

This file was deleted.

23 changes: 23 additions & 0 deletions app/assets/javascripts/pageflow/editor/utils/stylesheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pageflow.stylesheet = {
reload: function(name) {
var link = this.selectLink(name);

if (!link.data('originalHref')) {
link.data('originalHref', link.attr('href'));
}

link.attr('href', link.data('originalHref') + '&reload=' + new Date().getTime());
},

update: function(name, stylesheetPath) {
var link = this.selectLink(name);

if (link.attr('href') !== stylesheetPath) {
link.attr('href', stylesheetPath);
}
},

selectLink: function(name) {
return $('head link[data-name=' + name + ']');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
pageflow.ChangeThemeDialogView = Backbone.Marionette.ItemView.extend({
template: 'templates/change_theme_dialog',
className: 'change_theme dialog editor',

mixins: [pageflow.dialogView],

ui: {
content: '.content',
themesPanel: '.themes_panel',
previewImageRegion: '.preview_image_region',
previewImage: '.preview_image',
previewHeaderThemeName: '.preview_header_theme_name'
},

initialize: function(options) {
this.listenTo(this.model, 'change', this.update);
this.selection = new Backbone.Model();
var themeInUse = this.options.themes.findByName(pageflow.entry.configuration.get('theme_name'));
this.selection.set('theme', themeInUse);
this.listenTo(this.selection, 'change:theme', function() {
if (!this.selection.get('theme')) {
this.selection.set('theme', themeInUse);
}
this.update();
});
},

onRender: function() {
this.themesView = new pageflow.CollectionView({
collection: this.options.themes,
tagName: 'ul',
itemViewConstructor: pageflow.ThemeItemView,
itemViewOptions: {
configuration: this.model,
selection: this.selection,
onUse: this.options.onUse
}
});

this.ui.themesPanel.append(this.subview(this.themesView).el);

this.update();
},

update: function() {
var that = this;
var selectedTheme = this.options.themes.findByName(that.selection.get('theme').get('name'));
this.ui.previewImage.attr('src', selectedTheme.get('preview_image_url'));
this.ui.previewHeaderThemeName.text(that.translateThemeName({
name: selectedTheme.get('name')
}));
},

translateThemeName: function(options) {
var name = options.name;
return I18n.t('pageflow.' + name + '_theme.name');
}
});

pageflow.ChangeThemeDialogView.changeTheme = function(options) {
return $.Deferred(function(deferred) {
options.onUse = function() {
deferred.resolve(this.model);
};

var view = new pageflow.ChangeThemeDialogView(options);

view.on('close', function() {
deferred.reject();
});

pageflow.app.dialogRegion.show(view.render());
}).promise();
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pageflow.EditMetaDataView = Backbone.Marionette.Layout.extend({

configurationEditor.tab('general', function() {
this.input('title', pageflow.TextInputView, {
placeholder: entry.attributes.entry_title
placeholder: entry.get('entry_title')
});
this.input('locale', pageflow.SelectInputView, {
values: pageflow.config.availablePublicLocales,
Expand Down Expand Up @@ -68,6 +68,14 @@ pageflow.EditMetaDataView = Backbone.Marionette.Layout.extend({
model: entry,
widgetTypes: pageflow.editor.widgetTypes
});
if (pageflow.features.isEnabled('selectable_themes') &&
pageflow.editor.themes.length > 1) {
this.view(pageflow.ThemeInputView, {
themes: pageflow.editor.themes,
propertyName: 'theme_name',
hideUnsetButton: true
});
}
});

configurationEditor.tab('social', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pageflow.ReferenceInputView = Backbone.Marionette.ItemView.extend(
'click .choose': function() {
var view = this;

this.choose().then(function(site) {
view.model.set(view.options.propertyName, site.get('perma_id'));
this.chooseValue().then(function(id) {
view.model.set(view.options.propertyName, id);
});

return false;
Expand All @@ -44,11 +44,26 @@ pageflow.ReferenceInputView = Backbone.Marionette.ItemView.extend(
this.listenTo(this.model, 'change:' + this.options.propertyName, this.update);
},

/**
* Returns a promise for some identifying attribute.
*
* Default attribute name is perma_id. If the attribute is named
* differently, you can have your specific ReferenceInputView
* implement `chooseValue()` accordingly.
*
* Will be used to set the chosen Model for this View.
*/
chooseValue: function() {
return this.choose().then(function(model) {
return model.get('perma_id');
});
},

choose: function() {
throw 'Not implemented: Override ReferenceInputView#choose to return a promise';
},

getTarget: function() {
getTarget: function(targetId) {
throw 'Not implemented: Override ReferenceInputView#getTarget';
},

Expand All @@ -62,7 +77,7 @@ pageflow.ReferenceInputView = Backbone.Marionette.ItemView.extend(
var target = this.getTarget(this.model.get(this.options.propertyName));

this.ui.title.text(target ? target.title() : I18n.t('pageflow.editor.views.inputs.reference_input_view.none'));
this.ui.unsetButton.toggle(!!target);
this.ui.unsetButton.toggle(!!target && !this.options.hideUnsetButton);

this.updateDisabledAttribute(this.ui.buttons);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pageflow.ThemeInputView = pageflow.ReferenceInputView.extend({
choose: function() {
return pageflow.ChangeThemeDialogView.changeTheme({
model: this.model,
themes: this.options.themes
});
},

chooseValue: function() {
return this.choose().then(function(model) {
return model.get('name');
});
},

getTarget: function(themeName) {
return this.options.themes.findByName(themeName);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,37 @@ pageflow.ModelThumbnailView = Backbone.Marionette.View.extend({
},

update: function() {
var file = this.model && this.model.thumbnailFile();

if (this.fileThumbnailView && this.currentFileThumbnail == file) {
return;
if (this.model) {
if (_.isFunction(this.model.thumbnailFile)) {
var file = this.model && this.model.thumbnailFile();

if (this.thumbnailView && this.currentFileThumbnail == file) {
return;
}

this.currentFileThumbnail = file;

this.newThumbnailView = new pageflow.FileThumbnailView({
model: file,
className: 'thumbnail file_thumbnail',
imageUrlPropertyName: this.options.imageUrlPropertyName
});
}
else {
this.newThumbnailView = new pageflow.StaticThumbnailView({
model: this.model
});
}
}

this.currentFileThumbnail = file;

if (this.fileThumbnailView) {
this.fileThumbnailView.close();
if (this.thumbnailView) {
this.thumbnailView.close();
}

this.fileThumbnailView = this.subview(new pageflow.FileThumbnailView({
model: file,
className: 'thumbnail file_thumbnail',
imageUrlPropertyName: this.options.imageUrlPropertyName
}));
if (this.model) {
this.thumbnailView = this.subview(this.newThumbnailView);

this.$el.append(this.fileThumbnailView.el);
this.$el.append(this.thumbnailView.el);
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pageflow.StaticThumbnailView = Backbone.Marionette.ItemView.extend({
template: 'templates/static_thumbnail',
className: 'static_thumbnail',

onRender: function() {
this.update();
},

update: function() {
this.$el.css('background-image', 'url(' + this._imageUrl() + ')');
},

_imageUrl: function() {
return this.model.thumbnailUrl();
}
});
Loading