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.

235 lines
9.1 KiB

  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 {{ $t('admin:locale.title') }}
  6. .subheading.grey--text {{ $t('admin:locale.subtitle') }}
  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 {{ $t('admin: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='nativeName'
  21. :label='namespacing ? $t("admin:locale.base.labelWithNS") : $t("admin:locale.base.label")'
  22. persistent-hint
  23. :hint='$t("admin:locale.base.hint")'
  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.mt-3
  35. v-switch(
  36. v-model='autoUpdate'
  37. :label='$t("admin:locale.autoUpdate.label")'
  38. color='primary'
  39. persistent-hint
  40. :hint='namespacing ? $t("admin:locale.autoUpdate.hintWithNS") : $t("admin:locale.autoUpdate.hint")'
  41. )
  42. v-card-chin
  43. v-spacer
  44. v-btn(color='primary', :loading='loading', @click='save')
  45. v-icon(left) chevron_right
  46. span {{ $t('common:actions.save') }}
  47. v-card.mt-3
  48. v-toolbar(color='primary', dark, dense, flat)
  49. v-toolbar-title
  50. .subheading {{ $t('admin:locale.namespacing') }}
  51. v-card-text
  52. v-switch(
  53. v-model='namespacing'
  54. :label='$t("admin:locale.namespaces.label")'
  55. color='primary'
  56. persistent-hint
  57. :hint='$t("admin:locale.namespaces.hint")'
  58. )
  59. v-alert.mt-3(
  60. outline
  61. color='orange'
  62. :value='true'
  63. icon='warning'
  64. )
  65. span {{ $t('admin:locale.namespacingPrefixWarning.title', { langCode: selectedLocale }) }}
  66. .caption.grey--text {{ $t('admin:locale.namespacingPrefixWarning.subtitle') }}
  67. v-divider.mt-3.mb-4
  68. v-select(
  69. :disabled='!namespacing'
  70. :items='installedLocales'
  71. prepend-icon='language'
  72. multiple
  73. chips
  74. deletable-chips
  75. v-model='namespaces'
  76. item-value='code'
  77. item-text='name'
  78. :label='$t("admin:locale.activeNamespaces.label")'
  79. persistent-hint
  80. :hint='$t("admin:locale.activeNamespaces.hint")'
  81. )
  82. template(slot='item', slot-scope='data')
  83. template(v-if='typeof data.item !== "object"')
  84. v-list-tile-content(v-text='data.item')
  85. template(v-else)
  86. v-list-tile-avatar
  87. v-avatar.blue.white--text(tile, size='40', v-html='data.item.code.toUpperCase()')
  88. v-list-tile-content
  89. v-list-tile-title(v-html='data.item.name')
  90. v-list-tile-sub-title(v-html='data.item.nativeName')
  91. v-list-tile-action
  92. v-checkbox(:input-value='data.tile.props.value', color='primary', value)
  93. v-card-chin
  94. v-spacer
  95. v-btn(color='primary', :loading='loading', @click='save')
  96. v-icon(left) chevron_right
  97. span {{ $t('common:actions.save') }}
  98. v-flex(lg6 xs12)
  99. v-card
  100. v-toolbar(color='teal', dark, dense, flat)
  101. v-toolbar-title
  102. .subheading {{ $t('admin:locale.download') }}
  103. v-list(two-line, dense)
  104. template(v-for='(lc, idx) in locales')
  105. v-list-tile(:key='lc.code')
  106. v-list-tile-avatar
  107. v-avatar.teal.white--text(size='40') {{lc.code.toUpperCase()}}
  108. v-list-tile-content
  109. v-list-tile-title(v-html='lc.name')
  110. v-list-tile-sub-title(v-html='lc.nativeName')
  111. v-list-tile-action(v-if='lc.isRTL')
  112. v-chip(label, small).caption.grey--text.text--darken-2 RTL
  113. v-list-tile-action(v-if='lc.isInstalled && lc.installDate < lc.updatedAt', @click='download(lc.code)')
  114. v-icon.blue--text cached
  115. v-list-tile-action(v-else-if='lc.isInstalled')
  116. v-icon.green--text check
  117. v-list-tile-action(v-else-if='lc.isDownloading')
  118. v-progress-circular(indeterminate, color='blue', size='20', :width='3')
  119. v-list-tile-action(v-else)
  120. v-btn(icon, @click='download(lc)')
  121. v-icon.grey--text cloud_download
  122. v-divider.my-0(inset, v-if='idx < locales.length - 1')
  123. </template>
  124. <script>
  125. import _ from 'lodash'
  126. /* global WIKI */
  127. import localesQuery from 'gql/admin/locale/locale-query-list.gql'
  128. import localesDownloadMutation from 'gql/admin/locale/locale-mutation-download.gql'
  129. import localesSaveMutation from 'gql/admin/locale/locale-mutation-save.gql'
  130. export default {
  131. data() {
  132. return {
  133. loading: false,
  134. locales: [],
  135. selectedLocale: 'en',
  136. autoUpdate: false,
  137. namespacing: false,
  138. namespaces: []
  139. }
  140. },
  141. computed: {
  142. installedLocales() {
  143. return _.filter(this.locales, ['isInstalled', true])
  144. }
  145. },
  146. methods: {
  147. async download(lc) {
  148. lc.isDownloading = true
  149. const respRaw = await this.$apollo.mutate({
  150. mutation: localesDownloadMutation,
  151. variables: {
  152. locale: lc.code
  153. }
  154. })
  155. const resp = _.get(respRaw, 'data.localization.downloadLocale.responseResult', {})
  156. if (resp.succeeded) {
  157. lc.isDownloading = false
  158. lc.isInstalled = true
  159. this.$store.commit('showNotification', {
  160. message: `Locale ${lc.name} has been installed successfully.`,
  161. style: 'success',
  162. icon: 'get_app'
  163. })
  164. } else {
  165. this.$store.commit('showNotification', {
  166. message: `Error: ${resp.message}`,
  167. style: 'error',
  168. icon: 'warning'
  169. })
  170. }
  171. this.isDownloading = false
  172. },
  173. async save() {
  174. this.loading = true
  175. const respRaw = await this.$apollo.mutate({
  176. mutation: localesSaveMutation,
  177. variables: {
  178. locale: this.selectedLocale,
  179. autoUpdate: this.autoUpdate,
  180. namespacing: this.namespacing,
  181. namespaces: this.namespaces
  182. }
  183. })
  184. const resp = _.get(respRaw, 'data.localization.updateLocale.responseResult', {})
  185. if (resp.succeeded) {
  186. WIKI.$i18n.i18next.changeLanguage(this.selectedLocale)
  187. WIKI.$moment.locale(this.selectedLocale)
  188. this.$store.commit('showNotification', {
  189. message: 'Locale settings updated successfully.',
  190. style: 'success',
  191. icon: 'check'
  192. })
  193. } else {
  194. this.$store.commit('showNotification', {
  195. message: `Error: ${resp.message}`,
  196. style: 'error',
  197. icon: 'warning'
  198. })
  199. }
  200. this.loading = false
  201. }
  202. },
  203. apollo: {
  204. locales: {
  205. query: localesQuery,
  206. fetchPolicy: 'network-only',
  207. update: (data) => data.localization.locales.map(lc => ({ ...lc, isDownloading: false })),
  208. watchLoading (isLoading) {
  209. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-locale-refresh')
  210. }
  211. },
  212. selectedLocale: {
  213. query: localesQuery,
  214. update: (data) => data.localization.config.locale
  215. },
  216. autoUpdate: {
  217. query: localesQuery,
  218. update: (data) => data.localization.config.autoUpdate
  219. },
  220. namespacing: {
  221. query: localesQuery,
  222. update: (data) => data.localization.config.namespacing
  223. },
  224. namespaces: {
  225. query: localesQuery,
  226. update: (data) => data.localization.config.namespaces
  227. }
  228. }
  229. }
  230. </script>