[#369] pull request page; in progress

This commit is contained in:
Alexander Machehin 2014-12-24 23:41:13 +05:00
parent 8c061c19a6
commit a37616b352
15 changed files with 208 additions and 92 deletions

View File

@ -39,25 +39,3 @@ var SoundNotificationsHelper = function() {
} }
} }
RosaABF.factory('SoundNotificationsHelper', SoundNotificationsHelper); RosaABF.factory('SoundNotificationsHelper', SoundNotificationsHelper);
var confirmMessage = function() {
return {
show: function() {
return confirm('<%= I18n.t 'layout.confirm' %>');
}
}
}
RosaABF.service('confirmMessage', confirmMessage);
var DateTimeFormatter = function() {
var UtcFormatter = function(api_time) {
return moment.utc(api_time * 1000).format('YYYY-MM-DD HH:mm:ss UTC');
}
return {
utc : UtcFormatter
}
}
RosaABF.factory("DateTimeFormatter", DateTimeFormatter);

View File

@ -1,14 +1,9 @@
CommentsController = (Comment, Preview, confirmMessage, $compile, $scope) -> CommentsController = (Comment, Preview, confirmMessage, $scope, compileHTML, $rootScope) ->
inlineCommentParams = {} inlineCommentParams = {}
list = null list = null
new_inline_form = $('.new_inline_comment_form.hidden') new_inline_form = $('.new_inline_comment_form.hidden')
compileHTML = (data) ->
template = angular.element(data)
linkFn = $compile(template)
linkFn($scope)
setInlineCommentParams = (params) -> setInlineCommentParams = (params) ->
inlineCommentParams = params inlineCommentParams = params
@ -68,7 +63,7 @@ CommentsController = (Comment, Preview, confirmMessage, $compile, $scope) ->
vm.processing = true vm.processing = true
promise = Comment.add(vm.project, vm.commentable, vm.new_body) promise = Comment.add(vm.project, vm.commentable, vm.new_body)
promise.then (response) -> promise.then (response) ->
element = compileHTML(response.data.html) element = compileHTML.run($scope, response.data.html)
list.append(element) list.append(element)
vm.new_body = '' vm.new_body = ''
@ -110,7 +105,7 @@ CommentsController = (Comment, Preview, confirmMessage, $compile, $scope) ->
setInlineCommentParams(params) setInlineCommentParams(params)
new_form = new_inline_form.html() new_form = new_inline_form.html()
new_form = compileHTML(new_form) new_form = compileHTML.run($scope, new_form)
line_comments.append(new_form) line_comments.append(new_form)
line_comments.find('#new_inline_comment').addClass('cloned') line_comments.find('#new_inline_comment').addClass('cloned')
true true
@ -130,7 +125,7 @@ CommentsController = (Comment, Preview, confirmMessage, $compile, $scope) ->
vm.processing = true vm.processing = true
promise = Comment.addInline(vm.project, vm.commentable, vm.new_inline_body, inlineCommentParams) promise = Comment.addInline(vm.project, vm.commentable, vm.new_inline_body, inlineCommentParams)
promise.then (response) -> promise.then (response) ->
element = compileHTML(response.data.html) element = compileHTML.run($scope, response.data.html)
vm.hideInlineForm() vm.hideInlineForm()
inline_comments.append(element) inline_comments.append(element)
@ -140,6 +135,10 @@ CommentsController = (Comment, Preview, confirmMessage, $compile, $scope) ->
false false
$rootScope.$on "compile_html", (event, args) ->
html = compileHTML.run($scope, args.html)
args.element.html(html)
vm.init = (project, commentable = {}) -> vm.init = (project, commentable = {}) ->
vm.project = project vm.project = project
vm.commentable = commentable vm.commentable = commentable
@ -162,6 +161,7 @@ CommentsController.$inject = [
'Comment' 'Comment'
'Preview' 'Preview'
'confirmMessage' 'confirmMessage'
'$compile'
'$scope' '$scope'
'compileHTML'
'$rootScope'
] ]

View File

@ -1,4 +1,12 @@
ApiPullRequestService = ($resource) -> ApiPullRequestService = ($resource, $http) ->
getPath = (pull, kind) ->
name_with_owner = pull.owner+'/'+pull.project
switch kind
when 'activity' then params = { get_activity: true }
when 'diff' then params = { get_diff: true }
when 'commits' then params = { get_commits: true }
Routes.project_pull_request_path(name_with_owner, pull.serial_id, params)
PullRequestResource = $resource("/:owner/:project/pull_requests/:serial_id?format=json", PullRequestResource = $resource("/:owner/:project/pull_requests/:serial_id?format=json",
owner: "@pull_request.to_ref.project.owner_uname" owner: "@pull_request.to_ref.project.owner_uname"
@ -15,10 +23,26 @@ ApiPullRequestService = ($resource) ->
method: "PUT" method: "PUT"
isArray: false isArray: false
) )
get_activity = (params) ->
path = getPath(params, 'activity')
$http.get(path)
get_diff = (params) ->
path = getPath(params, 'diff')
$http.get(path)
get_commits = (params) ->
path = getPath(params, 'commits')
$http.get(path)
resource: PullRequestResource resource: PullRequestResource
get_activity: get_activity
get_diff: get_diff
get_commits: get_commits
angular angular
.module("RosaABF") .module("RosaABF")
.factory "ApiPullRequest", ApiPullRequestService .factory "ApiPullRequest", ApiPullRequestService
ApiPullRequestService.$inject = ['$resource'] ApiPullRequestService.$inject = ['$resource', '$http']

View File

@ -1,4 +1,5 @@
PullRequestController = (dataservice, $http, ApiPullRequest, ApiProject, DateTimeFormatter) -> PullRequestController = (dataservice, $http, ApiPullRequest, ApiProject, DateTimeFormatter,
compileHTML, $scope, $rootScope) ->
vm = this vm = this
vm.project_resource = null vm.project_resource = null
@ -13,8 +14,25 @@ PullRequestController = (dataservice, $http, ApiPullRequest, ApiProject, DateTim
vm.can_delete_branch = false vm.can_delete_branch = false
activity = $('#pull-activity')
diff = $('#diff.tab-pane > .content')
commits = $('#commits.tab-pane > .content')
vm.active_tab = null
vm.processing = false
vm.is_pull_updated = false
vm.is_activity_updated = false
vm.is_diff_updated = false
vm.is_commits_updated = false
vm.getPullRequest = -> vm.getPullRequest = ->
vm.pull_resource = ApiPullRequest.resource.get(vm.pull_params, (results) -> vm.pull_resource = ApiPullRequest.resource.get(vm.pull_params, (results) ->
if vm.pull
vm.is_pull_updated = vm.pull.updated_at is results.pull_request.updated_at
else
vm.is_pull_updated = true
vm.pull = results.pull_request vm.pull = results.pull_request
vm.merged_at = DateTimeFormatter.utc(vm.pull.merged_at) if vm.pull.merged_at vm.merged_at = DateTimeFormatter.utc(vm.pull.merged_at) if vm.pull.merged_at
vm.closed_at = DateTimeFormatter.utc(vm.pull.closed_at) if vm.pull.closed_at vm.closed_at = DateTimeFormatter.utc(vm.pull.closed_at) if vm.pull.closed_at
@ -69,15 +87,61 @@ PullRequestController = (dataservice, $http, ApiPullRequest, ApiProject, DateTim
ref: vm.pull.from_ref.ref ref: vm.pull.from_ref.ref
sha: vm.pull.from_ref.sha sha: vm.pull.from_ref.sha
vm.getActivity = ->
return if vm.pull_updated and vm.is_activity_updated
vm.processing = true
promise = ApiPullRequest.get_activity(vm.pull_params)
promise.then (response) ->
activity.html(null)
#html = compileHTML.run($scope, response.data)
#activity.html(html)
$rootScope.$broadcast('compile_html', { element: activity, html: response.data })
vm.processing = false
vm.is_activity_updated = true
false
vm.getDiff = ->
return if vm.pull_updated and vm.is_diff_updated
vm.processing = true
promise = ApiPullRequest.get_diff(vm.pull_params)
promise.then (response) ->
diff.html(null)
#html = compileHTML.run($scope, response.data)
#diff.html(html)
$rootScope.$broadcast('compile_html', { element: diff, html: response.data })
vm.processing = false
vm.is_diff_updated = true
false
vm.getCommits = ->
return if vm.pull_updated and vm.is_commits_updated
vm.processing = true
promise = ApiPullRequest.get_commits(vm.pull_params)
promise.then (response) ->
commits.html(null)
html = compileHTML.run($scope, response.data)
commits.html(html)
vm.processing = false
vm.is_commits_updated = true
false
init = (dataservice) -> init = (dataservice) ->
vm.pull_params = dataservice vm.pull_params = dataservice
tab = "discussion"
if location.href.match(/(.*)#diff(.*)/)
tab = "diff"
else tab = "commits" if document.location.href.match(/(.*)#commits(.*)/)
$("#pull_tabs a[href=\"#" + tab + "\"]").tab "show"
vm.getPullRequest() vm.getPullRequest()
if location.href.match(/(.*)#diff(.*)/)
vm.active_tab = "diff"
vm.getDiff()
else if document.location.href.match(/(.*)#commits(.*)/)
vm.active_tab = "commits"
vm.getCommits()
else
vm.active_tab = 'discussion'
vm.getActivity()
$("#pull_tabs a[href=\"#" + vm.active_tab + "\"]").tab "show"
true true
init(dataservice) init(dataservice)
@ -93,4 +157,7 @@ PullRequestController.$inject = [
'ApiPullRequest' 'ApiPullRequest'
'ApiProject' 'ApiProject'
'DateTimeFormatter' 'DateTimeFormatter'
'compileHTML'
'$scope'
'$rootScope'
] ]

View File

@ -0,0 +1,11 @@
compileHTML = ($compile) ->
run: (scope, data) ->
template = angular.element(data)
linkFn = $compile(template)
linkFn(scope)
angular
.module("RosaABF")
.service "compileHTML", compileHTML
compileHTML.$inject = ['$compile']

View File

@ -0,0 +1,7 @@
confirmMessage = ->
show: ->
confirm "<%= I18n.t 'layout.confirm' %>"
angular
.module("RosaABF")
.service "confirmMessage", confirmMessage

View File

@ -0,0 +1,9 @@
DateTimeFormatter = ->
UtcFormatter = (api_time) ->
moment.utc(api_time * 1000).format "YYYY-MM-DD HH:mm:ss UTC"
utc: UtcFormatter
angular
.module("RosaABF")
.service "DateTimeFormatter", DateTimeFormatter

View File

@ -26,6 +26,7 @@ table.table.diff.inline
text-align: right text-align: right
vertical-align: middle vertical-align: middle
padding: 0 6px padding: 0 6px
width: 40px
td.code.del td.code.del
background-color: #FFDDDD background-color: #FFDDDD

View File

@ -86,12 +86,18 @@ class Projects::PullRequestsController < Projects::BaseController
end end
def show def show
unless request.xhr?
if @pull.nil? if @pull.nil?
redirect_to project_issue_path(@project, @issue) redirect_to project_issue_path(@project, @issue)
else
load_diff_commits_data
end end
load_diff_commits_data
if params[:get_activity] == 'true'
render partial: 'activity', layout: false
elsif params[:get_diff] == 'true'
render partial: 'diff_tab', layout: false
elsif params[:get_commits] == 'true'
render partial: 'commits_tab', layout: false
end end
end end

View File

@ -0,0 +1,3 @@
- if @total_commits > @commits.count
h4= t("projects.pull_requests.is_big", count: @commits.count)
== render partial: 'projects/git/commits/commits', object: @commits, locals: { project: @pull.from_project }

View File

@ -1,21 +0,0 @@
#diff.tab-pane
.leftside
-total_additions = @stats.inject(0) {|sum, n| sum + n.additions}
-total_deletions = @stats.inject(0) {|sum, n| sum + n.deletions}
h5= t('layout.projects.diff_show_header',
files: t('layout.projects.commit_files_count', count: @stats.count),
additions: t('layout.projects.commit_additions_count', count: total_additions),
deletions: t('layout.projects.commit_deletions_count', count: total_deletions))
.both
-begin
== render_diff_stats(@stats)
== render partial: 'pull_diff', collection: @pull.diff
- rescue => ex
-if ex.try(:message) == 'Grit::Git::GitTimeout'
p= t 'layout.git.repositories.commit_diff_too_big'
-else
-raise ex
#commits.tab-pane
- if @total_commits > @commits.count
h4= t("projects.pull_requests.is_big", count: @commits.count)
== render partial: 'projects/git/commits/commits', object: @commits, locals: { project: @pull.from_project }

View File

@ -0,0 +1,16 @@
.leftside
-total_additions = @stats.inject(0) {|sum, n| sum + n.additions}
-total_deletions = @stats.inject(0) {|sum, n| sum + n.deletions}
h5= t('layout.projects.diff_show_header',
files: t('layout.projects.commit_files_count', count: @stats.count),
additions: t('layout.projects.commit_additions_count', count: total_additions),
deletions: t('layout.projects.commit_deletions_count', count: total_deletions))
.clearfix
-begin
== render_diff_stats(@stats)
== render partial: 'pull_diff', collection: @pull.diff
- rescue => ex
-if ex.try(:message) == 'Grit::Git::GitTimeout'
p= t 'layout.git.repositories.commit_diff_too_big'
-else
-raise ex

View File

@ -1,20 +1,21 @@
ul.nav.nav-tabs#pull_tabs role = 'tablist' ul.nav.nav-tabs#pull_tabs role = 'tablist'
li role = 'presentation' li role = 'presentation' ng-class = '{active: pullCtrl.active_tab == "discussion"}'
a[ data-toggle = 'tab' a[ data-toggle = 'tab'
role = 'tab' role = 'tab'
aria-controls = 'discussion' aria-controls = 'discussion'
ng-click = 'pullCtrl.getActivity()'
href = '#discussion' ]= t 'pull_requests.tabs.discussion' href = '#discussion' ]= t 'pull_requests.tabs.discussion'
-if @stats -if @stats
li role = 'presentation' li role = 'presentation' ng-class = '{active: pullCtrl.active_tab == "diff"}'
a[ data-toggle = 'tab' a[ data-toggle = 'tab'
role = 'tab' role = 'tab'
aria-controls = 'diff' aria-controls = 'diff'
href = "#diff" ]= "#{t'pull_requests.tabs.diff'} (#{@stats.count})" ng-click = 'pullCtrl.getDiff()'
href = "#diff" ]= "#{t'pull_requests.tabs.diff'} ({{ pullCtrl.pull.stats_count }})"
-if @commits -if @commits
li role = 'presentation' li role = 'presentation' ng-class = '{active: pullCtrl.active_tab == "commits"}'
- commits_message = @commits.count.to_s
- commits_message << '+' if @total_commits > @commits.count
a[ data-toggle = 'tab' a[ data-toggle = 'tab'
role = 'tab' role = 'tab'
aria-controls = 'commits' aria-controls = 'commits'
href = '#commits' ]= "#{t'pull_requests.tabs.commits'} (#{commits_message})" ng-click = 'pullCtrl.getCommits()'
href = '#commits' ]= "#{t'pull_requests.tabs.commits'} ({{ pullCtrl.pull.commits_count }})"

View File

@ -12,22 +12,30 @@ div ng-controller = 'PullRequestController as pullCtrl' ng-cloak = true
=< pull_header @pull =< pull_header @pull
div role = 'tabpanel' div role = 'tabpanel'
=render 'nav_tabs' == render 'nav_tabs'
.tab-content.pull_diff_fix
#discussion.tab-pane.active role = 'tabpanel' .tab-content
#discussion.tab-pane role = 'tabpanel'
div[ ng-controller = 'IssueController as issueCtrl' ng-cloak = true ] div[ ng-controller = 'IssueController as issueCtrl' ng-cloak = true ]
== render 'projects/issues/header' == render 'projects/issues/header'
- ctrl_params = "{ kind: 'pull', id: #{@issue.serial_id} }" - ctrl_params = "{ kind: 'pull', id: #{@issue.serial_id} }"
div[ ng-controller = 'CommentsController as commentsCtrl' div[ ng-controller = 'CommentsController as commentsCtrl'
ng-init = "commentsCtrl.init('#{@project.name_with_owner}', #{ctrl_params})" ] ng-init = "commentsCtrl.init('#{@project.name_with_owner}', #{ctrl_params})" ]
#pull-activity== render 'activity' #pull-activity ng-hide = 'pullCtrl.processing'
i.fa.fa-spinner.fa-spin.fa-lg ng-show = 'pullCtrl.processing'
- if current_user - if current_user
hr hr
== render 'projects/comments/add', project: @project, commentable: @issue == render 'projects/comments/add', project: @project, commentable: @issue
.pull_status.offset20== render 'status' .pull_status.offset20== render 'status'
== render 'diff_commits_tabs' unless @pull.already? #diff.tab-pane
.content ng-hide = 'pullCtrl.processing'
i.fa.fa-spinner.fa-spin.fa-lg.offset20 ng-show = 'pullCtrl.processing'
#commits.tab-pane
.content ng-hide = 'pullCtrl.processing'
i.fa.fa-spinner.fa-spin.fa-lg.offset20 ng-show = 'pullCtrl.processing'
div ng-non-bindable = true div ng-non-bindable = true
== render 'projects/comments/new_line' == render 'projects/comments/new_line'

View File

@ -1,7 +1,7 @@
json.pull_request do json.pull_request do
json.number @pull.serial_id json.number @pull.serial_id
json.(@pull, :status) json.(@pull, :status, :updated_at)
json.to_ref do json.to_ref do
json.ref @pull.to_ref json.ref @pull.to_ref
json.sha @pull.to_commit.try(:id) json.sha @pull.to_commit.try(:id)
@ -38,4 +38,10 @@ json.pull_request do
json.(@pull.issue.closer, :id, :name, :uname) json.(@pull.issue.closer, :id, :name, :uname)
end if @pull.merged? end if @pull.merged?
end end
commits_count = @commits.count.to_s
commits_count << '+' if @total_commits > @commits.count
json.stats_count @stats.count
json.commits_count commits_count
end end