BigW Consortium Gitlab

board_blank_state.js 2.34 KB
Newer Older
1
/* global ListLabel */
2

3
import _ from 'underscore';
4 5
import Cookies from 'js-cookie';

6
const Store = gl.issueBoards.BoardsStore;
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
export default {
  template: `
    <div class="board-blank-state">
      <p>
        Add the following default lists to your Issue Board with one click:
      </p>
      <ul class="board-blank-state-list">
        <li v-for="label in predefinedLabels">
          <span
            class="label-color"
            :style="{ backgroundColor: label.color }">
          </span>
          {{ label.title }}
        </li>
      </ul>
      <p>
        Starting out with the default set of lists will get you right on the way to making the most of your board.
      </p>
      <button
        class="btn btn-create btn-inverted btn-block"
        type="button"
        @click.stop="addDefaultLists">
        Add default lists
      </button>
      <button
        class="btn btn-default btn-block"
        type="button"
        @click.stop="clearBlankState">
        Nevermind, I'll use my own
      </button>
    </div>
  `,
  data() {
    return {
      predefinedLabels: [
        new ListLabel({ title: 'To Do', color: '#F0AD4E' }),
        new ListLabel({ title: 'Doing', color: '#5CB85C' }),
      ],
    };
  },
  methods: {
    addDefaultLists() {
      this.clearBlankState();
51

52 53 54 55 56 57
      this.predefinedLabels.forEach((label, i) => {
        Store.addList({
          title: label.title,
          position: i,
          list_type: 'label',
          label: {
58
            title: label.title,
59 60
            color: label.color,
          },
61
        });
62
      });
63

64
      Store.state.lists = _.sortBy(Store.state.lists, 'position');
65

66 67
      // Save the labels
      gl.boardService.generateDefaultLists()
Eric Eastwood committed
68
        .then(res => res.data)
Filipa Lacerda committed
69 70
        .then((data) => {
          data.forEach((listObj) => {
71
            const list = Store.findList('title', listObj.title);
Phil Hughes committed
72

73 74
            list.id = listObj.id;
            list.label.id = listObj.label.id;
75 76 77 78
            list.getIssues()
              .catch(() => {
                // TODO: handle request error
              });
79
          });
80 81 82 83 84 85 86
        })
        .catch(() => {
          Store.removeList(undefined, 'label');
          Cookies.remove('issue_board_welcome_hidden', {
            path: '',
          });
          Store.addBlankState();
87 88 89 90 91
        });
    },
    clearBlankState: Store.removeBlankState.bind(Store),
  },
};