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.

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