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;
this.target_type = tt; this.target_type = tt;
this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id; this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;
// get notes // get notes
this.getContent(); this.getContent();
// get new notes every n seconds // get new notes every n seconds
this.initRefresh(); this.initRefresh();
$('.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); $(".submit_note").attr("disabled", "disabled");
var closest_submit = field.closest("form").find(".submit_note"); })
if(field.val() == "") {
closest_submit.attr("disabled", "disabled").addClass("disabled"); $(".note-form-holder").live("ajax:complete", function(){
} else { $(".submit_note").removeAttr("disabled");
closest_submit.removeAttr("disabled").removeClass("disabled"); })
}
}) disableButtonIfEmtpyField(".note-text", ".submit_note");
$("#new_note").live("ajax:before", function(){ $(".note-text").live("focus", function(){
$(".submit_note").attr("disabled", "disabled"); $(this).css("height", "80px");
}) $('.note_advanced_opts').show();
});
$("#new_note").live("ajax:complete", function(){
$(".submit_note").removeAttr("disabled"); $("#note_attachment").change(function(e){
})
$("#note_note").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){
var val = $('.input-file').val(); var val = $('.input-file').val();
var filename = val.replace(/^.*[\\\/]/, ''); var filename = val.replace(/^.*[\\\/]/, '');
$(".file_name").text(filename); $(".file_name").text(filename);
}); });
}, },
/** /**
* 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({
type: "GET", type: "GET",
url: this.notes_path, url: this.notes_path,
data: "last_id=" + this.last_id + this.target_params, data: "last_id=" + this.last_id + this.target_params,
dataType: "script"}); dataType: "script"});
}, },
refresh: refresh:
function() { function() {
// refersh notes list // refersh notes list
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: this.notes_path, url: this.notes_path,
data: "first_id=" + this.first_id + "&last_id=" + this.last_id + this.target_params, data: "first_id=" + this.first_id + "&last_id=" + this.last_id + this.target_params,
dataType: "script"}); dataType: "script"});
}, },
/** /**
* 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",
url: this.notes_path, url: this.notes_path,
data: "?" + this.target_params, data: "?" + this.target_params,
complete: function(){ $('.status').removeClass("loading")}, complete: function(){ $('.status').removeClass("loading")},
beforeSend: function() { $('.status').addClass("loading") }, beforeSend: function() { $('.status').addClass("loading") },
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;
$("#notes-list").html(html); $("#notes-list").html(html);
// Init infinite scrolling // Init infinite scrolling
this.initLoadMore(); this.initLoadMore();
}, },
/** /**
* 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:
function() {
getOld: $('.loading').show();
function() { $.ajax({
$('.loading').show(); type: "GET",
$.ajax({ url: this.notes_path,
type: "GET", data: "first_id=" + this.first_id + this.target_params,
url: this.notes_path, complete: function(){ $('.status').removeClass("loading")},
data: "first_id=" + this.first_id + this.target_params, beforeSend: function() { $('.status').addClass("loading") },
complete: function(){ $('.status').removeClass("loading")}, dataType: "script"});
beforeSend: function() { $('.status').addClass("loading") }, },
dataType: "script"});
}, append:
function(id, html) {
append: if(this.first_id == id) {
function(id, html) { this.disable = true;
if(this.first_id == id) { } else {
this.disable = true; this.first_id = id;
} else { $("#notes-list").append(html);
this.first_id = id; }
$("#notes-list").append(html); },
}
},
initLoadMore: initLoadMore:
function() { function() {
$(document).endlessScroll({ $(document).endlessScroll({
bottomPixels: 400, bottomPixels: 400,
fireDelay: 1000, fireDelay: 1000,
fireOnce:true, fireOnce:true,
ceaseFire: function() { ceaseFire: function() {
...@@ -177,6 +163,20 @@ initLoadMore: ...@@ -177,6 +163,20 @@ initLoadMore:
callback: function(i) { callback: function(i) {
NoteList.getOld(); NoteList.getOld();
} }
}); });
} }
};
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
%h3.page_title Leave a comment = form_for [@project, @note], remote: "true", multipart: true do |f|
-if @note.errors.any? %h3.page_title Leave a comment
.alert-message.block-message.error -if @note.errors.any?
- @note.errors.full_messages.each do |msg| .alert-message.block-message.error
%div= msg - @note.errors.full_messages.each do |msg|
%div= msg
= 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'}.
.clearfix .clearfix
.row.note_advanced_opts.hide .row.note_advanced_opts.hide
.span3 .span3
= f.submit 'Add Comment', class: "btn success submit_note grouped", id: "submit_note" = f.submit 'Add Comment', class: "btn success submit_note grouped", id: "submit_note"
= link_to 'Preview', preview_project_notes_path(@project), class: 'btn grouped', id: 'preview-link' = link_to 'Preview', preview_project_notes_path(@project), class: 'btn grouped', id: 'preview-link'
.span4.notify_opts .span4.notify_opts
%h6.left Notify via email: %h6.left Notify via email:
= label_tag :notify do = label_tag :notify do
= check_box_tag :notify, 1, @note.noteable_type != "Commit" = check_box_tag :notify, 1, @note.noteable_type != "Commit"
%span Project team %span Project team
- if @note.notify_only_author?(current_user) - if @note.notify_only_author?(current_user)
= label_tag :notify_author do = label_tag :notify_author do
= check_box_tag :notify_author, 1 , @note.noteable_type == "Commit" = check_box_tag :notify_author, 1 , @note.noteable_type == "Commit"
%span Commit author %span Commit author
.span5.attachments .span5.attachments
%h6.left Attachment: %h6.left Attachment:
%span.file_name File name... %span.file_name File name...
.input.input_file .input.input_file
%a.file_upload.btn.small Upload File %a.file_upload.btn.small Upload File
= f.file_field :attachment, class: "input-file" = f.file_field :attachment, class: "input-file"
%span.hint Any file less than 10 MB %span.hint Any file less than 10 MB
%table{style: "display:none;"} %table{style: "display:none;"}
%tr.per_line_form %tr.per_line_form
%td{colspan: 3 } %td{colspan: 3 }
= form_for [@project, @note], remote: "true", multipart: true do |f| .line-note-form-holder
%h3.page_title Leave a note = form_for [@project, @note], remote: "true", multipart: true do |f|
%div.span10 %h3.page_title Leave a note
-if @note.errors.any? %div.span10
.alert-message.block-message.error -if @note.errors.any?
- @note.errors.full_messages.each do |msg| .alert-message.block-message.error
%div= msg - @note.errors.full_messages.each do |msg|
%div= msg
= 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:
.labels .labels
= label_tag :notify do = label_tag :notify do
= check_box_tag :notify, 1, @note.noteable_type != "Commit" = check_box_tag :notify, 1, @note.noteable_type != "Commit"
%span Project team %span Project team
- if @note.notify_only_author?(current_user) - if @note.notify_only_author?(current_user)
= label_tag :notify_author do = label_tag :notify_author do
= check_box_tag :notify_author, 1 , @note.noteable_type == "Commit" = check_box_tag :notify_author, 1 , @note.noteable_type == "Commit"
%span Commit author %span Commit author
:javascript :javascript
$(function(){ $(function(){
......
## 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