DEV: Apply prettier

This commit is contained in:
David Taylor 2018-10-22 19:49:32 +01:00
parent 11012a7fbd
commit 519effe056
12 changed files with 234 additions and 187 deletions

View File

@ -1,6 +1,6 @@
export default { export default {
resource: 'user.userPrivateMessages', resource: "user.userPrivateMessages",
map() { map() {
this.route('assigned'); this.route("assigned");
} }
}; };

View File

@ -1,6 +1,6 @@
export default { export default {
resource: 'user.userActivity', resource: "user.userActivity",
map() { map() {
this.route('assigned'); this.route("assigned");
} }
}; };

View File

@ -1,27 +1,30 @@
import showModal from 'discourse/lib/show-modal'; import showModal from "discourse/lib/show-modal";
import { ajax } from 'discourse/lib/ajax'; import { ajax } from "discourse/lib/ajax";
export default { export default {
shouldRender(args, component) { shouldRender(args, component) {
const needsButton = component.currentUser && component.currentUser.get('staff'); const needsButton =
return needsButton && (!component.get('site.mobileView') || args.topic.get('isPrivateMessage')); component.currentUser && component.currentUser.get("staff");
return (
needsButton &&
(!component.get("site.mobileView") || args.topic.get("isPrivateMessage"))
);
}, },
actions: { actions: {
unassign(){ unassign() {
this.set("topic.assigned_to_user", null);
this.set('topic.assigned_to_user', null);
return ajax("/assign/unassign", { return ajax("/assign/unassign", {
type: 'PUT', type: "PUT",
data: { topic_id: this.get('topic.id')} data: { topic_id: this.get("topic.id") }
}); });
}, },
assign(){ assign() {
showModal("assign-user", { showModal("assign-user", {
model: { model: {
topic: this.topic, topic: this.topic,
username: this.topic.get('assigned_to_user.username') username: this.topic.get("assigned_to_user.username")
} }
}); });
} }

View File

@ -1,6 +1,10 @@
export function shouldShowAssigned(args, component) { export function shouldShowAssigned(args, component) {
const needsButton = component.currentUser && component.currentUser.get('staff'); const needsButton =
return needsButton && (!component.get('site.mobileView') || args.model.get('isPrivateMessage')); component.currentUser && component.currentUser.get("staff");
return (
needsButton &&
(!component.get("site.mobileView") || args.model.get("isPrivateMessage"))
);
} }
export default { export default {

View File

@ -1,10 +1,9 @@
//import { default as computed } from 'ember-addons/ember-computed-decorators'; //import { default as computed } from 'ember-addons/ember-computed-decorators';
import { ajax } from 'discourse/lib/ajax'; import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from 'discourse/lib/ajax-error'; import { popupAjaxError } from "discourse/lib/ajax-error";
export default Ember.Controller.extend({ export default Ember.Controller.extend({
assignSuggestions: function() {
assignSuggestions: function(){
ajax("/assign/suggestions").then(users => { ajax("/assign/suggestions").then(users => {
this.set("assignSuggestions", users); this.set("assignSuggestions", users);
}); });
@ -17,26 +16,30 @@ export default Ember.Controller.extend({
actions: { actions: {
assignUser(user) { assignUser(user) {
this.set('model.username', user.username); this.set("model.username", user.username);
this.send('assign'); this.send("assign");
}, },
assign(){ assign() {
let path = "/assign/assign";
let path = '/assign/assign'; if (Ember.isEmpty(this.get("model.username"))) {
path = "/assign/unassign";
if (Ember.isEmpty(this.get('model.username'))) { this.set("model.assigned_to_user", null);
path = '/assign/unassign';
this.set('model.assigned_to_user', null);
} }
this.send('closeModal'); this.send("closeModal");
return ajax(path,{ return ajax(path, {
type: 'PUT', type: "PUT",
data: { username: this.get('model.username'), topic_id: this.get('model.topic.id') } data: {
}).then(()=>{ username: this.get("model.username"),
// done topic_id: this.get("model.topic.id")
}).catch(popupAjaxError); }
})
.then(() => {
// done
})
.catch(popupAjaxError);
} }
} }
}); });

View File

@ -1,25 +1,27 @@
import { ajax } from 'discourse/lib/ajax'; import { ajax } from "discourse/lib/ajax";
import computed from 'ember-addons/ember-computed-decorators'; import computed from "ember-addons/ember-computed-decorators";
export default Ember.Controller.extend({ export default Ember.Controller.extend({
user: Ember.inject.controller(), user: Ember.inject.controller(),
@computed('model.topics') @computed("model.topics")
canUnassignAll(topics) { canUnassignAll(topics) {
return topics && topics.length && this.currentUser.get('staff'); return topics && topics.length && this.currentUser.get("staff");
}, },
actions: { actions: {
unassignAll() { unassignAll() {
let user = this.get('user.model'); let user = this.get("user.model");
bootbox.confirm( bootbox.confirm(
I18n.t("discourse_assign.unassign_all.confirm", { username: user.get('username') }), I18n.t("discourse_assign.unassign_all.confirm", {
username: user.get("username")
}),
value => { value => {
if (value) { if (value) {
ajax("/assign/unassign-all", { ajax("/assign/unassign-all", {
type: 'PUT', type: "PUT",
data: { user_id: user.get('id') } data: { user_id: user.get("id") }
}).then(() => this.send('unassignedAll')); }).then(() => this.send("unassignedAll"));
} }
} }
); );

View File

@ -1,190 +1,212 @@
import { withPluginApi } from 'discourse/lib/plugin-api'; import { withPluginApi } from "discourse/lib/plugin-api";
import { default as computed } from 'ember-addons/ember-computed-decorators'; import { default as computed } from "ember-addons/ember-computed-decorators";
// should this be in API ? // should this be in API ?
import showModal from 'discourse/lib/show-modal'; import showModal from "discourse/lib/show-modal";
import { iconNode } from 'discourse-common/lib/icon-library'; import { iconNode } from "discourse-common/lib/icon-library";
import { h } from 'virtual-dom'; import { h } from "virtual-dom";
function modifySelectKit(api) { function modifySelectKit(api) {
api.modifySelectKit("topic-footer-mobile-dropdown") api
.modifyContent((context, existingContent) => { .modifySelectKit("topic-footer-mobile-dropdown")
if (context.get('currentUser.staff')) { .modifyContent((context, existingContent) => {
existingContent.push({ if (context.get("currentUser.staff")) {
id: 'assign', existingContent.push({
icon: 'user-plus', id: "assign",
name: I18n.t('discourse_assign.assign.title') icon: "user-plus",
}); name: I18n.t("discourse_assign.assign.title")
} });
return existingContent; }
}) return existingContent;
.onSelect((context, value) => { })
if (!context.get('currentUser.staff')) { .onSelect((context, value) => {
return; if (!context.get("currentUser.staff")) {
} return;
}
const topic = context.get('topic'); const topic = context.get("topic");
if (value === 'assign') { if (value === "assign") {
showModal("assign-user", { showModal("assign-user", {
model: { model: {
topic, topic,
username: topic.get('assigned_to_user.username') username: topic.get("assigned_to_user.username")
} }
}); });
context.set('value', null); context.set("value", null);
} }
}); });
} }
function initialize(api) { function initialize(api) {
// You can't act on flags claimed by another user // You can't act on flags claimed by another user
api.modifyClass('component:flagged-post', { api.modifyClass(
@computed('flaggedPost.topic.assigned_to_user_id') "component:flagged-post",
canAct(assignedToUserId) { {
let { siteSettings } = this; @computed("flaggedPost.topic.assigned_to_user_id")
canAct(assignedToUserId) {
let { siteSettings } = this;
if (siteSettings.assign_locks_flags) { if (siteSettings.assign_locks_flags) {
let unassigned = this.currentUser.id !== assignedToUserId;
let unassigned = (this.currentUser.id !== assignedToUserId); // Can never act on another user's flags
if (assignedToUserId && unassigned) {
return false;
}
// Can never act on another user's flags // If flags require assignment
if (assignedToUserId && unassigned) { if (this.siteSettings.flags_require_assign && unassigned) {
return false; return false;
}
} }
// If flags require assignment return this.get("actableFilter");
if (this.siteSettings.flags_require_assign && unassigned) { },
return false;
} didInsertElement() {
this._super();
this.messageBus.subscribe("/staff/topic-assignment", data => {
let flaggedPost = this.get("flaggedPost");
if (data.topic_id === flaggedPost.get("topic.id")) {
flaggedPost.set(
"topic.assigned_to_user_id",
data.type === "assigned" ? data.assigned_to.id : null
);
flaggedPost.set("topic.assigned_to_user", data.assigned_to);
}
});
},
willDestroyElement() {
this._super();
this.messageBus.unsubscribe("/staff/topic-assignment");
} }
return this.get('actableFilter');
}, },
{ ignoreMissing: true }
);
didInsertElement() { api.modifyClass("model:topic", {
this._super(); @computed("assigned_to_user")
this.messageBus.subscribe("/staff/topic-assignment", data => {
let flaggedPost = this.get('flaggedPost');
if (data.topic_id === flaggedPost.get('topic.id')) {
flaggedPost.set('topic.assigned_to_user_id',
data.type === 'assigned' ? data.assigned_to.id : null
);
flaggedPost.set('topic.assigned_to_user', data.assigned_to);
}
});
},
willDestroyElement() {
this._super();
this.messageBus.unsubscribe("/staff/topic-assignment");
}
}, { ignoreMissing: true });
api.modifyClass('model:topic', {
@computed('assigned_to_user')
assignedToUserPath(assignedToUser) { assignedToUserPath(assignedToUser) {
return this.siteSettings.assigns_user_url_path.replace( return this.siteSettings.assigns_user_url_path.replace(
"{username}", "{username}",
Ember.get(assignedToUser, 'username') Ember.get(assignedToUser, "username")
); );
} }
}); });
api.addPostSmallActionIcon('assigned','user-plus'); api.addPostSmallActionIcon("assigned", "user-plus");
api.addPostSmallActionIcon('unassigned','user-times'); api.addPostSmallActionIcon("unassigned", "user-times");
api.addPostTransformCallback(transformed => { api.addPostTransformCallback(transformed => {
if (transformed.actionCode === "assigned" || transformed.actionCode === "unassigned") { if (
transformed.actionCode === "assigned" ||
transformed.actionCode === "unassigned"
) {
transformed.isSmallAction = true; transformed.isSmallAction = true;
transformed.canEdit = false; transformed.canEdit = false;
} }
}); });
api.addDiscoveryQueryParam('assigned', {replace: true, refreshModel: true}); api.addDiscoveryQueryParam("assigned", { replace: true, refreshModel: true });
api.addTagsHtmlCallback((topic) => { api.addTagsHtmlCallback(topic => {
const assignedTo = topic.get('assigned_to_user.username'); const assignedTo = topic.get("assigned_to_user.username");
if (assignedTo) { if (assignedTo) {
const assignedPath = topic.get('assignedToUserPath'); const assignedPath = topic.get("assignedToUserPath");
return `<a class='assigned-to discourse-tag simple' href='${assignedPath}'><i class='fa fa-user-plus'></i>${assignedTo}</a>`; return `<a class='assigned-to discourse-tag simple' href='${assignedPath}'><i class='fa fa-user-plus'></i>${assignedTo}</a>`;
} }
}); });
api.addUserMenuGlyph(widget => { api.addUserMenuGlyph(widget => {
if (widget.currentUser && if (
widget.currentUser.get('staff') && widget.currentUser &&
widget.siteSettings.assign_enabled) { widget.currentUser.get("staff") &&
widget.siteSettings.assign_enabled
) {
return { return {
label: 'discourse_assign.assigned', label: "discourse_assign.assigned",
className: 'assigned', className: "assigned",
icon: 'user-plus', icon: "user-plus",
href: `${widget.currentUser.get("path")}/activity/assigned`, href: `${widget.currentUser.get("path")}/activity/assigned`
}; };
} }
}); });
api.createWidget('assigned-to', { api.createWidget("assigned-to", {
html(attrs) { html(attrs) {
let { assignedToUser, href } = attrs; let { assignedToUser, href } = attrs;
return h('p.assigned-to', [ return h("p.assigned-to", [
iconNode('user-plus'), iconNode("user-plus"),
h('span.assign-text', I18n.t('discourse_assign.assigned_to')), h("span.assign-text", I18n.t("discourse_assign.assigned_to")),
h('a', { attributes: { class: 'assigned-to-username', href } }, assignedToUser.username) h(
"a",
{ attributes: { class: "assigned-to-username", href } },
assignedToUser.username
)
]); ]);
} }
}); });
api.createWidget('assigned-to', { api.createWidget("assigned-to", {
html(attrs) { html(attrs) {
let { assignedToUser, href } = attrs; let { assignedToUser, href } = attrs;
return h('p.assigned-to', [ return h("p.assigned-to", [
iconNode('user-plus'), iconNode("user-plus"),
h('span.assign-text', I18n.t('discourse_assign.assigned_to')), h("span.assign-text", I18n.t("discourse_assign.assigned_to")),
h('a', { attributes: { class: 'assigned-to-username', href } }, assignedToUser.username) h(
"a",
{ attributes: { class: "assigned-to-username", href } },
assignedToUser.username
)
]); ]);
} }
}); });
api.createWidget('assigned-to', { api.createWidget("assigned-to", {
html(attrs) { html(attrs) {
let { assignedToUser, href } = attrs; let { assignedToUser, href } = attrs;
return h('p.assigned-to', [ return h("p.assigned-to", [
iconNode('user-plus'), iconNode("user-plus"),
h('span.assign-text', I18n.t('discourse_assign.assigned_to')), h("span.assign-text", I18n.t("discourse_assign.assigned_to")),
h('a', { attributes: { class: 'assigned-to-username', href } }, assignedToUser.username) h(
"a",
{ attributes: { class: "assigned-to-username", href } },
assignedToUser.username
)
]); ]);
} }
}); });
api.decorateWidget('post-contents:after-cooked', dec => { api.decorateWidget("post-contents:after-cooked", dec => {
if (dec.attrs.post_number === 1) { if (dec.attrs.post_number === 1) {
const postModel = dec.getModel(); const postModel = dec.getModel();
if (postModel) { if (postModel) {
const assignedToUser = postModel.get('topic.assigned_to_user'); const assignedToUser = postModel.get("topic.assigned_to_user");
if (assignedToUser) { if (assignedToUser) {
return dec.widget.attach('assigned-to', { return dec.widget.attach("assigned-to", {
assignedToUser, assignedToUser,
href: postModel.get('topic.assignedToUserPath') href: postModel.get("topic.assignedToUserPath")
}); });
} }
} }
} }
}); });
api.replaceIcon('notification.discourse_assign.assign_notification', 'user-plus'); api.replaceIcon(
}; "notification.discourse_assign.assign_notification",
"user-plus"
);
}
export default { export default {
name: 'extend-for-assign', name: "extend-for-assign",
initialize(container) { initialize(container) {
withPluginApi('0.8.11', api => initialize(api, container)); withPluginApi("0.8.11", api => initialize(api, container));
withPluginApi('0.8.13', api => modifySelectKit(api, container)); withPluginApi("0.8.13", api => modifySelectKit(api, container));
} }
}; };

View File

@ -1,3 +1,7 @@
import createPMRoute from "discourse/routes/build-private-messages-route"; import createPMRoute from "discourse/routes/build-private-messages-route";
export default createPMRoute('assigned', 'private-messages-assigned', 'assigned'); export default createPMRoute(
"assigned",
"private-messages-assigned",
"assigned"
);

View File

@ -1,3 +1,3 @@
export default Ember.Component.extend({ export default Ember.Component.extend({
classNames: ['assigned-to-user'] classNames: ["assigned-to-user"]
}); });

View File

@ -1,44 +1,52 @@
import { ajax } from 'discourse/lib/ajax'; import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from 'discourse/lib/ajax-error'; import { popupAjaxError } from "discourse/lib/ajax-error";
export default Ember.Component.extend({ export default Ember.Component.extend({
tagName: '', tagName: "",
claiming: false, claiming: false,
unassigning: false, unassigning: false,
actions: { actions: {
unassign() { unassign() {
this.set('unassigning', true); this.set("unassigning", true);
return ajax("/assign/unassign", { return ajax("/assign/unassign", {
type: 'PUT', type: "PUT",
data: { topic_id: this.get('topic.id') } data: { topic_id: this.get("topic.id") }
}).then(() => { })
this.set('topic.assigned_to_user', null); .then(() => {
}).catch(popupAjaxError).finally(() => { this.set("topic.assigned_to_user", null);
this.set('unassigning', false); })
}); .catch(popupAjaxError)
.finally(() => {
this.set("unassigning", false);
});
}, },
claim() { claim() {
this.set('claiming', true); this.set("claiming", true);
let topic = this.get('topic'); let topic = this.get("topic");
ajax(`/assign/claim/${topic.id}`, { ajax(`/assign/claim/${topic.id}`, {
method: 'PUT' method: "PUT"
}).then(() => { })
this.set('topic.assigned_to_user', this.currentUser); .then(() => {
}).catch(e => { this.set("topic.assigned_to_user", this.currentUser);
if (e.jqXHR && e.jqXHR.responseJSON) { })
let json = e.jqXHR.responseJSON; .catch(e => {
if (json && json.extras) { if (e.jqXHR && e.jqXHR.responseJSON) {
this.set('topic.assigned_to_user', json.extras.assigned_to); let json = e.jqXHR.responseJSON;
if (json && json.extras) {
this.set("topic.assigned_to_user", json.extras.assigned_to);
}
} }
} return popupAjaxError(e);
return popupAjaxError(e); })
}).finally(() => { .finally(() => {
if (this.isDestroying || this.isDestroyed) { return; } if (this.isDestroying || this.isDestroyed) {
this.set('claiming', false); return;
}); }
this.set("claiming", false);
});
} }
} }
}); });

View File

@ -1,6 +1,6 @@
function assignIfEqual(topic, data) { function assignIfEqual(topic, data) {
if (topic && topic.id === data.topic_id) { if (topic && topic.id === data.topic_id) {
Ember.set(topic, 'assigned_to_user', data.assigned_to); Ember.set(topic, "assigned_to_user", data.assigned_to);
} }
} }
@ -8,11 +8,11 @@ export default Ember.Component.extend({
didInsertElement() { didInsertElement() {
this._super(); this._super();
this.messageBus.subscribe("/staff/topic-assignment", data => { this.messageBus.subscribe("/staff/topic-assignment", data => {
let flaggedTopics = this.get('flaggedTopics'); let flaggedTopics = this.get("flaggedTopics");
if (flaggedTopics) { if (flaggedTopics) {
flaggedTopics.forEach(ft => assignIfEqual(ft.topic, data)); flaggedTopics.forEach(ft => assignIfEqual(ft.topic, data));
} else { } else {
assignIfEqual(this.get('topic'), data); assignIfEqual(this.get("topic"), data);
} }
}); });
}, },

View File

@ -11,7 +11,8 @@
} }
.assigned-to { .assigned-to {
.d-icon, i.fa { .d-icon,
i.fa {
margin-right: 0.25em; margin-right: 0.25em;
color: $primary-medium; color: $primary-medium;
} }