allow to unassign a topic
default select assigned user display icon for assigned user
This commit is contained in:
parent
8dd50be626
commit
c06761b396
|
@ -7,7 +7,12 @@ export default {
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
assign(){
|
assign(){
|
||||||
showModal("assign-user", { model: this.topic });
|
showModal("assign-user", {
|
||||||
|
model: {
|
||||||
|
topic: this.topic,
|
||||||
|
username: this.topic.get('assigned_to_user.username')
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
{{#if context.topic.assigned_to_user}}
|
{{#if context.topic.assigned_to_user}}
|
||||||
<a class='assigned-to discourse-tag simple' href="{{context.topic.assignedToUserPath}}">@{{context.topic.assigned_to_user.username}}</a>
|
<a class='assigned-to discourse-tag simple' href="{{context.topic.assignedToUserPath}}"><i class='fa fa-user-plus'></i>{{context.topic.assigned_to_user.username}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{{#if context.topic.assigned_to_user}}
|
{{#if context.topic.assigned_to_user}}
|
||||||
<div class='discourse-tags'>
|
<div class='discourse-tags'>
|
||||||
<a class='assigned-to discourse-tag simple' href="{{context.topic.assignedToUserPath}}">@{{context.topic.assigned_to_user.username}}</a>
|
<a class='assigned-to discourse-tag simple' href="{{context.topic.assignedToUserPath}}"><i class='fa fa-user-plus'></i>{{context.topic.assigned_to_user.username}}</a>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
|
@ -1,21 +1,29 @@
|
||||||
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({
|
||||||
|
|
||||||
@computed("username")
|
// @computed("username")
|
||||||
disabled(username) {
|
// disabled(username) {
|
||||||
return Ember.isEmpty(username);
|
// return Ember.isEmpty(username);
|
||||||
},
|
// },
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
assign(){
|
assign(){
|
||||||
return ajax('/assign/assign',{
|
|
||||||
|
let path = '/assign/assign';
|
||||||
|
|
||||||
|
if (Ember.isEmpty(this.get('model.username'))) {
|
||||||
|
path = '/assign/unassign';
|
||||||
|
this.set('model.assigned_to_user', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ajax(path,{
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
data: { username: this.get('username'), topic_id: this.get('model.id') }
|
data: { username: this.get('model.username'), topic_id: this.get('model.topic.id') }
|
||||||
}).then((user)=>{
|
}).then(()=>{
|
||||||
console.log(user);
|
//console.log(user);
|
||||||
this.send('closeModal');
|
this.send('closeModal');
|
||||||
}).catch(popupAjaxError);
|
}).catch(popupAjaxError);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||||
|
import { h } from 'virtual-dom';
|
||||||
|
|
||||||
// should this be in API ?
|
// should this be in API ?
|
||||||
import Topic from 'discourse/models/topic';
|
import Topic from 'discourse/models/topic';
|
||||||
|
@ -10,13 +11,28 @@ function initialize(api, container) {
|
||||||
Topic.reopen({
|
Topic.reopen({
|
||||||
assignedToUserPath: function(){
|
assignedToUserPath: function(){
|
||||||
return siteSettings.assigns_user_url_path.replace("{username}", this.get("assigned_to_user.username"));
|
return siteSettings.assigns_user_url_path.replace("{username}", this.get("assigned_to_user.username"));
|
||||||
}.property('owner')
|
}.property('assigned_to_user')
|
||||||
});
|
});
|
||||||
|
|
||||||
api.addPostSmallActionIcon('assigned','user-plus');
|
api.addPostSmallActionIcon('assigned','user-plus');
|
||||||
|
|
||||||
api.addDiscoveryQueryParam('assigned', {replace: true, refreshModel: true});
|
api.addDiscoveryQueryParam('assigned', {replace: true, refreshModel: true});
|
||||||
|
|
||||||
|
api.decorateWidget('header-topic-info:after-tags', dec => {
|
||||||
|
|
||||||
|
const topic = dec.attrs.topic;
|
||||||
|
const assignedTo = topic.get('assigned_to_user.username');
|
||||||
|
if (assignedTo) {
|
||||||
|
const assignedPath = topic.get('assignedToUserPath');
|
||||||
|
return h('div.list-tags.assigned',
|
||||||
|
h('a.assigned-to.discourse-tag.simple', {href: assignedPath}, [
|
||||||
|
h('i.fa.fa-user-plus'),
|
||||||
|
assignedTo
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
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();
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
excludeCurrentUser=false
|
excludeCurrentUser=false
|
||||||
includeMentionableGroups=false
|
includeMentionableGroups=false
|
||||||
hasGroups=false
|
hasGroups=false
|
||||||
usernames=username
|
usernames=model.username
|
||||||
placeholderKey=placeholderKey
|
placeholderKey=placeholderKey
|
||||||
autocomplete="off"}}
|
autocomplete="off"}}
|
||||||
{{/d-modal-body}}
|
{{/d-modal-body}}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
a.assigned-to .fa.fa-user-plus {
|
||||||
|
margin-right: 2px;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-tags.assigned {
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
|
@ -4,3 +4,4 @@ en:
|
||||||
assigns_user_url_path: "Path to link all user links for assigned (use: {username} to subtitue username)"
|
assigns_user_url_path: "Path to link all user links for assigned (use: {username} to subtitue username)"
|
||||||
discourse_assign:
|
discourse_assign:
|
||||||
assigned_to: "Topic assigned to @%{username}"
|
assigned_to: "Topic assigned to @%{username}"
|
||||||
|
unassigned: "Topic was unassigned"
|
||||||
|
|
48
plugin.rb
48
plugin.rb
|
@ -3,6 +3,8 @@
|
||||||
# version: 0.1
|
# version: 0.1
|
||||||
# authors: Sam Saffron
|
# authors: Sam Saffron
|
||||||
|
|
||||||
|
register_asset 'stylesheets/assigns.scss'
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
|
||||||
module ::DiscourseAssign
|
module ::DiscourseAssign
|
||||||
|
@ -16,7 +18,42 @@ after_initialize do
|
||||||
before_filter :ensure_logged_in
|
before_filter :ensure_logged_in
|
||||||
|
|
||||||
def unassign
|
def unassign
|
||||||
_topic_id = params.require(:topic_id)
|
topic_id = params.require(:topic_id)
|
||||||
|
topic = Topic.find(topic_id.to_i)
|
||||||
|
if assigned_to_id = topic.custom_fields["assigned_to_id"]
|
||||||
|
topic.custom_fields["assigned_to_id"] = nil
|
||||||
|
topic.custom_fields["assigned_by_id"] = nil
|
||||||
|
topic.save!
|
||||||
|
|
||||||
|
post = topic.posts.where(post_number: 1).first
|
||||||
|
post.publish_change_to_clients!(:revised, { reload_topic: true })
|
||||||
|
|
||||||
|
assigned_user = User.find_by(id: assigned_to_id)
|
||||||
|
|
||||||
|
UserAction.where(
|
||||||
|
action_type: UserAction::ASSIGNED,
|
||||||
|
target_post_id: post.id
|
||||||
|
).destroy_all
|
||||||
|
|
||||||
|
# yank notification
|
||||||
|
Notification.where(
|
||||||
|
notification_type: Notification.types[:custom],
|
||||||
|
user_id: assigned_user.try(:id),
|
||||||
|
topic_id: topic.id,
|
||||||
|
post_number: 1
|
||||||
|
).where("data like '%discourse_assign.assign_notification%'")
|
||||||
|
.destroy_all
|
||||||
|
|
||||||
|
|
||||||
|
post_type = SiteSetting.assigns_public ? Post.types[:small_action] : Post.types[:whisper]
|
||||||
|
topic.add_moderator_post(current_user,
|
||||||
|
I18n.t('discourse_assign.unassigned'),
|
||||||
|
{ bump: false,
|
||||||
|
post_type: post_type,
|
||||||
|
action_code: "assigned"})
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: success_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign
|
def assign
|
||||||
|
@ -28,11 +65,14 @@ after_initialize do
|
||||||
|
|
||||||
raise Discourse::NotFound unless assign_to
|
raise Discourse::NotFound unless assign_to
|
||||||
|
|
||||||
|
#Scheduler::Defer.later "assign topic" do
|
||||||
|
|
||||||
topic.custom_fields["assigned_to_id"] = assign_to.id
|
topic.custom_fields["assigned_to_id"] = assign_to.id
|
||||||
topic.custom_fields["assigned_by_id"] = current_user.id
|
topic.custom_fields["assigned_by_id"] = current_user.id
|
||||||
topic.save!
|
topic.save!
|
||||||
|
|
||||||
#Scheduler::Defer.later "add moderator post" do
|
topic.posts.first.publish_change_to_clients!(:revised, { reload_topic: true })
|
||||||
|
|
||||||
|
|
||||||
UserAction.log_action!(action_type: UserAction::ASSIGNED,
|
UserAction.log_action!(action_type: UserAction::ASSIGNED,
|
||||||
user_id: assign_to.id,
|
user_id: assign_to.id,
|
||||||
|
@ -49,7 +89,7 @@ after_initialize do
|
||||||
post_type: post_type,
|
post_type: post_type,
|
||||||
action_code: "assigned"})
|
action_code: "assigned"})
|
||||||
|
|
||||||
unless false && current_user.id == assign_to.id
|
unless current_user.id == assign_to.id
|
||||||
|
|
||||||
Notification.create!(notification_type: Notification.types[:custom],
|
Notification.create!(notification_type: Notification.types[:custom],
|
||||||
user_id: assign_to.id,
|
user_id: assign_to.id,
|
||||||
|
@ -63,7 +103,6 @@ after_initialize do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
#end
|
|
||||||
|
|
||||||
render json: success_json
|
render json: success_json
|
||||||
end
|
end
|
||||||
|
@ -167,6 +206,7 @@ after_initialize do
|
||||||
|
|
||||||
DiscourseAssign::Engine.routes.draw do
|
DiscourseAssign::Engine.routes.draw do
|
||||||
put "/assign" => "assign#assign"
|
put "/assign" => "assign#assign"
|
||||||
|
put "/unassign" => "assign#unassign"
|
||||||
end
|
end
|
||||||
|
|
||||||
Discourse::Application.routes.append do
|
Discourse::Application.routes.append do
|
||||||
|
|
Loading…
Reference in New Issue