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.

150 lines
5.6 KiB

  1. <template lang="pug">
  2. .criterias-item
  3. //- Type
  4. v-select(solo, :items='filteredCriteriaTypes', v-model='item.type', placeholder='Rule Type', ref='typeSelect')
  5. template(slot='item', slot-scope='data')
  6. v-list-tile-avatar
  7. v-avatar(:color='data.item.color', size='40', tile): v-icon(color='white') {{ data.item.icon }}
  8. v-list-tile-content
  9. v-list-tile-title(v-html='data.item.text')
  10. v-list-tile-sub-title.caption(v-html='data.item.description')
  11. //- Operator
  12. v-select(solo, :items='filteredCriteriaOperators', v-model='item.operator', placeholder='Operator', :disabled='!item.type', :class='!item.type ? "blue-grey lighten-4" : ""')
  13. template(slot='item', slot-scope='data')
  14. v-list-tile-avatar
  15. v-avatar.white--text(color='blue', size='30', tile) {{ data.item.icon }}
  16. v-list-tile-content
  17. v-list-tile-title(v-html='data.item.text')
  18. //- Value
  19. v-select(v-if='item.type === "country"', solo, :items='countries', v-model='item.value', placeholder='Countries...', multiple, item-text='name', item-value='code')
  20. v-text-field(v-else-if='item.type === "path"', solo, v-model='item.value', label='Path (e.g. /section)')
  21. v-text-field(v-else-if='item.type === "date"', solo, @click.native.stop='dateActivator = true', v-model='item.value', label='YYYY-MM-DD', readonly)
  22. v-text-field(v-else-if='item.type === "time"', solo, @click.native.stop='timeActivator = true', v-model='item.value', label='HH:MM', readonly)
  23. v-select(v-else-if='item.type === "group"', solo, :items='groups', v-model='item.value', placeholder='Group...', item-text='name', item-value='id')
  24. v-text-field.blue-grey.lighten-4(v-else, solo, disabled)
  25. v-dialog(lazy, v-model='dateActivator', width='290px', ref='dateDialog')
  26. v-date-picker(v-model='item.value', scrollable, color='primary')
  27. v-btn(flat, color='primary' @click='$refs.dateDialog.save(date)', block) ok
  28. v-dialog(lazy, v-model='timeActivator', width='300px', ref='timeDialog')
  29. v-time-picker(v-model='item.value', scrollable, color='primary')
  30. v-btn(flat, color='primary' @click='$refs.timeDialog.save(time)', block) ok
  31. v-btn(icon, @click='remove'): v-icon(color='blue-grey') clear
  32. </template>
  33. <script>
  34. import _ from 'lodash'
  35. // import countriesQuery from 'gql/upsells-query-countries.gql'
  36. export default {
  37. inject: ['allowedCriteriaTypes'],
  38. props: {
  39. value: {
  40. type: Object,
  41. default() { return {} }
  42. },
  43. groupIndex: {
  44. type: Number,
  45. default() { return 0 }
  46. },
  47. itemIndex: {
  48. type: Number,
  49. default() { return 0 }
  50. }
  51. },
  52. data() {
  53. return {
  54. item: {
  55. operator: '',
  56. type: '',
  57. value: ''
  58. },
  59. dateActivator: false,
  60. dateDialog: false,
  61. timeActivator: false,
  62. timeDialog: false,
  63. countries: [],
  64. groups: [],
  65. criteriaTypes: [
  66. { text: 'Path', value: 'path', icon: 'space_bar', color: 'blue', description: 'Match the path of the document being viewed.' },
  67. { text: 'Date', value: 'date', icon: 'date_range', color: 'blue', description: 'Match the current calendar day.' },
  68. { text: 'Time', value: 'time', icon: 'access_time', color: 'blue', description: 'Match the current time of day.' },
  69. { text: 'User Country', value: 'country', icon: 'public', color: 'red', description: `Match the user's country.` },
  70. { text: 'User Group', value: 'group', icon: 'group', color: 'orange', description: 'Match the user group assignments.' }
  71. ],
  72. criteriaOperators: {
  73. country: [
  74. { text: 'In', value: 'in', icon: '[...]' },
  75. { text: 'Not In', value: 'notIn', icon: '[ x ]' }
  76. ],
  77. path: [
  78. { text: 'Matches Exactly', value: 'eq', icon: '=' },
  79. { text: 'NOT Matches Exactly', value: 'ne', icon: '!=' },
  80. { text: 'Starts With', value: 'sw', icon: 'x...' },
  81. { text: 'NOT Starts With', value: 'nsw', icon: '!x...' },
  82. { text: 'Ends With', value: 'ew', icon: '...x' },
  83. { text: 'NOT Ends With', value: 'new', icon: '!...x' },
  84. { text: 'Matches Regex', value: 'regexp', icon: '^x$' }
  85. ],
  86. date: [
  87. { text: 'On or After', value: 'gte', icon: '>=' },
  88. { text: 'On or Before', value: 'lte', icon: '<=' }
  89. ],
  90. time: [
  91. { text: 'At or Later Than', value: 'gte', icon: '>=' },
  92. { text: 'At or Before', value: 'lte', icon: '<=' }
  93. ],
  94. group: [
  95. { text: 'Is Part Of', value: 'in', icon: '[...]' },
  96. { text: 'Is Not Part Of', value: 'notIn', icon: '[ x ]' }
  97. ]
  98. }
  99. }
  100. },
  101. computed: {
  102. filteredCriteriaOperators() {
  103. return _.get(this.criteriaOperators, this.item.type, [])
  104. },
  105. filteredCriteriaTypes() {
  106. console.info(this.allowedCriteriaTypes)
  107. return _.filter(this.criteriaTypes, c => _.includes(this.allowedCriteriaTypes, c.value))
  108. },
  109. itemType() {
  110. return this.item.type
  111. }
  112. },
  113. watch: {
  114. itemType(newValue, oldValue) {
  115. this.item.operator = _.head(this.criteriaOperators[newValue]).value
  116. this.item.value = ''
  117. },
  118. item: {
  119. handler(newValue, oldValue) {
  120. this.$emit('update', this.groupIndex, this.itemIndex, this.item)
  121. },
  122. deep: true
  123. }
  124. },
  125. mounted() {
  126. if (!this.item.type) {
  127. this.$refs.typeSelect.showMenu()
  128. }
  129. },
  130. methods: {
  131. remove() {
  132. this.$emit('remove', this.groupIndex, this.itemIndex)
  133. }
  134. }
  135. // apollo: {
  136. // countries: {
  137. // query: countriesQuery,
  138. // update: (data) => data.location.countries
  139. // }
  140. // }
  141. }
  142. </script>