admin-rendering.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row, wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img.animated.fadeInUp(src='/svg/icon-process.svg', alt='Rendering', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft Rendering
  9. .subtitle-1.grey--text.animated.fadeInLeft.wait-p4s Configure how content is rendered #[v-chip(label, color='primary', small).white--text coming soon]
  10. v-spacer
  11. v-btn.mx-3.animated.fadeInDown.wait-p2s(outlined, color='grey', @click='refresh', large)
  12. v-icon mdi-refresh
  13. v-btn.animated.fadeInDown(color='success', @click='save', depressed, large)
  14. v-icon(left) mdi-check
  15. span {{$t('common:actions.apply')}}
  16. v-flex.animated.fadeInUp(lg3, xs12)
  17. v-toolbar(
  18. color='primary'
  19. dense
  20. flat
  21. dark
  22. )
  23. v-icon.mr-2 mdi-creation
  24. .subtitle-1 Pipeline
  25. v-expansion-panels.adm-rendering-pipeline(
  26. v-model='selectedCore'
  27. accordion
  28. mandatory
  29. )
  30. v-expansion-panel(
  31. v-for='core in renderers'
  32. :key='core.key'
  33. )
  34. v-expansion-panel-header(
  35. hide-actions
  36. ripple
  37. )
  38. v-toolbar(
  39. color='blue'
  40. dense
  41. dark
  42. flat
  43. )
  44. v-spacer
  45. .body-2 {{core.input}}
  46. v-icon.mx-2 mdi-arrow-right-bold-hexagon-outline
  47. .caption {{core.output}}
  48. v-spacer
  49. v-expansion-panel-content
  50. v-list.py-0(two-line, dense)
  51. template(v-for='(rdr, n) in core.children')
  52. v-list-item(
  53. :key='rdr.key'
  54. @click='selectRenderer(rdr.key)'
  55. :class='currentRenderer.key === rdr.key ? (darkMode ? `grey darken-4-l4` : `blue lighten-5`) : ``'
  56. )
  57. v-list-item-avatar(size='24')
  58. v-icon(:color='currentRenderer.key === rdr.key ? "primary" : "grey"') {{rdr.icon}}
  59. v-list-item-content
  60. v-list-item-title {{rdr.title}}
  61. v-list-item-subtitle: .caption {{rdr.description}}
  62. v-list-item-avatar(size='24')
  63. status-indicator(v-if='rdr.isEnabled', positive, pulse)
  64. status-indicator(v-else, negative, pulse)
  65. v-divider.my-0(v-if='n < core.children.length - 1')
  66. v-flex(lg9, xs12)
  67. v-card.wiki-form.animated.fadeInUp
  68. v-toolbar(
  69. color='grey darken-1'
  70. dark
  71. flat
  72. dense
  73. )
  74. v-icon.mr-2 {{currentRenderer.icon}}
  75. .subtitle-1 {{currentRenderer.title}}
  76. v-spacer
  77. v-switch(
  78. dark
  79. color='white'
  80. label='Enabled'
  81. v-model='currentRenderer.isEnabled'
  82. hide-details
  83. )
  84. v-card-text.pb-4.pt-2.pl-4
  85. .overline.my-5 Rendering Module Configuration
  86. .body-2.ml-3(v-if='!currentRenderer.config || currentRenderer.config.length < 1'): em This rendering module has no configuration options you can modify.
  87. template(v-else, v-for='(cfg, idx) in currentRenderer.config')
  88. v-select(
  89. v-if='cfg.value.type === "string" && cfg.value.enum'
  90. outlined
  91. :items='cfg.value.enum'
  92. :key='cfg.key'
  93. :label='cfg.value.title'
  94. v-model='cfg.value.value'
  95. :hint='cfg.value.hint ? cfg.value.hint : ""'
  96. persistent-hint
  97. :class='cfg.value.hint ? "mb-2" : ""'
  98. )
  99. v-switch(
  100. v-else-if='cfg.value.type === "boolean"'
  101. :key='cfg.key'
  102. :label='cfg.value.title'
  103. v-model='cfg.value.value'
  104. color='primary'
  105. :hint='cfg.value.hint ? cfg.value.hint : ""'
  106. persistent-hint
  107. )
  108. v-text-field(
  109. v-else
  110. outlined
  111. :key='cfg.key'
  112. :label='cfg.value.title'
  113. v-model='cfg.value.value'
  114. :hint='cfg.value.hint ? cfg.value.hint : ""'
  115. persistent-hint
  116. :class='cfg.value.hint ? "mb-2" : ""'
  117. )
  118. v-divider.my-5(v-if='idx < currentRenderer.config.length - 1')
  119. v-card-chin
  120. v-spacer
  121. .caption.pr-3.grey--text Module: {{ currentRenderer.key }}
  122. </template>
  123. <script>
  124. import _ from 'lodash'
  125. import { DepGraph } from 'dependency-graph'
  126. import { get } from 'vuex-pathify'
  127. import { StatusIndicator } from 'vue-status-indicator'
  128. import renderersQuery from 'gql/admin/rendering/rendering-query-renderers.gql'
  129. export default {
  130. components: {
  131. StatusIndicator
  132. },
  133. data() {
  134. return {
  135. selectedCore: -1,
  136. renderers: [],
  137. currentRenderer: {}
  138. }
  139. },
  140. computed: {
  141. darkMode: get('site/dark')
  142. },
  143. watch: {
  144. renderers(newValue, oldValue) {
  145. _.delay(() => {
  146. this.selectedCore = _.findIndex(newValue, ['key', 'markdownCore'])
  147. this.selectRenderer('markdownCore')
  148. }, 500)
  149. }
  150. },
  151. methods: {
  152. selectRenderer (key) {
  153. this.renderers.map(rdr => {
  154. if (_.some(rdr.children, ['key', key])) {
  155. this.currentRenderer = _.find(rdr.children, ['key', key])
  156. }
  157. })
  158. },
  159. async refresh () {
  160. this.$store.commit('showNotification', {
  161. style: 'indigo',
  162. message: `Coming soon...`,
  163. icon: 'directions_boat'
  164. })
  165. },
  166. async save () {
  167. this.$store.commit('showNotification', {
  168. style: 'indigo',
  169. message: `Coming soon...`,
  170. icon: 'directions_boat'
  171. })
  172. }
  173. },
  174. apollo: {
  175. renderers: {
  176. query: renderersQuery,
  177. fetchPolicy: 'network-only',
  178. update: (data) => {
  179. let renderers = _.cloneDeep(data.rendering.renderers).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))}))
  180. // Build tree
  181. const graph = new DepGraph({ circular: true })
  182. const rawCores = _.filter(renderers, ['dependsOn', null]).map(core => {
  183. core.children = _.concat([_.cloneDeep(core)], _.filter(renderers, ['dependsOn', core.key]))
  184. return core
  185. })
  186. // Build dependency graph
  187. rawCores.map(core => { graph.addNode(core.key) })
  188. rawCores.map(core => {
  189. rawCores.map(coreTarget => {
  190. if (core.key !== coreTarget.key) {
  191. if (core.output === coreTarget.input) {
  192. graph.addDependency(core.key, coreTarget.key)
  193. }
  194. }
  195. })
  196. })
  197. // Reorder cores in reverse dependency order
  198. let orderedCores = []
  199. _.reverse(graph.overallOrder()).map(coreKey => {
  200. orderedCores.push(_.find(rawCores, ['key', coreKey]))
  201. })
  202. return orderedCores
  203. },
  204. watchLoading (isLoading) {
  205. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-rendering-refresh')
  206. }
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang='scss'>
  212. .adm-rendering-pipeline {
  213. .v-expansion-panel--active .v-expansion-panel-header {
  214. min-height: 0;
  215. }
  216. .v-expansion-panel-header {
  217. padding: 0;
  218. margin-top: 1px;
  219. }
  220. .v-expansion-panel-content__wrap {
  221. padding: 0;
  222. }
  223. }
  224. </style>