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.

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