Commit e0d7d84c authored by Simon Knox's avatar Simon Knox

use milestone_select to select milestone

parent 9cc341e2
...@@ -59,7 +59,6 @@ ...@@ -59,7 +59,6 @@
<board-milestone-select <board-milestone-select
:board="board" :board="board"
:milestone-path="milestonePath" :milestone-path="milestonePath"
v-model="board.milestone_id"
title="Milestone" title="Milestone"
default-text="Any milestone" default-text="Any milestone"
:can-edit="canAdminBoard" :can-edit="canAdminBoard"
......
<script> <script>
/* global BoardService */ /* global BoardService, MilestoneSelect */
import loadingIcon from '~/vue_shared/components/loading_icon.vue'; import loadingIcon from '~/vue_shared/components/loading_icon.vue';
import extraMilestones from '../mixins/extra_milestones'; import extraMilestones from '../mixins/extra_milestones';
...@@ -14,10 +14,6 @@ export default { ...@@ -14,10 +14,6 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
value: {
type: Number,
required: false,
},
defaultText: { defaultText: {
type: String, type: String,
required: true, required: true,
...@@ -45,94 +41,107 @@ export default { ...@@ -45,94 +41,107 @@ export default {
}, },
computed: { computed: {
milestoneTitle() { milestoneTitle() {
return this.board.milestone ? this.board.milestone.title : this.defaultText; return this.board.milestone ? this.board.milestone.title : '';
}, },
}, },
methods: { methods: {
selectMilestone(milestone) { selectMilestone(milestone) {
this.$set(this.board, 'milestone', milestone); this.$set(this.board, 'milestone', milestone);
this.$emit('input', milestone.id);
this.close();
},
open() {
this.isOpen = true;
},
close() {
this.isOpen = false;
},
toggle() {
this.isOpen = !this.isOpen;
}, },
}, },
mounted() { mounted() {
this.$http.get(this.milestonePath) new MilestoneSelect(null, this.$refs.dropdownButton, {
.then(resp => resp.json()) handleClick: this.selectMilestone,
.then((data) => {
this.milestones = data;
this.loading = false;
})
.catch(() => {
this.loading = false;
}); });
}, },
}; };
</script> </script>
<template> <template>
<div class="dropdown milestone" :class="{ open: isOpen }"> <div class="block milestone">
<div class="title append-bottom-10"> <div class="title append-bottom-10">
{{ title }} Milestone
<a <a
v-if="canEdit" v-if="canEdit"
class="edit-link pull-right" class="edit-link pull-right"
href="#" href="#"
@click.prevent="toggle"
> >
Edit Edit
</a> </a>
</div> </div>
<div class="value">
<span
class="no-value"
v-if="!board.milestone"
>
None
</span>
<span
class="bold has-tooltip"
v-if="board.milestone"
>
{{ board.milestone.title }}
</span>
</div>
<div <div
class="dropdown-menu dropdown-menu-wide" class="selectbox"
style="display: none;"
> >
<ul <input
ref="list" :value="board.milestone.id"
name="milestone_id"
type="hidden"
v-if="board.milestone"
> >
<li <div class="dropdown">
v-for="milestone in extraMilestones" <button
:key="milestone.id" ref="dropdownButton"
:data-selected="milestoneTitle"
class="dropdown-menu-toggle wide"
:data-milestones="milestonePath"
:data-show-no="true"
:data-show-any="true"
:data-show-started="true"
:data-show-upcoming="true"
data-toggle="dropdown"
:data-use-id="true"
type="button"
> >
<a Milestone
href="#"
@click.prevent.stop="selectMilestone(milestone)">
<i <i
class="fa fa-check" aria-hidden="true"
v-if="milestone.id === value"></i> data-hidden="true"
{{ milestone.title }} class="fa fa-chevron-down"
</a> />
</li> </button>
<li class="divider"></li> <div class="dropdown-menu dropdown-select dropdown-menu-selectable">
<li v-if="loading"> <div
<loading-icon /> class="dropdown-input"
</li> >
<li <input
v-else type="search"
v-for="milestone in milestones" class="dropdown-input-field"
:key="milestone.id" placeholder="Search milestones"
class="dropdown-menu-item" autocomplete="off"
> >
<a
href="#"
@click.prevent.stop="selectMilestone(milestone)">
<i <i
class="fa fa-check" aria-hidden="true"
v-if="milestone.id === value"></i> data-hidden="true"
{{ milestone.title }} class="fa fa-search dropdown-input-search"
</a> />
</li> <i
</ul> role="button"
aria-hidden="true"
data-hidden="true"
class="fa fa-times dropdown-input-clear js-dropdown-input-clear"
/>
</div>
<div class="dropdown-content" />
<div class="dropdown-loading">
<loading-icon />
</div>
</div>
</div> </div>
<div class="value">
{{ milestoneTitle }}
</div> </div>
</div> </div>
</template> </template>
...@@ -5,7 +5,7 @@ import _ from 'underscore'; ...@@ -5,7 +5,7 @@ import _ from 'underscore';
(function() { (function() {
this.MilestoneSelect = (function() { this.MilestoneSelect = (function() {
function MilestoneSelect(currentProject, els) { function MilestoneSelect(currentProject, els, options = {}) {
var _this, $els; var _this, $els;
if (currentProject != null) { if (currentProject != null) {
_this = this; _this = this;
...@@ -158,18 +158,25 @@ import _ from 'underscore'; ...@@ -158,18 +158,25 @@ import _ from 'underscore';
}, },
isSelectable: function() { isSelectable: function() {
if ($('html').hasClass('issue-boards-page') && !$dropdown.hasClass('js-issue-board-sidebar') && if ($('html').hasClass('issue-boards-page') && !$dropdown.hasClass('js-issue-board-sidebar') &&
!$dropdown.closest('.add-issues-modal').length && gl.issueBoards.BoardsStore.state.currentBoard.milestone_id) { !$dropdown.closest('.add-issues-modal').length && gl.issueBoards.BoardsStore.state.currentBoard.milestone_id &&
!options.handleClick) {
return false; return false;
} }
return true; return true;
}, },
clicked: function(options) { clicked: function(clickEvent) {
const { $el, e } = options; const { $el, e } = clickEvent;
let selected = options.selectedObj; let selected = clickEvent.selectedObj;
var data, isIssueIndex, isMRIndex, isSelecting, page, boardsStore; var data, isIssueIndex, isMRIndex, isSelecting, page, boardsStore;
if (!selected) return; if (!selected) return;
if (options.handleClick) {
options.handleClick(selected);
return;
}
page = $('body').data('page'); page = $('body').data('page');
isIssueIndex = page === 'projects:issues:index'; isIssueIndex = page === 'projects:issues:index';
isMRIndex = (page === page && page === 'projects:merge_requests:index'); isMRIndex = (page === page && page === 'projects:merge_requests:index');
......
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