diff options
author | Luke Bennett <lukeeeebennettplus@gmail.com> | 2016-07-27 18:52:30 +0100 |
---|---|---|
committer | Luke Bennett <lukeeeebennettplus@gmail.com> | 2016-09-12 14:35:12 +0100 |
commit | 03891a62a71cdab2810b90123d9ff9947403a9ca (patch) | |
tree | 3d2f9ca247c91244495352ef0b86d95b17d5bb75 | |
parent | ad2271a1686cd18ba4fbac3b8b43552de10915ad (diff) | |
download | gitlab-ce-03891a62a71cdab2810b90123d9ff9947403a9ca.tar.gz |
Updated for es5
-rw-r--r-- | app/assets/javascripts/dispatcher.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/dispatcher.js.coffee | 172 | ||||
-rw-r--r-- | app/assets/javascripts/merge_request_widget.js | 169 | ||||
-rw-r--r-- | app/assets/javascripts/merge_request_widget.js.coffee | 233 |
4 files changed, 149 insertions, 426 deletions
diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index 99b16f7d59b..0677880ec2e 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -82,6 +82,7 @@ shortcut_handler = new ShortcutsIssuable(true); new ZenMode(); new MergedButtons(); + new MergeRequestWidget(); break; case 'projects:merge_requests:commits': case 'projects:merge_requests:builds': diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee deleted file mode 100644 index 36d55fe88e6..00000000000 --- a/app/assets/javascripts/dispatcher.js.coffee +++ /dev/null @@ -1,172 +0,0 @@ -$ -> - new Dispatcher() - -class Dispatcher - constructor: () -> - @initSearch() - @initPageScripts() - - initPageScripts: -> - page = $('body').attr('data-page') - - unless page - return false - - path = page.split(':') - shortcut_handler = null - switch page - when 'projects:issues:index' - Issuable.init() - new IssuableBulkActions() - shortcut_handler = new ShortcutsNavigation() - when 'projects:issues:show' - new Issue() - shortcut_handler = new ShortcutsIssuable() - new ZenMode() - when 'projects:milestones:show', 'groups:milestones:show', 'dashboard:milestones:show' - new Milestone() - when 'dashboard:todos:index' - new Todos() - when 'projects:milestones:new', 'projects:milestones:edit' - new ZenMode() - new DueDateSelect() - new GLForm($('.milestone-form')) - when 'groups:milestones:new' - new ZenMode() - when 'projects:compare:show' - new Diff() - when 'projects:issues:new','projects:issues:edit' - shortcut_handler = new ShortcutsNavigation() - new GLForm($('.issue-form')) - new IssuableForm($('.issue-form')) - when 'projects:merge_requests:new', 'projects:merge_requests:edit' - new Diff() - shortcut_handler = new ShortcutsNavigation() - new GLForm($('.merge-request-form')) - new IssuableForm($('.merge-request-form')) - when 'projects:tags:new' - new ZenMode() - new GLForm($('.tag-form')) - when 'projects:releases:edit' - new ZenMode() - new GLForm($('.release-form')) - when 'projects:merge_requests:show' - new Diff() - shortcut_handler = new ShortcutsIssuable(true) - new ZenMode() - new MergedButtons() - new MergeRequestWidget() - when 'projects:merge_requests:commits', 'projects:merge_requests:builds' - new MergedButtons() - when "projects:merge_requests:diffs" - new Diff() - new ZenMode() - new MergedButtons() - when 'projects:merge_requests:index' - shortcut_handler = new ShortcutsNavigation() - Issuable.init() - when 'dashboard:activity' - new Activities() - when 'dashboard:projects:starred' - new Activities() - when 'projects:commit:show' - new Commit() - new Diff() - new ZenMode() - shortcut_handler = new ShortcutsNavigation() - when 'projects:commits:show', 'projects:activity' - shortcut_handler = new ShortcutsNavigation() - when 'projects:show' - shortcut_handler = new ShortcutsNavigation() - - new NotificationsForm() - new TreeView() if $('#tree-slider').length - when 'groups:activity' - new Activities() - when 'groups:show' - shortcut_handler = new ShortcutsNavigation() - new NotificationsForm() - new NotificationsDropdown() - when 'groups:group_members:index' - new GroupMembers() - new UsersSelect() - when 'projects:project_members:index' - new ProjectMembers() - new UsersSelect() - when 'groups:new', 'groups:edit', 'admin:groups:edit', 'admin:groups:new' - new GroupAvatar() - when 'projects:tree:show' - shortcut_handler = new ShortcutsNavigation() - new TreeView() - when 'projects:find_file:show' - shortcut_handler = true - when 'projects:blob:show', 'projects:blame:show' - new LineHighlighter() - shortcut_handler = new ShortcutsNavigation() - new ShortcutsBlob true - when 'projects:labels:new', 'projects:labels:edit' - new Labels() - when 'projects:labels:index' - new LabelManager() if $('.prioritized-labels').length - when 'projects:network:show' - # Ensure we don't create a particular shortcut handler here. This is - # already created, where the network graph is created. - shortcut_handler = true - when 'projects:forks:new' - new ProjectFork() - when 'projects:artifacts:browse' - new BuildArtifacts() - when 'projects:group_links:index' - new GroupsSelect() - when 'search:show' - new Search() - - switch path.first() - when 'admin' - new Admin() - switch path[1] - when 'groups' - new UsersSelect() - when 'projects' - new NamespaceSelects() - when 'dashboard', 'root' - shortcut_handler = new ShortcutsDashboardNavigation() - when 'profiles' - new NotificationsForm() - new NotificationsDropdown() - when 'projects' - new Project() - new ProjectAvatar() - switch path[1] - when 'compare' - new CompareAutocomplete() - when 'edit' - shortcut_handler = new ShortcutsNavigation() - new ProjectNew() - when 'new' - new ProjectNew() - when 'show' - new ProjectNew() - new ProjectShow() - new NotificationsDropdown() - when 'wikis' - new Wikis() - shortcut_handler = new ShortcutsNavigation() - new ZenMode() - new GLForm($('.wiki-form')) - when 'snippets' - shortcut_handler = new ShortcutsNavigation() - new ZenMode() if path[2] == 'show' - when 'labels', 'graphs', 'compare', 'pipelines', 'forks', \ - 'milestones', 'project_members', 'deploy_keys', 'builds', \ - 'hooks', 'services', 'protected_branches' - shortcut_handler = new ShortcutsNavigation() - - # If we haven't installed a custom shortcut handler, install the default one - if not shortcut_handler - new Shortcuts() - - initSearch: -> - - # Only when search form is present - new SearchAutocomplete() if $('.search').length diff --git a/app/assets/javascripts/merge_request_widget.js b/app/assets/javascripts/merge_request_widget.js index 7bbcdf59838..f9016949725 100644 --- a/app/assets/javascripts/merge_request_widget.js +++ b/app/assets/javascripts/merge_request_widget.js @@ -9,7 +9,15 @@ // merge_check_url - String, URL to use to check automerge status // ci_status_url - String, URL to use to check CI status // - this.opts = opts; + this.mergeRequestWidget = $('.mr-state-widget'); + this.mergeRequestWidgetBody = $('.mr-widget-body'); + this.opts = opts || $('.js-merge-request-widget-options').data(); + this.getInputs(); + this.getButtons(true); + if (this.opts.checkStatus) { + this.getMergeStatus(); + } + $('#modal_merge_info').modal({ show: false }); @@ -17,17 +25,49 @@ this.readyForCICheck = false; this.cancel = false; clearInterval(this.fetchBuildStatusInterval); + this.clearButtonEventListeners(); this.clearEventListeners(); + this.addButtonEventListeners(); this.addEventListeners(); this.getCIStatus(false); this.pollCIStatus(); notifyPermissions(); } + MergeRequestWidget.prototype.getInputs = function() { + this.acceptMergeRequestInput = $('.accept-mr-form :input'); + this.commitMessageInput = $('textarea[name=commit_message]'); + this.mergeWhenSucceedsInput = $('input[name=merge_when_build_succeeds]'); + this.removeSourceBranchInput = $('input[name=should_remove_source_branch]'); + this.shaInput = $('input[name=sha]'); + this.utfInput = $('input[name=utf8]'); + return this.authenticityTokenInput = $('input[name=authenticity_token]', this.mergeRequestWidget); + }; + + MergeRequestWidget.prototype.getButtons = function(skipListeners) { + this.dynamicMergeButton = $('.js-merge-button'); + this.acceptMergeRequestButton = $('.accept_merge_request'); + this.cancelMergeOnSuccessButton = $('.js-cancel-automatic-merge'); + this.mergeWhenSucceedsButton = $('.merge_when_build_succeeds'); + this.removeSourceBranchButton = $('.remove_source_branch'); + this.removeSourceBranchWhenMergedButton = $('.remove_source_branch_when_merged'); + if (!skipListeners) { + return this.addButtonEventListeners(); + } + }; + MergeRequestWidget.prototype.clearEventListeners = function() { return $(document).off('page:change.merge_request'); }; + MergeRequestWidget.prototype.clearButtonEventListeners = function() { + this.mergeWhenSucceedsButton.off('click'); + this.acceptMergeRequestButton.off('click'); + this.cancelMergeOnSuccessButton.off('click'); + this.removeSourceBranchButton.off('click'); + return this.removeSourceBranchWhenMergedButton.off('click'); + }; + MergeRequestWidget.prototype.cancelPolling = function() { return this.cancel = true; }; @@ -48,6 +88,36 @@ })(this)); }; + MergeRequestWidget.prototype.addButtonEventListeners = function() { + this.mergeWhenSucceedsButton.on('click', (function(_this) { + return function(e) { + _this.mergeWhenSucceedsInput.val('1'); + return _this.acceptMergeRequest(e); + }; + })(this)); + this.removeSourceBranchWhenMergedButton.on('click', (function(_this) { + return function(e) { + _this.mergeWhenSucceedsInput.val('1'); + return _this.acceptMergeRequest(e, _this.removeSourceBranchWhenMergedButton.data('url')); + }; + })(this)); + this.acceptMergeRequestButton.on('click', (function(_this) { + return function(e) { + return _this.acceptMergeRequest(e); + }; + })(this)); + this.cancelMergeOnSuccessButton.on('click', (function(_this) { + return function(e) { + return _this.cancelMergeOnSuccess(e); + }; + })(this)); + return this.removeSourceBranchButton.on('click', (function(_this) { + return function(e) { + return _this.removeSourceBranch(e); + }; + })(this)); + }; + MergeRequestWidget.prototype.mergeInProgress = function(deleteSourceBranch) { if (deleteSourceBranch == null) { deleteSourceBranch = false; @@ -55,30 +125,33 @@ return $.ajax({ type: 'GET', url: $('.merge-request').data('url'), + dataType: 'json', success: (function(_this) { return function(data) { - var callback, urlSuffix; + var urlSuffix; if (data.state === "merged") { urlSuffix = deleteSourceBranch ? '?deleted_source_branch=true' : ''; return window.location.href = window.location.pathname + urlSuffix; } else if (data.merge_error) { - return $('.mr-widget-body').html("<h4>" + data.merge_error + "</h4>"); + return _this.mergeRequestWidgetBody.html("<h4>" + data.merge_error + "</h4>"); } else { - callback = function() { - return merge_request_widget.mergeInProgress(deleteSourceBranch); - }; - return setTimeout(callback, 2000); + return setTimeout(function() { + return _this.mergeInProgress(deleteSourceBranch); + }, 2000); } }; - })(this), - dataType: 'json' + })(this) }); }; MergeRequestWidget.prototype.getMergeStatus = function() { - return $.get(this.opts.merge_check_url, function(data) { - return $('.mr-state-widget').replaceWith(data); - }); + return $.get(this.opts.mergeCheckUrl, (function(_this) { + return function(data) { + _this.mergeRequestWidget.replaceWith(data); + _this.getButtons(); + return _this.getInputs(); + }; + })(this)); }; MergeRequestWidget.prototype.ciLabelForStatus = function(status) { @@ -108,7 +181,7 @@ var _this; _this = this; $('.ci-widget-fetching').show(); - return $.getJSON(this.opts.ci_status_url, (function(_this) { + return $.getJSON(this.opts.ciStatusUrl, (function(_this) { return function(data) { var message, status, title; if (_this.cancel) { @@ -118,8 +191,8 @@ if (data.status === '') { return; } - if (_this.firstCICheck || data.status !== _this.opts.ci_status && (data.status != null)) { - _this.opts.ci_status = data.status; + if (_this.firstCICheck || data.status !== _this.opts.ciStatus && (data.status != null)) { + _this.opts.ciStatus = data.status; _this.showCIStatus(data.status); if (data.coverage) { _this.showCICoverage(data.coverage); @@ -129,19 +202,19 @@ if (showNotification && !_this.firstCICheck) { status = _this.ciLabelForStatus(data.status); if (status === "preparing") { - title = _this.opts.ci_title.preparing; + title = _this.opts.ciTitle.preparing; status = status.charAt(0).toUpperCase() + status.slice(1); - message = _this.opts.ci_message.preparing.replace('{{status}}', status); + message = _this.opts.ciMessage.preparing.replace('{{status}}', status); } else { - title = _this.opts.ci_title.normal; - message = _this.opts.ci_message.normal.replace('{{status}}', status); + title = _this.opts.ciTitle.normal; + message = _this.opts.ciMessage.normal.replace('{{status}}', status); } title = title.replace('{{status}}', status); message = message.replace('{{sha}}', data.sha); message = message.replace('{{title}}', data.title); - notify(title, message, _this.opts.gitlab_icon, function() { + notify(title, message, _this.opts.gitlabIcon, function() { this.close(); - return Turbolinks.visit(_this.opts.builds_path); + return Turbolinks.visit(_this.opts.buildsPath); }); } return _this.firstCICheck = false; @@ -186,6 +259,60 @@ return $('.js-merge-button,.accept-action .dropdown-toggle').removeClass('btn-danger btn-warning btn-create').addClass(css_class); }; + MergeRequestWidget.prototype.acceptMergeRequest = function(e, url) { + if (e) { + e.preventDefault(); + } + this.acceptMergeRequestInput.disable(); + this.dynamicMergeButton.html('<i class="fa fa-spinner fa-spin"></i> Merge in progress'); + return $.ajax({ + method: 'POST', + url: url || this.opts.mergePath, + data: { + utf8: this.utfInput.val(), + authenticity_token: this.authenticityTokenInput.val(), + sha: this.shaInput.val(), + commit_message: this.commitMessageInput.val(), + merge_when_build_succeeds: this.mergeWhenSucceedsInput.val(), + should_remove_source_branch: this.removeSourceBranchInput.is(':checked') ? this.removeSourceBranchInput.val() : void 0 + } + }).done((function(_this) { + return function(res) { + if (res.merge_in_progress != null) { + return _this.mergeInProgress(res.merge_in_progress); + } else { + _this.mergeRequestWidgetBody.html(res); + _this.getButtons(); + return _this.getInputs(); + } + }; + })(this)); + }; + + MergeRequestWidget.prototype.cancelMergeOnSuccess = function(e) { + if (e) { + e.preventDefault(); + } + return $.ajax({ + method: 'POST', + url: this.opts.cancelMergeOnSuccessPath + }).done((function(_this) { + return function(res) { + _this.mergeRequestWidgetBody.html(res); + _this.getButtons(); + return _this.getInputs(); + }; + })(this)); + }; + + MergeRequestWidget.prototype.removeSourceBranch = function(e) { + e.preventDefault(); + return $.ajax({ + method: 'DELETE', + url: this.opts.removePath + }); + }; + return MergeRequestWidget; })(); diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee deleted file mode 100644 index db8fda85ad3..00000000000 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ /dev/null @@ -1,233 +0,0 @@ -class @MergeRequestWidget - # Initialize MergeRequestWidget behavior - # - # checkEnable - Boolean, whether to check automerge status - # mergeCheckUrl - String, URL to use to check automerge status - # ciStatusUrl - String, URL to use to check CI status - # - - constructor: (opts) -> - @mergeRequestWidget = $('.mr-state-widget') - @mergeRequestWidgetBody = $('.mr-widget-body') - - @opts = opts || $('.js-merge-request-widget-options').data() - - @getInputs() - @getButtons true - - @getMergeStatus() if @opts.checkStatus - - $('#modal_merge_info').modal(show: false) - @firstCICheck = true - @readyForCICheck = false - @cancel = false - clearInterval @fetchBuildStatusInterval - - @clearButtonEventListeners() - @clearEventListeners() - @addButtonEventListeners() - @addEventListeners() - @getCIStatus(false) - @pollCIStatus() - notifyPermissions() - - getInputs: -> - @acceptMergeRequestInput = $('.accept-mr-form :input') - @commitMessageInput = $('textarea[name=commit_message]') - @mergeWhenSucceedsInput = $('input[name=merge_when_build_succeeds]') - @removeSourceBranchInput = $('input[name=should_remove_source_branch]') - @shaInput = $('input[name=sha]') - @utfInput = $('input[name=utf8]') - - @authenticityTokenInput = $('input[name=authenticity_token]', @mergeRequestWidget) - - getButtons: (skipListeners) -> - @dynamicMergeButton = $('.js-merge-button') - @acceptMergeRequestButton = $('.accept_merge_request') - @cancelMergeOnSuccessButton = $('.js-cancel-automatic-merge') - @mergeWhenSucceedsButton = $('.merge_when_build_succeeds') - @removeSourceBranchButton = $('.remove_source_branch') - @removeSourceBranchWhenMergedButton = $('.remove_source_branch_when_merged') - @addButtonEventListeners() unless skipListeners - - clearEventListeners: -> - $(document).off 'page:change.merge_request' - - clearButtonEventListeners: -> - @mergeWhenSucceedsButton.off 'click' - @acceptMergeRequestButton.off 'click' - @cancelMergeOnSuccessButton.off 'click' - @removeSourceBranchButton.off 'click' - @removeSourceBranchWhenMergedButton.off 'click' - - cancelPolling: -> - @cancel = true - - addEventListeners: -> - allowedPages = ['show', 'commits', 'builds', 'changes'] - $(document).on 'page:change.merge_request', => - page = $('body').data('page').split(':').last() - if allowedPages.indexOf(page) < 0 - clearInterval @fetchBuildStatusInterval - @cancelPolling() - @clearEventListeners() - - addButtonEventListeners: -> - @mergeWhenSucceedsButton.on 'click', (e) => - @mergeWhenSucceedsInput.val '1' - @acceptMergeRequest e - @removeSourceBranchWhenMergedButton.on 'click', (e) => - @mergeWhenSucceedsInput.val '1' - @acceptMergeRequest e, @removeSourceBranchWhenMergedButton.data 'url' - @acceptMergeRequestButton.on 'click', (e) => @acceptMergeRequest e - @cancelMergeOnSuccessButton.on 'click', (e) => @cancelMergeOnSuccess e - @removeSourceBranchButton.on 'click', (e) => @removeSourceBranch e - - mergeInProgress: (deleteSourceBranch = false) -> - $.ajax - type: 'GET' - url: $('.merge-request').data('url') - dataType: 'json' - success: (data) => - if data.state == "merged" - urlSuffix = if deleteSourceBranch then '?delete_source=true' else '' - - window.location.href = window.location.pathname + urlSuffix - else if data.merge_error - @mergeRequestWidgetBody.html("<h4>" + data.merge_error + "</h4>") - else - setTimeout => - @mergeInProgress(deleteSourceBranch) - , 2000 - - getMergeStatus: -> - $.get @opts.mergeCheckUrl, (data) => - @mergeRequestWidget.replaceWith(data) - @getButtons() - @getInputs() - - ciLabelForStatus: (status) -> - switch status - when 'success' - 'passed' - when 'success_with_warnings' - 'passed with warnings' - else - status - - pollCIStatus: -> - @fetchBuildStatusInterval = setInterval ( => - return if not @readyForCICheck - - @getCIStatus(true) - - @readyForCICheck = false - ), 10000 - - getCIStatus: (showNotification) -> - _this = @ - $('.ci-widget-fetching').show() - - $.getJSON @opts.ciStatusUrl, (data) => - return if @cancel - @readyForCICheck = true - - if data.status is '' - return - - if @firstCICheck || data.status isnt @opts.ciStatus and data.status? - @opts.ciStatus = data.status - @showCIStatus data.status - if data.coverage - @showCICoverage data.coverage - - # The first check should only update the UI, a notification - # should only be displayed on status changes - if showNotification and not @firstCICheck - status = @ciLabelForStatus(data.status) - - if status is "preparing" - title = @opts.ciTitle.preparing - status = status.charAt(0).toUpperCase() + status.slice(1) - message = @opts.ciMessage.preparing.replace('{{status}}', status) - else - title = @opts.ciTitle.normal - message = @opts.ciMessage.normal.replace('{{status}}', status) - - title = title.replace('{{status}}', status) - message = message.replace('{{sha}}', data.sha) - message = message.replace('{{title}}', data.title) - - notify( - title, - message, - @opts.gitlabIcon, - -> - @close() - Turbolinks.visit _this.opts.buildsPath - ) - @firstCICheck = false - - showCIStatus: (state) -> - return if not state? - $('.ci_widget').hide() - allowed_states = ["failed", "canceled", "running", "pending", "success", "success_with_warnings", "skipped", "not_found"] - if state in allowed_states - $('.ci_widget.ci-' + state).show() - switch state - when "failed", "canceled", "not_found" - @setMergeButtonClass('btn-danger') - when "running" - @setMergeButtonClass('btn-warning') - when "success", "success_with_warnings" - @setMergeButtonClass('btn-create') - else - $('.ci_widget.ci-error').show() - @setMergeButtonClass('btn-danger') - - showCICoverage: (coverage) -> - text = 'Coverage ' + coverage + '%' - $('.ci_widget:visible .ci-coverage').text(text) - - setMergeButtonClass: (css_class) -> - $('.js-merge-button,.accept-action .dropdown-toggle') - .removeClass('btn-danger btn-warning btn-create') - .addClass(css_class) - - acceptMergeRequest: (e, url) -> - e.preventDefault() if e - @acceptMergeRequestInput.disable() - @dynamicMergeButton.html '<i class="fa fa-spinner fa-spin"></i> Merge in progress' - $.ajax - method: 'POST' - url: url || @opts.mergePath - data: - utf8: @utfInput.val() - authenticity_token: @authenticityTokenInput.val() - sha: @shaInput.val() - commit_message: @commitMessageInput.val() - merge_when_build_succeeds: @mergeWhenSucceedsInput.val() - should_remove_source_branch: @removeSourceBranchInput.val() if @removeSourceBranchInput.is ':checked' - .done (res) => - if res.merge_in_progress? - @mergeInProgress res.merge_in_progress - else - @mergeRequestWidgetBody.html res - @getButtons() - @getInputs() - - cancelMergeOnSuccess: (e) -> - e.preventDefault() if e - $.ajax - method: 'POST' - url: @opts.cancelMergeOnSuccessPath - .done (res) => - @mergeRequestWidgetBody.html res - @getButtons() - @getInputs() - - removeSourceBranch: (e) -> - e.preventDefault() - $.ajax - method: 'DELETE', - url: @opts.removePath |