File size: 3,897 Bytes
7929f62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!--
  Matomo - free/libre analytics platform

  @link    https://matomo.org
  @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
-->

<template>
  <ContentBlock
    :content-title="translate('Diagnostics_ConfigFileTitle')"
    feature="true"
  >
    <p>
      <span v-html="$sanitize(configFileIntro)" style="margin-right:3.5px"></span>
      <span
        v-html="$sanitize(translate('Diagnostics_HideUnchanged', '<a>', '</a>'))"
        @click="onHideUnchanged($event)"
      ></span>
    </p>

    <h3>{{ translate('Diagnostics_Sections') }}</h3>
    <Passthrough v-for="(values, category) in allConfigValues" :key="category">
      <a :href="`#${category}`">{{ category }}</a><br />
    </Passthrough>

    <p/>

    <table class="diagnostics configfile" v-content-table>
      <tbody>
      <Passthrough v-for="(configValues, category) in allConfigValues" :key="category">

      <tr>
        <td colspan="3">
          <a :name="category"></a><h3>{{ category }}</h3>
        </td>
      </tr>

      <tr
        v-for="(configEntry, key) in configValues"
        :key="key"
        :class="{'custom-value': configEntry.isCustomValue}"
        v-show="configEntry.isCustomValue || !hideGlobalConfigValues"
      >
        <td class="name">
          {{ `${key}${configEntry.value !== null
            && (configEntry.value instanceof Array
              || typeof configEntry.value === 'object'
            ) ? '[]' : ''}` }}
        </td>
        <td class="value" v-html="$sanitize(humanReadableValue(configEntry.value))"></td>
        <td class="description">
          <span v-html="$sanitize(configEntry.description)"></span>

          <span
            v-if="(configEntry.isCustomValue || configEntry.value === null)
              && configEntry.defaultValue !== null"
          >
            <br v-if="configEntry.description" />
            {{ translate('General_Default') }}:
            <span
              class="defaultValue"
              v-html="$sanitize(humanReadableValue(configEntry.defaultValue))"
            ></span>
          </span>
        </td>
      </tr>
      </Passthrough>
      </tbody>
    </table>
  </ContentBlock>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import {
  ContentBlock,
  translate,
  ContentTable,
  Passthrough,
  Matomo,
} from 'CoreHome';

interface ConfigFileState {
  hideGlobalConfigValues: boolean;
}

export default defineComponent({
  props: {
    allConfigValues: {
      type: Object,
      required: true,
    },
    configFilePath: {
      type: String,
      required: true,
    },
  },
  components: {
    ContentBlock,
    Passthrough,
  },
  directives: {
    ContentTable,
  },
  data(): ConfigFileState {
    return {
      hideGlobalConfigValues: false,
    };
  },
  methods: {
    humanReadableValue(value: unknown) {
      if (value === false) {
        return 'false';
      }

      if (value === true) {
        return 'true';
      }

      if (value === null) {
        return '';
      }

      if (value === '') {
        return '\'\'';
      }

      if (typeof value === 'object'
        && Object.keys(value as Record<string, unknown>).length === 0
      ) {
        return '[]';
      }

      if (typeof value === 'object'
        && Object.keys(value as Record<string, unknown>).length > 0
      ) {
        return `<div class="pre">${JSON.stringify(value, null, 4)}</div>`;
      }

      return Matomo.helper.htmlEntities(`${value}`);
    },
    onHideUnchanged(event: Event) {
      if ((event.target as HTMLElement).tagName !== 'A') {
        return;
      }

      this.hideGlobalConfigValues = !this.hideGlobalConfigValues;
    },
  },
  computed: {
    configFileIntro() {
      return translate(
        'Diagnostics_ConfigFileIntroduction',
        `<code>"${Matomo.helper.htmlEntities(this.configFilePath)}"</code>`,
      );
    },
  },
});
</script>