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.

246 lines
5.4 KiB

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