@@ -21,16 +21,13 @@ Component.register('thumbnailprocessor-test', {
21
21
22
22
computed : {
23
23
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 ( ) ;
29
25
30
- configData = configData . $parent ;
26
+ if ( ! configComponent ) {
27
+ throw "Can not get pluginConfigData" ;
31
28
}
32
29
33
- throw "Can not get pluginConfigData" ;
30
+ return configComponent . currentSalesChannelId ;
34
31
}
35
32
} ,
36
33
@@ -52,47 +49,43 @@ Component.register('thumbnailprocessor-test', {
52
49
} ) ;
53
50
} ,
54
51
55
- saveAndCheck ( ) {
56
- this . isLoading = true ;
57
- this . systemConfigSaveAll ( ) ;
58
- } ,
59
-
60
52
check ( ) {
61
- const me = this ;
53
+ this . isLoading = true ;
62
54
63
- me . thumbnailProcessorTest . getUrl ( this . pluginSalesChannelId ) . then ( ( res ) => {
55
+ this . thumbnailProcessorTest . getUrl ( this . pluginSalesChannelId ) . then ( ( res ) => {
64
56
if ( res . url ) {
65
- me . isSuccessful = true ;
66
-
57
+ this . isSuccessful = true ;
58
+ const me = this ;
67
59
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' ) ;
70
63
64
+ img . src = res . url ;
65
+ img . width = 200 ;
66
+ img . height = 200 ;
71
67
img . onload = function ( ) {
72
68
if ( img . naturalWidth !== 200 ) {
69
+ testResultElement . innerText = me . $tc ( 'thumbnail-processor.test.error.noResize' ) ;
73
70
me . showError ( me . $tc ( 'thumbnail-processor.test.error.noResize' ) , res . url ) ;
74
71
}
75
72
} ;
76
-
77
73
img . onerror = function ( ) {
74
+ testImageElement . height = 0 ;
75
+ testImageElement . width = 0 ;
76
+ testResultElement . innerText = me . $tc ( 'thumbnail-processor.test.error.general' ) ;
78
77
me . showError ( me . $tc ( 'thumbnail-processor.test.error.general' ) , res . url ) ;
79
78
} ;
80
79
81
- img . src = res . url ;
80
+ if ( testImageElement ) {
81
+ testImageElement . replaceWith ( img ) ;
82
82
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 ;
93
84
}
85
+
86
+ testImageContainerElement . appendChild ( img ) ;
94
87
} else {
95
- me . showError ( me . $tc ( 'thumbnail-processor.test.error.general' ) ) ;
88
+ this . showError ( this . $tc ( 'thumbnail-processor.test.error.general' ) ) ;
96
89
}
97
90
98
91
setTimeout ( ( ) => {
@@ -102,21 +95,32 @@ Component.register('thumbnailprocessor-test', {
102
95
} ,
103
96
104
97
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 ;
115
103
116
- el = el . $parent ;
104
+ throw "Can not get systemConfig" ;
117
105
}
118
106
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
+ } ,
122
126
} )
0 commit comments