Remove wall from basic notes logic

This commit is contained in:
Dmitriy Zaporozhets 2013-03-19 12:34:14 +02:00
parent 1752c6dc8b
commit 5bf3a898ed
5 changed files with 3 additions and 183 deletions

View file

@ -4,31 +4,16 @@ var NoteList = {
target_params: null, target_params: null,
target_id: 0, target_id: 0,
target_type: null, target_type: null,
top_id: 0,
bottom_id: 0,
loading_more_disabled: false, loading_more_disabled: false,
reversed: false,
init: function(tid, tt, path) { init: function(tid, tt, path) {
NoteList.notes_path = path + ".js"; NoteList.notes_path = path + ".js";
NoteList.target_id = tid; NoteList.target_id = tid;
NoteList.target_type = tt; NoteList.target_type = tt;
NoteList.reversed = $("#notes-list").is(".reversed");
NoteList.target_params = "target_type=" + NoteList.target_type + "&target_id=" + NoteList.target_id; NoteList.target_params = "target_type=" + NoteList.target_type + "&target_id=" + NoteList.target_id;
NoteList.setupMainTargetNoteForm(); NoteList.setupMainTargetNoteForm();
if(NoteList.reversed) {
var form = $(".js-main-target-form");
form.find(".note-form-actions").hide();
var textarea = form.find(".js-note-text");
textarea.css("height", "40px");
textarea.on("focus", function(){
textarea.css("height", "80px");
form.find(".note-form-actions").show();
});
}
// get initial set of notes // get initial set of notes
NoteList.getContent(); NoteList.getContent();
@ -344,127 +329,10 @@ var NoteList = {
* Replaces the content of #notes-list with the given html. * Replaces the content of #notes-list with the given html.
*/ */
setContent: function(newNoteIds, html) { setContent: function(newNoteIds, html) {
NoteList.top_id = newNoteIds.first();
NoteList.bottom_id = newNoteIds.last();
$("#notes-list").html(html); $("#notes-list").html(html);
// for the wall
if (NoteList.reversed) {
// init infinite scrolling
NoteList.initLoadMore();
// init getting new notes
NoteList.initRefreshNew();
}
}, },
/**
* Handle loading more notes when scrolling to the bottom of the page.
* The id of the last note in the list is in NoteList.bottom_id.
*
* Set up refreshing only new notes after all notes have been loaded.
*/
/**
* Initializes loading more notes when scrolling to the bottom of the page.
*/
initLoadMore: function() {
$(document).endlessScroll({
bottomPixels: 400,
fireDelay: 1000,
fireOnce:true,
ceaseFire: function() {
return NoteList.loading_more_disabled;
},
callback: function(i) {
NoteList.getMore();
}
});
},
/**
* Gets an additional set of notes.
*/
getMore: function() {
// only load more notes if there are no "new" notes
$('.loading').show();
$.ajax({
url: NoteList.notes_path,
data: NoteList.target_params + "&loading_more=1&" + (NoteList.reversed ? "before_id" : "after_id") + "=" + NoteList.bottom_id,
complete: function(){ $('.js-notes-busy').removeClass("loading")},
beforeSend: function() { $('.js-notes-busy').addClass("loading") },
dataType: "script"
});
},
/**
* Called in response to getMore().
* Append notes to #notes-list.
*/
appendMoreNotes: function(newNoteIds, html) {
var lastNewNoteId = newNoteIds.last();
if(lastNewNoteId != NoteList.bottom_id) {
NoteList.bottom_id = lastNewNoteId;
$("#notes-list").append(html);
}
},
/**
* Called in response to getMore().
* Disables loading more notes when scrolling to the bottom of the page.
*/
finishedLoadingMore: function() {
NoteList.loading_more_disabled = true;
// make sure we are up to date
NoteList.updateVotes();
},
/**
* Handle refreshing and adding of new notes.
*
* New notes are all notes that are created after the site has been loaded.
* The "old" notes are in #notes-list the "new" ones will be in #new-notes-list.
* The id of the last "old" note is in NoteList.bottom_id.
*/
/**
* Initializes getting new notes every n seconds.
*
* Note: only used on wall.
*/
initRefreshNew: function() {
setInterval("NoteList.getNew()", 10000);
},
/**
* Gets the new set of notes.
*
* Note: only used on wall.
*/
getNew: function() {
$.ajax({
url: NoteList.notes_path,
data: NoteList.target_params + "&loading_new=1&after_id=" + (NoteList.reversed ? NoteList.top_id : NoteList.bottom_id),
dataType: "script"
});
},
/**
* Called in response to getNew().
* Replaces the content of #new-notes-list with the given html.
*
* Note: only used on wall.
*/
replaceNewNotes: function(newNoteIds, html) {
$("#new-notes-list").html(html);
NoteList.updateVotes();
},
/** /**
* Adds a single common note to #notes-list. * Adds a single common note to #notes-list.
*/ */
@ -497,15 +365,6 @@ var NoteList = {
$.proxy(NoteList.removeDiscussionNoteForm, form).call(); $.proxy(NoteList.removeDiscussionNoteForm, form).call();
}, },
/**
* Adds a single wall note to #new-notes-list.
*
* Note: only used on wall.
*/
appendNewWallNote: function(id, html) {
$("#new-notes-list").prepend(html);
},
/** /**
* Called in response the main target form has been successfully submitted. * Called in response the main target form has been successfully submitted.
* *

View file

@ -3,8 +3,6 @@ module Notes
def execute def execute
target_type = params[:target_type] target_type = params[:target_type]
target_id = params[:target_id] target_id = params[:target_id]
after_id = params[:after_id]
before_id = params[:before_id]
@notes = case target_type @notes = case target_type
@ -16,17 +14,6 @@ module Notes
project.merge_requests.find(target_id).mr_and_commit_notes.inc_author.fresh project.merge_requests.find(target_id).mr_and_commit_notes.inc_author.fresh
when "snippet" when "snippet"
project.snippets.find(target_id).notes.fresh project.snippets.find(target_id).notes.fresh
when "wall"
# this is the only case, where the order is DESC
project.notes.common.inc_author_project.order("created_at DESC, id DESC").limit(50)
end
@notes = if after_id
@notes.where("id > ?", after_id)
elsif before_id
@notes.where("id < ?", before_id)
else
@notes
end end
end end
end end

View file

@ -1,12 +0,0 @@
.js-main-target-form
- if can? current_user, :write_note, @project
= render "notes/form"
%ul#new-notes-list.reversed.notes
%ul#notes-list.reversed.notes
.notes-busy.js-notes-busy
:javascript
$(function(){
NoteList.init("#{@target_id}", "#{@target_type}", "#{project_notes_path(@project)}");
});

View file

@ -2,10 +2,7 @@
var noteHtml = "#{escape_javascript(render "notes/note", note: @note)}"; var noteHtml = "#{escape_javascript(render "notes/note", note: @note)}";
- if note_for_main_target?(@note) - if note_for_main_target?(@note)
- if @note.for_wall? NoteList.appendNewNote(#{@note.id}, noteHtml);
NoteList.appendNewWallNote(#{@note.id}, noteHtml);
- else
NoteList.appendNewNote(#{@note.id}, noteHtml);
- else - else
:plain :plain
var firstDiscussionNoteHtml = "#{escape_javascript(render "notes/diff_notes_with_reply", notes: [@note])}"; var firstDiscussionNoteHtml = "#{escape_javascript(render "notes/diff_notes_with_reply", notes: [@note])}";
@ -18,4 +15,4 @@
- if note_for_main_target?(@note) - if note_for_main_target?(@note)
NoteList.errorsOnForm(errorsHtml); NoteList.errorsOnForm(errorsHtml);
- else - else
NoteList.errorsOnForm(errorsHtml, "#{@note.discussion_id}"); NoteList.errorsOnForm(errorsHtml, "#{@note.discussion_id}");

View file

@ -1,15 +1,4 @@
- unless @notes.blank? - unless @notes.blank?
var notesHtml = "#{escape_javascript(render 'notes/notes')}"; var notesHtml = "#{escape_javascript(render 'notes/notes')}";
- new_note_ids = @notes.map(&:id) - new_note_ids = @notes.map(&:id)
- if loading_more_notes? NoteList.setContent(#{new_note_ids}, notesHtml);
NoteList.appendMoreNotes(#{new_note_ids}, notesHtml);
- elsif loading_new_notes?
NoteList.replaceNewNotes(#{new_note_ids}, notesHtml);
- else
NoteList.setContent(#{new_note_ids}, notesHtml);
- else
- if loading_more_notes?
NoteList.finishedLoadingMore();