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.

227 lines
5.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <v-card>
  3. <v-card-text v-if="isReady">
  4. <v-form ref="form" v-model="valid">
  5. <v-row>
  6. <v-col cols="12" sm="6">
  7. <h3>Name</h3>
  8. <v-text-field
  9. v-model="project.name"
  10. label="Add project name"
  11. :rules="projectNameRules($t('rules.projectNameRules'))"
  12. :disabled="!edit.name"
  13. single-line
  14. />
  15. </v-col>
  16. <v-col cols="12" sm="6">
  17. <v-btn
  18. v-if="!edit.name"
  19. outlined
  20. color="grey"
  21. class="text-capitalize"
  22. @click="editProject('name')"
  23. >
  24. Edit
  25. </v-btn>
  26. <v-btn
  27. v-if="edit.name"
  28. outlined
  29. color="primary"
  30. class="text-capitalize"
  31. @click="doneEdit()"
  32. >
  33. Save
  34. </v-btn>
  35. <v-btn
  36. v-if="edit.name"
  37. outlined
  38. color="grey"
  39. class="text-capitalize"
  40. @click="cancelEdit()"
  41. >
  42. Cancel
  43. </v-btn>
  44. </v-col>
  45. </v-row>
  46. <v-row>
  47. <v-col cols="12" sm="6">
  48. <h3>Description</h3>
  49. <v-text-field
  50. v-model="project.description"
  51. label="Add description"
  52. :rules="descriptionRules($t('rules.descriptionRules'))"
  53. :disabled="!edit.desc"
  54. single-line
  55. />
  56. </v-col>
  57. <v-col cols="12" sm="6">
  58. <v-btn
  59. v-if="!edit.desc"
  60. outlined
  61. color="grey"
  62. class="text-capitalize"
  63. @click="editProject('desc')"
  64. >
  65. Edit
  66. </v-btn>
  67. <v-btn
  68. v-if="edit.desc"
  69. outlined
  70. color="primary"
  71. class="text-capitalize"
  72. @click="doneEdit()"
  73. >
  74. Save
  75. </v-btn>
  76. <v-btn
  77. v-if="edit.desc"
  78. outlined
  79. color="grey"
  80. class="text-capitalize"
  81. @click="cancelEdit()"
  82. >
  83. Cancel
  84. </v-btn>
  85. </v-col>
  86. </v-row>
  87. <v-row>
  88. <v-col cols="12" sm="6">
  89. <h3>Tags</h3>
  90. <v-chip
  91. v-for="tag in tags"
  92. :key="tag.id"
  93. close
  94. outlined
  95. @click:close="removeTag(tag.id)"
  96. >{{ tag.text }}
  97. </v-chip>
  98. <v-text-field
  99. v-model="tagInput"
  100. clearable
  101. :prepend-icon="mdiPlusCircle"
  102. @keyup.enter="addTag()"
  103. @click:prepend="addTag()"
  104. >
  105. </v-text-field>
  106. </v-col>
  107. </v-row>
  108. <v-row>
  109. <v-col cols="12" sm="6">
  110. <h3>Shuffle</h3>
  111. <v-checkbox
  112. v-model="project.enableRandomOrder"
  113. :label="$t('overview.randomizeDocOrder')"
  114. />
  115. </v-col>
  116. </v-row>
  117. <v-row>
  118. <v-col cols="12" sm="6">
  119. <h3>Collaboration</h3>
  120. <v-checkbox
  121. v-model="project.enableShareAnnotation"
  122. :label="$t('overview.shareAnnotations')"
  123. />
  124. </v-col>
  125. </v-row>
  126. </v-form>
  127. </v-card-text>
  128. </v-card>
  129. </template>
  130. <script>
  131. import { mdiPlusCircle } from '@mdi/js'
  132. import { projectNameRules, descriptionRules } from '@/rules/index'
  133. export default {
  134. data() {
  135. return {
  136. project: {},
  137. tags: {},
  138. beforeEditCache: {},
  139. tagInput: '',
  140. edit: {
  141. name: false,
  142. desc: false
  143. },
  144. projectNameRules,
  145. descriptionRules,
  146. valid: false,
  147. mdiPlusCircle
  148. }
  149. },
  150. async fetch() {
  151. this.project = await this.$services.project.findById(this.projectId)
  152. this.getTags()
  153. },
  154. computed: {
  155. isReady() {
  156. return !!this.project
  157. },
  158. projectId() {
  159. return this.$route.params.id
  160. }
  161. },
  162. watch: {
  163. 'project.enableRandomOrder'() {
  164. this.doneEdit()
  165. },
  166. 'project.enableShareAnnotation'() {
  167. this.doneEdit()
  168. }
  169. },
  170. methods: {
  171. initEdit() {
  172. Object.keys(this.edit).forEach((v) => {
  173. this.edit[v] = false
  174. })
  175. },
  176. editProject(name) {
  177. this.cancelEdit()
  178. this.edit[name] = true
  179. Object.assign(this.beforeEditCache, this.project)
  180. },
  181. cancelEdit() {
  182. this.initEdit()
  183. Object.assign(this.project, this.beforeEditCache)
  184. },
  185. async doneEdit() {
  186. if (!this.validate()) {
  187. this.cancelEdit()
  188. return
  189. }
  190. try {
  191. await this.$services.project.update(this.project)
  192. this.beforeEditCache = {}
  193. this.$fetch()
  194. } finally {
  195. this.initEdit()
  196. }
  197. },
  198. validate() {
  199. return this.$refs.form.validate()
  200. },
  201. async getTags() {
  202. this.tags = await this.$services.tag.list(this.projectId)
  203. },
  204. addTag() {
  205. this.$services.tag.create(this.projectId, this.tagInput)
  206. this.tagInput = ''
  207. this.getTags()
  208. },
  209. removeTag(id) {
  210. this.$services.tag.delete(this.projectId, id)
  211. this.tags = this.tags.filter((tag) => tag.id !== id)
  212. }
  213. }
  214. }
  215. </script>