@@ -59,10 +59,13 @@ function setNewMicroservice(){
59
59
if ( $ ( "#input-hidden-mavenhomelocation" ) . val ( ) == '' && $ ( "#input-newmicroservice-build-tool" ) . val ( ) == 'maven' ) {
60
60
$ ( "#form-mavenhomelocation" ) . addClass ( "has-error" ) ;
61
61
} else {
62
- cleaningNewMicroserviceFrom ( ) ;
63
- if ( $ ( "#input-newmicroservice-name" ) . val ( ) == '' || $ ( "#input-newmicroservice-pomlocation" ) . val ( ) == '' || $ ( "#input-newmicroservice-defaultport" ) . val ( ) == '' || $ ( "#input-newmicroservice-build-tool" ) . val ( ) == '-1' ) {
64
- checkEachNewMicroserviceFromField ( ) ;
65
- } else {
62
+ var fieldsToCheck = [ ] ;
63
+ fieldsToCheck . push ( "newmicroservice-name" ) ;
64
+ fieldsToCheck . push ( "newmicroservice-pomlocation" ) ;
65
+ fieldsToCheck . push ( "newmicroservice-defaultport" ) ;
66
+ fieldsToCheck . push ( "newmicroservice-build-tool" ) ;
67
+
68
+ if ( ! cheackEmptyValuesForm ( fieldsToCheck ) ) {
66
69
$ ( '.front-loading' ) . show ( ) ;
67
70
$ . ajax ( {
68
71
url : "/settings/setnewmicroservice" ,
@@ -81,41 +84,6 @@ function setNewMicroservice(){
81
84
}
82
85
}
83
86
84
- function cleaningNewMicroserviceFrom ( ) {
85
- $ ( "#form-newmicroservice-name" ) . removeClass ( "has-error" ) ;
86
- $ ( "#form-newmicroservice-pomlocation" ) . removeClass ( "has-error" ) ;
87
- $ ( "#form-newmicroservice-defaultport" ) . removeClass ( "has-error" ) ;
88
- $ ( "#form-newmicroservice-build-tool" ) . removeClass ( "has-error" ) ;
89
-
90
- $ ( "#form-newmicroservice-name" ) . removeClass ( "has-success" ) ;
91
- $ ( "#form-newmicroservice-pomlocation" ) . removeClass ( "has-success" ) ;
92
- $ ( "#form-newmicroservice-defaultport" ) . removeClass ( "has-success" ) ;
93
- $ ( "#form-newmicroservice-build-tool" ) . removeClass ( "has-success" ) ;
94
- }
95
-
96
- function checkEachNewMicroserviceFromField ( ) {
97
- if ( $ ( "#input-newmicroservice-name" ) . val ( ) == '' ) {
98
- $ ( "#form-newmicroservice-name" ) . addClass ( "has-error" ) ;
99
- } else {
100
- $ ( "#form-newmicroservice-name" ) . addClass ( "has-success" ) ;
101
- }
102
- if ( $ ( "#input-newmicroservice-pomlocation" ) . val ( ) == '' ) {
103
- $ ( "#form-newmicroservice-pomlocation" ) . addClass ( "has-error" ) ;
104
- } else {
105
- $ ( "#form-newmicroservice-pomlocation" ) . addClass ( "has-success" ) ;
106
- }
107
- if ( $ ( "#input-newmicroservice-defaultport" ) . val ( ) == '' ) {
108
- $ ( "#form-newmicroservice-defaultport" ) . addClass ( "has-error" ) ;
109
- } else {
110
- $ ( "#form-newmicroservice-defaultport" ) . addClass ( "has-success" ) ;
111
- }
112
- if ( $ ( "#input-newmicroservice-build-tool" ) . val ( ) == '-1' ) {
113
- $ ( "#form-newmicroservice-build-tool" ) . addClass ( "has-error" ) ;
114
- } else {
115
- $ ( "#form-newmicroservice-build-tool" ) . addClass ( "has-success" ) ;
116
- }
117
- }
118
-
119
87
function removeMicroservice ( microserviceId ) {
120
88
$ ( '.front-loading' ) . show ( ) ;
121
89
$ . ajax ( {
@@ -350,4 +318,83 @@ function showNotification(notificationType, notificationMessage){
350
318
351
319
$ ( document ) . ready ( function ( ) {
352
320
$ ( '[data-toggle="git-popover"]' ) . popover ( ) ;
353
- } ) ;
321
+ $ ( "#tab-newmicroservice-git-repo" ) . addClass ( "active" ) ;
322
+ $ ( '#content-file-system' ) . hide ( ) ;
323
+ } ) ;
324
+
325
+ function showNewMsForm ( component ) {
326
+ $ ( '#content-file-system' ) . hide ( ) ;
327
+ $ ( '#content-newmicroservice-git-repo' ) . hide ( ) ;
328
+ $ ( '#content-' + component ) . show ( ) ;
329
+
330
+ $ ( "#tab-newmicroservice-git-repo" ) . removeClass ( "active" ) ;
331
+ $ ( "#tab-file-system" ) . removeClass ( "active" ) ;
332
+ $ ( "#tab-" + component ) . addClass ( "active" ) ;
333
+ }
334
+
335
+ function fillFormGitNewMs ( ) {
336
+ var girUrl = $ ( '#input-git-newmicroservice-repo' ) . val ( ) ;
337
+ var repoName = girUrl . split ( "/" ) [ girUrl . split ( "/" ) . length - 1 ] . replace ( '.git' , '' ) ;
338
+
339
+ $ ( '#input-git-newmicroservice-name' ) . val ( repoName ) ;
340
+ $ ( '#input-git-newmicroservice-destination' ) . val ( settingsFolder + "/" + repoName ) ;
341
+ $ ( '#input-git-newmicroservice-pomlocation' ) . val ( settingsFolder + "/" + repoName ) ;
342
+ $ ( '#input-git-newmicroservice-gitLocation' ) . val ( settingsFolder + "/" + repoName ) ;
343
+ }
344
+
345
+ function setNewMicroserviceFromGit ( ) {
346
+ var fieldsToCheck = [ ] ;
347
+ fieldsToCheck . push ( "git-newmicroservice-repo" ) ;
348
+ fieldsToCheck . push ( "git-newmicroservice-destination" ) ;
349
+ fieldsToCheck . push ( "git-newmicroservice-name" ) ;
350
+ fieldsToCheck . push ( "git-newmicroservice-pomlocation" ) ;
351
+ fieldsToCheck . push ( "git-newmicroservice-defaultport" ) ;
352
+ fieldsToCheck . push ( "git-newmicroservice-build-tool" ) ;
353
+ fieldsToCheck . push ( "git-newmicroservice-gitLocation" ) ;
354
+
355
+ if ( $ ( "#input-hidden-mavenhomelocation" ) . val ( ) == '' && $ ( "#input-newmicroservice-build-tool" ) . val ( ) == 'maven' ) {
356
+ $ ( "#form-mavenhomelocation" ) . addClass ( "has-error" ) ;
357
+ } else {
358
+ if ( ! cheackEmptyValuesForm ( fieldsToCheck ) ) {
359
+ $ ( '.front-loading' ) . show ( ) ;
360
+ $ . ajax ( {
361
+ url : "/settings/setnewmicroservice/git" ,
362
+ type : "POST" ,
363
+ data : { gitRepo : $ ( '#input-git-newmicroservice-repo' ) . val ( ) ,
364
+ destinationFolder : $ ( '#input-git-newmicroservice-destination' ) . val ( ) ,
365
+ name : $ ( "#input-git-newmicroservice-name" ) . val ( ) ,
366
+ pomLocation : $ ( "#input-git-newmicroservice-pomlocation" ) . val ( ) ,
367
+ defaultPort : $ ( "#input-git-newmicroservice-defaultport" ) . val ( ) ,
368
+ actuatorPrefix : $ ( "#input-git-newmicroservice-actuatorprefix" ) . val ( ) ,
369
+ vmArguments : $ ( "#input-git-newmicroservice-vmarguments" ) . val ( ) ,
370
+ buildTool : $ ( "#input-git-newmicroservice-build-tool" ) . val ( ) ,
371
+ gitLocation : $ ( "#input-git-newmicroservice-gitLocation" ) . val ( ) } ,
372
+ success : function ( data , textStatus , jqXHR ) { location . reload ( ) ; } ,
373
+ error : function ( request , status , error ) {
374
+ $ ( '.front-loading' ) . hide ( ) ;
375
+ showNotification ( 'danger' , "Error occurred when trying to register a microservice. Check Logs for more info" ) ;
376
+
377
+ }
378
+ } ) ;
379
+ }
380
+ }
381
+ }
382
+
383
+ function cheackEmptyValuesForm ( fieldsToCheck ) {
384
+ var errors = false ;
385
+ fieldsToCheck . forEach ( function ( field ) {
386
+ $ ( "#form-" + field ) . removeClass ( "has-error" ) ;
387
+ $ ( "#form-" + field ) . removeClass ( "has-success" ) ;
388
+
389
+ if ( $ ( "#input-" + field ) . val ( ) == '' || $ ( "#input-" + field ) . val ( ) == '-1' ) {
390
+ errors = true
391
+ $ ( "#form-" + field ) . addClass ( "has-error" ) ;
392
+ } else {
393
+ $ ( "#form-" + field ) . addClass ( "has-success" ) ;
394
+ }
395
+ } ) ;
396
+
397
+ return errors ;
398
+ }
399
+
400
+
0 commit comments