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.

248 lines
5.5 KiB

3 years ago
  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="mdiPlusCircle"
  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 { mdiPlusCircle } from '@mdi/js'
  154. import { projectNameRules, descriptionRules } from '@/rules/index'
  155. export default {
  156. data() {
  157. return {
  158. project: {},
  159. tags: {},
  160. beforeEditCache: {},
  161. tagInput: '',
  162. edit: {
  163. name: false,
  164. desc: false
  165. },
  166. projectNameRules,
  167. descriptionRules,
  168. valid: false,
  169. mdiPlusCircle
  170. }
  171. },
  172. async fetch() {
  173. this.project = await this.$services.project.findById(this.projectId)
  174. this.getTags()
  175. },
  176. computed: {
  177. isReady() {
  178. return !!this.project
  179. },
  180. projectId() {
  181. return this.$route.params.id
  182. }
  183. },
  184. watch: {
  185. 'project.enableRandomOrder'() {
  186. this.doneEdit()
  187. },
  188. 'project.enableShareAnnotation'() {
  189. this.doneEdit()
  190. }
  191. },
  192. methods: {
  193. initEdit() {
  194. Object.keys(this.edit).forEach((v) => { this.edit[v] = false })
  195. },
  196. editProject(name) {
  197. this.cancelEdit()
  198. this.edit[name] = true
  199. Object.assign(this.beforeEditCache, this.project)
  200. },
  201. cancelEdit() {
  202. this.initEdit()
  203. Object.assign(this.project, this.beforeEditCache)
  204. },
  205. async doneEdit() {
  206. if (!this.validate()) {
  207. this.cancelEdit()
  208. return
  209. }
  210. try {
  211. await this.$services.project.update(this.project)
  212. this.beforeEditCache = {}
  213. this.$fetch()
  214. } finally {
  215. this.initEdit()
  216. }
  217. },
  218. validate() {
  219. return this.$refs.form.validate()
  220. },
  221. async getTags(){
  222. this.tags = await this.$services.tag.list(this.projectId)
  223. },
  224. addTag(){
  225. this.$services.tag.create(this.projectId, this.tagInput)
  226. this.tagInput = ''
  227. this.getTags()
  228. },
  229. removeTag(id){
  230. this.$services.tag.delete(this.projectId, id)
  231. this.tags = this.tags.filter(tag => tag.id !== id)
  232. }
  233. }
  234. }
  235. </script>