Commit ab9612df authored by Jacob Schatz's avatar Jacob Schatz

initial json requests instead of HTML

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