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.

136 lines
3.3 KiB

  1. <template>
  2. <base-card
  3. title="Add Project"
  4. agree-text="Create"
  5. cancel-text="Cancel"
  6. :disabled="!valid"
  7. @agree="create"
  8. @cancel="cancel"
  9. >
  10. <template #content>
  11. <v-form
  12. ref="form"
  13. v-model="valid"
  14. >
  15. <v-text-field
  16. v-model="name"
  17. :rules="projectNameRules"
  18. label="Project name"
  19. prepend-icon="mdi-account-multiple"
  20. data-test="project-name"
  21. required
  22. autofocus
  23. />
  24. <v-text-field
  25. v-model="description"
  26. :rules="descriptionRules"
  27. label="Description"
  28. prepend-icon="mdi-clipboard-text"
  29. data-test="project-description"
  30. required
  31. />
  32. <v-select
  33. v-model="projectType"
  34. :items="projectTypes"
  35. :rules="projectTypeRules"
  36. label="projectType"
  37. prepend-icon="mdi-keyboard"
  38. data-test="project-type"
  39. required
  40. />
  41. <v-checkbox
  42. v-model="enableRandomizeDocOrder"
  43. label="Randomize document order"
  44. />
  45. <v-checkbox
  46. v-model="enableShareAnnotation"
  47. label="Share annotations across all users"
  48. />
  49. </v-form>
  50. </template>
  51. </base-card>
  52. </template>
  53. <script>
  54. import BaseCard from '@/components/molecules/BaseCard'
  55. import { projectNameRules, descriptionRules, projectTypeRules } from '@/rules/index'
  56. export default {
  57. components: {
  58. BaseCard
  59. },
  60. props: {
  61. createProject: {
  62. type: Function,
  63. default: () => {},
  64. required: true
  65. },
  66. projectTypes: {
  67. type: Array,
  68. default: () => [
  69. 'Text Classification',
  70. 'Sequence Labeling',
  71. 'Sequence to sequence'
  72. ] // Todo: Get project types from backend server.
  73. }
  74. },
  75. data() {
  76. return {
  77. valid: false,
  78. name: '',
  79. description: '',
  80. projectType: null,
  81. enableShareAnnotation: false,
  82. enableRandomizeDocOrder: false,
  83. projectNameRules,
  84. projectTypeRules,
  85. descriptionRules
  86. }
  87. },
  88. methods: {
  89. cancel() {
  90. this.$emit('close')
  91. },
  92. getServerType() {
  93. if (this.projectType === 'Text Classification') {
  94. return 'DocumentClassification'
  95. } else if (this.projectType === 'Sequence Labeling') {
  96. return 'SequenceLabeling'
  97. } else if (this.projectType === 'Sequence to sequence') {
  98. return 'Seq2seq'
  99. }
  100. },
  101. getResourceType() {
  102. if (this.projectType === 'Text Classification') {
  103. return 'TextClassificationProject'
  104. } else if (this.projectType === 'Sequence Labeling') {
  105. return 'SequenceLabelingProject'
  106. } else if (this.projectType === 'Sequence to sequence') {
  107. return 'Seq2seqProject'
  108. }
  109. },
  110. validate() {
  111. return this.$refs.form.validate()
  112. },
  113. reset() {
  114. this.$refs.form.reset()
  115. },
  116. create() {
  117. if (this.validate()) {
  118. this.createProject({
  119. name: this.name,
  120. description: this.description,
  121. project_type: this.getServerType(),
  122. guideline: 'Please write annotation guideline.',
  123. resourcetype: this.getResourceType(),
  124. randomize_document_order: this.enableRandomizeDocOrder,
  125. collaborative_annotation: this.enableShareAnnotation
  126. })
  127. this.reset()
  128. this.cancel()
  129. }
  130. }
  131. }
  132. }
  133. </script>