Browse Source

feat: dev flags

Nick 6 years ago
parent
commit
2141366335

+ 1 - 2
client/components/admin.vue

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

+ 11 - 1
client/components/admin/admin-contribute.vue

@@ -133,7 +133,7 @@
                   v-icon(color='grey') public
                   v-icon(color='grey') public
             v-divider
             v-divider
             v-list-tile
             v-list-tile
-              v-list-tile-avatar
+              v-list-tile-avatar(tile)
                 img(src='/svg/logo-icons8.svg', alt='Icons8')
                 img(src='/svg/logo-icons8.svg', alt='Icons8')
               v-list-tile-content
               v-list-tile-content
                 v-list-tile-title Icons8
                 v-list-tile-title Icons8
@@ -141,6 +141,16 @@
               v-list-tile-action
               v-list-tile-action
                 v-btn(icon, href='https://icons8.com', target='_blank')
                 v-btn(icon, href='https://icons8.com', target='_blank')
                   v-icon(color='grey') public
                   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>
 </template>
 
 

+ 36 - 2
client/components/admin/admin-dev-flags.vue

@@ -38,6 +38,9 @@
 <script>
 <script>
 import _ from 'lodash'
 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 {
 export default {
   data() {
   data() {
     return {
     return {
@@ -47,8 +50,39 @@ export default {
     }
     }
   },
   },
   methods: {
   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 - 0
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 - 0
client/graph/admin/dev/dev-query-flags.gql

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

+ 1 - 1
dev/build/config.yml

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

+ 2 - 0
server/app/data.yml

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

+ 6 - 0
server/core/config.js

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

+ 1 - 0
server/core/kernel.js

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

+ 21 - 0
server/graph/resolvers/system.js

@@ -6,6 +6,7 @@ const filesize = require('filesize')
 const path = require('path')
 const path = require('path')
 const fs = require('fs-extra')
 const fs = require('fs-extra')
 const moment = require('moment')
 const moment = require('moment')
+const graphHelper = require('../../helpers/graph')
 
 
 /* global WIKI */
 /* global WIKI */
 
 
@@ -21,9 +22,29 @@ module.exports = {
   Query: {
   Query: {
     async system() { return {} }
     async system() { return {} }
   },
   },
+  Mutation: {
+    async system() { return {} }
+  },
   SystemQuery: {
   SystemQuery: {
+    flags() {
+      return _.transform(WIKI.config.flags, (result, value, key) => {
+        result.push({ key, value })
+      }, [])
+    },
     async info() { return {} }
     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: {
   SystemInfo: {
     configFile() {
     configFile() {
       return path.join(process.cwd(), 'config.yml')
       return path.join(process.cwd(), 'config.yml')

+ 21 - 0
server/graph/schemas/system.graphql

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