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.

246 lines
9.8 KiB

  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', @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. v-card.wiki-form.mt-3.animated.fadeInUp.wait-p5s
  126. v-toolbar(color='teal', dark, dense, flat)
  127. v-toolbar-title
  128. .subheading {{ $t('admin:locale.sideload') }}
  129. v-spacer
  130. v-chip(label, color='white', small).teal--text coming soon
  131. v-card-text
  132. div {{ $t('admin:locale.sideloadHelp') }}
  133. v-btn.ml-0.mt-3(color='teal', disabled) {{ $t('common:actions.browse') }}
  134. </template>
  135. <script>
  136. import _ from 'lodash'
  137. /* global WIKI */
  138. import localesQuery from 'gql/admin/locale/locale-query-list.gql'
  139. import localesDownloadMutation from 'gql/admin/locale/locale-mutation-download.gql'
  140. import localesSaveMutation from 'gql/admin/locale/locale-mutation-save.gql'
  141. export default {
  142. data() {
  143. return {
  144. loading: false,
  145. locales: [],
  146. selectedLocale: 'en',
  147. autoUpdate: false,
  148. namespacing: false,
  149. namespaces: []
  150. }
  151. },
  152. computed: {
  153. installedLocales() {
  154. return _.filter(this.locales, ['isInstalled', true])
  155. }
  156. },
  157. methods: {
  158. async download(lc) {
  159. lc.isDownloading = true
  160. const respRaw = await this.$apollo.mutate({
  161. mutation: localesDownloadMutation,
  162. variables: {
  163. locale: lc.code
  164. }
  165. })
  166. const resp = _.get(respRaw, 'data.localization.downloadLocale.responseResult', {})
  167. if (resp.succeeded) {
  168. lc.isDownloading = false
  169. lc.isInstalled = true
  170. this.$store.commit('showNotification', {
  171. message: `Locale ${lc.name} has been installed successfully.`,
  172. style: 'success',
  173. icon: 'get_app'
  174. })
  175. } else {
  176. this.$store.commit('showNotification', {
  177. message: `Error: ${resp.message}`,
  178. style: 'error',
  179. icon: 'warning'
  180. })
  181. }
  182. this.isDownloading = false
  183. },
  184. async save() {
  185. this.loading = true
  186. const respRaw = await this.$apollo.mutate({
  187. mutation: localesSaveMutation,
  188. variables: {
  189. locale: this.selectedLocale,
  190. autoUpdate: this.autoUpdate,
  191. namespacing: this.namespacing,
  192. namespaces: this.namespaces
  193. }
  194. })
  195. const resp = _.get(respRaw, 'data.localization.updateLocale.responseResult', {})
  196. if (resp.succeeded) {
  197. WIKI.$i18n.i18next.changeLanguage(this.selectedLocale)
  198. WIKI.$moment.locale(this.selectedLocale)
  199. this.$store.commit('showNotification', {
  200. message: 'Locale settings updated successfully.',
  201. style: 'success',
  202. icon: 'check'
  203. })
  204. } else {
  205. this.$store.commit('showNotification', {
  206. message: `Error: ${resp.message}`,
  207. style: 'error',
  208. icon: 'warning'
  209. })
  210. }
  211. this.loading = false
  212. }
  213. },
  214. apollo: {
  215. locales: {
  216. query: localesQuery,
  217. fetchPolicy: 'network-only',
  218. update: (data) => data.localization.locales.map(lc => ({ ...lc, isDownloading: false })),
  219. watchLoading (isLoading) {
  220. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-locale-refresh')
  221. }
  222. },
  223. selectedLocale: {
  224. query: localesQuery,
  225. update: (data) => data.localization.config.locale
  226. },
  227. autoUpdate: {
  228. query: localesQuery,
  229. update: (data) => data.localization.config.autoUpdate
  230. },
  231. namespacing: {
  232. query: localesQuery,
  233. update: (data) => data.localization.config.namespacing
  234. },
  235. namespaces: {
  236. query: localesQuery,
  237. update: (data) => data.localization.config.namespaces
  238. }
  239. }
  240. }
  241. </script>