admin-logging.vue 6.98 KB
Newer Older
1
<template lang='pug'>
2 3 4 5
  v-container(fluid, grid-list-lg)
    v-layout(row, wrap)
      v-flex(xs12)
        .admin-header
6
          img(src='/_assets/svg/icon-registry-editor.svg', alt='Logging', style='width: 80px;')
7 8
          .admin-header-title
            .headline.primary--text Logging
9
            .subtitle-1.grey--text Configure the system logger(s) #[v-chip(label, color='primary', small).white--text coming soon]
10 11 12
          v-spacer
          v-btn(outline, color='grey', @click='refresh', large)
            v-icon refresh
13
          v-btn(color='black', disabled, depressed, @click='toggleConsole', large)
14
            v-icon check
15
            span Live Trail
16 17 18
          v-btn(color='success', @click='save', depressed, large)
            v-icon(left) check
            span {{$t('common:actions.apply')}}
19

20 21 22 23
        v-card.mt-3
          v-tabs(color='grey darken-2', fixed-tabs, slider-color='white', show-arrows, dark)
            v-tab(key='settings'): v-icon settings
            v-tab(v-for='logger in activeLoggers', :key='logger.key') {{ logger.title }}
24

25 26 27 28 29 30 31 32 33 34 35 36
            v-tab-item(key='settings', :transition='false', :reverse-transition='false')
              v-card.pa-3(flat, tile)
                .body-2.grey--text.text--darken-1 Select which logging service to enable:
                .caption.grey--text.pb-2 Some loggers require additional configuration in their dedicated tab (when selected).
                v-form
                  v-checkbox.my-0(
                    v-for='(logger, n) in loggers'
                    v-model='logger.isEnabled'
                    :key='logger.key'
                    :label='logger.title'
                    color='primary'
                    hide-details
37
                    disabled
38
                  )
39

40
            v-tab-item(v-for='(logger, n) in activeLoggers', :key='logger.key', :transition='false', :reverse-transition='false')
41
              v-card.wiki-form.pa-3(flat, tile)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
                v-form
                  .loggerlogo
                    img(:src='logger.logo', :alt='logger.title')
                  v-subheader.pl-0 {{logger.title}}
                  .caption {{logger.description}}
                  .caption: a(:href='logger.website') {{logger.website}}
                  v-divider.mt-3
                  v-subheader.pl-0 Logger Configuration
                  .body-1.ml-3(v-if='!logger.config || logger.config.length < 1') This logger has no configuration options you can modify.
                  template(v-else, v-for='cfg in logger.config')
                    v-select(
                      v-if='cfg.value.type === "string" && cfg.value.enum'
                      outline
                      background-color='grey lighten-2'
                      :items='cfg.value.enum'
                      :key='cfg.key'
                      :label='cfg.value.title'
                      v-model='cfg.value.value'
                      prepend-icon='settings_applications'
                      :hint='cfg.value.hint ? cfg.value.hint : ""'
                      persistent-hint
                      :class='cfg.value.hint ? "mb-2" : ""'
                    )
                    v-switch(
                      v-else-if='cfg.value.type === "boolean"'
                      :key='cfg.key'
                      :label='cfg.value.title'
                      v-model='cfg.value.value'
                      color='primary'
                      prepend-icon='settings_applications'
                      :hint='cfg.value.hint ? cfg.value.hint : ""'
                      persistent-hint
                      )
                    v-text-field(
                      v-else
                      outline
                      background-color='grey lighten-2'
                      :key='cfg.key'
                      :label='cfg.value.title'
                      v-model='cfg.value.value'
                      prepend-icon='settings_applications'
                      :hint='cfg.value.hint ? cfg.value.hint : ""'
                      persistent-hint
                      :class='cfg.value.hint ? "mb-2" : ""'
                      )
                  v-divider.mt-3
                  v-subheader.pl-0 Log Level
                  .body-1.ml-3 Select the minimum error level that will be reported to this logger.
                  v-layout(row)
                    v-flex(xs12, md6, lg4)
                      .pt-3
                        v-select(
                          single-line
                          outline
                          background-color='grey lighten-2'
                          :items='levels'
                          label='Level'
                          v-model='logger.level'
                          prepend-icon='graphic_eq'
                          hint='Default: warn'
                          persistent-hint
                        )
104

Nicolas Giard's avatar
Nicolas Giard committed
105
    logging-console(v-model='showConsole')
106 107 108 109 110
</template>

<script>
import _ from 'lodash'

Nicolas Giard's avatar
Nicolas Giard committed
111 112
import LoggingConsole from './admin-logging-console.vue'

113 114 115
import loggersQuery from 'gql/admin/logging/logging-query-loggers.gql'
import loggersSaveMutation from 'gql/admin/logging/logging-mutation-save-loggers.gql'

116
export default {
Nicolas Giard's avatar
Nicolas Giard committed
117
  components: {
118
    LoggingConsole
Nicolas Giard's avatar
Nicolas Giard committed
119
  },
120 121
  data() {
    return {
Nicolas Giard's avatar
Nicolas Giard committed
122
      showConsole: false,
123 124
      loggers: [],
      levels: ['error', 'warn', 'info', 'debug', 'verbose']
125 126 127
    }
  },
  computed: {
128 129
    activeLoggers() {
      return _.filter(this.loggers, 'isEnabled')
130 131 132 133
    }
  },
  methods: {
    async refresh() {
134 135 136 137 138 139
      await this.$apollo.queries.loggers.refetch()
      this.$store.commit('showNotification', {
        message: 'List of loggers has been refreshed.',
        style: 'success',
        icon: 'cached'
      })
Nicolas Giard's avatar
Nicolas Giard committed
140
    },
141 142 143 144 145 146 147 148 149 150
    async save() {
      this.$store.commit(`loadingStart`, 'admin-logging-saveloggers')
      await this.$apollo.mutate({
        mutation: loggersSaveMutation,
        variables: {
          loggers: this.loggers.map(tgt => _.pick(tgt, [
            'isEnabled',
            'key',
            'config',
            'level'
151
          ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
152 153 154 155 156 157 158 159
        }
      })
      this.$store.commit('showNotification', {
        message: 'Logging configuration saved successfully.',
        style: 'success',
        icon: 'check'
      })
      this.$store.commit(`loadingStop`, 'admin-logging-saveloggers')
160 161 162
    },
    toggleConsole() {
      this.showConsole = !this.showConsole
163 164 165 166 167 168 169 170 171 172
    }
  },
  apollo: {
    loggers: {
      query: loggersQuery,
      fetchPolicy: 'network-only',
      update: (data) => _.cloneDeep(data.logging.loggers).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))})),
      watchLoading (isLoading) {
        this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-logging-refresh')
      }
173 174 175 176 177
    }
  }
}
</script>

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
<style lang='scss' scoped>

.loggerlogo {
  width: 250px;
  height: 85px;
  float:right;
  display: flex;
  justify-content: flex-end;
  align-items: center;

  img {
    max-width: 100%;
    max-height: 50px;
  }
}
193 194

</style>