Commit 773da9b4 authored by Simon Knox's avatar Simon Knox

move filterpath setup to EE store

parent 67d01c10
...@@ -68,13 +68,7 @@ $(() => { ...@@ -68,13 +68,7 @@ $(() => {
rootPath: $boardApp.dataset.rootPath, rootPath: $boardApp.dataset.rootPath,
bulkUpdatePath: $boardApp.dataset.bulkUpdatePath, bulkUpdatePath: $boardApp.dataset.bulkUpdatePath,
detailIssue: Store.detail, detailIssue: Store.detail,
milestoneId: parseInt($boardApp.dataset.boardMilestoneId, 10),
milestoneTitle: $boardApp.dataset.boardMilestoneTitle,
weight: parseInt($boardApp.dataset.boardWeight, 10),
assigneeUsername: $boardApp.dataset.boardAssigneeUsername,
labels: JSON.parse($boardApp.dataset.labels || []),
defaultAvatar: $boardApp.dataset.defaultAvatar, defaultAvatar: $boardApp.dataset.defaultAvatar,
cantEdit: [],
}, },
computed: { computed: {
detailIssueVisible () { detailIssueVisible () {
...@@ -82,56 +76,6 @@ $(() => { ...@@ -82,56 +76,6 @@ $(() => {
}, },
}, },
created () { created () {
const updateFilterPath = (key, value) => {
if (!value) return;
const querystring = `${key}=${value}`;
Store.filter.path = [querystring].concat(
Store.filter.path.split('&').filter(param => param.match(new RegExp(`^${key}=(.*)$`, 'g')) === null)
).join('&');
};
if (this.milestoneId !== -1) {
let milestoneTitle = this.milestoneTitle;
if (this.milestoneId === 0) {
milestoneTitle = 'No+Milestone';
}
updateFilterPath('milestone_title', milestoneTitle);
this.cantEdit.push('milestone');
}
let weight = this.weight;
if (weight !== -1) {
if (weight === 0) {
weight = 'No+Weight';
}
updateFilterPath('weight', weight);
this.cantEdit.push('weight');
}
updateFilterPath('assignee_username', this.assigneeUsername);
if (this.assigneeUsername) {
this.cantEdit.push('assignee');
}
const filterPath = gl.issueBoards.BoardsStore.filter.path.split('&');
this.labels.forEach((label) => {
const labelTitle = encodeURIComponent(label.title);
const param = `label_name[]=${labelTitle}`;
const labelIndex = filterPath.indexOf(param);
if (labelIndex === -1) {
filterPath.push(param);
}
this.cantEdit.push({
name: 'label',
value: label.title,
});
});
Store.filter.path = filterPath.join('&');
Store.updateFiltersUrl(true);
gl.boardService = new BoardService({ gl.boardService = new BoardService({
boardsEndpoint: this.boardsEndpoint, boardsEndpoint: this.boardsEndpoint,
listsEndpoint: this.listsEndpoint, listsEndpoint: this.listsEndpoint,
...@@ -147,7 +91,7 @@ $(() => { ...@@ -147,7 +91,7 @@ $(() => {
eventHub.$off('updateTokens', this.updateTokens); eventHub.$off('updateTokens', this.updateTokens);
}, },
mounted () { mounted () {
this.filterManager = new FilteredSearchBoards(Store.filter, true, this.cantEdit); this.filterManager = new FilteredSearchBoards(Store.filter, true, Store.cantEdit);
this.filterManager.setup(); this.filterManager.setup();
Store.disabled = this.disabled; Store.disabled = this.disabled;
......
...@@ -11,6 +11,68 @@ class BoardsStoreEE { ...@@ -11,6 +11,68 @@ class BoardsStoreEE {
this.store.removePromotionState = () => { this.store.removePromotionState = () => {
this.removePromotion(); this.removePromotion();
}; };
this.store.boardConfig = {
milestoneId: parseInt(this.$boardApp.dataset.boardMilestoneId, 10),
milestoneTitle: this.$boardApp.dataset.boardMilestoneTitle,
assigneeUsername: this.$boardApp.dataset.boardAssigneeUsername,
labels: JSON.parse(this.$boardApp.dataset.labels || []),
weight: parseInt(this.$boardApp.dataset.boardWeight, 10),
};
this.store.cantEdit = [];
this.initBoardFilters();
}
initBoardFilters() {
const updateFilterPath = (key, value) => {
if (!value) return;
const querystring = `${key}=${value}`;
this.store.filter.path = [querystring].concat(
this.store.filter.path.split('&').filter(param => param.match(new RegExp(`^${key}=(.*)$`, 'g')) === null)
).join('&');
};
let milestoneTitle = this.store.boardConfig.milestoneTitle;
if (this.store.boardConfig.milestoneId !== -1) {
if (this.store.boardConfig.milestoneId === 0) {
milestoneTitle = 'No+Milestone';
}
updateFilterPath('milestone_title', milestoneTitle);
this.store.cantEdit.push('milestone');
}
let weight = this.store.boardConfig.weight;
if (weight !== -1) {
if (weight === 0) {
weight = 'No+Weight';
}
updateFilterPath('weight', weight);
this.store.cantEdit.push('weight');
}
updateFilterPath('assignee_username', this.store.boardConfig.assigneeUsername);
if (this.store.boardConfig.assigneeUsername) {
this.store.cantEdit.push('assignee');
}
const filterPath = this.store.filter.path.split('&');
this.store.boardConfig.labels.forEach((label) => {
const labelTitle = encodeURIComponent(label.title);
const param = `label_name[]=${labelTitle}`;
const labelIndex = filterPath.indexOf(param);
if (labelIndex === -1) {
filterPath.push(param);
}
this.store.cantEdit.push({
name: 'label',
value: label.title,
});
});
this.store.filter.path = filterPath.join('&');
this.store.updateFiltersUrl(true);
} }
shouldAddPromotionState() { shouldAddPromotionState() {
......
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