From 49b85146408f8c355e701c6e42bce8f9eae272aa Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 30 Jul 2018 14:55:52 +0900 Subject: [PATCH] Implement POST/PUT/DELETE method on seq2seq annotation --- app/db.sqlite3 | Bin 258048 -> 258048 bytes app/server/static/bundle/seq2seq.js | 2 +- app/server/static/js/seq2seq.js | 37 +++++++++---------- app/server/templates/annotation/seq2seq.html | 19 ++-------- app/server/views.py | 24 +++++++++++- 5 files changed, 45 insertions(+), 37 deletions(-) diff --git a/app/db.sqlite3 b/app/db.sqlite3 index 8207eeef0a3e844d2bd55388e2378aa73165d473..9ec537cbd74fb66a240523a759d9fc24738aca65 100644 GIT binary patch delta 396 zcmZp8z~AtIe}Xh)%S0Jx))ofczeO8U=E;lkF!1orVBvqs@5#T6e?Na6-**0Ze(lW? z3SanG_$M&PPZrRZW|a|Uwq=|ws4vm%q2KPI&$!(~pJ|T(7Zd+M2L6Nm_xSH^7cgL| z;t!K%W#lwvWC_X0ELH%bM1`W%;)49V;#36_78#(NIaWDiJyzV3MtW@9@A)&SCGaru ze`VnR&Ht7EJ^#zif(bYI)mfPt8Ch7sBrBL?V_|0GWZ`09U|{0^&cOeN|2zLD{$u@5#T6e?Na6-**0ZexA(| z3SanGq=lJnCkyCH%kocPkYf~A5LIK=XDm)FDoZVj&q+*5&54iC&q-rCjbDiXE#Xz diff --git a/app/server/static/bundle/seq2seq.js b/app/server/static/bundle/seq2seq.js index a871bb71..c1603a35 100644 --- a/app/server/static/bundle/seq2seq.js +++ b/app/server/static/bundle/seq2seq.js @@ -185,7 +185,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _htt /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var _mixin_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mixin.js */ \"./static/js/mixin.js\");\n/* harmony import */ var _http_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./http.js */ \"./static/js/http.js\");\n\nvue__WEBPACK_IMPORTED_MODULE_0__[\"default\"].use(__webpack_require__(/*! vue-shortkey */ \"./node_modules/vue-shortkey/dist/index.js\"));\n\n\n\n// localStorage persistence\nvar STORAGE_KEY = 'todos-vuejs-2.0'\nvar todoStorage = {\n fetch: function () {\n var todos = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]')\n todos.forEach(function (todo, index) {\n todo.id = index\n })\n todoStorage.uid = todos.length\n return todos\n },\n save: function (todos) {\n localStorage.setItem(STORAGE_KEY, JSON.stringify(todos))\n }\n}\n\nvar vm = new vue__WEBPACK_IMPORTED_MODULE_0__[\"default\"]({\n el: '#mail-app',\n delimiters: ['[[', ']]'],\n data: {\n todos: todoStorage.fetch(),\n newTodo: '',\n editedTodo: null\n },\n mixins: [_mixin_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"]],\n directives: {\n 'todo-focus': function (el, binding) {\n if (binding.value) {\n el.focus()\n }\n }\n },\n methods: {\n addLabel: async function (label_id) {\n var payload = {\n 'label_id': label_id\n };\n\n var doc_id = this.items[this.cur].id;\n await _http_js__WEBPACK_IMPORTED_MODULE_2__[\"default\"].post(`docs/${doc_id}/annotations/`, payload).then(response => {\n this.items[this.cur]['labels'].push(response.data);\n });\n this.updateProgress();\n },\n addTodo: function () {\n var value = this.newTodo && this.newTodo.trim()\n if (!value) {\n return\n }\n this.todos.push({\n id: todoStorage.uid++,\n title: value,\n })\n this.newTodo = ''\n },\n\n removeTodo: function (todo) {\n this.todos.splice(this.todos.indexOf(todo), 1)\n },\n\n editTodo: function (todo) {\n this.beforeEditCache = todo.title\n this.editedTodo = todo\n },\n\n doneEdit: function (todo) {\n if (!this.editedTodo) {\n return\n }\n this.editedTodo = null\n todo.title = todo.title.trim()\n if (!todo.title) {\n this.removeTodo(todo)\n }\n },\n\n cancelEdit: function (todo) {\n this.editedTodo = null\n todo.title = this.beforeEditCache\n }\n },\n created: function () {\n this.updateProgress();\n this.submit();\n },\n watch: {\n todos: {\n handler: function (todos) {\n todoStorage.save(todos)\n },\n deep: true\n }\n }\n});\n\n//# sourceURL=webpack:///./static/js/seq2seq.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var _mixin_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mixin.js */ \"./static/js/mixin.js\");\n/* harmony import */ var _http_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./http.js */ \"./static/js/http.js\");\n\nvue__WEBPACK_IMPORTED_MODULE_0__[\"default\"].use(__webpack_require__(/*! vue-shortkey */ \"./node_modules/vue-shortkey/dist/index.js\"));\n\n\n\n// localStorage persistence\nvar STORAGE_KEY = 'todos-vuejs-2.0'\nvar todoStorage = {\n fetch: function () {\n var todos = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]')\n todos.forEach(function (todo, index) {\n todo.id = index\n })\n todoStorage.uid = todos.length\n return todos\n },\n save: function (todos) {\n localStorage.setItem(STORAGE_KEY, JSON.stringify(todos))\n }\n}\n\nvar vm = new vue__WEBPACK_IMPORTED_MODULE_0__[\"default\"]({\n el: '#mail-app',\n delimiters: ['[[', ']]'],\n data: {\n todos: todoStorage.fetch(),\n newTodo: '',\n editedTodo: null\n },\n mixins: [_mixin_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"]],\n directives: {\n 'todo-focus': function (el, binding) {\n if (binding.value) {\n el.focus()\n }\n }\n },\n methods: {\n addTodo: function () {\n var value = this.newTodo && this.newTodo.trim()\n if (!value) {\n return\n }\n\n var doc_id = this.items[this.cur].id;\n var payload = {text: value}\n _http_js__WEBPACK_IMPORTED_MODULE_2__[\"default\"].post(`docs/${doc_id}/annotations/`, payload).then(response => {\n this.items[this.cur]['labels'].push(response.data)\n })\n\n this.newTodo = ''\n },\n\n removeTodo: function (todo) {\n var doc_id = this.items[this.cur].id;\n _http_js__WEBPACK_IMPORTED_MODULE_2__[\"default\"].delete(`docs/${doc_id}/annotations/${todo.id}`).then(response => {\n this.items[this.cur]['labels'].splice(this.items[this.cur]['labels'].indexOf(todo), 1)\n });\n },\n\n editTodo: function (todo) {\n this.beforeEditCache = todo.text\n this.editedTodo = todo\n },\n\n doneEdit: function (todo) {\n if (!this.editedTodo) {\n return\n }\n this.editedTodo = null\n todo.text = todo.text.trim()\n if (!todo.text) {\n this.removeTodo(todo)\n }\n var doc_id = this.items[this.cur].id;\n _http_js__WEBPACK_IMPORTED_MODULE_2__[\"default\"].put(`docs/${doc_id}/annotations/${todo.id}`, todo).then(response => {\n console.log(response)\n });\n },\n\n cancelEdit: function (todo) {\n this.editedTodo = null\n todo.text = this.beforeEditCache\n }\n },\n created: function () {\n this.updateProgress();\n this.submit();\n },\n watch: {\n todos: {\n handler: function (todos) {\n todoStorage.save(todos)\n },\n deep: true\n }\n }\n});\n\n//# sourceURL=webpack:///./static/js/seq2seq.js?"); /***/ }) diff --git a/app/server/static/js/seq2seq.js b/app/server/static/js/seq2seq.js index 18eebb50..2a2be174 100644 --- a/app/server/static/js/seq2seq.js +++ b/app/server/static/js/seq2seq.js @@ -36,35 +36,30 @@ var vm = new Vue({ } }, methods: { - addLabel: async function (label_id) { - var payload = { - 'label_id': label_id - }; - - var doc_id = this.items[this.cur].id; - await HTTP.post(`docs/${doc_id}/annotations/`, payload).then(response => { - this.items[this.cur]['labels'].push(response.data); - }); - this.updateProgress(); - }, addTodo: function () { var value = this.newTodo && this.newTodo.trim() if (!value) { return } - this.todos.push({ - id: todoStorage.uid++, - title: value, + + var doc_id = this.items[this.cur].id; + var payload = {text: value} + HTTP.post(`docs/${doc_id}/annotations/`, payload).then(response => { + this.items[this.cur]['labels'].push(response.data) }) + this.newTodo = '' }, removeTodo: function (todo) { - this.todos.splice(this.todos.indexOf(todo), 1) + var doc_id = this.items[this.cur].id; + HTTP.delete(`docs/${doc_id}/annotations/${todo.id}`).then(response => { + this.items[this.cur]['labels'].splice(this.items[this.cur]['labels'].indexOf(todo), 1) + }); }, editTodo: function (todo) { - this.beforeEditCache = todo.title + this.beforeEditCache = todo.text this.editedTodo = todo }, @@ -73,15 +68,19 @@ var vm = new Vue({ return } this.editedTodo = null - todo.title = todo.title.trim() - if (!todo.title) { + todo.text = todo.text.trim() + if (!todo.text) { this.removeTodo(todo) } + var doc_id = this.items[this.cur].id; + HTTP.put(`docs/${doc_id}/annotations/${todo.id}`, todo).then(response => { + console.log(response) + }); }, cancelEdit: function (todo) { this.editedTodo = null - todo.title = this.beforeEditCache + todo.text = this.beforeEditCache } }, created: function () { diff --git a/app/server/templates/annotation/seq2seq.html b/app/server/templates/annotation/seq2seq.html index 63d33a18..1cd76355 100644 --- a/app/server/templates/annotation/seq2seq.html +++ b/app/server/templates/annotation/seq2seq.html @@ -7,17 +7,6 @@ - -
-
+
    -
  • +
  • - +