debian-mirror-gitlab/app/assets/javascripts/notes/mixins/resolvable.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-03-27 19:54:05 +05:30
import Flash from '~/flash';
import { __ } from '~/locale';
export default {
computed: {
discussionResolved() {
2018-11-08 19:23:39 +05:30
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-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
return resolved;
2018-03-27 19:54:05 +05:30
}
2018-11-08 19:23:39 +05:30
return this.note.resolved;
2018-03-27 19:54:05 +05:30
},
resolveButtonTitle() {
if (this.updatedNoteBody) {
if (this.discussionResolved) {
2018-11-08 19:23:39 +05:30
return __('Comment & unresolve discussion');
2018-03-27 19:54:05 +05:30
}
2018-11-08 19:23:39 +05:30
return __('Comment & resolve discussion');
2018-03-27 19:54:05 +05:30
}
2018-11-08 19:23:39 +05:30
return this.discussionResolved ? __('Unresolve discussion') : __('Resolve discussion');
2018-03-27 19:54:05 +05:30
},
},
methods: {
resolveHandler(resolvedState = false) {
this.isResolving = true;
const isResolved = this.discussionResolved || resolvedState;
const discussion = this.resolveAsThread;
2018-11-08 19:23:39 +05:30
const endpoint = discussion ? this.discussion.resolve_path : `${this.note.path}/resolve`;
2018-03-27 19:54:05 +05:30
this.toggleResolveNote({ endpoint, isResolved, discussion })
.then(() => {
this.isResolving = false;
})
.catch(() => {
this.isResolving = false;
2018-11-08 19:23:39 +05:30
const msg = __('Something went wrong while resolving this discussion. Please try again.');
2018-03-27 19:54:05 +05:30
Flash(msg, 'alert', this.$el);
});
},
},
};