FEATURE: easy assign list
This commit is contained in:
parent
bd5575d975
commit
bfdffdca83
|
@ -4,12 +4,22 @@ import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
|
|
||||||
|
assignSuggestions: function(){
|
||||||
|
ajax("/assign/suggestions").then(users => {
|
||||||
|
this.set("assignSuggestions", users);
|
||||||
|
});
|
||||||
|
}.property(),
|
||||||
|
|
||||||
// @computed("username")
|
// @computed("username")
|
||||||
// disabled(username) {
|
// disabled(username) {
|
||||||
// return Ember.isEmpty(username);
|
// return Ember.isEmpty(username);
|
||||||
// },
|
// },
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
assignUser(user) {
|
||||||
|
this.set('model.username', user.username);
|
||||||
|
this.send('assign');
|
||||||
|
},
|
||||||
assign(){
|
assign(){
|
||||||
|
|
||||||
let path = '/assign/assign';
|
let path = '/assign/assign';
|
||||||
|
@ -19,12 +29,13 @@ export default Ember.Controller.extend({
|
||||||
this.set('model.assigned_to_user', null);
|
this.set('model.assigned_to_user', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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: { username: this.get('model.username'), topic_id: this.get('model.topic.id') }
|
||||||
}).then(()=>{
|
}).then(()=>{
|
||||||
//console.log(user);
|
// done
|
||||||
this.send('closeModal');
|
|
||||||
}).catch(popupAjaxError);
|
}).catch(popupAjaxError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,13 @@
|
||||||
usernames=model.username
|
usernames=model.username
|
||||||
placeholderKey=placeholderKey
|
placeholderKey=placeholderKey
|
||||||
autocomplete="off"}}
|
autocomplete="off"}}
|
||||||
|
<div class='assign-suggestions'>
|
||||||
|
{{#each assignSuggestions as |user|}}
|
||||||
|
<a {{action "assignUser" user}}>
|
||||||
|
{{avatar user imageSize="small"}}
|
||||||
|
</a>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
{{/d-modal-body}}
|
{{/d-modal-body}}
|
||||||
|
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|
|
@ -6,3 +6,12 @@ a.assigned-to .fa.fa-user-plus {
|
||||||
.list-tags.assigned {
|
.list-tags.assigned {
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.assign-suggestions {
|
||||||
|
height: 25px;
|
||||||
|
margin-top: 10px;
|
||||||
|
img {
|
||||||
|
margin-right: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
19
plugin.rb
19
plugin.rb
|
@ -196,6 +196,24 @@ SQL
|
||||||
class ::DiscourseAssign::AssignController < Admin::AdminController
|
class ::DiscourseAssign::AssignController < Admin::AdminController
|
||||||
before_filter :ensure_logged_in
|
before_filter :ensure_logged_in
|
||||||
|
|
||||||
|
def suggestions
|
||||||
|
users = [current_user]
|
||||||
|
users += User
|
||||||
|
.where('admin OR moderator')
|
||||||
|
.where('users.id <> ?', current_user.id)
|
||||||
|
.joins("join (
|
||||||
|
SELECT value::integer user_id, MAX(created_at) last_assigned
|
||||||
|
FROM topic_custom_fields
|
||||||
|
WHERE name = 'assigned_to_id'
|
||||||
|
GROUP BY value::integer
|
||||||
|
) as X ON X.user_id = users.id")
|
||||||
|
.order('X.last_assigned DESC')
|
||||||
|
.limit(6)
|
||||||
|
|
||||||
|
render json: ActiveModel::ArraySerializer.new(users,
|
||||||
|
scope: guardian, each_serializer: BasicUserSerializer)
|
||||||
|
end
|
||||||
|
|
||||||
def unassign
|
def unassign
|
||||||
topic_id = params.require(:topic_id)
|
topic_id = params.require(:topic_id)
|
||||||
topic = Topic.find(topic_id.to_i)
|
topic = Topic.find(topic_id.to_i)
|
||||||
|
@ -364,6 +382,7 @@ SQL
|
||||||
DiscourseAssign::Engine.routes.draw do
|
DiscourseAssign::Engine.routes.draw do
|
||||||
put "/assign" => "assign#assign"
|
put "/assign" => "assign#assign"
|
||||||
put "/unassign" => "assign#unassign"
|
put "/unassign" => "assign#unassign"
|
||||||
|
get "/suggestions" => "assign#suggestions"
|
||||||
end
|
end
|
||||||
|
|
||||||
Discourse::Application.routes.append do
|
Discourse::Application.routes.append do
|
||||||
|
|
Loading…
Reference in New Issue