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

Combine social and tiles #55

Merged
merged 25 commits into from Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1e691a2
stripped out grid item media queries to be handled by Theme locally
merefield Jan 27, 2019
488544d
fix typo
merefield Jan 27, 2019
e203a34
first commit
merefield Feb 13, 2019
7de54dd
merge in upstream master
merefield Feb 13, 2019
ecb1762
removed more social style logic, now tiles is functioning
merefield Feb 13, 2019
16a93c8
replaced missing Category logic
merefield Feb 13, 2019
254fe03
template refinements
merefield Feb 13, 2019
9f8874b
removed commented out code
merefield Feb 13, 2019
d3ea929
reduced calls to masonry and fixed mobile template bug
merefield Feb 13, 2019
3ce490d
moved topic badges for tiles so they appear next to title
merefield Feb 14, 2019
1c39e7f
merge of current PR
merefield Feb 14, 2019
896eecd
fix for wrong unless closer
merefield Feb 14, 2019
d66ae45
fixed typo in template
merefield Feb 14, 2019
7ca2af0
restored media queries
merefield Feb 14, 2019
2a09e65
updated title template to move badges next to title for tiles on mobile
merefield Feb 14, 2019
fa10538
renamed all .grid css to .tiles-grid to better differentiate
merefield Feb 15, 2019
590c895
removed social options from category settings, added tiles, simplifie…
merefield Feb 15, 2019
df6b9dd
remove unintended part of category settings code change
merefield Feb 15, 2019
e226d3b
NEW FEATURE: double sized tiles for featured Topics
merefield Feb 17, 2019
780c52c
Revert "NEW FEATURE: double sized tiles for featured Topics"
merefield Feb 18, 2019
1cd76b5
FIX: replace incorrect Masonry parameter
merefield Feb 18, 2019
7cbe8cb
restoring previous additional call to masonry as experimental fix to …
merefield Feb 19, 2019
8b7b9c7
Revert "restoring previous additional call to masonry as experimental…
merefield Feb 19, 2019
fb98ea0
removed unnecessary CSS for social view, added CSS additions from mas…
merefield Feb 28, 2019
7f2ce3b
fixed name of category setting on category settings dialogue code
merefield Feb 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,12 +1,7 @@
{{#if siteSettings.topic_list_previews_enabled}}
<section class='field'>
<label>{{i18n 'category.topic_list_social'}}</label>
{{list-setting settingValue=category.custom_fields.topic_list_social choices=choices settingName='category.topic_list_social'}}
</section>

<section class='field'>
<label>{{i18n 'category.topic_list_tiles'}}</label>
{{list-setting settingValue=category.custom_fields.topic_list_tiles choices=filteredChoices settingName='category.topic_list_tiles'}}
{{list-setting settingValue=category.custom_fields.topic_list_tiles choices=choices settingName='category.topic_list_tiles'}}
</section>

<section class='field'>
Expand Down
@@ -1,6 +1,6 @@

const listChoices = ['latest', 'new', 'unread', 'top', 'suggested', 'agenda', 'latest-mobile', 'new-mobile', 'unread-mobile', 'top-mobile', 'suggested-mobile', 'agenda-mobile'];
const listSettings = ['tiles', 'social', 'thumbnail', 'excerpt', 'action', 'category_column'];
const filterChoices = ['suggested', 'agenda', 'latest-mobile', 'new-mobile', 'unread-mobile','top-mobile', 'suggested-mobile', 'agenda-mobile'];
const listSettings = ['tiles', 'thumbnail', 'excerpt', 'action', 'category_column'];

export default {
setupComponent(args, component) {
Expand All @@ -16,9 +16,5 @@ export default {
}
});
component.set('choices', listChoices);

const filteredChoices = listChoices.filter(c => (filterChoices.indexOf(c) === -1));

component.set('filteredChoices', filteredChoices);
}
};
104 changes: 30 additions & 74 deletions assets/javascripts/discourse/initializers/preview-edits.js.es6
Expand Up @@ -16,13 +16,11 @@ export default {
api.modifyClass('component:topic-list', {
router: Ember.inject.service('-routing'),
currentRoute: Ember.computed.alias('router.router.currentRouteName'),
classNameBindings: ['showThumbnail', 'showExcerpt', 'showActions', 'socialStyle', 'tilesStyle'],
classNameBindings: ['showThumbnail', 'showExcerpt', 'showActions', 'tilesStyle'],
suggestedList: Ember.computed.equal('parentView.parentView.parentView.elementId', 'suggested-topics'),
discoveryList: Ember.computed.equal('parentView._debugContainerKey', 'component:discovery-topics-list'),
listChanged: false,

// Lifecyle logic

@on('init')
setup() {
const suggestedList = this.get('suggestedList');
Expand All @@ -32,11 +30,11 @@ export default {
};
},

@on('didRender')
completeRender(){
if (this.get('tilesStyle')){
Ember.run.scheduleOnce('afterRender', this, this.applyMasonry);
};
@on('didRender')
completeRender(){
if (this.get('tilesStyle')){
Ember.run.scheduleOnce('afterRender', this, this.applyMasonry);
};
},

@on('didInsertElement')
Expand All @@ -46,24 +44,22 @@ export default {
},

@on('didInsertElement')
@observes('socialStyle','tilesStyle')
@observes('tilesStyle')
setupListStyle() {
if (!this.$()) {return;}
this.$().parents('#list-area').toggleClass('social-style', this.get('socialStyle'));
if (this.get('tilesStyle')){
this.$().parents('#list-area').toggleClass('tiles-style', true);
this.$("tbody").toggleClass('grid', true);
if ( !this.$( ".grid-sizer" ).length) {
this.$(".grid").prepend("<div class='grid-sizer'></div><div class='gutter-sizer'></div>");
this.$("tbody").toggleClass('tiles-grid', true);
if ( !this.$( ".tiles-grid-sizer" ).length) {
this.$(".tiles-grid").prepend("<div class='tiles-grid-sizer'></div><div class='tiles-gutter-sizer'></div>");
};
}
},

@on('willDestroyElement')
_tearDown() {
this.$().parents('#list-area').removeClass('social-style');
this.$().parents('#list-area').removeClass('tiles-style');
this.$("tbody").removeClass('grid');
this.$("tbody").removeClass('tiles-grid');
},

filter() {
Expand Down Expand Up @@ -105,21 +101,11 @@ export default {
return category ? (catEnabled || siteDefaults && siteEnabled) : siteEnabled;
},

@computed('listChanged')
socialStyle() {
return this.settingEnabled('topic_list_social');
},

@computed('listChanged')
tilesStyle() {
return this.settingEnabled('topic_list_tiles');
},

@computed('listChanged')
tilesOrSocial() {
return (this.get('tilesStyle') || this.get('socialStyle'));
},

@computed('listChanged')
showThumbnail() {
return this.settingEnabled('topic_list_thumbnail');
Expand All @@ -136,10 +122,10 @@ export default {
},

@computed('listChanged')
showCategoryBadge() {
return !this.settingEnabled('topic_list_category_column') &&
(!this.get('category') || this.get('category.has_children'));
},
showCategoryBadge() {
return !this.settingEnabled('topic_list_category_column') &&
(!this.get('category') || this.get('category.has_children'));
},

@observes('showCategoryBadge', 'hideCategory')
toggleHideCategory() {
Expand All @@ -150,59 +136,49 @@ export default {

@computed('listChanged')
skipHeader() {
return this.get('tilesStyle') || this.get('socialStyle') || this.get('site.mobileView');
return this.get('tilesStyle') || this.get('site.mobileView');
},

@computed('listChanged')
thumbnailFirstXRows() {
return Discourse.SiteSettings.topic_list_thumbnail_first_x_rows;
},

// don't forget to update masonry layout when required
@observes('topics.[]')
masonryObserver() {
if (this.get('tilesStyle')){
Ember.run.scheduleOnce('afterRender', this, this.applyMasonry);
}
},

applyMasonry() {
// initialize
let msnry = this.$('.grid').data('masonry');
let msnry = this.$('.tiles-grid').data('masonry');

if (msnry) {
msnry.reloadItems();
//disable transition
var transitionDuration = msnry.options.transitionDuration;
msnry.options.transitionDuration = 0;
$('.grid').imagesLoaded(function() {msnry.layout()});
$('.tiles-grid').imagesLoaded(function() {msnry.layout()});
//reset transition
msnry.options.transitionDuration = transitionDuration;
} else {
// init masonry
// transition set to zero on mobile due to undesirable behaviour on mobile safari if > 0
const transDuration = this.get('site.mobileView') ? 0 : Discourse.SiteSettings.topic_list_tiles_transition_time;
this.$('.grid').masonry({
itemSelector: '.grid-item',
this.$('.tiles-grid').masonry({
itemSelector: '.tiles-grid-item',
transitionDuration: `${transDuration}s`,
percentPosition: true,
Width: '.grid-sizer',
gutter: '.gutter-sizer'
columnWidth: '.tiles-grid-sizer',
gutter: '.tiles-gutter-sizer'
});

msnry = this.$('.grid').data('masonry');
msnry = this.$('.tiles-grid').data('masonry');

$('.grid').imagesLoaded(function() {msnry.layout()});
$('.tiles-grid').imagesLoaded(function() {msnry.layout()});
};
}
});

api.modifyClass('component:topic-list-item', {
canBookmark: Ember.computed.bool('currentUser'),
rerenderTriggers: ['bulkSelectEnabled', 'topic.pinned', 'likeDifference', 'topic.thumbnails'],
socialStyle: Ember.computed.alias('parentView.socialStyle'),
tilesStyle: Ember.computed.alias('parentView.tilesStyle'),
tilesOrSocial: Ember.computed.alias('parentView.tilesOrSocial'),
showThumbnail: Ember.computed.and('thumbnails', 'parentView.showThumbnail'),
showExcerpt: Ember.computed.and('topic.excerpt', 'parentView.showExcerpt'),
showActions: Ember.computed.alias('parentView.showActions'),
Expand All @@ -221,7 +197,7 @@ export default {
if (this.get('tilesStyle')) {
// needs 'div's for masonry
this.set('tagName', 'div');
this.classNames = ['grid-item'];
this.classNames = ['tiles-grid-item'];
};

if (thumbnails) {
Expand Down Expand Up @@ -253,44 +229,25 @@ export default {
if (topic.get('thumbnails') && this.get('thumbnailFirstXRows') && (this.$().index() > this.get('thumbnailFirstXRows'))) {
this.set('showThumbnail', false);
}

this._afterRender();
},

@on('didRender')
@observes('thumbnails')
_afterRender() {
Ember.run.scheduleOnce('afterRender', this, () => {
this._setupTitleCSS();
if (this.get('showThumbnail') && (this.get('socialStyle') )) {
this._sizeThumbnails();
}
if (this.get('showExcerpt') && !this.get('tilesStyle')) {
this._setupExcerptClick();
}
if (this.get('showActions')) {
this._setupActions();
}
if (this.get('tilesStyle')) {
var myid = this.$().attr('id');
$(`#${myid} > .topic-title`).wrap("<div class='topic-header-grid'></div>");
$(`#${myid} .topic-users`).appendTo(`#${myid} .topic-header-grid`);
$(`#${myid} .topic-category`).appendTo(`#${myid} .topic-header-grid`);
$(`#${myid} .topic-category`).removeClass('inline').removeClass('sub');
$(`#${myid} .topic-actions`).unwrap(`#${myid} .main-link-footer`);
$(`#${myid} .discourse-tags`).insertAfter(`#${myid} .topic-details`);
$(`#${myid} .discourse-tags`).wrap("<div class='topic-tags'></div>");
$(`#${myid} .topic-meta`).insertAfter(`#${myid} .topic-tags`);
$(`#${myid} .topic-views`).prevAll().remove();
$(`#${myid} .topic-actions`).appendTo(`#${myid}`);
}
});
},

_setupTitleCSS() {
let $el = this.$('.topic-title a.visited');
if ($el) {
$el.closest('.topic-details').addClass('visited');
}
this.$('.topic-title a.visited').closest('.topic-details').addClass('visited');
},

_setupExcerptClick() {
Expand Down Expand Up @@ -378,11 +335,10 @@ export default {
return getDefaultThumbnail(category);
},

@computed('tilesStyle', 'socialStyle', 'thumbnailWidth', 'thumbnailHeight')
thumbnailOpts(tilesStyle, socialStyle, thumbnailWidth, thumbnailHeight) {
@computed('tilesStyle', 'thumbnailWidth', 'thumbnailHeight')
thumbnailOpts(tilesStyle, thumbnailWidth, thumbnailHeight) {
let opts = {
tilesStyle,
socialStyle,
tilesStyle
}

if (thumbnailWidth) {
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/discourse/lib/utilities.js.es6
Expand Up @@ -34,7 +34,7 @@ var renderUnboundPreview = function(thumbnails, params) {
};

const settings = Discourse.SiteSettings;
const attrPrefix = opts.socialStyle ? 'max-' : '';
const attrPrefix = '';
const attrWidthSuffix = opts.tilesStyle ? '%' : 'px';
const attrHeightSuffix = opts.tilesStyle ? '' : 'px';
const css_classes = opts.tilesStyle? 'thumbnail tiles-thumbnail' : 'thumbnail';
Expand Down
29 changes: 16 additions & 13 deletions assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs
Expand Up @@ -5,16 +5,23 @@
{{/if}}

<td class='main-link clearfix' colspan="{{titleColSpan}}">
{{#if tilesOrSocial}}
{{raw "list/topic-list-title" topic=topic tilesOrSocial=tilesOrSocial tilesStyle=tilesStyle socialStyle=socialStyle showTopicPostBadges=showTopicPostBadges}}
{{#if tilesStyle}}
<div class="topic-header-grid">
{{raw "list/topic-list-title" topic=topic tilesStyle=tilesStyle showTopicPostBadges=showTopicPostBadges}}
<div class="topic-category">
{{#if showCategoryBadge}}
{{category-link topic.category}}
{{/if}}
</div>
</div>
{{/if}}

{{#if showThumbnail}}
{{raw "list/topic-thumbnail" topic=topic thumbnails=thumbnails category=category opts=thumbnailOpts}}
{{/if}}

<div class="topic-details">
{{#unless tilesOrSocial}}
{{#unless tilesStyle}}
{{raw "list/topic-list-title"
topic=topic
showTopicPostBadges=showTopicPostBadges
Expand All @@ -34,29 +41,25 @@
{{raw "list/topic-excerpt" topic=topic}}
{{/if}}

{{#unless tilesOrSocial}}
</div>
{{#unless tilesStyle}}
<div class="actions-and-meta-data">
{{#if showActions}}
{{raw "list/topic-actions" likeCount=likeCount topicActions=topicActions}}
{{/if}}
{{raw "list/action-list" topic=topic postNumbers=topic.liked_post_numbers className="likes" icon="heart"}}
</div>
{{/unless}}
</div>

{{#if tilesOrSocial}}
<div class="main-link-footer">
{{#if tilesStyle}}
</div>
{{raw 'list/topic-meta' likesHeat=likesHeat title=view.title topic=topic}}
{{#if showActions}}
{{raw "list/topic-actions" likeCount=likeCount topicActions=topicActions}}
{{/if}}
{{raw-plugin-outlet name="topic-list-main-link-footer"}}
{{raw 'list/topic-meta' likesHeat=likesHeat title=view.title topic=topic}}
</div>
{{/if}}
{{/if}}
</td>

{{#unless tilesOrSocial}}
{{#unless tilesStyle}}
{{#if showCategoryColumn}}
{{raw "list/category-column" category=topic.category}}
{{/if}}
Expand Down
Expand Up @@ -3,27 +3,37 @@
{{raw-plugin-outlet name="topic-list-before-status"}}
{{raw "topic-status" topic=topic}}
{{topic-link topic}}
{{#if tilesStyle}}
{{#if mobileView}}
{{#if topic.unseen}}
<span class="badge-notification new-topic"></span>
{{/if}}
{{else}}
{{#if showTopicPostBadges}}
{{raw "topic-post-badges" unread=topic.unread newPosts=topic.displayNewPosts unseen=topic.unseen url=topic.lastUnreadUrl}}
{{/if}}
{{/if}}
{{/if}}

{{#if topic.featured_link}}
{{topic-featured-link topic}}
{{/if}}

{{#if mobileView}}
{{#if topic.unseen}}
<span class="badge-notification new-topic"></span>
{{#unless tilesStyle}}
{{#if mobileView}}
{{#if topic.unseen}}
<span class="badge-notification new-topic"></span>
{{/if}}
{{else}}
{{#if showTopicPostBadges}}
{{raw "topic-post-badges" unread=topic.unread newPosts=topic.displayNewPosts unseen=topic.unseen url=topic.lastUnreadUrl}}
{{/if}}
{{/if}}
{{else}}
{{#if showTopicPostBadges}}
{{raw "topic-post-badges" unread=topic.unread newPosts=topic.displayNewPosts unseen=topic.unseen url=topic.lastUnreadUrl}}
{{/if}}
{{/if}}

{{#unless tilesOrSocial}}
{{raw-plugin-outlet name="topic-list-after-title"}}
{{/unless}}
</span>

{{#if tilesOrSocial}}
{{raw "list/topic-users" topic=topic posterNames=posterNames}}
{{/if}}
{{raw-plugin-outlet name="topic-list-after-title"}}
</span>
</div>
{{#if tilesStyle}}
{{raw "list/topic-users" tilesStyle=tilesStyle topic=topic posterNames=posterNames}}
{{/if}}