-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitpool_tag_library.html
More file actions
133 lines (115 loc) · 4.8 KB
/
bitpool_tag_library.html
File metadata and controls
133 lines (115 loc) · 4.8 KB
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
<!--
MIT License Copyright 2021-2024 - Bitpool Pty Ltd
-->
<script type="text/html" data-template-name="Bitpool-Tag-Library">
<style>
.form-row {
align-items: center;
flex-wrap: nowrap !important;
display: flex;
}
button {
height: 34px;
border-radius: 5px !important;
}
.inputStyle {
color: var(--red-ui-workspace-button-color-hover) !important;
background: var(--red-ui-workspace-button-background-hover);
border: 1px solid var(--red-ui-secondary-border-color);
border-radius: 5px !important;
}
input[type="file"] {
display: none !important;
}
.custom-file-upload {
border: 1px solid var(--red-ui-secondary-border-color);
border-radius: 5px !important;
padding: 6px 12px;
cursor: pointer;
width: 110px !important;
}
.uploadButton {
margin-bottom: 5px !important;
margin-left: 30px !important;
}
</style>
<div class="form-row">
<label for="node-config-input-name"><i class="icon-tag"></i><span data-i18n="bitpool-uploader.label.name"></span> Name: </label>
<input type="text" id="node-config-input-name" placeholder="Config Name">
</div>
<div class="form-row">
<label for="node-config-input-file"><i class="icon-tag"></i> <span data-i18n="bitpool-uploader.label.file"></span>Tag Library: </label>
<label for="file-upload" class="custom-file-upload">
<i class="fa fa-upload"></i> Select File
</label>
<input type="file" id="file-upload" accept=".csv" class="inputStyle" style="width: 258px;">
<button id="fileUploadButton" class="inputStyle uploadButton"> Import </button>
<input type="text" id="node-config-input-file" style="display: none;" >
</div>
<div class="form-row" style="display: flex; padding-top: 5px;">
<label for="node-config-input-fileName"><i class="icon-tag"></i> <span data-i18n="bitpool-uploader.label.file"></span>File name: </label>
<p id="fileName" >Waiting for file</p>
<input id="node-config-input-fileName" style="display: none;">
</div>
<div class="form-row" style="display: flex; align-items: flex-start; padding-top: 5px;">
<label for="node-config-input-enabled"><i class="icon-tag"></i> <span data-i18n="bitpool-uploader.label.enabled"></span>Activate Library: </label>
<input class="form-check-input" type="checkbox" value="" id="node-config-input-enabled" style="width: 20px;">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('Bitpool-Tag-Library', {
category: 'config',
defaults: {
name: {value:""},
file: {value:""},
libJson: {value: []},
fileName: {value: ""},
enabled: {value: true}
},
label: function () {
return this.name || "Bitpool-Tag-Library";
},
oneditprepare: function() {
let node = this;
$("#fileName").text(node.fileName);
var csvFile = document.getElementById("file-upload");
csvFile.onchange = function(e) {
$("#fileName").text("Waiting for import");
$("#node-config-input-fileName").val("Waiting for import");
node.fileName = "Waiting for import";
$("#fileUploadButton").attr("style", "color: white !important; background-color: #00ADEF !important;");
}
$("#fileUploadButton").click(function(params) {
params.preventDefault();
const input = csvFile.files[0];
const reader = new FileReader();
$("#fileName").text(input.name);
$("#node-config-input-fileName").val(input.name);
node.fileName = input.name;
reader.onload = function (e) {
const text = e.target.result;
let lines = text.split(/\r?\n/);
let nameSpace = lines[0].split(",")[1];
let columnHeaders = lines[2].split(",");
let tagNameIndex = columnHeaders.findIndex(element => element == "Tag name");
let typeIndex = columnHeaders.findIndex(element => element == "Type");
for(let i = 4; i < lines.length; i++) {
let line = lines[i].split(",");
let tagName = line[tagNameIndex];
let type = line[typeIndex];
let fullTag = `${tagName}`
if(tagName && type) {
let json = {
tag: fullTag,
type: type
};
if(node.libJson.map(e => e.tag).indexOf(json.tag) === -1) node.libJson.push(json);
}
}
$("#fileUploadButton").attr("style", "color: var(--red-ui-workspace-button-color-hover) !important; background-color: var(--red-ui-workspace-button-background-hover) !important;");
};
reader.readAsText(input);
});
}
});
</script>