From da21119fe907f08aa746d212c6c32803dc769628 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 5 Aug 2016 18:39:49 +0100 Subject: [PATCH] Changed how the state is created when page is loaded Removed some un-used data --- .../javascripts/boards/boards_bundle.js.es6 | 4 +- .../boards/stores/boards_store.js.es6 | 37 ++++++++----------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/boards/boards_bundle.js.es6 b/app/assets/javascripts/boards/boards_bundle.js.es6 index ece53f0aad6..0d5ca81fe04 100644 --- a/app/assets/javascripts/boards/boards_bundle.js.es6 +++ b/app/assets/javascripts/boards/boards_bundle.js.es6 @@ -15,7 +15,6 @@ $(function () { if (gl.IssueBoardsApp) { gl.IssueBoardsApp.$destroy(true); - BoardsStore.reset(); } gl.IssueBoardsApp = new Vue({ @@ -23,6 +22,9 @@ $(function () { data: { state: BoardsStore.state }, + init: function () { + BoardsStore.create(); + }, ready: function () { gl.boardService.all() .then((resp) => { diff --git a/app/assets/javascripts/boards/stores/boards_store.js.es6 b/app/assets/javascripts/boards/stores/boards_store.js.es6 index 11826cbc108..abc64aef3d5 100644 --- a/app/assets/javascripts/boards/stores/boards_store.js.es6 +++ b/app/assets/javascripts/boards/stores/boards_store.js.es6 @@ -1,21 +1,13 @@ ((w) => { w.BoardsStore = { - state: { - lists: [], - filters: { + state: {}, + create: function () { + this.state.lists = []; + this.state.filters = { author_id: gl.utils.getParameterValues('author_id')[0], assignee_id: gl.utils.getParameterValues('assignee_id')[0], milestone_title: gl.utils.getParameterValues('milestone_title')[0], label_name: gl.utils.getParameterValues('label_name[]') - } - }, - reset: function () { - this.state.lists = []; - this.state.filters = { - author: {}, - assignee: {}, - milestone: {}, - label: [] }; }, new: function (board, persist = true) { @@ -26,7 +18,6 @@ if (persist) { list.save(); this.removeBlankState(); - this.addBlankState(); } return list; @@ -44,10 +35,9 @@ return addBlankState; }, addBlankState: function () { - if ($.cookie('issue_board_welcome_hidden') === 'true') return; + const addBlankState = this.shouldAddBlankState(); - const doneList = this.getDoneList(), - addBlankState = this.shouldAddBlankState(); + if (this.welcomeIsHidden()) return; if (addBlankState) { this.new({ @@ -59,13 +49,17 @@ } }, removeBlankState: function () { - if ($.cookie('issue_board_welcome_hidden') === 'true') return; + if (this.welcomeIsHidden()) return; + this.removeList('blank'); $.cookie('issue_board_welcome_hidden', 'true', { expires: 365 * 10 }); }, + welcomeIsHidden: function () { + return $.cookie('issue_board_welcome_hidden') === 'true'; + }, getDoneList: function () { return this.findList('type', 'done'); }, @@ -99,15 +93,14 @@ issueTo = listTo.findIssue(issueId); let issue = listFrom.findIssue(issueId); const issueLists = issue.getLists(), - issueLabels = issueLists.map(function (issue) { + listLabels = issueLists.map(function (issue) { return issue.label; }); + listFrom.removeIssue(issue); // Add to new lists issues if it doesn't already exist - if (issueTo) { - listTo.removeIssue(issueTo); - } else { + if (!issueTo) { listTo.addIssue(issue, listFrom); } @@ -115,7 +108,7 @@ issueLists.forEach((list) => { list.removeIssue(issue); }); - issue.removeLabels(issueLabels); + issue.removeLabels(listLabels); } }, findList: function (key, val) {