2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
2021-11-19 01:17:13 -08:00
|
|
|
<div class="node-icon-wrapper" :style="iconStyleData">
|
2019-06-23 03:35:23 -07:00
|
|
|
<div v-if="nodeIconData !== null" class="icon">
|
2021-11-19 01:17:13 -08:00
|
|
|
<img v-if="nodeIconData.type === 'file'" :src="nodeIconData.fileBuffer || nodeIconData.path" :style="imageStyleData" />
|
|
|
|
<font-awesome-icon v-else :icon="nodeIconData.icon || nodeIconData.path" :style="fontStyleData" />
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
<div v-else class="node-icon-placeholder">
|
|
|
|
{{nodeType !== null ? nodeType.displayName.charAt(0) : '?' }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
2021-11-19 01:17:13 -08:00
|
|
|
import { IVersionNode } from '@/Interface';
|
|
|
|
import { INodeTypeDescription } from 'n8n-workflow';
|
2019-06-23 03:35:23 -07:00
|
|
|
import Vue from 'vue';
|
|
|
|
|
|
|
|
interface NodeIconData {
|
|
|
|
type: string;
|
2021-11-19 01:17:13 -08:00
|
|
|
path?: string;
|
2020-10-03 05:10:08 -07:00
|
|
|
fileExtension?: string;
|
2021-11-19 01:17:13 -08:00
|
|
|
fileBuffer?: string;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
name: 'NodeIcon',
|
2021-11-19 01:17:13 -08:00
|
|
|
props: {
|
|
|
|
nodeType: {},
|
|
|
|
size: {
|
|
|
|
type: Number,
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
circle: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
computed: {
|
2019-07-25 09:50:45 -07:00
|
|
|
iconStyleData (): object {
|
2021-11-19 01:17:13 -08:00
|
|
|
const nodeType = this.nodeType as INodeTypeDescription | IVersionNode | null;
|
|
|
|
const color = nodeType ? nodeType.defaults && nodeType!.defaults.color : '';
|
2019-07-25 09:50:45 -07:00
|
|
|
if (!this.size) {
|
2021-07-22 01:22:17 -07:00
|
|
|
return {color};
|
2019-07-25 09:50:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2021-07-22 01:22:17 -07:00
|
|
|
color,
|
2021-11-19 01:17:13 -08:00
|
|
|
width: this.size + 'px',
|
|
|
|
height: this.size + 'px',
|
|
|
|
'font-size': this.size + 'px',
|
|
|
|
'line-height': this.size + 'px',
|
|
|
|
'border-radius': this.circle ? '50%': '2px',
|
|
|
|
...(this.disabled && {
|
|
|
|
color: '#ccc',
|
|
|
|
'-webkit-filter': 'contrast(40%) brightness(1.5) grayscale(100%)',
|
|
|
|
'filter': 'contrast(40%) brightness(1.5) grayscale(100%)',
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
fontStyleData (): object {
|
|
|
|
return {
|
|
|
|
'max-width': this.size + 'px',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
imageStyleData (): object {
|
|
|
|
return {
|
|
|
|
width: '100%',
|
|
|
|
'max-width': '100%',
|
|
|
|
'max-height': '100%',
|
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 {
|
2021-11-19 01:17:13 -08:00
|
|
|
const nodeType = this.nodeType as INodeTypeDescription | IVersionNode | null;
|
|
|
|
if (nodeType === null) {
|
2019-06-23 03:35:23 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-11-19 01:17:13 -08:00
|
|
|
if ((nodeType as IVersionNode).iconData) {
|
|
|
|
return (nodeType as IVersionNode).iconData;
|
2021-07-22 01:22:17 -07:00
|
|
|
}
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
const restUrl = this.$store.getters.getRestUrl;
|
|
|
|
|
2021-11-19 01:17:13 -08:00
|
|
|
if (nodeType.icon) {
|
2019-06-23 03:35:23 -07:00
|
|
|
let type, path;
|
2021-11-19 01:17:13 -08:00
|
|
|
[type, path] = 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') {
|
2021-11-19 01:17:13 -08:00
|
|
|
returnData.path = restUrl + '/node-icon/' + 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;
|
2021-11-19 01:17:13 -08:00
|
|
|
border-radius: 2px;
|
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
|
|
|
|
2021-11-19 01:17:13 -08:00
|
|
|
.icon {
|
2021-06-17 22:58:26 -07:00
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
2021-07-22 01:22:17 -07:00
|
|
|
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2021-06-17 22:58:26 -07:00
|
|
|
}
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
.node-icon-placeholder {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|