admin-locale.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template lang='pug'>
  2. v-container(fluid, fill-height, grid-list-lg)
  3. v-layout(row wrap)
  4. v-flex(xs12)
  5. .headline.primary--text Locale
  6. .subheading.grey--text Set localization options for your wiki
  7. v-form.pt-3
  8. v-layout(row wrap)
  9. v-flex(lg6 xs12)
  10. v-card
  11. v-toolbar(color='primary', dark, dense, flat)
  12. v-toolbar-title
  13. .subheading Locale Settings
  14. v-card-text
  15. v-select(
  16. :items='installedLocales'
  17. prepend-icon='language'
  18. v-model='selectedLocale'
  19. item-value='code'
  20. item-text='name'
  21. :label='namespacing ? "Base Locale" : "Site Locale"'
  22. persistent-hint
  23. hint='All UI text elements will be displayed in selected language.'
  24. )
  25. template(slot='item', slot-scope='data')
  26. template(v-if='typeof data.item !== "object"')
  27. v-list-tile-content(v-text='data.item')
  28. template(v-else)
  29. v-list-tile-avatar
  30. v-avatar.blue.white--text(tile, size='40', v-html='data.item.code.toUpperCase()')
  31. v-list-tile-content
  32. v-list-tile-title(v-html='data.item.name')
  33. v-list-tile-sub-title(v-html='data.item.nativeName')
  34. v-divider
  35. v-switch(
  36. v-model='autoUpdate'
  37. label='Update Automatically'
  38. color='primary'
  39. persistent-hint
  40. :hint='namespacing ? "Automatically download updates to all namespaced locales enabled below." : "Automatically download updates to this locale as they become available."'
  41. )
  42. v-divider.my-0
  43. v-card-actions.grey.lighten-4
  44. v-spacer
  45. v-btn(color='primary', :loading='loading', @click='save')
  46. v-icon(left) chevron_right
  47. span Save
  48. v-card.mt-3
  49. v-toolbar(color='primary', dark, dense, flat)
  50. v-toolbar-title
  51. .subheading Multilingual Namespacing
  52. v-card-text
  53. v-switch(
  54. v-model='namespacing'
  55. label='Multilingual Namespaces'
  56. color='primary'
  57. persistent-hint
  58. hint='Enables multiple language versions of the same page.'
  59. )
  60. v-alert.mt-3(
  61. outline
  62. color='orange'
  63. :value='true'
  64. icon='warning'
  65. )
  66. span The locale code will be prefixed to all paths. (e.g. /{{ selectedLocale }}/page-name)
  67. .caption.grey--text Paths without a locale code will be automatically redirected to the base locale defined above.
  68. v-divider
  69. v-select(
  70. :disabled='!namespacing'
  71. :items='installedLocales'
  72. prepend-icon='language'
  73. multiple
  74. chips
  75. deletable-chips
  76. v-model='namespaces'
  77. item-value='code'
  78. item-text='name'
  79. label='Active Namespaces'
  80. persistent-hint
  81. hint='List of locales enabled for multilingual namespacing. The base locale defined above will always be included regardless of this selection.'
  82. )
  83. template(slot='item', slot-scope='data')
  84. template(v-if='typeof data.item !== "object"')
  85. v-list-tile-content(v-text='data.item')
  86. template(v-else)
  87. v-list-tile-avatar
  88. v-avatar.blue.white--text(tile, size='40', v-html='data.item.code.toUpperCase()')
  89. v-list-tile-content
  90. v-list-tile-title(v-html='data.item.name')
  91. v-list-tile-sub-title(v-html='data.item.nativeName')
  92. v-list-tile-action
  93. v-checkbox(:input-value='data.tile.props.value', color='primary', value)
  94. v-divider.my-0
  95. v-card-actions.grey.lighten-4
  96. v-spacer
  97. v-btn(color='primary', :loading='loading', @click='save')
  98. v-icon(left) chevron_right
  99. span Save
  100. v-flex(lg6 xs12)
  101. v-card
  102. v-toolbar(color='teal', dark, dense, flat)
  103. v-toolbar-title
  104. .subheading Download Locale
  105. v-list(two-line, dense)
  106. template(v-for='(lc, idx) in locales')
  107. v-list-tile(:key='lc.code')
  108. v-list-tile-avatar
  109. v-avatar.teal.white--text(size='40') {{lc.code.toUpperCase()}}
  110. v-list-tile-content
  111. v-list-tile-title(v-html='lc.name')
  112. v-list-tile-sub-title(v-html='lc.nativeName')
  113. v-list-tile-action(v-if='lc.isRTL')
  114. v-chip(label, small).caption.grey--text.text--darken-2 RTL
  115. v-list-tile-action(v-if='lc.isInstalled && lc.installDate < lc.updatedAt', @click='download(lc.code)')
  116. v-icon.blue--text cached
  117. v-list-tile-action(v-else-if='lc.isInstalled')
  118. v-icon.green--text check
  119. v-list-tile-action(v-else-if='lc.isDownloading')
  120. v-progress-circular(indeterminate, color='blue', size='20', :width='3')
  121. v-list-tile-action(v-else)
  122. v-btn(icon, @click='download(lc)')
  123. v-icon.grey--text cloud_download
  124. v-divider.my-0(inset, v-if='idx < locales.length - 1')
  125. </template>
  126. <script>
  127. import _ from 'lodash'
  128. import localesQuery from 'gql/admin-locale-query-list.gql'
  129. import localesDownloadMutation from 'gql/admin-locale-mutation-download.gql'
  130. import localesSaveMutation from 'gql/admin-locale-mutation-save.gql'
  131. export default {
  132. data() {
  133. return {
  134. loading: false,
  135. locales: [],
  136. selectedLocale: 'en',
  137. autoUpdate: false,
  138. namespacing: false,
  139. namespaces: []
  140. }
  141. },
  142. computed: {
  143. installedLocales() {
  144. return _.filter(this.locales, ['isInstalled', true])
  145. }
  146. },
  147. methods: {
  148. async download(lc) {
  149. lc.isDownloading = true
  150. const respRaw = await this.$apollo.mutate({
  151. mutation: localesDownloadMutation,
  152. variables: {
  153. locale: lc.code
  154. }
  155. })
  156. const resp = _.get(respRaw, 'data.localization.downloadLocale.responseResult', {})
  157. if (resp.succeeded) {
  158. lc.isDownloading = false
  159. lc.isInstalled = true
  160. this.$store.commit('showNotification', {
  161. message: `Locale ${lc.name} has been installed successfully.`,
  162. style: 'success',
  163. icon: 'get_app'
  164. })
  165. } else {
  166. this.$store.commit('showNotification', {
  167. message: `Error: ${resp.message}`,
  168. style: 'error',
  169. icon: 'warning'
  170. })
  171. }
  172. this.isDownloading = false
  173. },
  174. async save() {
  175. this.loading = true
  176. const respRaw = await this.$apollo.mutate({
  177. mutation: localesSaveMutation,
  178. variables: {
  179. locale: this.selectedLocale,
  180. autoUpdate: this.autoUpdate,
  181. namespacing: this.namespacing,
  182. namespaces: this.namespaces
  183. }
  184. })
  185. const resp = _.get(respRaw, 'data.localization.updateLocale.responseResult', {})
  186. if (resp.succeeded) {
  187. this.$store.commit('showNotification', {
  188. message: 'Locale settings updated successfully.',
  189. style: 'success',
  190. icon: 'check'
  191. })
  192. } else {
  193. this.$store.commit('showNotification', {
  194. message: `Error: ${resp.message}`,
  195. style: 'error',
  196. icon: 'warning'
  197. })
  198. }
  199. this.loading = false
  200. }
  201. },
  202. apollo: {
  203. locales: {
  204. query: localesQuery,
  205. update: (data) => data.localization.locales.map(lc => ({ ...lc, isDownloading: false })),
  206. watchLoading (isLoading) {
  207. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-locale-refresh')
  208. }
  209. },
  210. selectedLocale: {
  211. query: localesQuery,
  212. update: (data) => data.localization.config.locale
  213. },
  214. autoUpdate: {
  215. query: localesQuery,
  216. update: (data) => data.localization.config.autoUpdate
  217. },
  218. namespacing: {
  219. query: localesQuery,
  220. update: (data) => data.localization.config.namespacing
  221. },
  222. namespaces: {
  223. query: localesQuery,
  224. update: (data) => data.localization.config.namespaces
  225. }
  226. }
  227. }
  228. </script>