Can remove staff notes
This commit is contained in:
parent
98a71cfc52
commit
71d0b4c784
|
@ -0,0 +1,11 @@
|
||||||
|
import RestAdapter from 'discourse/adapters/rest';
|
||||||
|
const ajax = Discourse.ajax;
|
||||||
|
|
||||||
|
export default RestAdapter.extend({
|
||||||
|
destroyRecord(store, type, record) {
|
||||||
|
const path = this.pathFor(store, type, record.get('id'));
|
||||||
|
const userId = record.get('user_id');
|
||||||
|
return ajax(`${path}?user_id=${userId}`, { method: 'DELETE' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -23,6 +23,10 @@ export default Ember.Controller.extend({
|
||||||
this.set('newNote', '');
|
this.set('newNote', '');
|
||||||
this.get('model').pushObject(note);
|
this.get('model').pushObject(note);
|
||||||
}).catch(popupAjaxError).finally(() => this.set('saving', false));
|
}).catch(popupAjaxError).finally(() => this.set('saving', false));
|
||||||
|
},
|
||||||
|
|
||||||
|
removeNote(note) {
|
||||||
|
note.destroyRecord().then(() => this.get('model').removeObject(note));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,6 +11,15 @@
|
||||||
<div class='note-info'>
|
<div class='note-info'>
|
||||||
<span class='username'>{{n.created_by.username}}</span>
|
<span class='username'>{{n.created_by.username}}</span>
|
||||||
<span class='post-date'>{{age-with-tooltip n.created_at}}</span>
|
<span class='post-date'>{{age-with-tooltip n.created_at}}</span>
|
||||||
|
|
||||||
|
<span class='controls'>
|
||||||
|
{{d-button action="removeNote"
|
||||||
|
actionParam=n
|
||||||
|
icon="times"
|
||||||
|
class="btn-small btn-danger"
|
||||||
|
title="staff_notes.remove"}}
|
||||||
|
</span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class='cooked'>
|
<div class='cooked'>
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
.modal-body.staff-notes-modal {
|
.modal-body.staff-notes-modal {
|
||||||
height: 300px;
|
height: 300px;
|
||||||
|
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
width: 99%;
|
width: 98%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.posted-by {
|
.posted-by {
|
||||||
|
@ -29,7 +33,7 @@
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-date {
|
.controls {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,3 +3,4 @@ en:
|
||||||
staff_notes:
|
staff_notes:
|
||||||
title: "Staff Notes"
|
title: "Staff Notes"
|
||||||
attach: "Attach Note"
|
attach: "Attach Note"
|
||||||
|
remove: "Remove Note"
|
||||||
|
|
30
plugin.rb
30
plugin.rb
|
@ -27,23 +27,39 @@ after_initialize do
|
||||||
|
|
||||||
def self.add_note(user_id, raw, created_by)
|
def self.add_note(user_id, raw, created_by)
|
||||||
notes = notes_for(user_id)
|
notes = notes_for(user_id)
|
||||||
record = { id: SecureRandom.hex(16), raw: raw, created_by: created_by, created_at: Time.now }
|
record = { id: SecureRandom.hex(16), user_id: user_id, raw: raw, created_by: created_by, created_at: Time.now }
|
||||||
notes << record
|
notes << record
|
||||||
::PluginStore.set("staff_notes", key_for(user_id), notes)
|
::PluginStore.set("staff_notes", key_for(user_id), notes)
|
||||||
|
|
||||||
record
|
record
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.remove_note(user_id, note_id)
|
||||||
|
notes = notes_for(user_id)
|
||||||
|
notes.reject! {|n| n[:id] == note_id}
|
||||||
|
|
||||||
|
if notes.size > 0
|
||||||
|
::PluginStore.set("staff_notes", key_for(user_id), notes)
|
||||||
|
else
|
||||||
|
::PluginStore.remove("staff_notes", key_for(user_id))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require_dependency 'application_serializer'
|
require_dependency 'application_serializer'
|
||||||
class ::StaffNoteSerializer < ApplicationSerializer
|
class ::StaffNoteSerializer < ApplicationSerializer
|
||||||
attributes :id, :raw, :created_by, :created_at
|
attributes :id, :user_id, :raw, :created_by, :created_at
|
||||||
|
|
||||||
def id
|
def id
|
||||||
object[:id]
|
object[:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_id
|
||||||
|
object[:user_id]
|
||||||
|
end
|
||||||
|
|
||||||
def raw
|
def raw
|
||||||
object[:raw]
|
object[:raw]
|
||||||
end
|
end
|
||||||
|
@ -85,11 +101,21 @@ after_initialize do
|
||||||
|
|
||||||
render json: serialize_data(staff_note, ::StaffNoteSerializer)
|
render json: serialize_data(staff_note, ::StaffNoteSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
user = User.where(id: params[:user_id]).first
|
||||||
|
raise Discourse::NotFound if user.blank?
|
||||||
|
|
||||||
|
::DiscourseStaffNotes.remove_note(user.id, params[:id])
|
||||||
|
render json: success_json
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
DiscourseStaffNotes::Engine.routes.draw do
|
DiscourseStaffNotes::Engine.routes.draw do
|
||||||
get '/' => 'staff_notes#index'
|
get '/' => 'staff_notes#index'
|
||||||
post '/' => 'staff_notes#create'
|
post '/' => 'staff_notes#create'
|
||||||
|
delete '/:id' => 'staff_notes#destroy'
|
||||||
end
|
end
|
||||||
|
|
||||||
Discourse::Application.routes.append do
|
Discourse::Application.routes.append do
|
||||||
|
|
Loading…
Reference in New Issue