gitlab-org--gitlab-foss/app/assets/javascripts/boards/components/board_new_issue.vue

135 lines
3.5 KiB
Vue
Raw Normal View History

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