Commit acd86c12 authored by Phil Hughes's avatar Phil Hughes Committed by Fatih Acet

Search bar now returns data

Selected data is added into a different array
parent 38d84c13
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
}, },
addIssues() { addIssues() {
const list = this.store.selectedList; const list = this.store.selectedList;
const issueIds = this.store.issues.filter(issue => issue.selected).map(issue => issue.id); const issueIds = this.store.selectedIssues.map(issue => issue.id);
// Post the data to the backend // Post the data to the backend
gl.boardService.addMultipleIssues(list, issueIds); gl.boardService.addMultipleIssues(list, issueIds);
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
<modal-dismiss></modal-dismiss> <modal-dismiss></modal-dismiss>
</h2> </h2>
</header> </header>
<modal-tabs v-if="issues.length"></modal-tabs> <modal-tabs v-if="!loading"></modal-tabs>
<modal-search v-if="issues.length"></modal-search> <modal-search v-if="!loading"></modal-search>
</div> </div>
`, `,
}); });
......
...@@ -22,9 +22,7 @@ ...@@ -22,9 +22,7 @@
issues: { issues: {
handler() { handler() {
this.$nextTick(() => { this.$nextTick(() => {
if (this.activeTab === 'selected') {
listMasonry.layout(); listMasonry.layout();
}
}); });
}, },
deep: true, deep: true,
...@@ -37,12 +35,26 @@ ...@@ -37,12 +35,26 @@
selectedCount() { selectedCount() {
return Store.modalSelectedCount(); return Store.modalSelectedCount();
}, },
loopIssues() {
if (this.activeTab === 'all') {
return this.issues;
}
return this.selectedIssues;
},
}, },
methods: { methods: {
toggleIssue(issueObj) { toggleIssue(issueObj) {
const issue = issueObj; const issue = issueObj;
issue.selected = !issue.selected; issue.selected = !issue.selected;
if (issue.selected) {
this.selectedIssues.push(issue);
} else {
// Remove this issue
const index = this.selectedIssues.indexOf(issue);
this.selectedIssues.splice(index, 1);
}
}, },
showIssue(issue) { showIssue(issue) {
if (this.activeTab === 'all') return true; if (this.activeTab === 'all') return true;
...@@ -64,7 +76,6 @@ ...@@ -64,7 +76,6 @@
this.initMasonry(); this.initMasonry();
}, },
destroyed() { destroyed() {
this.issues = [];
this.destroyMasonry(); this.destroyMasonry();
}, },
components: { components: {
...@@ -77,7 +88,7 @@ ...@@ -77,7 +88,7 @@
ref="list" ref="list"
v-show="!loading"> v-show="!loading">
<div <div
v-for="issue in issues" v-for="issue in loopIssues"
v-if="showIssue(issue)" v-if="showIssue(issue)"
class="card-parent"> class="card-parent">
<div <div
......
...@@ -12,16 +12,41 @@ ...@@ -12,16 +12,41 @@
data() { data() {
return Store.modal; return Store.modal;
}, },
watch: {
searchTerm() {
this.searchOperation();
},
},
mounted() { mounted() {
gl.boardService.getBacklog() this.loading = true;
.then((res) => {
this.loadIssues()
.then(() => {
this.loading = false;
});
},
methods: {
searchOperation: _.debounce(function() {
this.loadIssues();
}, 500),
loadIssues() {
return gl.boardService.getBacklog({
search: this.searchTerm,
}).then((res) => {
const data = res.json(); const data = res.json();
this.issues = [];
data.forEach((issueObj) => { data.forEach((issueObj) => {
this.issues.push(new ListIssue(issueObj)); const issue = new ListIssue(issueObj);
const foundSelectedIssue = this.selectedIssues
.filter(filteredIssue => filteredIssue.id === issue.id)[0];
issue.selected = foundSelectedIssue !== undefined;
this.issues.push(issue);
}); });
}); });
}, },
},
components: { components: {
'modal-header': gl.issueBoards.IssuesModalHeader, 'modal-header': gl.issueBoards.IssuesModalHeader,
'modal-list': gl.issueBoards.ModalList, 'modal-list': gl.issueBoards.ModalList,
...@@ -33,10 +58,10 @@ ...@@ -33,10 +58,10 @@
v-if="showAddIssuesModal"> v-if="showAddIssuesModal">
<div class="add-issues-container"> <div class="add-issues-container">
<modal-header></modal-header> <modal-header></modal-header>
<modal-list v-if="issues.length"></modal-list> <modal-list v-if="!loading"></modal-list>
<section <section
class="add-issues-list" class="add-issues-list"
v-if="issues.length == 0"> v-if="loading">
<div class="add-issues-list-loading"> <div class="add-issues-list-loading">
<i class="fa fa-spinner fa-spin"></i> <i class="fa fa-spinner fa-spin"></i>
</div> </div>
......
...@@ -24,7 +24,17 @@ ...@@ -24,7 +24,17 @@
this.issues.forEach((issue) => { this.issues.forEach((issue) => {
const issueUpdate = issue; const issueUpdate = issue;
if (issueUpdate.selected !== select) {
issueUpdate.selected = select; issueUpdate.selected = select;
if (select) {
this.selectedIssues.push(issueUpdate);
} else {
const index = this.selectedIssues.indexOf(issue);
this.selectedIssues.splice(index, 1);
}
}
}); });
}, },
}, },
...@@ -35,7 +45,8 @@ ...@@ -35,7 +45,8 @@
<input <input
placeholder="Search issues..." placeholder="Search issues..."
class="form-control" class="form-control"
type="search" /> type="search"
v-model="searchTerm" />
<button <button
type="button" type="button"
class="btn btn-success btn-inverted" class="btn btn-success btn-inverted"
......
...@@ -76,8 +76,8 @@ class BoardService { ...@@ -76,8 +76,8 @@ class BoardService {
}); });
} }
getBacklog() { getBacklog(data) {
return this.boards.backlog(); return this.boards.backlog(data);
} }
addMultipleIssues(list, issue_ids) { addMultipleIssues(list, issue_ids) {
......
...@@ -14,9 +14,12 @@ ...@@ -14,9 +14,12 @@
}, },
modal: { modal: {
issues: [], issues: [],
selectedIssues: [],
showAddIssuesModal: false, showAddIssuesModal: false,
activeTab: 'all', activeTab: 'all',
selectedList: {} selectedList: {},
searchTerm: '',
loading: false,
}, },
moving: { moving: {
issue: {}, issue: {},
...@@ -40,15 +43,10 @@ ...@@ -40,15 +43,10 @@
}, },
new (listObj) { new (listObj) {
const list = this.addList(listObj); const list = this.addList(listObj);
const backlogList = this.findList('type', 'backlog', 'backlog');
list list
.save() .save()
.then(() => { .then(() => {
// Remove any new issues from the backlog
// as they will be visible in the new list
list.issues.forEach(backlogList.removeIssue.bind(backlogList));
this.state.lists = _.sortBy(this.state.lists, 'position'); this.state.lists = _.sortBy(this.state.lists, 'position');
}); });
this.removeBlankState(); this.removeBlankState();
...@@ -58,7 +56,7 @@ ...@@ -58,7 +56,7 @@
}, },
shouldAddBlankState () { shouldAddBlankState () {
// Decide whether to add the blank state // Decide whether to add the blank state
return !(this.state.lists.filter(list => list.type !== 'backlog' && list.type !== 'done')[0]); return !(this.state.lists.filter(list => list.type !== 'done')[0]);
}, },
addBlankState () { addBlankState () {
if (!this.shouldAddBlankState() || this.welcomeIsHidden() || this.disabled) return; if (!this.shouldAddBlankState() || this.welcomeIsHidden() || this.disabled) return;
...@@ -108,7 +106,7 @@ ...@@ -108,7 +106,7 @@
listTo.addIssue(issue, listFrom, newIndex); listTo.addIssue(issue, listFrom, newIndex);
} }
if (listTo.type === 'done' && listFrom.type !== 'backlog') { if (listTo.type === 'done') {
issueLists.forEach((list) => { issueLists.forEach((list) => {
list.removeIssue(issue); list.removeIssue(issue);
}); });
...@@ -128,15 +126,7 @@ ...@@ -128,15 +126,7 @@
history.pushState(null, null, `?${$.param(this.state.filters)}`); history.pushState(null, null, `?${$.param(this.state.filters)}`);
}, },
modalSelectedCount() { modalSelectedCount() {
let count = 0; return this.modal.selectedIssues.length;
this.modal.issues.forEach((issue) => {
if (issue.selected) {
count += 1;
}
});
return count;
}, },
}; };
})(); })();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment