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.

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