Skip to content

Commit 875943a

Browse files
committed
fix: fix element data preview synchronisation
1 parent 9def353 commit 875943a

File tree

4 files changed

+62
-32
lines changed

4 files changed

+62
-32
lines changed

src/js/elements/addDataElement.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ const createFolderInput = boxId => {
9797
// return input;
9898
// };
9999

100-
const createFileInputNew = ({ boxId }) => {
100+
const createFileInputNew = ({ boxId, mimeType }) => {
101101
const btn = document.createElement("button");
102102
btn.innerText = "Choose a file";
103103
btn.addEventListener("click", function() {
104-
app.$refs.collections.openCollectionModel(boxId);
104+
app.$refs.collections.openCollectionModel(boxId, mimeType);
105105
});
106106
btn.classList.add("btn");
107107
btn.classList.add("btn-primary");
@@ -116,11 +116,18 @@ const createImgPreview = () => {
116116
};
117117

118118
export const updateImgPreview = (boxId, data) => {
119-
const { url, identifier } = data[0]; // suppose one file
120119
const preview = document.querySelector(
121120
`${INTERFACE_ROOT} foreignObject[boxId='${boxId}'] .preview`
122121
);
123-
preview.innerHTML = `<img src="${url}"/> <span>${identifier}</span>`;
122+
123+
if (data && data[0] && data[0].options["mime-type"].includes("image")) {
124+
const { url, identifier } = data[0]; // suppose one file
125+
preview.innerHTML = `<img src="${url}"/> <span>${identifier}</span>`;
126+
}
127+
// if the image is removed
128+
else {
129+
preview.innerHTML = "";
130+
}
124131
};
125132

126133
const createContentBox = () => {
@@ -179,9 +186,7 @@ const addContent = dataEl => {
179186
foreignObj.appendChild(content);
180187

181188
// add preview if already exist
182-
if (data.length && mimeType.includes("image")) {
183-
updateImgPreview(boxId, data);
184-
}
189+
updateImgPreview(boxId, data);
185190
};
186191

187192
export const addDataBox = data => {

src/js/layout/components/Collections.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,29 @@ import { mapState } from "vuex";
1010
const Collections = Vue.component("Collections", {
1111
data() {
1212
return {
13-
collections: [],
13+
collections: undefined,
1414
files: {},
15-
id: null
15+
id: null,
16+
mimeType: ""
1617
};
1718
},
1819
components: {
1920
draggable
2021
},
2122
computed: {
23+
filteredCollections() {
24+
if (!this.collections || !this.collections.length) {
25+
return this.collections;
26+
}
27+
return this.collections
28+
.map(coll => ({
29+
...coll,
30+
files: coll.files.filter(
31+
({ options }) => options["mime-type"] == this.mimeType
32+
)
33+
}))
34+
.filter(({ files }) => files.length);
35+
},
2236
dragOptions() {
2337
return {
2438
group: DRAGGABLE_GROUP_NAME,
@@ -36,8 +50,9 @@ const Collections = Vue.component("Collections", {
3650
// }
3751
},
3852
methods: {
39-
openCollectionModel(boxId) {
53+
openCollectionModel(boxId, mimeType) {
4054
this.id = boxId;
55+
this.mimeType = mimeType;
4156

4257
// if doesnt exist in obj, add it
4358
if (!(boxId in this.files)) {
@@ -54,9 +69,7 @@ const Collections = Vue.component("Collections", {
5469
const data = this.files[this.id];
5570
app.updateDataInDataElement({ boxId: this.id, data });
5671
// @TODO: suppose one image
57-
if (data[0].options["mime-type"].includes("image")) {
58-
updateImgPreview(this.id, data);
59-
}
72+
updateImgPreview(this.id, data);
6073

6174
// close modal
6275
$("#collections").modal("hide");
@@ -88,11 +101,13 @@ const Collections = Vue.component("Collections", {
88101
</button>
89102
</div>
90103
91-
<div v-if="collections.length == 0" >Loading...</div>
104+
<div v-if="!filteredCollections" >Loading...</div>
105+
106+
<div class="no-file-found" v-else-if="filteredCollections && filteredCollections.length == 0" >No file available</div>
92107
93108
<div id="collections-wrapper">
94109
95-
<div v-for="({files, name, url, statusMessage, error, loaded}, idx) in collections" class="collection accordion">
110+
<div v-for="({files, name, url, statusMessage, error, loaded}, idx) in filteredCollections" class="collection accordion">
96111
97112
<!-- @click="loadCollection(idx)" -->
98113
<div class="card-header" :id="'heading'+idx" data-toggle="collapse" :data-target="'#collapse-'+idx" aria-expanded="true" :aria-controls="'collapse-'+idx">
@@ -124,7 +139,7 @@ const Collections = Vue.component("Collections", {
124139
</a>
125140
</span>
126141
<div class="delete-button">
127-
<span @click="deleteFile(name, file)" title="delete">x</span>
142+
<span @click="deleteFile(file)" title="delete">x</span>
128143
</div>
129144
</div>
130145

src/js/workflows/saveWorkflow.js

+18-16
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,24 @@ export const saveWorkflow = async (jsonGraph, installation = false) => {
129129

130130
// @TODO get folder when folder type
131131
let i = 0;
132-
const file = sourceDataBox.data[0]; // suppose one file
133-
allFiles.push(file);
134-
const dataName =
135-
targetWebservice.Name + "_" + link.target.portName + "_" + i++;
136-
const fileData = {
137-
[dataName]: file.identifier
138-
};
139-
data.push(fileData);
140-
141-
targetWebservice.Inputs.Data.push({
142-
Name: link.target.portName,
143-
Path: file.identifier
144-
});
145-
_targetWebservice.inputs.data.push({
146-
[link.target.portName]: file.identifier
147-
});
132+
if (sourceDataBox.data && sourceDataBox.data.length) {
133+
const file = sourceDataBox.data[0]; // suppose one file
134+
allFiles.push(file);
135+
const dataName =
136+
targetWebservice.Name + "_" + link.target.portName + "_" + i++;
137+
const fileData = {
138+
[dataName]: file.identifier
139+
};
140+
data.push(fileData);
141+
142+
targetWebservice.Inputs.Data.push({
143+
Name: link.target.portName,
144+
Path: file.identifier
145+
});
146+
_targetWebservice.inputs.data.push({
147+
[link.target.portName]: file.identifier
148+
});
149+
}
148150
}
149151
});
150152

src/styles/collections.scss

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
overflow: auto;
44
}
55

6+
.no-file-found {
7+
font-weight: bold;
8+
text-align: center;
9+
color: red;
10+
font-style: italic;
11+
margin: 10px 0;
12+
}
13+
614
.input-files {
715
height: 100px;
816
width: 100%;

0 commit comments

Comments
 (0)