mirror of
https://github.com/discourse/discourse.git
synced 2025-03-23 17:15:43 +08:00
Merge branch 'vdom'
This commit is contained in:
commit
ee1aec6766
@ -90,6 +90,7 @@
|
|||||||
"no-undef": 2,
|
"no-undef": 2,
|
||||||
"no-unused-vars": 2,
|
"no-unused-vars": 2,
|
||||||
"no-with": 2,
|
"no-with": 2,
|
||||||
|
"no-this-before-super": 2,
|
||||||
"semi": 2,
|
"semi": 2,
|
||||||
"strict": 0,
|
"strict": 0,
|
||||||
"valid-typeof": 2,
|
"valid-typeof": 2,
|
||||||
|
@ -152,21 +152,20 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
function proxyDep(propName, moduleFunc, msg) {
|
function RemovedObject(name) {
|
||||||
if (Discourse.hasOwnProperty(propName)) { return; }
|
this._removedName = name;
|
||||||
Object.defineProperty(Discourse, propName, {
|
|
||||||
get: function() {
|
|
||||||
msg = msg || "import the module";
|
|
||||||
Ember.warn("DEPRECATION: `Discourse." + propName + "` is deprecated, " + msg + ".");
|
|
||||||
return moduleFunc();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyDep('computed', function() { return require('discourse/lib/computed'); });
|
function methodMissing() {
|
||||||
proxyDep('Formatter', function() { return require('discourse/lib/formatter'); });
|
console.warn("The " + this._removedName + " object has been removed from Discourse " +
|
||||||
proxyDep('PageTracker', function() { return require('discourse/lib/page-tracker').default; });
|
"and your plugin needs to be updated.");
|
||||||
proxyDep('URL', function() { return require('discourse/lib/url').default; });
|
};
|
||||||
proxyDep('Quote', function() { return require('discourse/lib/quote').default; });
|
|
||||||
proxyDep('debounce', function() { return require('discourse/lib/debounce').default; });
|
Discourse.RemovedObject = RemovedObject;
|
||||||
proxyDep('View', function() { return Ember.View; }, "Use `Ember.View` instead");
|
|
||||||
|
['reopen', 'registerButton', 'on', 'off'].forEach(function(m) { RemovedObject.prototype[m] = methodMissing; });
|
||||||
|
|
||||||
|
['discourse/views/post', 'discourse/components/post-menu'].forEach(function(moduleName) {
|
||||||
|
define(moduleName, [], function() { return new RemovedObject(moduleName); });
|
||||||
|
});
|
||||||
|
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
import RestAdapter from 'discourse/adapters/rest';
|
||||||
|
|
||||||
|
export default RestAdapter.extend({
|
||||||
|
find(store, type, findArgs) {
|
||||||
|
const maxReplies = Discourse.SiteSettings.max_reply_history;
|
||||||
|
return Discourse.ajax(`/posts/${findArgs.postId}/reply-history?max_replies=${maxReplies}`).then(replies => {
|
||||||
|
return { post_reply_histories: replies };
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@ -0,0 +1,9 @@
|
|||||||
|
import RestAdapter from 'discourse/adapters/rest';
|
||||||
|
|
||||||
|
export default RestAdapter.extend({
|
||||||
|
find(store, type, findArgs) {
|
||||||
|
return Discourse.ajax(`/posts/${findArgs.postId}/replies`).then(replies => {
|
||||||
|
return { post_replies: replies };
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@ -1,122 +0,0 @@
|
|||||||
import StringBuffer from 'discourse/mixins/string-buffer';
|
|
||||||
import { iconHTML } from 'discourse/helpers/fa-icon';
|
|
||||||
import { autoUpdatingRelativeAge } from 'discourse/lib/formatter';
|
|
||||||
import { on } from 'ember-addons/ember-computed-decorators';
|
|
||||||
|
|
||||||
export default Ember.Component.extend(StringBuffer, {
|
|
||||||
tagName: 'section',
|
|
||||||
classNameBindings: [':post-actions', 'hidden'],
|
|
||||||
actionsSummary: Em.computed.alias('post.actionsWithoutLikes'),
|
|
||||||
emptySummary: Em.computed.empty('actionsSummary'),
|
|
||||||
hidden: Em.computed.and('emptySummary', 'post.notDeleted'),
|
|
||||||
usersByType: null,
|
|
||||||
|
|
||||||
rerenderTriggers: ['actionsSummary.@each', 'post.deleted'],
|
|
||||||
|
|
||||||
@on('init')
|
|
||||||
initUsersByType() {
|
|
||||||
this.set('usersByType', {});
|
|
||||||
},
|
|
||||||
|
|
||||||
// This was creating way too many bound ifs and subviews in the handlebars version.
|
|
||||||
renderString(buffer) {
|
|
||||||
const usersByType = this.get('usersByType');
|
|
||||||
|
|
||||||
if (!this.get('emptySummary')) {
|
|
||||||
this.get('actionsSummary').forEach(function(c) {
|
|
||||||
const id = c.get('id');
|
|
||||||
const users = usersByType[id] || [];
|
|
||||||
|
|
||||||
buffer.push("<div class='post-action'>");
|
|
||||||
|
|
||||||
const renderLink = (dataAttribute, text) => {
|
|
||||||
buffer.push(` <span class='action-link ${dataAttribute}-action'><a href data-${dataAttribute}='${id}'>${text}</a>.</span>`);
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO multi line expansion for flags
|
|
||||||
let iconsHtml = "";
|
|
||||||
if (users.length) {
|
|
||||||
let postUrl;
|
|
||||||
users.forEach(function(u) {
|
|
||||||
const username = u.get('username');
|
|
||||||
|
|
||||||
iconsHtml += `<a href="${Discourse.getURL("/users")}${username}" data-user-card="${username}">`;
|
|
||||||
if (u.post_url) {
|
|
||||||
postUrl = postUrl || u.post_url;
|
|
||||||
}
|
|
||||||
iconsHtml += Discourse.Utilities.avatarImg({
|
|
||||||
size: 'small',
|
|
||||||
avatarTemplate: u.get('avatar_template'),
|
|
||||||
title: u.get('username')
|
|
||||||
});
|
|
||||||
iconsHtml += "</a>";
|
|
||||||
});
|
|
||||||
|
|
||||||
let key = 'post.actions.people.' + c.get('actionType.name_key');
|
|
||||||
if (postUrl) { key = key + "_with_url"; }
|
|
||||||
|
|
||||||
// TODO postUrl might be uninitialized? pick a good default
|
|
||||||
buffer.push(" " + I18n.t(key, { icons: iconsHtml, postUrl }) + ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (users.length === 0) {
|
|
||||||
renderLink('who-acted', c.get('description'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c.get('can_undo')) {
|
|
||||||
renderLink('undo', I18n.t("post.actions.undo." + c.get('actionType.name_key')));
|
|
||||||
}
|
|
||||||
if (c.get('can_defer_flags')) {
|
|
||||||
renderLink('defer-flags', I18n.t("post.actions.defer_flags", { count: c.count }));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
buffer.push("</div>");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const post = this.get('post');
|
|
||||||
if (post.get('deleted')) {
|
|
||||||
buffer.push("<div class='post-action'>" +
|
|
||||||
iconHTML('fa-trash-o') + ' ' +
|
|
||||||
Discourse.Utilities.tinyAvatar(post.get('postDeletedBy.avatar_template'), {title: post.get('postDeletedBy.username')}) +
|
|
||||||
autoUpdatingRelativeAge(new Date(post.get('postDeletedAt'))) +
|
|
||||||
"</div>");
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.push("<div class='clearfix'></div>");
|
|
||||||
},
|
|
||||||
|
|
||||||
actionTypeById(actionTypeId) {
|
|
||||||
return this.get('actionsSummary').findProperty('id', actionTypeId);
|
|
||||||
},
|
|
||||||
|
|
||||||
click(e) {
|
|
||||||
const $target = $(e.target);
|
|
||||||
let actionTypeId;
|
|
||||||
|
|
||||||
const post = this.get('post');
|
|
||||||
|
|
||||||
if (actionTypeId = $target.data('defer-flags')) {
|
|
||||||
this.actionTypeById(actionTypeId).deferFlags(post);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// User wants to know who actioned it
|
|
||||||
const usersByType = this.get('usersByType');
|
|
||||||
if (actionTypeId = $target.data('who-acted')) {
|
|
||||||
this.actionTypeById(actionTypeId).loadUsers(post).then(users => {
|
|
||||||
usersByType[actionTypeId] = users;
|
|
||||||
this.rerender();
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actionTypeId = $target.data('undo')) {
|
|
||||||
this.get('actionsSummary').findProperty('id', actionTypeId).undo(post);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
@ -12,8 +12,8 @@ export default Ember.Component.extend({
|
|||||||
return !c.get('parentCategory');
|
return !c.get('parentCategory');
|
||||||
}),
|
}),
|
||||||
|
|
||||||
hidden: function(){
|
hidden: function() {
|
||||||
return Discourse.Mobile.mobileView && !this.get('category');
|
return this.site.mobileView && !this.get('category');
|
||||||
}.property('category'),
|
}.property('category'),
|
||||||
|
|
||||||
firstCategory: function() {
|
firstCategory: function() {
|
||||||
|
@ -18,7 +18,7 @@ export default Ember.Component.extend({
|
|||||||
|
|
||||||
@on('init')
|
@on('init')
|
||||||
_setupPreview() {
|
_setupPreview() {
|
||||||
const val = (Discourse.Mobile.mobileView ? false : (this.keyValueStore.get('composer.showPreview') || 'true'));
|
const val = (this.site.mobileView ? false : (this.keyValueStore.get('composer.showPreview') || 'true'));
|
||||||
this.set('showPreview', val === 'true');
|
this.set('showPreview', val === 'true');
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -91,6 +91,8 @@ export default Ember.Component.extend({
|
|||||||
|
|
||||||
_syncEditorAndPreviewScroll() {
|
_syncEditorAndPreviewScroll() {
|
||||||
const $input = this.$('.d-editor-input');
|
const $input = this.$('.d-editor-input');
|
||||||
|
if (!$input) { return; }
|
||||||
|
|
||||||
const $preview = this.$('.d-editor-preview');
|
const $preview = this.$('.d-editor-preview');
|
||||||
|
|
||||||
if ($input.scrollTop() === 0) {
|
if ($input.scrollTop() === 0) {
|
||||||
@ -216,7 +218,7 @@ export default Ember.Component.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Discourse.Mobile.mobileView) {
|
if (this.site.mobileView) {
|
||||||
this.$(".mobile-file-upload").on("click.uploader", function () {
|
this.$(".mobile-file-upload").on("click.uploader", function () {
|
||||||
// redirect the click on the hidden file input
|
// redirect the click on the hidden file input
|
||||||
$("#mobile-uploader").click();
|
$("#mobile-uploader").click();
|
||||||
|
@ -25,156 +25,164 @@ const OP = {
|
|||||||
|
|
||||||
const _createCallbacks = [];
|
const _createCallbacks = [];
|
||||||
|
|
||||||
function Toolbar() {
|
class Toolbar {
|
||||||
this.shortcuts = {};
|
|
||||||
|
|
||||||
this.groups = [
|
constructor(site) {
|
||||||
{group: 'fontStyles', buttons: []},
|
this.shortcuts = {};
|
||||||
{group: 'insertions', buttons: []},
|
|
||||||
{group: 'extras', buttons: []}
|
|
||||||
];
|
|
||||||
|
|
||||||
this.addButton({
|
this.groups = [
|
||||||
id: 'bold',
|
{group: 'fontStyles', buttons: []},
|
||||||
group: 'fontStyles',
|
{group: 'insertions', buttons: []},
|
||||||
shortcut: 'B',
|
{group: 'extras', buttons: []}
|
||||||
perform: e => e.applySurround('**', '**', 'bold_text')
|
];
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'italic',
|
|
||||||
group: 'fontStyles',
|
|
||||||
shortcut: 'I',
|
|
||||||
perform: e => e.applySurround('_', '_', 'italic_text')
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({id: 'link', group: 'insertions', shortcut: 'K', action: 'showLinkModal'});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'quote',
|
|
||||||
group: 'insertions',
|
|
||||||
icon: 'quote-right',
|
|
||||||
shortcut: 'Shift+9',
|
|
||||||
perform: e => e.applySurround('> ', '', 'code_text')
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'code',
|
|
||||||
group: 'insertions',
|
|
||||||
shortcut: 'Shift+C',
|
|
||||||
perform(e) {
|
|
||||||
if (e.selected.value.indexOf("\n") !== -1) {
|
|
||||||
e.applySurround(' ', '', 'code_text');
|
|
||||||
} else {
|
|
||||||
e.applySurround('`', '`', 'code_text');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'bullet',
|
|
||||||
group: 'extras',
|
|
||||||
icon: 'list-ul',
|
|
||||||
shortcut: 'Shift+8',
|
|
||||||
title: 'composer.ulist_title',
|
|
||||||
perform: e => e.applyList('* ', 'list_item')
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'list',
|
|
||||||
group: 'extras',
|
|
||||||
icon: 'list-ol',
|
|
||||||
shortcut: 'Shift+7',
|
|
||||||
title: 'composer.olist_title',
|
|
||||||
perform: e => e.applyList(i => !i ? "1. " : `${parseInt(i) + 1}. `, 'list_item')
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'heading',
|
|
||||||
group: 'extras',
|
|
||||||
icon: 'font',
|
|
||||||
shortcut: 'Alt+1',
|
|
||||||
perform: e => e.applyList('## ', 'heading_text')
|
|
||||||
});
|
|
||||||
|
|
||||||
this.addButton({
|
|
||||||
id: 'rule',
|
|
||||||
group: 'extras',
|
|
||||||
icon: 'minus',
|
|
||||||
shortcut: 'Alt+R',
|
|
||||||
title: 'composer.hr_title',
|
|
||||||
perform: e => e.addText("\n\n----------\n")
|
|
||||||
});
|
|
||||||
|
|
||||||
if (Discourse.Mobile.mobileView) {
|
|
||||||
this.groups.push({group: 'mobileExtras', buttons: []});
|
|
||||||
|
|
||||||
this.addButton({
|
this.addButton({
|
||||||
id: 'preview',
|
id: 'bold',
|
||||||
group: 'mobileExtras',
|
group: 'fontStyles',
|
||||||
icon: 'television',
|
shortcut: 'B',
|
||||||
title: 'composer.hr_preview',
|
perform: e => e.applySurround('**', '**', 'bold_text')
|
||||||
perform: e => e.preview()
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this.groups[this.groups.length-1].lastGroup = true;
|
this.addButton({
|
||||||
};
|
id: 'italic',
|
||||||
|
group: 'fontStyles',
|
||||||
|
shortcut: 'I',
|
||||||
|
perform: e => e.applySurround('_', '_', 'italic_text')
|
||||||
|
});
|
||||||
|
|
||||||
Toolbar.prototype.addButton = function(button) {
|
this.addButton({id: 'link', group: 'insertions', shortcut: 'K', action: 'showLinkModal'});
|
||||||
const g = this.groups.findProperty('group', button.group);
|
|
||||||
if (!g) {
|
|
||||||
throw `Couldn't find toolbar group ${button.group}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const createdButton = {
|
this.addButton({
|
||||||
id: button.id,
|
id: 'quote',
|
||||||
className: button.className || button.id,
|
group: 'insertions',
|
||||||
icon: button.icon || button.id,
|
icon: 'quote-right',
|
||||||
action: button.action || 'toolbarButton',
|
shortcut: 'Shift+9',
|
||||||
perform: button.perform || Ember.K
|
perform: e => e.applySurround('> ', '', 'code_text')
|
||||||
};
|
});
|
||||||
|
|
||||||
if (button.sendAction) {
|
this.addButton({
|
||||||
createdButton.sendAction = button.sendAction;
|
id: 'code',
|
||||||
}
|
group: 'insertions',
|
||||||
|
shortcut: 'Shift+C',
|
||||||
|
perform(e) {
|
||||||
|
if (e.selected.value.indexOf("\n") !== -1) {
|
||||||
|
e.applySurround(' ', '', 'code_text');
|
||||||
|
} else {
|
||||||
|
e.applySurround('`', '`', 'code_text');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const title = I18n.t(button.title || `composer.${button.id}_title`);
|
this.addButton({
|
||||||
if (button.shortcut) {
|
id: 'bullet',
|
||||||
const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
group: 'extras',
|
||||||
const mod = mac ? 'Meta' : 'Ctrl';
|
icon: 'list-ul',
|
||||||
var shortcutTitle = `${mod}+${button.shortcut}`;
|
shortcut: 'Shift+8',
|
||||||
|
title: 'composer.ulist_title',
|
||||||
|
perform: e => e.applyList('* ', 'list_item')
|
||||||
|
});
|
||||||
|
|
||||||
// Mac users are used to glyphs for shortcut keys
|
this.addButton({
|
||||||
if (mac) {
|
id: 'list',
|
||||||
shortcutTitle = shortcutTitle
|
group: 'extras',
|
||||||
.replace('Shift', "\u21E7")
|
icon: 'list-ol',
|
||||||
.replace('Meta', "\u2318")
|
shortcut: 'Shift+7',
|
||||||
.replace('Alt', "\u2325")
|
title: 'composer.olist_title',
|
||||||
.replace(/\+/g, '');
|
perform: e => e.applyList(i => !i ? "1. " : `${parseInt(i) + 1}. `, 'list_item')
|
||||||
} else {
|
});
|
||||||
shortcutTitle = shortcutTitle
|
|
||||||
.replace('Shift', I18n.t('shortcut_modifier_key.shift'))
|
this.addButton({
|
||||||
.replace('Ctrl', I18n.t('shortcut_modifier_key.ctrl'))
|
id: 'heading',
|
||||||
.replace('Alt', I18n.t('shortcut_modifier_key.alt'));
|
group: 'extras',
|
||||||
|
icon: 'font',
|
||||||
|
shortcut: 'Alt+1',
|
||||||
|
perform: e => e.applyList('## ', 'heading_text')
|
||||||
|
});
|
||||||
|
|
||||||
|
this.addButton({
|
||||||
|
id: 'rule',
|
||||||
|
group: 'extras',
|
||||||
|
icon: 'minus',
|
||||||
|
shortcut: 'Alt+R',
|
||||||
|
title: 'composer.hr_title',
|
||||||
|
perform: e => e.addText("\n\n----------\n")
|
||||||
|
});
|
||||||
|
|
||||||
|
if (site.mobileView) {
|
||||||
|
this.groups.push({group: 'mobileExtras', buttons: []});
|
||||||
|
|
||||||
|
this.addButton({
|
||||||
|
id: 'preview',
|
||||||
|
group: 'mobileExtras',
|
||||||
|
icon: 'television',
|
||||||
|
title: 'composer.hr_preview',
|
||||||
|
perform: e => e.preview()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createdButton.title = `${title} (${shortcutTitle})`;
|
this.groups[this.groups.length-1].lastGroup = true;
|
||||||
|
|
||||||
this.shortcuts[`${mod}+${button.shortcut}`.toLowerCase()] = createdButton;
|
|
||||||
} else {
|
|
||||||
createdButton.title = title;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (button.unshift) {
|
addButton(button) {
|
||||||
g.buttons.unshift(createdButton);
|
const g = this.groups.findProperty('group', button.group);
|
||||||
} else {
|
if (!g) {
|
||||||
g.buttons.push(createdButton);
|
throw `Couldn't find toolbar group ${button.group}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const createdButton = {
|
||||||
|
id: button.id,
|
||||||
|
className: button.className || button.id,
|
||||||
|
icon: button.icon || button.id,
|
||||||
|
action: button.action || 'toolbarButton',
|
||||||
|
perform: button.perform || Ember.K
|
||||||
|
};
|
||||||
|
|
||||||
|
if (button.sendAction) {
|
||||||
|
createdButton.sendAction = button.sendAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = I18n.t(button.title || `composer.${button.id}_title`);
|
||||||
|
if (button.shortcut) {
|
||||||
|
const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
||||||
|
const mod = mac ? 'Meta' : 'Ctrl';
|
||||||
|
var shortcutTitle = `${mod}+${button.shortcut}`;
|
||||||
|
|
||||||
|
// Mac users are used to glyphs for shortcut keys
|
||||||
|
if (mac) {
|
||||||
|
shortcutTitle = shortcutTitle
|
||||||
|
.replace('Shift', "\u21E7")
|
||||||
|
.replace('Meta', "\u2318")
|
||||||
|
.replace('Alt', "\u2325")
|
||||||
|
.replace(/\+/g, '');
|
||||||
|
} else {
|
||||||
|
shortcutTitle = shortcutTitle
|
||||||
|
.replace('Shift', I18n.t('shortcut_modifier_key.shift'))
|
||||||
|
.replace('Ctrl', I18n.t('shortcut_modifier_key.ctrl'))
|
||||||
|
.replace('Alt', I18n.t('shortcut_modifier_key.alt'));
|
||||||
|
}
|
||||||
|
|
||||||
|
createdButton.title = `${title} (${shortcutTitle})`;
|
||||||
|
|
||||||
|
this.shortcuts[`${mod}+${button.shortcut}`.toLowerCase()] = createdButton;
|
||||||
|
} else {
|
||||||
|
createdButton.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button.unshift) {
|
||||||
|
g.buttons.unshift(createdButton);
|
||||||
|
} else {
|
||||||
|
g.buttons.push(createdButton);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export function addToolbarCallback(func) {
|
||||||
|
_createCallbacks.push(func);
|
||||||
|
}
|
||||||
|
|
||||||
export function onToolbarCreate(func) {
|
export function onToolbarCreate(func) {
|
||||||
_createCallbacks.push(func);
|
console.warn('`onToolbarCreate` is deprecated, use the plugin api instead.');
|
||||||
|
addToolbarCallback(func);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
@ -237,7 +245,7 @@ export default Ember.Component.extend({
|
|||||||
|
|
||||||
@computed
|
@computed
|
||||||
toolbar() {
|
toolbar() {
|
||||||
const toolbar = new Toolbar();
|
const toolbar = new Toolbar(this.site);
|
||||||
_createCallbacks.forEach(cb => cb(toolbar));
|
_createCallbacks.forEach(cb => cb(toolbar));
|
||||||
this.sendAction('extraButtons', toolbar);
|
this.sendAction('extraButtons', toolbar);
|
||||||
return toolbar;
|
return toolbar;
|
||||||
|
@ -10,17 +10,17 @@ export default Ember.Component.extend({
|
|||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
showKeyboardShortcuts() {
|
showKeyboardShortcuts() {
|
||||||
return !Discourse.Mobile.mobileView && !this.capabilities.touch;
|
return !this.site.mobileView && !this.capabilities.touch;
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
showMobileToggle() {
|
showMobileToggle() {
|
||||||
return Discourse.Mobile.mobileView || (this.siteSettings.enable_mobile_theme && this.capabilities.touch);
|
return this.site.mobileView || (this.siteSettings.enable_mobile_theme && this.capabilities.touch);
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
mobileViewLinkTextKey() {
|
mobileViewLinkTextKey() {
|
||||||
return Discourse.Mobile.mobileView ? "desktop_view" : "mobile_view";
|
return this.site.mobileView ? "desktop_view" : "mobile_view";
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
@ -68,7 +68,7 @@ export default Ember.Component.extend({
|
|||||||
this.sendAction('showKeyboardAction');
|
this.sendAction('showKeyboardAction');
|
||||||
},
|
},
|
||||||
toggleMobileView() {
|
toggleMobileView() {
|
||||||
Discourse.Mobile.toggleMobileView();
|
this.site.toggleMobileView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -17,7 +17,7 @@ export default Ember.Component.extend({
|
|||||||
if (this.siteSettings.login_required && !this.currentUser) {
|
if (this.siteSettings.login_required && !this.currentUser) {
|
||||||
this.sendAction('loginAction');
|
this.sendAction('loginAction');
|
||||||
} else {
|
} else {
|
||||||
if (Discourse.Mobile.mobileView && this.get('mobileAction')) {
|
if (this.site.mobileView && this.get('mobileAction')) {
|
||||||
this.sendAction('mobileAction');
|
this.sendAction('mobileAction');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,11 @@ export default Ember.Component.extend({
|
|||||||
}.property('targetUrl'),
|
}.property('targetUrl'),
|
||||||
|
|
||||||
showSmallLogo: function() {
|
showSmallLogo: function() {
|
||||||
return !Discourse.Mobile.mobileView && this.get("minimized");
|
return !this.site.mobileView && this.get("minimized");
|
||||||
}.property("minimized"),
|
}.property("minimized"),
|
||||||
|
|
||||||
showMobileLogo: function() {
|
showMobileLogo: function() {
|
||||||
return Discourse.Mobile.mobileView && !Ember.isBlank(this.get('mobileBigLogoUrl'));
|
return this.site.mobileView && !Ember.isBlank(this.get('mobileBigLogoUrl'));
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
smallLogoUrl: setting('logo_small_url'),
|
smallLogoUrl: setting('logo_small_url'),
|
||||||
|
@ -120,17 +120,17 @@ export default Ember.Component.extend({
|
|||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
showKeyboardShortcuts() {
|
showKeyboardShortcuts() {
|
||||||
return !Discourse.Mobile.mobileView && !this.capabilities.touch;
|
return !this.site.mobileView && !this.capabilities.touch;
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
showMobileToggle() {
|
showMobileToggle() {
|
||||||
return Discourse.Mobile.mobileView || (this.siteSettings.enable_mobile_theme && this.capabilities.touch);
|
return this.site.mobileView || (this.siteSettings.enable_mobile_theme && this.capabilities.touch);
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
mobileViewLinkTextKey() {
|
mobileViewLinkTextKey() {
|
||||||
return Discourse.Mobile.mobileView ? "desktop_view" : "mobile_view";
|
return this.site.mobileView ? "desktop_view" : "mobile_view";
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
import { diff, patch } from 'virtual-dom';
|
||||||
|
import { WidgetClickHook } from 'discourse/widgets/click-hook';
|
||||||
|
import { renderedKey } from 'discourse/widgets/widget';
|
||||||
|
|
||||||
|
const _cleanCallbacks = {};
|
||||||
|
export function addWidgetCleanCallback(widgetName, fn) {
|
||||||
|
_cleanCallbacks[widgetName] = _cleanCallbacks[widgetName] || [];
|
||||||
|
_cleanCallbacks[widgetName].push(fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
_tree: null,
|
||||||
|
_rootNode: null,
|
||||||
|
_timeout: null,
|
||||||
|
_widgetClass: null,
|
||||||
|
_afterRender: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this._super();
|
||||||
|
this._widgetClass = this.container.lookupFactory(`widget:${this.get('widget')}`);
|
||||||
|
this._connected = [];
|
||||||
|
},
|
||||||
|
|
||||||
|
didInsertElement() {
|
||||||
|
WidgetClickHook.setupDocumentCallback();
|
||||||
|
|
||||||
|
this._rootNode = document.createElement('div');
|
||||||
|
this.element.appendChild(this._rootNode);
|
||||||
|
this._timeout = Ember.run.scheduleOnce('render', this, this.rerenderWidget);
|
||||||
|
},
|
||||||
|
|
||||||
|
willClearRender() {
|
||||||
|
const callbacks = _cleanCallbacks[this.get('widget')];
|
||||||
|
if (callbacks) {
|
||||||
|
callbacks.forEach(cb => cb());
|
||||||
|
}
|
||||||
|
|
||||||
|
this._connected.forEach(v => v.destroy());
|
||||||
|
this._connected.length = 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
willDestroyElement() {
|
||||||
|
Ember.run.cancel(this._timeout);
|
||||||
|
},
|
||||||
|
|
||||||
|
queueRerender(callback) {
|
||||||
|
if (callback && !this._afterRender) {
|
||||||
|
this._afterRender = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ember.run.scheduleOnce('render', this, this.rerenderWidget);
|
||||||
|
},
|
||||||
|
|
||||||
|
rerenderWidget() {
|
||||||
|
Ember.run.cancel(this._timeout);
|
||||||
|
if (this._rootNode) {
|
||||||
|
const opts = { model: this.get('model') };
|
||||||
|
const newTree = new this._widgetClass(this.get('args'), this.container, opts);
|
||||||
|
|
||||||
|
newTree._emberView = this;
|
||||||
|
const patches = diff(this._tree || this._rootNode, newTree);
|
||||||
|
this._rootNode = patch(this._rootNode, patches);
|
||||||
|
this._tree = newTree;
|
||||||
|
|
||||||
|
if (this._afterRender) {
|
||||||
|
this._afterRender();
|
||||||
|
this._afterRender = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderedKey('*');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
@ -1,44 +0,0 @@
|
|||||||
export default Ember.Component.extend({
|
|
||||||
classNameBindings: [':gap', ':jagged-border', 'gap::hidden'],
|
|
||||||
|
|
||||||
initGaps: function(){
|
|
||||||
this.set('loading', false);
|
|
||||||
const before = this.get('before') === 'true';
|
|
||||||
const gaps = before ? this.get('postStream.gaps.before') : this.get('postStream.gaps.after');
|
|
||||||
|
|
||||||
if (gaps) {
|
|
||||||
this.set('gap', gaps[this.get('post.id')]);
|
|
||||||
}
|
|
||||||
}.on('init'),
|
|
||||||
|
|
||||||
gapsChanged: function(){
|
|
||||||
this.initGaps();
|
|
||||||
this.rerender();
|
|
||||||
}.observes('post.hasGap'),
|
|
||||||
|
|
||||||
render(buffer) {
|
|
||||||
if (this.get('loading')) {
|
|
||||||
buffer.push(I18n.t('loading'));
|
|
||||||
} else {
|
|
||||||
const gapLength = this.get('gap.length');
|
|
||||||
if (gapLength) {
|
|
||||||
buffer.push(I18n.t('post.gap', {count: gapLength}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
click() {
|
|
||||||
if (this.get('loading') || (!this.get('gap'))) { return false; }
|
|
||||||
this.set('loading', true);
|
|
||||||
this.rerender();
|
|
||||||
|
|
||||||
const postStream = this.get('postStream');
|
|
||||||
const filler = this.get('before') === 'true' ? postStream.fillGapBefore : postStream.fillGapAfter;
|
|
||||||
|
|
||||||
filler.call(postStream, this.get('post'), this.get('gap')).then(() => {
|
|
||||||
this.set('gap', null);
|
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,85 +0,0 @@
|
|||||||
const MAX_SHOWN = 5;
|
|
||||||
|
|
||||||
import StringBuffer from 'discourse/mixins/string-buffer';
|
|
||||||
import { iconHTML } from 'discourse/helpers/fa-icon';
|
|
||||||
import computed from 'ember-addons/ember-computed-decorators';
|
|
||||||
|
|
||||||
const { get, isEmpty, Component } = Ember;
|
|
||||||
|
|
||||||
export default Component.extend(StringBuffer, {
|
|
||||||
classNameBindings: [':gutter'],
|
|
||||||
|
|
||||||
rerenderTriggers: ['expanded'],
|
|
||||||
|
|
||||||
// Roll up links to avoid duplicates
|
|
||||||
@computed('links')
|
|
||||||
collapsed(links) {
|
|
||||||
const seen = {};
|
|
||||||
const result = [];
|
|
||||||
|
|
||||||
if (!isEmpty(links)) {
|
|
||||||
links.forEach(function(l) {
|
|
||||||
const title = get(l, 'title');
|
|
||||||
if (!seen[title]) {
|
|
||||||
result.pushObject(l);
|
|
||||||
seen[title] = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
|
|
||||||
renderString(buffer) {
|
|
||||||
const links = this.get('collapsed');
|
|
||||||
const collapsed = !this.get('expanded');
|
|
||||||
|
|
||||||
if (!isEmpty(links)) {
|
|
||||||
let toRender = links;
|
|
||||||
if (collapsed) {
|
|
||||||
toRender = toRender.slice(0, MAX_SHOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.push("<ul class='post-links'>");
|
|
||||||
toRender.forEach(function(l) {
|
|
||||||
const direction = get(l, 'reflection') ? 'inbound' : 'outbound',
|
|
||||||
clicks = get(l, 'clicks');
|
|
||||||
|
|
||||||
buffer.push(`<li><a href='${get(l, 'url')}' class='track-link ${direction}'>`);
|
|
||||||
|
|
||||||
let title = get(l, 'title');
|
|
||||||
if (!isEmpty(title)) {
|
|
||||||
title = Discourse.Utilities.escapeExpression(title);
|
|
||||||
buffer.push(Discourse.Emoji.unescape(title));
|
|
||||||
}
|
|
||||||
if (clicks) {
|
|
||||||
buffer.push(`<span class='badge badge-notification clicks'>${clicks}</span>`);
|
|
||||||
}
|
|
||||||
buffer.push("</a></li>");
|
|
||||||
});
|
|
||||||
|
|
||||||
if (collapsed) {
|
|
||||||
const remaining = links.length - MAX_SHOWN;
|
|
||||||
if (remaining > 0) {
|
|
||||||
buffer.push(`<li><a href class='toggle-more'>${I18n.t('post.more_links', {count: remaining})}</a></li>`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buffer.push('</ul>');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.get('canReplyAsNewTopic')) {
|
|
||||||
buffer.push(`<a href class='reply-new'>${iconHTML('plus')}${I18n.t('post.reply_as_new_topic')}</a>`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
click(e) {
|
|
||||||
const $target = $(e.target);
|
|
||||||
if ($target.hasClass('toggle-more')) {
|
|
||||||
this.toggleProperty('expanded');
|
|
||||||
return false;
|
|
||||||
} else if ($target.closest('.reply-new').length) {
|
|
||||||
this.sendAction('newTopicAction', this.get('post'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,440 +0,0 @@
|
|||||||
import StringBuffer from 'discourse/mixins/string-buffer';
|
|
||||||
import { iconHTML } from 'discourse/helpers/fa-icon';
|
|
||||||
|
|
||||||
// Helper class for rendering a button
|
|
||||||
export const Button = function(action, label, icon, opts) {
|
|
||||||
this.action = action;
|
|
||||||
this.label = label;
|
|
||||||
|
|
||||||
if (typeof icon === "object") {
|
|
||||||
this.opts = icon;
|
|
||||||
} else {
|
|
||||||
this.icon = icon;
|
|
||||||
}
|
|
||||||
this.opts = this.opts || opts || {};
|
|
||||||
};
|
|
||||||
|
|
||||||
function animateHeart($elem, start, end, complete) {
|
|
||||||
if (Ember.testing) { return Ember.run(this, complete); }
|
|
||||||
|
|
||||||
$elem.stop()
|
|
||||||
.css('textIndent', start)
|
|
||||||
.animate({ textIndent: end }, {
|
|
||||||
complete,
|
|
||||||
step(now) {
|
|
||||||
$(this).css('transform','scale('+now+')');
|
|
||||||
},
|
|
||||||
duration: 150
|
|
||||||
}, 'linear');
|
|
||||||
}
|
|
||||||
|
|
||||||
Button.prototype.render = function(buffer) {
|
|
||||||
const opts = this.opts;
|
|
||||||
|
|
||||||
const label = I18n.t(this.label, opts.labelOptions);
|
|
||||||
if (opts.prefixHTML) {
|
|
||||||
buffer.push(opts.prefixHTML);
|
|
||||||
}
|
|
||||||
buffer.push("<button aria-label=\"" + label +"\" " + "title=\"" + label + "\"");
|
|
||||||
|
|
||||||
if (opts.disabled) { buffer.push(" disabled"); }
|
|
||||||
if (opts.className) { buffer.push(" class=\"" + opts.className + "\""); }
|
|
||||||
if (opts.shareUrl) { buffer.push(" data-share-url=\"" + opts.shareUrl + "\""); }
|
|
||||||
if (opts.postNumber) { buffer.push(" data-post-number=\"" + opts.postNumber + "\""); }
|
|
||||||
buffer.push(" data-action=\"" + this.action + "\">");
|
|
||||||
if (this.icon) { buffer.push(iconHTML(this.icon)); }
|
|
||||||
if (opts.textLabel) { buffer.push(I18n.t(opts.textLabel)); }
|
|
||||||
if (opts.innerHTML) { buffer.push(opts.innerHTML); }
|
|
||||||
buffer.push("</button>");
|
|
||||||
};
|
|
||||||
|
|
||||||
let hiddenButtons;
|
|
||||||
|
|
||||||
const PostMenuComponent = Ember.Component.extend(StringBuffer, {
|
|
||||||
tagName: 'section',
|
|
||||||
classNames: ['post-menu-area', 'clearfix'],
|
|
||||||
|
|
||||||
rerenderTriggers: [
|
|
||||||
'post.deleted_at',
|
|
||||||
'post.likeAction.count',
|
|
||||||
'post.likeAction.users.length',
|
|
||||||
'post.reply_count',
|
|
||||||
'post.showRepliesBelow',
|
|
||||||
'post.can_delete',
|
|
||||||
'post.bookmarked',
|
|
||||||
'post.shareUrl',
|
|
||||||
'post.topic.deleted_at',
|
|
||||||
'post.replies.length',
|
|
||||||
'post.wiki',
|
|
||||||
'post.post_type',
|
|
||||||
'collapsed'],
|
|
||||||
|
|
||||||
_collapsedByDefault: function() {
|
|
||||||
this.set('collapsed', true);
|
|
||||||
}.on('init'),
|
|
||||||
|
|
||||||
renderString(buffer) {
|
|
||||||
const post = this.get('post');
|
|
||||||
|
|
||||||
buffer.push("<nav class='post-controls'>");
|
|
||||||
this.renderReplies(post, buffer);
|
|
||||||
this.renderButtons(post, buffer);
|
|
||||||
this.renderAdminPopup(post, buffer);
|
|
||||||
buffer.push("</nav>");
|
|
||||||
},
|
|
||||||
|
|
||||||
// Delegate click actions
|
|
||||||
click(e) {
|
|
||||||
const $target = $(e.target);
|
|
||||||
const action = $target.data('action') || $target.parent().data('action');
|
|
||||||
|
|
||||||
if ($target.prop('disabled') || $target.parent().prop('disabled')) { return; }
|
|
||||||
|
|
||||||
if (!action) return;
|
|
||||||
const handler = this["click" + action.classify()];
|
|
||||||
if (!handler) return;
|
|
||||||
|
|
||||||
handler.call(this, this.get('post'));
|
|
||||||
},
|
|
||||||
|
|
||||||
// Replies Button
|
|
||||||
renderReplies(post, buffer) {
|
|
||||||
if (!post.get('showRepliesBelow')) return;
|
|
||||||
|
|
||||||
const replyCount = post.get('reply_count');
|
|
||||||
buffer.push("<button class='show-replies highlight-action' data-action='replies'>");
|
|
||||||
buffer.push(I18n.t("post.has_replies", { count: replyCount || 0 }));
|
|
||||||
|
|
||||||
const icon = (this.get('post.replies.length') > 0) ? 'chevron-up' : 'chevron-down';
|
|
||||||
return buffer.push(iconHTML(icon) + "</button>");
|
|
||||||
},
|
|
||||||
|
|
||||||
renderButtons(post, buffer) {
|
|
||||||
const self = this;
|
|
||||||
const allButtons = [];
|
|
||||||
let visibleButtons = [];
|
|
||||||
|
|
||||||
if (typeof hiddenButtons === "undefined") {
|
|
||||||
if (!Em.isEmpty(this.siteSettings.post_menu_hidden_items)) {
|
|
||||||
hiddenButtons = this.siteSettings.post_menu_hidden_items.split('|');
|
|
||||||
} else {
|
|
||||||
hiddenButtons = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (post.get("bookmarked")) {
|
|
||||||
hiddenButtons.removeObject("bookmark");
|
|
||||||
}
|
|
||||||
|
|
||||||
const yours = post.get('yours');
|
|
||||||
this.siteSettings.post_menu.split("|").forEach(function(i) {
|
|
||||||
const creator = self["buttonFor" + i.classify()];
|
|
||||||
if (creator) {
|
|
||||||
const button = creator.call(self, post);
|
|
||||||
if (button) {
|
|
||||||
allButtons.push(button);
|
|
||||||
if ((yours && button.opts.alwaysShowYours) ||
|
|
||||||
(post.get('wiki') && button.opts.alwaysShowWiki) ||
|
|
||||||
(hiddenButtons.indexOf(i) === -1)) {
|
|
||||||
visibleButtons.push(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Only show ellipsis if there is more than one button hidden
|
|
||||||
// if there are no more buttons, we are not collapsed
|
|
||||||
const collapsed = this.get('collapsed');
|
|
||||||
if (!collapsed || (allButtons.length <= visibleButtons.length + 1)) {
|
|
||||||
visibleButtons = allButtons;
|
|
||||||
if (collapsed) { this.set('collapsed', false); }
|
|
||||||
} else {
|
|
||||||
visibleButtons.splice(visibleButtons.length - 1, 0, this.buttonForShowMoreActions(post));
|
|
||||||
}
|
|
||||||
|
|
||||||
const callbacks = PostMenuComponent._registerButtonCallbacks;
|
|
||||||
if (callbacks) {
|
|
||||||
_.each(callbacks, function(callback) {
|
|
||||||
callback.apply(self, [visibleButtons]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.push('<div class="actions">');
|
|
||||||
visibleButtons.forEach((b) => b.render(buffer));
|
|
||||||
buffer.push("</div>");
|
|
||||||
},
|
|
||||||
|
|
||||||
clickLikeCount() {
|
|
||||||
this.sendActionTarget('toggleWhoLiked');
|
|
||||||
},
|
|
||||||
|
|
||||||
sendActionTarget(action, arg) {
|
|
||||||
const target = this.get(`${action}Target`);
|
|
||||||
return target ? target.send(this.get(action), arg) : this.sendAction(action, arg);
|
|
||||||
},
|
|
||||||
|
|
||||||
clickReplies() {
|
|
||||||
if (this.get('post.replies.length') > 0) {
|
|
||||||
this.set('post.replies', []);
|
|
||||||
} else {
|
|
||||||
this.get('post').loadReplies();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Delete button
|
|
||||||
buttonForDelete(post) {
|
|
||||||
let label, icon;
|
|
||||||
|
|
||||||
if (post.get('post_number') === 1) {
|
|
||||||
// If it's the first post, the delete/undo actions are related to the topic
|
|
||||||
const topic = post.get('topic');
|
|
||||||
if (topic.get('deleted_at')) {
|
|
||||||
if (!topic.get('details.can_recover')) { return; }
|
|
||||||
label = "topic.actions.recover";
|
|
||||||
icon = "undo";
|
|
||||||
} else {
|
|
||||||
if (!topic.get('details.can_delete')) { return; }
|
|
||||||
label = "topic.actions.delete";
|
|
||||||
icon = "trash-o";
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// The delete actions target the post iteself
|
|
||||||
if (post.get('deleted_at') || post.get('user_deleted')) {
|
|
||||||
if (!post.get('can_recover')) { return; }
|
|
||||||
label = "post.controls.undelete";
|
|
||||||
icon = "undo";
|
|
||||||
} else {
|
|
||||||
if (!post.get('can_delete')) { return; }
|
|
||||||
label = "post.controls.delete";
|
|
||||||
icon = "trash-o";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const action = (icon === 'trash-o') ? 'delete' : 'recover';
|
|
||||||
let opts;
|
|
||||||
if (icon === "trash-o"){
|
|
||||||
opts = {className: 'delete'};
|
|
||||||
}
|
|
||||||
return new Button(action, label, icon, opts);
|
|
||||||
},
|
|
||||||
|
|
||||||
clickRecover(post) {
|
|
||||||
this.sendAction('recoverPost', post);
|
|
||||||
},
|
|
||||||
|
|
||||||
clickDelete(post) {
|
|
||||||
this.sendAction('deletePost', post);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Like button
|
|
||||||
buttonForLike() {
|
|
||||||
const likeAction = this.get('post.likeAction');
|
|
||||||
if (!likeAction) { return; }
|
|
||||||
|
|
||||||
const className = likeAction.get('acted') ? 'has-like fade-out' : 'like';
|
|
||||||
const opts = {className: className};
|
|
||||||
|
|
||||||
if (likeAction.get('canToggle')) {
|
|
||||||
const descKey = likeAction.get('acted') ? 'post.controls.undo_like' : 'post.controls.like';
|
|
||||||
return new Button('like', descKey, 'heart', opts);
|
|
||||||
} else if (likeAction.get('acted')) {
|
|
||||||
opts.disabled = true;
|
|
||||||
return new Button('like', 'post.controls.has_liked', 'heart', opts);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
buttonForLikeCount() {
|
|
||||||
const likeCount = this.get('post.likeAction.count') || 0;
|
|
||||||
if (likeCount > 0) {
|
|
||||||
const likedPost = !!this.get('post.likeAction.acted');
|
|
||||||
|
|
||||||
const label = likedPost
|
|
||||||
? likeCount === 1 ? 'post.has_likes_title_only_you' : 'post.has_likes_title_you'
|
|
||||||
: 'post.has_likes_title';
|
|
||||||
|
|
||||||
return new Button('like-count', label, undefined, {
|
|
||||||
className: 'like-count highlight-action',
|
|
||||||
innerHTML: I18n.t("post.has_likes", { count: likeCount }),
|
|
||||||
labelOptions: {count: likedPost ? (likeCount-1) : likeCount}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
clickLike(post) {
|
|
||||||
const $heart = this.$('.fa-heart'),
|
|
||||||
$likeButton = this.$('button[data-action=like]'),
|
|
||||||
acted = post.get('likeAction.acted'),
|
|
||||||
self = this;
|
|
||||||
|
|
||||||
if (acted) {
|
|
||||||
this.sendActionTarget('toggleLike');
|
|
||||||
$likeButton.removeClass('has-like').addClass('like');
|
|
||||||
} else {
|
|
||||||
const scale = [1.0, 1.5];
|
|
||||||
animateHeart($heart, scale[0], scale[1], function() {
|
|
||||||
animateHeart($heart, scale[1], scale[0], function() {
|
|
||||||
self.sendActionTarget('toggleLike');
|
|
||||||
$likeButton.removeClass('like').addClass('has-like');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Flag button
|
|
||||||
buttonForFlag(post) {
|
|
||||||
if (Em.isEmpty(post.get('flagsAvailable'))) return;
|
|
||||||
return new Button('flag', 'post.controls.flag', 'flag');
|
|
||||||
},
|
|
||||||
|
|
||||||
clickFlag(post) {
|
|
||||||
this.sendAction('showFlags', post);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Edit button
|
|
||||||
buttonForEdit(post) {
|
|
||||||
if (!post.get('can_edit')) return;
|
|
||||||
return new Button('edit', 'post.controls.edit', 'pencil', {
|
|
||||||
alwaysShowYours: true,
|
|
||||||
alwaysShowWiki: true
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
clickEdit(post) {
|
|
||||||
this.sendAction('editPost', post);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Share button
|
|
||||||
buttonForShare(post) {
|
|
||||||
const options = {
|
|
||||||
shareUrl: post.get('shareUrl'),
|
|
||||||
postNumber: post.get('post_number')
|
|
||||||
};
|
|
||||||
return new Button('share', 'post.controls.share', 'link', options);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Reply button
|
|
||||||
buttonForReply() {
|
|
||||||
if (!this.get('canCreatePost')) return;
|
|
||||||
const options = {className: 'create fade-out'};
|
|
||||||
|
|
||||||
if(!Discourse.Mobile.mobileView) {
|
|
||||||
options.textLabel = 'topic.reply.title';
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Button('reply', 'post.controls.reply', 'reply', options);
|
|
||||||
},
|
|
||||||
|
|
||||||
clickReply(post) {
|
|
||||||
this.sendAction('replyToPost', post);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Bookmark button
|
|
||||||
buttonForBookmark(post) {
|
|
||||||
if (!Discourse.User.current()) return;
|
|
||||||
|
|
||||||
let iconClass = 'read-icon',
|
|
||||||
buttonClass = 'bookmark',
|
|
||||||
tooltip = 'bookmarks.not_bookmarked';
|
|
||||||
|
|
||||||
if (post.get('bookmarked')) {
|
|
||||||
iconClass += ' bookmarked';
|
|
||||||
buttonClass += ' bookmarked';
|
|
||||||
tooltip = 'bookmarks.created';
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Button('bookmark', tooltip, {className: buttonClass, innerHTML: "<div class='" + iconClass + "'>"});
|
|
||||||
},
|
|
||||||
|
|
||||||
clickBookmark(post) {
|
|
||||||
this.sendAction('toggleBookmark', post);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Wiki button
|
|
||||||
buttonForWiki(post) {
|
|
||||||
if (!post.get('can_wiki')) return;
|
|
||||||
|
|
||||||
if (post.get('wiki')) {
|
|
||||||
return new Button('wiki', 'post.controls.unwiki', 'pencil-square-o', {className: 'wiki wikied'});
|
|
||||||
} else {
|
|
||||||
return new Button('wiki', 'post.controls.wiki', 'pencil-square-o', {className: 'wiki'});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
clickWiki(post) {
|
|
||||||
this.sendAction('toggleWiki', post);
|
|
||||||
},
|
|
||||||
|
|
||||||
buttonForAdmin() {
|
|
||||||
if (!Discourse.User.currentProp('canManageTopic')) { return; }
|
|
||||||
return new Button('admin', 'post.controls.admin', 'wrench');
|
|
||||||
},
|
|
||||||
|
|
||||||
renderAdminPopup(post, buffer) {
|
|
||||||
if (!Discourse.User.currentProp('canManageTopic')) { return; }
|
|
||||||
|
|
||||||
const isModerator = post.get('post_type') === this.site.get('post_types.moderator_action'),
|
|
||||||
postTypeIcon = iconHTML('shield'),
|
|
||||||
postTypeText = isModerator ? I18n.t('post.controls.revert_to_regular') : I18n.t('post.controls.convert_to_moderator'),
|
|
||||||
rebakePostIcon = iconHTML('cog'),
|
|
||||||
rebakePostText = I18n.t('post.controls.rebake'),
|
|
||||||
unhidePostIcon = iconHTML('eye'),
|
|
||||||
unhidePostText = I18n.t('post.controls.unhide'),
|
|
||||||
changePostOwnerIcon = iconHTML('user'),
|
|
||||||
changePostOwnerText = I18n.t('post.controls.change_owner');
|
|
||||||
|
|
||||||
const html = '<div class="post-admin-menu popup-menu">' +
|
|
||||||
'<h3>' + I18n.t('admin_title') + '</h3>' +
|
|
||||||
'<ul>' +
|
|
||||||
(Discourse.User.currentProp('staff') ? '<li class="btn" data-action="togglePostType">' + postTypeIcon + postTypeText + '</li>' : '') +
|
|
||||||
'<li class="btn" data-action="rebakePost">' + rebakePostIcon + rebakePostText + '</li>' +
|
|
||||||
(post.hidden ? '<li class="btn" data-action="unhidePost">' + unhidePostIcon + unhidePostText + '</li>' : '') +
|
|
||||||
(Discourse.User.currentProp('admin') ? '<li class="btn" data-action="changePostOwner">' + changePostOwnerIcon + changePostOwnerText + '</li>' : '') +
|
|
||||||
'</ul>' +
|
|
||||||
'</div>';
|
|
||||||
|
|
||||||
buffer.push(html);
|
|
||||||
},
|
|
||||||
|
|
||||||
clickAdmin() {
|
|
||||||
const $postAdminMenu = this.$(".post-admin-menu");
|
|
||||||
$postAdminMenu.show();
|
|
||||||
$("html").on("mouseup.post-admin-menu", function() {
|
|
||||||
$postAdminMenu.hide();
|
|
||||||
$("html").off("mouseup.post-admin-menu");
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
clickTogglePostType() {
|
|
||||||
this.sendAction("togglePostType", this.get("post"));
|
|
||||||
},
|
|
||||||
|
|
||||||
clickRebakePost() {
|
|
||||||
this.sendAction("rebakePost", this.get("post"));
|
|
||||||
},
|
|
||||||
|
|
||||||
clickUnhidePost() {
|
|
||||||
this.sendAction("unhidePost", this.get("post"));
|
|
||||||
},
|
|
||||||
|
|
||||||
clickChangePostOwner() {
|
|
||||||
this.sendAction("changePostOwner", this.get("post"));
|
|
||||||
},
|
|
||||||
|
|
||||||
buttonForShowMoreActions() {
|
|
||||||
return new Button('showMoreActions', 'show_more', 'ellipsis-h');
|
|
||||||
},
|
|
||||||
|
|
||||||
clickShowMoreActions() {
|
|
||||||
this.set('collapsed', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
PostMenuComponent.reopenClass({
|
|
||||||
registerButton(callback){
|
|
||||||
this._registerButtonCallbacks = this._registerButtonCallbacks || [];
|
|
||||||
this._registerButtonCallbacks.push(callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default PostMenuComponent;
|
|
@ -1,77 +1,2 @@
|
|||||||
import { setting } from 'discourse/lib/computed';
|
const removed = new Discourse.RemovedObject('discourse/components/poster-name');
|
||||||
|
export default removed;
|
||||||
const PosterNameComponent = Em.Component.extend({
|
|
||||||
classNames: ['names', 'trigger-user-card'],
|
|
||||||
displayNameOnPosts: setting('display_name_on_posts'),
|
|
||||||
|
|
||||||
// sanitize name for comparison
|
|
||||||
sanitizeName(name){
|
|
||||||
return name.toLowerCase().replace(/[\s_-]/g,'');
|
|
||||||
},
|
|
||||||
|
|
||||||
render(buffer) {
|
|
||||||
const post = this.get('post');
|
|
||||||
|
|
||||||
if (post) {
|
|
||||||
const username = post.get('username'),
|
|
||||||
primaryGroupName = post.get('primary_group_name'),
|
|
||||||
url = post.get('usernameUrl');
|
|
||||||
|
|
||||||
var linkClass = 'username',
|
|
||||||
name = post.get('name');
|
|
||||||
|
|
||||||
if (post.get('staff')) { linkClass += ' staff'; }
|
|
||||||
if (post.get('admin')) { linkClass += ' admin'; }
|
|
||||||
if (post.get('moderator')) { linkClass += ' moderator'; }
|
|
||||||
if (post.get('new_user')) { linkClass += ' new-user'; }
|
|
||||||
|
|
||||||
if (!Em.isEmpty(primaryGroupName)) {
|
|
||||||
linkClass += ' ' + primaryGroupName;
|
|
||||||
}
|
|
||||||
// Main link
|
|
||||||
buffer.push("<span class='" + linkClass + "'><a href='" + url + "' data-auto-route='true' data-user-card='" + username + "'>" + username + "</a>");
|
|
||||||
|
|
||||||
// Add a glyph if we have one
|
|
||||||
const glyph = this.posterGlyph(post);
|
|
||||||
if (!Em.isEmpty(glyph)) {
|
|
||||||
buffer.push(glyph);
|
|
||||||
}
|
|
||||||
buffer.push("</span>");
|
|
||||||
|
|
||||||
// Are we showing full names?
|
|
||||||
if (name && this.get('displayNameOnPosts') && (this.sanitizeName(name) !== this.sanitizeName(username))) {
|
|
||||||
name = Discourse.Utilities.escapeExpression(name);
|
|
||||||
buffer.push("<span class='full-name'><a href='" + url + "' data-auto-route='true' data-user-card='" + username + "'>" + name + "</a></span>");
|
|
||||||
}
|
|
||||||
|
|
||||||
// User titles
|
|
||||||
let title = post.get('user_title');
|
|
||||||
if (!Em.isEmpty(title)) {
|
|
||||||
|
|
||||||
title = Discourse.Utilities.escapeExpression(title);
|
|
||||||
buffer.push('<span class="user-title">');
|
|
||||||
if (Em.isEmpty(primaryGroupName)) {
|
|
||||||
buffer.push(title);
|
|
||||||
} else {
|
|
||||||
buffer.push("<a href='/groups/" + post.get('primary_group_name') + "' class='user-group'>" + title + "</a>");
|
|
||||||
}
|
|
||||||
buffer.push("</span>");
|
|
||||||
}
|
|
||||||
|
|
||||||
PosterNameComponent.trigger('renderedName', buffer, post);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Overwrite this to give a user a custom font awesome glyph.
|
|
||||||
posterGlyph(post) {
|
|
||||||
if(post.get('moderator')) {
|
|
||||||
const desc = I18n.t('user.moderator_tooltip');
|
|
||||||
return '<i class="fa fa-shield" title="' + desc + '" alt="' + desc + '"></i>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Support for event triggering
|
|
||||||
PosterNameComponent.reopenClass(Em.Evented);
|
|
||||||
|
|
||||||
export default PosterNameComponent;
|
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
export default Ember.Component.extend({
|
|
||||||
layoutName: 'components/private-message-map',
|
|
||||||
tagName: 'section',
|
|
||||||
classNames: ['information'],
|
|
||||||
details: Em.computed.alias('topic.details'),
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
removeAllowedUser: function(user) {
|
|
||||||
var self = this;
|
|
||||||
bootbox.dialog(I18n.t("private_message_info.remove_allowed_user", {name: user.get('username')}), [
|
|
||||||
{label: I18n.t("no_value"),
|
|
||||||
'class': 'btn-danger right'},
|
|
||||||
{label: I18n.t("yes_value"),
|
|
||||||
'class': 'btn-primary',
|
|
||||||
callback: function() {
|
|
||||||
self.get('topic.details').removeAllowedUser(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
|
|
||||||
showPrivateInvite: function() {
|
|
||||||
this.sendAction('showPrivateInviteAction');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
@ -0,0 +1,176 @@
|
|||||||
|
import DiscourseURL from 'discourse/lib/url';
|
||||||
|
import { keyDirty } from 'discourse/widgets/widget';
|
||||||
|
import MountWidget from 'discourse/components/mount-widget';
|
||||||
|
|
||||||
|
function findTopView($posts, viewportTop, min, max) {
|
||||||
|
if (max < min) { return min; }
|
||||||
|
|
||||||
|
while(max>min){
|
||||||
|
const mid = Math.floor((min + max) / 2);
|
||||||
|
const $post = $($posts[mid]);
|
||||||
|
const viewBottom = $post.position().top + $post.height();
|
||||||
|
|
||||||
|
if (viewBottom > viewportTop) {
|
||||||
|
max = mid-1;
|
||||||
|
} else {
|
||||||
|
min = mid+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MountWidget.extend({
|
||||||
|
widget: 'post-stream',
|
||||||
|
_topVisible: null,
|
||||||
|
_bottomVisible: null,
|
||||||
|
|
||||||
|
args: Ember.computed(function() {
|
||||||
|
return this.getProperties('posts',
|
||||||
|
'canCreatePost',
|
||||||
|
'multiSelect',
|
||||||
|
'gaps',
|
||||||
|
'selectedQuery',
|
||||||
|
'selectedPostsCount',
|
||||||
|
'searchService');
|
||||||
|
}).volatile(),
|
||||||
|
|
||||||
|
scrolled() {
|
||||||
|
if (this.isDestroyed || this.isDestroying) { return; }
|
||||||
|
|
||||||
|
const $w = $(window);
|
||||||
|
const windowHeight = window.innerHeight ? window.innerHeight : $w.height();
|
||||||
|
const slack = Math.round(windowHeight * 15);
|
||||||
|
const onscreen = [];
|
||||||
|
|
||||||
|
let windowTop = $w.scrollTop();
|
||||||
|
|
||||||
|
const $posts = this.$('.onscreen-post');
|
||||||
|
const viewportTop = windowTop - slack;
|
||||||
|
const topView = findTopView($posts, viewportTop, 0, $posts.length-1);
|
||||||
|
|
||||||
|
let windowBottom = windowTop + windowHeight;
|
||||||
|
let viewportBottom = windowBottom + slack;
|
||||||
|
|
||||||
|
const bodyHeight = $('body').height();
|
||||||
|
if (windowBottom > bodyHeight) { windowBottom = bodyHeight; }
|
||||||
|
if (viewportBottom > bodyHeight) { viewportBottom = bodyHeight; }
|
||||||
|
|
||||||
|
let bottomView = topView;
|
||||||
|
while (bottomView < $posts.length) {
|
||||||
|
const post = $posts[bottomView];
|
||||||
|
const $post = $(post);
|
||||||
|
|
||||||
|
if (!$post) { break; }
|
||||||
|
|
||||||
|
const viewTop = $post.offset().top;
|
||||||
|
const viewBottom = viewTop + $post.height();
|
||||||
|
|
||||||
|
if (viewTop > viewportBottom) { break; }
|
||||||
|
|
||||||
|
if (viewBottom > windowTop && viewTop <= windowBottom) {
|
||||||
|
onscreen.push(bottomView);
|
||||||
|
}
|
||||||
|
|
||||||
|
bottomView++;
|
||||||
|
}
|
||||||
|
|
||||||
|
const posts = this.posts;
|
||||||
|
if (onscreen.length) {
|
||||||
|
|
||||||
|
const refresh = cb => this.queueRerender(cb);
|
||||||
|
const first = posts.objectAt(onscreen[0]);
|
||||||
|
if (this._topVisible !== first) {
|
||||||
|
this._topVisible = first;
|
||||||
|
const $body = $('body');
|
||||||
|
const elem = $posts[onscreen[0]];
|
||||||
|
const elemId = elem.id;
|
||||||
|
const $elem = $(elem);
|
||||||
|
const elemPos = $elem.position();
|
||||||
|
const distToElement = elemPos ? $body.scrollTop() - elemPos.top : 0;
|
||||||
|
|
||||||
|
const topRefresh = () => {
|
||||||
|
refresh(() => {
|
||||||
|
const $refreshedElem = $(`#${elemId}`);
|
||||||
|
|
||||||
|
// Quickly going back might mean the element is destroyed
|
||||||
|
const position = $refreshedElem.position();
|
||||||
|
if (position && position.top) {
|
||||||
|
$('html, body').scrollTop(position.top + distToElement);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
this.sendAction('topVisibleChanged', { post: first, refresh: topRefresh });
|
||||||
|
}
|
||||||
|
|
||||||
|
const last = posts.objectAt(onscreen[onscreen.length-1]);
|
||||||
|
if (this._bottomVisible !== last) {
|
||||||
|
this._bottomVisible = last;
|
||||||
|
this.sendAction('bottomVisibleChanged', { post: last, refresh });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this._topVisible = null;
|
||||||
|
this._bottomVisible = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const onscreenPostNumbers = onscreen.map(idx => posts.objectAt(idx).post_number);
|
||||||
|
this.screenTrack.setOnscreen(onscreenPostNumbers);
|
||||||
|
},
|
||||||
|
|
||||||
|
_scrollTriggered() {
|
||||||
|
Ember.run.scheduleOnce('afterRender', this, this.scrolled);
|
||||||
|
},
|
||||||
|
|
||||||
|
didInsertElement() {
|
||||||
|
this._super();
|
||||||
|
const debouncedScroll = () => Ember.run.debounce(this, this._scrollTriggered, 10);
|
||||||
|
|
||||||
|
this.appEvents.on('post-stream:refresh', debouncedScroll);
|
||||||
|
$(document).bind('touchmove.post-stream', debouncedScroll);
|
||||||
|
$(window).bind('scroll.post-stream', debouncedScroll);
|
||||||
|
this._scrollTriggered();
|
||||||
|
|
||||||
|
this.appEvents.on('post-stream:posted', staged => {
|
||||||
|
const disableJumpReply = this.currentUser.get('disable_jump_reply');
|
||||||
|
|
||||||
|
this.queueRerender(() => {
|
||||||
|
if (staged && !disableJumpReply) {
|
||||||
|
const postNumber = staged.get('post_number');
|
||||||
|
DiscourseURL.jumpToPost(postNumber, { skipIfOnScreen: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$().on('mouseenter.post-stream', 'button.widget-button', e => {
|
||||||
|
$('button.widget-button').removeClass('d-hover');
|
||||||
|
$(e.target).addClass('d-hover');
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$().on('mouseleave.post-stream', 'button.widget-button', () => {
|
||||||
|
$('button.widget-button').removeClass('d-hover');
|
||||||
|
});
|
||||||
|
|
||||||
|
this.appEvents.on('post-stream:refresh', args => {
|
||||||
|
if (args) {
|
||||||
|
if (args.id) {
|
||||||
|
keyDirty(`post-${args.id}`);
|
||||||
|
} else if (args.force) {
|
||||||
|
keyDirty(`*`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.queueRerender();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
willDestroyElement() {
|
||||||
|
this._super();
|
||||||
|
$(document).unbind('touchmove.post-stream');
|
||||||
|
$(window).unbind('scroll.post-stream');
|
||||||
|
this.appEvents.off('post-stream:refresh');
|
||||||
|
this.$().off('mouseenter.post-stream');
|
||||||
|
this.$().off('mouseleave.post-stream');
|
||||||
|
this.appEvents.off('post-stream:refresh');
|
||||||
|
this.appEvents.off('post-stream:posted');
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
@ -1,33 +1,17 @@
|
|||||||
import { autoUpdatingRelativeAge } from 'discourse/lib/formatter';
|
import { autoUpdatingRelativeAge } from 'discourse/lib/formatter';
|
||||||
import computed from 'ember-addons/ember-computed-decorators';
|
|
||||||
|
|
||||||
const icons = {
|
export function actionDescriptionHtml(actionCode, createdAt, username) {
|
||||||
'closed.enabled': 'lock',
|
const dt = new Date(createdAt);
|
||||||
'closed.disabled': 'unlock-alt',
|
const when = autoUpdatingRelativeAge(dt, { format: 'medium-with-ago' });
|
||||||
'autoclosed.enabled': 'lock',
|
const who = username ? `<a class="mention" href="/users/${username}">@${username}</a>` : "";
|
||||||
'autoclosed.disabled': 'unlock-alt',
|
return I18n.t(`action_codes.${actionCode}`, { who, when }).htmlSafe();
|
||||||
'archived.enabled': 'folder',
|
}
|
||||||
'archived.disabled': 'folder-open',
|
|
||||||
'pinned.enabled': 'thumb-tack',
|
|
||||||
'pinned.disabled': 'thumb-tack unpinned',
|
|
||||||
'pinned_globally.enabled': 'thumb-tack',
|
|
||||||
'pinned_globally.disabled': 'thumb-tack unpinned',
|
|
||||||
'visible.enabled': 'eye',
|
|
||||||
'visible.disabled': 'eye-slash',
|
|
||||||
'split_topic': 'sign-out',
|
|
||||||
'invited_user': 'plus-circle',
|
|
||||||
'removed_user': 'minus-circle'
|
|
||||||
};
|
|
||||||
|
|
||||||
export function actionDescription(actionCode, createdAt, username) {
|
export function actionDescription(actionCode, createdAt, username) {
|
||||||
return function() {
|
return function() {
|
||||||
const ac = this.get(actionCode);
|
const ac = this.get(actionCode);
|
||||||
if (ac) {
|
if (ac) {
|
||||||
const dt = new Date(this.get(createdAt));
|
return actionDescriptionHtml(ac, this.get(createdAt), this.get(username));
|
||||||
const when = autoUpdatingRelativeAge(dt, { format: 'medium-with-ago' });
|
|
||||||
const u = this.get(username);
|
|
||||||
const who = u ? `<a class="mention" href="/users/${u}">@${u}</a>` : "";
|
|
||||||
return I18n.t(`action_codes.${ac}`, { who, when }).htmlSafe();
|
|
||||||
}
|
}
|
||||||
}.property(actionCode, createdAt);
|
}.property(actionCode, createdAt);
|
||||||
}
|
}
|
||||||
@ -38,11 +22,6 @@ export default Ember.Component.extend({
|
|||||||
|
|
||||||
description: actionDescription('actionCode', 'post.created_at', 'post.action_code_who'),
|
description: actionDescription('actionCode', 'post.created_at', 'post.action_code_who'),
|
||||||
|
|
||||||
@computed("actionCode")
|
|
||||||
icon(actionCode) {
|
|
||||||
return icons[actionCode] || 'exclamation';
|
|
||||||
},
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
edit() {
|
edit() {
|
||||||
this.sendAction('editPost', this.get('post'));
|
this.sendAction('editPost', this.get('post'));
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
import SmallActionComponent from 'discourse/components/small-action';
|
|
||||||
|
|
||||||
export default SmallActionComponent.extend({
|
|
||||||
classNames: ['time-gap'],
|
|
||||||
classNameBindings: ['hideTimeGap::hidden'],
|
|
||||||
hideTimeGap: Em.computed.alias('postStream.hasNoFilters'),
|
|
||||||
icon: 'clock-o',
|
|
||||||
|
|
||||||
description: function() {
|
|
||||||
const gapDays = this.get('daysAgo');
|
|
||||||
if (gapDays < 30) {
|
|
||||||
return I18n.t('dates.later.x_days', {count: gapDays});
|
|
||||||
} else if (gapDays < 365) {
|
|
||||||
const gapMonths = Math.floor(gapDays / 30);
|
|
||||||
return I18n.t('dates.later.x_months', {count: gapMonths});
|
|
||||||
} else {
|
|
||||||
const gapYears = Math.floor(gapDays / 365);
|
|
||||||
return I18n.t('dates.later.x_years', {count: gapYears});
|
|
||||||
}
|
|
||||||
}.property(),
|
|
||||||
});
|
|
@ -1,12 +0,0 @@
|
|||||||
export default Ember.Component.extend({
|
|
||||||
layoutName: 'components/toggle-summary',
|
|
||||||
tagName: 'section',
|
|
||||||
classNames: ['information'],
|
|
||||||
postStream: Em.computed.alias('topic.postStream'),
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
toggleSummary() {
|
|
||||||
this.get('postStream').toggleSummary();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
@ -19,7 +19,7 @@ export default Ember.Component.extend({
|
|||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
skipHeader: function() {
|
skipHeader: function() {
|
||||||
return Discourse.Mobile.mobileView;
|
return this.site.mobileView;
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
showLikes: function(){
|
showLikes: function(){
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
var LINKS_SHOWN = 5;
|
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
|
||||||
mapCollapsed: true,
|
|
||||||
layoutName: 'components/topic-map',
|
|
||||||
details: Em.computed.alias('topic.details'),
|
|
||||||
allLinksShown: false,
|
|
||||||
|
|
||||||
init: function() {
|
|
||||||
this._super();
|
|
||||||
|
|
||||||
// If the topic has a summary, expand the map by default
|
|
||||||
this.set('mapCollapsed', Discourse.Mobile.mobileView || (!this.get('topic.has_summary')));
|
|
||||||
},
|
|
||||||
|
|
||||||
showPosterAvatar: Em.computed.gt('topic.posts_count', 2),
|
|
||||||
|
|
||||||
toggleMapClass: function() {
|
|
||||||
return this.get('mapCollapsed') ? 'chevron-down' : 'chevron-up';
|
|
||||||
}.property('mapCollapsed'),
|
|
||||||
|
|
||||||
showAllLinksControls: function() {
|
|
||||||
if (this.get('allLinksShown')) return false;
|
|
||||||
if ((this.get('details.links.length') || 0) <= LINKS_SHOWN) return false;
|
|
||||||
return true;
|
|
||||||
}.property('allLinksShown', 'topic.details.links'),
|
|
||||||
|
|
||||||
infoLinks: function() {
|
|
||||||
var allLinks = this.get('details.links');
|
|
||||||
if (Em.isNone(allLinks)) return [];
|
|
||||||
|
|
||||||
if (this.get('allLinksShown')) return allLinks;
|
|
||||||
return allLinks.slice(0, LINKS_SHOWN);
|
|
||||||
|
|
||||||
}.property('details.links', 'allLinksShown'),
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
toggleMap: function() {
|
|
||||||
this.toggleProperty('mapCollapsed');
|
|
||||||
},
|
|
||||||
|
|
||||||
showAllLinks: function() {
|
|
||||||
this.set('allLinksShown', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,18 +0,0 @@
|
|||||||
export default Ember.Component.extend({
|
|
||||||
|
|
||||||
postStream: Em.computed.alias('participant.topic.postStream'),
|
|
||||||
showPostCount: Em.computed.gte('participant.post_count', 2),
|
|
||||||
|
|
||||||
toggled: function() {
|
|
||||||
return this.get('postStream.userFilters').contains(this.get('participant.username'));
|
|
||||||
}.property('postStream.userFilters.[]'),
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
toggle() {
|
|
||||||
const postStream = this.get('postStream');
|
|
||||||
if (postStream) {
|
|
||||||
postStream.toggleParticipant(this.get('participant.username'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,26 +0,0 @@
|
|||||||
import StringBuffer from 'discourse/mixins/string-buffer';
|
|
||||||
|
|
||||||
export default Ember.Component.extend(StringBuffer, {
|
|
||||||
rerenderTriggers: ['users.length'],
|
|
||||||
|
|
||||||
renderString(buffer) {
|
|
||||||
const users = this.get('users');
|
|
||||||
if (users && users.get('length') > 0) {
|
|
||||||
buffer.push("<div class='who-liked'>");
|
|
||||||
let iconsHtml = "";
|
|
||||||
users.forEach(function(u) {
|
|
||||||
iconsHtml += "<a href=\"" + Discourse.getURL("/users/") + u.get('username_lower') + "\" data-user-card=\"" + u.get('username') + "\">";
|
|
||||||
iconsHtml += Discourse.Utilities.avatarImg({
|
|
||||||
size: 'small',
|
|
||||||
avatarTemplate: u.get('avatar_template'),
|
|
||||||
title: u.get('username')
|
|
||||||
});
|
|
||||||
iconsHtml += "</a>";
|
|
||||||
});
|
|
||||||
buffer.push(I18n.t('post.actions.people.like',{icons: iconsHtml}));
|
|
||||||
buffer.push("</div>");
|
|
||||||
} else {
|
|
||||||
buffer.push("<span></span>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
@ -263,7 +263,6 @@ export default Ember.Controller.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
var staged = false;
|
var staged = false;
|
||||||
const disableJumpReply = Discourse.User.currentProp('disable_jump_reply');
|
|
||||||
|
|
||||||
// TODO: This should not happen in model
|
// TODO: This should not happen in model
|
||||||
const imageSizes = {};
|
const imageSizes = {};
|
||||||
@ -281,6 +280,7 @@ export default Ember.Controller.extend({
|
|||||||
self.send('postWasEnqueued', result.responseJson);
|
self.send('postWasEnqueued', result.responseJson);
|
||||||
self.destroyDraft();
|
self.destroyDraft();
|
||||||
self.close();
|
self.close();
|
||||||
|
self.appEvents.trigger('post-stream:refresh');
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +288,15 @@ export default Ember.Controller.extend({
|
|||||||
if (result.responseJson.action === "create_post" || self.get('replyAsNewTopicDraft')) {
|
if (result.responseJson.action === "create_post" || self.get('replyAsNewTopicDraft')) {
|
||||||
self.destroyDraft();
|
self.destroyDraft();
|
||||||
}
|
}
|
||||||
|
if (self.get('model.action') === 'edit') {
|
||||||
|
self.appEvents.trigger('post-stream:refresh', { id: parseInt(result.responseJson.id) });
|
||||||
|
} else {
|
||||||
|
self.appEvents.trigger('post-stream:refresh');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.responseJson.action === "create_post") {
|
||||||
|
self.appEvents.trigger('post:highlight', result.payload.post_number);
|
||||||
|
}
|
||||||
self.close();
|
self.close();
|
||||||
|
|
||||||
const currentUser = Discourse.User.current();
|
const currentUser = Discourse.User.current();
|
||||||
@ -298,14 +306,14 @@ export default Ember.Controller.extend({
|
|||||||
currentUser.set('reply_count', currentUser.get('reply_count') + 1);
|
currentUser.set('reply_count', currentUser.get('reply_count') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO disableJumpReply is super crude, it needs to provide some sort
|
const disableJumpReply = Discourse.User.currentProp('disable_jump_reply');
|
||||||
// of notification to the end user
|
|
||||||
if (!composer.get('replyingToTopic') || !disableJumpReply) {
|
if (!composer.get('replyingToTopic') || !disableJumpReply) {
|
||||||
const post = result.target;
|
const post = result.target;
|
||||||
if (post && !staged) {
|
if (post && !staged) {
|
||||||
DiscourseURL.routeTo(post.get('url'));
|
DiscourseURL.routeTo(post.get('url'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
composer.set('disableDrafts', false);
|
composer.set('disableDrafts', false);
|
||||||
self.appEvents.one('composer:opened', () => bootbox.alert(error));
|
self.appEvents.one('composer:opened', () => bootbox.alert(error));
|
||||||
@ -316,18 +324,10 @@ export default Ember.Controller.extend({
|
|||||||
staged = composer.get('stagedPost');
|
staged = composer.get('stagedPost');
|
||||||
}
|
}
|
||||||
|
|
||||||
Em.run.schedule('afterRender', function() {
|
this.appEvents.trigger('post-stream:posted', staged);
|
||||||
if (staged && !disableJumpReply) {
|
|
||||||
const postNumber = staged.get('post_number');
|
|
||||||
DiscourseURL.jumpToPost(postNumber, { skipIfOnScreen: true });
|
|
||||||
self.appEvents.trigger('post:highlight', postNumber);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.messageBus.pause();
|
this.messageBus.pause();
|
||||||
promise.finally(function(){
|
promise.finally(() => this.messageBus.resume());
|
||||||
self.messageBus.resume();
|
|
||||||
});
|
|
||||||
|
|
||||||
return promise;
|
return promise;
|
||||||
},
|
},
|
||||||
@ -587,14 +587,6 @@ export default Ember.Controller.extend({
|
|||||||
$('.d-editor-input').autocomplete({ cancel: true });
|
$('.d-editor-input').autocomplete({ cancel: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
showOptions() {
|
|
||||||
var _ref;
|
|
||||||
return (_ref = this.get('controllers.modal')) ? _ref.show(Discourse.ArchetypeOptionsModalView.create({
|
|
||||||
archetype: this.get('model.archetype'),
|
|
||||||
metaData: this.get('model.metaData')
|
|
||||||
})) : void 0;
|
|
||||||
},
|
|
||||||
|
|
||||||
canEdit: function() {
|
canEdit: function() {
|
||||||
return this.get("model.action") === "edit" && Discourse.User.current().get("can_edit");
|
return this.get("model.action") === "edit" && Discourse.User.current().get("can_edit");
|
||||||
}.property("model.action"),
|
}.property("model.action"),
|
||||||
|
@ -89,7 +89,6 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
createFlag(opts) {
|
createFlag(opts) {
|
||||||
const self = this;
|
|
||||||
let postAction; // an instance of ActionSummary
|
let postAction; // an instance of ActionSummary
|
||||||
|
|
||||||
if (!this.get('flagTopic')) {
|
if (!this.get('flagTopic')) {
|
||||||
@ -103,13 +102,14 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||||||
|
|
||||||
this.send('hideModal');
|
this.send('hideModal');
|
||||||
|
|
||||||
postAction.act(this.get('model'), params).then(function() {
|
postAction.act(this.get('model'), params).then(() => {
|
||||||
self.send('closeModal');
|
this.send('closeModal');
|
||||||
if (params.message) {
|
if (params.message) {
|
||||||
self.set('message', '');
|
this.set('message', '');
|
||||||
}
|
}
|
||||||
}, function(errors) {
|
this.appEvents.trigger('post-stream:refresh', { id: this.get('model.id') });
|
||||||
self.send('closeModal');
|
}).catch(errors => {
|
||||||
|
this.send('closeModal');
|
||||||
if (errors && errors.responseText) {
|
if (errors && errors.responseText) {
|
||||||
bootbox.alert($.parseJSON(errors.responseText).errors);
|
bootbox.alert($.parseJSON(errors.responseText).errors);
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,7 +10,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||||||
revisionsTextKey: "post.revisions.controls.comparing_previous_to_current_out_of_total",
|
revisionsTextKey: "post.revisions.controls.comparing_previous_to_current_out_of_total",
|
||||||
|
|
||||||
_changeViewModeOnMobile: function() {
|
_changeViewModeOnMobile: function() {
|
||||||
if (Discourse.Mobile.mobileView) { this.set("viewMode", "inline"); }
|
if (this.site.mobileView) { this.set("viewMode", "inline"); }
|
||||||
}.on("init"),
|
}.on("init"),
|
||||||
|
|
||||||
refresh(postId, postVersion) {
|
refresh(postId, postVersion) {
|
||||||
|
@ -61,8 +61,10 @@ export default Ember.Controller.extend({
|
|||||||
// containing a single invisible character
|
// containing a single invisible character
|
||||||
markerElement.appendChild(document.createTextNode("\ufeff"));
|
markerElement.appendChild(document.createTextNode("\ufeff"));
|
||||||
|
|
||||||
|
const isMobileDevice = this.site.isMobileDevice;
|
||||||
|
|
||||||
// collapse the range at the beginning/end of the selection
|
// collapse the range at the beginning/end of the selection
|
||||||
range.collapse(!Discourse.Mobile.isMobileDevice);
|
range.collapse(!isMobileDevice);
|
||||||
// and insert it at the start of our selection range
|
// and insert it at the start of our selection range
|
||||||
range.insertNode(markerElement);
|
range.insertNode(markerElement);
|
||||||
|
|
||||||
@ -83,7 +85,7 @@ export default Ember.Controller.extend({
|
|||||||
let topOff = markerOffset.top;
|
let topOff = markerOffset.top;
|
||||||
let leftOff = markerOffset.left;
|
let leftOff = markerOffset.left;
|
||||||
|
|
||||||
if (Discourse.Mobile.isMobileDevice) {
|
if (isMobileDevice) {
|
||||||
topOff = topOff + 20;
|
topOff = topOff + 20;
|
||||||
leftOff = Math.min(leftOff + 10, $(window).width() - $quoteButton.outerWidth());
|
leftOff = Math.min(leftOff + 10, $(window).width() - $quoteButton.outerWidth());
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,7 +19,6 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
loadedAllPosts: Em.computed.or('model.postStream.loadedAllPosts', 'model.postStream.loadingLastPost'),
|
loadedAllPosts: Em.computed.or('model.postStream.loadedAllPosts', 'model.postStream.loadingLastPost'),
|
||||||
enteredAt: null,
|
enteredAt: null,
|
||||||
retrying: false,
|
retrying: false,
|
||||||
firstPostExpanded: false,
|
|
||||||
adminMenuVisible: false,
|
adminMenuVisible: false,
|
||||||
|
|
||||||
showRecover: Em.computed.and('model.deleted', 'model.details.can_recover'),
|
showRecover: Em.computed.and('model.deleted', 'model.details.can_recover'),
|
||||||
@ -100,7 +99,64 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
DiscourseURL.routeTo(url);
|
DiscourseURL.routeTo(url);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
selectedQuery: function() {
|
||||||
|
return post => this.postSelected(post);
|
||||||
|
}.property(),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
|
||||||
|
fillGapBefore(args) {
|
||||||
|
return this.get('model.postStream').fillGapBefore(args.post, args.gap);
|
||||||
|
},
|
||||||
|
|
||||||
|
fillGapAfter(args) {
|
||||||
|
return this.get('model.postStream').fillGapAfter(args.post, args.gap);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Called the the topmost visible post on the page changes.
|
||||||
|
topVisibleChanged(event) {
|
||||||
|
const { post, refresh } = event;
|
||||||
|
|
||||||
|
if (!post) { return; }
|
||||||
|
|
||||||
|
const postStream = this.get('model.postStream');
|
||||||
|
const firstLoadedPost = postStream.get('posts.firstObject');
|
||||||
|
|
||||||
|
const currentPostNumber = post.get('post_number');
|
||||||
|
this.set('model.currentPost', currentPostNumber);
|
||||||
|
this.send('postChangedRoute', currentPostNumber);
|
||||||
|
|
||||||
|
if (post.get('post_number') === 1) { return; }
|
||||||
|
|
||||||
|
if (firstLoadedPost && firstLoadedPost === post) {
|
||||||
|
postStream.prependMore().then(() => refresh());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Called the the bottommost visible post on the page changes.
|
||||||
|
bottomVisibleChanged(event) {
|
||||||
|
const { post, refresh } = event;
|
||||||
|
|
||||||
|
const postStream = this.get('model.postStream');
|
||||||
|
const lastLoadedPost = postStream.get('posts.lastObject');
|
||||||
|
|
||||||
|
this.set('controllers.topic-progress.progressPosition', postStream.progressIndexOfPost(post));
|
||||||
|
|
||||||
|
if (lastLoadedPost && lastLoadedPost === post && postStream.get('canAppendMore')) {
|
||||||
|
postStream.appendMore().then(() => refresh());
|
||||||
|
// show loading stuff
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
toggleSummary() {
|
||||||
|
return this.get('model.postStream').toggleSummary();
|
||||||
|
},
|
||||||
|
|
||||||
|
removeAllowedUser(user) {
|
||||||
|
return this.get('model.details').removeAllowedUser(user);
|
||||||
|
},
|
||||||
|
|
||||||
showTopicAdminMenu() {
|
showTopicAdminMenu() {
|
||||||
this.set('adminMenuVisible', true);
|
this.set('adminMenuVisible', true);
|
||||||
},
|
},
|
||||||
@ -113,7 +169,6 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
this.deleteTopic();
|
this.deleteTopic();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
archiveMessage() {
|
archiveMessage() {
|
||||||
const topic = this.get('model');
|
const topic = this.get('model');
|
||||||
topic.archiveMessage().then(()=>{
|
topic.archiveMessage().then(()=>{
|
||||||
@ -176,8 +231,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
|
|
||||||
// Deleting the first post deletes the topic
|
// Deleting the first post deletes the topic
|
||||||
if (post.get('post_number') === 1) {
|
if (post.get('post_number') === 1) {
|
||||||
this.deleteTopic();
|
return this.deleteTopic();
|
||||||
return;
|
|
||||||
} else if (!post.can_delete) {
|
} else if (!post.can_delete) {
|
||||||
// check if current user can delete post
|
// check if current user can delete post
|
||||||
return false;
|
return false;
|
||||||
@ -210,7 +264,9 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
post.destroy(user).catch(function(error) {
|
return post.destroy(user).then(() => {
|
||||||
|
this.appEvents.trigger('post-stream:refresh');
|
||||||
|
}).catch(error => {
|
||||||
popupAjaxError(error);
|
popupAjaxError(error);
|
||||||
post.undoDeleteState();
|
post.undoDeleteState();
|
||||||
});
|
});
|
||||||
@ -245,14 +301,17 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
toggleBookmark(post) {
|
toggleBookmark(post) {
|
||||||
if (!Discourse.User.current()) {
|
if (!this.currentUser) {
|
||||||
alert(I18n.t("bookmarks.not_bookmarked"));
|
alert(I18n.t("bookmarks.not_bookmarked"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (post) {
|
if (post) {
|
||||||
return post.toggleBookmark().catch(popupAjaxError);
|
return post.toggleBookmark().catch(popupAjaxError);
|
||||||
} else {
|
} else {
|
||||||
return this.get("model").toggleBookmark();
|
return this.get("model").toggleBookmark().then(changedIds => {
|
||||||
|
if (!changedIds) { return; }
|
||||||
|
changedIds.forEach(id => this.appEvents.trigger('post-stream:refresh', { id }));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -261,18 +320,20 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
selectAll() {
|
selectAll() {
|
||||||
const posts = this.get('model.postStream.posts'),
|
const posts = this.get('model.postStream.posts');
|
||||||
selectedPosts = this.get('selectedPosts');
|
const selectedPosts = this.get('selectedPosts');
|
||||||
if (posts) {
|
if (posts) {
|
||||||
selectedPosts.addObjects(posts);
|
selectedPosts.addObjects(posts);
|
||||||
}
|
}
|
||||||
this.set('allPostsSelected', true);
|
this.set('allPostsSelected', true);
|
||||||
|
this.appEvents.trigger('post-stream:refresh', { force: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
deselectAll() {
|
deselectAll() {
|
||||||
this.get('selectedPosts').clear();
|
this.get('selectedPosts').clear();
|
||||||
this.get('selectedReplies').clear();
|
this.get('selectedReplies').clear();
|
||||||
this.set('allPostsSelected', false);
|
this.set('allPostsSelected', false);
|
||||||
|
this.appEvents.trigger('post-stream:refresh', { force: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleParticipant(user) {
|
toggleParticipant(user) {
|
||||||
@ -293,6 +354,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
|
|
||||||
toggleMultiSelect() {
|
toggleMultiSelect() {
|
||||||
this.toggleProperty('multiSelect');
|
this.toggleProperty('multiSelect');
|
||||||
|
this.appEvents.trigger('post-stream:refresh', { force: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
finishedEditingTopic() {
|
finishedEditingTopic() {
|
||||||
@ -324,27 +386,26 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
deleteSelected() {
|
deleteSelected() {
|
||||||
const self = this;
|
bootbox.confirm(I18n.t("post.delete.confirm", { count: this.get('selectedPostsCount')}), result => {
|
||||||
bootbox.confirm(I18n.t("post.delete.confirm", { count: this.get('selectedPostsCount')}), function(result) {
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|
||||||
// If all posts are selected, it's the same thing as deleting the topic
|
// If all posts are selected, it's the same thing as deleting the topic
|
||||||
if (self.get('allPostsSelected')) {
|
if (this.get('allPostsSelected')) {
|
||||||
return self.deleteTopic();
|
return this.deleteTopic();
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedPosts = self.get('selectedPosts'),
|
const selectedPosts = this.get('selectedPosts');
|
||||||
selectedReplies = self.get('selectedReplies'),
|
const selectedReplies = this.get('selectedReplies');
|
||||||
postStream = self.get('model.postStream'),
|
const postStream = this.get('model.postStream');
|
||||||
toRemove = [];
|
|
||||||
|
|
||||||
Discourse.Post.deleteMany(selectedPosts, selectedReplies);
|
Discourse.Post.deleteMany(selectedPosts, selectedReplies);
|
||||||
postStream.get('posts').forEach(function (p) {
|
postStream.get('posts').forEach(p => {
|
||||||
if (self.postSelected(p)) { toRemove.addObject(p); }
|
if (this.postSelected(p)) {
|
||||||
|
p.set('deleted_at', new Date());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
postStream.removePosts(toRemove);
|
this.send('toggleMultiSelect');
|
||||||
self.send('toggleMultiSelect');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -447,18 +508,6 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
expandFirstPost(post) {
|
|
||||||
const self = this;
|
|
||||||
this.set('loadingExpanded', true);
|
|
||||||
post.expand().then(function() {
|
|
||||||
self.set('firstPostExpanded', true);
|
|
||||||
}).catch(function(error) {
|
|
||||||
bootbox.alert($.parseJSON(error.responseText).errors);
|
|
||||||
}).finally(function() {
|
|
||||||
self.set('loadingExpanded', false);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
retryLoading() {
|
retryLoading() {
|
||||||
const self = this;
|
const self = this;
|
||||||
self.set('retrying', true);
|
self.set('retrying', true);
|
||||||
@ -470,22 +519,22 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
toggleWiki(post) {
|
toggleWiki(post) {
|
||||||
post.updatePostField('wiki', !post.get('wiki'));
|
return post.updatePostField('wiki', !post.get('wiki'));
|
||||||
},
|
},
|
||||||
|
|
||||||
togglePostType(post) {
|
togglePostType(post) {
|
||||||
const regular = this.site.get('post_types.regular');
|
const regular = this.site.get('post_types.regular');
|
||||||
const moderator = this.site.get('post_types.moderator_action');
|
const moderator = this.site.get('post_types.moderator_action');
|
||||||
|
|
||||||
post.updatePostField('post_type', post.get('post_type') === moderator ? regular : moderator);
|
return post.updatePostField('post_type', post.get('post_type') === moderator ? regular : moderator);
|
||||||
},
|
},
|
||||||
|
|
||||||
rebakePost(post) {
|
rebakePost(post) {
|
||||||
post.rebake();
|
return post.rebake();
|
||||||
},
|
},
|
||||||
|
|
||||||
unhidePost(post) {
|
unhidePost(post) {
|
||||||
post.unhide();
|
return post.unhide();
|
||||||
},
|
},
|
||||||
|
|
||||||
changePostOwner(post) {
|
changePostOwner(post) {
|
||||||
@ -498,11 +547,6 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
this.send('togglePinnedForUser');
|
this.send('togglePinnedForUser');
|
||||||
},
|
},
|
||||||
|
|
||||||
showExpandButton: function() {
|
|
||||||
const post = this.get('post');
|
|
||||||
return post.get('post_number') === 1 && post.get('topic.expandable_first_post');
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
canMergeTopic: function() {
|
canMergeTopic: function() {
|
||||||
if (!this.get('model.details.can_move_posts')) return false;
|
if (!this.get('model.details.can_move_posts')) return false;
|
||||||
return this.get('selectedPostsCount') > 0;
|
return this.get('selectedPostsCount') > 0;
|
||||||
@ -598,9 +642,10 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
// Unsubscribe before subscribing again
|
// Unsubscribe before subscribing again
|
||||||
this.unsubscribe();
|
this.unsubscribe();
|
||||||
|
|
||||||
const self = this;
|
const refresh = (id) => this.appEvents.trigger('post-stream:refresh', { id });
|
||||||
this.messageBus.subscribe("/topic/" + this.get('model.id'), function(data) {
|
|
||||||
const topic = self.get('model');
|
this.messageBus.subscribe("/topic/" + this.get('model.id'), data => {
|
||||||
|
const topic = this.get('model');
|
||||||
|
|
||||||
if (data.notification_level_change) {
|
if (data.notification_level_change) {
|
||||||
topic.set('details.notification_level', data.notification_level_change);
|
topic.set('details.notification_level', data.notification_level_change);
|
||||||
@ -608,26 +653,26 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const postStream = self.get('model.postStream');
|
const postStream = this.get('model.postStream');
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case "revised":
|
case "revised":
|
||||||
case "acted":
|
case "acted":
|
||||||
case "rebaked": {
|
case "rebaked": {
|
||||||
// TODO we could update less data for "acted" (only post actions)
|
// TODO we could update less data for "acted" (only post actions)
|
||||||
postStream.triggerChangedPost(data.id, data.updated_at);
|
postStream.triggerChangedPost(data.id, data.updated_at).then(() => refresh(data.id));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "deleted": {
|
case "deleted": {
|
||||||
postStream.triggerDeletedPost(data.id, data.post_number);
|
postStream.triggerDeletedPost(data.id, data.post_number).then(() => refresh(data.id));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "recovered": {
|
case "recovered": {
|
||||||
postStream.triggerRecoveredPost(data.id, data.post_number);
|
postStream.triggerRecoveredPost(data.id, data.post_number).then(() => refresh(data.id));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "created": {
|
case "created": {
|
||||||
postStream.triggerNewPostInStream(data.id);
|
postStream.triggerNewPostInStream(data.id).then(() => refresh());
|
||||||
if (self.get('currentUser.id') !== data.user_id) {
|
if (this.get('currentUser.id') !== data.user_id) {
|
||||||
Discourse.notifyBackgroundCountIncrement();
|
Discourse.notifyBackgroundCountIncrement();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -673,23 +718,17 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// If our current post is changed, notify the router
|
|
||||||
_currentPostChanged: function() {
|
|
||||||
const currentPost = this.get('model.currentPost');
|
|
||||||
if (currentPost) {
|
|
||||||
this.send('postChangedRoute', currentPost);
|
|
||||||
}
|
|
||||||
}.observes('model.currentPost'),
|
|
||||||
|
|
||||||
readPosts(topicId, postNumbers) {
|
readPosts(topicId, postNumbers) {
|
||||||
const topic = this.get("model"),
|
const topic = this.get("model");
|
||||||
postStream = topic.get("postStream");
|
const postStream = topic.get("postStream");
|
||||||
|
|
||||||
|
if (topic.get('id') === topicId) {
|
||||||
|
|
||||||
if (topic.get("id") === topicId) {
|
|
||||||
// TODO identity map for postNumber
|
// TODO identity map for postNumber
|
||||||
_.each(postStream.get('posts'), post => {
|
postStream.get('posts').forEach(post => {
|
||||||
if (_.include(postNumbers, post.post_number) && !post.read) {
|
if (!post.read && postNumbers.indexOf(post.post_number) !== -1) {
|
||||||
post.set("read", true);
|
post.set('read', true);
|
||||||
|
this.appEvents.trigger('post-stream:refresh', { id: post.id });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -709,59 +748,6 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Called the the topmost visible post on the page changes.
|
|
||||||
topVisibleChanged(post) {
|
|
||||||
if (!post) { return; }
|
|
||||||
|
|
||||||
const postStream = this.get('model.postStream');
|
|
||||||
const firstLoadedPost = postStream.get('posts.firstObject');
|
|
||||||
|
|
||||||
this.set('model.currentPost', post.get('post_number'));
|
|
||||||
|
|
||||||
if (post.get('post_number') === 1) { return; }
|
|
||||||
|
|
||||||
if (firstLoadedPost && firstLoadedPost === post) {
|
|
||||||
// Note: jQuery shouldn't be done in a controller, but how else can we
|
|
||||||
// trigger a scroll after a promise resolves in a controller? We need
|
|
||||||
// to do this to preserve upwards infinte scrolling.
|
|
||||||
const $body = $('body');
|
|
||||||
const elemId = `#post_${post.get('post_number')}`;
|
|
||||||
const $elem = $(elemId).closest('.post-cloak');
|
|
||||||
const elemPos = $elem.position();
|
|
||||||
const distToElement = elemPos ? $body.scrollTop() - elemPos.top : 0;
|
|
||||||
|
|
||||||
postStream.prependMore().then(function() {
|
|
||||||
Em.run.next(function () {
|
|
||||||
const $refreshedElem = $(elemId).closest('.post-cloak');
|
|
||||||
|
|
||||||
// Quickly going back might mean the element is destroyed
|
|
||||||
const position = $refreshedElem.position();
|
|
||||||
if (position && position.top) {
|
|
||||||
$('html, body').scrollTop(position.top + distToElement);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Called the the bottommost visible post on the page changes.
|
|
||||||
|
|
||||||
@method bottomVisibleChanged
|
|
||||||
@params {Discourse.Post} post that is at the bottom
|
|
||||||
**/
|
|
||||||
bottomVisibleChanged(post) {
|
|
||||||
if (!post) { return; }
|
|
||||||
|
|
||||||
const postStream = this.get('model.postStream');
|
|
||||||
const lastLoadedPost = postStream.get('posts.lastObject');
|
|
||||||
|
|
||||||
this.set('controllers.topic-progress.progressPosition', postStream.progressIndexOfPost(post));
|
|
||||||
|
|
||||||
if (lastLoadedPost && lastLoadedPost === post) {
|
|
||||||
postStream.appendMore();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_showFooter: function() {
|
_showFooter: function() {
|
||||||
const showFooter = this.get("model.postStream.loaded") && this.get("model.postStream.loadedAllPosts");
|
const showFooter = this.get("model.postStream.loaded") && this.get("model.postStream.loadedAllPosts");
|
||||||
|
@ -45,7 +45,7 @@ export default Ember.Controller.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't show on mobile
|
// Don't show on mobile
|
||||||
if (Discourse.Mobile.mobileView) {
|
if (this.site.mobileView) {
|
||||||
const url = "/users/" + username;
|
const url = "/users/" + username;
|
||||||
DiscourseURL.routeTo(url);
|
DiscourseURL.routeTo(url);
|
||||||
return;
|
return;
|
||||||
|
@ -2,7 +2,6 @@ import computed from 'ember-addons/ember-computed-decorators';
|
|||||||
import Topic from 'discourse/models/topic';
|
import Topic from 'discourse/models/topic';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
|
|
||||||
needs: ["application", "user-topics-list", "user"],
|
needs: ["application", "user-topics-list", "user"],
|
||||||
pmView: false,
|
pmView: false,
|
||||||
viewingSelf: Em.computed.alias('controllers.user.viewingSelf'),
|
viewingSelf: Em.computed.alias('controllers.user.viewingSelf'),
|
||||||
@ -11,10 +10,6 @@ export default Ember.Controller.extend({
|
|||||||
selected: Em.computed.alias('controllers.user-topics-list.selected'),
|
selected: Em.computed.alias('controllers.user-topics-list.selected'),
|
||||||
bulkSelectEnabled: Em.computed.alias('controllers.user-topics-list.bulkSelectEnabled'),
|
bulkSelectEnabled: Em.computed.alias('controllers.user-topics-list.bulkSelectEnabled'),
|
||||||
|
|
||||||
mobileView: function() {
|
|
||||||
return Discourse.Mobile.mobileView;
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
showNewPM: function(){
|
showNewPM: function(){
|
||||||
return this.get('controllers.user.viewingSelf') &&
|
return this.get('controllers.user.viewingSelf') &&
|
||||||
Discourse.User.currentProp('can_send_private_messages');
|
Discourse.User.currentProp('can_send_private_messages');
|
||||||
|
@ -22,13 +22,11 @@ function loadingResolver(cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseName(fullName) {
|
function parseName(fullName) {
|
||||||
/*jshint validthis:true */
|
|
||||||
|
|
||||||
const nameParts = fullName.split(":"),
|
const nameParts = fullName.split(":"),
|
||||||
type = nameParts[0], fullNameWithoutType = nameParts[1],
|
type = nameParts[0], fullNameWithoutType = nameParts[1],
|
||||||
name = fullNameWithoutType,
|
name = fullNameWithoutType,
|
||||||
namespace = get(this, 'namespace'),
|
namespace = get(this, 'namespace'),
|
||||||
root = namespace;
|
root = namespace;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fullName: fullName,
|
fullName: fullName,
|
||||||
@ -85,6 +83,10 @@ export default Ember.DefaultResolver.extend({
|
|||||||
return module;
|
return module;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
resolveWidget(parsedName) {
|
||||||
|
return this.customResolve(parsedName) || this._super(parsedName);
|
||||||
|
},
|
||||||
|
|
||||||
resolveAdapter(parsedName) {
|
resolveAdapter(parsedName) {
|
||||||
return this.customResolve(parsedName) || this._super(parsedName);
|
return this.customResolve(parsedName) || this._super(parsedName);
|
||||||
},
|
},
|
||||||
@ -139,7 +141,7 @@ export default Ember.DefaultResolver.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
findMobileTemplate(parsedName) {
|
findMobileTemplate(parsedName) {
|
||||||
if (Discourse.Mobile.mobileView) {
|
if (this.mobileView) {
|
||||||
var mobileParsedName = this.parseName(parsedName.fullName.replace("template:", "template:mobile/"));
|
var mobileParsedName = this.parseName(parsedName.fullName.replace("template:", "template:mobile/"));
|
||||||
return this.findTemplate(mobileParsedName);
|
return this.findTemplate(mobileParsedName);
|
||||||
}
|
}
|
||||||
|
8
app/assets/javascripts/discourse/helpers/as-hash.js.es6
Normal file
8
app/assets/javascripts/discourse/helpers/as-hash.js.es6
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// Note: Later versions of ember include `hash`
|
||||||
|
export default function hashHelper(params) {
|
||||||
|
const hash = {};
|
||||||
|
Object.keys(params.hash).forEach(k => {
|
||||||
|
hash[k] = params.data.view.getStream(params.hash[k]).value();
|
||||||
|
});
|
||||||
|
return hash;
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
import { h } from 'virtual-dom';
|
||||||
import registerUnbound from 'discourse/helpers/register-unbound';
|
import registerUnbound from 'discourse/helpers/register-unbound';
|
||||||
|
|
||||||
function iconClasses(icon, params) {
|
function iconClasses(icon, params) {
|
||||||
@ -7,7 +8,7 @@ function iconClasses(icon, params) {
|
|||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
function iconHTML(icon, params) {
|
export function iconHTML(icon, params) {
|
||||||
params = params || {};
|
params = params || {};
|
||||||
|
|
||||||
var html = "<i class='" + iconClasses(icon, params) + "'";
|
var html = "<i class='" + iconClasses(icon, params) + "'";
|
||||||
@ -19,6 +20,24 @@ function iconHTML(icon, params) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function iconNode(icon, params) {
|
||||||
|
params = params || {};
|
||||||
|
|
||||||
|
const properties = {
|
||||||
|
className: iconClasses(icon, params),
|
||||||
|
attributes: { "aria-hidden": true }
|
||||||
|
};
|
||||||
|
|
||||||
|
if (params.title) { properties.attributes.title = params.title; }
|
||||||
|
|
||||||
|
if (params.label) {
|
||||||
|
return h('i', properties, h('span.sr-only', I18n.t(params.label)));
|
||||||
|
} else {
|
||||||
|
return h('i', properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Ember.Handlebars.helper('fa-icon-bound', function(value, options) {
|
Ember.Handlebars.helper('fa-icon-bound', function(value, options) {
|
||||||
return new Handlebars.SafeString(iconHTML(value, options));
|
return new Handlebars.SafeString(iconHTML(value, options));
|
||||||
});
|
});
|
||||||
@ -26,5 +45,3 @@ Ember.Handlebars.helper('fa-icon-bound', function(value, options) {
|
|||||||
registerUnbound('fa-icon', function(icon, params) {
|
registerUnbound('fa-icon', function(icon, params) {
|
||||||
return new Handlebars.SafeString(iconHTML(icon, params));
|
return new Handlebars.SafeString(iconHTML(icon, params));
|
||||||
});
|
});
|
||||||
|
|
||||||
export { iconHTML };
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
import registerUnbound from 'discourse/helpers/register-unbound';
|
|
||||||
|
|
||||||
registerUnbound('link-domain', function(link) {
|
|
||||||
if (link) {
|
|
||||||
const hasTitle = (!Ember.isEmpty(Em.get(link, 'title')));
|
|
||||||
|
|
||||||
if (hasTitle) {
|
|
||||||
let domain = Ember.get(link, 'domain');
|
|
||||||
if (!Ember.isEmpty(domain)) {
|
|
||||||
const s = domain.split('.');
|
|
||||||
domain = s[s.length-2] + "." + s[s.length-1];
|
|
||||||
return new Handlebars.SafeString("<span class='domain'>" + domain + "</span>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
31
app/assets/javascripts/discourse/helpers/node.js.es6
Normal file
31
app/assets/javascripts/discourse/helpers/node.js.es6
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { h } from 'virtual-dom';
|
||||||
|
import { relativeAge, longDate } from 'discourse/lib/formatter';
|
||||||
|
import { number } from 'discourse/lib/formatter';
|
||||||
|
|
||||||
|
export function dateNode(dt) {
|
||||||
|
if (typeof dt === "string") { dt = new Date(dt); }
|
||||||
|
if (dt) {
|
||||||
|
const attributes = {
|
||||||
|
title: longDate(dt),
|
||||||
|
'data-time': dt.getTime(),
|
||||||
|
'data-format': 'tiny'
|
||||||
|
};
|
||||||
|
|
||||||
|
return h('span.relative-date', { attributes }, relativeAge(dt));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function numberNode(num, opts) {
|
||||||
|
opts = opts || {};
|
||||||
|
num = parseInt(num, 10);
|
||||||
|
if (isNaN(num)) { num = 0; }
|
||||||
|
|
||||||
|
const numString = num.toString();
|
||||||
|
const attributes = { };
|
||||||
|
const formatted = number(num);
|
||||||
|
if (formatted !== numString) {
|
||||||
|
attributes.title = numString;
|
||||||
|
}
|
||||||
|
|
||||||
|
return h('span.number', { className: opts.className, attributes }, formatted);
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { onToolbarCreate } from 'discourse/components/d-editor';
|
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'enable-emoji',
|
name: 'enable-emoji',
|
||||||
@ -7,13 +7,15 @@ export default {
|
|||||||
const siteSettings = container.lookup('site-settings:main');
|
const siteSettings = container.lookup('site-settings:main');
|
||||||
|
|
||||||
if (siteSettings.enable_emoji) {
|
if (siteSettings.enable_emoji) {
|
||||||
onToolbarCreate(toolbar => {
|
withPluginApi('0.1', api => {
|
||||||
toolbar.addButton({
|
api.onToolbarCreate(toolbar => {
|
||||||
id: 'emoji',
|
toolbar.addButton({
|
||||||
group: 'extras',
|
id: 'emoji',
|
||||||
icon: 'smile-o',
|
group: 'extras',
|
||||||
action: 'emoji',
|
icon: 'smile-o',
|
||||||
title: 'composer.emoji'
|
action: 'emoji',
|
||||||
|
title: 'composer.emoji'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
export default {
|
export default {
|
||||||
name: 'ensure-image-dimensions',
|
name: 'ensure-image-dimensions',
|
||||||
after: 'mobile',
|
after: 'mobile',
|
||||||
initialize: function() {
|
initialize(container) {
|
||||||
if (!window) { return; }
|
if (!window) { return; }
|
||||||
|
|
||||||
// This enforces maximum dimensions of images based on site settings
|
// This enforces maximum dimensions of images based on site settings
|
||||||
@ -11,7 +11,8 @@ export default {
|
|||||||
var width = Discourse.SiteSettings.max_image_width;
|
var width = Discourse.SiteSettings.max_image_width;
|
||||||
var height = Discourse.SiteSettings.max_image_height;
|
var height = Discourse.SiteSettings.max_image_height;
|
||||||
|
|
||||||
if (Discourse.Mobile.mobileView) {
|
const site = container.lookup('site:main');
|
||||||
|
if (site.mobileView) {
|
||||||
width = $(window).width() - 20;
|
width = $(window).width() - 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
/**
|
import Mobile from 'discourse/lib/mobile';
|
||||||
Initializes the `Discourse.Mobile` helper object.
|
|
||||||
**/
|
// Initializes the `Mobile` helper object.
|
||||||
export default {
|
export default {
|
||||||
name: 'mobile',
|
name: 'mobile',
|
||||||
after: 'inject-objects',
|
after: 'inject-objects',
|
||||||
|
|
||||||
initialize: function(container) {
|
initialize(container, app) {
|
||||||
Discourse.Mobile.init();
|
Mobile.init();
|
||||||
var site = container.lookup('site:main');
|
const site = container.lookup('site:main');
|
||||||
site.set('mobileView', Discourse.Mobile.mobileView);
|
|
||||||
|
site.set('mobileView', Mobile.mobileView);
|
||||||
|
site.set('isMobileDevice', Mobile.isMobileDevice);
|
||||||
|
|
||||||
|
// This is a bit weird but you can't seem to inject into the resolver?
|
||||||
|
app.registry.resolver.__resolver__.mobileView = Mobile.mobileView;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { cleanDOM } from 'discourse/routes/discourse';
|
import { cleanDOM } from 'discourse/routes/discourse';
|
||||||
import PageTracker from 'discourse/lib/page-tracker';
|
import { startPageTracking, onPageChange } from 'discourse/lib/page-tracker';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "page-tracking",
|
name: "page-tracking",
|
||||||
@ -34,13 +34,12 @@ export default {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const pageTracker = PageTracker.current();
|
startPageTracking(router);
|
||||||
pageTracker.start();
|
|
||||||
|
|
||||||
// Out of the box, Discourse tries to track google analytics
|
// Out of the box, Discourse tries to track google analytics
|
||||||
// if it is present
|
// if it is present
|
||||||
if (typeof window._gaq !== 'undefined') {
|
if (typeof window._gaq !== 'undefined') {
|
||||||
pageTracker.on('change', function(url, title) {
|
onPageChange((url, title) => {
|
||||||
window._gaq.push(["_set", "title", title]);
|
window._gaq.push(["_set", "title", title]);
|
||||||
window._gaq.push(['_trackPageview', url]);
|
window._gaq.push(['_trackPageview', url]);
|
||||||
});
|
});
|
||||||
@ -49,7 +48,7 @@ export default {
|
|||||||
|
|
||||||
// Also use Universal Analytics if it is present
|
// Also use Universal Analytics if it is present
|
||||||
if (typeof window.ga !== 'undefined') {
|
if (typeof window.ga !== 'undefined') {
|
||||||
pageTracker.on('change', function(url, title) {
|
onPageChange.on('change', (url, title) => {
|
||||||
window.ga('send', 'pageview', {page: url, title: title});
|
window.ga('send', 'pageview', {page: url, title: title});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import { decorateCooked } from 'discourse/lib/plugin-api';
|
import highlightSyntax from 'discourse/lib/highlight-syntax';
|
||||||
import HighlightSyntax from 'discourse/lib/highlight-syntax';
|
import lightbox from 'discourse/lib/lightbox';
|
||||||
import Lightbox from 'discourse/lib/lightbox';
|
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "post-decorations",
|
name: "post-decorations",
|
||||||
initialize: function(container) {
|
initialize() {
|
||||||
decorateCooked(container, HighlightSyntax);
|
withPluginApi('0.1', api => {
|
||||||
decorateCooked(container, Lightbox);
|
api.decorateCooked(highlightSyntax);
|
||||||
|
api.decorateCooked(lightbox);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
import ScreenTrack from 'discourse/lib/screen-track';
|
|
||||||
import Session from 'discourse/models/session';
|
import Session from 'discourse/models/session';
|
||||||
|
|
||||||
const ANON_TOPIC_IDS = 2,
|
const ANON_TOPIC_IDS = 2;
|
||||||
ANON_PROMPT_READ_TIME = 2 * 60 * 1000,
|
const ANON_PROMPT_READ_TIME = 2 * 60 * 1000;
|
||||||
ONE_DAY = 24 * 60 * 60 * 1000,
|
const ONE_DAY = 24 * 60 * 60 * 1000;
|
||||||
PROMPT_HIDE_DURATION = ONE_DAY;
|
const PROMPT_HIDE_DURATION = ONE_DAY;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "signup-cta",
|
name: "signup-cta",
|
||||||
|
|
||||||
initialize(container) {
|
initialize(container) {
|
||||||
const screenTrack = ScreenTrack.current(),
|
const screenTrack = container.lookup('screen-track:main');
|
||||||
session = Session.current(),
|
const session = Session.current();
|
||||||
siteSettings = container.lookup('site-settings:main'),
|
const siteSettings = container.lookup('site-settings:main');
|
||||||
keyValueStore = container.lookup('key-value-store:main'),
|
const keyValueStore = container.lookup('key-value-store:main');
|
||||||
user = container.lookup('current-user:main');
|
const user = container.lookup('current-user:main');
|
||||||
|
|
||||||
screenTrack.set('keyValueStore', keyValueStore);
|
screenTrack.keyValueStore = keyValueStore;
|
||||||
|
|
||||||
// Preconditions
|
// Preconditions
|
||||||
|
|
||||||
if (user) return; // must not be logged in
|
if (user) return; // must not be logged in
|
||||||
if (keyValueStore.get('anon-cta-never')) return; // "never show again"
|
if (keyValueStore.get('anon-cta-never')) return; // "never show again"
|
||||||
if (!siteSettings.allow_new_registrations) return;
|
if (!siteSettings.allow_new_registrations) return;
|
||||||
@ -63,7 +61,7 @@ export default {
|
|||||||
session.set('showSignupCta', true);
|
session.set('showSignupCta', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
screenTrack.set('anonFlushCallback', checkSignupCtaRequirements);
|
screenTrack.registerAnonCallback(checkSignupCtaRequirements);
|
||||||
|
|
||||||
checkSignupCtaRequirements();
|
checkSignupCtaRequirements();
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!Ember.testing) {
|
if (!Ember.testing) {
|
||||||
if (!Discourse.Mobile.mobileView) {
|
if (!site.mobileView) {
|
||||||
bus.subscribe("/notification-alert/" + user.get('id'), function(data){
|
bus.subscribe("/notification-alert/" + user.get('id'), function(data){
|
||||||
onNotification(data, user);
|
onNotification(data, user);
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
@module $.fn.autocomplete
|
@module $.fn.autocomplete
|
||||||
**/
|
**/
|
||||||
|
|
||||||
export var CANCELLED_STATUS = "__CANCELLED";
|
export var CANCELLED_STATUS = "__CANCELLED";
|
||||||
|
|
||||||
const allowedLettersRegex = /[\s\t\[\{\(\/]/;
|
const allowedLettersRegex = /[\s\t\[\{\(\/]/;
|
||||||
@ -232,7 +231,7 @@ export default function(options) {
|
|||||||
vOffset = div.height();
|
vOffset = div.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Discourse.Mobile.mobileView && !isInput) {
|
if (Discourse.Site.currentProp('mobileView') && !isInput) {
|
||||||
div.css('width', 'auto');
|
div.css('width', 'auto');
|
||||||
|
|
||||||
if ((me.height() / 2) >= pos.top) { vOffset = -23; }
|
if ((me.height() / 2) >= pos.top) { vOffset = -23; }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import DiscourseURL from 'discourse/lib/url';
|
import DiscourseURL from 'discourse/lib/url';
|
||||||
import PageTracker from 'discourse/lib/page-tracker';
|
|
||||||
import KeyValueStore from 'discourse/lib/key-value-store';
|
import KeyValueStore from 'discourse/lib/key-value-store';
|
||||||
|
import { onPageChange } from 'discourse/lib/page-tracker';
|
||||||
|
|
||||||
let primaryTab = false;
|
let primaryTab = false;
|
||||||
let liveEnabled = false;
|
let liveEnabled = false;
|
||||||
@ -84,7 +84,8 @@ function setupNotifications() {
|
|||||||
if (document) {
|
if (document) {
|
||||||
document.addEventListener("scroll", resetIdle);
|
document.addEventListener("scroll", resetIdle);
|
||||||
}
|
}
|
||||||
PageTracker.on("change", resetIdle);
|
|
||||||
|
onPageChange(resetIdle);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetIdle() {
|
function resetIdle() {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import CloakedCollectionView from 'discourse/views/cloaked-collection';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@module Discourse
|
@module Discourse
|
||||||
*/
|
*/
|
||||||
@ -33,7 +31,12 @@ const DiscourseLocation = Ember.Object.extend({
|
|||||||
@method initState
|
@method initState
|
||||||
*/
|
*/
|
||||||
initState() {
|
initState() {
|
||||||
set(this, 'history', get(this, 'history') || window.history);
|
const history = get(this, 'history') || window.history;
|
||||||
|
if (history && history.scrollRestoration) {
|
||||||
|
history.scrollRestoration = "manual";
|
||||||
|
}
|
||||||
|
|
||||||
|
set(this, 'history', history);
|
||||||
|
|
||||||
let url = this.formatURL(this.getURL());
|
let url = this.formatURL(this.getURL());
|
||||||
const loc = get(this, 'location');
|
const loc = get(this, 'location');
|
||||||
@ -221,36 +224,4 @@ const DiscourseLocation = Ember.Object.extend({
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
Since we're using pushState/replaceState let's add extra hooks to cloakedView to
|
|
||||||
eject itself when the popState occurs. This results in better back button
|
|
||||||
behavior.
|
|
||||||
**/
|
|
||||||
CloakedCollectionView.reopen({
|
|
||||||
_watchForPopState: function() {
|
|
||||||
const self = this,
|
|
||||||
cb = function() {
|
|
||||||
// Sam: This is a hack, but a very important one
|
|
||||||
// Due to the way we use replace state the back button works strangely
|
|
||||||
//
|
|
||||||
// If you visit a topic from the front page, scroll a bit around and then hit back
|
|
||||||
// you notice that first the page scrolls a bit (within the topic) and then it goes back
|
|
||||||
// this transition is jarring and adds uneeded rendering costs.
|
|
||||||
//
|
|
||||||
// To repro comment the hack out and wack a debugger statement here and in
|
|
||||||
// topic_route deactivate
|
|
||||||
$('.posts,#topic-title').hide();
|
|
||||||
self.cleanUp();
|
|
||||||
self.set('controller.model.postStream.loaded', false);
|
|
||||||
};
|
|
||||||
this.set('_callback', cb);
|
|
||||||
popstateCallbacks.addObject(cb);
|
|
||||||
}.on('didInsertElement'),
|
|
||||||
|
|
||||||
_disbandWatcher: function() {
|
|
||||||
popstateCallbacks.removeObject(this.get('_callback'));
|
|
||||||
this.set('_callback', null);
|
|
||||||
}.on('willDestroyElement')
|
|
||||||
});
|
|
||||||
|
|
||||||
export default DiscourseLocation;
|
export default DiscourseLocation;
|
||||||
|
@ -161,7 +161,7 @@ function showSelector(options) {
|
|||||||
options.appendTo.append('<div class="emoji-modal-wrapper"></div>');
|
options.appendTo.append('<div class="emoji-modal-wrapper"></div>');
|
||||||
$('.emoji-modal-wrapper').click(() => closeSelector());
|
$('.emoji-modal-wrapper').click(() => closeSelector());
|
||||||
|
|
||||||
if (Discourse.Mobile.mobileView) PER_ROW = 9;
|
if (Discourse.Site.currentProp('mobileView')) { PER_ROW = 9; }
|
||||||
const page = keyValueStore.getInt("emojiPage", 0);
|
const page = keyValueStore.getInt("emojiPage", 0);
|
||||||
const offset = keyValueStore.getInt("emojiOffset", 0);
|
const offset = keyValueStore.getInt("emojiOffset", 0);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ const bindings = {
|
|||||||
'home': {handler: 'goToFirstPost', anonymous: true},
|
'home': {handler: 'goToFirstPost', anonymous: true},
|
||||||
'j': {handler: 'selectDown', anonymous: true},
|
'j': {handler: 'selectDown', anonymous: true},
|
||||||
'k': {handler: 'selectUp', anonymous: true},
|
'k': {handler: 'selectUp', anonymous: true},
|
||||||
'l': {click: '.topic-post.selected button[data-action="like"]'},
|
'l': {click: '.topic-post.selected button.toggle-like'},
|
||||||
'm m': {click: 'div.notification-options li[data-id="0"] a'}, // mark topic as muted
|
'm m': {click: 'div.notification-options li[data-id="0"] a'}, // mark topic as muted
|
||||||
'm r': {click: 'div.notification-options li[data-id="1"] a'}, // mark topic as regular
|
'm r': {click: 'div.notification-options li[data-id="1"] a'}, // mark topic as regular
|
||||||
'm t': {click: 'div.notification-options li[data-id="2"] a'}, // mark topic as tracking
|
'm t': {click: 'div.notification-options li[data-id="2"] a'}, // mark topic as tracking
|
||||||
@ -222,10 +222,14 @@ export default {
|
|||||||
// TODO: We should keep track of the post without a CSS class
|
// TODO: We should keep track of the post without a CSS class
|
||||||
const selectedPostId = parseInt($('.topic-post.selected article.boxed').data('post-id'), 10);
|
const selectedPostId = parseInt($('.topic-post.selected article.boxed').data('post-id'), 10);
|
||||||
if (selectedPostId) {
|
if (selectedPostId) {
|
||||||
const topicController = container.lookup('controller:topic'),
|
const topicController = container.lookup('controller:topic');
|
||||||
post = topicController.get('model.postStream.posts').findBy('id', selectedPostId);
|
const post = topicController.get('model.postStream.posts').findBy('id', selectedPostId);
|
||||||
if (post) {
|
if (post) {
|
||||||
topicController.send(action, post);
|
// TODO: Use ember closure actions
|
||||||
|
const result = topicController._actions[action].call(topicController, post);
|
||||||
|
if (result && result.then) {
|
||||||
|
this.appEvents.trigger('post-stream:refresh', { id: selectedPostId });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -312,12 +316,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($article.is('.topic-post')) {
|
if ($article.is('.topic-post')) {
|
||||||
let tabLoc = $article.find('a.tabLoc');
|
$('a.tabLoc', $article).focus();
|
||||||
if (tabLoc.length === 0) {
|
|
||||||
tabLoc = $('<a href class="tabLoc"></a>');
|
|
||||||
$article.prepend(tabLoc);
|
|
||||||
}
|
|
||||||
tabLoc.focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._scrollList($article, direction);
|
this._scrollList($article, direction);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
// An object that is responsible for logic related to mobile devices.
|
// An object that is responsible for logic related to mobile devices.
|
||||||
Discourse.Mobile = {
|
const Mobile = {
|
||||||
isMobileDevice: false,
|
isMobileDevice: false,
|
||||||
mobileView: false,
|
mobileView: false,
|
||||||
|
|
||||||
init: function() {
|
init() {
|
||||||
var $html = $('html');
|
const $html = $('html');
|
||||||
this.isMobileDevice = $html.hasClass('mobile-device');
|
this.isMobileDevice = $html.hasClass('mobile-device');
|
||||||
this.mobileView = $html.hasClass('mobile-view');
|
this.mobileView = $html.hasClass('mobile-view');
|
||||||
|
|
||||||
@ -42,3 +42,13 @@ Discourse.Mobile = {
|
|||||||
window.location.assign(window.location.pathname + '?mobile_view=' + (mobile ? '1' : '0'));
|
window.location.assign(window.location.pathname + '?mobile_view=' + (mobile ? '1' : '0'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Backwards compatibiltity, deprecated
|
||||||
|
Object.defineProperty(Discourse, 'Mobile', {
|
||||||
|
get: function() {
|
||||||
|
Ember.warn("DEPRECATION: `Discourse.Mobile` is deprecated, use `this.site.mobileView` instead");
|
||||||
|
return Mobile;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Mobile;
|
@ -1,37 +1,31 @@
|
|||||||
import Singleton from 'discourse/mixins/singleton';
|
const PageTracker = Ember.Object.extend(Ember.Evented);
|
||||||
|
let _pageTracker = PageTracker.create();
|
||||||
|
|
||||||
/**
|
let _started = false;
|
||||||
Called whenever the "page" changes. This allows us to set up analytics
|
export function startPageTracking(router) {
|
||||||
and other tracking.
|
if (_started) { return; }
|
||||||
|
|
||||||
To get notified when the page changes, you can install a hook like so:
|
router.on('didTransition', function() {
|
||||||
|
this.send('refreshTitle');
|
||||||
|
const url = Discourse.getURL(this.get('url'));
|
||||||
|
|
||||||
```javascript
|
// Refreshing the title is debounced, so we need to trigger this in the
|
||||||
PageTracker.current().on('change', function(url, title) {
|
// next runloop to have the correct title.
|
||||||
console.log('the page changed to: ' + url + ' and title ' + title);
|
Em.run.next(() => {
|
||||||
|
_pageTracker.trigger('change', url, Discourse.get('_docTitle'));
|
||||||
});
|
});
|
||||||
```
|
});
|
||||||
**/
|
_started = true;
|
||||||
const PageTracker = Ember.Object.extend(Ember.Evented, {
|
}
|
||||||
start: function() {
|
|
||||||
if (this.get('started')) { return; }
|
|
||||||
|
|
||||||
var router = Discourse.__container__.lookup('router:main'),
|
export function onPageChange(fn) {
|
||||||
self = this;
|
_pageTracker.on('change', fn);
|
||||||
|
}
|
||||||
|
|
||||||
router.on('didTransition', function() {
|
// backwards compatibility
|
||||||
this.send('refreshTitle');
|
export default {
|
||||||
var url = Discourse.getURL(this.get('url'));
|
current() {
|
||||||
|
console.warn(`Using PageTracker.current() is deprecated. Your plugin should use the PluginAPI`);
|
||||||
// Refreshing the title is debounced, so we need to trigger this in the
|
return _pageTracker;
|
||||||
// next runloop to have the correct title.
|
|
||||||
Em.run.next(function() {
|
|
||||||
self.trigger('change', url, Discourse.get('_docTitle'));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this.set('started', true);
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
PageTracker.reopenClass(Singleton);
|
|
||||||
|
|
||||||
export default PageTracker;
|
|
||||||
|
@ -1,4 +1,275 @@
|
|||||||
|
import { iconNode } from 'discourse/helpers/fa-icon';
|
||||||
|
import { addDecorator } from 'discourse/widgets/post-cooked';
|
||||||
import ComposerEditor from 'discourse/components/composer-editor';
|
import ComposerEditor from 'discourse/components/composer-editor';
|
||||||
|
import { addButton } from 'discourse/widgets/post-menu';
|
||||||
|
import { includeAttributes } from 'discourse/lib/transform-post';
|
||||||
|
import { addToolbarCallback } from 'discourse/components/d-editor';
|
||||||
|
import { addWidgetCleanCallback } from 'discourse/components/mount-widget';
|
||||||
|
import { decorateWidget } from 'discourse/widgets/widget';
|
||||||
|
import { onPageChange } from 'discourse/lib/page-tracker';
|
||||||
|
|
||||||
|
class PluginApi {
|
||||||
|
constructor(version, container) {
|
||||||
|
this.version = version;
|
||||||
|
this.container = container;
|
||||||
|
this._currentUser = container.lookup('current-user:main');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this function to retrieve the currently logged in user within your plugin.
|
||||||
|
* If the user is not logged in, it will be `null`.
|
||||||
|
**/
|
||||||
|
getCurrentUser() {
|
||||||
|
return this._currentUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for decorating the `cooked` content of a post after it is rendered using
|
||||||
|
* jQuery.
|
||||||
|
*
|
||||||
|
* `callback` will be called when it is time to decorate with a jQuery selector.
|
||||||
|
*
|
||||||
|
* Use `options.onlyStream` if you only want to decorate posts within a topic,
|
||||||
|
* and not in other places like the user stream.
|
||||||
|
*
|
||||||
|
* For example, to add a yellow background to all posts you could do this:
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* api.decorateCooked($elem => $elem.css({ backgroundColor: 'yellow' }));
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
decorateCooked(callback, opts) {
|
||||||
|
opts = opts || {};
|
||||||
|
|
||||||
|
addDecorator(callback);
|
||||||
|
|
||||||
|
if (!opts.onlyStream) {
|
||||||
|
decorate(ComposerEditor, 'previewRefreshed', callback);
|
||||||
|
decorate(this.container.lookupFactory('view:user-stream'), 'didInsertElement', callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* addPosterIcon(callback)
|
||||||
|
*
|
||||||
|
* This function can be used to add an icon with a link that will be displayed
|
||||||
|
* beside a poster's name. The `callback` is called with the post's user custom
|
||||||
|
* fields and post attrions. An icon will be rendered if the callback returns
|
||||||
|
* an object with the appropriate attributes.
|
||||||
|
*
|
||||||
|
* The returned object can have the following attributes:
|
||||||
|
*
|
||||||
|
* icon the font awesome icon to render
|
||||||
|
* emoji an emoji icon to render
|
||||||
|
* className (optional) a css class to apply to the icon
|
||||||
|
* url (optional) where to link the icon
|
||||||
|
* title (optional) the tooltip title for the icon on hover
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* api.addPosterIcon((cfs, attrs) => {
|
||||||
|
* if (cfs.customer) {
|
||||||
|
* return { icon: 'user', className: 'customer', title: 'customer' };
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
addPosterIcon(cb) {
|
||||||
|
decorateWidget('poster-name:after', dec => {
|
||||||
|
const attrs = dec.attrs;
|
||||||
|
|
||||||
|
const result = cb(attrs.userCustomFields || {}, attrs);
|
||||||
|
if (result) {
|
||||||
|
let iconBody;
|
||||||
|
|
||||||
|
if (result.icon) {
|
||||||
|
iconBody = iconNode(result.icon);
|
||||||
|
} else if (result.emoji) {
|
||||||
|
iconBody = result.emoji.split('|').map(emoji => {
|
||||||
|
const src = Discourse.Emoji.urlFor(emoji);
|
||||||
|
return dec.h('img', { className: 'emoji', attributes: { src } });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.text) {
|
||||||
|
iconBody = [iconBody, result.text];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.url) {
|
||||||
|
iconBody = dec.h('a', { attributes: { href: result.url } }, iconBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return dec.h('span',
|
||||||
|
{ className: result.className, attributes: { title: result.title } },
|
||||||
|
iconBody);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main interface for extending widgets with additional HTML.
|
||||||
|
*
|
||||||
|
* The `name` you pass it should be the name of the widget and a type
|
||||||
|
* for the decorator. All widgets support `before` and `after` types.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* api.decorateWidget('post:after', () => {
|
||||||
|
* return "I am displayed after every post!";
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Your decorator will be called with an instance of a `DecoratorHelper`
|
||||||
|
* object, which provides methods you can use to build more interesting
|
||||||
|
* formatting.
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* api.decorateWidget('post:after', helper => {
|
||||||
|
* return helper.h('p.fancy', `I'm an HTML paragraph on post with id ${helper.attrs.id}`);
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* (View the source for `DecoratorHelper` for more helper methods you
|
||||||
|
* can use in your plugin decorators.)
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
decorateWidget(name, fn) {
|
||||||
|
decorateWidget(name, fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new action to a widget that already exists. You can use this to
|
||||||
|
* add additional functionality from your plugin.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* api.attachWidgetAction('post', 'annoyMe', () => {
|
||||||
|
* alert('ANNOYED!');
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
attachWidgetAction(widget, actionName, fn) {
|
||||||
|
const widgetClass = this.container.lookupFactory(`widget:${widget}`);
|
||||||
|
widgetClass.prototype[actionName] = fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add more attributes to the Post's `attrs` object passed through to widgets.
|
||||||
|
* You'll need to do this if you've added attributes to the serializer for a
|
||||||
|
* Post and want to use them when you're rendering.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* // attrs.poster_age and attrs.poster_height will be present
|
||||||
|
* api.includePostAttributes('poster_age', 'poster_height');
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
includePostAttributes(...attributes) {
|
||||||
|
includeAttributes(...attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new button below a post with your plugin.
|
||||||
|
*
|
||||||
|
* The `callback` function will be called whenever the post menu is rendered,
|
||||||
|
* and if you return an object with the button details it will be rendered.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* api.addPostMenuButton('coffee', () => {
|
||||||
|
* return {
|
||||||
|
* action: 'drinkCoffee',
|
||||||
|
* icon: 'coffee',
|
||||||
|
* className: 'hot-coffee',
|
||||||
|
* title: 'coffee.title',
|
||||||
|
* position: 'first' // can be `first`, `last` or `second-last-hidden`
|
||||||
|
* };
|
||||||
|
* });
|
||||||
|
**/
|
||||||
|
addPostMenuButton(name, callback) {
|
||||||
|
addButton(name, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that is called when the editor toolbar is created. You can
|
||||||
|
* use this to add custom editor buttons.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* api.onToolbarCreate(toolbar => {
|
||||||
|
* toolbar.addButton({
|
||||||
|
* id: 'pop-text',
|
||||||
|
* group: 'extras',
|
||||||
|
* icon: 'bolt',
|
||||||
|
* action: 'makeItPop',
|
||||||
|
* title: 'pop_format.title'
|
||||||
|
* });
|
||||||
|
* });
|
||||||
|
**/
|
||||||
|
onToolbarCreate(callback) {
|
||||||
|
addToolbarCallback(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that is called when the post stream is removed from the DOM.
|
||||||
|
* This advanced hook should be used if you end up wiring up any
|
||||||
|
* events that need to be torn down when the user leaves the topic
|
||||||
|
* page.
|
||||||
|
**/
|
||||||
|
cleanupStream(fn) {
|
||||||
|
addWidgetCleanCallback('post-stream', fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called whenever the "page" changes. This allows us to set up analytics
|
||||||
|
and other tracking.
|
||||||
|
|
||||||
|
To get notified when the page changes, you can install a hook like so:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
api.onPageChange((url, title) => {
|
||||||
|
console.log('the page changed to: ' + url + ' and title ' + title);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
**/
|
||||||
|
onPageChange(fn) {
|
||||||
|
onPageChange(fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
let _pluginv01;
|
||||||
|
function getPluginApi(version) {
|
||||||
|
if (version === "0.1") {
|
||||||
|
if (!_pluginv01) {
|
||||||
|
_pluginv01 = new PluginApi(version, Discourse.__container__);
|
||||||
|
}
|
||||||
|
return _pluginv01;
|
||||||
|
} else {
|
||||||
|
console.warn(`Plugin API v${version} is not supported`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* withPluginApi(version, apiCode, noApi)
|
||||||
|
*
|
||||||
|
* Helper to version our client side plugin API. Pass the version of the API that your
|
||||||
|
* plugin is coded against. If that API is available, the `apiCodeCallback` function will
|
||||||
|
* be called with the `PluginApi` object.
|
||||||
|
*/
|
||||||
|
export function withPluginApi(version, apiCodeCallback, opts) {
|
||||||
|
opts = opts || {};
|
||||||
|
|
||||||
|
const api = getPluginApi(version);
|
||||||
|
if (api) {
|
||||||
|
return apiCodeCallback(api);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let _decorateId = 0;
|
let _decorateId = 0;
|
||||||
function decorate(klass, evt, cb) {
|
function decorate(klass, evt, cb) {
|
||||||
@ -7,38 +278,6 @@ function decorate(klass, evt, cb) {
|
|||||||
klass.reopen(mixin);
|
klass.reopen(mixin);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decorateCooked(container, cb) {
|
export function decorateCooked() {
|
||||||
const postView = container.lookupFactory('view:post');
|
console.warn('`decorateCooked` has been removed. Use `getPluginApi(version).decorateCooked` instead');
|
||||||
decorate(postView, 'postViewInserted', cb);
|
|
||||||
decorate(postView, 'postViewUpdated', cb);
|
|
||||||
decorate(ComposerEditor, 'previewRefreshed', cb);
|
|
||||||
decorate(container.lookupFactory('view:embedded-post'), 'didInsertElement', cb);
|
|
||||||
decorate(container.lookupFactory('view:user-stream'), 'didInsertElement', cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is backported so plugins in the new format will not raise errors
|
|
||||||
//
|
|
||||||
// To upgrade your plugin for backwards compatibility, you can add code in this
|
|
||||||
// form:
|
|
||||||
//
|
|
||||||
// function newApiCode(api) {
|
|
||||||
// // api.xyz();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// function oldCode() {
|
|
||||||
// // your pre-PluginAPI code goes here. You will be able to delete this
|
|
||||||
// // code once the `PluginAPI` has been rolled out to all versions of
|
|
||||||
// // Discourse you want to support.
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // `newApiCode` will use API version 0.1, if no API support then
|
|
||||||
// // `oldCode` will be called
|
|
||||||
// withPluginApi('0.1', newApiCode, { noApi: oldCode });
|
|
||||||
//
|
|
||||||
export function withPluginApi(version, apiCodeCallback, opts) {
|
|
||||||
console.warn(`Plugin API v${version} is not supported`);
|
|
||||||
|
|
||||||
if (opts && opts.noApi) {
|
|
||||||
return opts.noApi();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { Placeholder } from 'discourse/views/cloaked';
|
|
||||||
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
|
export function Placeholder(viewName) {
|
||||||
|
this.viewName = viewName;
|
||||||
|
}
|
||||||
|
|
||||||
export default Ember.Object.extend(Ember.Array, {
|
export default Ember.Object.extend(Ember.Array, {
|
||||||
posts: null,
|
posts: null,
|
||||||
@ -34,6 +36,11 @@ export default Ember.Object.extend(Ember.Array, {
|
|||||||
this._changeArray(cb, this.get('posts.length') - 1, 1, 0);
|
this._changeArray(cb, this.get('posts.length') - 1, 1, 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
refreshAll(cb) {
|
||||||
|
const length = this.get('posts.length');
|
||||||
|
this._changeArray(cb, 0, length, length);
|
||||||
|
},
|
||||||
|
|
||||||
appending(postIds) {
|
appending(postIds) {
|
||||||
this._changeArray(() => {
|
this._changeArray(() => {
|
||||||
const appendingIds = this._appendingIds;
|
const appendingIds = this._appendingIds;
|
||||||
|
@ -37,8 +37,6 @@ function positioningWorkaround($fixedElement) {
|
|||||||
if (evt) {
|
if (evt) {
|
||||||
evt.target.removeEventListener('blur', blurred);
|
evt.target.removeEventListener('blur', blurred);
|
||||||
}
|
}
|
||||||
|
|
||||||
$('body').removeData('disable-cloaked-view');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var blurred = _.debounce(blurredNow, 250);
|
var blurred = _.debounce(blurredNow, 250);
|
||||||
@ -63,7 +61,6 @@ function positioningWorkaround($fixedElement) {
|
|||||||
|
|
||||||
// take care of body
|
// take care of body
|
||||||
|
|
||||||
$('body').data('disable-cloaked-view',true);
|
|
||||||
$('#main-outlet').hide();
|
$('#main-outlet').hide();
|
||||||
$('header').hide();
|
$('header').hide();
|
||||||
|
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
// We use this class to track how long posts in a topic are on the screen.
|
// We use this class to track how long posts in a topic are on the screen.
|
||||||
|
const PAUSE_UNLESS_SCROLLED = 1000 * 60 * 3;
|
||||||
|
const MAX_TRACKING_TIME = 1000 * 60 * 6;
|
||||||
|
const ANON_MAX_TOPIC_IDS = 5;
|
||||||
|
|
||||||
import Singleton from 'discourse/mixins/singleton';
|
const getTime = () => new Date().getTime();
|
||||||
|
|
||||||
const PAUSE_UNLESS_SCROLLED = 1000 * 60 * 3,
|
export default class {
|
||||||
MAX_TRACKING_TIME = 1000 * 60 * 6,
|
constructor(topicTrackingState, siteSettings, session, currentUser) {
|
||||||
ANON_MAX_TOPIC_IDS = 5;
|
this.topicTrackingState = topicTrackingState;
|
||||||
|
this.siteSettings = siteSettings;
|
||||||
const ScreenTrack = Ember.Object.extend({
|
this.session = session;
|
||||||
|
this.currentUser = currentUser;
|
||||||
init() {
|
|
||||||
this.reset();
|
this.reset();
|
||||||
|
}
|
||||||
// TODO: Move `ScreenTrack` to injection and remove this
|
|
||||||
this.set('topicTrackingState', Discourse.__container__.lookup('topic-tracking-state:main'));
|
|
||||||
},
|
|
||||||
|
|
||||||
start(topicId, topicController) {
|
start(topicId, topicController) {
|
||||||
const currentTopicId = this.get('topicId');
|
const currentTopicId = this._topicId;
|
||||||
if (currentTopicId && (currentTopicId !== topicId)) {
|
if (currentTopicId && (currentTopicId !== topicId)) {
|
||||||
this.tick();
|
this.tick();
|
||||||
this.flush();
|
this.flush();
|
||||||
@ -25,90 +24,81 @@ const ScreenTrack = Ember.Object.extend({
|
|||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
// Create an interval timer if we don't have one.
|
// Create an interval timer if we don't have one.
|
||||||
if (!this.get('interval')) {
|
if (!this._interval) {
|
||||||
const self = this;
|
this._interval = setInterval(() => this.tick(), 1000);
|
||||||
this.set('interval', setInterval(function () {
|
$(window).on('scroll.screentrack', () => this.scrolled());
|
||||||
self.tick();
|
|
||||||
}, 1000));
|
|
||||||
|
|
||||||
$(window).on('scroll.screentrack', function(){self.scrolled();});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set('topicId', topicId);
|
this._topicId = topicId;
|
||||||
this.set('topicController', topicController);
|
this._topicController = topicController;
|
||||||
},
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
if(!this.get('topicId')) {
|
// already stopped no need to "extra stop"
|
||||||
// already stopped no need to "extra stop"
|
if(!this._topicId) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
$(window).off('scroll.screentrack');
|
$(window).off('scroll.screentrack');
|
||||||
this.tick();
|
this.tick();
|
||||||
this.flush();
|
this.flush();
|
||||||
this.reset();
|
this.reset();
|
||||||
this.set('topicId', null);
|
|
||||||
this.set('topicController', null);
|
this._topicId = null;
|
||||||
if (this.get('interval')) {
|
this._topicController = null;
|
||||||
clearInterval(this.get('interval'));
|
|
||||||
this.set('interval', null);
|
if (this._interval) {
|
||||||
|
clearInterval(this._interval);
|
||||||
|
this._interval = null;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
track(elementId, postNumber) {
|
setOnscreen(onscreen) {
|
||||||
this.get('timings')["#" + elementId] = {
|
this._onscreen = onscreen;
|
||||||
time: 0,
|
}
|
||||||
postNumber: postNumber
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
stopTracking(elementId) {
|
|
||||||
delete this.get('timings')['#' + elementId];
|
|
||||||
},
|
|
||||||
|
|
||||||
// Reset our timers
|
// Reset our timers
|
||||||
reset() {
|
reset() {
|
||||||
this.setProperties({
|
const now = getTime();
|
||||||
lastTick: new Date().getTime(),
|
this._lastTick = now;
|
||||||
lastScrolled: new Date().getTime(),
|
this._lastScrolled = now;
|
||||||
lastFlush: 0,
|
this._lastFlush = 0;
|
||||||
cancelled: false,
|
this._timings = {};
|
||||||
timings: {},
|
this._totalTimings = {};
|
||||||
totalTimings: {},
|
this._topicTime = 0;
|
||||||
topicTime: 0
|
this._onscreen = [];
|
||||||
});
|
}
|
||||||
},
|
|
||||||
|
|
||||||
scrolled() {
|
scrolled() {
|
||||||
this.set('lastScrolled', new Date().getTime());
|
this._lastScrolled = getTime();
|
||||||
},
|
}
|
||||||
|
|
||||||
|
registerAnonCallback(cb) {
|
||||||
|
this._anonCallback = cb;
|
||||||
|
}
|
||||||
|
|
||||||
flush() {
|
flush() {
|
||||||
if (this.get('cancelled')) { return; }
|
const newTimings = {};
|
||||||
|
const totalTimings = this._totalTimings;
|
||||||
|
|
||||||
const newTimings = {},
|
const timings = this._timings;
|
||||||
totalTimings = this.get('totalTimings'),
|
Object.keys(this._timings).forEach(postNumber => {
|
||||||
self = this;
|
const time = timings[postNumber];
|
||||||
|
totalTimings[postNumber] = totalTimings[postNumber] || 0;
|
||||||
|
|
||||||
_.each(this.get('timings'), function(timing) {
|
if (time > 0 && totalTimings[postNumber] < MAX_TRACKING_TIME) {
|
||||||
if (!totalTimings[timing.postNumber])
|
totalTimings[postNumber] += time;
|
||||||
totalTimings[timing.postNumber] = 0;
|
newTimings[postNumber] = time;
|
||||||
|
|
||||||
if (timing.time > 0 && totalTimings[timing.postNumber] < MAX_TRACKING_TIME) {
|
|
||||||
totalTimings[timing.postNumber] += timing.time;
|
|
||||||
newTimings[timing.postNumber] = timing.time;
|
|
||||||
}
|
}
|
||||||
timing.time = 0;
|
timings[postNumber] = 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
const topicId = parseInt(this.get('topicId'), 10);
|
const topicId = parseInt(this._topicId, 10);
|
||||||
let highestSeen = 0;
|
let highestSeen = 0;
|
||||||
|
|
||||||
_.each(newTimings, function(time,postNumber) {
|
Object.keys(newTimings).forEach(postNumber => {
|
||||||
highestSeen = Math.max(highestSeen, parseInt(postNumber, 10));
|
highestSeen = Math.max(highestSeen, parseInt(postNumber, 10));
|
||||||
});
|
});
|
||||||
|
|
||||||
const highestSeenByTopic = Discourse.Session.currentProp('highestSeenByTopic');
|
const highestSeenByTopic = this.session.get('highestSeenByTopic');
|
||||||
if ((highestSeenByTopic[topicId] || 0) < highestSeen) {
|
if ((highestSeenByTopic[topicId] || 0) < highestSeen) {
|
||||||
highestSeenByTopic[topicId] = highestSeen;
|
highestSeenByTopic[topicId] = highestSeen;
|
||||||
}
|
}
|
||||||
@ -116,11 +106,11 @@ const ScreenTrack = Ember.Object.extend({
|
|||||||
this.topicTrackingState.updateSeen(topicId, highestSeen);
|
this.topicTrackingState.updateSeen(topicId, highestSeen);
|
||||||
|
|
||||||
if (!$.isEmptyObject(newTimings)) {
|
if (!$.isEmptyObject(newTimings)) {
|
||||||
if (Discourse.User.current()) {
|
if (this.currentUser) {
|
||||||
Discourse.ajax('/topics/timings', {
|
Discourse.ajax('/topics/timings', {
|
||||||
data: {
|
data: {
|
||||||
timings: newTimings,
|
timings: newTimings,
|
||||||
topic_time: this.get('topicTime'),
|
topic_time: this._topicTime,
|
||||||
topic_id: topicId
|
topic_id: topicId
|
||||||
},
|
},
|
||||||
cache: false,
|
cache: false,
|
||||||
@ -128,22 +118,20 @@ const ScreenTrack = Ember.Object.extend({
|
|||||||
headers: {
|
headers: {
|
||||||
'X-SILENCE-LOGGER': 'true'
|
'X-SILENCE-LOGGER': 'true'
|
||||||
}
|
}
|
||||||
}).then(function() {
|
}).then(() => {
|
||||||
const controller = self.get('topicController');
|
const controller = this._topicController;
|
||||||
if (controller) {
|
if (controller) {
|
||||||
const postNumbers = Object.keys(newTimings).map(function(v) {
|
const postNumbers = Object.keys(newTimings).map(v => parseInt(v, 10));
|
||||||
return parseInt(v, 10);
|
|
||||||
});
|
|
||||||
controller.readPosts(topicId, postNumbers);
|
controller.readPosts(topicId, postNumbers);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (this.get('anonFlushCallback')) {
|
} else if (this._anonCallback) {
|
||||||
// Anonymous viewer - save to localStorage
|
// Anonymous viewer - save to localStorage
|
||||||
const storage = this.get('keyValueStore');
|
const storage = this.keyValueStore;
|
||||||
|
|
||||||
// Save total time
|
// Save total time
|
||||||
const existingTime = storage.getInt('anon-topic-time');
|
const existingTime = storage.getInt('anon-topic-time');
|
||||||
storage.setItem('anon-topic-time', existingTime + this.get('topicTime'));
|
storage.setItem('anon-topic-time', existingTime + this._topicTime);
|
||||||
|
|
||||||
// Save unique topic IDs up to a max
|
// Save unique topic IDs up to a max
|
||||||
let topicIds = storage.get('anon-topic-ids');
|
let topicIds = storage.get('anon-topic-ids');
|
||||||
@ -158,64 +146,47 @@ const ScreenTrack = Ember.Object.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inform the observer
|
// Inform the observer
|
||||||
this.get('anonFlushCallback')();
|
this._anonCallback();
|
||||||
|
|
||||||
// No need to call controller.readPosts()
|
// No need to call controller.readPosts()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set('topicTime', 0);
|
this._topicTime = 0;
|
||||||
}
|
}
|
||||||
this.set('lastFlush', 0);
|
|
||||||
},
|
this._lastFlush = 0;
|
||||||
|
}
|
||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
|
const now = new Date().getTime();
|
||||||
|
|
||||||
// If the user hasn't scrolled the browser in a long time, stop tracking time read
|
// If the user hasn't scrolled the browser in a long time, stop tracking time read
|
||||||
const sinceScrolled = new Date().getTime() - this.get('lastScrolled');
|
const sinceScrolled = now - this._lastScrolled;
|
||||||
if (sinceScrolled > PAUSE_UNLESS_SCROLLED) {
|
if (sinceScrolled > PAUSE_UNLESS_SCROLLED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const diff = new Date().getTime() - this.get('lastTick');
|
const diff = now - this._lastTick;
|
||||||
this.set('lastFlush', this.get('lastFlush') + diff);
|
this._lastFlush += diff;
|
||||||
this.set('lastTick', new Date().getTime());
|
this._lastTick = now;
|
||||||
|
|
||||||
const totalTimings = this.get('totalTimings'), timings = this.get('timings');
|
const totalTimings = this._totalTimings;
|
||||||
const nextFlush = Discourse.SiteSettings.flush_timings_secs * 1000;
|
const timings = this._timings;
|
||||||
|
const nextFlush = this.siteSettings.flush_timings_secs * 1000;
|
||||||
|
|
||||||
// rush new post numbers
|
const rush = Object.keys(timings).some(postNumber => {
|
||||||
const rush = _.any(_.filter(timings, function(t){return t.time>0;}), function(t){
|
return timings[postNumber] > 0 && !totalTimings[postNumber];
|
||||||
return !totalTimings[t.postNumber];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.get('lastFlush') > nextFlush || rush) {
|
if (this._lastFlush > nextFlush || rush) {
|
||||||
this.flush();
|
this.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't track timings if we're not in focus
|
// Don't track timings if we're not in focus
|
||||||
if (!Discourse.get("hasFocus")) return;
|
if (!Discourse.get("hasFocus")) return;
|
||||||
|
|
||||||
this.set('topicTime', this.get('topicTime') + diff);
|
this._topicTime += diff;
|
||||||
const docViewTop = $(window).scrollTop() + $('header').height(),
|
|
||||||
docViewBottom = docViewTop + $(window).height();
|
|
||||||
|
|
||||||
// TODO: Eyeline has a smarter more accurate function here. It's bad to do jQuery
|
this._onscreen.forEach(postNumber => timings[postNumber] = (timings[postNumber] || 0) + diff);
|
||||||
// in a model like component, so we should refactor this out later.
|
|
||||||
_.each(this.get('timings'),function(timing,id) {
|
|
||||||
const $element = $(id);
|
|
||||||
if ($element.length === 1) {
|
|
||||||
const elemTop = $element.offset().top,
|
|
||||||
elemBottom = elemTop + $element.height();
|
|
||||||
|
|
||||||
// If part of the element is on the screen, increase the counter
|
|
||||||
if (((docViewTop <= elemTop && elemTop <= docViewBottom)) || ((docViewTop <= elemBottom && elemBottom <= docViewBottom))) {
|
|
||||||
timing.time = timing.time + diff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
|
||||||
ScreenTrack.reopenClass(Singleton);
|
|
||||||
export default ScreenTrack;
|
|
||||||
|
201
app/assets/javascripts/discourse/lib/transform-post.js.es6
Normal file
201
app/assets/javascripts/discourse/lib/transform-post.js.es6
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
function actionDescription(action, acted, count) {
|
||||||
|
if (acted) {
|
||||||
|
if (count <= 1) {
|
||||||
|
return I18n.t(`post.actions.by_you.${action}`);
|
||||||
|
} else {
|
||||||
|
return I18n.t(`post.actions.by_you_and_others.${action}`, { count: count - 1 });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return I18n.t(`post.actions.by_others.${action}`, { count });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const _additionalAttributes = [];
|
||||||
|
|
||||||
|
export function includeAttributes(...attributes) {
|
||||||
|
attributes.forEach(a => _additionalAttributes.push(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transformBasicPost(post) {
|
||||||
|
// Note: it can be dangerous to not use `get` in Ember code, but this is significantly
|
||||||
|
// faster and has tests to confirm it works. We only call `get` when the property is a CP
|
||||||
|
return {
|
||||||
|
id: post.id,
|
||||||
|
hidden: post.hidden,
|
||||||
|
deleted: post.get('deleted'),
|
||||||
|
deleted_at: post.deleted_at,
|
||||||
|
user_deleted: post.user_deleted,
|
||||||
|
isDeleted: post.deleted_at || post.user_deleted,
|
||||||
|
deletedByAvatarTemplate: null,
|
||||||
|
deletedByUsername: null,
|
||||||
|
primary_group_name: post.primary_group_name,
|
||||||
|
wiki: post.wiki,
|
||||||
|
firstPost: post.post_number === 1,
|
||||||
|
post_number: post.post_number,
|
||||||
|
cooked: post.cooked,
|
||||||
|
via_email: post.via_email,
|
||||||
|
user_id: post.user_id,
|
||||||
|
usernameUrl: Discourse.getURL(`/users/${post.username}`),
|
||||||
|
username: post.username,
|
||||||
|
avatar_template: post.avatar_template,
|
||||||
|
bookmarked: post.bookmarked,
|
||||||
|
yours: post.yours,
|
||||||
|
shareUrl: post.get('shareUrl'),
|
||||||
|
staff: post.staff,
|
||||||
|
admin: post.admin,
|
||||||
|
moderator: post.moderator,
|
||||||
|
new_user: post.trust_level === 0,
|
||||||
|
name: post.name,
|
||||||
|
user_title: post.user_title,
|
||||||
|
created_at: post.created_at,
|
||||||
|
updated_at: post.updated_at,
|
||||||
|
canDelete: post.can_delete,
|
||||||
|
canRecover: post.can_recover,
|
||||||
|
canEdit: post.can_edit,
|
||||||
|
canFlag: !Ember.isEmpty(post.get('flagsAvailable')),
|
||||||
|
version: post.version,
|
||||||
|
canRecoverTopic: false,
|
||||||
|
canDeletedTopic: false,
|
||||||
|
canViewEditHistory: post.can_view_edit_history,
|
||||||
|
canWiki: post.can_wiki,
|
||||||
|
showLike: false,
|
||||||
|
liked: false,
|
||||||
|
canToggleLike: false,
|
||||||
|
likeCount: false,
|
||||||
|
actionsSummary: null,
|
||||||
|
read: post.read,
|
||||||
|
replyToUsername: null,
|
||||||
|
replyToAvatarTemplate: null,
|
||||||
|
reply_to_post_number: post.reply_to_post_number,
|
||||||
|
cooked_hidden: !!post.cooked_hidden,
|
||||||
|
expandablePost: false,
|
||||||
|
replyCount: post.reply_count,
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default function transformPost(currentUser, site, post, prevPost, nextPost) {
|
||||||
|
// Note: it can be dangerous to not use `get` in Ember code, but this is significantly
|
||||||
|
// faster and has tests to confirm it works. We only call `get` when the property is a CP
|
||||||
|
const postType = post.post_type;
|
||||||
|
const postTypes = site.post_types;
|
||||||
|
const topic = post.topic;
|
||||||
|
const details = topic.get('details');
|
||||||
|
|
||||||
|
const postAtts = transformBasicPost(post);
|
||||||
|
|
||||||
|
postAtts.topicId = topic.id;
|
||||||
|
postAtts.topicOwner = details.created_by.id === post.user_id;
|
||||||
|
postAtts.post_type = postType;
|
||||||
|
postAtts.via_email = post.via_email;
|
||||||
|
postAtts.isModeratorAction = postType === postTypes.moderator_action;
|
||||||
|
postAtts.isWhisper = postType === postTypes.whisper;
|
||||||
|
postAtts.isSmallAction = postType === postTypes.small_action;
|
||||||
|
postAtts.canBookmark = !!currentUser;
|
||||||
|
postAtts.canManage = currentUser && currentUser.get('canManageTopic');
|
||||||
|
postAtts.canViewRawEmail = currentUser && (currentUser.id === post.user_id || currentUser.staff);
|
||||||
|
postAtts.canReplyAsNewTopic = details.can_reply_as_new_topic;
|
||||||
|
postAtts.isWarning = topic.is_warning;
|
||||||
|
postAtts.links = post.get('internalLinks');
|
||||||
|
postAtts.replyDirectlyBelow = nextPost && nextPost.reply_to_post_number === post.post_number;
|
||||||
|
postAtts.replyDirectlyAbove = prevPost && post.reply_to_post_number === prevPost.post_number;
|
||||||
|
postAtts.linkCounts = post.link_counts;
|
||||||
|
postAtts.actionCode = post.action_code;
|
||||||
|
postAtts.actionCodeWho = post.action_code_who;
|
||||||
|
postAtts.userCustomFields = post.user_custom_fields;
|
||||||
|
|
||||||
|
const showPMMap = topic.archetype === 'private_message' && post.post_number === 1;
|
||||||
|
if (showPMMap) {
|
||||||
|
postAtts.showPMMap = true;
|
||||||
|
postAtts.allowedGroups = details.allowed_groups;
|
||||||
|
postAtts.allowedUsers = details.allowed_users;
|
||||||
|
postAtts.canRemoveAllowedUsers = details.can_remove_allowed_users;
|
||||||
|
postAtts.canInvite = details.can_invite_to;
|
||||||
|
}
|
||||||
|
|
||||||
|
const showTopicMap = showPMMap || (post.post_number === 1 && topic.archetype === 'regular' && topic.posts_count > 1);
|
||||||
|
if (showTopicMap) {
|
||||||
|
postAtts.showTopicMap = true;
|
||||||
|
postAtts.topicUrl = topic.get('url');
|
||||||
|
postAtts.topicCreatedAt = topic.created_at;
|
||||||
|
postAtts.createdByUsername = details.created_by.username;
|
||||||
|
postAtts.createdByAvatarTemplate = details.created_by.avatar_template;
|
||||||
|
|
||||||
|
postAtts.lastPostUrl = topic.get('lastPostUrl');
|
||||||
|
postAtts.lastPostUsername = details.last_poster.username;
|
||||||
|
postAtts.lastPostAvatarTemplate = details.last_poster.avatar_template;
|
||||||
|
postAtts.lastPostAt = topic.last_posted_at;
|
||||||
|
|
||||||
|
postAtts.topicReplyCount = topic.get('replyCount');
|
||||||
|
postAtts.topicViews = topic.views;
|
||||||
|
postAtts.topicViewsHeat = topic.get('viewsHeat');
|
||||||
|
|
||||||
|
postAtts.participantCount = topic.participant_count;
|
||||||
|
postAtts.topicLikeCount = topic.like_count;
|
||||||
|
postAtts.topicLinks = details.links;
|
||||||
|
if (postAtts.topicLinks) {
|
||||||
|
postAtts.topicLinkLength = details.links.length;
|
||||||
|
}
|
||||||
|
postAtts.topicPostsCount = topic.posts_count;
|
||||||
|
|
||||||
|
postAtts.participants = details.participants;
|
||||||
|
|
||||||
|
const postStream = topic.get('postStream');
|
||||||
|
postAtts.userFilters = postStream.userFilters;
|
||||||
|
postAtts.topicSummaryEnabled = postStream.summary;
|
||||||
|
postAtts.topicWordCount = topic.word_count;
|
||||||
|
postAtts.hasTopicSummary = topic.has_summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (postAtts.isDeleted) {
|
||||||
|
postAtts.deletedByAvatarTemplate = post.get('postDeletedBy.avatar_template');
|
||||||
|
postAtts.deletedByUsername = post.get('postDeletedBy.username');
|
||||||
|
}
|
||||||
|
|
||||||
|
const replyToUser = post.get('reply_to_user');
|
||||||
|
if (replyToUser) {
|
||||||
|
postAtts.replyToUsername = replyToUser.username;
|
||||||
|
postAtts.replyToAvatarTemplate = replyToUser.avatar_template;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (post.actions_summary) {
|
||||||
|
postAtts.actionsSummary = post.actions_summary.filter(a => {
|
||||||
|
return a.actionType.name_key !== 'like' && a.count > 0;
|
||||||
|
}).map(a => {
|
||||||
|
const acted = a.acted;
|
||||||
|
const action = a.actionType.name_key;
|
||||||
|
const count = a.count;
|
||||||
|
|
||||||
|
return { id: a.id,
|
||||||
|
postId: post.id,
|
||||||
|
action,
|
||||||
|
acted,
|
||||||
|
count,
|
||||||
|
canUndo: a.can_undo,
|
||||||
|
canDeferFlags: a.can_defer_flags,
|
||||||
|
description: actionDescription(action, acted, count) };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const likeAction = post.likeAction;
|
||||||
|
if (likeAction) {
|
||||||
|
postAtts.liked = likeAction.acted;
|
||||||
|
postAtts.canToggleLike = likeAction.get('canToggle');
|
||||||
|
postAtts.showLike = postAtts.liked || postAtts.canToggleLike;
|
||||||
|
postAtts.likeCount = likeAction.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (postAtts.post_number === 1) {
|
||||||
|
postAtts.canRecoverTopic = topic.deleted_at && details.can_recover;
|
||||||
|
postAtts.canDeleteTopic = !topic.deleted_at && details.can_delete;
|
||||||
|
postAtts.expandablePost = topic.expandable_first_post;
|
||||||
|
} else {
|
||||||
|
postAtts.canRecover = postAtts.isDeleted && postAtts.canRecover;
|
||||||
|
postAtts.canDelete = !postAtts.isDeleted && postAtts.canDelete;
|
||||||
|
}
|
||||||
|
|
||||||
|
_additionalAttributes.forEach(a => postAtts[a] = post[a]);
|
||||||
|
|
||||||
|
return postAtts;
|
||||||
|
}
|
@ -14,10 +14,9 @@ const DiscourseURL = Ember.Object.createWithMixins({
|
|||||||
/**
|
/**
|
||||||
Jumps to a particular post in the stream
|
Jumps to a particular post in the stream
|
||||||
**/
|
**/
|
||||||
jumpToPost: function(postNumber, opts) {
|
jumpToPost(postNumber, opts) {
|
||||||
const holderId = `.post-cloak[data-post-number=${postNumber}]`;
|
const holderId = `#post_${postNumber}`;
|
||||||
const offset = function() {
|
const offset = () => {
|
||||||
|
|
||||||
const $header = $('header');
|
const $header = $('header');
|
||||||
const $title = $('#topic-title');
|
const $title = $('#topic-title');
|
||||||
const windowHeight = $(window).height() - $title.height();
|
const windowHeight = $(window).height() - $title.height();
|
||||||
@ -26,8 +25,7 @@ const DiscourseURL = Ember.Object.createWithMixins({
|
|||||||
return $header.outerHeight(true) + ((expectedOffset < 0) ? 0 : expectedOffset);
|
return $header.outerHeight(true) + ((expectedOffset < 0) ? 0 : expectedOffset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Em.run.schedule('afterRender', () => {
|
||||||
Em.run.schedule('afterRender', function() {
|
|
||||||
if (postNumber === 1) {
|
if (postNumber === 1) {
|
||||||
$(window).scrollTop(0);
|
$(window).scrollTop(0);
|
||||||
return;
|
return;
|
||||||
@ -37,21 +35,18 @@ const DiscourseURL = Ember.Object.createWithMixins({
|
|||||||
const holder = $(holderId);
|
const holder = $(holderId);
|
||||||
|
|
||||||
if (holder.length > 0 && opts && opts.skipIfOnScreen){
|
if (holder.length > 0 && opts && opts.skipIfOnScreen){
|
||||||
|
|
||||||
// if we are on screen skip
|
// if we are on screen skip
|
||||||
const elementTop = lockon.elementTop(),
|
const elementTop = lockon.elementTop(),
|
||||||
scrollTop = $(window).scrollTop(),
|
scrollTop = $(window).scrollTop(),
|
||||||
windowHeight = $(window).height()-offset(),
|
windowHeight = $(window).height()-offset(),
|
||||||
height = holder.height();
|
height = holder.height();
|
||||||
|
|
||||||
if (elementTop > scrollTop &&
|
if (elementTop > scrollTop && (elementTop + height) < (scrollTop + windowHeight)) {
|
||||||
(elementTop + height) < (scrollTop + windowHeight)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lockon.lock();
|
lockon.lock();
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -3,20 +3,6 @@ import { popupAjaxError } from 'discourse/lib/ajax-error';
|
|||||||
|
|
||||||
export default RestModel.extend({
|
export default RestModel.extend({
|
||||||
|
|
||||||
// Description for the action
|
|
||||||
description: function() {
|
|
||||||
const action = this.get('actionType.name_key');
|
|
||||||
if (this.get('acted')) {
|
|
||||||
if (this.get('count') <= 1) {
|
|
||||||
return I18n.t('post.actions.by_you.' + action);
|
|
||||||
} else {
|
|
||||||
return I18n.t('post.actions.by_you_and_others.' + action, { count: this.get('count') - 1 });
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return I18n.t('post.actions.by_others.' + action, { count: this.get('count') });
|
|
||||||
}
|
|
||||||
}.property('count', 'acted', 'actionType'),
|
|
||||||
|
|
||||||
canToggle: function() {
|
canToggle: function() {
|
||||||
return this.get('can_undo') || this.get('can_act');
|
return this.get('can_undo') || this.get('can_act');
|
||||||
}.property('can_undo', 'can_act'),
|
}.property('can_undo', 'can_act'),
|
||||||
@ -31,7 +17,14 @@ export default RestModel.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
toggle: function(post) {
|
togglePromise(post) {
|
||||||
|
if (!this.get('acted')) {
|
||||||
|
return this.act(post).then(() => true);
|
||||||
|
}
|
||||||
|
return this.undo(post).then(() => false);
|
||||||
|
},
|
||||||
|
|
||||||
|
toggle(post) {
|
||||||
if (!this.get('acted')) {
|
if (!this.get('acted')) {
|
||||||
this.act(post);
|
this.act(post);
|
||||||
return true;
|
return true;
|
||||||
@ -42,7 +35,7 @@ export default RestModel.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Perform this action
|
// Perform this action
|
||||||
act: function(post, opts) {
|
act(post, opts) {
|
||||||
|
|
||||||
if (!opts) opts = {};
|
if (!opts) opts = {};
|
||||||
|
|
||||||
@ -83,37 +76,20 @@ export default RestModel.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Undo this action
|
// Undo this action
|
||||||
undo: function(post) {
|
undo(post) {
|
||||||
this.removeAction(post);
|
this.removeAction(post);
|
||||||
|
|
||||||
// Remove our post action
|
// Remove our post action
|
||||||
return Discourse.ajax("/post_actions/" + post.get('id'), {
|
return Discourse.ajax("/post_actions/" + post.get('id'), {
|
||||||
type: 'DELETE',
|
type: 'DELETE',
|
||||||
data: {
|
data: { post_action_type_id: this.get('id') }
|
||||||
post_action_type_id: this.get('id')
|
}).then(result => post.updateActionsSummary(result));
|
||||||
}
|
|
||||||
}).then(function(result) {
|
|
||||||
return post.updateActionsSummary(result);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
deferFlags: function(post) {
|
deferFlags(post) {
|
||||||
const self = this;
|
|
||||||
return Discourse.ajax("/post_actions/defer_flags", {
|
return Discourse.ajax("/post_actions/defer_flags", {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: { post_action_type_id: this.get("id"), id: post.get('id') }
|
||||||
post_action_type_id: this.get("id"),
|
}).then(() => this.set('count', 0));
|
||||||
id: post.get('id')
|
|
||||||
}
|
|
||||||
}).then(function () {
|
|
||||||
self.set("count", 0);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
loadUsers(post) {
|
|
||||||
return this.store.find('post-action-user', {
|
|
||||||
id: post.get('id'),
|
|
||||||
post_action_type_id: this.get('id')
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -154,7 +154,7 @@ const Composer = RestModel.extend({
|
|||||||
usernameLink
|
usernameLink
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!Discourse.Mobile.mobileView) {
|
if (!this.site.mobileView) {
|
||||||
const replyUsername = post.get('reply_to_user.username');
|
const replyUsername = post.get('reply_to_user.username');
|
||||||
const replyAvatarTemplate = post.get('reply_to_user.avatar_template');
|
const replyAvatarTemplate = post.get('reply_to_user.avatar_template');
|
||||||
if (replyUsername && replyAvatarTemplate && this.get('action') === EDIT) {
|
if (replyUsername && replyAvatarTemplate && this.get('action') === EDIT) {
|
||||||
|
@ -7,7 +7,7 @@ const NavItem = Discourse.Model.extend({
|
|||||||
name = this.get('name'),
|
name = this.get('name'),
|
||||||
count = this.get('count') || 0;
|
count = this.get('count') || 0;
|
||||||
|
|
||||||
if (name === 'latest' && !Discourse.Mobile.mobileView) {
|
if (name === 'latest' && !Discourse.Site.currentProp('mobileView')) {
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,21 +4,6 @@ import PostsWithPlaceholders from 'discourse/lib/posts-with-placeholders';
|
|||||||
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
||||||
import { loadTopicView } from 'discourse/models/topic';
|
import { loadTopicView } from 'discourse/models/topic';
|
||||||
|
|
||||||
function calcDayDiff(p1, p2) {
|
|
||||||
if (!p1) { return; }
|
|
||||||
|
|
||||||
const date = p1.get('created_at');
|
|
||||||
if (date && p2) {
|
|
||||||
const lastDate = p2.get('created_at');
|
|
||||||
if (lastDate) {
|
|
||||||
const delta = new Date(date).getTime() - new Date(lastDate).getTime();
|
|
||||||
const days = Math.round(delta / (1000 * 60 * 60 * 24));
|
|
||||||
|
|
||||||
p1.set('daysSincePrevious', days);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default RestModel.extend({
|
export default RestModel.extend({
|
||||||
_identityMap: null,
|
_identityMap: null,
|
||||||
posts: null,
|
posts: null,
|
||||||
@ -295,6 +280,7 @@ export default RestModel.extend({
|
|||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
stream.pushObjects(gap);
|
stream.pushObjects(gap);
|
||||||
return this.appendMore().then(() => {
|
return this.appendMore().then(() => {
|
||||||
|
delete this.get('gaps.after')[postId];
|
||||||
this.get('stream').enumerableContentDidChange();
|
this.get('stream').enumerableContentDidChange();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -377,7 +363,6 @@ export default RestModel.extend({
|
|||||||
|
|
||||||
// Commit the post we staged. Call this after a save succeeds.
|
// Commit the post we staged. Call this after a save succeeds.
|
||||||
commitPost(post) {
|
commitPost(post) {
|
||||||
|
|
||||||
if (this.get('topic.id') === post.get('topic_id')) {
|
if (this.get('topic.id') === post.get('topic_id')) {
|
||||||
if (this.get('loadedAllPosts')) {
|
if (this.get('loadedAllPosts')) {
|
||||||
this.appendPost(post);
|
this.appendPost(post);
|
||||||
@ -414,7 +399,6 @@ export default RestModel.extend({
|
|||||||
const stored = this.storePost(post);
|
const stored = this.storePost(post);
|
||||||
if (stored) {
|
if (stored) {
|
||||||
const posts = this.get('posts');
|
const posts = this.get('posts');
|
||||||
calcDayDiff(posts.get('firstObject'), stored);
|
|
||||||
posts.unshiftObject(stored);
|
posts.unshiftObject(stored);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,7 +410,6 @@ export default RestModel.extend({
|
|||||||
if (stored) {
|
if (stored) {
|
||||||
const posts = this.get('posts');
|
const posts = this.get('posts');
|
||||||
|
|
||||||
calcDayDiff(stored, this.get('lastAppended'));
|
|
||||||
if (!posts.contains(stored)) {
|
if (!posts.contains(stored)) {
|
||||||
if (!this.get('loadingBelow')) {
|
if (!this.get('loadingBelow')) {
|
||||||
this.get('postsWithPlaceholders').appendPost(() => posts.pushObject(stored));
|
this.get('postsWithPlaceholders').appendPost(() => posts.pushObject(stored));
|
||||||
@ -445,12 +428,15 @@ export default RestModel.extend({
|
|||||||
removePosts(posts) {
|
removePosts(posts) {
|
||||||
if (Ember.isEmpty(posts)) { return; }
|
if (Ember.isEmpty(posts)) { return; }
|
||||||
|
|
||||||
const postIds = posts.map(p => p.get('id'));
|
this.get('postsWithPlaceholders').refreshAll(() => {
|
||||||
const identityMap = this._identityMap;
|
const allPosts = this.get('posts');
|
||||||
|
const postIds = posts.map(p => p.get('id'));
|
||||||
|
const identityMap = this._identityMap;
|
||||||
|
|
||||||
this.get('stream').removeObjects(postIds);
|
this.get('stream').removeObjects(postIds);
|
||||||
this.get('posts').removeObjects(posts);
|
allPosts.removeObjects(posts);
|
||||||
postIds.forEach(id => delete identityMap[id]);
|
postIds.forEach(id => delete identityMap[id]);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns a post from the identity map if it's been inserted.
|
// Returns a post from the identity map if it's been inserted.
|
||||||
@ -471,10 +457,12 @@ export default RestModel.extend({
|
|||||||
have no filters.
|
have no filters.
|
||||||
**/
|
**/
|
||||||
triggerNewPostInStream(postId) {
|
triggerNewPostInStream(postId) {
|
||||||
if (!postId) { return; }
|
const resolved = Ember.RSVP.Promise.resolve();
|
||||||
|
|
||||||
|
if (!postId) { return resolved; }
|
||||||
|
|
||||||
// We only trigger if there are no filters active
|
// We only trigger if there are no filters active
|
||||||
if (!this.get('hasNoFilters')) { return; }
|
if (!this.get('hasNoFilters')) { return resolved; }
|
||||||
|
|
||||||
const loadedAllPosts = this.get('loadedAllPosts');
|
const loadedAllPosts = this.get('loadedAllPosts');
|
||||||
|
|
||||||
@ -482,25 +470,27 @@ export default RestModel.extend({
|
|||||||
this.get('stream').addObject(postId);
|
this.get('stream').addObject(postId);
|
||||||
if (loadedAllPosts) {
|
if (loadedAllPosts) {
|
||||||
this.set('loadingLastPost', true);
|
this.set('loadingLastPost', true);
|
||||||
this.findPostsByIds([postId]).then(posts => {
|
return this.findPostsByIds([postId]).then(posts => {
|
||||||
posts.forEach(p => this.appendPost(p));
|
posts.forEach(p => this.appendPost(p));
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.set('loadingLastPost', false);
|
this.set('loadingLastPost', false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return resolved;
|
||||||
},
|
},
|
||||||
|
|
||||||
triggerRecoveredPost(postId) {
|
triggerRecoveredPost(postId) {
|
||||||
const existing = this._identityMap[postId];
|
const existing = this._identityMap[postId];
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
this.triggerChangedPost(postId, new Date());
|
return this.triggerChangedPost(postId, new Date());
|
||||||
} else {
|
} else {
|
||||||
// need to insert into stream
|
// need to insert into stream
|
||||||
const url = "/posts/" + postId;
|
const url = "/posts/" + postId;
|
||||||
const store = this.store;
|
const store = this.store;
|
||||||
Discourse.ajax(url).then(p => {
|
return Discourse.ajax(url).then(p => {
|
||||||
const post = store.createRecord('post', p);
|
const post = store.createRecord('post', p);
|
||||||
const stream = this.get("stream");
|
const stream = this.get("stream");
|
||||||
const posts = this.get("posts");
|
const posts = this.get("posts");
|
||||||
@ -541,34 +531,26 @@ export default RestModel.extend({
|
|||||||
const url = "/posts/" + postId;
|
const url = "/posts/" + postId;
|
||||||
const store = this.store;
|
const store = this.store;
|
||||||
|
|
||||||
Discourse.ajax(url).then(p => {
|
return Discourse.ajax(url).then(p => {
|
||||||
this.storePost(store.createRecord('post', p));
|
this.storePost(store.createRecord('post', p));
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.removePosts([existing]);
|
this.removePosts([existing]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return Ember.RSVP.Promise.resolve();
|
||||||
},
|
},
|
||||||
|
|
||||||
triggerChangedPost(postId, updatedAt) {
|
triggerChangedPost(postId, updatedAt) {
|
||||||
if (!postId) { return; }
|
const resolved = Ember.RSVP.Promise.resolve();
|
||||||
|
if (!postId) { return resolved; }
|
||||||
|
|
||||||
const existing = this._identityMap[postId];
|
const existing = this._identityMap[postId];
|
||||||
if (existing && existing.updated_at !== updatedAt) {
|
if (existing && existing.updated_at !== updatedAt) {
|
||||||
const url = "/posts/" + postId;
|
const url = "/posts/" + postId;
|
||||||
const store = this.store;
|
const store = this.store;
|
||||||
Discourse.ajax(url).then(p => this.storePost(store.createRecord('post', p)));
|
return Discourse.ajax(url).then(p => this.storePost(store.createRecord('post', p)));
|
||||||
}
|
}
|
||||||
},
|
return resolved;
|
||||||
|
|
||||||
// Returns the "thread" of posts in the history of a post.
|
|
||||||
findReplyHistory(post) {
|
|
||||||
const url = `/posts/${post.get('id')}/reply-history.json?max_replies=${Discourse.SiteSettings.max_reply_history}`;
|
|
||||||
const store = this.store;
|
|
||||||
return Discourse.ajax(url).then(result => {
|
|
||||||
return result.map(p => this.storePost(store.createRecord('post', p)));
|
|
||||||
}).then(replyHistory => {
|
|
||||||
post.set('replyHistory', replyHistory);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,10 +7,6 @@ import computed from 'ember-addons/ember-computed-decorators';
|
|||||||
|
|
||||||
const Post = RestModel.extend({
|
const Post = RestModel.extend({
|
||||||
|
|
||||||
init() {
|
|
||||||
this.set('replyHistory', []);
|
|
||||||
},
|
|
||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
siteSettings() {
|
siteSettings() {
|
||||||
// TODO: Remove this once one instantiate all `Discourse.Post` models via the store.
|
// TODO: Remove this once one instantiate all `Discourse.Post` models via the store.
|
||||||
@ -35,11 +31,6 @@ const Post = RestModel.extend({
|
|||||||
deletedViaTopic: Em.computed.and('firstPost', 'topic.deleted_at'),
|
deletedViaTopic: Em.computed.and('firstPost', 'topic.deleted_at'),
|
||||||
deleted: Em.computed.or('deleted_at', 'deletedViaTopic'),
|
deleted: Em.computed.or('deleted_at', 'deletedViaTopic'),
|
||||||
notDeleted: Em.computed.not('deleted'),
|
notDeleted: Em.computed.not('deleted'),
|
||||||
userDeleted: Em.computed.empty('user_id'),
|
|
||||||
|
|
||||||
hasTimeGap: function() {
|
|
||||||
return (this.get('daysSincePrevious') || 0) > Discourse.SiteSettings.show_time_gap_days;
|
|
||||||
}.property('daysSincePrevious'),
|
|
||||||
|
|
||||||
showName: function() {
|
showName: function() {
|
||||||
const name = this.get('name');
|
const name = this.get('name');
|
||||||
@ -68,25 +59,13 @@ const Post = RestModel.extend({
|
|||||||
|
|
||||||
usernameUrl: url('username', '/users/%@'),
|
usernameUrl: url('username', '/users/%@'),
|
||||||
|
|
||||||
showUserReplyTab: function() {
|
|
||||||
return this.get('reply_to_user') && (
|
|
||||||
!Discourse.SiteSettings.suppress_reply_directly_above ||
|
|
||||||
this.get('reply_to_post_number') < (this.get('post_number') - 1)
|
|
||||||
);
|
|
||||||
}.property('reply_to_user', 'reply_to_post_number', 'post_number'),
|
|
||||||
|
|
||||||
topicOwner: propertyEqual('topic.details.created_by.id', 'user_id'),
|
topicOwner: propertyEqual('topic.details.created_by.id', 'user_id'),
|
||||||
hasHistory: Em.computed.gt('version', 1),
|
|
||||||
|
|
||||||
canViewRawEmail: function() {
|
|
||||||
return this.get("user_id") === Discourse.User.currentProp("id") || Discourse.User.currentProp('staff');
|
|
||||||
}.property("user_id"),
|
|
||||||
|
|
||||||
updatePostField(field, value) {
|
updatePostField(field, value) {
|
||||||
const data = {};
|
const data = {};
|
||||||
data[field] = value;
|
data[field] = value;
|
||||||
|
|
||||||
Discourse.ajax(`/posts/${this.get('id')}/${field}`, { type: 'PUT', data }).then(() => {
|
return Discourse.ajax(`/posts/${this.get('id')}/${field}`, { type: 'PUT', data }).then(() => {
|
||||||
this.set(field, value);
|
this.set(field, value);
|
||||||
this.incrementProperty("version");
|
this.incrementProperty("version");
|
||||||
}).catch(popupAjaxError);
|
}).catch(popupAjaxError);
|
||||||
@ -97,9 +76,6 @@ const Post = RestModel.extend({
|
|||||||
return this.get('link_counts').filterProperty('internal').filterProperty('title');
|
return this.get('link_counts').filterProperty('internal').filterProperty('title');
|
||||||
}.property('link_counts.@each.internal'),
|
}.property('link_counts.@each.internal'),
|
||||||
|
|
||||||
// Edits are the version - 1, so version 2 = 1 edit
|
|
||||||
editCount: function() { return this.get('version') - 1; }.property('version'),
|
|
||||||
|
|
||||||
flagsAvailable: function() {
|
flagsAvailable: function() {
|
||||||
const post = this;
|
const post = this;
|
||||||
return Discourse.Site.currentProp('flagTypes').filter(function(item) {
|
return Discourse.Site.currentProp('flagTypes').filter(function(item) {
|
||||||
@ -107,17 +83,6 @@ const Post = RestModel.extend({
|
|||||||
});
|
});
|
||||||
}.property('actions_summary.@each.can_act'),
|
}.property('actions_summary.@each.can_act'),
|
||||||
|
|
||||||
actionsWithoutLikes: function() {
|
|
||||||
if (!!Ember.isEmpty(this.get('actions_summary'))) return null;
|
|
||||||
|
|
||||||
return this.get('actions_summary').filter(function(i) {
|
|
||||||
if (i.get('count') === 0) return false;
|
|
||||||
if (i.get('actionType.name_key') === 'like') { return false; }
|
|
||||||
if (i.get('users') && i.get('users').length > 0) return true;
|
|
||||||
return !i.get('hidden');
|
|
||||||
});
|
|
||||||
}.property('actions_summary.@each.users', 'actions_summary.@each.count'),
|
|
||||||
|
|
||||||
afterUpdate(res) {
|
afterUpdate(res) {
|
||||||
if (res.category) {
|
if (res.category) {
|
||||||
Discourse.Site.current().updateCategory(res.category);
|
Discourse.Site.current().updateCategory(res.category);
|
||||||
@ -246,10 +211,6 @@ const Post = RestModel.extend({
|
|||||||
let value = otherPost[key],
|
let value = otherPost[key],
|
||||||
oldValue = self[key];
|
oldValue = self[key];
|
||||||
|
|
||||||
if (key === "replyHistory") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!value) { value = null; }
|
if (!value) { value = null; }
|
||||||
if (!oldValue) { oldValue = null; }
|
if (!oldValue) { oldValue = null; }
|
||||||
|
|
||||||
@ -267,56 +228,9 @@ const Post = RestModel.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Load replies to this post
|
|
||||||
loadReplies() {
|
|
||||||
if(this.get('loadingReplies')){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.set('loadingReplies', true);
|
|
||||||
this.set('replies', []);
|
|
||||||
|
|
||||||
const self = this;
|
|
||||||
return Discourse.ajax("/posts/" + (this.get('id')) + "/replies")
|
|
||||||
.then(function(loaded) {
|
|
||||||
const replies = self.get('replies');
|
|
||||||
_.each(loaded,function(reply) {
|
|
||||||
const post = Discourse.Post.create(reply);
|
|
||||||
post.set('topic', self.get('topic'));
|
|
||||||
replies.pushObject(post);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
['finally'](function(){
|
|
||||||
self.set('loadingReplies', false);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// Whether to show replies directly below
|
|
||||||
showRepliesBelow: function() {
|
|
||||||
const replyCount = this.get('reply_count');
|
|
||||||
|
|
||||||
// We don't show replies if there aren't any
|
|
||||||
if (replyCount === 0) return false;
|
|
||||||
|
|
||||||
// Always show replies if the setting `suppress_reply_directly_below` is false.
|
|
||||||
if (!Discourse.SiteSettings.suppress_reply_directly_below) return true;
|
|
||||||
|
|
||||||
// Always show replies if there's more than one
|
|
||||||
if (replyCount > 1) return true;
|
|
||||||
|
|
||||||
// If we have *exactly* one reply, we have to consider if it's directly below us
|
|
||||||
const topic = this.get('topic');
|
|
||||||
return !topic.isReplyDirectlyBelow(this);
|
|
||||||
|
|
||||||
}.property('reply_count'),
|
|
||||||
|
|
||||||
expandHidden() {
|
expandHidden() {
|
||||||
const self = this;
|
return Discourse.ajax("/posts/" + this.get('id') + "/cooked.json").then(result => {
|
||||||
return Discourse.ajax("/posts/" + this.get('id') + "/cooked.json").then(function (result) {
|
this.setProperties({ cooked: result.cooked, cooked_hidden: false });
|
||||||
self.setProperties({
|
|
||||||
cooked: result.cooked,
|
|
||||||
cooked_hidden: false
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -37,7 +37,9 @@ function findAndRemoveMap(type, id) {
|
|||||||
flushMap();
|
flushMap();
|
||||||
|
|
||||||
export default Ember.Object.extend({
|
export default Ember.Object.extend({
|
||||||
_plurals: {},
|
_plurals: {'post-reply': 'post-replies',
|
||||||
|
'post-reply-history': 'post_reply_histories'},
|
||||||
|
|
||||||
pluralize(thing) {
|
pluralize(thing) {
|
||||||
return this._plurals[thing] || thing + "s";
|
return this._plurals[thing] || thing + "s";
|
||||||
},
|
},
|
||||||
|
@ -34,12 +34,6 @@ const TopicDetails = RestModel.extend({
|
|||||||
this.set('loaded', true);
|
this.set('loaded', true);
|
||||||
},
|
},
|
||||||
|
|
||||||
fewParticipants: function() {
|
|
||||||
if (!!Ember.isEmpty(this.get('participants'))) return null;
|
|
||||||
return this.get('participants').slice(0, 3);
|
|
||||||
}.property('participants'),
|
|
||||||
|
|
||||||
|
|
||||||
notificationReasonText: function() {
|
notificationReasonText: function() {
|
||||||
var level = this.get('notification_level');
|
var level = this.get('notification_level');
|
||||||
if(typeof level !== 'number'){
|
if(typeof level !== 'number'){
|
||||||
@ -68,13 +62,13 @@ const TopicDetails = RestModel.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeAllowedUser(user) {
|
removeAllowedUser(user) {
|
||||||
var users = this.get('allowed_users'),
|
const users = this.get('allowed_users');
|
||||||
username = user.get('username');
|
const username = user.get('username');
|
||||||
|
|
||||||
Discourse.ajax("/t/" + this.get('topic.id') + "/remove-allowed-user", {
|
return Discourse.ajax("/t/" + this.get('topic.id') + "/remove-allowed-user", {
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
data: { username: username }
|
data: { username: username }
|
||||||
}).then(function() {
|
}).then(() => {
|
||||||
users.removeObject(users.findProperty('username', username));
|
users.removeObject(users.findProperty('username', username));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -224,34 +224,37 @@ const Topic = RestModel.extend({
|
|||||||
.then(function () { self.set('archetype', 'regular'); });
|
.then(function () { self.set('archetype', 'regular'); });
|
||||||
},
|
},
|
||||||
|
|
||||||
estimatedReadingTime: function() {
|
|
||||||
const wordCount = this.get('word_count');
|
|
||||||
if (!wordCount) return;
|
|
||||||
|
|
||||||
return Math.floor(wordCount / Discourse.SiteSettings.read_time_word_count);
|
|
||||||
}.property('word_count'),
|
|
||||||
|
|
||||||
toggleBookmark() {
|
toggleBookmark() {
|
||||||
if (this.get("bookmarking")) { return; }
|
if (this.get('bookmarking')) { return Ember.RSVP.Promise.resolve(); }
|
||||||
this.set("bookmarking", true);
|
this.set("bookmarking", true);
|
||||||
|
|
||||||
const self = this,
|
const stream = this.get('postStream');
|
||||||
stream = this.get('postStream'),
|
const posts = Em.get(stream, 'posts');
|
||||||
posts = Em.get(stream, 'posts'),
|
const firstPost = posts && posts[0] && posts[0].get('post_number') === 1 && posts[0];
|
||||||
firstPost = posts && posts[0] && posts[0].get('post_number') === 1 && posts[0],
|
const bookmark = !this.get('bookmarked');
|
||||||
bookmark = !this.get('bookmarked'),
|
const path = bookmark ? '/bookmark' : '/remove_bookmarks';
|
||||||
path = bookmark ? '/bookmark' : '/remove_bookmarks';
|
|
||||||
|
|
||||||
const toggleBookmarkOnServer = function() {
|
const toggleBookmarkOnServer = () => {
|
||||||
return Discourse.ajax('/t/' + self.get('id') + path, {
|
return Discourse.ajax(`/t/${this.get('id')}${path}`, { type: 'PUT' }).then(() => {
|
||||||
type: 'PUT',
|
this.toggleProperty('bookmarked');
|
||||||
}).then(function() {
|
if (bookmark && firstPost) {
|
||||||
self.toggleProperty('bookmarked');
|
firstPost.set('bookmarked', true);
|
||||||
if (bookmark && firstPost) { firstPost.set('bookmarked', true); }
|
return [firstPost.id];
|
||||||
if (!bookmark && posts) {
|
|
||||||
posts.forEach((post) => post.get('bookmarked') && post.set('bookmarked', false));
|
|
||||||
}
|
}
|
||||||
}).catch(function(error) {
|
if (!bookmark && posts) {
|
||||||
|
|
||||||
|
const updated = [];
|
||||||
|
posts.forEach(post => {
|
||||||
|
if (post.get('bookmarked')) {
|
||||||
|
post.set('bookmarked', false);
|
||||||
|
updated.push(post.get('id'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}).catch(error => {
|
||||||
let showGenericError = true;
|
let showGenericError = true;
|
||||||
if (error && error.responseText) {
|
if (error && error.responseText) {
|
||||||
try {
|
try {
|
||||||
@ -265,28 +268,26 @@ const Topic = RestModel.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}).finally(function() {
|
}).finally(() => this.set('bookmarking', false));
|
||||||
self.set("bookmarking", false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let unbookmarkedPosts = [];
|
const unbookmarkedPosts = [];
|
||||||
if (!bookmark && posts) {
|
if (!bookmark && posts) {
|
||||||
posts.forEach((post) => post.get('bookmarked') && unbookmarkedPosts.push(post));
|
posts.forEach(post => post.get('bookmarked') && unbookmarkedPosts.push(post));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unbookmarkedPosts.length > 1) {
|
return new Ember.RSVP.Promise(resolve => {
|
||||||
return bootbox.confirm(
|
if (unbookmarkedPosts.length > 1) {
|
||||||
I18n.t("bookmarks.confirm_clear"),
|
bootbox.confirm(
|
||||||
I18n.t("no_value"),
|
I18n.t("bookmarks.confirm_clear"),
|
||||||
I18n.t("yes_value"),
|
I18n.t("no_value"),
|
||||||
function (confirmed) {
|
I18n.t("yes_value"),
|
||||||
if (confirmed) { return toggleBookmarkOnServer(); }
|
confirmed => confirmed ? toggleBookmarkOnServer().then(resolve) : resolve()
|
||||||
}
|
);
|
||||||
);
|
} else {
|
||||||
} else {
|
toggleBookmarkOnServer().then(resolve);
|
||||||
return toggleBookmarkOnServer();
|
}
|
||||||
}
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
createInvite(emailOrUsername, groupNames) {
|
createInvite(emailOrUsername, groupNames) {
|
||||||
@ -390,25 +391,6 @@ const Topic = RestModel.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Is the reply to a post directly below it?
|
|
||||||
isReplyDirectlyBelow(post) {
|
|
||||||
const posts = this.get('postStream.posts');
|
|
||||||
const postNumber = post.get('post_number');
|
|
||||||
if (!posts) return;
|
|
||||||
|
|
||||||
const postBelow = posts[posts.indexOf(post) + 1];
|
|
||||||
|
|
||||||
// If the post directly below's reply_to_post_number is our post number or we are quoted,
|
|
||||||
// it's considered directly below.
|
|
||||||
//
|
|
||||||
// TODO: we don't carry information about quoting, this leaves this code fairly fragile
|
|
||||||
// instead we should start shipping quote meta data with posts, but this will add at least
|
|
||||||
// 1 query to the topics page
|
|
||||||
//
|
|
||||||
return postBelow && (postBelow.get('reply_to_post_number') === postNumber ||
|
|
||||||
postBelow.get('cooked').indexOf('data-post="'+ postNumber + '"') >= 0
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
hasExcerpt: Em.computed.notEmpty('excerpt'),
|
hasExcerpt: Em.computed.notEmpty('excerpt'),
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import DiscourseURL from 'discourse/lib/url';
|
|||||||
import DiscourseLocation from 'discourse/lib/discourse-location';
|
import DiscourseLocation from 'discourse/lib/discourse-location';
|
||||||
import SearchService from 'discourse/services/search';
|
import SearchService from 'discourse/services/search';
|
||||||
import { startTracking, default as TopicTrackingState } from 'discourse/models/topic-tracking-state';
|
import { startTracking, default as TopicTrackingState } from 'discourse/models/topic-tracking-state';
|
||||||
|
import ScreenTrack from 'discourse/lib/screen-track';
|
||||||
|
|
||||||
function inject() {
|
function inject() {
|
||||||
const app = arguments[0],
|
const app = arguments[0],
|
||||||
@ -38,23 +39,29 @@ export default {
|
|||||||
const currentUser = Discourse.User.current();
|
const currentUser = Discourse.User.current();
|
||||||
app.register('current-user:main', currentUser, { instantiate: false });
|
app.register('current-user:main', currentUser, { instantiate: false });
|
||||||
|
|
||||||
const tracking = TopicTrackingState.create({ messageBus, currentUser });
|
const topicTrackingState = TopicTrackingState.create({ messageBus, currentUser });
|
||||||
app.register('topic-tracking-state:main', tracking, { instantiate: false });
|
app.register('topic-tracking-state:main', topicTrackingState, { instantiate: false });
|
||||||
injectAll(app, 'topicTrackingState');
|
injectAll(app, 'topicTrackingState');
|
||||||
|
|
||||||
const site = Discourse.Site.current();
|
const site = Discourse.Site.current();
|
||||||
app.register('site:main', site, { instantiate: false });
|
app.register('site:main', site, { instantiate: false });
|
||||||
injectAll(app, 'site');
|
injectAll(app, 'site');
|
||||||
|
|
||||||
app.register('site-settings:main', Discourse.SiteSettings, { instantiate: false });
|
const siteSettings = Discourse.SiteSettings;
|
||||||
|
app.register('site-settings:main', siteSettings, { instantiate: false });
|
||||||
injectAll(app, 'siteSettings');
|
injectAll(app, 'siteSettings');
|
||||||
|
|
||||||
app.register('search-service:main', SearchService);
|
app.register('search-service:main', SearchService);
|
||||||
injectAll(app, 'searchService');
|
injectAll(app, 'searchService');
|
||||||
|
|
||||||
app.register('session:main', Session.current(), { instantiate: false });
|
const session = Session.current();
|
||||||
|
app.register('session:main', session, { instantiate: false });
|
||||||
injectAll(app, 'session');
|
injectAll(app, 'session');
|
||||||
|
|
||||||
|
const screenTrack = new ScreenTrack(topicTrackingState, siteSettings, session, currentUser);
|
||||||
|
app.register('screen-track:main', screenTrack, { instantiate: false });
|
||||||
|
inject(app, 'screenTrack', 'component', 'route');
|
||||||
|
|
||||||
inject(app, 'currentUser', 'component', 'route', 'controller');
|
inject(app, 'currentUser', 'component', 'route', 'controller');
|
||||||
|
|
||||||
app.register('location:discourse-location', DiscourseLocation);
|
app.register('location:discourse-location', DiscourseLocation);
|
||||||
@ -63,6 +70,6 @@ export default {
|
|||||||
app.register('key-value-store:main', keyValueStore, { instantiate: false });
|
app.register('key-value-store:main', keyValueStore, { instantiate: false });
|
||||||
injectAll(app, 'keyValueStore');
|
injectAll(app, 'keyValueStore');
|
||||||
|
|
||||||
startTracking(tracking);
|
startTracking(topicTrackingState);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -37,12 +37,6 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
|||||||
return this._super();
|
return this._super();
|
||||||
},
|
},
|
||||||
|
|
||||||
// This is here as a bugfix for when an Ember Cloaked view triggers
|
|
||||||
// a scroll after a controller has been torn down. The real fix
|
|
||||||
// should be to fix ember cloaking to not do that, but this catches
|
|
||||||
// it safely just in case.
|
|
||||||
postChangedRoute: Ember.K,
|
|
||||||
|
|
||||||
showTopicEntrance(data) {
|
showTopicEntrance(data) {
|
||||||
this.controllerFor('topic-entrance').send('show', data);
|
this.controllerFor('topic-entrance').send('show', data);
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import ScreenTrack from 'discourse/lib/screen-track';
|
|
||||||
import { queryParams } from 'discourse/controllers/discovery-sortable';
|
import { queryParams } from 'discourse/controllers/discovery-sortable';
|
||||||
|
|
||||||
// A helper to build a topic route for a filter
|
// A helper to build a topic route for a filter
|
||||||
@ -69,7 +68,7 @@ export default function(filter, extras) {
|
|||||||
|
|
||||||
model(data, transition) {
|
model(data, transition) {
|
||||||
// attempt to stop early cause we need this to be called before .sync
|
// attempt to stop early cause we need this to be called before .sync
|
||||||
ScreenTrack.current().stop();
|
this.screenTrack.stop();
|
||||||
|
|
||||||
const findOpts = filterQueryParams(data),
|
const findOpts = filterQueryParams(data),
|
||||||
findExtras = { cached: this.isPoppedState(transition) };
|
findExtras = { cached: this.isPoppedState(transition) };
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import ScreenTrack from 'discourse/lib/screen-track';
|
|
||||||
import DiscourseURL from 'discourse/lib/url';
|
import DiscourseURL from 'discourse/lib/url';
|
||||||
|
|
||||||
let isTransitioning = false,
|
let isTransitioning = false,
|
||||||
@ -186,7 +185,7 @@ const TopicRoute = Discourse.Route.extend({
|
|||||||
topicController.set('multiSelect', false);
|
topicController.set('multiSelect', false);
|
||||||
topicController.unsubscribe();
|
topicController.unsubscribe();
|
||||||
this.controllerFor('composer').set('topic', null);
|
this.controllerFor('composer').set('topic', null);
|
||||||
ScreenTrack.current().stop();
|
this.screenTrack.stop();
|
||||||
|
|
||||||
const headerController = this.controllerFor('header');
|
const headerController = this.controllerFor('header');
|
||||||
if (headerController) {
|
if (headerController) {
|
||||||
@ -215,8 +214,9 @@ const TopicRoute = Discourse.Route.extend({
|
|||||||
controller.subscribe();
|
controller.subscribe();
|
||||||
|
|
||||||
this.controllerFor('topic-progress').set('model', model);
|
this.controllerFor('topic-progress').set('model', model);
|
||||||
|
|
||||||
// We reset screen tracking every time a topic is entered
|
// We reset screen tracking every time a topic is entered
|
||||||
ScreenTrack.current().start(model.get('id'), controller);
|
this.screenTrack.start(model.get('id'), controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,7 @@ export default Discourse.Route.extend({
|
|||||||
// HACK: Something with the way the user card intercepts clicks seems to break how the
|
// HACK: Something with the way the user card intercepts clicks seems to break how the
|
||||||
// transition into a user's activity works. This makes the back button work on mobile
|
// transition into a user's activity works. This makes the back button work on mobile
|
||||||
// where there is no user card as well as desktop where there is.
|
// where there is no user card as well as desktop where there is.
|
||||||
if (Discourse.Mobile.mobileView) {
|
if (this.site.mobileView) {
|
||||||
this.replaceWith('userActivity');
|
this.replaceWith('userActivity');
|
||||||
} else {
|
} else {
|
||||||
this.transitionTo('userActivity');
|
this.transitionTo('userActivity');
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
{{#link-to 'user' user}}
|
{{#link-to 'user' user}}
|
||||||
{{avatar user imageSize="extra_large"}}
|
{{avatar user imageSize="extra_large"}}
|
||||||
<div class="details clearfix">
|
<div class="details clearfix">
|
||||||
{{poster-name post=user}}
|
<div class='username'>{{user.username}}</div>
|
||||||
</div>
|
</div>
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
<div class='earned'>
|
<div class='earned'>
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
<h3>{{fa-icon 'envelope'}} {{i18n 'private_message_info.title'}}</h3>
|
|
||||||
<div class='participants clearfix'>
|
|
||||||
{{#each details.allowed_groups as |ag|}}
|
|
||||||
<div class='user group'>
|
|
||||||
{{fa-icon 'users'}} {{#link-to "group.index" ag.name}}{{unbound ag.name}}{{/link-to}}
|
|
||||||
</div>
|
|
||||||
{{/each}}
|
|
||||||
{{#each details.allowed_users as |au|}}
|
|
||||||
<div class='user'>
|
|
||||||
{{#user-link user=au}}
|
|
||||||
{{avatar au imageSize="small"}}
|
|
||||||
{{unbound au.username}}
|
|
||||||
{{/user-link}}
|
|
||||||
{{#if details.can_remove_allowed_users}}
|
|
||||||
<a href class='remove-invited' {{action "removeAllowedUser" au}}>{{fa-icon "times"}}</a>
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
{{/each}}
|
|
||||||
</div>
|
|
||||||
{{#if details.can_invite_to}}
|
|
||||||
<div class='controls'>
|
|
||||||
<button class='btn' {{action "showPrivateInvite"}}>{{i18n 'private_message_info.invite'}}</button>
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
@ -1,4 +1,3 @@
|
|||||||
<div class='topic-avatar'>{{fa-icon icon}}</div>
|
|
||||||
<div class='small-action-desc'>
|
<div class='small-action-desc'>
|
||||||
{{#if post}}
|
{{#if post}}
|
||||||
{{#if post.can_delete}}
|
{{#if post.can_delete}}
|
||||||
@ -11,8 +10,4 @@
|
|||||||
{{avatar post imageSize="small"}}
|
{{avatar post imageSize="small"}}
|
||||||
</a>
|
</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<p>{{description}}</p>
|
|
||||||
{{#if post.cooked}}
|
|
||||||
<div class='custom-message'>{{{post.cooked}}}</div>
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
{{#if postStream.summary}}
|
|
||||||
<p>{{{i18n 'summary.enabled_description'}}}</p>
|
|
||||||
<button class='btn btn-primary' {{action "toggleSummary"}}>{{i18n 'summary.disable'}}</button>
|
|
||||||
{{else}}
|
|
||||||
{{#if topic.estimatedReadingTime}}
|
|
||||||
<p>{{{i18n 'summary.description_time' replyCount=topic.replyCount readingTime=topic.estimatedReadingTime}}}</p>
|
|
||||||
{{else}}
|
|
||||||
<p>{{{i18n 'summary.description' replyCount=topic.replyCount}}}</p>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
<button class='btn btn-primary' {{action "toggleSummary"}}>{{i18n 'summary.enable'}}</button>
|
|
||||||
{{/if}}
|
|
@ -1,6 +0,0 @@
|
|||||||
<a href {{bind-attr class=":poster toggled"}} {{action "toggle"}} title={{unbound participant.username}}>
|
|
||||||
{{#if showPostCount}}
|
|
||||||
<span class='post-count'>{{unbound participant.post_count}}</span>
|
|
||||||
{{/if}}
|
|
||||||
{{avatar participant imageSize="medium"}}
|
|
||||||
</a>
|
|
@ -1,16 +0,0 @@
|
|||||||
<div class='row'>
|
|
||||||
<div class='topic-avatar'>
|
|
||||||
{{raw "post/poster-avatar" post=this classNames="main-avatar"}}
|
|
||||||
</div>
|
|
||||||
<div class='topic-body'>
|
|
||||||
<div class="topic-meta-data">
|
|
||||||
{{poster-name post=this}}
|
|
||||||
{{#if view.parentView.previousPost}}<a href='{{unbound url}}' class="post-info arrow" title="{{i18n 'topic.jump_reply_up'}}"><i class='fa fa-arrow-up'></i></a>{{/if}}
|
|
||||||
{{#unless view.parentView.previousPost}}<a href='{{unbound url}}' class="post-info arrow" title="{{i18n 'topic.jump_reply_down'}}"><i class='fa fa-arrow-down'></i></a>{{/unless}}
|
|
||||||
<a href='{{unbound url}}'><div class='post-info post-date'>{{age-with-tooltip created_at}}</div></a>
|
|
||||||
</div>
|
|
||||||
<div class='cooked'>
|
|
||||||
{{{unbound cooked}}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -1,8 +0,0 @@
|
|||||||
<div class="modal-body">
|
|
||||||
<form>
|
|
||||||
{{view "archetype-options" archetype=view.archetype}}
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button class='btn btn-primary' {{action "closeModal"}}>{{i18n 'post.archetypes.save'}}</button>
|
|
||||||
</div>
|
|
@ -1,13 +0,0 @@
|
|||||||
<article class='placeholder'>
|
|
||||||
<div class='row'>
|
|
||||||
<div class="topic-avatar">
|
|
||||||
<div class='placeholder-avatar'></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class='topic-body'>
|
|
||||||
<div class='placeholder-text'></div>
|
|
||||||
<div class='placeholder-text'></div>
|
|
||||||
<div class='placeholder-text'></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
@ -1,9 +0,0 @@
|
|||||||
{{post-gap post=this postStream=controller.model.postStream before="true"}}
|
|
||||||
|
|
||||||
{{small-action actionCode=action_code
|
|
||||||
post=this
|
|
||||||
daysAgo=view.daysAgo
|
|
||||||
editPost="editPost"
|
|
||||||
deletePost="deletePost"}}
|
|
||||||
|
|
||||||
{{post-gap post=this postStream=controller.model.postStream before="false"}}
|
|
@ -1,141 +0,0 @@
|
|||||||
{{post-gap post=this postStream=controller.model.postStream before="true"}}
|
|
||||||
|
|
||||||
{{#if hasTimeGap}}
|
|
||||||
{{time-gap daysAgo=daysSincePrevious postStream=controller.model.postStream}}
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
<div class='row'>
|
|
||||||
{{view 'reply-history' content=replyHistory}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<article class="boxed {{if via_email 'via-email'}}" id={{view.postElementId}} data-post-id={{id}} data-user-id={{user_id}}>
|
|
||||||
<div class='row'>
|
|
||||||
|
|
||||||
<div class="topic-avatar">
|
|
||||||
{{#if userDeleted}}
|
|
||||||
<i class="fa fa-trash-o deleted-user-avatar"></i>
|
|
||||||
{{else}}
|
|
||||||
{{raw "post/poster-avatar" post=this classNames="main-avatar"}}
|
|
||||||
{{/if}}
|
|
||||||
<div class="poster-avatar-extra"></div>
|
|
||||||
{{plugin-outlet "poster-avatar-bottom"}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class='topic-body'>
|
|
||||||
<div class='topic-meta-data'>
|
|
||||||
{{poster-name post=this}}
|
|
||||||
{{plugin-outlet "poster-name-right"}}
|
|
||||||
<div class='post-info'>
|
|
||||||
<a class='post-date' {{bind-attr href="shareUrl" data-share-url="shareUrl" data-post-number="post_number"}}>{{age-with-tooltip created_at}}</a>
|
|
||||||
</div>
|
|
||||||
{{#if hasHistory}}
|
|
||||||
<div class='post-info edits'>
|
|
||||||
{{#if can_view_edit_history}}
|
|
||||||
<a href class="{{unbound view.historyHeat}}" {{action "showHistory" this}} title="{{i18n 'post.last_edited_on'}} {{raw-date updated_at}}">
|
|
||||||
{{editCount}}
|
|
||||||
{{fa-icon "pencil"}}
|
|
||||||
</a>
|
|
||||||
{{else}}
|
|
||||||
<span class="{{unbound view.historyHeat}}" title="{{i18n 'post.last_edited_on'}} {{raw-date updated_at}}">
|
|
||||||
{{editCount}}
|
|
||||||
{{fa-icon "pencil"}}
|
|
||||||
</span>
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
||||||
{{#if wiki}}
|
|
||||||
<div class="post-info wiki" title={{i18n 'post.wiki.about'}} {{action "editPost" this}}>{{fa-icon "pencil-square-o"}}</div>
|
|
||||||
{{/if}}
|
|
||||||
{{#if via_email}}
|
|
||||||
{{#if canViewRawEmail}}
|
|
||||||
<div class="post-info via-email raw-email" title={{i18n 'post.via_email'}} {{action "showRawEmail" this}}>{{fa-icon "envelope-o"}}</div>
|
|
||||||
{{else}}
|
|
||||||
<div class="post-info via-email" title={{i18n 'post.via_email'}}>{{fa-icon "envelope-o"}}</div>
|
|
||||||
{{/if}}
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
{{#if view.whisper}}
|
|
||||||
<div class="post-info whisper" title={{i18n 'post.whisper'}}>{{fa-icon "eye-slash"}}</div>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
{{#if showUserReplyTab}}
|
|
||||||
<a href {{action "toggleReplyHistory" this target="view"}} class='reply-to-tab'>
|
|
||||||
{{#if loadingReplyHistory}}
|
|
||||||
{{i18n 'loading'}}
|
|
||||||
{{else}}
|
|
||||||
{{fa-icon "mail-forward"}}
|
|
||||||
{{avatar reply_to_user imageSize="tiny"}}
|
|
||||||
<span>{{reply_to_user.username}}</span>
|
|
||||||
{{/if}}
|
|
||||||
</a>
|
|
||||||
{{/if}}
|
|
||||||
<div {{bind-attr class=":read-state read"}} title="{{i18n 'post.unread'}}">{{fa-icon "circle"}}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="select-posts {{unless controller.multiSelect 'hidden'}}">
|
|
||||||
<button {{action "toggledSelectedPostReplies" this}} class="{{unless view.canSelectReplies 'hidden'}}">{{i18n 'topic.multi_select.select_replies'}}</button>
|
|
||||||
<button {{action "toggledSelectedPost" this}} class="select-post">{{view.selectPostText}}</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- keep the classes here in sync with composer.hbs -->
|
|
||||||
<div {{bind-attr class="showUserReplyTab:avoid-tab view.repliesShown::contents :regular view.extraClass"}}>
|
|
||||||
<div class='cooked'>
|
|
||||||
{{{cooked}}}
|
|
||||||
{{plugin-outlet "post-after-cooked"}}
|
|
||||||
{{#if firstPost}}
|
|
||||||
{{plugin-outlet "topic-after-cooked"}}
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
{{#if cooked_hidden}}
|
|
||||||
<a href {{action "expandHidden" this}}>{{i18n 'post.show_hidden'}}</a>
|
|
||||||
{{/if}}
|
|
||||||
{{#if view.showExpandButton}}
|
|
||||||
{{#if controller.loadingExpanded}}
|
|
||||||
<button class="btn expand-post" disabled>{{i18n 'loading'}}</button>
|
|
||||||
{{else}}
|
|
||||||
<button {{action "expandFirstPost" this}} class='btn expand-post'>{{i18n 'post.show_full'}}…</button>
|
|
||||||
{{/if}}
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
{{post-menu post=this
|
|
||||||
canCreatePost=controller.model.details.can_create_post
|
|
||||||
replyToPost="replyToPost"
|
|
||||||
recoverPost="recoverPost"
|
|
||||||
deletePost="deletePost"
|
|
||||||
toggleLike="toggleLike"
|
|
||||||
toggleLikeTarget=view
|
|
||||||
showFlags="showFlags"
|
|
||||||
editPost="editPost"
|
|
||||||
toggleBookmark="toggleBookmark"
|
|
||||||
toggleWiki="toggleWiki"
|
|
||||||
togglePostType="togglePostType"
|
|
||||||
rebakePost="rebakePost"
|
|
||||||
unhidePost="unhidePost"
|
|
||||||
changePostOwner="changePostOwner"
|
|
||||||
toggleWhoLiked="toggleWhoLiked"
|
|
||||||
toggleWhoLikedTarget=view}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{who-liked users=view.likedUsers}}
|
|
||||||
{{#if replies}}
|
|
||||||
<section class='embedded-posts bottom'>
|
|
||||||
{{#each reply in replies}}
|
|
||||||
{{view 'embedded-post' content=reply}}
|
|
||||||
{{/each}}
|
|
||||||
</section>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
{{actions-summary post=this}}
|
|
||||||
{{view 'topic-map-container' post=this topic=controller.model}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{post-gutter post=this
|
|
||||||
links=internalLinks
|
|
||||||
canReplyAsNewTopic=topic.details.can_reply_as_new_topic
|
|
||||||
newTopicAction="replyAsNewTopic"}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</article>
|
|
||||||
|
|
||||||
{{post-gap post=this postStream=controller.model.postStream before="false"}}
|
|
||||||
{{plugin-outlet "post-bottom"}}
|
|
@ -69,15 +69,39 @@
|
|||||||
{{conditional-loading-spinner condition=model.postStream.loadingAbove}}
|
{{conditional-loading-spinner condition=model.postStream.loadingAbove}}
|
||||||
|
|
||||||
{{#unless model.postStream.loadingFilter}}
|
{{#unless model.postStream.loadingFilter}}
|
||||||
{{cloaked-collection itemViewClass="post"
|
{{scrolling-post-stream
|
||||||
defaultHeight="200"
|
posts=postsToRender
|
||||||
content=postsToRender
|
canCreatePost=model.details.can_create_post
|
||||||
slackRatio="15"
|
multiSelect=multiSelect
|
||||||
loadingHTML=""
|
selectedPostsCount=selectedPostsCount
|
||||||
preservesContext="true"
|
selectedQuery=selectedQuery
|
||||||
uncloakDefault="true"
|
gaps=model.postStream.gaps
|
||||||
offsetFixedTop="header"
|
showFlags="showFlags"
|
||||||
offsetFixedBottom="#reply-control"}}
|
editPost="editPost"
|
||||||
|
showHistory="showHistory"
|
||||||
|
showRawEmail="showRawEmail"
|
||||||
|
deletePost="deletePost"
|
||||||
|
recoverPost="recoverPost"
|
||||||
|
expandHidden="expandHidden"
|
||||||
|
newTopicAction="replyAsNewTopic"
|
||||||
|
expandFirstPost="expandFirstPost"
|
||||||
|
toggleBookmark="toggleBookmark"
|
||||||
|
togglePostType="togglePostType"
|
||||||
|
rebakePost="rebakePost"
|
||||||
|
changePostOwner="changePostOwner"
|
||||||
|
unhidePost="unhidePost"
|
||||||
|
replyToPost="replyToPost"
|
||||||
|
toggleWiki="toggleWiki"
|
||||||
|
toggleParticipant="toggleParticipant"
|
||||||
|
toggleSummary="toggleSummary"
|
||||||
|
removeAllowedUser="removeAllowedUser"
|
||||||
|
showInvite="showInvite"
|
||||||
|
topVisibleChanged="topVisibleChanged"
|
||||||
|
bottomVisibleChanged="bottomVisibleChanged"
|
||||||
|
selectPost="toggledSelectedPost"
|
||||||
|
selectReplies="toggledSelectedPostReplies"
|
||||||
|
fillGapBefore="fillGapBefore"
|
||||||
|
fillGapAfter="fillGapAfter"}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
<div id="topic-bottom"></div>
|
<div id="topic-bottom"></div>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<section class='user-navigation'>
|
<section class='user-navigation'>
|
||||||
{{#unless mobileView}}
|
{{#unless site.mobileView}}
|
||||||
{{#if showNewPM}}
|
{{#if showNewPM}}
|
||||||
{{d-button class="btn-primary new-private-message" action="composePrivateMessage" icon="envelope" label="user.new_private_message"}}
|
{{d-button class="btn-primary new-private-message" action="composePrivateMessage" icon="envelope" label="user.new_private_message"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
{{#mobile-nav class='messages-nav' desktopClass='nav-stacked action-list' currentPath=currentPath}}
|
{{#mobile-nav class='messages-nav' desktopClass='nav-stacked action-list' currentPath=currentPath}}
|
||||||
@ -47,10 +47,10 @@
|
|||||||
<i class="fa fa-list"></i>
|
<i class="fa fa-list"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{{#if mobileView}}
|
{{#if site.mobileView}}
|
||||||
{{#if showNewPM}}
|
{{#if showNewPM}}
|
||||||
{{d-button class="btn-primary new-private-message" action="composePrivateMessage" icon="envelope" label="user.new_private_message"}}
|
{{d-button class="btn-primary new-private-message" action="composePrivateMessage" icon="envelope" label="user.new_private_message"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if canArchive}}
|
{{#if canArchive}}
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
import DiscourseContainerView from 'discourse/views/container';
|
|
||||||
|
|
||||||
export default DiscourseContainerView.extend({
|
|
||||||
metaDataBinding: 'parentView.metaData',
|
|
||||||
|
|
||||||
init: function() {
|
|
||||||
this._super();
|
|
||||||
var metaData = this.get('metaData');
|
|
||||||
var archetypeOptionsView = this;
|
|
||||||
return this.get('archetype.options').forEach(function(a) {
|
|
||||||
if (a.option_type === 1) {
|
|
||||||
archetypeOptionsView.attachViewWithArgs({
|
|
||||||
content: a,
|
|
||||||
checked: metaData.get(a.key) === 'true'
|
|
||||||
}, Discourse.OptionBooleanView);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,300 +0,0 @@
|
|||||||
/*eslint no-bitwise:0 */
|
|
||||||
const CloakedCollectionView = Ember.CollectionView.extend({
|
|
||||||
cloakView: Ember.computed.alias('itemViewClass'),
|
|
||||||
topVisible: null,
|
|
||||||
bottomVisible: null,
|
|
||||||
offsetFixedTopElement: null,
|
|
||||||
offsetFixedBottomElement: null,
|
|
||||||
loadingHTML: 'Loading...',
|
|
||||||
scrollDebounce: 10,
|
|
||||||
|
|
||||||
init() {
|
|
||||||
const cloakView = this.get('cloakView'),
|
|
||||||
idProperty = this.get('idProperty'),
|
|
||||||
uncloakDefault = !!this.get('uncloakDefault');
|
|
||||||
|
|
||||||
// Set the slack ratio differently to allow for more or less slack in preloading
|
|
||||||
const slackRatio = parseFloat(this.get('slackRatio'));
|
|
||||||
if (!slackRatio) { this.set('slackRatio', 1.0); }
|
|
||||||
|
|
||||||
const CloakedView = this.container.lookupFactory('view:cloaked');
|
|
||||||
this.set('itemViewClass', CloakedView.extend({
|
|
||||||
classNames: [cloakView + '-cloak'],
|
|
||||||
cloaks: cloakView,
|
|
||||||
preservesContext: this.get('preservesContext') === 'true',
|
|
||||||
cloaksController: this.get('itemController'),
|
|
||||||
defaultHeight: this.get('defaultHeight'),
|
|
||||||
|
|
||||||
init() {
|
|
||||||
this._super();
|
|
||||||
if (idProperty) {
|
|
||||||
this.set('elementId', cloakView + '-cloak-' + this.get('content.' + idProperty));
|
|
||||||
}
|
|
||||||
if (uncloakDefault) {
|
|
||||||
this.uncloak();
|
|
||||||
} else {
|
|
||||||
this.cloak();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
this._super();
|
|
||||||
Ember.run.next(this, 'scrolled');
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
If the topmost visible view changed, we will notify the controller if it has an appropriate hook.
|
|
||||||
|
|
||||||
@method _topVisibleChanged
|
|
||||||
@observes topVisible
|
|
||||||
**/
|
|
||||||
_topVisibleChanged: function() {
|
|
||||||
const controller = this.get('controller');
|
|
||||||
if (controller.topVisibleChanged) { controller.topVisibleChanged(this.get('topVisible')); }
|
|
||||||
}.observes('topVisible'),
|
|
||||||
|
|
||||||
/**
|
|
||||||
If the bottommost visible view changed, we will notify the controller if it has an appropriate hook.
|
|
||||||
|
|
||||||
@method _bottomVisible
|
|
||||||
@observes bottomVisible
|
|
||||||
**/
|
|
||||||
_bottomVisible: function() {
|
|
||||||
const controller = this.get('controller');
|
|
||||||
if (controller.bottomVisibleChanged) { controller.bottomVisibleChanged(this.get('bottomVisible')); }
|
|
||||||
}.observes('bottomVisible'),
|
|
||||||
|
|
||||||
/**
|
|
||||||
Binary search for finding the topmost view on screen.
|
|
||||||
|
|
||||||
@method findTopView
|
|
||||||
@param {Array} childViews the childViews to search through
|
|
||||||
@param {Number} windowTop The top of the viewport to search against
|
|
||||||
@param {Number} min The minimum index to search through of the child views
|
|
||||||
@param {Number} max The max index to search through of the child views
|
|
||||||
@returns {Number} the index into childViews of the topmost view
|
|
||||||
**/
|
|
||||||
findTopView(childViews, viewportTop, min, max) {
|
|
||||||
if (max < min) { return min; }
|
|
||||||
|
|
||||||
const wrapperTop = this.get('wrapperTop')>>0;
|
|
||||||
|
|
||||||
while(max>min){
|
|
||||||
const mid = Math.floor((min + max) / 2),
|
|
||||||
// in case of not full-window scrolling
|
|
||||||
$view = childViews[mid].$(),
|
|
||||||
|
|
||||||
// .position is quite expensive, shortcut here to get a slightly rougher
|
|
||||||
// but much faster value
|
|
||||||
parentOffsetTop = $view.offsetParent().offset().top,
|
|
||||||
offsetTop = $view.offset().top,
|
|
||||||
viewBottom = (offsetTop - parentOffsetTop) + wrapperTop + $view.height();
|
|
||||||
|
|
||||||
if (viewBottom > viewportTop) {
|
|
||||||
max = mid-1;
|
|
||||||
} else {
|
|
||||||
min = mid+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return min;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Determine what views are onscreen and cloak/uncloak them as necessary.
|
|
||||||
|
|
||||||
@method scrolled
|
|
||||||
**/
|
|
||||||
scrolled() {
|
|
||||||
if (!this.get('scrollingEnabled')) { return; }
|
|
||||||
|
|
||||||
const childViews = this.get('childViews');
|
|
||||||
if ((!childViews) || (childViews.length === 0)) { return; }
|
|
||||||
|
|
||||||
const self = this,
|
|
||||||
toUncloak = [],
|
|
||||||
onscreen = [],
|
|
||||||
onscreenCloaks = [],
|
|
||||||
$w = $(window),
|
|
||||||
windowHeight = this.get('wrapperHeight') || ( window.innerHeight ? window.innerHeight : $w.height() ),
|
|
||||||
slack = Math.round(windowHeight * this.get('slackRatio')),
|
|
||||||
offsetFixedTopElement = this.get('offsetFixedTopElement'),
|
|
||||||
offsetFixedBottomElement = this.get('offsetFixedBottomElement'),
|
|
||||||
bodyHeight = this.get('wrapperHeight') ? this.$().height() : $('body').height();
|
|
||||||
|
|
||||||
let windowTop = this.get('wrapperTop') || $w.scrollTop();
|
|
||||||
|
|
||||||
const viewportTop = windowTop - slack,
|
|
||||||
topView = this.findTopView(childViews, viewportTop, 0, childViews.length-1);
|
|
||||||
|
|
||||||
let windowBottom = windowTop + windowHeight;
|
|
||||||
let viewportBottom = windowBottom + slack;
|
|
||||||
|
|
||||||
if (windowBottom > bodyHeight) { windowBottom = bodyHeight; }
|
|
||||||
if (viewportBottom > bodyHeight) { viewportBottom = bodyHeight; }
|
|
||||||
|
|
||||||
if (offsetFixedTopElement) {
|
|
||||||
windowTop += (offsetFixedTopElement.outerHeight(true) || 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offsetFixedBottomElement) {
|
|
||||||
windowBottom -= (offsetFixedBottomElement.outerHeight(true) || 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the bottom view and what's onscreen
|
|
||||||
let bottomView = topView;
|
|
||||||
let bottomVisible = null;
|
|
||||||
while (bottomView < childViews.length) {
|
|
||||||
const view = childViews[bottomView];
|
|
||||||
const $view = view.$();
|
|
||||||
|
|
||||||
if (!$view) { break; }
|
|
||||||
|
|
||||||
// in case of not full-window scrolling
|
|
||||||
const scrollOffset = this.get('wrapperTop') || 0;
|
|
||||||
const viewTop = $view.offset().top + scrollOffset;
|
|
||||||
const viewBottom = viewTop + $view.height();
|
|
||||||
|
|
||||||
if (viewTop > viewportBottom) { break; }
|
|
||||||
toUncloak.push(view);
|
|
||||||
|
|
||||||
if (viewBottom > windowTop && viewTop <= windowBottom) {
|
|
||||||
const content = view.get('content');
|
|
||||||
onscreen.push(content);
|
|
||||||
|
|
||||||
if (!view.get('isPlaceholder')) {
|
|
||||||
bottomVisible = content;
|
|
||||||
}
|
|
||||||
onscreenCloaks.push(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
bottomView++;
|
|
||||||
}
|
|
||||||
if (bottomView >= childViews.length) { bottomView = childViews.length - 1; }
|
|
||||||
|
|
||||||
// If our controller has a `sawObjects` method, pass the on screen objects to it.
|
|
||||||
const controller = this.get('controller');
|
|
||||||
if (onscreen.length) {
|
|
||||||
this.setProperties({topVisible: onscreen[0], bottomVisible });
|
|
||||||
if (controller && controller.sawObjects) {
|
|
||||||
Em.run.schedule('afterRender', function() {
|
|
||||||
controller.sawObjects(onscreen);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.setProperties({topVisible: null, bottomVisible: null});
|
|
||||||
}
|
|
||||||
|
|
||||||
const toCloak = childViews.slice(0, topView).concat(childViews.slice(bottomView+1));
|
|
||||||
|
|
||||||
this._uncloak = toUncloak;
|
|
||||||
if(this._nextUncloak){
|
|
||||||
Em.run.cancel(this._nextUncloak);
|
|
||||||
this._nextUncloak = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Em.run.schedule('afterRender', this, function() {
|
|
||||||
onscreenCloaks.forEach(function (v) {
|
|
||||||
if(v && v.uncloak) {
|
|
||||||
v.uncloak();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
toCloak.forEach(function (v) { v.cloak(); });
|
|
||||||
if (self._nextUncloak) { Em.run.cancel(self._nextUncloak); }
|
|
||||||
self._nextUncloak = Em.run.later(self, self.uncloakQueue,50);
|
|
||||||
});
|
|
||||||
|
|
||||||
for (let j=bottomView; j<childViews.length; j++) {
|
|
||||||
const checkView = childViews[j];
|
|
||||||
if (!checkView._containedView) {
|
|
||||||
const loadingHTML = this.get('loadingHTML');
|
|
||||||
if (!Em.isEmpty(loadingHTML) && !checkView.get('loading')) {
|
|
||||||
checkView.$().html(loadingHTML);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
uncloakQueue() {
|
|
||||||
const maxPerRun = 3, delay = 50, self = this;
|
|
||||||
let processed = 0;
|
|
||||||
|
|
||||||
if(this._uncloak){
|
|
||||||
while(processed < maxPerRun && this._uncloak.length>0){
|
|
||||||
const view = this._uncloak.shift();
|
|
||||||
if(view && view.uncloak && !view._containedView){
|
|
||||||
Em.run.schedule('afterRender', view, view.uncloak);
|
|
||||||
processed++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(this._uncloak.length === 0){
|
|
||||||
this._uncloak = null;
|
|
||||||
} else {
|
|
||||||
Em.run.schedule('afterRender', self, function(){
|
|
||||||
if(self._nextUncloak){
|
|
||||||
Em.run.cancel(self._nextUncloak);
|
|
||||||
}
|
|
||||||
self._nextUncloak = Em.run.next(self, function(){
|
|
||||||
if(self._nextUncloak){
|
|
||||||
Em.run.cancel(self._nextUncloak);
|
|
||||||
}
|
|
||||||
self._nextUncloak = Em.run.later(self,self.uncloakQueue,delay);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
scrollTriggered() {
|
|
||||||
if ($('body').data('disable-cloaked-view')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Em.run.scheduleOnce('afterRender', this, 'scrolled');
|
|
||||||
},
|
|
||||||
|
|
||||||
_startEvents: function() {
|
|
||||||
if (this.get('offsetFixed')) {
|
|
||||||
Em.warn("Cloaked-collection's `offsetFixed` is deprecated. Use `offsetFixedTop` instead.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const self = this,
|
|
||||||
offsetFixedTop = this.get('offsetFixedTop') || this.get('offsetFixed'),
|
|
||||||
offsetFixedBottom = this.get('offsetFixedBottom'),
|
|
||||||
scrollDebounce = this.get('scrollDebounce'),
|
|
||||||
onScrollMethod = function() {
|
|
||||||
Ember.run.debounce(self, 'scrollTriggered', scrollDebounce);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (offsetFixedTop) {
|
|
||||||
this.set('offsetFixedTopElement', $(offsetFixedTop));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offsetFixedBottom) {
|
|
||||||
this.set('offsetFixedBottomElement', $(offsetFixedBottom));
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).bind('touchmove.ember-cloak', onScrollMethod);
|
|
||||||
$(window).bind('scroll.ember-cloak', onScrollMethod);
|
|
||||||
this.addObserver('wrapperTop', self, onScrollMethod);
|
|
||||||
this.addObserver('wrapperHeight', self, onScrollMethod);
|
|
||||||
this.addObserver('content.@each', self, onScrollMethod);
|
|
||||||
this.scrollTriggered();
|
|
||||||
|
|
||||||
this.set('scrollingEnabled', true);
|
|
||||||
}.on('didInsertElement'),
|
|
||||||
|
|
||||||
cleanUp() {
|
|
||||||
$(document).unbind('touchmove.ember-cloak');
|
|
||||||
$(window).unbind('scroll.ember-cloak');
|
|
||||||
this.set('scrollingEnabled', false);
|
|
||||||
},
|
|
||||||
|
|
||||||
_endEvents: function() {
|
|
||||||
this.cleanUp();
|
|
||||||
}.on('willDestroyElement')
|
|
||||||
});
|
|
||||||
|
|
||||||
Ember.Handlebars.helper('cloaked-collection', Ember.testing ? Ember.CollectionView : CloakedCollectionView);
|
|
||||||
export default CloakedCollectionView;
|
|
@ -1,143 +0,0 @@
|
|||||||
export function Placeholder(viewName) {
|
|
||||||
this.viewName = viewName;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Ember.View.extend({
|
|
||||||
attributeBindings: ['style'],
|
|
||||||
_containedView: null,
|
|
||||||
_scheduled: null,
|
|
||||||
isPlaceholder: null,
|
|
||||||
|
|
||||||
init() {
|
|
||||||
this._super();
|
|
||||||
this._scheduled = false;
|
|
||||||
this._childViews = [];
|
|
||||||
},
|
|
||||||
|
|
||||||
setContainedView(cv) {
|
|
||||||
if (this._childViews[0]) {
|
|
||||||
this._childViews[0].destroy();
|
|
||||||
this._childViews[0] = cv;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.set('isPlaceholder', cv && (cv.get('content') instanceof Placeholder));
|
|
||||||
|
|
||||||
if (cv) {
|
|
||||||
cv.set('_parentView', this);
|
|
||||||
cv.set('templateData', this.get('templateData'));
|
|
||||||
this._childViews[0] = cv;
|
|
||||||
} else {
|
|
||||||
this._childViews.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._scheduled) return;
|
|
||||||
this._scheduled = true;
|
|
||||||
this.set('_containedView', cv);
|
|
||||||
Ember.run.schedule('render', this, this.updateChildView);
|
|
||||||
},
|
|
||||||
|
|
||||||
render(buffer) {
|
|
||||||
const element = buffer.element();
|
|
||||||
const dom = buffer.dom;
|
|
||||||
|
|
||||||
this._childViewsMorph = dom.appendMorph(element);
|
|
||||||
},
|
|
||||||
|
|
||||||
updateChildView() {
|
|
||||||
this._scheduled = false;
|
|
||||||
if (!this._elementCreated || this.isDestroying || this.isDestroyed) { return; }
|
|
||||||
|
|
||||||
const childView = this._containedView;
|
|
||||||
if (childView && !childView._elementCreated) {
|
|
||||||
this._renderer.renderTree(childView, this, 0);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Triggers the set up for rendering a view that is cloaked.
|
|
||||||
|
|
||||||
@method uncloak
|
|
||||||
*/
|
|
||||||
uncloak() {
|
|
||||||
const state = this._state || this.state;
|
|
||||||
if (state !== 'inDOM' && state !== 'preRender') { return; }
|
|
||||||
|
|
||||||
if (!this._containedView) {
|
|
||||||
const model = this.get('content');
|
|
||||||
const container = this.get('container');
|
|
||||||
|
|
||||||
let controller;
|
|
||||||
|
|
||||||
// Wire up the itemController if necessary
|
|
||||||
const controllerName = this.get('cloaksController');
|
|
||||||
if (controllerName) {
|
|
||||||
const controllerFullName = 'controller:' + controllerName;
|
|
||||||
let factory = container.lookupFactory(controllerFullName);
|
|
||||||
|
|
||||||
// let ember generate controller if needed
|
|
||||||
if (!factory) {
|
|
||||||
factory = Ember.generateControllerFactory(container, controllerName, model);
|
|
||||||
|
|
||||||
// inform developer about typo
|
|
||||||
Ember.Logger.warn('ember-cloaking: can\'t lookup controller by name "' + controllerFullName + '".');
|
|
||||||
Ember.Logger.warn('ember-cloaking: using ' + factory.toString() + '.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const parentController = this.get('controller');
|
|
||||||
controller = factory.create({ model, parentController, target: parentController });
|
|
||||||
}
|
|
||||||
|
|
||||||
const createArgs = {};
|
|
||||||
const target = controller || model;
|
|
||||||
|
|
||||||
if (this.get('preservesContext')) {
|
|
||||||
createArgs.content = target;
|
|
||||||
} else {
|
|
||||||
createArgs.context = target;
|
|
||||||
}
|
|
||||||
if (controller) { createArgs.controller = controller; }
|
|
||||||
this.setProperties({ style: ''.htmlSafe(), loading: false });
|
|
||||||
|
|
||||||
const cloaks = target && (target instanceof Placeholder) ? target.viewName : this.get('cloaks');
|
|
||||||
this.setContainedView(this.createChildView(cloaks, createArgs));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Removes the view from the DOM and tears down all observers.
|
|
||||||
|
|
||||||
@method cloak
|
|
||||||
*/
|
|
||||||
cloak() {
|
|
||||||
const self = this;
|
|
||||||
|
|
||||||
if (this._containedView && (this._state || this.state) === 'inDOM') {
|
|
||||||
const style = `height: ${this.$().height()}px;`.htmlSafe();
|
|
||||||
this.set('style', style);
|
|
||||||
this.$().prop('style', style);
|
|
||||||
|
|
||||||
|
|
||||||
// We need to remove the container after the height of the element has taken
|
|
||||||
// effect.
|
|
||||||
Ember.run.schedule('afterRender', function() {
|
|
||||||
self.setContainedView(null);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_setHeights: function(){
|
|
||||||
if (!this._containedView) {
|
|
||||||
// setting default height
|
|
||||||
// but do not touch if height already defined
|
|
||||||
if(!this.$().height()){
|
|
||||||
let defaultHeight = 100;
|
|
||||||
if(this.get('defaultHeight')) {
|
|
||||||
defaultHeight = this.get('defaultHeight');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.$().css('height', defaultHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.on('didInsertElement')
|
|
||||||
});
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
|||||||
import ScreenTrack from 'discourse/lib/screen-track';
|
|
||||||
|
|
||||||
export default Discourse.GroupedView.extend({
|
|
||||||
templateName: 'embedded-post',
|
|
||||||
classNames: ['reply'],
|
|
||||||
attributeBindings: ['data-post-id'],
|
|
||||||
'data-post-id': Em.computed.alias('content.id'),
|
|
||||||
|
|
||||||
_startTracking: function() {
|
|
||||||
const post = this.get('content');
|
|
||||||
ScreenTrack.current().track(this.get('elementId'), post.get('post_number'));
|
|
||||||
}.on('didInsertElement'),
|
|
||||||
|
|
||||||
_stopTracking: function() {
|
|
||||||
ScreenTrack.current().stopTracking(this.get('elementId'));
|
|
||||||
}.on('willDestroyElement')
|
|
||||||
});
|
|
@ -1,10 +0,0 @@
|
|||||||
export default Ember.View.extend({
|
|
||||||
_groupInit: function() {
|
|
||||||
this.set('context', this.get('content'));
|
|
||||||
|
|
||||||
const templateData = this.get('templateData');
|
|
||||||
if (templateData) {
|
|
||||||
this.set('templateData.insideGroup', true);
|
|
||||||
}
|
|
||||||
}.on('init')
|
|
||||||
});
|
|
@ -9,7 +9,7 @@ export default Ember.View.extend({
|
|||||||
$('#discourse-modal').modal('show');
|
$('#discourse-modal').modal('show');
|
||||||
|
|
||||||
// Focus on first element
|
// Focus on first element
|
||||||
if (!Discourse.Mobile.mobileView && this.get('focusInput')) {
|
if (!this.site.mobileView && this.get('focusInput')) {
|
||||||
Em.run.schedule('afterRender', () => this.$('input:first').focus());
|
Em.run.schedule('afterRender', () => this.$('input:first').focus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
export default Discourse.GroupedView.extend({
|
|
||||||
classNames: ['archetype-option'],
|
|
||||||
composerControllerBinding: 'Discourse.router.composerController',
|
|
||||||
templateName: "modal/option_boolean",
|
|
||||||
|
|
||||||
_checkedChanged: function() {
|
|
||||||
var metaData = this.get('parentView.metaData');
|
|
||||||
metaData.set(this.get('content.key'), this.get('checked') ? 'true' : 'false');
|
|
||||||
this.get('controller.controllers.composer').saveDraft();
|
|
||||||
}.observes('checked')
|
|
||||||
});
|
|
@ -1 +0,0 @@
|
|||||||
export default Ember.View.extend({ templateName: 'post-placeholder' });
|
|
@ -1,383 +0,0 @@
|
|||||||
import ScreenTrack from 'discourse/lib/screen-track';
|
|
||||||
import { number } from 'discourse/lib/formatter';
|
|
||||||
import DiscourseURL from 'discourse/lib/url';
|
|
||||||
import { default as computed, on } from 'ember-addons/ember-computed-decorators';
|
|
||||||
import { fmt } from 'discourse/lib/computed';
|
|
||||||
import { isValidLink } from 'discourse/lib/click-track';
|
|
||||||
|
|
||||||
const DAY = 60 * 50 * 1000;
|
|
||||||
|
|
||||||
const PostView = Discourse.GroupedView.extend(Ember.Evented, {
|
|
||||||
classNames: ['topic-post', 'clearfix'],
|
|
||||||
classNameBindings: ['needsModeratorClass:moderator:regular',
|
|
||||||
'selected',
|
|
||||||
'post.hidden:post-hidden',
|
|
||||||
'post.deleted:deleted',
|
|
||||||
'post.topicOwner:topic-owner',
|
|
||||||
'groupNameClass',
|
|
||||||
'post.wiki:wiki',
|
|
||||||
'whisper'],
|
|
||||||
|
|
||||||
post: Ember.computed.alias('content'),
|
|
||||||
postElementId: fmt('post.post_number', 'post_%@'),
|
|
||||||
likedUsers: null,
|
|
||||||
|
|
||||||
@on('init')
|
|
||||||
initLikedUsers() {
|
|
||||||
this.set('likedUsers', []);
|
|
||||||
},
|
|
||||||
|
|
||||||
@computed('post.post_type')
|
|
||||||
whisper(postType) {
|
|
||||||
return postType === this.site.get('post_types.whisper');
|
|
||||||
},
|
|
||||||
|
|
||||||
templateName: function() {
|
|
||||||
return (this.get('post.post_type') === this.site.get('post_types.small_action')) ? 'post-small-action' : 'post';
|
|
||||||
}.property('post.post_type'),
|
|
||||||
|
|
||||||
historyHeat: function() {
|
|
||||||
const updatedAt = this.get('post.updated_at');
|
|
||||||
if (!updatedAt) { return; }
|
|
||||||
|
|
||||||
// Show heat on age
|
|
||||||
const rightNow = new Date().getTime(),
|
|
||||||
updatedAtDate = new Date(updatedAt).getTime();
|
|
||||||
|
|
||||||
if (updatedAtDate > (rightNow - DAY * Discourse.SiteSettings.history_hours_low)) return 'heatmap-high';
|
|
||||||
if (updatedAtDate > (rightNow - DAY * Discourse.SiteSettings.history_hours_medium)) return 'heatmap-med';
|
|
||||||
if (updatedAtDate > (rightNow - DAY * Discourse.SiteSettings.history_hours_high)) return 'heatmap-low';
|
|
||||||
}.property('post.updated_at'),
|
|
||||||
|
|
||||||
needsModeratorClass: function() {
|
|
||||||
return (this.get('post.post_type') === this.site.get('post_types.moderator_action')) ||
|
|
||||||
(this.get('post.topic.is_warning') && this.get('post.firstPost'));
|
|
||||||
}.property('post.post_type'),
|
|
||||||
|
|
||||||
groupNameClass: function() {
|
|
||||||
const primaryGroupName = this.get('post.primary_group_name');
|
|
||||||
if (primaryGroupName) {
|
|
||||||
return "group-" + primaryGroupName;
|
|
||||||
}
|
|
||||||
}.property('post.primary_group_name'),
|
|
||||||
|
|
||||||
showExpandButton: function() {
|
|
||||||
if (this.get('controller.firstPostExpanded')) { return false; }
|
|
||||||
|
|
||||||
const post = this.get('post');
|
|
||||||
return post.get('post_number') === 1 && post.get('topic.expandable_first_post');
|
|
||||||
}.property('post.post_number', 'controller.firstPostExpanded'),
|
|
||||||
|
|
||||||
// If the cooked content changed, add the quote controls
|
|
||||||
cookedChanged: function() {
|
|
||||||
Em.run.scheduleOnce('afterRender', this, '_cookedWasChanged');
|
|
||||||
}.observes('post.cooked'),
|
|
||||||
|
|
||||||
_cookedWasChanged() {
|
|
||||||
this.trigger('postViewUpdated', this.$());
|
|
||||||
this._insertQuoteControls();
|
|
||||||
},
|
|
||||||
|
|
||||||
mouseUp(e) {
|
|
||||||
if (this.get('controller.multiSelect') && (e.metaKey || e.ctrlKey)) {
|
|
||||||
this.get('controller').toggledSelectedPost(this.get('post'));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
selected: function() {
|
|
||||||
return this.get('controller').postSelected(this.get('post'));
|
|
||||||
}.property('controller.selectedPostsCount'),
|
|
||||||
|
|
||||||
canSelectReplies: function() {
|
|
||||||
if (this.get('post.reply_count') === 0) { return false; }
|
|
||||||
return !this.get('selected');
|
|
||||||
}.property('post.reply_count', 'selected'),
|
|
||||||
|
|
||||||
selectPostText: function() {
|
|
||||||
return this.get('selected') ? I18n.t('topic.multi_select.selected', { count: this.get('controller.selectedPostsCount') }) : I18n.t('topic.multi_select.select');
|
|
||||||
}.property('selected', 'controller.selectedPostsCount'),
|
|
||||||
|
|
||||||
repliesShown: Em.computed.gt('post.replies.length', 0),
|
|
||||||
|
|
||||||
_updateQuoteElements($aside, desc) {
|
|
||||||
let navLink = "";
|
|
||||||
const quoteTitle = I18n.t("post.follow_quote"),
|
|
||||||
postNumber = $aside.data('post');
|
|
||||||
|
|
||||||
if (postNumber) {
|
|
||||||
|
|
||||||
// If we have a topic reference
|
|
||||||
let topicId, topic;
|
|
||||||
if (topicId = $aside.data('topic')) {
|
|
||||||
topic = this.get('controller.content');
|
|
||||||
|
|
||||||
// If it's the same topic as ours, build the URL from the topic object
|
|
||||||
if (topic && topic.get('id') === topicId) {
|
|
||||||
navLink = `<a href='${topic.urlForPostNumber(postNumber)}' title='${quoteTitle}' class='back'></a>`;
|
|
||||||
} else {
|
|
||||||
// Made up slug should be replaced with canonical URL
|
|
||||||
navLink = `<a href='${Discourse.getURL("/t/via-quote/") + topicId + "/" + postNumber}' title='${quoteTitle}' class='quote-other-topic'></a>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (topic = this.get('controller.content')) {
|
|
||||||
// assume the same topic
|
|
||||||
navLink = `<a href='${topic.urlForPostNumber(postNumber)}' title='${quoteTitle}' class='back'></a>`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Only add the expand/contract control if it's not a full post
|
|
||||||
let expandContract = "";
|
|
||||||
if (!$aside.data('full')) {
|
|
||||||
expandContract = `<i class='fa fa-${desc}' title='${I18n.t("post.expand_collapse")}'></i>`;
|
|
||||||
$('.title', $aside).css('cursor', 'pointer');
|
|
||||||
}
|
|
||||||
$('.quote-controls', $aside).html(expandContract + navLink);
|
|
||||||
},
|
|
||||||
|
|
||||||
_toggleQuote($aside) {
|
|
||||||
if (this.get('expanding')) { return; }
|
|
||||||
|
|
||||||
this.set('expanding', true);
|
|
||||||
|
|
||||||
$aside.data('expanded', !$aside.data('expanded'));
|
|
||||||
|
|
||||||
const finished = () => this.set('expanding', false);
|
|
||||||
|
|
||||||
if ($aside.data('expanded')) {
|
|
||||||
this._updateQuoteElements($aside, 'chevron-up');
|
|
||||||
// Show expanded quote
|
|
||||||
const $blockQuote = $('blockquote', $aside);
|
|
||||||
$aside.data('original-contents', $blockQuote.html());
|
|
||||||
|
|
||||||
const originalText = $blockQuote.text().trim();
|
|
||||||
$blockQuote.html(I18n.t("loading"));
|
|
||||||
let topicId = this.get('post.topic_id');
|
|
||||||
if ($aside.data('topic')) {
|
|
||||||
topicId = $aside.data('topic');
|
|
||||||
}
|
|
||||||
|
|
||||||
const postId = parseInt($aside.data('post'), 10);
|
|
||||||
topicId = parseInt(topicId, 10);
|
|
||||||
|
|
||||||
Discourse.ajax(`/posts/by_number/${topicId}/${postId}`).then(result => {
|
|
||||||
const div = $("<div class='expanded-quote'></div>");
|
|
||||||
div.html(result.cooked);
|
|
||||||
div.highlight(originalText, {caseSensitive: true, element: 'span', className: 'highlighted'});
|
|
||||||
$blockQuote.showHtml(div, 'fast', finished);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Hide expanded quote
|
|
||||||
this._updateQuoteElements($aside, 'chevron-down');
|
|
||||||
$('blockquote', $aside).showHtml($aside.data('original-contents'), 'fast', finished);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Show how many times links have been clicked on
|
|
||||||
_showLinkCounts() {
|
|
||||||
const self = this,
|
|
||||||
link_counts = this.get('post.link_counts');
|
|
||||||
|
|
||||||
if (!link_counts) { return; }
|
|
||||||
|
|
||||||
link_counts.forEach(function(lc) {
|
|
||||||
if (!lc.clicks || lc.clicks < 1) { return; }
|
|
||||||
|
|
||||||
self.$(".cooked a[href]").each(function() {
|
|
||||||
const $link = $(this),
|
|
||||||
href = $link.attr('href');
|
|
||||||
|
|
||||||
let valid = href === lc.url;
|
|
||||||
|
|
||||||
// this might be an attachment
|
|
||||||
if (lc.internal && /^\/uploads\//.test(lc.url)) {
|
|
||||||
valid = href.indexOf(lc.url) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valid) {
|
|
||||||
// don't display badge counts on category badge & oneboxes (unless when explicitely stated)
|
|
||||||
if (isValidLink($link)) {
|
|
||||||
$link.append("<span class='badge badge-notification clicks' title='" + I18n.t("topic_map.clicks", {count: lc.clicks}) + "'>" + number(lc.clicks) + "</span>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
toggleLike() {
|
|
||||||
const currentUser = this.get('controller.currentUser');
|
|
||||||
const post = this.get('post');
|
|
||||||
const likeAction = post.get('likeAction');
|
|
||||||
if (likeAction && likeAction.get('canToggle')) {
|
|
||||||
const users = this.get('likedUsers');
|
|
||||||
const store = this.get('controller.store');
|
|
||||||
const action = store.createRecord('post-action-user',
|
|
||||||
currentUser.getProperties('id', 'username', 'avatar_template')
|
|
||||||
);
|
|
||||||
|
|
||||||
if (likeAction.toggle(post) && users.get('length')) {
|
|
||||||
users.addObject(action);
|
|
||||||
} else {
|
|
||||||
users.removeObject(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
toggleWhoLiked() {
|
|
||||||
const post = this.get('post');
|
|
||||||
const likeAction = post.get('likeAction');
|
|
||||||
if (likeAction) {
|
|
||||||
const users = this.get('likedUsers');
|
|
||||||
if (users.get('length')) {
|
|
||||||
users.clear();
|
|
||||||
} else {
|
|
||||||
likeAction.loadUsers(post).then(newUsers => this.set('likedUsers', newUsers));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Toggle the replies this post is a reply to
|
|
||||||
toggleReplyHistory(post) {
|
|
||||||
const replyHistory = post.get('replyHistory'),
|
|
||||||
topicController = this.get('controller'),
|
|
||||||
origScrollTop = $(window).scrollTop(),
|
|
||||||
replyPostNumber = this.get('post.reply_to_post_number'),
|
|
||||||
postNumber = this.get('post.post_number'),
|
|
||||||
self = this;
|
|
||||||
|
|
||||||
if (Discourse.Mobile.mobileView) {
|
|
||||||
DiscourseURL.routeTo(this.get('post.topic').urlForPostNumber(replyPostNumber));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const stream = topicController.get('model.postStream');
|
|
||||||
const offsetFromTop = this.$().position().top - $(window).scrollTop();
|
|
||||||
|
|
||||||
if(Discourse.SiteSettings.experimental_reply_expansion) {
|
|
||||||
if(postNumber - replyPostNumber > 1) {
|
|
||||||
stream.collapsePosts(replyPostNumber + 1, postNumber - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Em.run.next(function() {
|
|
||||||
PostView.highlight(replyPostNumber);
|
|
||||||
$(window).scrollTop(self.$().position().top - offsetFromTop);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (replyHistory.length > 0) {
|
|
||||||
const origHeight = this.$('.embedded-posts.top').height();
|
|
||||||
|
|
||||||
replyHistory.clear();
|
|
||||||
Em.run.next(function() {
|
|
||||||
$(window).scrollTop(origScrollTop - origHeight);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
post.set('loadingReplyHistory', true);
|
|
||||||
|
|
||||||
stream.findReplyHistory(post).then(function () {
|
|
||||||
post.set('loadingReplyHistory', false);
|
|
||||||
|
|
||||||
Em.run.next(function() {
|
|
||||||
$(window).scrollTop(origScrollTop + self.$('.embedded-posts.top').height());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Add the quote controls to a post
|
|
||||||
_insertQuoteControls() {
|
|
||||||
const self = this,
|
|
||||||
$quotes = this.$('aside.quote');
|
|
||||||
|
|
||||||
// Safety check - in some cases with cloackedView this seems to be `undefined`.
|
|
||||||
if (Em.isEmpty($quotes)) { return; }
|
|
||||||
|
|
||||||
$quotes.each(function(i, e) {
|
|
||||||
const $aside = $(e);
|
|
||||||
if ($aside.data('post')) {
|
|
||||||
self._updateQuoteElements($aside, 'chevron-down');
|
|
||||||
const $title = $('.title', $aside);
|
|
||||||
|
|
||||||
// Unless it's a full quote, allow click to expand
|
|
||||||
if (!($aside.data('full') || $title.data('has-quote-controls'))) {
|
|
||||||
$title.on('click', function(e2) {
|
|
||||||
if ($(e2.target).is('a')) return true;
|
|
||||||
self._toggleQuote($aside);
|
|
||||||
});
|
|
||||||
$title.data('has-quote-controls', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
_destroyedPostView: function() {
|
|
||||||
ScreenTrack.current().stopTracking(this.get('elementId'));
|
|
||||||
}.on('willDestroyElement'),
|
|
||||||
|
|
||||||
_postViewInserted: function() {
|
|
||||||
const $post = this.$(),
|
|
||||||
postNumber = this.get('post').get('post_number');
|
|
||||||
|
|
||||||
this._showLinkCounts();
|
|
||||||
|
|
||||||
ScreenTrack.current().track($post.prop('id'), postNumber);
|
|
||||||
|
|
||||||
this.trigger('postViewInserted', $post);
|
|
||||||
|
|
||||||
// Find all the quotes
|
|
||||||
Em.run.scheduleOnce('afterRender', this, '_insertQuoteControls');
|
|
||||||
|
|
||||||
$post.closest('.post-cloak').attr('data-post-number', postNumber);
|
|
||||||
this._applySearchHighlight();
|
|
||||||
}.on('didInsertElement'),
|
|
||||||
|
|
||||||
_fixImageSizes: function(){
|
|
||||||
var maxWidth;
|
|
||||||
this.$('img:not(.avatar)').each(function(idx,img){
|
|
||||||
|
|
||||||
// deferring work only for posts with images
|
|
||||||
// we got to use screen here, cause nothing is rendered yet.
|
|
||||||
// long term we may want to allow for weird margins that are enforced, instead of hardcoding at 70/20
|
|
||||||
maxWidth = maxWidth || $(window).width() - (Discourse.Mobile.mobileView ? 20 : 70);
|
|
||||||
if (Discourse.SiteSettings.max_image_width < maxWidth) {
|
|
||||||
maxWidth = Discourse.SiteSettings.max_image_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
var aspect = img.height / img.width;
|
|
||||||
if (img.width > maxWidth) {
|
|
||||||
img.width = maxWidth;
|
|
||||||
img.height = parseInt(maxWidth * aspect,10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// very unlikely but lets fix this too
|
|
||||||
if (img.height > Discourse.SiteSettings.max_image_height) {
|
|
||||||
img.height = Discourse.SiteSettings.max_image_height;
|
|
||||||
img.width = parseInt(maxWidth / aspect,10);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}.on('willInsertElement'),
|
|
||||||
|
|
||||||
_applySearchHighlight: function() {
|
|
||||||
const highlight = this.get('searchService.highlightTerm');
|
|
||||||
const cooked = this.$('.cooked');
|
|
||||||
|
|
||||||
if (!cooked) { return; }
|
|
||||||
|
|
||||||
if (highlight && highlight.length > 2) {
|
|
||||||
if (this._highlighted) {
|
|
||||||
cooked.unhighlight();
|
|
||||||
}
|
|
||||||
cooked.highlight(highlight.split(/\s+/));
|
|
||||||
this._highlighted = true;
|
|
||||||
|
|
||||||
} else if (this._highlighted) {
|
|
||||||
cooked.unhighlight();
|
|
||||||
this._highlighted = false;
|
|
||||||
}
|
|
||||||
}.observes('searchService.highlightTerm', 'cooked')
|
|
||||||
});
|
|
||||||
|
|
||||||
export default PostView;
|
|
@ -1,3 +1,11 @@
|
|||||||
|
// we don't want to deselect when we click on buttons that use it
|
||||||
|
function ignoreElements(e) {
|
||||||
|
const $target = $(e.target);
|
||||||
|
return $target.hasClass('quote-button') ||
|
||||||
|
$target.closest('.create').length ||
|
||||||
|
$target.closest('.reply-new').length;
|
||||||
|
}
|
||||||
|
|
||||||
export default Ember.View.extend({
|
export default Ember.View.extend({
|
||||||
classNames: ['quote-button'],
|
classNames: ['quote-button'],
|
||||||
classNameBindings: ['visible'],
|
classNameBindings: ['visible'],
|
||||||
@ -45,11 +53,7 @@ export default Ember.View.extend({
|
|||||||
.on("mousedown.quote-button", function(e) {
|
.on("mousedown.quote-button", function(e) {
|
||||||
view.set('isMouseDown', true);
|
view.set('isMouseDown', true);
|
||||||
|
|
||||||
const $target = $(e.target);
|
if (ignoreElements(e)) { return; }
|
||||||
// we don't want to deselect when we click on buttons that use it
|
|
||||||
if ($target.hasClass('quote-button') ||
|
|
||||||
$target.closest('.create').length ||
|
|
||||||
$target.closest('.reply-new').length) return;
|
|
||||||
|
|
||||||
// deselects only when the user left click
|
// deselects only when the user left click
|
||||||
// (allows anyone to `extend` their selection using shift+click)
|
// (allows anyone to `extend` their selection using shift+click)
|
||||||
@ -58,6 +62,8 @@ export default Ember.View.extend({
|
|||||||
!e.shiftKey) controller.deselectText();
|
!e.shiftKey) controller.deselectText();
|
||||||
})
|
})
|
||||||
.on('mouseup.quote-button', function(e) {
|
.on('mouseup.quote-button', function(e) {
|
||||||
|
if (ignoreElements(e)) { return; }
|
||||||
|
|
||||||
view.selectText(e.target, controller);
|
view.selectText(e.target, controller);
|
||||||
view.set('isMouseDown', false);
|
view.set('isMouseDown', false);
|
||||||
})
|
})
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
export default Em.CollectionView.extend({
|
|
||||||
tagName: 'section',
|
|
||||||
classNameBindings: [':embedded-posts', ':top', ':topic-body', ':offset2', 'hidden'],
|
|
||||||
itemViewClass: 'embedded-post',
|
|
||||||
hidden: Em.computed.equal('content.length', 0),
|
|
||||||
previousPost: true
|
|
||||||
});
|
|
@ -82,7 +82,7 @@ export default Ember.View.extend({
|
|||||||
|
|
||||||
$shareLink.css({top: "" + y + "px"});
|
$shareLink.css({top: "" + y + "px"});
|
||||||
|
|
||||||
if (!Discourse.Mobile.mobileView) {
|
if (!self.site.mobileView) {
|
||||||
$shareLink.css({left: "" + x + "px"});
|
$shareLink.css({left: "" + x + "px"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ export default ContainerView.extend({
|
|||||||
|
|
||||||
@on('init')
|
@on('init')
|
||||||
createButtons() {
|
createButtons() {
|
||||||
const mobileView = Discourse.Mobile.mobileView;
|
const mobileView = this.site.mobileView;
|
||||||
|
|
||||||
if (!mobileView && this.currentUser.get('staff')) {
|
if (!mobileView && this.currentUser.get('staff')) {
|
||||||
const viewArgs = {action: 'showTopicAdminMenu', title: 'topic_admin_menu', icon: 'wrench', position: 'absolute'};
|
const viewArgs = {action: 'showTopicAdminMenu', title: 'topic_admin_menu', icon: 'wrench', position: 'absolute'};
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
import ContainerView from 'discourse/views/container';
|
|
||||||
import { default as computed, observes, on } from 'ember-addons/ember-computed-decorators';
|
|
||||||
|
|
||||||
export default ContainerView.extend({
|
|
||||||
classNameBindings: ['hidden', ':topic-map'],
|
|
||||||
|
|
||||||
@observes('topic.posts_count')
|
|
||||||
_postsChanged() {
|
|
||||||
Ember.run.once(this, 'rerender');
|
|
||||||
},
|
|
||||||
|
|
||||||
@computed
|
|
||||||
hidden() {
|
|
||||||
if (!this.get('post.firstPost')) return true;
|
|
||||||
|
|
||||||
const topic = this.get('topic');
|
|
||||||
if (topic.get('archetype') === 'private_message') return false;
|
|
||||||
if (topic.get('archetype') !== 'regular') return true;
|
|
||||||
return topic.get('posts_count') < 2;
|
|
||||||
},
|
|
||||||
|
|
||||||
@on('init')
|
|
||||||
startAppending() {
|
|
||||||
if (this.get('hidden')) return;
|
|
||||||
|
|
||||||
this.attachViewWithArgs({ topic: this.get('topic') }, 'topic-map');
|
|
||||||
this.trigger('appendMapInformation', this);
|
|
||||||
},
|
|
||||||
|
|
||||||
appendMapInformation(view) {
|
|
||||||
const topic = this.get('topic');
|
|
||||||
|
|
||||||
if (topic.get('has_summary')) {
|
|
||||||
view.attachViewWithArgs({ topic, filterBinding: 'controller.filter' }, 'toggle-summary');
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentUser = this.get('controller.currentUser');
|
|
||||||
if (currentUser && currentUser.get('staff') && topic.get('has_deleted')) {
|
|
||||||
view.attachViewWithArgs({ topic, filterBinding: 'controller.filter' }, 'topic-deleted');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.get('topic.isPrivateMessage')) {
|
|
||||||
view.attachViewWithArgs({ topic, showPrivateInviteAction: 'showInvite' }, 'private-message-map');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
@ -76,7 +76,7 @@ export default Ember.View.extend({
|
|||||||
_focusWhenOpened: function() {
|
_focusWhenOpened: function() {
|
||||||
|
|
||||||
// Don't focus on mobile or touch
|
// Don't focus on mobile or touch
|
||||||
if (Discourse.Mobile.mobileView || this.capabilities.isIOS) {
|
if (this.site.mobileView || this.capabilities.isIOS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ function highlight(postNumber) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
listenForViewEvent(TopicView, 'post:highlight', function(postNumber) {
|
listenForViewEvent(TopicView, 'post:highlight', postNumber => {
|
||||||
Ember.run.scheduleOnce('afterRender', null, highlight, postNumber);
|
Ember.run.scheduleOnce('afterRender', null, highlight, postNumber);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
136
app/assets/javascripts/discourse/widgets/actions-summary.js.es6
Normal file
136
app/assets/javascripts/discourse/widgets/actions-summary.js.es6
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import { createWidget } from 'discourse/widgets/widget';
|
||||||
|
import { avatarFor } from 'discourse/widgets/post';
|
||||||
|
import { iconNode } from 'discourse/helpers/fa-icon';
|
||||||
|
import { h } from 'virtual-dom';
|
||||||
|
import { dateNode } from 'discourse/helpers/node';
|
||||||
|
|
||||||
|
export function avatarAtts(user) {
|
||||||
|
return { template: user.avatar_template,
|
||||||
|
username: user.username,
|
||||||
|
post_url: user.post_url,
|
||||||
|
url: Discourse.getURL('/users/') + user.username_lower };
|
||||||
|
}
|
||||||
|
|
||||||
|
createWidget('small-user-list', {
|
||||||
|
tagName: 'div.clearfix',
|
||||||
|
|
||||||
|
buildClasses(atts) {
|
||||||
|
return atts.listClassName;
|
||||||
|
},
|
||||||
|
|
||||||
|
html(atts) {
|
||||||
|
let users = atts.users;
|
||||||
|
if (users) {
|
||||||
|
const currentUser = this.currentUser;
|
||||||
|
if (atts.addSelf && !users.some(u => u.username === currentUser.username)) {
|
||||||
|
users = users.concat(avatarAtts(currentUser));
|
||||||
|
}
|
||||||
|
|
||||||
|
let description = I18n.t(atts.description, { icons: '' });
|
||||||
|
|
||||||
|
// oddly post_url is on the user
|
||||||
|
let postUrl;
|
||||||
|
const icons = users.map(u => {
|
||||||
|
postUrl = postUrl || u.post_url;
|
||||||
|
return avatarFor.call(this, 'small', u);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (postUrl) {
|
||||||
|
description = h('a', { attributes: { href: Discourse.getURL(postUrl) } }, description);
|
||||||
|
}
|
||||||
|
return [icons, description, '.'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
createWidget('action-link', {
|
||||||
|
tagName: 'span.action-link',
|
||||||
|
|
||||||
|
buildClasses(attrs) {
|
||||||
|
return attrs.className;
|
||||||
|
},
|
||||||
|
|
||||||
|
html(attrs) {
|
||||||
|
return h('a', [attrs.text, '. ']);
|
||||||
|
},
|
||||||
|
|
||||||
|
click() {
|
||||||
|
this.sendWidgetAction(this.attrs.action);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
createWidget('actions-summary-item', {
|
||||||
|
tagName: 'div.post-action',
|
||||||
|
|
||||||
|
defaultState() {
|
||||||
|
return { users: [] };
|
||||||
|
},
|
||||||
|
|
||||||
|
html(attrs, state) {
|
||||||
|
const users = state.users;
|
||||||
|
|
||||||
|
const result = [];
|
||||||
|
const action = attrs.action;
|
||||||
|
|
||||||
|
if (users.length === 0) {
|
||||||
|
result.push(this.attach('action-link', { action: 'whoActed', text: attrs.description }));
|
||||||
|
} else {
|
||||||
|
result.push(this.attach('small-user-list', { users, description: `post.actions.people.${action}` }));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attrs.canUndo) {
|
||||||
|
result.push(this.attach('action-link', { action: 'undo', className: 'undo', text: I18n.t(`post.actions.undo.${action}`)}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attrs.canDeferFlags) {
|
||||||
|
const flagsDesc = I18n.t(`post.actions.defer_flags`, { count: attrs.count });
|
||||||
|
result.push(this.attach('action-link', { action: 'deferFlags', className: 'defer-flags', text: flagsDesc }));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
|
whoActed() {
|
||||||
|
const attrs = this.attrs;
|
||||||
|
const state = this.state;
|
||||||
|
return this.store.find('post-action-user', { id: attrs.postId, post_action_type_id: attrs.id }).then(users => {
|
||||||
|
state.users = users.map(avatarAtts);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
undo() {
|
||||||
|
this.sendWidgetAction('undoPostAction', this.attrs.id);
|
||||||
|
},
|
||||||
|
|
||||||
|
deferFlags() {
|
||||||
|
this.sendWidgetAction('deferPostActionFlags', this.attrs.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default createWidget('actions-summary', {
|
||||||
|
tagName: 'section.post-actions',
|
||||||
|
|
||||||
|
html(attrs) {
|
||||||
|
const actionsSummary = attrs.actionsSummary || [];
|
||||||
|
const body = [];
|
||||||
|
actionsSummary.forEach(as => {
|
||||||
|
body.push(this.attach('actions-summary-item', as));
|
||||||
|
body.push(h('div.clearfix'));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (attrs.isDeleted) {
|
||||||
|
body.push(h('div.post-action', [
|
||||||
|
iconNode('trash-o'),
|
||||||
|
' ',
|
||||||
|
avatarFor.call(this, 'small', {
|
||||||
|
template: attrs.deletedByAvatarTemplate,
|
||||||
|
username: attrs.deletedByUsername
|
||||||
|
}),
|
||||||
|
' ',
|
||||||
|
dateNode(attrs.deleted_at)
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
});
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user