target_params: null,
target_id: 0,
target_type: null,
+ top_id: 0,
bottom_id: 0,
loading_more_disabled: false,
+ reversed: false,
init:
function(tid, tt, path) {
this.notes_path = path + ".js";
this.target_id = tid;
this.target_type = tt;
+ this.reversed = $("#notes-list").hasClass("reversed");
this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;
// get initial set of notes
* Replaces the content of #notes-list with the given html.
*/
setContent:
- function(last_id, html) {
+ function(first_id, last_id, html) {
+ this.top_id = first_id;
this.bottom_id = last_id;
$("#notes-list").html(html);
- // Init infinite scrolling
+ // init infinite scrolling
this.initLoadMore();
+
+ // init getting new notes
+ if (this.reversed) {
+ this.initRefreshNew();
+ }
},
$.ajax({
type: "GET",
url: this.notes_path,
- data: "loading_more=1&after_id=" + this.bottom_id + this.target_params,
+ data: "loading_more=1&" + (this.reversed ? "before_id" : "after_id") + "=" + this.bottom_id + this.target_params,
complete: function(){ $('.notes-status').removeClass("loading")},
beforeSend: function() { $('.notes-status').addClass("loading") },
dataType: "script"});
this.loading_more_disabled = true;
// from now on only get new notes
- this.initRefreshNew();
+ if (!this.reversed) {
+ this.initRefreshNew();
+ }
},
},
/**
- * Gets the new set of notes (i.e. all notes after ).
+ * Gets the new set of notes.
*/
getNew:
function() {
$.ajax({
type: "GET",
url: this.notes_path,
- data: "loading_new=1&after_id=" + this.bottom_id + this.target_params,
+ data: "loading_new=1&after_id=" + (this.reversed ? this.top_id : this.bottom_id) + this.target_params,
dataType: "script"});
},
*/
appendNewNote:
function(id, html) {
- if(id != this.bottom_id) {
+ if (this.reversed) {
+ $("#new-notes-list").prepend(html);
+ } else {
$("#new-notes-list").append(html);
}
}
target_type = params[:target_type]
target_id = params[:target_id]
after_id = params[:after_id]
+ before_id = params[:before_id]
@notes = case target_type
project.snippets.find(target_id).notes.fresh
when "wall"
# this is the only case, where the order is DESC
- project.common_notes.order("created_at DESC").limit(50)
+ project.common_notes.order("created_at DESC, id DESC").limit(50)
when "wiki"
project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20]
end
@notes = if after_id
@notes.where("id > ?", after_id)
- else
+ elsif before_id
+ @notes.where("id < ?", before_id)
+ else
@notes
end
end
scope :today, where("created_at >= :date", date: Date.today)
scope :last_week, where("created_at >= :date", date: (Date.today - 7.days))
scope :since, lambda { |day| where("created_at >= :date", date: (day)) }
- scope :fresh, order("created_at ASC")
+ scope :fresh, order("created_at ASC, id ASC")
scope :inc_author_project, includes(:project, :author)
scope :inc_author, includes(:author)