allow to unassign a topic

default select assigned user
display icon for assigned user
This commit is contained in:
Sam 2017-02-17 16:40:43 -05:00
parent 8dd50be626
commit c06761b396
9 changed files with 99 additions and 21 deletions

View File

@ -7,7 +7,12 @@ export default {
actions: {
assign(){
showModal("assign-user", { model: this.topic });
showModal("assign-user", {
model: {
topic: this.topic,
username: this.topic.get('assigned_to_user.username')
}
});
}
}
};

View File

@ -1,3 +1,3 @@
{{#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}}

View File

@ -2,7 +2,7 @@
{{#if context.topic.assigned_to_user}}
<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>
{{/if}}
{{/unless}}

View File

@ -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 { popupAjaxError } from 'discourse/lib/ajax-error';
export default Ember.Controller.extend({
@computed("username")
disabled(username) {
return Ember.isEmpty(username);
},
// @computed("username")
// disabled(username) {
// return Ember.isEmpty(username);
// },
actions: {
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',
data: { username: this.get('username'), topic_id: this.get('model.id') }
}).then((user)=>{
console.log(user);
data: { username: this.get('model.username'), topic_id: this.get('model.topic.id') }
}).then(()=>{
//console.log(user);
this.send('closeModal');
}).catch(popupAjaxError);
}

View File

@ -1,4 +1,5 @@
import { withPluginApi } from 'discourse/lib/plugin-api';
import { h } from 'virtual-dom';
// should this be in API ?
import Topic from 'discourse/models/topic';
@ -10,13 +11,28 @@ function initialize(api, container) {
Topic.reopen({
assignedToUserPath: function(){
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.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 => {
if (dec.attrs.post_number === 1) {
const postModel = dec.getModel();

View File

@ -7,7 +7,7 @@
excludeCurrentUser=false
includeMentionableGroups=false
hasGroups=false
usernames=username
usernames=model.username
placeholderKey=placeholderKey
autocomplete="off"}}
{{/d-modal-body}}

View File

@ -0,0 +1,8 @@
a.assigned-to .fa.fa-user-plus {
margin-right: 2px;
color: #999;
}
.list-tags.assigned {
margin-left: 5px;
}

View File

@ -4,3 +4,4 @@ en:
assigns_user_url_path: "Path to link all user links for assigned (use: {username} to subtitue username)"
discourse_assign:
assigned_to: "Topic assigned to @%{username}"
unassigned: "Topic was unassigned"

View File

@ -3,6 +3,8 @@
# version: 0.1
# authors: Sam Saffron
register_asset 'stylesheets/assigns.scss'
after_initialize do
module ::DiscourseAssign
@ -16,7 +18,42 @@ after_initialize do
before_filter :ensure_logged_in
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
def assign
@ -28,11 +65,14 @@ after_initialize do
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_by_id"] = current_user.id
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,
user_id: assign_to.id,
@ -49,7 +89,7 @@ after_initialize do
post_type: post_type,
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],
user_id: assign_to.id,
@ -63,7 +103,6 @@ after_initialize do
)
end
#end
render json: success_json
end
@ -167,6 +206,7 @@ after_initialize do
DiscourseAssign::Engine.routes.draw do
put "/assign" => "assign#assign"
put "/unassign" => "assign#unassign"
end
Discourse::Application.routes.append do