Skip to content

Commit e945797

Browse files
committed
1 parent 0e62a2e commit e945797

3 files changed

Lines changed: 109 additions & 17 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<!--
2+
- BSD 3-Clause License
3+
-
4+
- Copyright (c) 2019, CROC Inc.
5+
- All rights reserved.
6+
-
7+
- Redistribution and use in source and binary forms, with or without
8+
- modification, are permitted provided that the following conditions are met:
9+
-
10+
- 1. Redistributions of source code must retain the above copyright notice, this
11+
- list of conditions and the following disclaimer.
12+
-
13+
- 2. Redistributions in binary form must reproduce the above copyright notice,
14+
- this list of conditions and the following disclaimer in the documentation
15+
- and/or other materials provided with the distribution.
16+
-
17+
- 3. Neither the name of the copyright holder nor the names of its
18+
- contributors may be used to endorse or promote products derived from
19+
- this software without specific prior written permission.
20+
-
21+
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
-->
32+
33+
<template>
34+
<div>
35+
<a v-if="met.properties.datatype==='json' && props.item[met.name]"
36+
:href="'#/'+props.item['endpoint']+'/'+JSON.parse(props.item[met.name].value).link">
37+
<v-icon medium v-if="JSON.parse(props.item[met.name].value).icon">
38+
{{ JSON.parse(props.item[met.name].value).icon }}
39+
</v-icon>
40+
<v-chip v-else color="green" dark>{{ JSON.parse(props.item[met.name].value).label }}</v-chip>
41+
</a>
42+
<pre v-else-if="met.properties.format==='sql'" v-highlightjs="props.item[met.name]" class="text-sm-left">
43+
<code class="sql"/>
44+
</pre>
45+
<span v-else-if="met.properties.datatype==='time'">{{ props.item[met.name] | formatDate }}</span>
46+
<span v-else-if="met.properties.format==='size'">{{ props.item[met.name] | prettyByte }}</span>
47+
<span v-else>{{ props.item[met.name] | round(2) }}</span>
48+
</div>
49+
</template>
50+
<script>
51+
import moment from 'moment'
52+
53+
export default {
54+
name: 'CustomComponent',
55+
props: {
56+
met: {},
57+
props: {}
58+
},
59+
filters: {
60+
formatDate: function (value) {
61+
if (value) {
62+
return moment(String(value)).format('DD.MM.YYYY HH:mm:ss')
63+
}
64+
},
65+
round: function (value, decimals) {
66+
if(typeof value !== 'number'){
67+
return value
68+
}
69+
if(!value) {
70+
value = 0;
71+
}
72+
if (!decimals) {
73+
decimals = 0;
74+
}
75+
value = Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals)
76+
return value;
77+
},
78+
prettyByte: function (num) {
79+
if (typeof num !== 'number' || isNaN(num)) {
80+
throw new TypeError('Expected a number');
81+
}
82+
83+
var exponent;
84+
var unit;
85+
var neg = num < 0;
86+
var units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
87+
88+
if (neg) {
89+
num = -num;
90+
}
91+
92+
if (num < 1) {
93+
return (neg ? '-' : '') + num + ' B';
94+
}
95+
96+
exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1);
97+
num = (num / Math.pow(1000, exponent)).toFixed(2) * 1;
98+
unit = units[exponent];
99+
100+
return (neg ? '-' : '') + num + ' ' + unit;
101+
}
102+
}
103+
}
104+
</script>

src/main/malewicz/src/components/ObjectsTablePanel.vue

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,7 @@
8282
</template>
8383
<template v-slot:items="props">
8484
<td v-for="met in defaultMeta">
85-
<a v-if="met.properties.datatype==='json' && props.item[met.name]"
86-
:href="'#/'+props.item['endpoint']+'/'+JSON.parse(props.item[met.name].value).link">
87-
<v-icon medium v-if="JSON.parse(props.item[met.name].value).icon">{{ JSON.parse(props.item[met.name].value).icon }}</v-icon>
88-
<v-chip v-else color="green" dark>{{ JSON.parse(props.item[met.name].value).label }}</v-chip>
89-
</a>
90-
<pre v-else-if="met.properties.format==='sql'" v-highlightjs="props.item[met.name]" class="text-sm-left"><code class="sql"></code></pre>
91-
<span v-else-if="met.properties.datatype">{{ props.item[met.name] | formatDate }}</span>
92-
<span v-else>{{ props.item[met.name] }}</span>
85+
<CustomComponent :met="met" :props="props"/>
9386
</td>
9487
</template>
9588
</v-data-table>
@@ -105,8 +98,11 @@
10598
</div>
10699
</template>
107100
<script>
108-
export default {
101+
import CustomComponent from "./CustomComponent";
102+
103+
export default {
109104
name: 'ObjectsTablePanel',
105+
components: {CustomComponent},
110106
data () {
111107
return {
112108
meta: [],

src/main/malewicz/src/main.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import JsonExcel from 'vue-json-excel'
4343
import VueSSE from 'vue-sse'
4444
import Vuetify from 'vuetify'
4545
import VueHighlightJS from 'vue-highlightjs'
46-
import moment from 'moment'
4746

4847

4948
import 'vuetify/dist/vuetify.min.css' // Ensure you are using css-loader
@@ -57,15 +56,8 @@ Vue.use(VueSSE)
5756
Vue.use(Vuetify)
5857
Vue.use(VueHighlightJS)
5958

60-
6159
Vue.config.productionTip = false
6260

63-
Vue.filter('formatDate', function(value) {
64-
if (value) {
65-
return moment(String(value)).format('DD.MM.YYYY HH:mm:ss')
66-
}
67-
});
68-
6961
const store = new Vuex.Store({
7062
state: {
7163
host: '',

0 commit comments

Comments
 (0)