diff --git a/app/db.sqlite3 b/app/db.sqlite3 index 7bf9ba88..fd423129 100644 Binary files a/app/db.sqlite3 and b/app/db.sqlite3 differ diff --git a/app/server/package-lock.json b/app/server/package-lock.json index 33ed639e..bb5a41ec 100644 --- a/app/server/package-lock.json +++ b/app/server/package-lock.json @@ -4012,9 +4012,9 @@ } }, "vue-shortkey": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/vue-shortkey/-/vue-shortkey-3.1.5.tgz", - "integrity": "sha512-tva1QsEbEO0Qc4N62ODSophFB4LszwQZzwEn9VaB3uchIJ0wsfVX8zSYi1OkFOuY/MsodDoC/YbbHlwINl27gA==", + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/vue-shortkey/-/vue-shortkey-3.1.6.tgz", + "integrity": "sha512-Nh5cwN86rfNCKINVi16OzN/iVPLvhk1yvVZD8h8E34WlzDRtdm+dngUjfsedz30+Eebbr6c444TmLLIrKqzW9g==", "requires": { "vue": "2.5.16" } diff --git a/app/server/package.json b/app/server/package.json index e1ed08ec..c4986a15 100644 --- a/app/server/package.json +++ b/app/server/package.json @@ -11,7 +11,7 @@ "dependencies": { "vue": "^2.5.16", "vue-loader": "^15.2.4", - "vue-shortkey": "^3.1.5" + "vue-shortkey": "^3.1.6" }, "devDependencies": { "webpack": "^4.12.0", diff --git a/app/server/static/js/http.js b/app/server/static/js/http.js new file mode 100644 index 00000000..e80cc13a --- /dev/null +++ b/app/server/static/js/http.js @@ -0,0 +1,8 @@ +axios.defaults.xsrfCookieName = 'csrftoken'; +axios.defaults.xsrfHeaderName = 'X-CSRFToken'; +var base_url = window.location.href.split('/').slice(3, 5).join('/'); +let HTTP = axios.create({ + baseURL: `/api/${base_url}/` +}); + +export default HTTP; \ No newline at end of file diff --git a/app/server/static/js/mixin.js b/app/server/static/js/mixin.js new file mode 100644 index 00000000..531c3321 --- /dev/null +++ b/app/server/static/js/mixin.js @@ -0,0 +1,102 @@ +import HTTP from './http.js'; + +var annotationMixin = { + data: function () { + return { + cur: 0, + items: [{ + id: null, + text: '', + labels: [] + }], + labels: [], + guideline: 'Here is the Annotation Guideline Text', + total: 0, + remaining: 0, + searchQuery: '', + url: '', + } + }, + methods: { + nextPage: async function () { + this.cur += 1; + if (this.cur == this.items.length) { + if (this.next) { + this.url = this.next; + await this.search(); + this.cur = 0; + } else { + this.cur = this.items.length - 1; + } + } + this.showMessage(this.cur); + }, + prevPage: async function () { + this.cur -= 1; + if (this.cur == -1) { + if (this.prev) { + this.url = this.prev; + await this.search(); + this.cur = this.items.length - 1; + } else { + this.cur = 0; + } + } + this.showMessage(this.cur); + }, + search: async function () { + await HTTP.get(this.url).then(response => { + this.items = response.data['results']; + this.next = response.data['next']; + this.prev = response.data['previous']; + }) + }, + showMessage: function (index) { + this.cur = index; + }, + submit: async function () { + this.url = `docs/?q=${this.searchQuery}`; + await this.search(); + this.cur = 0; + }, + updateProgress: function () { + HTTP.get('progress').then(response => { + this.total = response.data['total']; + this.remaining = response.data['remaining']; + }) + }, + deleteLabel: async function (index) { + var doc_id = this.items[this.cur].id; + var annotation_id = this.items[this.cur]['labels'][index].id; + HTTP.delete(`docs/${doc_id}/annotations/${annotation_id}`).then(response => { + this.items[this.cur]['labels'].splice(index, 1) + }); + this.updateProgress(); + } + }, + created: function () { + HTTP.get('labels').then(response => { + this.labels = response.data + }); + this.updateProgress(); + this.submit(); + }, + computed: { + achievement: function () { + var done = this.total - this.remaining; + var percentage = Math.round(done / this.total * 100); + return this.total > 0 ? percentage : 0; + }, + progressColor: function () { + if (this.achievement < 30) { + return 'is-danger' + } else if (this.achievement < 70) { + return 'is-warning' + } else { + return 'is-primary' + } + } + } +}; + +export default annotationMixin; \ No newline at end of file diff --git a/app/server/static/js/sequence_labeling.js b/app/server/static/js/sequence_labeling.js index 2f08ec12..38f42506 100644 --- a/app/server/static/js/sequence_labeling.js +++ b/app/server/static/js/sequence_labeling.js @@ -1,14 +1,9 @@ -//import Vue from 'vue'; -//Vue.use(require('vue-shortkey')); +import Vue from 'vue'; +Vue.use(require('vue-shortkey')); +import annotationMixin from './mixin.js'; +import HTTP from './http.js'; -axios.defaults.xsrfCookieName = 'csrftoken'; -axios.defaults.xsrfHeaderName = 'X-CSRFToken'; -var base_url = window.location.href.split('/').slice(3, 5).join('/'); -const HTTP = axios.create({ - baseURL: `/api/${base_url}/` -}) - -const Annotator = { +Vue.component('annotator', { template: '