board.js 3.0 KB
Newer Older
1
/* eslint-disable comma-dangle, space-before-function-paren, one-var */
2 3 4
/* global Vue */
/* global Sortable */

5 6 7
require('./board_blank_state');
require('./board_delete');
require('./board_list');
8

P
Phil Hughes 已提交
9
(() => {
10 11
  const Store = gl.issueBoards.BoardsStore;

12 13 14 15
  window.gl = window.gl || {};
  window.gl.issueBoards = window.gl.issueBoards || {};

  gl.issueBoards.Board = Vue.extend({
16
    template: '#js-board-template',
17 18 19 20 21
    components: {
      'board-list': gl.issueBoards.BoardList,
      'board-delete': gl.issueBoards.BoardDelete,
      'board-blank-state': gl.issueBoards.BoardBlankState
    },
P
Phil Hughes 已提交
22
    props: {
23
      list: Object,
24
      disabled: Boolean,
25 26
      issueLinkBase: String,
      rootPath: String,
P
Phil Hughes 已提交
27
    },
P
Phil Hughes 已提交
28
    data () {
P
Phil Hughes 已提交
29
      return {
30
        detailIssue: Store.detail,
P
Phil Hughes 已提交
31
        filter: Store.filter,
P
Phil Hughes 已提交
32 33
      };
    },
P
Phil Hughes 已提交
34
    watch: {
P
Phil Hughes 已提交
35 36
      filter: {
        handler() {
37
          this.list.page = 1;
38
          this.list.getIssues(true);
P
Phil Hughes 已提交
39
        },
P
Phil Hughes 已提交
40
        deep: true,
41 42 43 44 45 46 47 48
      },
      detailIssue: {
        handler () {
          if (!Object.keys(this.detailIssue.issue).length) return;

          const issue = this.list.findIssue(this.detailIssue.issue.id);

          if (issue) {
P
Phil Hughes 已提交
49
            const offsetLeft = this.$el.offsetLeft;
50
            const boardsList = document.querySelectorAll('.boards-list')[0];
P
Phil Hughes 已提交
51 52
            const left = boardsList.scrollLeft - offsetLeft;
            let right = (offsetLeft + this.$el.offsetWidth);
53 54

            if (window.innerWidth > 768 && boardsList.classList.contains('is-compact')) {
P
Phil Hughes 已提交
55 56 57
              // -290 here because width of boardsList is animating so therefore
              // getting the width here is incorrect
              // 290 is the width of the sidebar
58 59 60 61
              right -= (boardsList.offsetWidth - 290);
            } else {
              right -= boardsList.offsetWidth;
            }
62 63

            if (right - boardsList.scrollLeft > 0) {
P
Phil Hughes 已提交
64 65
              $(boardsList).animate({
                scrollLeft: right
P
Phil Hughes 已提交
66
              }, this.sortableOptions.animation);
67
            } else if (left > 0) {
P
Phil Hughes 已提交
68
              $(boardsList).animate({
P
Phil Hughes 已提交
69 70
                scrollLeft: offsetLeft
              }, this.sortableOptions.animation);
71 72 73 74
            }
          }
        },
        deep: true
P
Phil Hughes 已提交
75 76
      }
    },
P
Phil Hughes 已提交
77 78
    methods: {
      showNewIssueForm() {
79
        this.$refs['board-list'].showIssueForm = !this.$refs['board-list'].showIssueForm;
P
Phil Hughes 已提交
80 81
      }
    },
F
Fatih Acet 已提交
82
    mounted () {
P
Phil Hughes 已提交
83
      this.sortableOptions = gl.issueBoards.getBoardSortableDefaultOptions({
84
        disabled: this.disabled,
P
Phil Hughes 已提交
85 86
        group: 'boards',
        draggable: '.is-draggable',
87
        handle: '.js-board-handle',
88
        onEnd: (e) => {
P
Phil Hughes 已提交
89
          gl.issueBoards.onEnd();
90 91

          if (e.newIndex !== undefined && e.oldIndex !== e.newIndex) {
92
            const order = this.sortable.toArray();
93
            const list = Store.findList('id', parseInt(e.item.dataset.id, 10));
94 95

            this.$nextTick(() => {
96
              Store.moveList(list, order);
97
            });
P
Phil Hughes 已提交
98
          }
P
Phil Hughes 已提交
99
        }
P
Phil Hughes 已提交
100
      });
101

P
Phil Hughes 已提交
102
      this.sortable = Sortable.create(this.$el.parentNode, this.sortableOptions);
P
Phil Hughes 已提交
103
    },
P
Phil Hughes 已提交
104
  });
P
Phil Hughes 已提交
105
})();