2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
2021-06-17 22:58:26 -07:00
|
|
|
<div class="node-icon-wrapper" :style="iconStyleData" :class="{shrink: isSvgIcon && shrink, full: !shrink}">
|
2019-06-23 03:35:23 -07:00
|
|
|
<div v-if="nodeIconData !== null" class="icon">
|
2021-06-17 22:58:26 -07:00
|
|
|
<img :src="nodeIconData.path" style="max-width: 100%; max-height: 100%;" v-if="nodeIconData.type === 'file'"/>
|
2019-06-23 03:35:23 -07:00
|
|
|
<font-awesome-icon :icon="nodeIconData.path" v-else-if="nodeIconData.type === 'fa'" />
|
|
|
|
</div>
|
|
|
|
<div v-else class="node-icon-placeholder">
|
|
|
|
{{nodeType !== null ? nodeType.displayName.charAt(0) : '?' }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
|
|
|
import Vue from 'vue';
|
|
|
|
|
|
|
|
interface NodeIconData {
|
|
|
|
type: string;
|
|
|
|
path: string;
|
2020-10-03 05:10:08 -07:00
|
|
|
fileExtension?: string;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
name: 'NodeIcon',
|
|
|
|
props: [
|
|
|
|
'nodeType',
|
2019-07-25 09:50:45 -07:00
|
|
|
'size',
|
2021-06-17 22:58:26 -07:00
|
|
|
'shrink',
|
2019-06-23 03:35:23 -07:00
|
|
|
],
|
|
|
|
computed: {
|
2019-07-25 09:50:45 -07:00
|
|
|
iconStyleData (): object {
|
|
|
|
if (!this.size) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-07-25 10:15:41 -07:00
|
|
|
const size = parseInt(this.size, 10);
|
2019-07-25 09:50:45 -07:00
|
|
|
|
|
|
|
return {
|
|
|
|
width: size + 'px',
|
|
|
|
height: size + 'px',
|
|
|
|
'font-size': Math.floor(parseInt(this.size, 10) * 0.6) + 'px',
|
|
|
|
'line-height': size + 'px',
|
|
|
|
'border-radius': Math.ceil(size / 2) + 'px',
|
2019-07-25 10:15:41 -07:00
|
|
|
};
|
2019-07-25 09:50:45 -07:00
|
|
|
},
|
2020-10-03 05:10:08 -07:00
|
|
|
isSvgIcon (): boolean {
|
|
|
|
if (this.nodeIconData && this.nodeIconData.type === 'file' && this.nodeIconData.fileExtension === 'svg') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
nodeIconData (): null | NodeIconData {
|
|
|
|
if (this.nodeType === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const restUrl = this.$store.getters.getRestUrl;
|
|
|
|
|
|
|
|
if (this.nodeType.icon) {
|
|
|
|
let type, path;
|
|
|
|
[type, path] = this.nodeType.icon.split(':');
|
2020-10-03 05:10:08 -07:00
|
|
|
const returnData: NodeIconData = {
|
2019-06-23 03:35:23 -07:00
|
|
|
type,
|
|
|
|
path,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (type === 'file') {
|
|
|
|
returnData.path = restUrl + '/node-icon/' + this.nodeType.name;
|
2020-10-03 05:10:08 -07:00
|
|
|
returnData.fileExtension = path.split('.').slice(-1).join();
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
|
|
.node-icon-wrapper {
|
2021-06-17 22:58:26 -07:00
|
|
|
width: 26px;
|
|
|
|
height: 26px;
|
|
|
|
border-radius: 4px;
|
2019-06-23 03:35:23 -07:00
|
|
|
color: #444;
|
2021-06-17 22:58:26 -07:00
|
|
|
line-height: 26px;
|
2019-06-23 03:35:23 -07:00
|
|
|
font-size: 1.1em;
|
|
|
|
overflow: hidden;
|
|
|
|
text-align: center;
|
|
|
|
font-weight: bold;
|
2019-07-25 09:50:45 -07:00
|
|
|
font-size: 20px;
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2020-10-03 05:10:08 -07:00
|
|
|
&.full .icon {
|
2021-06-17 22:58:26 -07:00
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.shrink .icon {
|
2020-10-03 05:10:08 -07:00
|
|
|
margin: 0.24em;
|
|
|
|
}
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
.node-icon-placeholder {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|