@@ -16,6 +16,7 @@ import Set exposing (Set)
16
16
import Maybe
17
17
import Maybe.Extra exposing (isJust , join )
18
18
import Json.Decode
19
+ import Regex exposing (contains , regex )
19
20
20
21
21
22
editingParamColor =
@@ -223,6 +224,24 @@ editParameterValueView instance parameterValues parameterInfos maybeInstancePara
223
224
( Nothing , Just ( Just original) ) ->
224
225
original
225
226
227
+ dataType =
228
+ maybeParameterInfo
229
+ |> Maybe . andThen ( \ i -> i. dataType)
230
+ |> Maybe . withDefault RawParam
231
+
232
+ maybeErrMsg =
233
+ case maybeEditedValue of
234
+ Just value ->
235
+ if String . isEmpty value then
236
+ Nothing -- In this case the default value gets picked up
237
+ else getErrorMsg value dataType
238
+ Nothing -> Nothing
239
+
240
+ hasError =
241
+ case maybeErrMsg of
242
+ Nothing -> False
243
+ Just _ -> True
244
+
226
245
isSecret =
227
246
maybeParameterInfo
228
247
|> Maybe . andThen ( \ i -> i. secret)
@@ -238,69 +257,83 @@ editParameterValueView instance parameterValues parameterInfos maybeInstancePara
238
257
in
239
258
p
240
259
[]
241
- [ div
242
- [ class " input-group" ]
243
- ( List . append
244
- [ span
245
- [ class " input-group-addon"
246
- , style
247
- [ ( " background-color" , Maybe . withDefault normalParamColor ( Maybe . map ( \ v -> editingParamColor) maybeEditedValue) )
248
- ]
249
- ]
250
- [ text parameterName ]
251
- , input
252
- [ type_
253
- ( if ( isSecret && ( not secretVisible)) then
254
- " password"
255
- else
256
- " text"
257
- )
258
- , class " form-control"
259
- , attribute " aria-label" parameter
260
- , placeholder placeholderValue
261
- , value parameterValue
262
- , disabled ( not enabled)
263
- , onInput ( EnterEditInstanceParameterValue instance parameter)
264
- ]
265
- []
260
+ ( List . append
261
+ [ div
262
+ [ classList [
263
+ ( " input-group" , True ) ,
264
+ ( " has-error" , hasError)
265
+ ]
266
266
]
267
- ( if ( isSecret && enabled ) then
268
- [ a
267
+ ( List . append
268
+ [ span
269
269
[ class " input-group-addon"
270
- , attribute " role" " button"
271
- , onClick ( ToggleEditInstanceSecretVisibility instance. id parameter)
270
+ , style
271
+ [ ( " background-color" , Maybe . withDefault normalParamColor ( Maybe . map ( \ v -> editingParamColor) maybeEditedValue) )
272
+ ]
272
273
]
273
- [ icon
274
- ( String . concat
275
- [ " glyphicon glyphicon-eye-"
276
- , ( if secretVisible then
277
- " close"
278
- else
279
- " open"
280
- )
281
- ]
274
+ [ text parameterName ]
275
+ , input
276
+ [ type_
277
+ ( if ( isSecret && ( not secretVisible)) then
278
+ " password"
279
+ else
280
+ " text"
282
281
)
283
- []
282
+ , class " form-control"
283
+ , attribute " aria-label" parameter
284
+ , placeholder placeholderValue
285
+ , value parameterValue
286
+ , disabled ( not enabled)
287
+ , onInput ( EnterEditInstanceParameterValue instance parameter)
284
288
]
285
- , a
286
- [ class " input-group-addon"
287
- , attribute " role" " button"
288
- , attribute
289
- " onclick"
290
- ( String . concat
291
- [ " copy('"
292
- , parameterValue
293
- , " ')"
294
- ]
295
- )
296
- ]
297
- [ icon " glyphicon glyphicon-copy" [] ]
289
+ []
298
290
]
299
- else
300
- []
291
+ ( if ( isSecret && enabled) then
292
+ [ a
293
+ [ class " input-group-addon"
294
+ , attribute " role" " button"
295
+ , onClick ( ToggleEditInstanceSecretVisibility instance. id parameter)
296
+ ]
297
+ [ icon
298
+ ( String . concat
299
+ [ " glyphicon glyphicon-eye-"
300
+ , ( if secretVisible then
301
+ " close"
302
+ else
303
+ " open"
304
+ )
305
+ ]
306
+ )
307
+ []
308
+ ]
309
+ , a
310
+ [ class " input-group-addon"
311
+ , attribute " role" " button"
312
+ , attribute
313
+ " onclick"
314
+ ( String . concat
315
+ [ " copy('"
316
+ , parameterValue
317
+ , " ')"
318
+ ]
319
+ )
320
+ ]
321
+ [ icon " glyphicon glyphicon-copy" [] ]
322
+ ]
323
+ else
324
+ []
325
+ )
301
326
)
302
- )
303
- ]
327
+ ]
328
+ ( case maybeErrMsg of
329
+ Nothing -> []
330
+ Just msg ->
331
+ [ span
332
+ [ class " help-block" ]
333
+ [ text msg]
334
+ ]
335
+ )
336
+ )
304
337
305
338
306
339
newView template maybeInstanceParameterForm visibleSecrets =
@@ -404,6 +437,11 @@ newParameterValueView template parameterInfos maybeInstanceParameterForm enabled
404
437
maybeEditedValue
405
438
|> Maybe . withDefault " "
406
439
440
+ dataType =
441
+ maybeParameterInfo
442
+ |> Maybe . andThen ( \ i -> i. dataType)
443
+ |> Maybe . withDefault RawParam
444
+
407
445
isSecret =
408
446
maybeParameterInfo
409
447
|> Maybe . andThen ( \ i -> i. secret)
@@ -416,73 +454,112 @@ newParameterValueView template parameterInfos maybeInstanceParameterForm enabled
416
454
maybeParameterInfo
417
455
|> Maybe . andThen ( \ i -> i. name)
418
456
|> Maybe . withDefault parameter
457
+
458
+ maybeErrMsg =
459
+ case maybeEditedValue of
460
+ Just value ->
461
+ if String . isEmpty value then
462
+ Nothing -- In this case the default value gets picked up
463
+ else getErrorMsg value dataType
464
+ Nothing -> Nothing
465
+
466
+ hasError =
467
+ case maybeErrMsg of
468
+ Nothing -> False
469
+ Just _ -> True
419
470
in
420
471
p
421
472
[]
422
- [ div
423
- [ class " input-group"
424
- , id <| String . concat [ " new-instance-form-input-group-" , template. id, " -" , parameter ]
425
- ]
426
- ( List . append
427
- [ span
428
- [ class " input-group-addon"
429
- , style
430
- [ ( " background-color" , Maybe . withDefault normalParamColor ( Maybe . map ( \ v -> editingParamColor) maybeEditedValue) )
431
- ]
432
- ]
433
- [ text parameterName ]
434
- , input
435
- [ type_
436
- ( if ( isSecret && ( not secretVisible)) then
437
- " password"
438
- else
439
- " text"
440
- )
441
- , class " form-control"
442
- , attribute " aria-label" parameter
443
- , placeholder placeholderValue
444
- , value parameterValue
445
- , disabled ( not enabled)
446
- , id <| String . concat [ " new-instance-form-parameter-input-" , template. id, " -" , parameter ]
447
- , onInput ( EnterNewInstanceParameterValue template. id parameter)
473
+ ( List . append
474
+ [ div
475
+ [ classList [
476
+ ( " input-group" , True ) ,
477
+ ( " has-error" , hasError)
448
478
]
449
- [ ]
479
+ , id <| String . concat [ " new-instance-form-input-group- " , template . id , " - " , parameter ]
450
480
]
451
- ( if ( isSecret ) then
452
- [ a
481
+ ( List . append
482
+ [ span
453
483
[ class " input-group-addon"
454
- , attribute " role " " button "
455
- , onClick ( ToggleNewInstanceSecretVisibility template . id parameter )
456
- , id <| String . concat [ " new-instance-form-parameter-secret-visibility- " , template . id , " - " , parameter ]
484
+ , style
485
+ [ ( " background-color " , Maybe . withDefault normalParamColor ( Maybe . map ( \ v -> editingParamColor ) maybeEditedValue ) )
486
+ ]
457
487
]
458
- [ icon
459
- ( String . concat
460
- [ " glyphicon glyphicon-eye-"
461
- , ( if secretVisible then
462
- " close"
463
- else
464
- " open"
465
- )
466
- ]
488
+ [ text parameterName ]
489
+ , input
490
+ [ type_
491
+ ( if ( isSecret && ( not secretVisible)) then
492
+ " password"
493
+ else
494
+ " text"
467
495
)
468
- []
496
+ , class " form-control"
497
+ , attribute " aria-label" parameter
498
+ , placeholder placeholderValue
499
+ , value parameterValue
500
+ , disabled ( not enabled)
501
+ , id <| String . concat [ " new-instance-form-parameter-input-" , template. id, " -" , parameter ]
502
+ , onInput ( EnterNewInstanceParameterValue template. id parameter)
469
503
]
470
- , a
471
- [ class " input-group-addon"
472
- , attribute " role" " button"
473
- , attribute
474
- " onclick"
475
- ( String . concat
476
- [ " copy('"
477
- , parameterValue
478
- , " ')"
479
- ]
480
- )
481
- ]
482
- [ icon " glyphicon glyphicon-copy" [] ]
504
+ []
483
505
]
484
- else
485
- []
506
+ ( if ( isSecret) then
507
+ [ a
508
+ [ class " input-group-addon"
509
+ , attribute " role" " button"
510
+ , onClick ( ToggleNewInstanceSecretVisibility template. id parameter)
511
+ , id <| String . concat [ " new-instance-form-parameter-secret-visibility-" , template. id, " -" , parameter ]
512
+ ]
513
+ [ icon
514
+ ( String . concat
515
+ [ " glyphicon glyphicon-eye-"
516
+ , ( if secretVisible then
517
+ " close"
518
+ else
519
+ " open"
520
+ )
521
+ ]
522
+ )
523
+ []
524
+ ]
525
+ , a
526
+ [ class " input-group-addon"
527
+ , attribute " role" " button"
528
+ , attribute
529
+ " onclick"
530
+ ( String . concat
531
+ [ " copy('"
532
+ , parameterValue
533
+ , " ')"
534
+ ]
535
+ )
536
+ ]
537
+ [ icon " glyphicon glyphicon-copy" [] ]
538
+ ]
539
+ else
540
+ []
541
+ )
486
542
)
487
- )
488
- ]
543
+ ]
544
+ ( case maybeErrMsg of
545
+ Nothing -> []
546
+ Just msg ->
547
+ [ span
548
+ [ class " help-block" ]
549
+ [ text msg]
550
+ ]
551
+ )
552
+ )
553
+
554
+ getErrorMsg : String -> DataType -> Maybe String
555
+ getErrorMsg value dataType =
556
+ case dataType of
557
+ -- we do not validate string and raw fields
558
+ StringParam -> Nothing
559
+ RawParam -> Nothing
560
+ NumericParam ->
561
+ let
562
+ expr = regex " ^-?[0-9]+(\\ .[0-9]+)?$"
563
+ in
564
+ if ( contains expr value) then Nothing
565
+ else Just " Not a valid number"
0 commit comments