list.js.es6 2.1 KB
Newer Older
P
Phil Hughes 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/* global Vue */
/* global ListIssue */
(() => {
  const Store = gl.issueBoards.BoardsStore;

  window.gl = window.gl || {};
  window.gl.issueBoards = window.gl.issueBoards || {};

  gl.issueBoards.ModalList = Vue.extend({
    data() {
      return Store.modal;
    },
P
Phil Hughes 已提交
13 14 15 16 17 18 19 20
    watch: {
      activeTab() {
        this.$nextTick(() => {
          this.destroyMasonry();
          this.initMasonry();
        });
      },
    },
P
Phil Hughes 已提交
21 22 23 24 25
    computed: {
      loading() {
        return this.issues.length === 0;
      },
    },
P
Phil Hughes 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    methods: {
      toggleIssue(issue) {
        issue.selected = !issue.selected;
      },
      showIssue(issue) {
        if (this.activeTab === 'all') return true;

        return issue.selected;
      },
      initMasonry() {
        listMasonry = new Masonry(this.$refs.list, {
          transitionDuration: 0,
        });
      },
      destroyMasonry() {
        if (listMasonry) {
          listMasonry.destroy();
        }
      }
    },
P
Phil Hughes 已提交
46 47 48 49 50 51 52 53
    mounted() {
      gl.boardService.getBacklog()
        .then((res) => {
          const data = res.json();

          data.forEach((issueObj) => {
            this.issues.push(new ListIssue(issueObj));
          });
P
Phil Hughes 已提交
54 55 56 57

          this.$nextTick(() => {
            this.initMasonry();
          });
P
Phil Hughes 已提交
58 59
        });
    },
P
Phil Hughes 已提交
60 61 62 63
    destroyed() {
      this.issues = [];
      this.destroyMasonry();
    },
P
Phil Hughes 已提交
64 65 66 67 68 69 70 71
    components: {
      'issue-card-inner': gl.issueBoards.IssueCardInner,
    },
    template: `
      <section class="add-issues-list">
        <i
          class="fa fa-spinner fa-spin"
          v-if="loading"></i>
P
Phil Hughes 已提交
72
        <div
P
Phil Hughes 已提交
73
          class="add-issues-list-columns list-unstyled"
P
Phil Hughes 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
          ref="list"
          v-show="!loading">
          <div
            v-for="issue in issues"
            v-if="showIssue(issue)"
            class="card-parent">
            <div
              class="card"
              :class="{ 'is-active': issue.selected }"
              @click="toggleIssue(issue)">
              <issue-card-inner
                :issue="issue"
                :issue-link-base="'/'">
              </issue-card-inner>
            </div>
          </div>
        </div>
P
Phil Hughes 已提交
91 92 93 94
      </section>
    `,
  });
})();