Skip to content

Commit 484a143

Browse files
authored
feat: Adjust administration handling for test button and add some more context (#100)
1 parent 9aa225a commit 484a143

File tree

4 files changed

+69
-53
lines changed

4 files changed

+69
-53
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import './module/frosh-thumbnail-processor/frosh-thumbnail-processor-info-texts';
22
import './module/frosh-thumbnail-processor/test-button'
3+
34
import './service/thumbnailProcessorTestService';

src/Resources/app/administration/src/module/frosh-thumbnail-processor/test-button/index.js

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ Component.register('thumbnailprocessor-test', {
2121

2222
computed: {
2323
pluginSalesChannelId() {
24-
let configData = this.$parent;
25-
for (let i = 0; i < 20; i++) {
26-
if (typeof configData.currentSalesChannelId != "undefined") {
27-
return configData.currentSalesChannelId;
28-
}
24+
const configComponent = this.getParentComponent();
2925

30-
configData = configData.$parent;
26+
if (!configComponent) {
27+
throw "Can not get pluginConfigData";
3128
}
3229

33-
throw "Can not get pluginConfigData";
30+
return configComponent.currentSalesChannelId;
3431
}
3532
},
3633

@@ -52,47 +49,43 @@ Component.register('thumbnailprocessor-test', {
5249
});
5350
},
5451

55-
saveAndCheck() {
56-
this.isLoading = true;
57-
this.systemConfigSaveAll();
58-
},
59-
6052
check() {
61-
const me = this;
53+
this.isLoading = true;
6254

63-
me.thumbnailProcessorTest.getUrl(this.pluginSalesChannelId).then((res) => {
55+
this.thumbnailProcessorTest.getUrl(this.pluginSalesChannelId).then((res) => {
6456
if (res.url) {
65-
me.isSuccessful = true;
66-
57+
this.isSuccessful = true;
58+
const me = this;
6759
const img = document.createElement('img');
68-
img.width = 200;
69-
img.height = 200;
60+
const testImageContainerElement = document.querySelector('#testimage-container');
61+
const testImageElement = testImageContainerElement.querySelector('img');
62+
const testResultElement = document.querySelector('#test-result');
7063

64+
img.src = res.url;
65+
img.width = 200;
66+
img.height = 200;
7167
img.onload = function() {
7268
if (img.naturalWidth !== 200) {
69+
testResultElement.innerText = me.$tc('thumbnail-processor.test.error.noResize');
7370
me.showError(me.$tc('thumbnail-processor.test.error.noResize'), res.url);
7471
}
7572
};
76-
7773
img.onerror = function() {
74+
testImageElement.height = 0;
75+
testImageElement.width = 0;
76+
testResultElement.innerText = me.$tc('thumbnail-processor.test.error.general');
7877
me.showError(me.$tc('thumbnail-processor.test.error.general'), res.url);
7978
};
8079

81-
img.src = res.url;
80+
if (testImageElement) {
81+
testImageElement.replaceWith(img);
8282

83-
const testElement = document.querySelector('[name="FroshPlatformThumbnailProcessor.config.test"]');
84-
const testImage = testElement.querySelector('.frosh-thumbnail-processor-testimage img');
85-
86-
if (testImage) {
87-
testImage.replaceWith(img);
88-
} else {
89-
const testImageContainer = document.createElement('p');
90-
testImageContainer.classList.add('frosh-thumbnail-processor-testimage');
91-
testImageContainer.appendChild(img);
92-
testElement.appendChild(testImageContainer);
83+
return;
9384
}
85+
86+
testImageContainerElement.appendChild(img);
9487
} else {
95-
me.showError(me.$tc('thumbnail-processor.test.error.general'));
88+
this.showError(this.$tc('thumbnail-processor.test.error.general'));
9689
}
9790

9891
setTimeout(() => {
@@ -102,21 +95,32 @@ Component.register('thumbnailprocessor-test', {
10295
},
10396

10497
systemConfigSaveAll() {
105-
const me = this;
106-
let el = this.$parent;
107-
108-
for (let i = 0; i < 30; i++) {
109-
if (typeof el.$refs.systemConfig != "undefined") {
110-
return el.$refs.systemConfig.saveAll()
111-
.then(() => {
112-
me.check();
113-
})
114-
}
98+
this.isLoading = true;
99+
const configComponent = this.getParentComponent();
100+
101+
if (!configComponent) {
102+
this.isLoading = false;
115103

116-
el = el.$parent;
104+
throw "Can not get systemConfig";
117105
}
118106

119-
throw "Can not get systemConfig";
120-
}
121-
}
107+
configComponent.saveAll()
108+
.then(() => {
109+
this.check();
110+
this.isLoading = false;
111+
});
112+
},
113+
114+
getParentComponent (component = this) {
115+
if (typeof component.actualConfigData !== 'undefined') {
116+
return component;
117+
}
118+
119+
if (component.$parent) {
120+
return this.getParentComponent(component.$parent);
121+
}
122+
123+
return null;
124+
},
125+
},
122126
})
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
.frosh-thumbnail-processor-testimage {
1+
.frosh-thumbnail-processor .testdata-container {
22
margin: 20px 0;
33
}
4+
5+
#test-result {
6+
margin: 10px 0;
7+
}
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
<div>
1+
<sw-card class="sub-card frosh-thumbnail-processor">
22
<sw-button-process
3-
:isLoading="isLoading"
4-
:processSuccess="isSuccessful"
5-
@process-finish="finish"
6-
@click="saveAndCheck"
7-
>{{ btnLabel }}</sw-button-process>
8-
</div>
3+
class="frosh-thumbnail-processor--test-button"
4+
:isLoading="isLoading"
5+
:processSuccess="isSuccessful"
6+
@process-finish="finish"
7+
@click="systemConfigSaveAll">
8+
{{ btnLabel }}
9+
</sw-button-process>
10+
11+
<div class="testdata-container">
12+
<p id="test-result"></p>
13+
<div id="testimage-container"></div>
14+
</div>
15+
</sw-card>

0 commit comments

Comments
 (0)