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 {
resource: 'user.userPrivateMessages',
resource: "user.userPrivateMessages",
map() {
this.route('assigned');
this.route("assigned");
}
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
function assignIfEqual(topic, data) {
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() {
this._super();
this.messageBus.subscribe("/staff/topic-assignment", data => {
let flaggedTopics = this.get('flaggedTopics');
let flaggedTopics = this.get("flaggedTopics");
if (flaggedTopics) {
flaggedTopics.forEach(ft => assignIfEqual(ft.topic, data));
} else {
assignIfEqual(this.get('topic'), data);
assignIfEqual(this.get("topic"), data);
}
});
},

View File

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