|
| 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> |
0 commit comments