|
1 | 1 | import Vue from 'vue'; |
2 | | -import axios from 'axios'; |
| 2 | +import Projects from './projects.vue'; |
3 | 3 |
|
4 | | -axios.defaults.xsrfCookieName = 'csrftoken'; |
5 | | -axios.defaults.xsrfHeaderName = 'X-CSRFToken'; |
6 | | -const baseUrl = window.location.href.split('/').slice(0, 3).join('/'); |
7 | | - |
8 | | - |
9 | | -const vm = new Vue({ // eslint-disable-line no-unused-vars |
| 4 | +new Vue({ |
10 | 5 | el: '#projects_root', |
11 | | - delimiters: ['[[', ']]'], |
12 | | - data: { |
13 | | - items: [], |
14 | | - isActive: false, |
15 | | - isDelete: false, |
16 | | - project: null, |
17 | | - selected: 'All Project', |
18 | | - projectName: '', |
19 | | - description: '', |
20 | | - projectType: '', |
21 | | - descriptionError: '', |
22 | | - projectTypeError: '', |
23 | | - projectNameError: '', |
24 | | - }, |
25 | | - |
26 | | - methods: { |
27 | | - |
28 | | - deleteProject() { |
29 | | - axios.delete(`${baseUrl}/v1/projects/${this.project.id}`).then(() => { |
30 | | - this.isDelete = false; |
31 | | - const index = this.items.indexOf(this.project); |
32 | | - this.items.splice(index, 1); |
33 | | - }); |
34 | | - }, |
35 | | - |
36 | | - setProject(project) { |
37 | | - this.project = project; |
38 | | - this.isDelete = true; |
39 | | - }, |
40 | | - |
41 | | - matchType(projectType) { |
42 | | - if (projectType === 'DocumentClassification') { |
43 | | - return this.selected === 'Text Classification'; |
44 | | - } |
45 | | - if (projectType === 'SequenceLabeling') { |
46 | | - return this.selected === 'Sequence Labeling'; |
47 | | - } |
48 | | - if (projectType === 'Seq2seq') { |
49 | | - return this.selected === 'Seq2seq'; |
50 | | - } |
51 | | - return false; |
52 | | - }, |
53 | | - |
54 | | - getDaysAgo(dateStr) { |
55 | | - const updatedAt = new Date(dateStr); |
56 | | - const currentTm = new Date(); |
57 | | - |
58 | | - // difference between days(ms) |
59 | | - const msDiff = currentTm.getTime() - updatedAt.getTime(); |
60 | | - |
61 | | - // convert daysDiff(ms) to daysDiff(day) |
62 | | - const daysDiff = Math.floor(msDiff / (1000 * 60 * 60 * 24)); |
63 | | - |
64 | | - return daysDiff; |
65 | | - }, |
66 | | - |
67 | | - create() { |
68 | | - const payload = { |
69 | | - name: this.projectName, |
70 | | - description: this.description, |
71 | | - project_type: this.projectType, |
72 | | - guideline: 'Please write annotation guideline.', |
73 | | - resourcetype: this.resourceType(), |
74 | | - }; |
75 | | - axios.post(`${baseUrl}/v1/projects`, payload) |
76 | | - .then((response) => { |
77 | | - window.location = `${baseUrl}/projects/${response.data.id}/docs/create`; |
78 | | - }) |
79 | | - .catch((error) => { |
80 | | - this.projectTypeError = ''; |
81 | | - this.projectNameError = ''; |
82 | | - this.descriptionError = ''; |
83 | | - if ('resourcetype' in error.response.data) { |
84 | | - this.projectTypeError = error.response.data.resourcetype; |
85 | | - } |
86 | | - if ('name' in error.response.data) { |
87 | | - this.projectNameError = error.response.data.name[0]; |
88 | | - } |
89 | | - if ('description' in error.response.data) { |
90 | | - this.descriptionError = error.response.data.description[0]; |
91 | | - } |
92 | | - }); |
93 | | - }, |
94 | | - |
95 | | - resourceType() { |
96 | | - if (this.projectType === 'DocumentClassification') { |
97 | | - return 'TextClassificationProject'; |
98 | | - } |
99 | | - if (this.projectType === 'SequenceLabeling') { |
100 | | - return 'SequenceLabelingProject'; |
101 | | - } |
102 | | - if (this.projectType === 'Seq2seq') { |
103 | | - return 'Seq2seqProject'; |
104 | | - } |
105 | | - return ''; |
106 | | - }, |
107 | | - }, |
108 | 6 |
|
109 | | - computed: { |
110 | | - selectedProjects() { |
111 | | - return this.items.filter(item => this.selected === 'All Project' || this.matchType(item.project_type)); |
112 | | - }, |
113 | | - }, |
| 7 | + components: { Projects }, |
114 | 8 |
|
115 | | - created() { |
116 | | - axios.get(`${baseUrl}/v1/projects`).then((response) => { |
117 | | - this.items = response.data; |
118 | | - }); |
119 | | - }, |
| 9 | + template: '<Projects />', |
120 | 10 | }); |
0 commit comments