Commit 4a6596af authored by randx's avatar randx

Fixed bunch of js bugs with comments. Also added development tips

parent 92137b7b
...@@ -39,5 +39,6 @@ Email ...@@ -39,5 +39,6 @@ Email
## Contribute ## Contribute
[Development Tips](https://github.com/gitlabhq/gitlabhq/blob/master/doc/development.md)
Want to help - send a pull request. Want to help - send a pull request.
We'll accept good pull requests. We'll accept good pull requests.
...@@ -128,3 +128,23 @@ function showDiff(link) { ...@@ -128,3 +128,23 @@ function showDiff(link) {
function ajaxGet(url) { function ajaxGet(url) {
$.ajax({type: "GET", url: url, dataType: "script"}); $.ajax({type: "GET", url: url, dataType: "script"});
} }
/**
* Disable button if text field is empty
*/
function disableButtonIfEmtpyField(field_selector, button_selector) {
field = $(field_selector);
if(field.val() == "") {
field.closest("form").find(button_selector).attr("disabled", "disabled").addClass("disabled");
}
field.on('keyup', function(){
var field = $(this);
var closest_submit = field.closest("form").find(button_selector);
if(field.val() == "") {
closest_submit.attr("disabled", "disabled").addClass("disabled");
} else {
closest_submit.removeAttr("disabled").removeClass("disabled");
}
})
}
var NoteList = { var NoteList = {
notes_path: null, notes_path: null,
target_params: null, target_params: null,
target_id: 0, target_id: 0,
target_type: null, target_type: null,
first_id: 0, first_id: 0,
last_id: 0, last_id: 0,
disable:false, disable:false,
init: init:
function(tid, tt, path) { function(tid, tt, path) {
this.notes_path = path + ".js"; this.notes_path = path + ".js";
this.target_id = tid; this.target_id = tid;
...@@ -24,30 +24,19 @@ init: ...@@ -24,30 +24,19 @@ init:
$('.delete-note').live('ajax:success', function() { $('.delete-note').live('ajax:success', function() {
$(this).closest('li').fadeOut(); }); $(this).closest('li').fadeOut(); });
$('#note_note').on('keyup', function(){ $(".note-form-holder").live("ajax:before", function(){
var field = $(this);
var closest_submit = field.closest("form").find(".submit_note");
if(field.val() == "") {
closest_submit.attr("disabled", "disabled").addClass("disabled");
} else {
closest_submit.removeAttr("disabled").removeClass("disabled");
}
})
$("#new_note").live("ajax:before", function(){
$(".submit_note").attr("disabled", "disabled"); $(".submit_note").attr("disabled", "disabled");
}) })
$("#new_note").live("ajax:complete", function(){ $(".note-form-holder").live("ajax:complete", function(){
$(".submit_note").removeAttr("disabled"); $(".submit_note").removeAttr("disabled");
}) })
$("#note_note").live("focus", function(){ disableButtonIfEmtpyField(".note-text", ".submit_note");
$(".note-text").live("focus", function(){
$(this).css("height", "80px"); $(this).css("height", "80px");
$('.note_advanced_opts').show(); $('.note_advanced_opts').show();
if($(this).val() == "") {
$(this).closest("form").find(".submit_note").attr("disabled", "disabled").addClass("disabled");
}
}); });
$("#note_attachment").change(function(e){ $("#note_attachment").change(function(e){
...@@ -59,31 +48,31 @@ init: ...@@ -59,31 +48,31 @@ init:
}, },
/** /**
* Load new notes to fresh list called 'new_notes_list': * Load new notes to fresh list called 'new_notes_list':
* - Replace 'new_notes_list' with new list every n seconds * - Replace 'new_notes_list' with new list every n seconds
* - Append new notes to this list after submit * - Append new notes to this list after submit
*/ */
initRefresh: initRefresh:
function() { function() {
// init timer // init timer
var intNew = setInterval("NoteList.getNew()", 10000); var intNew = setInterval("NoteList.getNew()", 10000);
}, },
replace: replace:
function(html) { function(html) {
$("#new_notes_list").html(html); $("#new_notes_list").html(html);
}, },
prepend: prepend:
function(id, html) { function(id, html) {
if(id != this.last_id) { if(id != this.last_id) {
$("#new_notes_list").prepend(html); $("#new_notes_list").prepend(html);
} }
}, },
getNew: getNew:
function() { function() {
// refersh notes list // refersh notes list
$.ajax({ $.ajax({
...@@ -93,7 +82,7 @@ getNew: ...@@ -93,7 +82,7 @@ getNew:
dataType: "script"}); dataType: "script"});
}, },
refresh: refresh:
function() { function() {
// refersh notes list // refersh notes list
$.ajax({ $.ajax({
...@@ -104,14 +93,14 @@ refresh: ...@@ -104,14 +93,14 @@ refresh:
}, },
/** /**
* Init load of notes: * Init load of notes:
* 1. Get content with ajax call * 1. Get content with ajax call
* 2. Set content of notes list with loaded one * 2. Set content of notes list with loaded one
*/ */
getContent: getContent:
function() { function() {
$.ajax({ $.ajax({
type: "GET", type: "GET",
...@@ -122,7 +111,7 @@ getContent: ...@@ -122,7 +111,7 @@ getContent:
dataType: "script"}); dataType: "script"});
}, },
setContent: setContent:
function(fid, lid, html) { function(fid, lid, html) {
this.last_id = lid; this.last_id = lid;
this.first_id = fid; this.first_id = fid;
...@@ -133,16 +122,14 @@ setContent: ...@@ -133,16 +122,14 @@ setContent:
}, },
/** /**
* Paging for old notes when scroll to bottom: * Paging for old notes when scroll to bottom:
* 1. Init scroll events with 'initLoadMore' * 1. Init scroll events with 'initLoadMore'
* 2. Load onlder notes with 'getOld' method * 2. Load onlder notes with 'getOld' method
* 3. append old notes to bottom of list with 'append' * 3. append old notes to bottom of list with 'append'
* *
*/ */
getOld:
getOld:
function() { function() {
$('.loading').show(); $('.loading').show();
$.ajax({ $.ajax({
...@@ -154,7 +141,7 @@ getOld: ...@@ -154,7 +141,7 @@ getOld:
dataType: "script"}); dataType: "script"});
}, },
append: append:
function(id, html) { function(id, html) {
if(this.first_id == id) { if(this.first_id == id) {
this.disable = true; this.disable = true;
...@@ -164,8 +151,7 @@ append: ...@@ -164,8 +151,7 @@ append:
} }
}, },
initLoadMore:
initLoadMore:
function() { function() {
$(document).endlessScroll({ $(document).endlessScroll({
bottomPixels: 400, bottomPixels: 400,
...@@ -179,4 +165,18 @@ initLoadMore: ...@@ -179,4 +165,18 @@ initLoadMore:
} }
}); });
} }
};
var PerLineNotes = {
init:
function() {
$(".line_note_link, .line_note_reply_link").live("click", function(e) {
var form = $(".per_line_form");
$(this).closest("tr").after(form);
form.find("#note_line_code").val($(this).attr("line_code"));
form.show();
return false;
});
disableButtonIfEmtpyField(".line-note-text", ".submit_inline_note");
}
} }
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
} }
#new_note { #new_note {
#note_note { .note-text {
height:25px; height:25px;
} }
.attach_holder { .attach_holder {
......
...@@ -5,12 +5,6 @@ ...@@ -5,12 +5,6 @@
:javascript :javascript
$(document).ready(function(){ $(function(){
$(".line_note_link, .line_note_reply_link").live("click", function(e) { PerLineNotes.init();
var form = $(".per_line_form");
$(this).parent().parent().after(form);
form.find("#note_line_code").val($(this).attr("line_code"));
form.show();
return false;
});
}); });
- if note.valid? - if note.valid?
:plain :plain
$("#new_note .error").remove(); $(".note-form-holder .error").remove();
$('#new_note textarea').val(""); $('.note-form-holder textarea').val("");
$('#preview-link').text('Preview'); $('.note-form-holder #preview-link').text('Preview');
$('#preview-note').hide(); $('#note_note').show(); $('.note-form-holder #preview-note').hide();
$('.note-form-holder').show();
NoteList.prepend(#{note.id}, "#{escape_javascript(render partial: "notes/show", locals: {note: note})}"); NoteList.prepend(#{note.id}, "#{escape_javascript(render partial: "notes/show", locals: {note: note})}");
- else - else
:plain :plain
$("#new_note").replaceWith("#{escape_javascript(render('form'))}"); $(".note-form-holder").replaceWith("#{escape_javascript(render('form'))}");
- if note.valid? - if note.valid?
:plain :plain
$(".per_line_form").hide(); $(".per_line_form").hide();
$('#new_note textarea').val(""); $('.line-note-form-holder textarea').val("");
$("a.line_note_reply_link[line_code='#{note.line_code}']").closest("tr").remove(); $("a.line_note_reply_link[line_code='#{note.line_code}']").closest("tr").remove();
var trEl = $(".#{note.line_code}").parent(); var trEl = $(".#{note.line_code}").parent();
trEl.after("#{escape_javascript(render partial: "notes/per_line_show", locals: {note: note})}"); trEl.after("#{escape_javascript(render partial: "notes/per_line_show", locals: {note: note})}");
......
= form_for [@project, @note], remote: "true", multipart: true do |f| .note-form-holder
= form_for [@project, @note], remote: "true", multipart: true do |f|
%h3.page_title Leave a comment %h3.page_title Leave a comment
-if @note.errors.any? -if @note.errors.any?
.alert-message.block-message.error .alert-message.block-message.error
...@@ -7,7 +8,7 @@ ...@@ -7,7 +8,7 @@
= f.hidden_field :noteable_id = f.hidden_field :noteable_id
= f.hidden_field :noteable_type = f.hidden_field :noteable_type
= f.text_area :note, size: 255 = f.text_area :note, size: 255, class: 'note-text'
#preview-note.preview_note.hide #preview-note.preview_note.hide
.hint .hint
.right Comments are parsed with #{link_to "Gitlab Flavored Markdown", help_markdown_path, target: '_blank'}. .right Comments are parsed with #{link_to "Gitlab Flavored Markdown", help_markdown_path, target: '_blank'}.
......
%table{style: "display:none;"} %table{style: "display:none;"}
%tr.per_line_form %tr.per_line_form
%td{colspan: 3 } %td{colspan: 3 }
.line-note-form-holder
= form_for [@project, @note], remote: "true", multipart: true do |f| = form_for [@project, @note], remote: "true", multipart: true do |f|
%h3.page_title Leave a note %h3.page_title Leave a note
%div.span10 %div.span10
...@@ -12,10 +13,10 @@ ...@@ -12,10 +13,10 @@
= f.hidden_field :noteable_id = f.hidden_field :noteable_id
= f.hidden_field :noteable_type = f.hidden_field :noteable_type
= f.hidden_field :line_code = f.hidden_field :line_code
= f.text_area :note, size: 255 = f.text_area :note, size: 255, class: 'line-note-text'
.note_actions .note_actions
.buttons .buttons
= f.submit 'Add note', class: "btn primary submit_note", id: "submit_note" = f.submit 'Add note', class: "btn primary submit_note submit_inline_note", id: "submit_note"
= link_to "Cancel", "#", class: "btn hide-button" = link_to "Cancel", "#", class: "btn hide-button"
.options .options
%h6.left Notify via email: %h6.left Notify via email:
......
## Development tips:
### Start application in development mode
#### 1. Via foreman
bundle exec foreman -p 3000
#### 2. Via gitlab cli
./gitlab start
#### 3. Manually
bundle exec rails s
bundle exec rake environment resque:work QUEUE=* VVERBOSE=1
### Run tests:
#### 1. Packages
# ubuntu
sudo apt-get install libqt4-dev libqtwebkit-dev
sudo apt-get install xvfb
# Mac
brew install qt
brew install xvfb
#### 2. DB & seeds
bundle exec rake db:setup RAILS_ENV=test
bundle exec rake db:seed_fu RAILS_ENV=test
### 3. Run Tests
# All in one
bundle exec gitlab:test
# Rspec
bundle exec rake spec
# Cucumber
bundle exec rake cucumber
...@@ -22,10 +22,11 @@ class GitlabCli ...@@ -22,10 +22,11 @@ class GitlabCli
case @mode case @mode
when 'production'; when 'production';
system(unicorn_start_cmd) system(unicorn_start_cmd)
system(resque_start_cmd)
else else
system(rails_start_cmd) system(rails_start_cmd)
system(resque_dev_start_cmd)
end end
system(resque_start_cmd)
end end
def stop def stop
...@@ -57,6 +58,10 @@ class GitlabCli ...@@ -57,6 +58,10 @@ class GitlabCli
"kill -QUIT `cat #{pid}`" "kill -QUIT `cat #{pid}`"
end end
def resque_dev_start_cmd
"./resque_dev.sh > /dev/null 2>&1"
end
def resque_start_cmd def resque_start_cmd
"./resque.sh > /dev/null 2>&1" "./resque.sh > /dev/null 2>&1"
end end
......
bundle exec rake environment resque:work QUEUE=post_receive,mailer,system_hook VVERBOSE=1 mkdir -p tmp/pids
bundle exec rake environment resque:work QUEUE=post_receive,mailer,system_hook VVERBOSE=1 PIDFILE=tmp/pids/resque_worker.pid RAILS_ENV=development BACKGROUND=yes
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment