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.

232 lines
7.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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. div.field
  38. label.checkbox
  39. input(
  40. v-model="randomizeDocumentOrder"
  41. name="randomize_document_order"
  42. type="checkbox"
  43. style="margin-right: 0.25em;"
  44. required
  45. )
  46. | Randomize document order per user
  47. footer.modal-card-foot.pt20.pb20.pr20.pl20.has-background-white-ter
  48. button.button.is-primary(v-on:click="create()") Create
  49. button.button(v-on:click="isActive = !isActive") Cancel
  50. div.modal(v-bind:class="{ 'is-active': isDelete }")
  51. div.modal-background
  52. div.modal-card
  53. header.modal-card-head
  54. p.modal-card-title Delete Project
  55. button.delete(aria-label="close", v-on:click="isDelete = !isDelete")
  56. section.modal-card-body Are you sure you want to delete project?
  57. footer.modal-card-foot.pt20.pb20.pr20.pl20.has-background-white-ter
  58. button.button.is-danger(v-on:click="deleteProject()") Delete
  59. button.button(v-on:click="isDelete = !isDelete") Cancel
  60. section.hero
  61. div.container
  62. div.columns
  63. div.column.is-10.is-offset-1
  64. div.card.events-card
  65. header.card-header
  66. p.card-header-title {{ items.length }} Projects
  67. div.field.card-header-icon
  68. div.control
  69. div.select
  70. select(v-model="selected")
  71. option(selected) All Project
  72. option Text Classification
  73. option Sequence Labeling
  74. option Seq2seq
  75. div.card-table
  76. div.content
  77. table.table.is-fullwidth
  78. tbody
  79. tr(v-for="project in selectedProjects", v-bind:key="project.id")
  80. td.pl15r
  81. div.thumbnail-wrapper.is-vertical
  82. img.project-thumbnail(
  83. v-bind:src="project.image"
  84. alt="Project thumbnail"
  85. )
  86. div.dataset-item__main.is-vertical
  87. div.dataset-item__main-title
  88. div.dataset-item__main-title-link.dataset-item__link
  89. a.has-text-black(v-bind:href="'/projects/' + project.id")
  90. | {{ project.name }}
  91. div.dataset-item__main-subtitle {{ project.description }}
  92. div.dataset-item__main-info
  93. span.dataset-item__main-update updated
  94. span {{ project.updated_at | daysAgo }}
  95. td.is-vertical
  96. span.tag.is-normal {{ project.project_type }}
  97. td.is-vertical(v-if="isSuperuser")
  98. a(v-bind:href="'/projects/' + project.id + '/docs'") Edit
  99. td.is-vertical(v-if="isSuperuser")
  100. a.has-text-danger(v-on:click="setProject(project)") Delete
  101. </template>
  102. <script>
  103. import { title, daysAgo } from './filter';
  104. import { defaultHttpClient } from './http';
  105. export default {
  106. filters: { title, daysAgo },
  107. data: () => ({
  108. items: [],
  109. isActive: false,
  110. isDelete: false,
  111. project: null,
  112. selected: 'All Project',
  113. projectName: '',
  114. description: '',
  115. projectType: '',
  116. descriptionError: '',
  117. projectTypeError: '',
  118. projectNameError: '',
  119. username: '',
  120. isSuperuser: false,
  121. randomizeDocumentOrder: false,
  122. }),
  123. computed: {
  124. selectedProjects() {
  125. return this.items.filter(item => this.selected === 'All Project' || this.matchType(item.project_type));
  126. },
  127. },
  128. created() {
  129. Promise.all([
  130. defaultHttpClient.get('/v1/projects'),
  131. defaultHttpClient.get('/v1/me'),
  132. ]).then(([projects, me]) => {
  133. this.items = projects.data;
  134. this.username = me.data.username;
  135. this.isSuperuser = me.data.is_superuser;
  136. });
  137. },
  138. methods: {
  139. deleteProject() {
  140. defaultHttpClient.delete(`/v1/projects/${this.project.id}`).then(() => {
  141. this.isDelete = false;
  142. const index = this.items.indexOf(this.project);
  143. this.items.splice(index, 1);
  144. });
  145. },
  146. setProject(project) {
  147. this.project = project;
  148. this.isDelete = true;
  149. },
  150. matchType(projectType) {
  151. if (projectType === 'DocumentClassification') {
  152. return this.selected === 'Text Classification';
  153. }
  154. if (projectType === 'SequenceLabeling') {
  155. return this.selected === 'Sequence Labeling';
  156. }
  157. if (projectType === 'Seq2seq') {
  158. return this.selected === 'Seq2seq';
  159. }
  160. return false;
  161. },
  162. create() {
  163. const payload = {
  164. name: this.projectName,
  165. description: this.description,
  166. project_type: this.projectType,
  167. randomize_document_order: this.randomizeDocumentOrder,
  168. guideline: 'Please write annotation guideline.',
  169. resourcetype: this.resourceType(),
  170. };
  171. defaultHttpClient.post('/v1/projects', payload)
  172. .then((response) => {
  173. window.location = `/projects/${response.data.id}/docs/create`;
  174. })
  175. .catch((error) => {
  176. this.projectTypeError = '';
  177. this.projectNameError = '';
  178. this.descriptionError = '';
  179. if ('resourcetype' in error.response.data) {
  180. this.projectTypeError = error.response.data.resourcetype;
  181. }
  182. if ('name' in error.response.data) {
  183. this.projectNameError = error.response.data.name[0];
  184. }
  185. if ('description' in error.response.data) {
  186. this.descriptionError = error.response.data.description[0];
  187. }
  188. });
  189. },
  190. resourceType() {
  191. if (this.projectType === 'DocumentClassification') {
  192. return 'TextClassificationProject';
  193. }
  194. if (this.projectType === 'SequenceLabeling') {
  195. return 'SequenceLabelingProject';
  196. }
  197. if (this.projectType === 'Seq2seq') {
  198. return 'Seq2seqProject';
  199. }
  200. return '';
  201. },
  202. },
  203. };
  204. </script>