Skip to content
Snippets Groups Projects
Commit ab9612df authored by Jacob Schatz's avatar Jacob Schatz
Browse files

initial json requests instead of HTML

parent f7164201
No related branches found
No related tags found
No related merge requests found
Showing with 66 additions and 39 deletions
Loading
Loading
@@ -63,12 +63,18 @@ class @MergeRequest
$('a.btn-reopen').removeClass('hidden')
$('div.status-box-closed').removeClass('hidden')
$('div.status-box-open').addClass('hidden')
$('div.mr-state-widget-closed').removeClass('hidden')
$('div.mr-state-widget-opened').addClass('hidden')
else
$('a.btn-reopen').addClass('hidden')
$('a.issuable-edit').removeClass('hidden')
$('a.btn-close').removeClass('hidden')
$('div.status-box-closed').addClass('hidden')
$('div.status-box-open').removeClass('hidden')
$('div.mr-state-widget-closed').addClass('hidden')
$('div.mr-state-widget-opened').removeClass('hidden')
else
new Flash(mergeRequestFailMessage, 'alert')
$this.prop('disabled', false)
Loading
Loading
Loading
Loading
@@ -28,8 +28,9 @@ class @MergeRequestWidget
 
getMergeStatus: ->
$.get @opts.url_to_automerge_check, (data) ->
$('.mr-state-widget').replaceWith(data)
console.log("data",data);
# $('div.mr-state-widget.mr-state-widget-opened').replaceWith(data)
getCiStatus: ->
if @opts.ci_enable
$.get @opts.url_to_ci_check, (data) =>
Loading
Loading
Loading
Loading
@@ -48,9 +48,15 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@note_counts = Note.where(commit_id: @merge_request.commits.map(&:id)).
group(:commit_id).count
 
json_merge_request = @merge_requests.as_json
respond_to do |format|
format.html
format.json { render json: @merge_request }
format.json do
render json: {
hi: "yes"
}
end
format.diff { render text: @merge_request.to_diff(current_user) }
format.patch { render text: @merge_request.to_patch(current_user) }
end
Loading
Loading
@@ -143,7 +149,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
format.json do
render json: {
saved: @merge_request.valid?,
assignee_avatar_url: @merge_request.assignee.try(:avatar_url)
assignee_avatar_url: @merge_request.assignee.try(:avatar_url),
closed_event: @merge_request.closed_event
}
end
end
Loading
Loading
@@ -154,8 +161,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController
 
def merge_check
@merge_request.check_if_can_be_merged if @merge_request.unchecked?
render partial: "projects/merge_requests/widget/show.html.haml", layout: false
puts @merge_request.merge_status
respond_to do |format|
format.json do
render json: {
can_be_merged: @merge_request.merge_status == :can_be_merged
}
end
format.html do
render partial: "projects/merge_requests/widget/show.html.haml", layout: false
end
end
end
 
def cancel_merge_when_build_succeeds
Loading
Loading
Loading
Loading
@@ -23,6 +23,15 @@ module MergeRequestsHelper
return 'hidden' if mr.closed? == closed
end
 
def merge_request_widget_visibility(mr, *states)
states.each do |state|
if mr.state == state
return
end
end
return 'hidden'
end
def mr_css_classes(mr)
classes = "merge-request"
classes << " closed" if mr.closed?
Loading
Loading
.mr-state-widget
.mr-state-widget.mr-state-widget-closed{class: merge_request_widget_visibility(@merge_request, 'closed')}
= render 'projects/merge_requests/widget/heading'
.mr-widget-body
%h4
Loading
Loading
.mr-state-widget
.mr-state-widget.mr-state-widget-locked{class: merge_request_widget_visibility(@merge_request, 'locked')}
= render 'projects/merge_requests/widget/heading'
.mr-widget-body
%h4
Loading
Loading
.mr-state-widget
.mr-state-widget.mr-state-widget-merged{class: merge_request_widget_visibility(@merge_request, 'merged')}
= render 'projects/merge_requests/widget/heading'
.mr-widget-body
%h4
Loading
Loading
.mr-state-widget
.mr-state-widget.mr-state-widget-opened{class: merge_request_widget_visibility(@merge_request, "opened","reopened")}
= render 'projects/merge_requests/widget/heading'
.mr-widget-body
- if @project.archived?
= render 'projects/merge_requests/widget/open/archived'
- elsif @merge_request.commits.blank?
= render 'projects/merge_requests/widget/open/nothing'
- elsif @merge_request.branch_missing?
= render 'projects/merge_requests/widget/open/missing_branch'
- elsif @merge_request.unchecked?
= render 'projects/merge_requests/widget/open/check'
- elsif @merge_request.cannot_be_merged?
= render 'projects/merge_requests/widget/open/conflicts'
- elsif @merge_request.work_in_progress?
= render 'projects/merge_requests/widget/open/wip'
- elsif @merge_request.merge_when_build_succeeds?
= render 'projects/merge_requests/widget/open/merge_when_build_succeeds'
- elsif !@merge_request.can_be_merged_by?(current_user)
= render 'projects/merge_requests/widget/open/not_allowed'
- elsif @merge_request.can_be_merged?
= render 'projects/merge_requests/widget/open/accept'
.mr-widget-body.merge-request-archived{class: ("hidden" unless @project.archived?)}
= render 'projects/merge_requests/widget/open/archived'
.mr-widget-body.merge-request-blank{class: ("hidden" unless @merge_request.commits.blank?)}
= render 'projects/merge_requests/widget/open/nothing'
.mr-widget-body.merge-request-branch-missing{class: ("hidden" unless @merge_request.branch_missing?)}
= render 'projects/merge_requests/widget/open/missing_branch'
.mr-widget-body.merge-request-unchecked{class: ("hidden" unless @merge_request.unchecked?)}
= render 'projects/merge_requests/widget/open/check'
.mr-widget-body.merge-request-cannot-be-merged{class: ("hidden" unless @merge_request.cannot_be_merged?)}
= render 'projects/merge_requests/widget/open/conflicts'
.mr-widget-body.merge-request-work-in-progress{class: ("hidden" unless @merge_request.work_in_progress?)}
= render 'projects/merge_requests/widget/open/wip'
.mr-widget-body.merge-request-merge-when-build-succeeds{class: ("hidden" unless @merge_request.merge_when_build_succeeds?)}
= render 'projects/merge_requests/widget/open/merge_when_build_succeeds'
.mr-widget-body.not-allowed{class: ("hidden" if @merge_request.can_be_merged_by?(current_user))}
= render 'projects/merge_requests/widget/open/not_allowed'
.mr-widget-body.merge-request-archived.can-be-merged{class: ("hidden" unless @merge_request.can_be_merged?)}
= render 'projects/merge_requests/widget/open/accept'
 
- if @closes_issues.present?
.mr-widget-footer
Loading
Loading
- if @merge_request.open?
= render 'projects/merge_requests/widget/open'
- elsif @merge_request.merged?
= render 'projects/merge_requests/widget/merged'
- elsif @merge_request.closed?
= render 'projects/merge_requests/widget/closed'
- elsif @merge_request.locked?
= render 'projects/merge_requests/widget/locked'
= render 'projects/merge_requests/widget/open'
= render 'projects/merge_requests/widget/merged'
= render 'projects/merge_requests/widget/closed'
= render 'projects/merge_requests/widget/locked'
 
:javascript
var merge_request_widget;
 
merge_request_widget = new MergeRequestWidget({
url_to_automerge_check: "#{merge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
url_to_automerge_check: "#{merge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, format: :json)}",
check_enable: #{@merge_request.unchecked? ? "true" : "false"},
url_to_ci_check: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
ci_enable: #{@project.ci_service ? "true" : "false"},
Loading
Loading
%h4
%h4
Project is archived
%p
This merge request cannot be merged because archived projects cannot be written to.
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