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.

204 lines
6.6 KiB

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