diff --git a/ui/src/main/webapp/src/app/registered-application/edit-application-form.component.ts b/ui/src/main/webapp/src/app/registered-application/edit-application-form.component.ts index 67103705f..1bbb185af 100644 --- a/ui/src/main/webapp/src/app/registered-application/edit-application-form.component.ts +++ b/ui/src/main/webapp/src/app/registered-application/edit-application-form.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit} from "@angular/core"; +import {ChangeDetectorRef, Component, OnInit} from "@angular/core"; import {FormBuilder, Validators} from "@angular/forms"; import {ActivatedRoute, Router} from "@angular/router"; import {RegisteredApplication, RegistrationType} from "../generated/windup-services"; @@ -27,10 +27,11 @@ export class EditApplicationFormComponent extends RegisterApplicationFormCompone _routeFlattener: RouteFlattenerService, _eventBus: EventBusService, _migrationProjectService: MigrationProjectService, - _notificationService: NotificationService + _notificationService: NotificationService, + _changeDetectorRef: ChangeDetectorRef ) { super(_router, _activatedRoute, _fileService, _registeredApplicationService, _formBuilder, _routeFlattener, - _eventBus, _migrationProjectService, _notificationService); + _eventBus, _migrationProjectService, _notificationService, _changeDetectorRef); this.labels.heading = 'Update application'; this.labels.uploadButton = 'Update'; diff --git a/ui/src/main/webapp/src/app/registered-application/register-application-form.component.html b/ui/src/main/webapp/src/app/registered-application/register-application-form.component.html index a86d3d369..7984925c2 100644 --- a/ui/src/main/webapp/src/app/registered-application/register-application-form.component.html +++ b/ui/src/main/webapp/src/app/registered-application/register-application-form.component.html @@ -88,6 +88,9 @@

{{labels.heading}}

+
+ +
@@ -96,7 +99,7 @@

{{labels.heading}}

- +
diff --git a/ui/src/main/webapp/src/app/registered-application/register-application-form.component.ts b/ui/src/main/webapp/src/app/registered-application/register-application-form.component.ts index 8e1413f1b..389e7e932 100644 --- a/ui/src/main/webapp/src/app/registered-application/register-application-form.component.ts +++ b/ui/src/main/webapp/src/app/registered-application/register-application-form.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy} from "@angular/core"; +import {Component, OnInit, OnDestroy, ChangeDetectorRef} from "@angular/core"; import {FormBuilder, FormGroup, Validators} from "@angular/forms"; import {ActivatedRoute, Router, NavigationEnd} from "@angular/router"; import {FileUploader} from "ng2-file-upload/ng2-file-upload"; @@ -43,7 +43,7 @@ export class RegisterApplicationFormComponent extends FormComponent implements O labels = { heading: 'Add Applications', - uploadButton: 'Upload' + uploadButton: 'Done' }; constructor( @@ -55,7 +55,8 @@ export class RegisterApplicationFormComponent extends FormComponent implements O protected _routeFlattener: RouteFlattenerService, protected _eventBus: EventBusService, protected _migrationProjectService: MigrationProjectService, - protected _notificationService: NotificationService + protected _notificationService: NotificationService, + protected _changeDetectorRef: ChangeDetectorRef ) { super(); @@ -138,42 +139,40 @@ export class RegisterApplicationFormComponent extends FormComponent implements O } register() { + if (!this.isValid) { + return false; + } + if (this.mode == "PATH") { this.registerPath(); } else { - this.navigateOnSuccess(); return false; } } - private registerPath() { - /** - * If there are already some uploaded applications, we consider form to be valid - * But if user is on Register Path section, clicking submit button triggers registering app by path with invalid - * path. - * To avoid that, treat it as success and do the navigation right away, even when no input path is set. - */ - if ((!this.fileInputPath || this.fileInputPath.length === 0) && this.isValid) { - this.navigateOnSuccess(); - return; - } - + public registerPath() { this._fileService.queryServerPathTargetType(this.fileInputPath).subscribe((type_: string) => { if (type_ === "DIRECTORY" && !this.isDirWithExplodedApp) { //this.isDirWithApps this._registeredApplicationService.registerApplicationInDirectoryByPath(this.project, this.fileInputPath) .subscribe( - application => this.navigateOnSuccess(), + () => this.clearFileInputPath(), error => this.handleError(error) ); } else { this._registeredApplicationService.registerByPath(this.project, this.fileInputPath, this.isDirWithExplodedApp).subscribe( - application => this.navigateOnSuccess(), + () => this.clearFileInputPath(), error => this.handleError(error) ) } }); } + protected clearFileInputPath() { + this.fileInputPath = ''; + // Make sure angular is aware of changes (avoids an angular exception in debug mode otherwise) + this._changeDetectorRef.detectChanges(); + } + private registerUploaded() { if (this.multipartUploader.getNotUploadedItems().length == 0) { this.handleError("Please select the file to upload."); @@ -224,7 +223,7 @@ export class RegisterApplicationFormComponent extends FormComponent implements O this.mode = mode; if (this.mode === 'PATH') { - this.labels.uploadButton = 'Upload'; + this.labels.uploadButton = 'Done'; } else if (this.mode === 'UPLOADED') { // this is not really nice, but when using UPLOADED mode, upload is done automatically // so no action is actually being executed, so label is 'Done' @@ -246,17 +245,6 @@ export class RegisterApplicationFormComponent extends FormComponent implements O } public get isValid() { - /** - * If project already has some applications, - * form is always valid for "upload" tab and also for empty path in "server path" tab. - * - * This allows us to have 'Back' step in wizard and not requiring - * user to upload new application. - */ - if (this.isInWizard && this.projectHasApplications() && this.fileInputPath.length === 0) { - return true; - } - if (this.mode === 'PATH') { const appPathField = this.registrationForm.get('appPathToRegister');