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.

301 lines
10 KiB

  1. <template lang="pug">
  2. v-card.wiki-form
  3. v-card-text(v-if='group.id === 1')
  4. v-alert.radius-7(
  5. :class='$vuetify.dark ? "grey darken-4" : "orange lighten-5"'
  6. color='orange darken-2'
  7. outline
  8. :value='true'
  9. icon='lock_outline'
  10. ) This group has access to everything.
  11. template(v-else)
  12. v-card-title(:class='$vuetify.dark ? `grey darken-3-d5` : `grey lighten-5`')
  13. v-alert.radius-7(
  14. :class='$vuetify.dark ? `grey darken-3-d3` : `white`'
  15. :value='true'
  16. color='grey'
  17. outline
  18. icon='info'
  19. ) You must enable global content permissions (under Permissions tab) for page rules to have any effect.
  20. v-spacer
  21. v-btn(depressed, color='primary', @click='addRule')
  22. v-icon(left) add
  23. | Add Rule
  24. v-menu(
  25. right
  26. offset-y
  27. nudge-left='115'
  28. )
  29. v-btn.is-icon(slot='activator', flat, outline, color='primary')
  30. v-icon more_horiz
  31. v-list(dense)
  32. v-list-tile(@click='comingSoon')
  33. v-list-tile-avatar
  34. v-icon keyboard_capslock
  35. v-list-tile-title Load Preset
  36. v-divider
  37. v-list-tile(@click='comingSoon')
  38. v-list-tile-avatar
  39. v-icon publish
  40. v-list-tile-title Save As Preset
  41. v-divider
  42. v-list-tile(@click='comingSoon')
  43. v-list-tile-avatar
  44. v-icon cloud_upload
  45. v-list-tile-title Import Rules
  46. v-divider
  47. v-list-tile(@click='comingSoon')
  48. v-list-tile-avatar
  49. v-icon cloud_download
  50. v-list-tile-title Export Rules
  51. v-card-text(:class='$vuetify.dark ? `grey darken-4-l5` : `white`')
  52. .rules
  53. .caption(v-if='group.pageRules.length === 0')
  54. em(:class='$vuetify.dark ? `grey--text` : `blue-grey--text`') This group has no page rules yet.
  55. .rule(v-for='rule of group.pageRules', :key='rule.id')
  56. v-btn.ma-0.rule-deny-btn(
  57. solo
  58. :color='rule.deny ? "red" : "green"'
  59. dark
  60. @click='rule.deny = !rule.deny'
  61. )
  62. v-icon(v-if='rule.deny') block
  63. v-icon(v-else) check_circle
  64. //- Roles
  65. v-select.ml-1(
  66. solo
  67. :items='roles'
  68. v-model='rule.roles'
  69. placeholder='Select Role(s)...'
  70. hide-details
  71. multiple
  72. chips
  73. deletable-chips
  74. small-chips
  75. style='flex: 0 1 440px;'
  76. :menu-props='{ "maxHeight": 500 }'
  77. clearable
  78. dense
  79. )
  80. template(slot='selection', slot-scope='{ item, index }')
  81. v-chip.white--text.ml-0(v-if='index <= 2', small, label, :color='rule.deny ? `red` : `green`').caption {{ item.value }}
  82. v-chip.white--text.ml-0(v-if='index === 3', small, label, :color='rule.deny ? `red lighten-2` : `green lighten-2`').caption + {{ rule.roles.length - 3 }} more
  83. template(slot='item', slot-scope='props')
  84. v-list-tile-action(style='min-width: 30px;')
  85. v-checkbox(
  86. v-model='props.tile.props.value'
  87. hide-details
  88. color='primary'
  89. )
  90. v-icon.mr-2(:color='rule.deny ? `red` : `green`') {{props.item.icon}}
  91. v-list-tile-content
  92. v-list-tile-title.body-2 {{props.item.text}}
  93. v-chip.mr-2.grey--text(label, small, :color='$vuetify.dark ? `grey darken-4` : `grey lighten-4`').caption {{props.item.value}}
  94. //- Match
  95. v-select.ml-1.mr-1(
  96. solo
  97. :items='matches'
  98. v-model='rule.match'
  99. placeholder='Match...'
  100. hide-details
  101. style='flex: 0 1 250px;'
  102. dense
  103. )
  104. template(slot='selection', slot-scope='{ item, index }')
  105. .body-1 {{item.text}}
  106. template(slot='item', slot-scope='data')
  107. v-list-tile-avatar
  108. v-avatar.white--text.radius-4(color='blue', size='30', tile) {{ data.item.icon }}
  109. v-list-tile-content
  110. v-list-tile-title(v-html='data.item.text')
  111. //- Locales
  112. v-select.mr-1(
  113. :background-color='$vuetify.dark ? `grey darken-3-d5` : `blue-grey lighten-5`'
  114. solo
  115. :items='locales'
  116. v-model='rule.locales'
  117. placeholder='Any Locale'
  118. multiple
  119. hide-details
  120. dense
  121. :menu-props='{ "minWidth": 250 }'
  122. style='flex: 0 1 150px;'
  123. )
  124. template(slot='selection', slot-scope='{ item, index }')
  125. v-chip.white--text.ml-0(v-if='rule.locales.length === 1', small, label, :color='rule.deny ? `red` : `green`').caption {{ item.value.toUpperCase() }}
  126. v-chip.white--text.ml-0(v-else-if='index === 0', small, label, :color='rule.deny ? `red` : `green`').caption {{ rule.locales.length }} locales
  127. v-list-tile(slot='prepend-item', @click='rule.locales = []')
  128. v-list-tile-action(style='min-width: 30px;')
  129. v-checkbox(
  130. :input-value='rule.locales.length === 0'
  131. hide-details
  132. color='primary'
  133. readonly
  134. )
  135. v-icon.mr-2(:color='rule.deny ? `red` : `green`') public
  136. v-list-tile-content
  137. v-list-tile-title.body-2 Any Locale
  138. v-divider(slot='prepend-item')
  139. template(slot='item', slot-scope='props')
  140. v-list-tile-action(style='min-width: 30px;')
  141. v-checkbox(
  142. v-model='props.tile.props.value'
  143. hide-details
  144. color='primary'
  145. )
  146. v-icon.mr-2(:color='rule.deny ? `red` : `green`') language
  147. v-list-tile-content
  148. v-list-tile-title.body-2 {{props.item.text}}
  149. v-chip.mr-2.grey--text(label, small, :color='$vuetify.dark ? `grey darken-4` : `grey lighten-4`').caption {{props.item.value.toUpperCase()}}
  150. //- Path
  151. v-text-field(
  152. solo
  153. v-model='rule.path'
  154. label='Path'
  155. :prefix='rule.match !== `END` ? `/` : null'
  156. :placeholder='rule.match === `REGEX` ? `Regular Expression` : `Path`'
  157. :suffix='rule.match === `REGEX` ? `/` : null'
  158. hide-details
  159. :color='$vuetify.dark ? `grey` : `blue-grey`'
  160. )
  161. v-btn(icon, @click='removeRule(rule.id)')
  162. v-icon(:color='$vuetify.dark ? `grey` : `blue-grey`') clear
  163. </template>
  164. <script>
  165. import _ from 'lodash'
  166. import nanoid from 'nanoid/non-secure/generate'
  167. export default {
  168. props: {
  169. value: {
  170. type: Object
  171. }
  172. },
  173. data() {
  174. return {
  175. roles: [
  176. { text: 'Read Pages', value: 'READ', icon: 'insert_drive_file' },
  177. { text: 'Create Pages', value: 'WRITE', icon: 'insert_drive_file' },
  178. { text: 'Edit + Move Pages', value: 'MANAGE', icon: 'insert_drive_file' },
  179. { text: 'Delete Pages', value: 'DELETE', icon: 'insert_drive_file' },
  180. { text: 'Read / Use Assets', value: 'AS_READ', icon: 'camera' },
  181. { text: 'Upload Assets', value: 'AS_WRITE', icon: 'camera' },
  182. { text: 'Edit + Delete Assets', value: 'AS_MANAGE', icon: 'camera' },
  183. { text: 'Read Comments', value: 'CM_READ', icon: 'insert_comment' },
  184. { text: 'Create Comments', value: 'CM_WRITE', icon: 'insert_comment' },
  185. { text: 'Edit + Delete Comments', value: 'CM_MANAGE', icon: 'insert_comment' }
  186. ],
  187. matches: [
  188. { text: 'Path Starts With...', value: 'START', icon: '/...' },
  189. { text: 'Path is Exactly...', value: 'EXACT', icon: '=' },
  190. { text: 'Path Ends With...', value: 'END', icon: '.../' },
  191. { text: 'Path Matches Regex...', value: 'REGEX', icon: '$.*' }
  192. ],
  193. locales: [
  194. { text: 'English', value: 'en' }
  195. ]
  196. }
  197. },
  198. computed: {
  199. group: {
  200. get() { return this.value },
  201. set(val) { this.$set('input', val) }
  202. }
  203. },
  204. methods: {
  205. addRule(group) {
  206. this.group.pageRules.push({
  207. id: nanoid('1234567890abcdef', 10),
  208. path: '',
  209. roles: [],
  210. match: 'START',
  211. deny: false,
  212. locales: []
  213. })
  214. },
  215. removeRule(rule) {
  216. this.group.pageRules.splice(_.findIndex(this.group.pageRules, ['id', rule.id]), 1)
  217. },
  218. comingSoon() {
  219. this.$store.commit('showNotification', {
  220. style: 'indigo',
  221. message: `Coming soon...`,
  222. icon: 'directions_boat'
  223. })
  224. }
  225. }
  226. }
  227. </script>
  228. <style lang="scss">
  229. .rules {
  230. background-color: mc('blue-grey', '50');
  231. border-radius: 4px;
  232. padding: 1rem;
  233. position: relative;
  234. @at-root .theme--dark & {
  235. background-color: mc('grey', '800');
  236. }
  237. }
  238. .rule {
  239. display: flex;
  240. background-color: mc('blue-grey', '100');
  241. border-radius: 4px;
  242. padding: .5rem;
  243. &-enter-active, &-leave-active {
  244. transition: all .5s ease;
  245. }
  246. &-enter, &-leave-to {
  247. opacity: 0;
  248. }
  249. @at-root .theme--dark & {
  250. background-color: mc('grey', '700');
  251. }
  252. & + .rule {
  253. margin-top: .5rem;
  254. position: relative;
  255. &::before {
  256. content: '+';
  257. position: absolute;
  258. width: 2rem;
  259. height: 2rem;
  260. border-radius: 50%;
  261. display: flex;
  262. justify-content: center;
  263. align-items: center;
  264. font-weight: 600;
  265. color: mc('blue-grey', '700');
  266. font-size: 1.25rem;
  267. background-color: mc('blue-grey', '50');
  268. left: -2rem;
  269. top: -1.3rem;
  270. @at-root .theme--dark & {
  271. background-color: mc('grey', '800');
  272. color: mc('grey', '600');
  273. }
  274. }
  275. }
  276. .input-group + * {
  277. margin-left: .5rem;
  278. }
  279. &-deny-btn {
  280. height: 48px;
  281. border-radius: 2px 0 0 2px;
  282. min-width: 0;
  283. }
  284. }
  285. </style>