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

104 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-07-26 06:56:36 -04:00
((w) => {
w.ResolveBtn = Vue.extend({
props: {
noteId: Number,
discussionId: String,
resolved: Boolean,
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
};
},
watch: {
'discussions': {
handler: 'updateTooltip',
deep: true
}
},
2016-07-26 06:56:36 -04:00
computed: {
discussion: function () {
return this.discussions[this.discussionId];
},
note: function () {
if (this.discussion) {
return this.discussion.getNote(this.noteId);
} else {
return undefined;
}
},
2016-07-26 06:56:36 -04:00
buttonText: function () {
if (this.isResolved) {
return `Resolved by ${this.resolvedByName}`;
} else if (this.canResolve) {
return 'Mark as resolved';
} else {
return 'Unable to resolve';
2016-07-26 06:56:36 -04:00
}
},
isResolved: function () {
if (this.note) {
return this.note.resolved;
} else {
return false;
}
},
resolvedByName: function () {
return this.note.resolved_by;
},
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.projectPath, this.noteId);
} else {
promise = ResolveService
.resolve(this.projectPath, this.noteId);
}
promise.then((response) => {
this.loading = false;
if (response.status === 200) {
const data = response.json();
const resolved_by = data ? data.resolved_by : null;
CommentsStore.update(this.discussionId, this.noteId, !this.isResolved, resolved_by);
this.discussion.updateHeadline(data);
2016-07-29 10:50:58 -04:00
} else {
new Flash('An error occurred when trying to resolve a comment. Please try again.', 'alert');
}
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
},
beforeDestroy: function () {
CommentsStore.delete(this.discussionId, this.noteId);
2016-07-26 06:56:36 -04:00
},
created: function () {
CommentsStore.create(this.discussionId, this.noteId, this.canResolve, this.resolved, this.resolvedBy);
2016-07-26 06:56:36 -04:00
}
});
})(window);