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.

220 lines
7.0 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. img(src='/svg/icon-process.svg', alt='Rendering', style='width: 80px;')
  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='success', @click='save', depressed, large)
  14. v-icon(left) check
  15. span {{$t('common:actions.apply')}}
  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 ? (darkMode ? `grey darken-4-l4` : `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.wiki-form
  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. :items='cfg.value.enum'
  86. :key='cfg.key'
  87. :label='cfg.value.title'
  88. v-model='cfg.value.value'
  89. :hint='cfg.value.hint ? cfg.value.hint : ""'
  90. persistent-hint
  91. :class='cfg.value.hint ? "mb-2" : ""'
  92. )
  93. v-switch(
  94. v-else-if='cfg.value.type === "boolean"'
  95. :key='cfg.key'
  96. :label='cfg.value.title'
  97. v-model='cfg.value.value'
  98. color='primary'
  99. :hint='cfg.value.hint ? cfg.value.hint : ""'
  100. persistent-hint
  101. )
  102. v-text-field(
  103. v-else
  104. outline
  105. :key='cfg.key'
  106. :label='cfg.value.title'
  107. v-model='cfg.value.value'
  108. :hint='cfg.value.hint ? cfg.value.hint : ""'
  109. persistent-hint
  110. :class='cfg.value.hint ? "mb-2" : ""'
  111. )
  112. v-divider.my-3(v-if='idx < currentRenderer.config.length - 1')
  113. v-card-chin
  114. v-spacer
  115. .caption.pr-3.grey--text Module: {{ currentRenderer.key }}
  116. </template>
  117. <script>
  118. import _ from 'lodash'
  119. import { DepGraph } from 'dependency-graph'
  120. import { get } from 'vuex-pathify'
  121. import { StatusIndicator } from 'vue-status-indicator'
  122. import renderersQuery from 'gql/admin/rendering/rendering-query-renderers.gql'
  123. export default {
  124. components: {
  125. StatusIndicator
  126. },
  127. data() {
  128. return {
  129. selectedCore: -1,
  130. renderers: [],
  131. currentRenderer: {}
  132. }
  133. },
  134. computed: {
  135. darkMode: get('site/dark'),
  136. },
  137. watch: {
  138. renderers(newValue, oldValue) {
  139. _.delay(() => {
  140. this.selectedCore = _.findIndex(newValue, ['key', 'markdownCore'])
  141. this.selectRenderer('markdownCore')
  142. }, 500)
  143. }
  144. },
  145. methods: {
  146. selectRenderer (key) {
  147. this.renderers.map(rdr => {
  148. if (_.some(rdr.children, ['key', key])) {
  149. this.currentRenderer = _.find(rdr.children, ['key', key])
  150. }
  151. })
  152. },
  153. async refresh () {
  154. this.$store.commit('showNotification', {
  155. style: 'indigo',
  156. message: `Coming soon...`,
  157. icon: 'directions_boat'
  158. })
  159. },
  160. async save () {
  161. this.$store.commit('showNotification', {
  162. style: 'indigo',
  163. message: `Coming soon...`,
  164. icon: 'directions_boat'
  165. })
  166. }
  167. },
  168. apollo: {
  169. renderers: {
  170. query: renderersQuery,
  171. fetchPolicy: 'network-only',
  172. update: (data) => {
  173. let renderers = _.cloneDeep(data.rendering.renderers).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))}))
  174. // Build tree
  175. const graph = new DepGraph({ circular: true })
  176. const rawCores = _.filter(renderers, ['dependsOn', null]).map(core => {
  177. core.children = _.concat([_.cloneDeep(core)], _.filter(renderers, ['dependsOn', core.key]))
  178. return core
  179. })
  180. // Build dependency graph
  181. rawCores.map(core => { graph.addNode(core.key) })
  182. rawCores.map(core => {
  183. rawCores.map(coreTarget => {
  184. if (core.key !== coreTarget.key) {
  185. if (core.output === coreTarget.input) {
  186. graph.addDependency(core.key, coreTarget.key)
  187. }
  188. }
  189. })
  190. })
  191. // Reorder cores in reverse dependency order
  192. let orderedCores = []
  193. _.reverse(graph.overallOrder()).map(coreKey => {
  194. orderedCores.push(_.find(rawCores, ['key', coreKey]))
  195. })
  196. return orderedCores
  197. },
  198. watchLoading (isLoading) {
  199. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-rendering-refresh')
  200. }
  201. }
  202. }
  203. }
  204. </script>
  205. <style lang='scss'>
  206. .adm-rendering-pipeline {
  207. border-top: 1px solid #FFF;
  208. .v-expansion-panel__header {
  209. padding: 0 0;
  210. }
  211. }
  212. </style>