Browse Source

feat: dev flags

pull/795/head
Nick 5 years ago
parent
commit
2141366335
11 changed files with 124 additions and 6 deletions
  1. 3
      client/components/admin.vue
  2. 12
      client/components/admin/admin-contribute.vue
  3. 38
      client/components/admin/admin-dev-flags.vue
  4. 16
      client/graph/admin/dev/dev-mutation-save-flags.gql
  5. 8
      client/graph/admin/dev/dev-query-flags.gql
  6. 2
      dev/build/config.yml
  7. 2
      server/app/data.yml
  8. 6
      server/core/config.js
  9. 1
      server/core/kernel.js
  10. 21
      server/graph/resolvers/system.js
  11. 21
      server/graph/schemas/system.graphql

3
client/components/admin.vue

@ -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')

12
client/components/admin/admin-contribute.vue

@ -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>

38
client/components/admin/admin-dev-flags.vue

@ -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')
}
}
}
}

16
client/graph/admin/dev/dev-mutation-save-flags.gql

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

8
client/graph/admin/dev/dev-query-flags.gql

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

2
dev/build/config.yml

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

2
server/app/data.yml

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

6
server/core/config.js

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

1
server/core/kernel.js

@ -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) {

21
server/graph/resolvers/system.js

@ -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')

21
server/graph/schemas/system.graphql

@ -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"])

Loading…
Cancel
Save