admin-locale.vue 11.5 KB
Newer Older
1
<template lang='pug'>
2 3
  v-container(fluid, grid-list-lg)
    v-layout(row, wrap)
4
      v-flex(xs12)
5
        .admin-header
6
          img.animated.fadeInUp(src='/_assets/svg/icon-globe-earth.svg', alt='Locale', style='width: 80px;')
7
          .admin-header-title
Nick's avatar
Nick committed
8
            .headline.primary--text.animated.fadeInLeft {{ $t('admin:locale.title') }}
9
            .subtitle-1.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:locale.subtitle') }}
10
          v-spacer
11 12 13
          v-btn.animated.fadeInDown.wait-p3s(icon, outlined, color='grey', href='https://docs.requarks.io/locales', target='_blank')
            v-icon mdi-help-circle
          v-btn.animated.fadeInDown.ml-3(color='success', depressed, @click='save', large, :loading='loading')
14
            v-icon(left) mdi-check
15
            span {{$t('common:actions.apply')}}
16 17
        v-form.pt-3
          v-layout(row wrap)
18
            v-flex(xl6 lg5 xs12)
Nick's avatar
Nick committed
19
              v-card.wiki-form.animated.fadeInUp
20
                v-toolbar(color='primary', dark, dense, flat)
21
                  v-toolbar-title.subtitle-1 {{ $t('admin:locale.settings') }}
22
                v-card-text
23
                  v-select(
24
                    outlined
25
                    :items='installedLocales'
26
                    prepend-icon='mdi-web'
27
                    v-model='selectedLocale'
28
                    item-value='code'
29 30
                    item-text='nativeName'
                    :label='namespacing ? $t("admin:locale.base.labelWithNS") : $t("admin:locale.base.label")'
31
                    persistent-hint
32
                    :hint='$t("admin:locale.base.hint")'
33
                  )
34
                    template(slot='item', slot-scope='data')
35
                      template(v-if='typeof data.item !== "object"')
36
                        v-list-item-content(v-text='data.item')
37
                      template(v-else)
38
                        v-list-item-avatar
39
                          v-avatar.blue.white--text(tile, size='40', v-html='data.item.code.toUpperCase()')
40 41
                        v-list-item-content
                          v-list-item-title(v-html='data.item.name')
42
                          v-list-item-subtitle(v-html='data.item.nativeName')
43
                  v-divider.mt-3
44
                  v-switch(
45
                    inset
46
                    v-model='autoUpdate'
47
                    :label='$t("admin:locale.autoUpdate.label")'
48 49
                    color='primary'
                    persistent-hint
50
                    :hint='namespacing ? $t("admin:locale.autoUpdate.hintWithNS") : $t("admin:locale.autoUpdate.hint")'
51
                  )
52

Nick's avatar
Nick committed
53
              v-card.wiki-form.mt-3.animated.fadeInUp.wait-p2s
54
                v-toolbar(color='primary', dark, dense, flat)
55
                  v-toolbar-title.subtitle-1 {{ $t('admin:locale.namespacing') }}
56 57
                v-card-text
                  v-switch(
58
                    inset
59
                    v-model='namespacing'
60
                    :label='$t("admin:locale.namespaces.label")'
61 62
                    color='primary'
                    persistent-hint
63
                    :hint='$t("admin:locale.namespaces.hint")'
64 65
                    )
                  v-alert.mt-3(
66
                    outlined
67 68
                    color='orange'
                    :value='true'
69
                    icon='mdi-alert'
70
                    )
71 72
                    span {{ $t('admin:locale.namespacingPrefixWarning.title', { langCode: selectedLocale }) }}
                    .caption.grey--text {{ $t('admin:locale.namespacingPrefixWarning.subtitle') }}
73
                  v-divider.mt-3.mb-4
74
                  v-select(
75
                    outlined
76 77
                    :disabled='!namespacing'
                    :items='installedLocales'
78
                    prepend-icon='mdi-web'
79 80 81 82 83 84
                    multiple
                    chips
                    deletable-chips
                    v-model='namespaces'
                    item-value='code'
                    item-text='name'
85
                    :label='$t("admin:locale.activeNamespaces.label")'
86
                    persistent-hint
87
                    small-chips
88
                    :hint='$t("admin:locale.activeNamespaces.hint")'
89 90 91
                    )
                    template(slot='item', slot-scope='data')
                      template(v-if='typeof data.item !== "object"')
92
                        v-list-item-content(v-text='data.item')
93
                      template(v-else)
94
                        v-list-item-avatar
95
                          v-avatar.blue.white--text(tile, size='40', v-html='data.item.code.toUpperCase()')
96 97
                        v-list-item-content
                          v-list-item-title(v-html='data.item.name')
98
                          v-list-item-subtitle(v-html='data.item.nativeName')
99
                        v-list-item-action
100
                          v-checkbox(:input-value='data.attrs.inputValue', color='primary', value)
101
            v-flex(xl6 lg7 xs12)
Nick's avatar
Nick committed
102
              v-card.animated.fadeInUp.wait-p4s
103
                v-toolbar(color='teal', dark, dense, flat)
104
                  v-toolbar-title.subtitle-1 {{ $t('admin:locale.downloadTitle') }}
105 106 107
                v-data-table(
                  :headers='headers',
                  :items='locales',
108
                  hide-default-footer,
109
                  item-key='code',
110 111 112 113 114 115 116 117 118 119 120
                  :items-per-page='1000'
                  )
                  template(v-slot:item.code='{ item }')
                    v-chip.white--text(label, color='teal', small) {{item.code}}
                  template(v-slot:item.name='{ item }')
                    strong {{item.name}}
                  template(v-slot:item.isRTL='{ item }')
                    v-icon(v-if='item.isRTL') mdi-check
                  template(v-slot:item.availability='{ item }')
                    .d-flex.align-center.pl-4
                      v-progress-circular(:value='item.availability', width='2', size='20', :color='item.availability <= 33 ? `red` : (item.availability <= 66) ? `orange` : `green`')
Nick's avatar
Nick committed
121
                      .caption.mx-2(:class='item.availability <= 33 ? `red--text` : (item.availability <= 66) ? `orange--text` : `green--text`') {{item.availability}}%
122 123
                  template(v-slot:item.isInstalled='{ item }')
                    v-progress-circular(v-if='item.isDownloading', indeterminate, color='blue', size='20', :width='2')
Nick's avatar
Nick committed
124
                    v-btn(v-else-if='item.isInstalled && item.installDate < item.updatedAt', icon, small, @click='download(item)')
125
                      v-icon.blue--text mdi-cached
Nick's avatar
Nick committed
126
                    v-btn(v-else-if='item.isInstalled', icon, small, @click='download(item)')
Nick's avatar
Nick committed
127
                      v-icon.green--text mdi-check-bold
128 129
                    v-btn(v-else, icon, small, @click='download(item)')
                      v-icon.grey--text mdi-cloud-download
130 131
              v-card.wiki-form.mt-3.animated.fadeInUp.wait-p5s
                v-toolbar(color='teal', dark, dense, flat)
132
                  v-toolbar-title.subtitle-1 {{ $t('admin:locale.sideload') }}
133 134 135 136 137
                  v-spacer
                  v-chip(label, color='white', small).teal--text coming soon
                v-card-text
                  div {{ $t('admin:locale.sideloadHelp') }}
                  v-btn.ml-0.mt-3(color='teal', disabled) {{ $t('common:actions.browse') }}
138 139 140
</template>

<script>
141 142
import _ from 'lodash'

143 144
/* global WIKI */

145 146 147
import localesQuery from 'gql/admin/locale/locale-query-list.gql'
import localesDownloadMutation from 'gql/admin/locale/locale-mutation-download.gql'
import localesSaveMutation from 'gql/admin/locale/locale-mutation-save.gql'
148

149 150 151
export default {
  data() {
    return {
152
      loading: false,
153
      locales: [],
154
      selectedLocale: 'en',
155 156 157
      autoUpdate: false,
      namespacing: false,
      namespaces: []
158 159 160 161 162
    }
  },
  computed: {
    installedLocales() {
      return _.filter(this.locales, ['isInstalled', true])
163 164 165 166 167 168 169
    },
    headers() {
      return [
        {
          text: this.$t('admin:locale.code'),
          align: 'left',
          value: 'code',
170
          width: 90
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
        },
        {
          text: this.$t('admin:locale.name'),
          align: 'left',
          value: 'name'
        },
        {
          text: this.$t('admin:locale.nativeName'),
          align: 'left',
          value: 'nativeName'
        },
        {
          text: this.$t('admin:locale.rtl'),
          align: 'center',
          value: 'isRTL',
          sortable: false,
          width: 10
        },
        {
          text: this.$t('admin:locale.availability'),
          align: 'center',
          value: 'availability',
193
          sortable: false,
194
          width: 120
195 196 197 198
        },
        {
          text: this.$t('admin:locale.download'),
          align: 'center',
199
          value: 'isInstalled',
200 201 202 203
          sortable: false,
          width: 100
        }
      ]
204 205
    }
  },
206
  methods: {
207 208 209 210 211 212 213 214 215 216 217 218
    async download(lc) {
      lc.isDownloading = true
      const respRaw = await this.$apollo.mutate({
        mutation: localesDownloadMutation,
        variables: {
          locale: lc.code
        }
      })
      const resp = _.get(respRaw, 'data.localization.downloadLocale.responseResult', {})
      if (resp.succeeded) {
        lc.isDownloading = false
        lc.isInstalled = true
219 220
        lc.updatedAt = new Date().toISOString()
        lc.installDate = lc.updatedAt
221 222 223 224 225 226 227 228 229 230 231 232 233 234
        this.$store.commit('showNotification', {
          message: `Locale ${lc.name} has been installed successfully.`,
          style: 'success',
          icon: 'get_app'
        })
      } else {
        this.$store.commit('showNotification', {
          message: `Error: ${resp.message}`,
          style: 'error',
          icon: 'warning'
        })
      }
      this.isDownloading = false
    },
235 236 237
    async save() {
      this.loading = true
      const respRaw = await this.$apollo.mutate({
238
        mutation: localesSaveMutation,
239 240
        variables: {
          locale: this.selectedLocale,
241 242 243
          autoUpdate: this.autoUpdate,
          namespacing: this.namespacing,
          namespaces: this.namespaces
244 245 246 247
        }
      })
      const resp = _.get(respRaw, 'data.localization.updateLocale.responseResult', {})
      if (resp.succeeded) {
248
        // Change UI language
249
        WIKI.$i18n.i18next.changeLanguage(this.selectedLocale)
250
        WIKI.$moment.locale(this.selectedLocale)
251 252 253 254 255

        // Check for RTL
        const curLocale = _.find(this.locales, ['code', this.selectedLocale])
        this.$vuetify.rtl = curLocale && curLocale.isRTL

256 257 258 259 260
        this.$store.commit('showNotification', {
          message: 'Locale settings updated successfully.',
          style: 'success',
          icon: 'check'
        })
261 262 263

        _.delay(() => {
          window.location.reload(true)
Nick's avatar
Nick committed
264
        }, 1000)
265 266 267 268 269 270 271 272 273 274
      } else {
        this.$store.commit('showNotification', {
          message: `Error: ${resp.message}`,
          style: 'error',
          icon: 'warning'
        })
      }
      this.loading = false
    }
  },
275 276 277
  apollo: {
    locales: {
      query: localesQuery,
278
      fetchPolicy: 'network-only',
279
      update: (data) => data.localization.locales.map(lc => ({ ...lc, isDownloading: false })),
280 281 282
      watchLoading (isLoading) {
        this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-locale-refresh')
      }
283 284 285 286 287 288 289 290
    },
    selectedLocale: {
      query: localesQuery,
      update: (data) => data.localization.config.locale
    },
    autoUpdate: {
      query: localesQuery,
      update: (data) => data.localization.config.autoUpdate
291 292 293 294 295 296 297 298
    },
    namespacing: {
      query: localesQuery,
      update: (data) => data.localization.config.namespacing
    },
    namespaces: {
      query: localesQuery,
      update: (data) => data.localization.config.namespaces
299 300 301 302
    }
  }
}
</script>