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({
|
||||
|
||||
assignSuggestions: function(){
|
||||
ajax("/assign/suggestions").then(users => {
|
||||
this.set("assignSuggestions", users);
|
||||
});
|
||||
}.property(),
|
||||
|
||||
// @computed("username")
|
||||
// disabled(username) {
|
||||
// return Ember.isEmpty(username);
|
||||
// },
|
||||
|
||||
actions: {
|
||||
assignUser(user) {
|
||||
this.set('model.username', user.username);
|
||||
this.send('assign');
|
||||
},
|
||||
assign(){
|
||||
|
||||
let path = '/assign/assign';
|
||||
|
@ -19,12 +29,13 @@ export default Ember.Controller.extend({
|
|||
this.set('model.assigned_to_user', null);
|
||||
}
|
||||
|
||||
this.send('closeModal');
|
||||
|
||||
return ajax(path,{
|
||||
type: 'PUT',
|
||||
data: { username: this.get('model.username'), topic_id: this.get('model.topic.id') }
|
||||
}).then(()=>{
|
||||
//console.log(user);
|
||||
this.send('closeModal');
|
||||
// done
|
||||
}).catch(popupAjaxError);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,13 @@
|
|||
usernames=model.username
|
||||
placeholderKey=placeholderKey
|
||||
autocomplete="off"}}
|
||||
<div class='assign-suggestions'>
|
||||
{{#each assignSuggestions as |user|}}
|
||||
<a {{action "assignUser" user}}>
|
||||
{{avatar user imageSize="small"}}
|
||||
</a>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/d-modal-body}}
|
||||
|
||||
<div class="modal-footer">
|
||||
|
|
|
@ -6,3 +6,12 @@ a.assigned-to .fa.fa-user-plus {
|
|||
.list-tags.assigned {
|
||||
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
|
||||
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
|
||||
topic_id = params.require(:topic_id)
|
||||
topic = Topic.find(topic_id.to_i)
|
||||
|
@ -364,6 +382,7 @@ SQL
|
|||
DiscourseAssign::Engine.routes.draw do
|
||||
put "/assign" => "assign#assign"
|
||||
put "/unassign" => "assign#unassign"
|
||||
get "/suggestions" => "assign#suggestions"
|
||||
end
|
||||
|
||||
Discourse::Application.routes.append do
|
||||
|
|
Loading…
Reference in New Issue