6
0

Create.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <v-container fluid>
  3. <v-row>
  4. <v-col :cols=10>
  5. <h1>Project Creation</h1>
  6. </v-col>
  7. <v-col :cols=2 >
  8. <v-btn :to = "{ name: 'projects' }" block color="error">
  9. <v-icon>mdi-reply</v-icon> Back
  10. </v-btn>
  11. </v-col>
  12. </v-row>
  13. <v-card outlined elevation="2" max-width=80% class="mx-auto">
  14. <v-card-title>New Project</v-card-title>
  15. <v-card-text>
  16. <v-container fluid>
  17. <v-form
  18. @submit.prevent="create"
  19. ref="form"
  20. >
  21. <v-row>
  22. <v-col cols=12 sm=12>
  23. <v-text-field
  24. v-model="project.name"
  25. name="name"
  26. label="Project Name"
  27. :error-messages="nameErrors"
  28. required>
  29. </v-text-field>
  30. </v-col>
  31. </v-row>
  32. <v-row>
  33. <v-col cols=12 sm=12>
  34. <v-textarea
  35. v-model="project.description"
  36. name="description"
  37. label="Project Description"
  38. :error-messages="descErrors"
  39. auto-grow
  40. rows="3"
  41. row-height="25"
  42. required>
  43. </v-textarea>
  44. </v-col>
  45. </v-row>
  46. <v-row>
  47. <v-col cols=12 sm=12>
  48. <v-select
  49. v-model="project.model"
  50. name="model"
  51. label="Model"
  52. :error-messages="modelErrors"
  53. :items="data.models"
  54. :hint="modelHint"
  55. item-text="name"
  56. item-value="id"
  57. persistent-hint
  58. return-object
  59. required>
  60. </v-select>
  61. </v-col>
  62. </v-row>
  63. <v-row>
  64. <v-col cols=12 sm=12 class="d-flex align-end flex-column">
  65. <v-btn
  66. type="submit"
  67. color="primary"
  68. >
  69. Create
  70. </v-btn>
  71. </v-col>
  72. </v-row>
  73. </v-form>
  74. </v-container>
  75. </v-card-text>
  76. </v-card>
  77. </v-container>
  78. </template>
  79. <script>
  80. import Project from '@/store/models/project';
  81. import { validationMixin } from 'vuelidate';
  82. import { required, minLength } from 'vuelidate/lib/validators';
  83. import { mapState } from 'vuex'
  84. export default {
  85. name: 'CreateProject',
  86. mixins: [validationMixin],
  87. validations: {
  88. project: {
  89. name: { required, minLength: minLength(5) },
  90. description: { required },
  91. model: { required },
  92. }
  93. },
  94. data () {
  95. return {
  96. project: new Project(),
  97. }
  98. },
  99. computed: {
  100. nameErrors () {
  101. const errors = [];
  102. if (!this.$v.project.name.$dirty) return errors
  103. !this.$v.project.name.minLength && errors.push('Name must be at least 5 characters long')
  104. !this.$v.project.name.required && errors.push('Name is required')
  105. return errors;
  106. },
  107. descErrors () {
  108. const errors = [];
  109. if (!this.$v.project.description.$dirty) return errors
  110. !this.$v.project.description.required && errors.push('Description is required')
  111. return errors;
  112. },
  113. modelErrors () {
  114. const errors = [];
  115. if (!this.$v.project.model.$dirty) return errors
  116. !this.$v.project.model.required && errors.push('Model selection is required')
  117. return errors;
  118. },
  119. modelHint() {
  120. return this.project.model?.description
  121. },
  122. ...mapState(['data'])
  123. },
  124. methods: {
  125. create() {
  126. this.$v.$touch();
  127. if (!this.$v.$invalid) {
  128. console.log("Creating project:", this.project);
  129. }
  130. }
  131. },
  132. created () {
  133. this.$store.dispatch('data/getModels')
  134. this.$store.dispatch('data/getLabelProviders')
  135. },
  136. }
  137. </script>
  138. <style scoped>
  139. </style>