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.

237 lines
9.1 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(src='/svg/icon-globe-earth.svg', alt='Locale', style='width: 80px;')
  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-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
  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).caption.grey--text.text--darken-2 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. </template>
  126. <script>
  127. import _ from 'lodash'
  128. /* global WIKI */
  129. import localesQuery from 'gql/admin/locale/locale-query-list.gql'
  130. import localesDownloadMutation from 'gql/admin/locale/locale-mutation-download.gql'
  131. import localesSaveMutation from 'gql/admin/locale/locale-mutation-save.gql'
  132. export default {
  133. data() {
  134. return {
  135. loading: false,
  136. locales: [],
  137. selectedLocale: 'en',
  138. autoUpdate: false,
  139. namespacing: false,
  140. namespaces: []
  141. }
  142. },
  143. computed: {
  144. installedLocales() {
  145. return _.filter(this.locales, ['isInstalled', true])
  146. }
  147. },
  148. methods: {
  149. async download(lc) {
  150. lc.isDownloading = true
  151. const respRaw = await this.$apollo.mutate({
  152. mutation: localesDownloadMutation,
  153. variables: {
  154. locale: lc.code
  155. }
  156. })
  157. const resp = _.get(respRaw, 'data.localization.downloadLocale.responseResult', {})
  158. if (resp.succeeded) {
  159. lc.isDownloading = false
  160. lc.isInstalled = true
  161. this.$store.commit('showNotification', {
  162. message: `Locale ${lc.name} has been installed successfully.`,
  163. style: 'success',
  164. icon: 'get_app'
  165. })
  166. } else {
  167. this.$store.commit('showNotification', {
  168. message: `Error: ${resp.message}`,
  169. style: 'error',
  170. icon: 'warning'
  171. })
  172. }
  173. this.isDownloading = false
  174. },
  175. async save() {
  176. this.loading = true
  177. const respRaw = await this.$apollo.mutate({
  178. mutation: localesSaveMutation,
  179. variables: {
  180. locale: this.selectedLocale,
  181. autoUpdate: this.autoUpdate,
  182. namespacing: this.namespacing,
  183. namespaces: this.namespaces
  184. }
  185. })
  186. const resp = _.get(respRaw, 'data.localization.updateLocale.responseResult', {})
  187. if (resp.succeeded) {
  188. WIKI.$i18n.i18next.changeLanguage(this.selectedLocale)
  189. WIKI.$moment.locale(this.selectedLocale)
  190. this.$store.commit('showNotification', {
  191. message: 'Locale settings updated successfully.',
  192. style: 'success',
  193. icon: 'check'
  194. })
  195. } else {
  196. this.$store.commit('showNotification', {
  197. message: `Error: ${resp.message}`,
  198. style: 'error',
  199. icon: 'warning'
  200. })
  201. }
  202. this.loading = false
  203. }
  204. },
  205. apollo: {
  206. locales: {
  207. query: localesQuery,
  208. fetchPolicy: 'network-only',
  209. update: (data) => data.localization.locales.map(lc => ({ ...lc, isDownloading: false })),
  210. watchLoading (isLoading) {
  211. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-locale-refresh')
  212. }
  213. },
  214. selectedLocale: {
  215. query: localesQuery,
  216. update: (data) => data.localization.config.locale
  217. },
  218. autoUpdate: {
  219. query: localesQuery,
  220. update: (data) => data.localization.config.autoUpdate
  221. },
  222. namespacing: {
  223. query: localesQuery,
  224. update: (data) => data.localization.config.namespacing
  225. },
  226. namespaces: {
  227. query: localesQuery,
  228. update: (data) => data.localization.config.namespaces
  229. }
  230. }
  231. }
  232. </script>