Skip to content
Snippets Groups Projects
Commit 2f7effe8 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Refactor issues, Remove ajax

parent 88260774
No related branches found
No related tags found
No related merge requests found
Showing
with 44 additions and 174 deletions
function switchToNewIssue(){
$(".issues_content").hide("fade", { direction: "left" }, 150, function(){
$('select#issue_assignee_id').chosen();
$('select#issue_milestone_id').chosen();
$("#new_issue_dialog").show("fade", { direction: "right" }, 150);
$('.top-tabs .add_new').hide();
disableButtonIfEmptyField("#issue_title", ".save-btn");
GitLab.GfmAutoComplete.setup();
});
}
function switchToEditIssue(){
$(".issues_content").hide("fade", { direction: "left" }, 150, function(){
$('select#issue_assignee_id').chosen();
$('select#issue_milestone_id').chosen();
$("#edit_issue_dialog").show("fade", { direction: "right" }, 150);
$('.add_new').hide();
disableButtonIfEmptyField("#issue_title", ".save-btn");
GitLab.GfmAutoComplete.setup();
});
}
function switchFromNewIssue(){
backToIssues();
}
function switchFromEditIssue(){
backToIssues();
}
function backToIssues(){
$("#edit_issue_dialog, #new_issue_dialog").hide("fade", { direction: "right" }, 150, function(){
$(".issues_content").show("fade", { direction: "left" }, 150, function() {
$("#edit_issue_dialog").html("");
$("#new_issue_dialog").html("");
$('.add_new').show();
});
});
}
function initIssuesSearch() {
var href = $('#issue_search_form').attr('action');
var last_terms = '';
Loading
Loading
@@ -76,23 +36,15 @@ function issuesPage(){
$(this).closest("form").submit();
});
 
$("#new_issue_link").click(function(){
updateNewIssueURL();
});
$('body').on('ajax:success', '.close_issue, .reopen_issue, #new_issue', function(){
$('body').on('ajax:success', '.close_issue, .reopen_issue', function(){
var t = $(this),
totalIssues,
reopen = t.hasClass('reopen_issue'),
newIssue = false;
if( this.id == 'new_issue' ){
newIssue = true;
}
$('.issue_counter, #new_issue').each(function(){
reopen = t.hasClass('reopen_issue');
$('.issue_counter').each(function(){
var issue = $(this);
totalIssues = parseInt( $(this).html(), 10 );
 
if( newIssue || ( reopen && issue.closest('.main_menu').length ) ){
if( reopen && issue.closest('.main_menu').length ){
$(this).html( totalIssues+1 );
}else {
$(this).html( totalIssues-1 );
Loading
Loading
@@ -126,20 +78,3 @@ function issuesCheckChanged() {
$('.issues_filters').show();
}
}
function updateNewIssueURL(){
var new_issue_link = $("#new_issue_link");
var milestone_id = $("#milestone_id").val();
var assignee_id = $("#assignee_id").val();
var new_href = "";
if(milestone_id){
new_href = "issue[milestone_id]=" + milestone_id + "&";
}
if(assignee_id){
new_href = new_href + "issue[assignee_id]=" + assignee_id;
}
if(new_href.length){
new_href = new_issue_link.attr("href") + "?" + new_href;
new_issue_link.attr("href", new_href);
}
};
class IssuesController < ProjectResourceController
before_filter :module_enabled
before_filter :issue, only: [:edit, :update, :destroy, :show]
before_filter :issue, only: [:edit, :update, :show]
 
# Allow read any issue
before_filter :authorize_read_issue!
Loading
Loading
@@ -11,9 +11,6 @@ class IssuesController < ProjectResourceController
# Allow modify issue
before_filter :authorize_modify_issue!, only: [:edit, :update]
 
# Allow destroy issue
before_filter :authorize_admin_issue!, only: [:destroy]
respond_to :js, :html
 
def index
Loading
Loading
@@ -77,15 +74,6 @@ class IssuesController < ProjectResourceController
end
end
 
def destroy
@issue.destroy
respond_to do |format|
format.html { redirect_to project_issues_path }
format.js { render nothing: true }
end
end
def sort
return render_404 unless can?(current_user, :admin_issue, @project)
 
Loading
Loading
class MergeRequestsController < ProjectResourceController
before_filter :module_enabled
before_filter :merge_request, only: [:edit, :update, :destroy, :show, :commits, :diffs, :automerge, :automerge_check, :ci_status]
before_filter :merge_request, only: [:edit, :update, :show, :commits, :diffs, :automerge, :automerge_check, :ci_status]
before_filter :validates_merge_request, only: [:show, :diffs]
before_filter :define_show_vars, only: [:show, :diffs]
 
Loading
Loading
@@ -13,9 +13,6 @@ class MergeRequestsController < ProjectResourceController
# Allow modify merge_request
before_filter :authorize_modify_merge_request!, only: [:close, :edit, :update, :sort]
 
# Allow destroy merge_request
before_filter :authorize_admin_merge_request!, only: [:destroy]
def index
@merge_requests = MergeRequestsLoadContext.new(project, current_user, params).execute
end
Loading
Loading
@@ -85,14 +82,6 @@ class MergeRequestsController < ProjectResourceController
end
end
 
def destroy
@merge_request.destroy
respond_to do |format|
format.html { redirect_to project_merge_requests_url(@project) }
end
end
def branch_from
@commit = project.commit(params[:ref])
@commit = CommitDecorator.decorate(@commit)
Loading
Loading
Loading
Loading
@@ -62,7 +62,11 @@ class Milestone < ActiveRecord::Base
end
 
def can_be_closed?
issues.count > 0 && open? && issues.opened.count.zero?
open? && issues.opened.count.zero?
end
def is_empty?
total_items_count.zero?
end
 
def open?
Loading
Loading
%div.issue-form-holder
%h3.page_title= @issue.new_record? ? "New Issue" : "Edit Issue ##{@issue.id}"
= form_for [@project, @issue], remote: request.xhr? do |f|
= form_for [@project, @issue] do |f|
-if @issue.errors.any?
.alert-message.block-message.error
%ul
- @issue.errors.full_messages.each do |msg|
%li= msg
- @issue.errors.full_messages.each do |msg|
%span= msg
%br
.issue_form_box
.issue_title
.clearfix
= f.label :title do
%strong= "Subject *"
.input
= f.text_field :title, maxlength: 255, class: "xxlarge js-gfm-input", autofocus: true
= f.text_field :title, maxlength: 255, class: "xxlarge js-gfm-input", autofocus: true, required: true
.issue_middle_block
.issue_assignee
= f.label :assignee_id do
Loading
Loading
@@ -47,14 +47,8 @@
-else
= f.submit 'Save changes', class: "save-btn btn"
 
- cancel_class = 'btn cancel-btn'
- if request.xhr?
= link_to "Cancel", "#back", onclick: "backToIssues();", class: cancel_class
- else
- if @issue.new_record?
= link_to "Cancel", project_issues_path(@project), class: cancel_class
- else
= link_to "Cancel", project_issue_path(@project, @issue), class: cancel_class
- cancel_path = @issue.new_record? ? project_issues_path(@project) : project_issue_path(@project, @issue)
= link_to "Cancel", cancel_path, class: 'btn cancel-btn'
 
 
 
Loading
Loading
Loading
Loading
@@ -16,7 +16,7 @@
= link_to 'Reopen', project_issue_path(issue.project, issue, issue: {closed: false }, status_only: true), method: :put, class: "btn small grouped reopen_issue", remote: true
- else
= link_to 'Close', project_issue_path(issue.project, issue, issue: {closed: true }, status_only: true), method: :put, class: "btn small grouped close_issue", remote: true
= link_to edit_project_issue_path(issue.project, issue), class: "btn small edit-issue-link grouped", remote: true do
= link_to edit_project_issue_path(issue.project, issue), class: "btn small edit-issue-link grouped" do
%i.icon-edit
Edit
 
Loading
Loading
- if @issue.valid?
:plain
switchFromNewIssue();
$("#issues-table").prepend("#{escape_javascript(render(partial: 'show', locals: {issue: @issue}))}");
$.ajax({type: "GET", url: location.href, dataType: "script"});
- else
:plain
$("#new_issue_dialog").empty();
$("#new_issue_dialog").append("#{escape_javascript(render('form'))}");
$('select#issue_assignee_id').chosen();
:plain
$("#edit_issue_dialog").html("#{escape_javascript(render('form'))}");
switchToEditIssue();
= render "issues/head"
#new_issue_dialog
#edit_issue_dialog
.issues_content
%h3.page_title
Issues
Loading
Loading
@@ -6,7 +8,7 @@
.right
.span5
- if can? current_user, :write_issue, @project
= link_to new_project_issue_path(@project), class: "right btn", title: "New Issue", remote: true, id: "new_issue_link" do
= link_to new_project_issue_path(@project, issue: { assignee_id: params[:assignee_id], milestone_id: params[:milestone_id]}), class: "right btn", title: "New Issue", id: "new_issue_link" do
%i.icon-plus
New Issue
= form_tag search_project_issues_path(@project), method: :get, remote: true, id: "issue_search_form", class: :right do
Loading
Loading
@@ -58,9 +60,6 @@
%ul#issues-table.well-list.issues_table
= render "issues"
 
#new_issue_dialog
#edit_issue_dialog
:javascript
$(function(){
issuesPage();
Loading
Loading
:plain
$("#new_issue_dialog").html("#{escape_javascript(render('form'))}");
switchToNewIssue();
- if params[:status_only]
- if @issue.valid?
:plain
$("##{dom_id(@issue)}").fadeOut();
- else
- if @issue.valid?
:plain
updatePage();
switchFromEditIssue();
- else
:plain
$("#edit_issue_dialog").empty();
$("#edit_issue_dialog").append("#{escape_javascript(render('form'))}");
$('select#issue_assignee_id').chosen();
Loading
Loading
@@ -32,7 +32,7 @@
.top_box_content
= f.label :title do
%strong= "Title *"
.input= f.text_field :title, class: "input-xxlarge pad js-gfm-input", maxlength: 255, rows: 5
.input= f.text_field :title, class: "input-xxlarge pad js-gfm-input", maxlength: 255, rows: 5, required: true
.merge_requests_middle_box
.merge_requests_assignee
= f.label :assignee_id do
Loading
Loading
Loading
Loading
@@ -10,15 +10,18 @@
%span.cred (Expired)
%small
= milestone.expires_at
.row
.span4
.progress.progress-info
.bar{style: "width: #{milestone.percent_complete}%;"}
.span6
= link_to project_issues_path(milestone.project, milestone_id: milestone.id) do
= pluralize milestone.issues.count, 'Issue'
&nbsp;
= link_to project_merge_requests_path(milestone.project, milestone_id: milestone.id) do
= pluralize milestone.merge_requests.count, 'Merge Request'
&nbsp;
%span.light #{milestone.percent_complete}% complete
- if milestone.is_empty?
%span.muted Empty
- else
.row
.span4
.progress.progress-info
.bar{style: "width: #{milestone.percent_complete}%;"}
.span6
= link_to project_issues_path(milestone.project, milestone_id: milestone.id) do
= pluralize milestone.issues.count, 'Issue'
&nbsp;
= link_to project_merge_requests_path(milestone.project, milestone_id: milestone.id) do
= pluralize milestone.merge_requests.count, 'Merge Request'
&nbsp;
%span.light #{milestone.percent_complete}% complete
Loading
Loading
@@ -164,7 +164,7 @@ Gitlab::Application.routes.draw do
end
end
 
resources :merge_requests, constraints: {id: /\d+/} do
resources :merge_requests, constraints: {id: /\d+/}, except: [:destroy] do
member do
get :diffs
get :automerge
Loading
Loading
@@ -200,9 +200,9 @@ Gitlab::Application.routes.draw do
:via => [:get, :post], constraints: {from: /.+/, to: /.+/}
 
resources :team, controller: 'team_members', only: [:index]
resources :milestones
resources :milestones, except: [:destroy]
resources :labels, only: [:index]
resources :issues do
resources :issues, except: [:destroy] do
collection do
post :sort
post :bulk_update
Loading
Loading
Loading
Loading
@@ -24,11 +24,9 @@ Feature: Project Issues
Given I click link "Release 0.4"
Then I should see issue "Release 0.4"
 
@javascript
Scenario: I submit new unassigned issue
Given I click link "New Issue"
And I submit new issue "500 error on profile"
Given I click link "500 error on profile"
Then I should see issue "500 error on profile"
 
@javascript
Loading
Loading
@@ -57,15 +55,6 @@ Feature: Project Issues
Then I should see "Release 0.3" in issues
And I should not see "Release 0.4" in issues
 
# TODO: find out solution for poltergeist/phantomjs or remove
# @javascript
# Scenario: I clear search
# Given I click link "All"
# And I fill in issue search with "Something"
# And I fill in issue search with ""
# Then I should see "Release 0.4" in issues
# And I should see "Release 0.3" in issues
@javascript
Scenario: I create Issue with pre-selected milestone
Given project "Shop" has milestone "v2.2"
Loading
Loading
Loading
Loading
@@ -95,7 +95,7 @@ class ProjectIssues < Spinach::FeatureSteps
end
 
Then 'I should see selected milestone with title "v3.0"' do
issues_milestone_selector = "#milestone_id_chzn > a"
issues_milestone_selector = "#issue_milestone_id_chzn > a"
page.find(issues_milestone_selector).should have_content("v3.0")
end
 
Loading
Loading
@@ -106,7 +106,7 @@ class ProjectIssues < Spinach::FeatureSteps
end
 
Then 'I should see first assignee from "Shop" as selected assignee' do
issues_assignee_selector = "#assignee_id_chzn > a"
issues_assignee_selector = "#issue_assignee_id_chzn > a"
project = Project.find_by_name "Shop"
assignee_name = project.users.first.name
page.find(issues_assignee_selector).should have_content(assignee_name)
Loading
Loading
Loading
Loading
@@ -11,7 +11,7 @@ describe "Issues" do
project.add_access(user2, :read, :write)
end
 
describe "Edit issue", js: true do
describe "Edit issue" do
let!(:issue) do
create(:issue,
author: @user,
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment