feat: admin - save locale settings + system info linux os

pull/621/head
NGPixel 7 years ago
parent b143aa2f8c
commit 9f8feb6540

@ -15,6 +15,7 @@
v-select(:items='installedLocales'
prepend-icon='public'
v-model='selectedLocale'
item-value='code'
item-text='name'
label='Site Locale'
persistent-hint
@ -39,7 +40,9 @@
)
v-divider
.px-3.pb-3
v-btn(color='primary') Save
v-btn(color='primary', :loading='loading', @click='save')
v-icon(left) chevron_right
span Save
v-flex(lg6 xs12)
v-card
v-toolbar(color='teal', dark, dense, flat)
@ -65,13 +68,15 @@
import _ from 'lodash'
import localesQuery from 'gql/admin-locale-query-list.gql'
import localesMutation from 'gql/admin-locale-mutation-save.gql'
export default {
data() {
return {
loading: false,
locales: [],
selectedLocale: 'en',
autoUpdate: true
autoUpdate: false
}
},
computed: {
@ -79,6 +84,33 @@ export default {
return _.filter(this.locales, ['isInstalled', true])
}
},
methods: {
async save() {
this.loading = true
const respRaw = await this.$apollo.mutate({
mutation: localesMutation,
variables: {
locale: this.selectedLocale,
autoUpdate: this.autoUpdate
}
})
const resp = _.get(respRaw, 'data.localization.updateLocale.responseResult', {})
if (resp.succeeded) {
this.$store.commit('showNotification', {
message: 'Locale settings updated successfully.',
style: 'success',
icon: 'check'
})
} else {
this.$store.commit('showNotification', {
message: `Error: ${resp.message}`,
style: 'error',
icon: 'warning'
})
}
this.loading = false
}
},
apollo: {
locales: {
query: localesQuery,
@ -86,6 +118,14 @@ export default {
watchLoading (isLoading) {
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-locale-refresh')
}
},
selectedLocale: {
query: localesQuery,
update: (data) => data.localization.config.locale
},
autoUpdate: {
query: localesQuery,
update: (data) => data.localization.config.autoUpdate
}
}
}

@ -58,6 +58,12 @@
v-list-tile-content
v-list-tile-title Working Directory
v-list-tile-sub-title {{ info.workingDirectory }}
v-list-tile(avatar)
v-list-tile-avatar
v-icon.blue-grey.white--text settings
v-list-tile-content
v-list-tile-title Configuration File
v-list-tile-sub-title {{ info.configFile }}
v-flex(lg6 xs12)
v-card.pb-3
@ -85,14 +91,14 @@
v-divider
v-subheader PostgreSQL
v-subheader {{ info.dbType }}
v-list-tile(avatar)
v-list-tile-avatar
v-avatar.indigo.darken-1(size='40')
icon-database(fillColor='#FFFFFF')
v-list-tile-content
v-list-tile-title {{ info.postgreVersion }}
v-list-tile-sub-title {{ info.postgreHost }}
v-list-tile-title {{ info.dbVersion }}
v-list-tile-sub-title {{ info.dbHost }}
</template>
<script>

@ -0,0 +1,12 @@
mutation($locale: String!, $autoUpdate: Boolean!) {
localization {
updateLocale(locale: $locale, autoUpdate: $autoUpdate) {
responseResult {
succeeded
errorCode
slug
message
}
}
}
}

@ -10,5 +10,9 @@
nativeName
updatedAt
}
config {
locale
autoUpdate
}
}
}

@ -1,7 +1,11 @@
query {
system {
info {
configFile
currentVersion
dbType
dbVersion
dbHost
latestVersion
latestVersionReleaseDate
operatingSystem
@ -14,8 +18,6 @@ query {
redisUsedRAM
redisTotalRAM
redisHost
postgreVersion
postgreHost
}
}
}

@ -65,6 +65,7 @@
"filesize.js": "1.0.2",
"follow-redirects": "1.4.1",
"fs-extra": "5.0.0",
"getos": "3.1.0",
"graphql": "0.13.2",
"graphql-list-fields": "2.0.2",
"graphql-tools": "3.0.0",

@ -39,9 +39,13 @@ module.exports = {
LocalizationMutation: {
async updateLocale(obj, args, context) {
try {
let authResult = await WIKI.db.User.login(args, context)
WIKI.config.site.lang = args.locale
WIKI.config.site.langAutoUpdate = args.autoUpdate
await WIKI.configSvc.saveToDb(['site'])
await WIKI.lang.setCurrentLocale(args.locale)
return {
...authResult,
responseResult: graphHelper.generateSuccess('Login success')
}
} catch (err) {

@ -1,9 +1,18 @@
const _ = require('lodash')
const Promise = require('bluebird')
const getos = Promise.promisify(require('getos'))
const os = require('os')
const filesize = require('filesize')
const path = require('path')
/* global WIKI */
const dbTypes = {
mysql: 'MySQL / MariaDB',
postgres: 'PostgreSQL',
sqlite: 'SQLite'
}
module.exports = {
Query: {
async system() { return {} }
@ -13,11 +22,21 @@ module.exports = {
},
SystemQuery: {
async info(obj, args, context, info) {
let osLabel = `${os.type()} (${os.platform()}) ${os.release()} ${os.arch()}`
if (os.platform() === 'linux') {
const osInfo = await getos()
osLabel = `${os.type()} - ${osInfo.dist} (${osInfo.codename || os.platform()}) ${osInfo.release || os.release()} ${os.arch()}`
}
return {
configFile: path.join(process.cwd(), 'config.yml'),
currentVersion: WIKI.version,
dbType: _.get(dbTypes, WIKI.config.db.type, 'Unknown DB'),
dbVersion: WIKI.db.inst.options.databaseVersion,
dbHost: WIKI.db.inst.options.host,
latestVersion: WIKI.version, // TODO
latestVersionReleaseDate: new Date(), // TODO
operatingSystem: `${os.type()} (${os.platform()}) ${os.release()} ${os.arch()}`,
operatingSystem: osLabel,
hostname: os.hostname(),
cpuCores: os.cpus().length,
ramTotal: filesize(os.totalmem()),
@ -26,9 +45,7 @@ module.exports = {
redisVersion: WIKI.redis.serverInfo.redis_version,
redisUsedRAM: WIKI.redis.serverInfo.used_memory_human,
redisTotalRAM: _.get(WIKI.redis.serverInfo, 'total_system_memory_human', 'N/A'),
redisHost: WIKI.redis.options.host,
postgreVersion: WIKI.db.inst.options.databaseVersion,
postgreHost: WIKI.db.inst.options.host
redisHost: WIKI.redis.options.host
}
}
},

@ -25,7 +25,7 @@ type LocalizationQuery {
type LocalizationMutation {
updateLocale(
localeId: String!
locale: String!
autoUpdate: Boolean!
): DefaultResponse
}

@ -31,19 +31,21 @@ type SystemMutation {
# -----------------------------------------------
type SystemInfo {
configFile: String
cpuCores: Int
currentVersion: String
dbHost: String
dbType: String
dbVersion: String
hostname: String
latestVersion: String
latestVersionReleaseDate: Date
nodeVersion: String
operatingSystem: String
hostname: String
cpuCores: Int
ramTotal: String
workingDirectory: String
nodeVersion: String
redisVersion: String
redisUsedRAM: String
redisTotalRAM: String
redisHost: String
postgreVersion: String
postgreHost: String
redisTotalRAM: String
redisUsedRAM: String
redisVersion: String
workingDirectory: String
}

@ -802,6 +802,12 @@ async@1.5, async@^1.4.0, async@^1.5, async@^1.5.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
async@2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/async/-/async-2.4.0.tgz#4990200f18ea5b837c2cc4f8c031a6985c385611"
dependencies:
lodash "^4.14.0"
async@^2.1.4, async@^2.5:
version "2.5.0"
resolved "https://registry.yarnpkg.com/async/-/async-2.5.0.tgz#843190fd6b7357a0b9e1c956edddd5ec8462b54d"
@ -5006,6 +5012,12 @@ get-value@^2.0.3, get-value@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28"
getos@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/getos/-/getos-3.1.0.tgz#db3aa4df15a3295557ce5e81aa9e3e5cdfaa6567"
dependencies:
async "2.4.0"
getpass@^0.1.1:
version "0.1.7"
resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa"

Loading…
Cancel
Save