Commit b05a67f4e3fdf94477539d61bff6d74337d2ddef
1 parent
8a55636f
Exists in
spb-stable
and in
3 other branches
Split merge request coffee
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
2 changed files
with
103 additions
and
96 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,103 @@ |
| 1 | +class MergeRequest | |
| 2 | + constructor: (@opts) -> | |
| 3 | + @initContextWidget() | |
| 4 | + this.$el = $('.merge-request') | |
| 5 | + @diffs_loaded = if @opts.action == 'diffs' then true else false | |
| 6 | + @commits_loaded = false | |
| 7 | + | |
| 8 | + this.activateTab(@opts.action) | |
| 9 | + | |
| 10 | + this.bindEvents() | |
| 11 | + | |
| 12 | + this.initMergeWidget() | |
| 13 | + this.$('.show-all-commits').on 'click', => | |
| 14 | + this.showAllCommits() | |
| 15 | + | |
| 16 | + modal = $('#modal_merge_info').modal(show: false) | |
| 17 | + | |
| 18 | + disableButtonIfEmptyField '#merge_commit_message', '.accept_merge_request' | |
| 19 | + | |
| 20 | + | |
| 21 | + # Local jQuery finder | |
| 22 | + $: (selector) -> | |
| 23 | + this.$el.find(selector) | |
| 24 | + | |
| 25 | + initContextWidget: -> | |
| 26 | + $('.edit-merge_request.inline-update input[type="submit"]').hide() | |
| 27 | + $(".issue-box .inline-update").on "change", "select", -> | |
| 28 | + $(this).submit() | |
| 29 | + $(".issue-box .inline-update").on "change", "#merge_request_assignee_id", -> | |
| 30 | + $(this).submit() | |
| 31 | + | |
| 32 | + initMergeWidget: -> | |
| 33 | + this.showState( @opts.current_status ) | |
| 34 | + | |
| 35 | + if this.$('.automerge_widget').length and @opts.check_enable | |
| 36 | + $.get @opts.url_to_automerge_check, (data) => | |
| 37 | + this.showState( data.merge_status ) | |
| 38 | + , 'json' | |
| 39 | + | |
| 40 | + if @opts.ci_enable | |
| 41 | + $.get @opts.url_to_ci_check, (data) => | |
| 42 | + this.showCiState data.status | |
| 43 | + , 'json' | |
| 44 | + | |
| 45 | + bindEvents: -> | |
| 46 | + this.$('.nav-tabs').on 'click', 'a', (event) => | |
| 47 | + a = $(event.currentTarget) | |
| 48 | + | |
| 49 | + href = a.attr('href') | |
| 50 | + History.replaceState {path: href}, document.title, href | |
| 51 | + | |
| 52 | + event.preventDefault() | |
| 53 | + | |
| 54 | + this.$('.nav-tabs').on 'click', 'li', (event) => | |
| 55 | + this.activateTab($(event.currentTarget).data('action')) | |
| 56 | + | |
| 57 | + this.$('.accept_merge_request').on 'click', -> | |
| 58 | + $('.automerge_widget.can_be_merged').hide() | |
| 59 | + $('.merge-in-progress').show() | |
| 60 | + | |
| 61 | + activateTab: (action) -> | |
| 62 | + this.$('.nav-tabs li').removeClass 'active' | |
| 63 | + this.$('.tab-content').hide() | |
| 64 | + switch action | |
| 65 | + when 'diffs' | |
| 66 | + this.$('.nav-tabs .diffs-tab').addClass 'active' | |
| 67 | + this.loadDiff() unless @diffs_loaded | |
| 68 | + this.$('.diffs').show() | |
| 69 | + else | |
| 70 | + this.$('.nav-tabs .notes-tab').addClass 'active' | |
| 71 | + this.$('.notes').show() | |
| 72 | + | |
| 73 | + showState: (state) -> | |
| 74 | + $('.automerge_widget').hide() | |
| 75 | + $('.automerge_widget.' + state).show() | |
| 76 | + | |
| 77 | + showCiState: (state) -> | |
| 78 | + $('.ci_widget').hide() | |
| 79 | + $('.ci_widget.ci-' + state).show() | |
| 80 | + | |
| 81 | + loadDiff: (event) -> | |
| 82 | + $.ajax | |
| 83 | + type: 'GET' | |
| 84 | + url: this.$('.nav-tabs .diffs-tab a').attr('href') | |
| 85 | + beforeSend: => | |
| 86 | + this.$('.status').addClass 'loading' | |
| 87 | + complete: => | |
| 88 | + @diffs_loaded = true | |
| 89 | + this.$('.status').removeClass 'loading' | |
| 90 | + success: (data) => | |
| 91 | + this.$(".diffs").html(data.html) | |
| 92 | + dataType: 'json' | |
| 93 | + | |
| 94 | + showAllCommits: -> | |
| 95 | + this.$('.first-commits').remove() | |
| 96 | + this.$('.all-commits').removeClass 'hide' | |
| 97 | + | |
| 98 | + alreadyOrCannotBeMerged: -> | |
| 99 | + this.$('.automerge_widget').hide() | |
| 100 | + this.$('.merge-in-progress').hide() | |
| 101 | + this.$('.automerge_widget.already_cannot_be_merged').show() | |
| 102 | + | |
| 103 | +this.MergeRequest = MergeRequest | ... | ... |
app/assets/javascripts/merge_requests.js.coffee
| ... | ... | @@ -6,99 +6,3 @@ |
| 6 | 6 | $('#milestone_id').select2() |
| 7 | 7 | $('#milestone_id, #assignee_id').on 'change', -> |
| 8 | 8 | $(this).closest('form').submit() |
| 9 | - | |
| 10 | -class MergeRequest | |
| 11 | - | |
| 12 | - constructor: (@opts) -> | |
| 13 | - this.$el = $('.merge-request') | |
| 14 | - @diffs_loaded = if @opts.action == 'diffs' then true else false | |
| 15 | - @commits_loaded = false | |
| 16 | - | |
| 17 | - this.activateTab(@opts.action) | |
| 18 | - | |
| 19 | - this.bindEvents() | |
| 20 | - | |
| 21 | - this.initMergeWidget() | |
| 22 | - this.$('.show-all-commits').on 'click', => | |
| 23 | - this.showAllCommits() | |
| 24 | - | |
| 25 | - modal = $('#modal_merge_info').modal(show: false) | |
| 26 | - | |
| 27 | - disableButtonIfEmptyField '#merge_commit_message', '.accept_merge_request' | |
| 28 | - | |
| 29 | - # Local jQuery finder | |
| 30 | - $: (selector) -> | |
| 31 | - this.$el.find(selector) | |
| 32 | - | |
| 33 | - initMergeWidget: -> | |
| 34 | - this.showState( @opts.current_status ) | |
| 35 | - | |
| 36 | - if this.$('.automerge_widget').length and @opts.check_enable | |
| 37 | - $.get @opts.url_to_automerge_check, (data) => | |
| 38 | - this.showState( data.merge_status ) | |
| 39 | - , 'json' | |
| 40 | - | |
| 41 | - if @opts.ci_enable | |
| 42 | - $.get @opts.url_to_ci_check, (data) => | |
| 43 | - this.showCiState data.status | |
| 44 | - , 'json' | |
| 45 | - | |
| 46 | - bindEvents: -> | |
| 47 | - this.$('.nav-tabs').on 'click', 'a', (event) => | |
| 48 | - a = $(event.currentTarget) | |
| 49 | - | |
| 50 | - href = a.attr('href') | |
| 51 | - History.replaceState {path: href}, document.title, href | |
| 52 | - | |
| 53 | - event.preventDefault() | |
| 54 | - | |
| 55 | - this.$('.nav-tabs').on 'click', 'li', (event) => | |
| 56 | - this.activateTab($(event.currentTarget).data('action')) | |
| 57 | - | |
| 58 | - this.$('.accept_merge_request').on 'click', -> | |
| 59 | - $('.automerge_widget.can_be_merged').hide() | |
| 60 | - $('.merge-in-progress').show() | |
| 61 | - | |
| 62 | - activateTab: (action) -> | |
| 63 | - this.$('.nav-tabs li').removeClass 'active' | |
| 64 | - this.$('.tab-content').hide() | |
| 65 | - switch action | |
| 66 | - when 'diffs' | |
| 67 | - this.$('.nav-tabs .diffs-tab').addClass 'active' | |
| 68 | - this.loadDiff() unless @diffs_loaded | |
| 69 | - this.$('.diffs').show() | |
| 70 | - else | |
| 71 | - this.$('.nav-tabs .notes-tab').addClass 'active' | |
| 72 | - this.$('.notes').show() | |
| 73 | - | |
| 74 | - showState: (state) -> | |
| 75 | - $('.automerge_widget').hide() | |
| 76 | - $('.automerge_widget.' + state).show() | |
| 77 | - | |
| 78 | - showCiState: (state) -> | |
| 79 | - $('.ci_widget').hide() | |
| 80 | - $('.ci_widget.ci-' + state).show() | |
| 81 | - | |
| 82 | - loadDiff: (event) -> | |
| 83 | - $.ajax | |
| 84 | - type: 'GET' | |
| 85 | - url: this.$('.nav-tabs .diffs-tab a').attr('href') | |
| 86 | - beforeSend: => | |
| 87 | - this.$('.status').addClass 'loading' | |
| 88 | - complete: => | |
| 89 | - @diffs_loaded = true | |
| 90 | - this.$('.status').removeClass 'loading' | |
| 91 | - success: (data) => | |
| 92 | - this.$(".diffs").html(data.html) | |
| 93 | - dataType: 'json' | |
| 94 | - | |
| 95 | - showAllCommits: -> | |
| 96 | - this.$('.first-commits').remove() | |
| 97 | - this.$('.all-commits').removeClass 'hide' | |
| 98 | - | |
| 99 | - alreadyOrCannotBeMerged: -> | |
| 100 | - this.$('.automerge_widget').hide() | |
| 101 | - this.$('.merge-in-progress').hide() | |
| 102 | - this.$('.automerge_widget.already_cannot_be_merged').show() | |
| 103 | - | |
| 104 | -this.MergeRequest = MergeRequest | ... | ... |