6
6
'use strict' ;
7
7
8
8
define ( [ 'accUtils' , 'knockout' , 'utils/i18n' , 'models/wkt-project' , 'utils/view-helper' , 'ojs/ojarraydataprovider' ,
9
- 'ojs/ojbufferingdataprovider' , 'utils/observable-properties' , 'ojs/ojconverter-number' , 'ojs/ojinputtext' ,
10
- 'ojs/ojlabel' , 'ojs/ojbutton' , 'ojs/ojdialog' , 'ojs/ojformlayout' , 'ojs/ojvalidationgroup' , 'ojs/ojselectcombobox' ] ,
11
- function ( accUtils , ko , i18n , project , viewHelper , ArrayDataProvider , BufferingDataProvider , props , ojConverterNumber ) {
9
+ 'ojs/ojbufferingdataprovider' , 'utils/observable-properties' , 'ojs/ojconverter-number' , 'utils/wkt-logger' ,
10
+ 'ojs/ojinputtext' , 'ojs/ojlabel' , 'ojs/ojbutton' , 'ojs/ojdialog' , 'ojs/ojformlayout' , 'ojs/ojvalidationgroup' ,
11
+ 'ojs/ojselectcombobox' ] ,
12
+ function ( accUtils , ko , i18n , project , viewHelper , ArrayDataProvider , BufferingDataProvider , props ,
13
+ ojConverterNumber ) {
12
14
function RouteEditDialogModel ( args ) {
13
15
const DIALOG_SELECTOR = '#routeEditDialog' ;
14
16
15
- const DEFAULT_ROUTE_PORT = 0 ;
17
+ const DEFAULT_ROUTE_PORT = undefined ;
16
18
17
19
// SIMPLE_PROPERTIES - names matching simple route fields
18
20
let EXCLUDE_PROPERTIES = [ 'uid' , 'annotations' ] ;
19
21
let SIMPLE_PROPERTIES = project . ingress . ingressRouteKeys . filter ( key => ! EXCLUDE_PROPERTIES . includes ( key ) ) ;
20
22
23
+ this . project = project ;
24
+ this . route = args . route ;
25
+ this . serviceList = args . serviceList ;
26
+
21
27
this . connected = ( ) => {
22
28
accUtils . announce ( 'Route edit dialog loaded.' , 'assertive' ) ;
23
-
24
29
// open the dialog after the current thread, which is loading this view model.
25
30
// using oj-dialog initial-visibility="show" causes vertical centering issues.
26
31
setTimeout ( function ( ) {
@@ -36,13 +41,9 @@ function(accUtils, ko, i18n, project, viewHelper, ArrayDataProvider, BufferingDa
36
41
return i18n . t ( labelId , arg ) ;
37
42
} ;
38
43
39
- this . project = project ;
40
- this . route = args . route ;
41
- this . serviceList = args . serviceList ;
42
-
43
44
this . buildTargetSvcNames = ( ) => {
44
45
let options = [ ] ;
45
- for ( var name in this . serviceList ) {
46
+ for ( const name in this . serviceList ) {
46
47
options . push ( { id : name , value : name , text : name } ) ;
47
48
}
48
49
return options ;
@@ -52,7 +53,7 @@ function(accUtils, ko, i18n, project, viewHelper, ArrayDataProvider, BufferingDa
52
53
let options = [ ] ;
53
54
if ( this . serviceList [ svcName ] ) {
54
55
for ( const port of this . serviceList [ svcName ] . ports ) {
55
- options . push ( { id : port . port , value : port . port , text : port . port } ) ;
56
+ options . push ( { id : port . port , value : port . port , text : port . port } ) ;
56
57
}
57
58
}
58
59
@@ -64,7 +65,7 @@ function(accUtils, ko, i18n, project, viewHelper, ArrayDataProvider, BufferingDa
64
65
this . targetSvcPorts = ko . observableArray ( [ ] ) ;
65
66
66
67
if ( this . route . targetService ) {
67
- this . targetSvcPorts = this . buildTargetSvcPorts ( this . route . targetService ) ;
68
+ this . buildTargetSvcPorts ( this . route . targetService ) . forEach ( port => this . targetSvcPorts . push ( port ) ) ;
68
69
}
69
70
70
71
this . savedAnnotations = args . route . annotations || { } ;
@@ -144,6 +145,24 @@ function(accUtils, ko, i18n, project, viewHelper, ArrayDataProvider, BufferingDa
144
145
this [ propertyName ] = props . createProperty ( defaultValue ) ;
145
146
} ) ;
146
147
148
+ this . getTargetServicePlaceholder = ko . computed ( ( ) => {
149
+ if ( Array . isArray ( this . targetSvcNames ) && this . targetSvcNames . length > 0 ) {
150
+ return this . labelMapper ( 'route-targetservice-placeholder' ) ;
151
+ } else {
152
+ return this . labelMapper ( 'route-targetservice-placeholder-empty' ) ;
153
+ }
154
+ } ) ;
155
+
156
+ this . getTargetPortPlaceholder = ko . computed ( ( ) => {
157
+ console . log ( 'targetSvcPorts is a ' + typeof ( this . targetSvcPorts ) ) ;
158
+ const ports = this . targetSvcPorts ( ) ;
159
+ if ( Array . isArray ( ports ) && ports . length > 0 ) {
160
+ return this . labelMapper ( 'route-targetport-placeholder' ) ;
161
+ } else {
162
+ return this . labelMapper ( 'route-targetport-placeholder-empty' ) ;
163
+ }
164
+ } ) ;
165
+
147
166
this . handleAddAnnotation = ( ) => {
148
167
const nextIndex = this . nextAnnotationIndex ( ) ;
149
168
const annotation = { uid : getAnnotationUid ( nextIndex ) , key : `annotation-${ nextIndex } ` } ;
@@ -186,10 +205,7 @@ function(accUtils, ko, i18n, project, viewHelper, ArrayDataProvider, BufferingDa
186
205
187
206
this . targetSvcNameChanged = ( event ) => {
188
207
this . targetSvcPorts . removeAll ( ) ;
189
- const list = this . buildTargetSvcPorts ( event . detail . value ) ;
190
- for ( const item of list ) {
191
- this . targetSvcPorts . push ( item ) ;
192
- }
208
+ this . buildTargetSvcPorts ( event . detail . value ) . forEach ( port => this . targetSvcPorts . push ( port ) ) ;
193
209
} ;
194
210
195
211
this . okInput = ( ) => {
0 commit comments