This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/widgets/actions-summary.js.es6
Robin Ward 31e100530f FEATURE: Flag count in post menu
This change shows a notification number besides the flag icon in the
post menu if there is reviewable content associated with the post.
Additionally, if there is pending stuff to review, the icon has a red
background.

We have also removed the list of links below a post with the flag
status. A reviewer is meant to click the number beside the flag icon to
view the flags. As a consequence of losing those links, we've removed
the ability to undo or ignore flags below a post.
2019-05-06 16:13:31 -04:00

93 lines
2.2 KiB
JavaScript

import { createWidget } from "discourse/widgets/widget";
import { avatarFor } from "discourse/widgets/post";
import { h } from "virtual-dom";
import { userPath } from "discourse/lib/url";
import hbs from "discourse/widgets/hbs-compiler";
export function avatarAtts(user) {
return {
template: user.avatar_template,
username: user.username,
post_url: user.post_url,
url: userPath(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 = null;
if (atts.description) {
description = I18n.t(atts.description, { count: atts.count });
}
// 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
);
}
let buffer = [icons];
if (description) {
buffer.push(description);
}
return buffer;
}
}
});
createWidget("action-link", {
tagName: "span.action-link",
template: hbs`<a>{{attrs.text}}. </a>`,
buildClasses(attrs) {
return attrs.className;
},
click() {
this.sendWidgetAction(this.attrs.action);
}
});
export default createWidget("actions-summary", {
tagName: "section.post-actions",
template: hbs`
{{#each attrs.actionsSummary as |as|}}
<div class='post-action'>{{as.description}}</div>
<div class='clearfix'></div>
{{/each}}
{{#if attrs.deleted_at}}
<div class='post-action deleted-post'>
{{d-icon "far-trash-alt"}}
{{avatar size="small" template=attrs.deletedByAvatarTemplate username=attrs.deletedByUsername}}
{{date attrs.deleted_at}}
</div>
{{/if}}
`
});