BigW Consortium Gitlab

Commit 4a6596af by randx

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

parent 92137b7b
......@@ -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.
......@@ -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");
}
})
}
var NoteList = {
notes_path: null,
target_params: null,
target_id: 0,
target_type: null,
first_id: 0,
last_id: 0,
disable:false,
init:
notes_path: null,
target_params: null,
target_id: 0,
target_type: null,
first_id: 0,
last_id: 0,
disable:false,
init:
function(tid, tt, path) {
this.notes_path = path + ".js";
this.target_id = tid;
......@@ -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){
......@@ -59,31 +48,31 @@ init:
},
/**
/**
* Load new notes to fresh list called 'new_notes_list':
* - Replace 'new_notes_list' with new list every n seconds
* - Append new notes to this list after submit
*/
initRefresh:
initRefresh:
function() {
// init timer
var intNew = setInterval("NoteList.getNew()", 10000);
},
replace:
replace:
function(html) {
$("#new_notes_list").html(html);
},
prepend:
prepend:
function(id, html) {
if(id != this.last_id) {
$("#new_notes_list").prepend(html);
}
},
getNew:
getNew:
function() {
// refersh notes list
$.ajax({
......@@ -93,7 +82,7 @@ getNew:
dataType: "script"});
},
refresh:
refresh:
function() {
// refersh notes list
$.ajax({
......@@ -104,14 +93,14 @@ refresh:
},
/**
/**
* Init load of notes:
* 1. Get content with ajax call
* 2. Set content of notes list with loaded one
*/
getContent:
getContent:
function() {
$.ajax({
type: "GET",
......@@ -122,7 +111,7 @@ getContent:
dataType: "script"});
},
setContent:
setContent:
function(fid, lid, html) {
this.last_id = lid;
this.first_id = fid;
......@@ -133,16 +122,14 @@ setContent:
},
/**
/**
* Paging for old notes when scroll to bottom:
* 1. Init scroll events with 'initLoadMore'
* 2. Load onlder notes with 'getOld' method
* 3. append old notes to bottom of list with 'append'
*
*/
getOld:
getOld:
function() {
$('.loading').show();
$.ajax({
......@@ -154,7 +141,7 @@ getOld:
dataType: "script"});
},
append:
append:
function(id, html) {
if(this.first_id == id) {
this.disable = true;
......@@ -164,8 +151,7 @@ append:
}
},
initLoadMore:
initLoadMore:
function() {
$(document).endlessScroll({
bottomPixels: 400,
......@@ -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 @@
}
#new_note {
#note_note {
.note-text {
height:25px;
}
.attach_holder {
......
......@@ -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();
});
- 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'))}");
- 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})}");
......
= 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
-if @note.errors.any?
.alert-message.block-message.error
......@@ -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'}.
......
%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:
......
## 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
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
......
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