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.

Event.vue 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div class="event">
  3. <div v-if="operation.isComplex && operation.fixedEntity !== ''" class="isComplex">
  4. <img class="option__icon" :src="entity.icon">
  5. <span class="option__title option__title_single">{{ operation.triggerHint }}</span>
  6. </div>
  7. <Multiselect v-else
  8. :value="currentEvent"
  9. :options="allEvents"
  10. track-by="id"
  11. :multiple="true"
  12. :auto-limit="false"
  13. :disabled="allEvents.length <= 1"
  14. @input="updateEvent">
  15. <template slot="selection" slot-scope="{ values, isOpen }">
  16. <div v-if="values.length && !isOpen" class="eventlist">
  17. <img class="option__icon" :src="values[0].entity.icon">
  18. <span v-for="(value, index) in values" :key="value.id" class="text option__title option__title_single">{{ value.displayName }} <span v-if="index+1 < values.length">, </span></span>
  19. </div>
  20. </template>
  21. <template slot="option" slot-scope="props">
  22. <img class="option__icon" :src="props.option.entity.icon">
  23. <span class="option__title">{{ props.option.displayName }}</span>
  24. </template>
  25. </Multiselect>
  26. </div>
  27. </template>
  28. <script>
  29. import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
  30. import { showWarning } from '@nextcloud/dialogs'
  31. export default {
  32. name: 'Event',
  33. components: {
  34. Multiselect,
  35. },
  36. props: {
  37. rule: {
  38. type: Object,
  39. required: true,
  40. },
  41. },
  42. computed: {
  43. entity() {
  44. return this.$store.getters.getEntityForOperation(this.operation)
  45. },
  46. operation() {
  47. return this.$store.getters.getOperationForRule(this.rule)
  48. },
  49. allEvents() {
  50. return this.$store.getters.getEventsForOperation(this.operation)
  51. },
  52. currentEvent() {
  53. return this.allEvents.filter(event => event.entity.id === this.rule.entity && this.rule.events.indexOf(event.eventName) !== -1)
  54. },
  55. },
  56. methods: {
  57. updateEvent(events) {
  58. if (events.length === 0) {
  59. showWarning(t('workflowengine', 'At least one event must be selected'))
  60. return
  61. }
  62. const existingEntity = this.rule.entity
  63. const newEntities = events.map(event => event.entity.id).filter((value, index, self) => self.indexOf(value) === index)
  64. let newEntity = null
  65. if (newEntities.length > 1) {
  66. newEntity = newEntities.filter(entity => entity !== existingEntity)[0]
  67. } else {
  68. newEntity = newEntities[0]
  69. }
  70. this.$set(this.rule, 'entity', newEntity)
  71. this.$set(this.rule, 'events', events.filter(event => event.entity.id === newEntity).map(event => event.eventName))
  72. this.$emit('update', this.rule)
  73. },
  74. },
  75. }
  76. </script>
  77. <style scoped lang="scss">
  78. .event {
  79. margin-bottom: 5px;
  80. }
  81. .isComplex {
  82. img {
  83. vertical-align: text-top;
  84. }
  85. span {
  86. padding-top: 2px;
  87. display: inline-block;
  88. }
  89. }
  90. .multiselect {
  91. width: 100%;
  92. max-width: 550px;
  93. margin-top: 4px;
  94. }
  95. .multiselect::v-deep .multiselect__single {
  96. display: flex;
  97. }
  98. .multiselect:not(.multiselect--active)::v-deep .multiselect__tags {
  99. background-color: var(--color-main-background) !important;
  100. border: 1px solid transparent;
  101. }
  102. .multiselect::v-deep .multiselect__tags {
  103. background-color: var(--color-main-background) !important;
  104. height: auto;
  105. min-height: 34px;
  106. }
  107. .multiselect:not(.multiselect--disabled)::v-deep .multiselect__tags .multiselect__single {
  108. background-image: var(--icon-triangle-s-000);
  109. background-repeat: no-repeat;
  110. background-position: right center;
  111. }
  112. input {
  113. border: 1px solid transparent;
  114. }
  115. .option__title {
  116. margin-left: 5px;
  117. color: var(--color-main-text);
  118. }
  119. .option__title_single {
  120. font-weight: 900;
  121. }
  122. .option__icon {
  123. width: 16px;
  124. height: 16px;
  125. }
  126. .eventlist img,
  127. .eventlist .text {
  128. vertical-align: middle;
  129. }
  130. </style>