You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
7.5 KiB

5 years ago
  1. <template lang="pug">
  2. div(v-cloak="")
  3. section.hero.project-image
  4. div.container
  5. div.columns
  6. div.column.is-10.is-offset-1
  7. h1.title.is-1.has-text-white Hello, {{ username | title }}.
  8. h2.subtitle.is-4.has-text-white I hope you are having a great day!
  9. p(v-if="isSuperuser")
  10. a.button.is-medium.is-primary(v-on:click="isActive = !isActive") Create Project
  11. div.modal(v-bind:class="{ 'is-active': isActive }")
  12. div.modal-background
  13. div.modal-card
  14. header.modal-card-head
  15. p.modal-card-title Create Project
  16. button.delete(aria-label="close", v-on:click="isActive = !isActive")
  17. section.modal-card-body
  18. div.field
  19. label.label Project Name
  20. div.control
  21. input.input(v-model="projectName", type="text", required, placeholder="Project name")
  22. p.help.is-danger {{ projectNameError }}
  23. div.field
  24. label.label Description
  25. div.control
  26. textarea.textarea(v-model="description", required, placeholder="Project description")
  27. p.help.is-danger {{ descriptionError }}
  28. div.field
  29. label.label Project Type
  30. div.control
  31. select(v-model="projectType", name="project_type", required)
  32. option(value="", selected="selected") ---------
  33. option(value="DocumentClassification") document classification
  34. option(value="SequenceLabeling") sequence labeling
  35. option(value="Seq2seq") sequence to sequence
  36. p.help.is-danger {{ projectTypeError }}
  37. footer.modal-card-foot.pt20.pb20.pr20.pl20.has-background-white-ter
  38. button.button.is-primary(v-on:click="create()") Create
  39. button.button(v-on:click="isActive = !isActive") Cancel
  40. div.modal(v-bind:class="{ 'is-active': isDelete }")
  41. div.modal-background
  42. div.modal-card
  43. header.modal-card-head
  44. p.modal-card-title Delete Project
  45. button.delete(aria-label="close", v-on:click="isDelete = !isDelete")
  46. section.modal-card-body Are you sure you want to delete project?
  47. footer.modal-card-foot.pt20.pb20.pr20.pl20.has-background-white-ter
  48. button.button.is-danger(v-on:click="deleteProject()") Delete
  49. button.button(v-on:click="isDelete = !isDelete") Cancel
  50. section.hero
  51. div.container
  52. div.columns
  53. div.column.is-10.is-offset-1
  54. div.card.events-card
  55. header.card-header
  56. p.card-header-title {{ items.length }} Projects
  57. div.field.card-header-icon
  58. div.control
  59. div.select
  60. select(v-model="selected")
  61. option(selected) All Project
  62. option Text Classification
  63. option Sequence Labeling
  64. option Seq2seq
  65. div.card-table
  66. div.content
  67. table.table.is-fullwidth
  68. tbody
  69. tr(v-for="project in selectedProjects", v-bind:key="project.id")
  70. td.pl15r
  71. div.thumbnail-wrapper.is-vertical
  72. img.project-thumbnail(
  73. v-bind:src="project.image"
  74. alt="Project thumbnail"
  75. )
  76. div.dataset-item__main.is-vertical
  77. div.dataset-item__main-title
  78. div.dataset-item__main-title-link.dataset-item__link
  79. a.has-text-black(v-bind:href="'/projects/' + project.id")
  80. | {{ project.name }}
  81. div.dataset-item__main-subtitle {{ project.description }}
  82. div.dataset-item__main-info
  83. span.dataset-item__main-update updated
  84. span {{ project.updated_at | daysAgo }}
  85. td.is-vertical
  86. span.tag.is-normal {{ project.project_type }}
  87. td.is-vertical(v-if="isSuperuser")
  88. a(v-bind:href="'/projects/' + project.id + '/docs'") Edit
  89. td.is-vertical(v-if="isSuperuser")
  90. a.has-text-danger(v-on:click="setProject(project)") Delete
  91. </template>
  92. <script>
  93. import axios from 'axios';
  94. import { title, daysAgo } from './filter';
  95. axios.defaults.xsrfCookieName = 'csrftoken';
  96. axios.defaults.xsrfHeaderName = 'X-CSRFToken';
  97. const baseUrl = window.location.href.split('/').slice(0, 3).join('/');
  98. export default {
  99. filters: { title, daysAgo },
  100. data: () => ({
  101. items: [],
  102. isActive: false,
  103. isDelete: false,
  104. project: null,
  105. selected: 'All Project',
  106. projectName: '',
  107. description: '',
  108. projectType: '',
  109. descriptionError: '',
  110. projectTypeError: '',
  111. projectNameError: '',
  112. username: '',
  113. isSuperuser: false,
  114. }),
  115. computed: {
  116. selectedProjects() {
  117. return this.items.filter(item => this.selected === 'All Project' || this.matchType(item.project_type));
  118. },
  119. },
  120. created() {
  121. Promise.all([
  122. axios.get(`${baseUrl}/v1/projects`),
  123. axios.get(`${baseUrl}/v1/me`),
  124. ]).then(([projects, me]) => {
  125. this.items = projects.data;
  126. this.username = me.data.username;
  127. this.isSuperuser = me.data.is_superuser;
  128. });
  129. },
  130. methods: {
  131. deleteProject() {
  132. axios.delete(`${baseUrl}/v1/projects/${this.project.id}`).then(() => {
  133. this.isDelete = false;
  134. const index = this.items.indexOf(this.project);
  135. this.items.splice(index, 1);
  136. });
  137. },
  138. setProject(project) {
  139. this.project = project;
  140. this.isDelete = true;
  141. },
  142. matchType(projectType) {
  143. if (projectType === 'DocumentClassification') {
  144. return this.selected === 'Text Classification';
  145. }
  146. if (projectType === 'SequenceLabeling') {
  147. return this.selected === 'Sequence Labeling';
  148. }
  149. if (projectType === 'Seq2seq') {
  150. return this.selected === 'Seq2seq';
  151. }
  152. return false;
  153. },
  154. create() {
  155. const payload = {
  156. name: this.projectName,
  157. description: this.description,
  158. project_type: this.projectType,
  159. guideline: 'Please write annotation guideline.',
  160. resourcetype: this.resourceType(),
  161. };
  162. axios.post(`${baseUrl}/v1/projects`, payload)
  163. .then((response) => {
  164. window.location = `${baseUrl}/projects/${response.data.id}/docs/create`;
  165. })
  166. .catch((error) => {
  167. this.projectTypeError = '';
  168. this.projectNameError = '';
  169. this.descriptionError = '';
  170. if ('resourcetype' in error.response.data) {
  171. this.projectTypeError = error.response.data.resourcetype;
  172. }
  173. if ('name' in error.response.data) {
  174. this.projectNameError = error.response.data.name[0];
  175. }
  176. if ('description' in error.response.data) {
  177. this.descriptionError = error.response.data.description[0];
  178. }
  179. });
  180. },
  181. resourceType() {
  182. if (this.projectType === 'DocumentClassification') {
  183. return 'TextClassificationProject';
  184. }
  185. if (this.projectType === 'SequenceLabeling') {
  186. return 'SequenceLabelingProject';
  187. }
  188. if (this.projectType === 'Seq2seq') {
  189. return 'Seq2seqProject';
  190. }
  191. return '';
  192. },
  193. },
  194. };
  195. </script>