admin-locale.vue 9.0 KB

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