Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

RequestURL.vue 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 request URL')"
  27. label="label"
  28. track-by="pattern"
  29. group-values="children"
  30. group-label="label"
  31. :options="options"
  32. :multiple="false"
  33. :tagging="false"
  34. @input="setValue">
  35. <template slot="singleLabel" slot-scope="props">
  36. <span class="option__icon" :class="props.option.icon" />
  37. <span class="option__title option__title_single">{{ props.option.label }}</span>
  38. </template>
  39. <template slot="option" slot-scope="props">
  40. <span class="option__icon" :class="props.option.icon" />
  41. <span class="option__title">{{ props.option.label }} {{ props.option.$groupLabel }}</span>
  42. </template>
  43. </Multiselect>
  44. <input v-if="!isPredefined"
  45. type="text"
  46. :value="currentValue.pattern"
  47. :placeholder="placeholder"
  48. @input="updateCustom">
  49. </div>
  50. </template>
  51. <script>
  52. import { Multiselect } from 'nextcloud-vue/dist/Components/Multiselect'
  53. import valueMixin from '../../mixins/valueMixin'
  54. export default {
  55. name: 'RequestURL',
  56. components: {
  57. Multiselect
  58. },
  59. mixins: [
  60. valueMixin
  61. ],
  62. data() {
  63. return {
  64. newValue: '',
  65. predefinedTypes: [
  66. {
  67. label: t('workflowengine', 'Predefined URLs'),
  68. children: [
  69. { pattern: 'webdav', label: t('workflowengine', 'Files WebDAV') }
  70. ]
  71. }
  72. ]
  73. }
  74. },
  75. computed: {
  76. options() {
  77. return [...this.predefinedTypes, this.customValue]
  78. },
  79. placeholder() {
  80. if (this.check.operator === 'matches' || this.check.operator === '!matches') {
  81. return '/^https\\:\\/\\/localhost\\/index\\.php$/i'
  82. }
  83. return 'https://localhost/index.php'
  84. },
  85. matchingPredefined() {
  86. return this.predefinedTypes
  87. .map(groups => groups.children)
  88. .flat()
  89. .find((type) => this.newValue === type.pattern)
  90. },
  91. isPredefined() {
  92. return !!this.matchingPredefined
  93. },
  94. customValue() {
  95. return {
  96. label: t('workflowengine', 'Others'),
  97. children: [
  98. {
  99. icon: 'icon-settings-dark',
  100. label: t('workflowengine', 'Custom URL'),
  101. pattern: ''
  102. }
  103. ]
  104. }
  105. },
  106. currentValue() {
  107. if (this.matchingPredefined) {
  108. return this.matchingPredefined
  109. }
  110. return {
  111. icon: 'icon-settings-dark',
  112. label: t('workflowengine', 'Custom URL'),
  113. pattern: this.newValue
  114. }
  115. }
  116. },
  117. methods: {
  118. validateRegex(string) {
  119. var regexRegex = /^\/(.*)\/([gui]{0,3})$/
  120. var result = regexRegex.exec(string)
  121. return result !== null
  122. },
  123. setValue(value) {
  124. // TODO: check if value requires a regex and set the check operator according to that
  125. if (value !== null) {
  126. this.newValue = value.pattern
  127. this.$emit('input', this.newValue)
  128. }
  129. },
  130. updateCustom(event) {
  131. this.newValue = event.target.value
  132. this.$emit('input', this.newValue)
  133. }
  134. }
  135. }
  136. </script>