summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/merge_conflict_resolver.js.es6
blob: 77bffbcb403be6e4835ad33121ae1b81241f3084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//= require vue

class MergeConflictResolver {

  constructor() {
    this.dataProvider = new MergeConflictDataProvider()
    this.initVue()
  }


  initVue() {
    const that = this;
    this.vue   = new Vue({
      el       : '#conflicts',
      name     : 'MergeConflictResolver',
      data     : this.dataProvider.getInitialData(),
      created  : this.fetchData(),
      computed : this.setComputedProperties(),
      methods  : {
        handleSelected(sectionId, selection) {
          that.dataProvider.handleSelected(sectionId, selection);
        },
        handleViewTypeChange(newType) {
          that.dataProvider.updateViewType(newType);
        },
        commit() {
          that.commit();
        }
      }
    })
  }


  setComputedProperties() {
    const dp = this.dataProvider;

    return {
      conflictsCount() { return dp.getConflictsCount() },
      resolvedCount() { return dp.getResolvedCount() },
      readyToCommit() { return dp.isReadyToCommit() },
      commitButtonText() { return dp.getCommitButtonText() }
    }
  }


  fetchData() {
    const dp = this.dataProvider;

    $.get($('#conflicts').data('conflictsPath'))
      .done((data) => {
        dp.decorateData(this.vue, data);
      })
      .error((data) => {
        dp.handleFailedRequest(this.vue, data);
      })
      .always(() => {
        this.vue.isLoading = false;

        this.vue.$nextTick(() => {
          $('#conflicts .js-syntax-highlight').syntaxHighlight();
        });

        if (this.vue.diffViewType === 'parallel') {
          $('.content-wrapper .container-fluid').removeClass('container-limited');
        }
      })
  }


  commit() {
    this.vue.isSubmitting = true;

    $.post($('#conflicts').data('resolveConflictsPath'), this.dataProvider.getCommitData())
      .done((data) => {
        window.location.href = data.redirect_to;
      })
      .error(() => {
        new Flash('Something went wrong!');
      })
      .always(() => {
        this.vue.isSubmitting = false;
      });
  }

}