2018-02-06 09:44:38 -05:00
|
|
|
<script>
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-11-16 14:29:11 -05:00
|
|
|
import { GlButton } from '@gitlab/ui';
|
2019-04-29 07:06:13 -04:00
|
|
|
import { getMilestone } from 'ee_else_ce/boards/boards_util';
|
2017-03-15 05:18:05 -04:00
|
|
|
import eventHub from '../eventhub';
|
2018-02-19 14:06:16 -05:00
|
|
|
import ProjectSelect from './project_select.vue';
|
2018-02-06 09:44:38 -05:00
|
|
|
import ListIssue from '../models/issue';
|
2018-10-10 13:08:43 -04:00
|
|
|
import boardsStore from '../stores/boards_store';
|
2017-02-28 05:23:19 -05:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'BoardNewIssue',
|
2018-02-19 14:06:16 -05:00
|
|
|
components: {
|
|
|
|
ProjectSelect,
|
2018-10-29 19:16:10 -04:00
|
|
|
GlButton,
|
2018-02-19 14:06:16 -05:00
|
|
|
},
|
2017-02-28 05:23:19 -05:00
|
|
|
props: {
|
2018-02-19 14:06:16 -05:00
|
|
|
groupId: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: 0,
|
|
|
|
},
|
2017-09-06 01:02:30 -04:00
|
|
|
list: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2017-02-28 05:23:19 -05:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
title: '',
|
|
|
|
error: false,
|
2018-02-19 14:06:16 -05:00
|
|
|
selectedProject: {},
|
2017-02-28 05:23:19 -05:00
|
|
|
};
|
|
|
|
},
|
2018-02-19 14:06:16 -05:00
|
|
|
computed: {
|
|
|
|
disabled() {
|
|
|
|
if (this.groupId) {
|
|
|
|
return this.title === '' || !this.selectedProject.name;
|
|
|
|
}
|
|
|
|
return this.title === '';
|
|
|
|
},
|
|
|
|
},
|
2018-02-06 09:44:38 -05:00
|
|
|
mounted() {
|
|
|
|
this.$refs.input.focus();
|
2018-02-19 14:06:16 -05:00
|
|
|
eventHub.$on('setSelectedProject', this.setSelectedProject);
|
2018-02-06 09:44:38 -05:00
|
|
|
},
|
2017-02-28 05:23:19 -05:00
|
|
|
methods: {
|
|
|
|
submit(e) {
|
|
|
|
e.preventDefault();
|
2017-06-23 05:28:19 -04:00
|
|
|
if (this.title.trim() === '') return Promise.resolve();
|
2017-02-28 05:23:19 -05:00
|
|
|
|
|
|
|
this.error = false;
|
|
|
|
|
|
|
|
const labels = this.list.label ? [this.list.label] : [];
|
2018-06-07 16:54:24 -04:00
|
|
|
const assignees = this.list.assignee ? [this.list.assignee] : [];
|
2019-04-29 07:06:13 -04:00
|
|
|
const milestone = getMilestone(this.list);
|
|
|
|
|
2017-02-28 05:23:19 -05:00
|
|
|
const issue = new ListIssue({
|
|
|
|
title: this.title,
|
|
|
|
labels,
|
|
|
|
subscribed: true,
|
2018-06-07 16:54:24 -04:00
|
|
|
assignees,
|
2019-04-29 07:06:13 -04:00
|
|
|
milestone,
|
2018-02-19 14:06:16 -05:00
|
|
|
project_id: this.selectedProject.id,
|
2017-02-28 05:23:19 -05:00
|
|
|
});
|
|
|
|
|
2017-06-23 05:28:19 -04:00
|
|
|
eventHub.$emit(`scroll-board-list-${this.list.id}`);
|
|
|
|
this.cancel();
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
return this.list
|
|
|
|
.newIssue(issue)
|
2017-02-28 05:23:19 -05:00
|
|
|
.then(() => {
|
|
|
|
// Need this because our jQuery very kindly disables buttons on ALL form submissions
|
|
|
|
$(this.$refs.submitButton).enable();
|
|
|
|
|
2019-06-04 11:34:17 -04:00
|
|
|
boardsStore.setIssueDetail(issue);
|
2019-06-05 08:44:29 -04:00
|
|
|
boardsStore.setListDetail(this.list);
|
2017-02-28 05:23:19 -05:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
// Need this because our jQuery very kindly disables buttons on ALL form submissions
|
|
|
|
$(this.$refs.submitButton).enable();
|
|
|
|
|
|
|
|
// Remove the issue
|
|
|
|
this.list.removeIssue(issue);
|
|
|
|
|
|
|
|
// Show error message
|
|
|
|
this.error = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
cancel() {
|
|
|
|
this.title = '';
|
2017-03-15 05:18:05 -04:00
|
|
|
eventHub.$emit(`hide-issue-form-${this.list.id}`);
|
2017-02-28 05:23:19 -05:00
|
|
|
},
|
2018-02-19 14:06:16 -05:00
|
|
|
setSelectedProject(selectedProject) {
|
|
|
|
this.selectedProject = selectedProject;
|
|
|
|
},
|
2017-02-28 05:23:19 -05:00
|
|
|
},
|
|
|
|
};
|
2018-02-06 09:44:38 -05:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2018-02-19 14:06:16 -05:00
|
|
|
<div class="board-new-issue-form">
|
2019-04-16 10:41:25 -04:00
|
|
|
<div class="board-card position-relative p-3 rounded">
|
2019-01-10 16:56:37 -05:00
|
|
|
<form @submit="submit($event)">
|
2018-11-16 15:07:38 -05:00
|
|
|
<div v-if="error" class="flash-container">
|
|
|
|
<div class="flash-alert">An error occurred. Please try again.</div>
|
2018-02-19 14:06:16 -05:00
|
|
|
</div>
|
2018-11-16 15:07:38 -05:00
|
|
|
<label :for="list.id + '-title'" class="label-bold"> Title </label>
|
2018-02-19 14:06:16 -05:00
|
|
|
<input
|
2018-09-20 02:13:50 -04:00
|
|
|
:id="list.id + '-title'"
|
2018-06-11 05:49:47 -04:00
|
|
|
ref="input"
|
|
|
|
v-model="title"
|
2018-02-19 14:06:16 -05:00
|
|
|
class="form-control"
|
|
|
|
type="text"
|
2018-08-01 12:17:56 -04:00
|
|
|
name="issue_title"
|
2018-02-19 14:06:16 -05:00
|
|
|
autocomplete="off"
|
|
|
|
/>
|
2018-11-16 15:07:38 -05:00
|
|
|
<project-select v-if="groupId" :group-id="groupId" />
|
2018-02-19 14:06:16 -05:00
|
|
|
<div class="clearfix prepend-top-10">
|
2018-09-26 16:44:48 -04:00
|
|
|
<gl-button
|
2018-06-11 05:49:47 -04:00
|
|
|
ref="submit-button"
|
|
|
|
:disabled="disabled"
|
2018-09-26 16:44:48 -04:00
|
|
|
class="float-left"
|
|
|
|
variant="success"
|
2018-02-19 14:06:16 -05:00
|
|
|
type="submit"
|
|
|
|
>
|
|
|
|
Submit issue
|
2018-09-26 16:44:48 -04:00
|
|
|
</gl-button>
|
2018-11-16 15:07:38 -05:00
|
|
|
<gl-button class="float-right" type="button" variant="default" @click="cancel">
|
2018-02-19 14:06:16 -05:00
|
|
|
Cancel
|
2018-09-26 16:44:48 -04:00
|
|
|
</gl-button>
|
2018-02-19 14:06:16 -05:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2018-02-06 09:44:38 -05:00
|
|
|
</div>
|
|
|
|
</template>
|