2018-02-27 19:10:43 -05:00
|
|
|
import Flash from '~/flash';
|
|
|
|
import { __ } from '~/locale';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
computed: {
|
|
|
|
discussionResolved() {
|
2018-06-21 08:22:40 -04:00
|
|
|
if (this.discussion) {
|
|
|
|
const { notes, resolved } = this.discussion;
|
|
|
|
|
|
|
|
if (notes) {
|
|
|
|
// Decide resolved state using store. Only valid for discussions.
|
|
|
|
return notes.filter(note => !note.system).every(note => note.resolved);
|
|
|
|
}
|
2018-02-27 19:10:43 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
return resolved;
|
2018-02-27 19:10:43 -05:00
|
|
|
}
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
return this.note.resolved;
|
2018-02-27 19:10:43 -05:00
|
|
|
},
|
|
|
|
resolveButtonTitle() {
|
|
|
|
if (this.updatedNoteBody) {
|
|
|
|
if (this.discussionResolved) {
|
2019-06-12 08:18:22 -04:00
|
|
|
return __('Comment & unresolve thread');
|
2018-02-27 19:10:43 -05:00
|
|
|
}
|
|
|
|
|
2019-06-12 08:18:22 -04:00
|
|
|
return __('Comment & resolve thread');
|
2018-02-27 19:10:43 -05:00
|
|
|
}
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2019-06-12 08:18:22 -04:00
|
|
|
return this.discussionResolved ? __('Unresolve thread') : __('Resolve thread');
|
2018-02-27 19:10:43 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
resolveHandler(resolvedState = false) {
|
2019-03-01 04:34:16 -05:00
|
|
|
if (this.note && this.note.isDraft) {
|
|
|
|
return this.$emit('toggleResolveStatus');
|
|
|
|
}
|
|
|
|
|
2018-02-27 19:10:43 -05:00
|
|
|
this.isResolving = true;
|
|
|
|
const isResolved = this.discussionResolved || resolvedState;
|
|
|
|
const discussion = this.resolveAsThread;
|
2018-06-21 08:22:40 -04:00
|
|
|
const endpoint = discussion ? this.discussion.resolve_path : `${this.note.path}/resolve`;
|
2018-02-27 19:10:43 -05:00
|
|
|
|
2018-11-29 07:03:33 -05:00
|
|
|
return this.toggleResolveNote({ endpoint, isResolved, discussion })
|
2018-02-27 19:10:43 -05:00
|
|
|
.then(() => {
|
|
|
|
this.isResolving = false;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.isResolving = false;
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
const msg = __('Something went wrong while resolving this discussion. Please try again.');
|
2018-02-27 19:10:43 -05:00
|
|
|
Flash(msg, 'alert', this.$el);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|