您希望完成什么?
我需要在顶部菜单中添加一个类似于 posted 的按钮,该按钮应显示您创建的所有帖子,但不像 posted 那样包含您回复过的其他用户的主题。
如果能在某些分类中将其重命名为“我的照片”,那就更好了。
此功能需要与 Topic Previews 插件兼容,以便结果能显示缩略图,而下面的代码已支持此功能。
您希望何时完成?
不着急,但最好能在一个月内完成。
您能为此任务提供的预算(美元)是多少?
我希望下面的代码可以作为起点(这是一个用于显示无回复帖子的按钮),并且认为这是一项相对简单的任务,因此我愿意提供 100 美元。
我自己修改时遇到的最大问题是,无法在搜索查询中使用用户名变量,以便仅显示当前用户的主题。
<!-- 需要回复 -->
<script type="text/discourse-plugin" version="0.8.18">
if (I18n.translations.en) {
I18n.translations.en.js.filters.needsreply = {title: "无回复", help: "无回复的主题"};
}
// 自定义这些值
// 设置搜索查询
let search_query = '?max_posts=1';
// 从显示“需要回复”菜单项中排除某些分类
let excludeList = ['classifieds', 'workshops', 'staff', 'wiki','site-discussions', 'site-feedback', 'announcements', 'site-tips', 'site-support'];
// 为“需要回复”按钮添加激活类
api.modifyClass('component:navigation-item', {
active: Ember.computed("contentFilterMode", "filterMode", function () {
let contentFilterMode = this.get('content').get('filterMode');
if (window.location.search && window.location.search.split('&')[0] === search_query.split('&')[0]) {
return contentFilterMode === "needsreply";
} else {
return this._super(contentFilterMode, this.get('filterMode'));
}
}),
});
// 移除 max_posts 过滤器和标签过滤器
api.modifyClass('controller:discovery/topics', {
resetParams: function () {
this.setProperties({max_posts: null});
this.setProperties({tags: null});
this._super();
}
});
Discourse.ExternalNavItem = Discourse.NavItem.extend({
href: function () {
return this.get('href');
}.property("href")
});
Discourse.NavItem.reopenClass({
buildList: function (category, args) {
let list = this._super(category, args),
tag = args.tagId,
needsreplyHref;
if (!category) { // 没有分类
needsreplyHref = tag ? '/latest/' + search_query + '&tags=' + tag : '/latest/' + search_query; // 如果有标签,则构建带标签的 href,否则回退到最新视图和搜索查询
}
else if (excludeList.indexOf(category.slug) != -1) { // 分类在排除列表中,不执行任何操作
return list; // 返回不包含自定义导航项的列表
}
else if (!category.parentCategory) { // 不是子分类
needsreplyHref = tag ? '/c/' + category.slug + search_query + '&tags=' + tag : '/c/' + category.slug + search_query; // 如果有标签,则构建带标签和分类的 href,否则回退到搜索查询等
} else { // 是子分类
needsreplyHref = tag ? '/c/' + category.parentCategory.slug + '/' + category.slug + search_query + '&tags=' + tag :
'/c/' + category.parentCategory.slug + '/' + category.slug + search_query; // 如果有标签,则构建带标签、子分类和分类的 href,否则回退到搜索查询等
}
list.push(Discourse.ExternalNavItem.create({href: needsreplyHref, name: 'needsreply'}));
return list;
}
});
</script>