gitlab-org--gitlab-foss/app/assets/javascripts/diff_notes/components/resolve_btn.js.es6

80 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-07-26 06:56:36 -04:00
((w) => {
w.ResolveBtn = Vue.extend({
mixins: [
ButtonMixins
],
2016-07-26 06:56:36 -04:00
props: {
noteId: Number,
discussionId: String,
resolved: Boolean,
namespacePath: String,
projectPath: String,
canResolve: Boolean,
resolvedBy: String
2016-07-26 06:56:36 -04:00
},
data: function () {
return {
2016-07-26 12:49:49 -04:00
discussions: CommentsStore.state,
2016-07-26 06:56:36 -04:00
loading: false
};
},
computed: {
buttonText: function () {
if (this.isResolved) {
return `Resolved by ${this.resolvedByName}`;
} else if (this.canResolve) {
return 'Mark as resolved';
2016-07-26 06:56:36 -04:00
}
},
isResolved: function () { return CommentsStore.get(this.discussionId, this.noteId).resolved; },
resolvedByName: function () { return CommentsStore.get(this.discussionId, this.noteId).user; },
2016-07-26 06:56:36 -04:00
},
methods: {
updateTooltip: function () {
$(this.$els.button)
.tooltip('hide')
.tooltip('fixTitle');
2016-07-26 06:56:36 -04:00
},
resolve: function () {
if (!this.canResolve) return;
2016-07-26 12:49:49 -04:00
let promise;
2016-07-26 06:56:36 -04:00
this.loading = true;
if (this.isResolved) {
promise = ResolveService
.unresolve(this.namespace, this.noteId);
} else {
promise = ResolveService
.resolve(this.namespace, this.noteId);
}
promise.then((response) => {
const data = response.data;
const user = data ? data.resolved_by : null;
this.loading = false;
if (response.status === 200) {
CommentsStore.update(this.discussionId, this.noteId, !this.isResolved, user);
ResolveService.updateUpdatedHtml(this.discussionId, data);
}
this.$nextTick(this.updateTooltip);
});
2016-07-26 06:56:36 -04:00
}
},
compiled: function () {
$(this.$els.button).tooltip({
container: 'body'
});
2016-07-26 06:56:36 -04:00
},
destroyed: function () {
CommentsStore.delete(this.discussionId, this.noteId);
2016-07-26 06:56:36 -04:00
},
created: function () {
CommentsStore.create(this.discussionId, this.noteId, this.resolved, this.resolvedBy);
2016-07-26 06:56:36 -04:00
}
});
})(window);