Can remove staff notes

This commit is contained in:
Robin Ward 2016-03-11 12:27:46 -05:00
parent 98a71cfc52
commit 71d0b4c784
6 changed files with 59 additions and 4 deletions

View File

@ -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' });
}
});

View File

@ -23,6 +23,10 @@ export default Ember.Controller.extend({
this.set('newNote', '');
this.get('model').pushObject(note);
}).catch(popupAjaxError).finally(() => this.set('saving', false));
},
removeNote(note) {
note.destroyRecord().then(() => this.get('model').removeObject(note));
}
}
});

View File

@ -11,6 +11,15 @@
<div class='note-info'>
<span class='username'>{{n.created_by.username}}</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 class='cooked'>

View File

@ -1,8 +1,12 @@
.modal-body.staff-notes-modal {
height: 300px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
textarea {
width: 99%;
width: 98%;
}
.posted-by {
@ -29,7 +33,7 @@
margin-bottom: 1em;
}
.post-date {
.controls {
float: right;
}
}

View File

@ -3,3 +3,4 @@ en:
staff_notes:
title: "Staff Notes"
attach: "Attach Note"
remove: "Remove Note"

View File

@ -27,23 +27,39 @@ after_initialize do
def self.add_note(user_id, raw, created_by)
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
::PluginStore.set("staff_notes", key_for(user_id), notes)
record
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
require_dependency 'application_serializer'
class ::StaffNoteSerializer < ApplicationSerializer
attributes :id, :raw, :created_by, :created_at
attributes :id, :user_id, :raw, :created_by, :created_at
def id
object[:id]
end
def user_id
object[:user_id]
end
def raw
object[:raw]
end
@ -85,11 +101,21 @@ after_initialize do
render json: serialize_data(staff_note, ::StaffNoteSerializer)
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
DiscourseStaffNotes::Engine.routes.draw do
get '/' => 'staff_notes#index'
post '/' => 'staff_notes#create'
delete '/:id' => 'staff_notes#destroy'
end
Discourse::Application.routes.append do