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.

241 lines
8.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. <template lang='pug'>
  2. v-card
  3. v-toolbar(flat, color='primary', dark, dense)
  4. .subtitle-1 {{ $t('admin:utilities.contentTitle') }}
  5. v-card-text
  6. .subtitle-1.pb-3.primary--text Rebuild Page Tree
  7. .body-2 The virtual structure of your wiki is automatically inferred from all page paths. You can trigger a full rebuild of the tree if some virtual folders are missing or not valid anymore.
  8. v-btn(outlined, color='primary', @click='rebuildTree', :disabled='loading').ml-0.mt-3
  9. v-icon(left) mdi-gesture-double-tap
  10. span Proceed
  11. v-divider.my-5
  12. .subtitle-1.pb-3.primary--text Rerender All Pages
  13. .body-2 All pages will be rendered again. Useful if internal links are broken or the rendering pipeline has changed.
  14. v-btn(outlined, color='primary', @click='rerenderPages', :disabled='loading', :loading='isRerendering').ml-0.mt-3
  15. v-icon(left) mdi-gesture-double-tap
  16. span Proceed
  17. v-dialog(
  18. v-model='isRerendering'
  19. persistent
  20. max-width='450'
  21. )
  22. v-card(color='blue darken-2', dark)
  23. v-card-text.pa-10.text-center
  24. semipolar-spinner.animated.fadeIn(
  25. :animation-duration='1500'
  26. :size='65'
  27. color='#FFF'
  28. style='margin: 0 auto;'
  29. )
  30. .mt-5.body-1.white--text Rendering all pages...
  31. .caption(v-if='renderIndex > 0') Rendering {{renderCurrentPath}}... ({{renderIndex}}/{{renderTotal}}, {{renderProgress}}%)
  32. .caption.mt-4 Do not leave this page.
  33. v-progress-linear.mt-5(
  34. color='white'
  35. :value='renderProgress'
  36. stream
  37. rounded
  38. :buffer-value='0'
  39. )
  40. v-divider.my-5
  41. .subtitle-1.pb-3.pl-0.primary--text Migrate all pages to target locale
  42. .body-2 If you created content before selecting a different locale and activating the namespacing capabilities, you may want to transfer all content to the base locale.
  43. .body-2.red--text: strong This operation is destructive and cannot be reversed! Make sure you have proper backups!
  44. v-toolbar.radius-7.mt-5(flat, :color='$vuetify.theme.dark ? `grey darken-3-d5` : `grey lighten-4`', height='80')
  45. v-select(
  46. label='Source Locale'
  47. outlined
  48. hide-details
  49. :items='locales'
  50. item-text='name'
  51. item-value='code'
  52. v-model='sourceLocale'
  53. )
  54. v-icon.mx-3(large) mdi-chevron-right-box-outline
  55. v-select(
  56. label='Target Locale'
  57. outlined
  58. hide-details
  59. :items='locales'
  60. item-text='name'
  61. item-value='code'
  62. v-model='targetLocale'
  63. )
  64. .body-2.mt-5 Pages that are already in the target locale will not be touched. If a page already exists at the target, the source page will not be modified as it would create a conflict. If you want to overwrite the target page, you must first delete it.
  65. v-btn(outlined, color='primary', @click='migrateToLocale', :disabled='loading').ml-0.mt-3
  66. v-icon(left) mdi-gesture-double-tap
  67. span Proceed
  68. </template>
  69. <script>
  70. import _ from 'lodash'
  71. import gql from 'graphql-tag'
  72. import utilityContentMigrateLocaleMutation from 'gql/admin/utilities/utilities-mutation-content-migratelocale.gql'
  73. import utilityContentRebuildTreeMutation from 'gql/admin/utilities/utilities-mutation-content-rebuildtree.gql'
  74. import { SemipolarSpinner } from 'epic-spinners'
  75. /* global siteLangs, siteConfig */
  76. export default {
  77. components: {
  78. SemipolarSpinner
  79. },
  80. data: () => {
  81. return {
  82. isRerendering: false,
  83. loading: false,
  84. renderProgress: 0,
  85. renderIndex: 0,
  86. renderTotal: 0,
  87. renderCurrentPath: '',
  88. sourceLocale: '',
  89. targetLocale: ''
  90. }
  91. },
  92. computed: {
  93. currentLocale () {
  94. return siteConfig.lang
  95. },
  96. locales () {
  97. return siteLangs
  98. }
  99. },
  100. methods: {
  101. async rebuildTree () {
  102. this.loading = true
  103. this.$store.commit(`loadingStart`, 'admin-utilities-content-rebuildtree')
  104. try {
  105. const respRaw = await this.$apollo.mutate({
  106. mutation: utilityContentRebuildTreeMutation
  107. })
  108. const resp = _.get(respRaw, 'data.pages.rebuildTree.responseResult', {})
  109. if (resp.succeeded) {
  110. this.$store.commit('showNotification', {
  111. message: 'Page Tree rebuilt successfully.',
  112. style: 'success',
  113. icon: 'check'
  114. })
  115. } else {
  116. throw new Error(resp.message)
  117. }
  118. } catch (err) {
  119. this.$store.commit('pushGraphError', err)
  120. }
  121. this.$store.commit(`loadingStop`, 'admin-utilities-content-rebuildtree')
  122. this.loading = false
  123. },
  124. async rerenderPages () {
  125. this.loading = true
  126. this.isRerendering = true
  127. this.$store.commit(`loadingStart`, 'admin-utilities-content-rerender')
  128. try {
  129. const pagesRaw = await this.$apollo.query({
  130. query: gql`
  131. {
  132. pages {
  133. list {
  134. id
  135. path
  136. locale
  137. }
  138. }
  139. }
  140. `,
  141. fetchPolicy: 'network-only'
  142. })
  143. if (_.get(pagesRaw, 'data.pages.list', []).length < 1) {
  144. throw new Error('Could not find any page to render!')
  145. }
  146. this.renderIndex = 0
  147. this.renderTotal = pagesRaw.data.pages.list.length
  148. let failed = 0
  149. for (const page of pagesRaw.data.pages.list) {
  150. this.renderCurrentPath = `${page.locale}/${page.path}`
  151. this.renderIndex++
  152. this.renderProgress = Math.round(this.renderIndex / this.renderTotal * 100)
  153. const respRaw = await this.$apollo.mutate({
  154. mutation: gql`
  155. mutation($id: Int!) {
  156. pages {
  157. render(id: $id) {
  158. responseResult {
  159. succeeded
  160. errorCode
  161. slug
  162. message
  163. }
  164. }
  165. }
  166. }
  167. `,
  168. variables: {
  169. id: page.id
  170. }
  171. })
  172. const resp = _.get(respRaw, 'data.pages.render.responseResult', {})
  173. if (!resp.succeeded) {
  174. failed++
  175. }
  176. }
  177. if (failed > 0) {
  178. this.$store.commit('showNotification', {
  179. message: `Completed with ${failed} pages that failed to render. Check server logs for details.`,
  180. style: 'error',
  181. icon: 'alert'
  182. })
  183. } else {
  184. this.$store.commit('showNotification', {
  185. message: 'All pages have been rendered successfully.',
  186. style: 'success',
  187. icon: 'check'
  188. })
  189. }
  190. } catch (err) {
  191. this.$store.commit('pushGraphError', err)
  192. }
  193. this.$store.commit(`loadingStop`, 'admin-utilities-content-rerender')
  194. this.isRerendering = false
  195. this.loading = false
  196. },
  197. async migrateToLocale () {
  198. this.loading = true
  199. this.$store.commit(`loadingStart`, 'admin-utilities-content-migratelocale')
  200. try {
  201. const respRaw = await this.$apollo.mutate({
  202. mutation: utilityContentMigrateLocaleMutation,
  203. variables: {
  204. sourceLocale: this.sourceLocale,
  205. targetLocale: this.targetLocale
  206. }
  207. })
  208. const resp = _.get(respRaw, 'data.pages.migrateToLocale.responseResult', {})
  209. if (resp.succeeded) {
  210. this.$store.commit('showNotification', {
  211. message: `Migrated ${_.get(respRaw, 'data.pages.migrateToLocale.count', 0)} page(s) to target locale successfully.`,
  212. style: 'success',
  213. icon: 'check'
  214. })
  215. } else {
  216. throw new Error(resp.message)
  217. }
  218. } catch (err) {
  219. this.$store.commit('pushGraphError', err)
  220. }
  221. this.$store.commit(`loadingStop`, 'admin-utilities-content-migratelocale')
  222. this.loading = false
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang='scss'>
  228. </style>