admin-locale.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template lang='pug'>
  2. v-container(fluid, fill-height, grid-list-lg)
  3. v-layout(row wrap)
  4. v-flex(xs12)
  5. .admin-header-icon: v-icon(size='80', color='grey lighten-2') language
  6. .headline.primary--text {{ $t('admin:locale.title') }}
  7. .subheading.grey--text {{ $t('admin:locale.subtitle') }}
  8. v-form.pt-3
  9. v-layout(row wrap)
  10. v-flex(lg6 xs12)
  11. v-card
  12. v-toolbar(color='primary', dark, dense, flat)
  13. v-toolbar-title
  14. .subheading {{ $t('admin:locale.settings') }}
  15. v-card-text
  16. v-select(
  17. :items='installedLocales'
  18. prepend-icon='language'
  19. v-model='selectedLocale'
  20. item-value='code'
  21. item-text='nativeName'
  22. :label='namespacing ? $t("admin:locale.base.labelWithNS") : $t("admin:locale.base.label")'
  23. persistent-hint
  24. :hint='$t("admin:locale.base.hint")'
  25. )
  26. template(slot='item', slot-scope='data')
  27. template(v-if='typeof data.item !== "object"')
  28. v-list-tile-content(v-text='data.item')
  29. template(v-else)
  30. v-list-tile-avatar
  31. v-avatar.blue.white--text(tile, size='40', v-html='data.item.code.toUpperCase()')
  32. v-list-tile-content
  33. v-list-tile-title(v-html='data.item.name')
  34. v-list-tile-sub-title(v-html='data.item.nativeName')
  35. v-divider.mt-3
  36. v-switch(
  37. v-model='autoUpdate'
  38. :label='$t("admin:locale.autoUpdate.label")'
  39. color='primary'
  40. persistent-hint
  41. :hint='namespacing ? $t("admin:locale.autoUpdate.hintWithNS") : $t("admin:locale.autoUpdate.hint")'
  42. )
  43. v-card-chin
  44. v-spacer
  45. v-btn(color='primary', :loading='loading', @click='save')
  46. v-icon(left) chevron_right
  47. span {{ $t('common:actions.save') }}
  48. v-card.mt-3
  49. v-toolbar(color='primary', dark, dense, flat)
  50. v-toolbar-title
  51. .subheading {{ $t('admin:locale.namespacing') }}
  52. v-card-text
  53. v-switch(
  54. v-model='namespacing'
  55. :label='$t("admin:locale.namespaces.label")'
  56. color='primary'
  57. persistent-hint
  58. :hint='$t("admin:locale.namespaces.hint")'
  59. )
  60. v-alert.mt-3(
  61. outline
  62. color='orange'
  63. :value='true'
  64. icon='warning'
  65. )
  66. span {{ $t('admin:locale.namespacingPrefixWarning.title', { langCode: selectedLocale }) }}
  67. .caption.grey--text {{ $t('admin:locale.namespacingPrefixWarning.subtitle') }}
  68. v-divider.mt-3.mb-4
  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='$t("admin:locale.activeNamespaces.label")'
  80. persistent-hint
  81. :hint='$t("admin:locale.activeNamespaces.hint")'
  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-card-chin
  95. v-spacer
  96. v-btn(color='primary', :loading='loading', @click='save')
  97. v-icon(left) chevron_right
  98. span {{ $t('common:actions.save') }}
  99. v-flex(lg6 xs12)
  100. v-card
  101. v-toolbar(color='teal', dark, dense, flat)
  102. v-toolbar-title
  103. .subheading {{ $t('admin:locale.download') }}
  104. v-list(two-line, dense)
  105. template(v-for='(lc, idx) in locales')
  106. v-list-tile(:key='lc.code')
  107. v-list-tile-avatar
  108. v-avatar.teal.white--text(size='40') {{lc.code.toUpperCase()}}
  109. v-list-tile-content
  110. v-list-tile-title(v-html='lc.name')
  111. v-list-tile-sub-title(v-html='lc.nativeName')
  112. v-list-tile-action(v-if='lc.isRTL')
  113. v-chip(label, small).caption.grey--text.text--darken-2 RTL
  114. v-list-tile-action(v-if='lc.isInstalled && lc.installDate < lc.updatedAt', @click='download(lc.code)')
  115. v-icon.blue--text cached
  116. v-list-tile-action(v-else-if='lc.isInstalled')
  117. v-icon.green--text check
  118. v-list-tile-action(v-else-if='lc.isDownloading')
  119. v-progress-circular(indeterminate, color='blue', size='20', :width='3')
  120. v-list-tile-action(v-else)
  121. v-btn(icon, @click='download(lc)')
  122. v-icon.grey--text cloud_download
  123. v-divider.my-0(inset, v-if='idx < locales.length - 1')
  124. </template>
  125. <script>
  126. import _ from 'lodash'
  127. /* global WIKI */
  128. import localesQuery from 'gql/admin/locale/locale-query-list.gql'
  129. import localesDownloadMutation from 'gql/admin/locale/locale-mutation-download.gql'
  130. import localesSaveMutation from 'gql/admin/locale/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. WIKI.$i18n.i18next.changeLanguage(this.selectedLocale)
  188. WIKI.$moment.locale(this.selectedLocale)
  189. this.$store.commit('showNotification', {
  190. message: 'Locale settings updated successfully.',
  191. style: 'success',
  192. icon: 'check'
  193. })
  194. } else {
  195. this.$store.commit('showNotification', {
  196. message: `Error: ${resp.message}`,
  197. style: 'error',
  198. icon: 'warning'
  199. })
  200. }
  201. this.loading = false
  202. }
  203. },
  204. apollo: {
  205. locales: {
  206. query: localesQuery,
  207. fetchPolicy: 'network-only',
  208. update: (data) => data.localization.locales.map(lc => ({ ...lc, isDownloading: false })),
  209. watchLoading (isLoading) {
  210. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-locale-refresh')
  211. }
  212. },
  213. selectedLocale: {
  214. query: localesQuery,
  215. update: (data) => data.localization.config.locale
  216. },
  217. autoUpdate: {
  218. query: localesQuery,
  219. update: (data) => data.localization.config.autoUpdate
  220. },
  221. namespacing: {
  222. query: localesQuery,
  223. update: (data) => data.localization.config.namespacing
  224. },
  225. namespaces: {
  226. query: localesQuery,
  227. update: (data) => data.localization.config.namespaces
  228. }
  229. }
  230. }
  231. </script>