diff --git a/doccano/app/db.sqlite3 b/doccano/app/db.sqlite3 index a48584b1..b6bf2e24 100644 Binary files a/doccano/app/db.sqlite3 and b/doccano/app/db.sqlite3 differ diff --git a/doccano/app/server/static/project_admin.js b/doccano/app/server/static/project_admin.js new file mode 100644 index 00000000..243c5a91 --- /dev/null +++ b/doccano/app/server/static/project_admin.js @@ -0,0 +1,188 @@ +axios.defaults.xsrfCookieName = 'csrftoken'; +axios.defaults.xsrfHeaderName = 'X-CSRFToken'; +var base_url = window.location.href.split('/').slice(3, 5).join('/'); + + +function swap(values) { + var ret = {}; + for (var item of values) { + ret[item['text']] = item['id']; + } + return ret; +}; + + +Vue.component('tabs', { + template: ` +
+
+ +
+ +
+ +
+
+ `, + + data() { + return { + tabs: [] + }; + }, + + created() { + this.tabs = this.$children; + }, + + methods: { + selectTab(selectedTab) { + this.tabs.forEach(tab => { + tab.isActive = (tab.name == selectedTab.name); + }); + } + } + +}); + +Vue.component('tab', { + template: ` +
+ `, + + props: { + name: { + required: true + }, + selected: { + default: false + }, + }, + + data() { + return { + isActive: false + } + }, + + computed: { + href() { + return '#' + this.name.toLowerCase().replace(/ /g, '-') + } + }, + + mounted() { + this.isActive = this.selected + } + +}); + +var vm = new Vue({ + el: '#root', + delimiters: ['[[', ']]'], + data: { + cur: 0, + items: [{ + "id": 10, + "labels": [{ + "text": "Prefecture", + "prob": 0.98 + }], + "text": 'document' + }], + labels: [], + file: null, + file_name: '', + }, + + methods: { + handleFileUpload() { + this.file = this.$refs.file.files[0]; + console.log(this.file); + console.log(this.file.name); + this.file_name = this.file.name; + }, + submitFile() { + let formData = new FormData(); + formData.append('file', this.file); + axios.post('/' + base_url + '/apis/raw_data', + formData, { + headers: { + 'Content-Type': 'multipart/form-data' + } + } + ).then(function () { + console.log('SUCCESS!!'); + }) + .catch(function () { + console.log('FAILURE!!'); + }); + }, + addLabel: function (label) { + var label = { + 'text': label, + 'prob': null + }; + this.items[this.cur]['labels'].push(label); + + var label2id = swap(this.labels); + var data = { + 'id': this.items[this.cur]['id'], + 'label_id': label2id[label['text']] + }; + + axios.post('/' + base_url + '/apis/data', data) + .then(function (response) { + console.log('post data'); + }) + .catch(function (error) { + console.log('ERROR!! happend by Backend.') + }); + }, + deleteLabel: function (index) { + var label2id = swap(this.labels); + var label = this.items[this.cur]['labels'][index]; + var payload = { + 'id': this.items[this.cur]['id'], + 'label_id': label2id[label['text']] + }; + + axios.delete('/' + base_url + '/apis/data', { + data: payload + }) + .then(function (response) { + console.log('delete data'); + }) + .catch(function (error) { + console.log('ERROR!! happend by Backend.') + }); + this.items[this.cur]['labels'].splice(index, 1) + }, + submit: function () { + console.log('submit' + this.searchQuery); + var self = this; + axios.get('/' + base_url + '/apis/search?keyword=' + this.searchQuery) + .then(function (response) { + console.log('search response'); + self.history = response.data['data']; + }) + .catch(function (error) { + console.log('ERROR!! happend by Backend.') + }); + } + }, + created: function () { + var self = this; + axios.get('/' + base_url + '/apis/labels') + .then(function (response) { + self.labels = response.data['labels']; + }) + .catch(function (error) { + console.log('ERROR!! happend by Backend.') + }); + } +}); \ No newline at end of file diff --git a/doccano/app/server/templates/project_admin.html b/doccano/app/server/templates/project_admin.html index 17ff7dae..fcfb6780 100644 --- a/doccano/app/server/templates/project_admin.html +++ b/doccano/app/server/templates/project_admin.html @@ -1,38 +1,84 @@ -{% extends "base.html" %} -{% load static %} -{% block content %} +{% extends "base.html" %} {% load static %} {% block content %}
-
-
-

{{ object.name }}

-
-
-

- -

-
-
-
-

{{ object.description|truncatechars:200 }}

-

Data Upload, Label definition

-

- @jsmith created at {{ object.created_at|date }}   - Question -

+ + +
+
+

Project Dataset

+
+
+

+ +

+
+
+
+
+ +
+
+
+ +
+
+
+
+
+ + 1 +
-
-
- - 1 -
+
- -
+ + + +
+
+

Label Definition

+
+
+

+ +

+
+
+
+

Label definition

+

+ @jsmith created at {{ object.created_at|date }}   + Question +

+
+
+
+ + 1 +
+
+
+
+
+
+ {% endblock %} \ No newline at end of file diff --git a/doccano/app/server/views.py b/doccano/app/server/views.py index ed723731..386a652d 100644 --- a/doccano/app/server/views.py +++ b/doccano/app/server/views.py @@ -125,7 +125,7 @@ class RawDataAPI(View): def post(self, request, *args, **kwargs): """Upload data.""" - f = request.FILES['attachment'] + f = request.FILES['file'] content = ''.join(chunk.decode('utf-8') for chunk in f.chunks()) for line in content.split('\n'): j = json.loads(line)