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

This commit is contained in:
randx 2012-08-30 21:31:55 +03:00
parent 92137b7beb
commit 4a6596af27
12 changed files with 269 additions and 200 deletions

View file

@ -39,5 +39,6 @@ Email
## Contribute
[Development Tips](https://github.com/gitlabhq/gitlabhq/blob/master/doc/development.md)
Want to help - send a pull request.
We'll accept good pull requests.

View file

@ -128,3 +128,23 @@ function showDiff(link) {
function ajaxGet(url) {
$.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");
}
})
}

View file

@ -24,30 +24,19 @@ init:
$('.delete-note').live('ajax:success', function() {
$(this).closest('li').fadeOut(); });
$('#note_note').on('keyup', 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(){
$(".note-form-holder").live("ajax:before", function(){
$(".submit_note").attr("disabled", "disabled");
})
$("#new_note").live("ajax:complete", function(){
$(".note-form-holder").live("ajax:complete", function(){
$(".submit_note").removeAttr("disabled");
})
$("#note_note").live("focus", function(){
disableButtonIfEmtpyField(".note-text", ".submit_note");
$(".note-text").live("focus", function(){
$(this).css("height", "80px");
$('.note_advanced_opts').show();
if($(this).val() == "") {
$(this).closest("form").find(".submit_note").attr("disabled", "disabled").addClass("disabled");
}
});
$("#note_attachment").change(function(e){
@ -140,8 +129,6 @@ setContent:
* 3. append old notes to bottom of list with 'append'
*
*/
getOld:
function() {
$('.loading').show();
@ -164,7 +151,6 @@ append:
}
},
initLoadMore:
function() {
$(document).endlessScroll({
@ -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");
}
}

View file

@ -30,7 +30,7 @@
}
#new_note {
#note_note {
.note-text {
height:25px;
}
.attach_holder {

View file

@ -5,12 +5,6 @@
:javascript
$(document).ready(function(){
$(".line_note_link, .line_note_reply_link").live("click", function(e) {
var form = $(".per_line_form");
$(this).parent().parent().after(form);
form.find("#note_line_code").val($(this).attr("line_code"));
form.show();
return false;
});
$(function(){
PerLineNotes.init();
});

View file

@ -1,11 +1,12 @@
- if note.valid?
:plain
$("#new_note .error").remove();
$('#new_note textarea').val("");
$('#preview-link').text('Preview');
$('#preview-note').hide(); $('#note_note').show();
$(".note-form-holder .error").remove();
$('.note-form-holder textarea').val("");
$('.note-form-holder #preview-link').text('Preview');
$('.note-form-holder #preview-note').hide();
$('.note-form-holder').show();
NoteList.prepend(#{note.id}, "#{escape_javascript(render partial: "notes/show", locals: {note: note})}");
- else
:plain
$("#new_note").replaceWith("#{escape_javascript(render('form'))}");
$(".note-form-holder").replaceWith("#{escape_javascript(render('form'))}");

View file

@ -1,7 +1,7 @@
- if note.valid?
:plain
$(".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();
var trEl = $(".#{note.line_code}").parent();
trEl.after("#{escape_javascript(render partial: "notes/per_line_show", locals: {note: note})}");

View file

@ -1,3 +1,4 @@
.note-form-holder
= form_for [@project, @note], remote: "true", multipart: true do |f|
%h3.page_title Leave a comment
-if @note.errors.any?
@ -7,7 +8,7 @@
= f.hidden_field :noteable_id
= 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
.hint
.right Comments are parsed with #{link_to "Gitlab Flavored Markdown", help_markdown_path, target: '_blank'}.

View file

@ -1,6 +1,7 @@
%table{style: "display:none;"}
%tr.per_line_form
%td{colspan: 3 }
.line-note-form-holder
= form_for [@project, @note], remote: "true", multipart: true do |f|
%h3.page_title Leave a note
%div.span10
@ -12,10 +13,10 @@
= f.hidden_field :noteable_id
= f.hidden_field :noteable_type
= f.hidden_field :line_code
= f.text_area :note, size: 255
= f.text_area :note, size: 255, class: 'line-note-text'
.note_actions
.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"
.options
%h6.left Notify via email:

45
doc/development.md Normal file
View file

@ -0,0 +1,45 @@
## 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

7
gitlab
View file

@ -22,10 +22,11 @@ class GitlabCli
case @mode
when 'production';
system(unicorn_start_cmd)
system(resque_start_cmd)
else
system(rails_start_cmd)
system(resque_dev_start_cmd)
end
system(resque_start_cmd)
end
def stop
@ -57,6 +58,10 @@ class GitlabCli
"kill -QUIT `cat #{pid}`"
end
def resque_dev_start_cmd
"./resque_dev.sh > /dev/null 2>&1"
end
def resque_start_cmd
"./resque.sh > /dev/null 2>&1"
end

View file

@ -1 +1,2 @@
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