2016-07-26 06:56:36 -04:00
|
|
|
((w) => {
|
|
|
|
w.ResolveBtn = Vue.extend({
|
|
|
|
props: {
|
|
|
|
noteId: Number,
|
|
|
|
discussionId: String,
|
|
|
|
resolved: Boolean,
|
2016-07-26 08:44:51 -04:00
|
|
|
projectPath: String,
|
2016-07-26 10:47:19 -04:00
|
|
|
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
|
|
|
|
};
|
|
|
|
},
|
2016-07-29 06:19:56 -04:00
|
|
|
watch: {
|
|
|
|
'discussions': {
|
|
|
|
handler: 'updateTooltip',
|
|
|
|
deep: true
|
|
|
|
}
|
|
|
|
},
|
2016-07-26 06:56:36 -04:00
|
|
|
computed: {
|
2016-08-01 06:31:35 -04:00
|
|
|
discussion: function () {
|
|
|
|
return this.discussions[this.discussionId];
|
|
|
|
},
|
2016-07-29 06:19:56 -04:00
|
|
|
note: function () {
|
2016-08-04 04:52:17 -04:00
|
|
|
if (this.discussion) {
|
|
|
|
return this.discussion.getNote(this.noteId);
|
2016-08-17 10:38:23 -04:00
|
|
|
} else {
|
|
|
|
return undefined;
|
2016-08-04 04:52:17 -04:00
|
|
|
}
|
2016-07-29 06:19:56 -04:00
|
|
|
},
|
2016-07-26 06:56:36 -04:00
|
|
|
buttonText: function () {
|
|
|
|
if (this.isResolved) {
|
2016-07-26 10:47:19 -04:00
|
|
|
return `Resolved by ${this.resolvedByName}`;
|
2016-07-26 10:57:14 -04:00
|
|
|
} else if (this.canResolve) {
|
2016-07-26 10:47:19 -04:00
|
|
|
return 'Mark as resolved';
|
2016-08-17 12:01:26 -04:00
|
|
|
} else {
|
|
|
|
return 'Unable to resolve';
|
2016-07-26 06:56:36 -04:00
|
|
|
}
|
|
|
|
},
|
2016-07-29 06:19:56 -04:00
|
|
|
isResolved: function () {
|
2016-08-04 04:52:17 -04:00
|
|
|
if (this.note) {
|
|
|
|
return this.note.resolved;
|
2016-08-17 10:38:23 -04:00
|
|
|
} else {
|
|
|
|
return false;
|
2016-08-04 04:52:17 -04:00
|
|
|
}
|
2016-07-29 06:19:56 -04:00
|
|
|
},
|
|
|
|
resolvedByName: function () {
|
2016-08-01 05:06:31 -04:00
|
|
|
return this.note.resolved_by;
|
2016-07-29 06:19:56 -04:00
|
|
|
},
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateTooltip: function () {
|
2016-07-26 10:57:14 -04:00
|
|
|
$(this.$els.button)
|
|
|
|
.tooltip('hide')
|
|
|
|
.tooltip('fixTitle');
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
|
|
|
resolve: function () {
|
2016-07-26 10:57:14 -04:00
|
|
|
if (!this.canResolve) return;
|
2016-07-26 12:49:49 -04:00
|
|
|
|
2016-07-26 08:44:51 -04:00
|
|
|
let promise;
|
2016-07-26 06:56:36 -04:00
|
|
|
this.loading = true;
|
2016-07-26 08:44:51 -04:00
|
|
|
|
|
|
|
if (this.isResolved) {
|
|
|
|
promise = ResolveService
|
2016-08-31 10:43:18 -04:00
|
|
|
.unresolve(this.projectPath, this.noteId);
|
2016-07-26 08:44:51 -04:00
|
|
|
} else {
|
|
|
|
promise = ResolveService
|
2016-08-31 10:43:18 -04:00
|
|
|
.resolve(this.projectPath, this.noteId);
|
2016-07-26 08:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
promise.then((response) => {
|
|
|
|
this.loading = false;
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
2016-08-01 06:31:35 -04:00
|
|
|
const data = response.json();
|
2016-08-01 05:06:31 -04:00
|
|
|
const resolved_by = data ? data.resolved_by : null;
|
2016-07-27 13:34:04 -04:00
|
|
|
|
2016-08-01 05:06:31 -04:00
|
|
|
CommentsStore.update(this.discussionId, this.noteId, !this.isResolved, resolved_by);
|
2016-08-01 06:31:35 -04:00
|
|
|
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');
|
2016-07-26 08:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
this.$nextTick(this.updateTooltip);
|
|
|
|
});
|
2016-07-26 06:56:36 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
compiled: function () {
|
2016-07-26 10:57:14 -04:00
|
|
|
$(this.$els.button).tooltip({
|
|
|
|
container: 'body'
|
|
|
|
});
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
2016-08-04 04:52:17 -04:00
|
|
|
beforeDestroy: function () {
|
2016-07-26 10:47:19 -04:00
|
|
|
CommentsStore.delete(this.discussionId, this.noteId);
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
|
|
|
created: function () {
|
2016-08-04 04:52:17 -04:00
|
|
|
CommentsStore.create(this.discussionId, this.noteId, this.canResolve, this.resolved, this.resolvedBy);
|
2016-07-26 06:56:36 -04:00
|
|
|
}
|
|
|
|
});
|
2016-07-28 10:07:47 -04:00
|
|
|
})(window);
|