admin-locale.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row, wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img.animated.fadeInUp(src='/svg/icon-globe-earth.svg', alt='Locale', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{ $t('admin:locale.title') }}
  9. .subheading.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:locale.subtitle') }}
  10. v-spacer
  11. v-btn.animated.fadeInDown(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.animated.fadeInUp
  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.animated.fadeInUp.wait-p2s
  51. v-toolbar(color='primary', dark, dense, flat)
  52. v-toolbar-title
  53. .subheading {{ $t('admin:locale.namespacing') }}
  54. v-spacer
  55. v-chip(label, color='white', small).primary--text coming soon
  56. v-card-text
  57. v-switch(
  58. v-model='namespacing'
  59. :label='$t("admin:locale.namespaces.label")'
  60. color='primary'
  61. persistent-hint
  62. :hint='$t("admin:locale.namespaces.hint")'
  63. )
  64. v-alert.mt-3(
  65. outline
  66. color='orange'
  67. :value='true'
  68. icon='warning'
  69. )
  70. span {{ $t('admin:locale.namespacingPrefixWarning.title', { langCode: selectedLocale }) }}
  71. .caption.grey--text {{ $t('admin:locale.namespacingPrefixWarning.subtitle') }}
  72. v-divider.mt-3.mb-4
  73. v-select(
  74. outline
  75. :disabled='!namespacing'
  76. :items='installedLocales'
  77. prepend-icon='language'
  78. multiple
  79. chips
  80. deletable-chips
  81. v-model='namespaces'
  82. item-value='code'
  83. item-text='name'
  84. :label='$t("admin:locale.activeNamespaces.label")'
  85. persistent-hint
  86. small-chips
  87. :hint='$t("admin:locale.activeNamespaces.hint")'
  88. )
  89. template(slot='item', slot-scope='data')
  90. template(v-if='typeof data.item !== "object"')
  91. v-list-tile-content(v-text='data.item')
  92. template(v-else)
  93. v-list-tile-avatar
  94. v-avatar.blue.white--text(tile, size='40', v-html='data.item.code.toUpperCase()')
  95. v-list-tile-content
  96. v-list-tile-title(v-html='data.item.name')
  97. v-list-tile-sub-title(v-html='data.item.nativeName')
  98. v-list-tile-action
  99. v-checkbox(:input-value='data.tile.props.value', color='primary', value)
  100. v-flex(lg6 xs12)
  101. v-card.animated.fadeInUp.wait-p4s
  102. v-toolbar(color='teal', dark, dense, flat)
  103. v-toolbar-title
  104. .subheading {{ $t('admin:locale.download') }}
  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, :class='$vuetify.dark ? `text--lighten-5` : `text--darken-2`').caption.grey--text RTL
  115. v-list-tile-action(v-if='lc.isInstalled && lc.installDate < lc.updatedAt')
  116. v-btn(icon, @click='download(lc)')
  117. v-icon.blue--text cached
  118. v-list-tile-action(v-else-if='lc.isInstalled')
  119. v-icon.green--text check
  120. v-list-tile-action(v-else-if='lc.isDownloading')
  121. v-progress-circular(indeterminate, color='blue', size='20', :width='3')
  122. v-list-tile-action(v-else)
  123. v-btn(icon, @click='download(lc)')
  124. v-icon.grey--text cloud_download
  125. v-divider.my-0(inset, v-if='idx < locales.length - 1')
  126. v-card.wiki-form.mt-3.animated.fadeInUp.wait-p5s
  127. v-toolbar(color='teal', dark, dense, flat)
  128. v-toolbar-title
  129. .subheading {{ $t('admin:locale.sideload') }}
  130. v-spacer
  131. v-chip(label, color='white', small).teal--text coming soon
  132. v-card-text
  133. div {{ $t('admin:locale.sideloadHelp') }}
  134. v-btn.ml-0.mt-3(color='teal', disabled) {{ $t('common:actions.browse') }}
  135. </template>
  136. <script>
  137. import _ from 'lodash'
  138. /* global WIKI */
  139. import localesQuery from 'gql/admin/locale/locale-query-list.gql'
  140. import localesDownloadMutation from 'gql/admin/locale/locale-mutation-download.gql'
  141. import localesSaveMutation from 'gql/admin/locale/locale-mutation-save.gql'
  142. export default {
  143. data() {
  144. return {
  145. loading: false,
  146. locales: [],
  147. selectedLocale: 'en',
  148. autoUpdate: false,
  149. namespacing: false,
  150. namespaces: []
  151. }
  152. },
  153. computed: {
  154. installedLocales() {
  155. return _.filter(this.locales, ['isInstalled', true])
  156. }
  157. },
  158. methods: {
  159. async download(lc) {
  160. lc.isDownloading = true
  161. const respRaw = await this.$apollo.mutate({
  162. mutation: localesDownloadMutation,
  163. variables: {
  164. locale: lc.code
  165. }
  166. })
  167. const resp = _.get(respRaw, 'data.localization.downloadLocale.responseResult', {})
  168. if (resp.succeeded) {
  169. lc.isDownloading = false
  170. lc.isInstalled = true
  171. this.$store.commit('showNotification', {
  172. message: `Locale ${lc.name} has been installed successfully.`,
  173. style: 'success',
  174. icon: 'get_app'
  175. })
  176. } else {
  177. this.$store.commit('showNotification', {
  178. message: `Error: ${resp.message}`,
  179. style: 'error',
  180. icon: 'warning'
  181. })
  182. }
  183. this.isDownloading = false
  184. },
  185. async save() {
  186. this.loading = true
  187. const respRaw = await this.$apollo.mutate({
  188. mutation: localesSaveMutation,
  189. variables: {
  190. locale: this.selectedLocale,
  191. autoUpdate: this.autoUpdate,
  192. namespacing: this.namespacing,
  193. namespaces: this.namespaces
  194. }
  195. })
  196. const resp = _.get(respRaw, 'data.localization.updateLocale.responseResult', {})
  197. if (resp.succeeded) {
  198. // Change UI language
  199. WIKI.$i18n.i18next.changeLanguage(this.selectedLocale)
  200. WIKI.$moment.locale(this.selectedLocale)
  201. // Check for RTL
  202. const curLocale = _.find(this.locales, ['code', this.selectedLocale])
  203. this.$vuetify.rtl = curLocale && curLocale.isRTL
  204. this.$store.commit('showNotification', {
  205. message: 'Locale settings updated successfully.',
  206. style: 'success',
  207. icon: 'check'
  208. })
  209. } else {
  210. this.$store.commit('showNotification', {
  211. message: `Error: ${resp.message}`,
  212. style: 'error',
  213. icon: 'warning'
  214. })
  215. }
  216. this.loading = false
  217. }
  218. },
  219. apollo: {
  220. locales: {
  221. query: localesQuery,
  222. fetchPolicy: 'network-only',
  223. update: (data) => data.localization.locales.map(lc => ({ ...lc, isDownloading: false })),
  224. watchLoading (isLoading) {
  225. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-locale-refresh')
  226. }
  227. },
  228. selectedLocale: {
  229. query: localesQuery,
  230. update: (data) => data.localization.config.locale
  231. },
  232. autoUpdate: {
  233. query: localesQuery,
  234. update: (data) => data.localization.config.autoUpdate
  235. },
  236. namespacing: {
  237. query: localesQuery,
  238. update: (data) => data.localization.config.namespacing
  239. },
  240. namespaces: {
  241. query: localesQuery,
  242. update: (data) => data.localization.config.namespaces
  243. }
  244. }
  245. }
  246. </script>