feat: dev flags

This commit is contained in:
Nick 2019-02-23 18:22:25 -05:00
parent bf505e6901
commit 2141366335
11 changed files with 124 additions and 6 deletions

View File

@ -80,13 +80,12 @@
v-list-tile-avatar: v-icon(color='grey lighten-2') build
v-list-tile-title {{ $t('admin:utilities.title') }}
v-list-group(
prepend-icon='weekend'
value='true'
to='/dev'
no-action
v-if='hasPermission([`manage:system`, `manage:api`])'
)
v-list-tile(slot='activator')
v-list-tile-avatar: v-icon weekend
v-list-tile-title {{ $t('admin:dev.title') }}
v-list-tile(to='/dev-flags')

View File

@ -133,7 +133,7 @@
v-icon(color='grey') public
v-divider
v-list-tile
v-list-tile-avatar
v-list-tile-avatar(tile)
img(src='/svg/logo-icons8.svg', alt='Icons8')
v-list-tile-content
v-list-tile-title Icons8
@ -141,6 +141,16 @@
v-list-tile-action
v-btn(icon, href='https://icons8.com', target='_blank')
v-icon(color='grey') public
v-divider
v-list-tile
v-list-tile-avatar(tile)
img(src='https://static.requarks.io/logo/lokalise.png', alt='Lokalise')
v-list-tile-content
v-list-tile-title Lokalise
v-list-tile-sub-title Lokalise is a translation management system built for agile teams who want to automate their localization process.
v-list-tile-action
v-btn(icon, href='https://lokalise.co', target='_blank')
v-icon(color='grey') public
</template>

View File

@ -38,6 +38,9 @@
<script>
import _ from 'lodash'
import flagsQuery from 'gql/admin/dev/dev-query-flags.gql'
import flagsMutation from 'gql/admin/dev/dev-mutation-save-flags.gql'
export default {
data() {
return {
@ -47,8 +50,39 @@ export default {
}
},
methods: {
save() {
async save() {
try {
await this.$apollo.mutate({
mutation: flagsMutation,
variables: {
flags: _.transform(this.flags, (result, value, key) => {
result.push({ key, value })
}, [])
},
watchLoading (isLoading) {
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-dev-flags-update')
}
})
this.$store.commit('showNotification', {
style: 'success',
message: 'Flags applied successfully.',
icon: 'check'
})
} catch (err) {
this.$store.commit('pushGraphError', err)
}
}
},
apollo: {
flags: {
query: flagsQuery,
fetchPolicy: 'network-only',
update: (data) => _.transform(data.system.flags, (result, row) => {
_.set(result, row.key, row.value)
}, {}),
watchLoading (isLoading) {
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-dev-flags-refresh')
}
}
}
}

View File

@ -0,0 +1,16 @@
mutation (
$flags: [SystemFlagInput]!
) {
system {
updateFlags(
flags: $flags
) {
responseResult {
succeeded
errorCode
slug
message
}
}
}
}

View File

@ -0,0 +1,8 @@
{
system {
flags {
key
value
}
}
}

View File

@ -1,4 +1,4 @@
port: $(PORT)
port: 3000
bindIP: 0.0.0.0
db:
type: $(DB_TYPE)

View File

@ -33,6 +33,8 @@ defaults:
theming:
theme: 'default'
darkMode: false
flags:
sqllog: false
# System defaults
setup: false
paths:

View File

@ -96,5 +96,11 @@ module.exports = {
}
return true
},
/**
* Apply Dev Flags
*/
async applyFlags() {
WIKI.models.knex.client.config.debug = WIKI.config.flags.sqllog
}
}

View File

@ -14,6 +14,7 @@ module.exports = {
try {
await WIKI.models.onReady
await WIKI.configSvc.loadFromDb()
await WIKI.configSvc.applyFlags()
} catch (err) {
WIKI.logger.error('Database Initialization Error: ' + err.message)
if (WIKI.IS_DEBUG) {

View File

@ -6,6 +6,7 @@ const filesize = require('filesize')
const path = require('path')
const fs = require('fs-extra')
const moment = require('moment')
const graphHelper = require('../../helpers/graph')
/* global WIKI */
@ -21,9 +22,29 @@ module.exports = {
Query: {
async system() { return {} }
},
Mutation: {
async system() { return {} }
},
SystemQuery: {
flags() {
return _.transform(WIKI.config.flags, (result, value, key) => {
result.push({ key, value })
}, [])
},
async info() { return {} }
},
SystemMutation: {
async updateFlags(obj, args, context) {
WIKI.config.flags = _.transform(args.flags, (result, row) => {
_.set(result, row.key, row.value)
}, {})
await WIKI.configSvc.applyFlags()
await WIKI.configSvc.saveToDb(['flags'])
return {
responseResult: graphHelper.generateSuccess('System Flags applied successfully')
}
}
},
SystemInfo: {
configFile() {
return path.join(process.cwd(), 'config.yml')

View File

@ -6,11 +6,16 @@ extend type Query {
system: SystemQuery
}
extend type Mutation {
system: SystemMutation
}
# -----------------------------------------------
# QUERIES
# -----------------------------------------------
type SystemQuery {
flags: [SystemFlag] @auth(requires: ["manage:system"])
info: SystemInfo
}
@ -18,10 +23,26 @@ type SystemQuery {
# MUTATIONS
# -----------------------------------------------
type SystemMutation {
updateFlags(
flags: [SystemFlagInput]!
): DefaultResponse @auth(requires: ["manage:system"])
}
# -----------------------------------------------
# TYPES
# -----------------------------------------------
type SystemFlag {
key: String!
value: Boolean!
}
input SystemFlagInput {
key: String!
value: Boolean!
}
type SystemInfo {
configFile: String @auth(requires: ["manage:system"])
cpuCores: Int @auth(requires: ["manage:system"])