RequestURL.vue 3.8 KB

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