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.

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