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.

FileMimeType.vue 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!--
  2. - @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
  3. -
  4. - @author Julius Härtl <jus@bitgrid.net>
  5. -
  6. - @license GNU AGPL version 3 or any later version
  7. -
  8. - This program is free software: you can redistribute it and/or modify
  9. - it under the terms of the GNU Affero General Public License as
  10. - published by the Free Software Foundation, either version 3 of the
  11. - License, or (at your option) any later version.
  12. -
  13. - This program is distributed in the hope that it will be useful,
  14. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. - GNU Affero General Public License for more details.
  17. -
  18. - You should have received a copy of the GNU Affero General Public License
  19. - along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. -
  21. -->
  22. <template>
  23. <div>
  24. <Multiselect
  25. :value="currentValue"
  26. :placeholder="t('workflowengine', 'Select a file type')"
  27. label="label"
  28. track-by="pattern"
  29. :options="options"
  30. :multiple="false"
  31. :tagging="false"
  32. @input="setValue">
  33. <template slot="singleLabel" slot-scope="props">
  34. <span class="option__icon" :class="props.option.icon" />
  35. <span class="option__title option__title_single">{{ props.option.label }}</span>
  36. </template>
  37. <template slot="option" slot-scope="props">
  38. <span class="option__icon" :class="props.option.icon" />
  39. <span class="option__title">{{ props.option.label }}</span>
  40. </template>
  41. </Multiselect>
  42. <input v-if="!isPredefined"
  43. type="text"
  44. :value="currentValue.pattern"
  45. @input="updateCustom">
  46. </div>
  47. </template>
  48. <script>
  49. import { Multiselect } from 'nextcloud-vue/dist/Components/Multiselect'
  50. import valueMixin from './../../mixins/valueMixin'
  51. export default {
  52. name: 'FileMimeType',
  53. components: {
  54. Multiselect
  55. },
  56. mixins: [
  57. valueMixin
  58. ],
  59. data() {
  60. return {
  61. predefinedTypes: [
  62. {
  63. icon: 'icon-picture',
  64. label: t('workflowengine', 'Images'),
  65. pattern: '/image\\/.*/'
  66. },
  67. {
  68. icon: 'icon-category-office',
  69. label: t('workflowengine', 'Office documents'),
  70. pattern: '/(vnd\\.(ms-|openxmlformats-).*))$/'
  71. },
  72. {
  73. icon: 'icon-filetype-file',
  74. label: t('workflowengine', 'PDF documents'),
  75. pattern: 'application/pdf'
  76. }
  77. ]
  78. }
  79. },
  80. computed: {
  81. options() {
  82. return [...this.predefinedTypes, this.customValue]
  83. },
  84. isPredefined() {
  85. const matchingPredefined = this.predefinedTypes.find((type) => this.newValue === type.pattern)
  86. if (matchingPredefined) {
  87. return true
  88. }
  89. return false
  90. },
  91. customValue() {
  92. return {
  93. icon: 'icon-settings-dark',
  94. label: t('workflowengine', 'Custom mimetype'),
  95. pattern: ''
  96. }
  97. },
  98. currentValue() {
  99. const matchingPredefined = this.predefinedTypes.find((type) => this.newValue === type.pattern)
  100. if (matchingPredefined) {
  101. return matchingPredefined
  102. }
  103. return {
  104. icon: 'icon-settings-dark',
  105. label: t('workflowengine', 'Custom mimetype'),
  106. pattern: this.newValue
  107. }
  108. }
  109. },
  110. methods: {
  111. validateRegex(string) {
  112. var regexRegex = /^\/(.*)\/([gui]{0,3})$/
  113. var result = regexRegex.exec(string)
  114. return result !== null
  115. },
  116. setValue(value) {
  117. // TODO: check if value requires a regex and set the check operator according to that
  118. if (value !== null) {
  119. this.newValue = value.pattern
  120. this.$emit('input', this.newValue)
  121. }
  122. },
  123. updateCustom(event) {
  124. this.newValue = event.target.value
  125. this.$emit('input', this.newValue)
  126. }
  127. }
  128. }
  129. </script>