Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Commit

Permalink
fix: introduced project name validator
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit authored and ia3andy committed Jul 5, 2018
1 parent c7ce9b8 commit 5209268
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ <h2 class="card-pf-title">
</div>
</div>
</div>
<form class="form-horizontal" #form="ngForm">
<div class="container-fluid container-cards-pf" *ngIf="launcherComponent.summary?.targetEnvironment === 'os' && launcherComponent.flow !== 'launch'">
<div class="row row-cards-pf">
<div class="col-xs-12">
Expand Down Expand Up @@ -242,19 +243,15 @@ <h2 class="card-pf-title">
<label class="col-xs-4 control-label">Application Name</label>
<div class="col-xs-8 f8launcher-project-summary-data-field f8launcher-application-text-field">
<input class="f8launcher-project-summary-data-field_input f8launcher-application-text-field_input"
name="applicationTitle" placeholder="New Application" type="text"
[(ngModel)]="dependencyCheck.projectName"
[value]="launcherComponent.summary.dependencyCheck.projectName | lowercase"
(keyup.enter)="$event.target.blur();"
(keyup)="validateProjectName()">
name="applicationTitle" placeholder="New Application" type="text" #projectName="ngModel"
[(ngModel)]="dependencyCheck.projectName" lowercase validateProjectName
(keyup.enter)="$event.target.blur();">
</div>
<div class="col-xs-8 col-xs-offset-4" [ngClass]="{'has-error': launcherComponent.isProjectNameValid === false}">
<span class="help-block" *ngIf="launcherComponent.isProjectNameValid === false">
<div *ngIf="projectName.invalid && (projectName.dirty || projectName.touched)">
<span *ngIf="projectName.errors.pattern" class="help-block f8launcher-vertical-bar_application-name-help-text">
Please enter a valid Application Name.
</span>
</div>
<div class="col-xs-8 col-xs-offset-4" [ngClass]="{'has-error': launcherComponent.isProjectNameAvailable === false}">
<span class="help-block" *ngIf="launcherComponent.isProjectNameAvailable === false">
<span *ngIf="projectName.errors.duplicate" class="help-block f8launcher-vertical-bar_application-name-help-text">
Application name is already used. Please enter a new one.
</span>
</div>
Expand Down Expand Up @@ -362,35 +359,33 @@ <h2 class="card-pf-title">
</div>
<div class="card-pf-body card-column">
<div class="card-column-70">
<form class="form-horizontal">
<div class="form-group f8launcher-project-summary-data-form-group">
<label class="col-xs-5 control-label">Username</label>
<div class="col-xs-6 f8launcher-project-summary-data-field">
<div class="f8launcher-project-summary-data-field-account">
<img class="card-column_user-profile-icon"
[src]="summary?.gitHubDetails?.avatar"
*ngIf="summary?.gitHubDetails.avatar !== undefined">
<i class="fa fa-ban fa-2x"
*ngIf="summary?.gitHubDetails?.avatar === undefined"></i>
<span class="f8launcher-project-summary-data-field-account-username">
{{summary?.gitHubDetails?.login}}
</span>
</div>
<div class="form-group f8launcher-project-summary-data-form-group">
<label class="col-xs-5 control-label">Username</label>
<div class="col-xs-6 f8launcher-project-summary-data-field">
<div class="f8launcher-project-summary-data-field-account">
<img class="card-column_user-profile-icon"
[src]="summary?.gitHubDetails?.avatar"
*ngIf="summary?.gitHubDetails.avatar !== undefined">
<i class="fa fa-ban fa-2x"
*ngIf="summary?.gitHubDetails?.avatar === undefined"></i>
<span class="f8launcher-project-summary-data-field-account-username">
{{summary?.gitHubDetails?.login}}
</span>
</div>
</div>
<div class="form-group f8launcher-project-summary-data-form-group">
<label class="col-xs-5 control-label">Location</label>
<div class="col-xs-6 f8launcher-project-summary-data-field">
<span>{{summary?.gitHubDetails?.organization}}</span>
</div>
</div>
<div class="form-group f8launcher-project-summary-data-form-group">
<label class="col-xs-5 control-label">Location</label>
<div class="col-xs-6 f8launcher-project-summary-data-field">
<span>{{summary?.gitHubDetails?.organization}}</span>
</div>
<div class="form-group f8launcher-project-summary-data-form-group">
<label class="col-xs-5 control-label">Repository</label>
<div class="col-xs-6 f8launcher-project-summary-data-field">
<span>{{summary?.gitHubDetails?.repository}}</span>
</div>
</div>
<div class="form-group f8launcher-project-summary-data-form-group">
<label class="col-xs-5 control-label">Repository</label>
<div class="col-xs-6 f8launcher-project-summary-data-field">
<span>{{summary?.gitHubDetails?.repository}}</span>
</div>
</form>
</div>
</div>
<div class="card-column-30">
<i class="fa fa-github git-provider-icon"></i>
Expand All @@ -401,6 +396,7 @@ <h2 class="card-pf-title">
</div>
</div>
</div>
</form>
<div class="container-fluid">
<div id="ProjectSummary" class="f8launcher-continue">
<button class="btn btn-primary btn-xlarge"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
Input,
OnDestroy,
OnInit,
ViewEncapsulation
ViewEncapsulation,
ViewChild
} from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { DomSanitizer } from '@angular/platform-browser';
Expand All @@ -20,6 +21,7 @@ import { LauncherStep } from '../../launcher-step';
import { DependencyCheck } from '../../model/dependency-check.model';
import { Summary } from '../../model/summary.model';
import { broadcast } from '../../shared/telemetry.decorator';
import { NgForm } from '@angular/forms';

@Component({
encapsulation: ViewEncapsulation.None,
Expand All @@ -28,6 +30,7 @@ import { broadcast } from '../../shared/telemetry.decorator';
styleUrls: ['./project-summary-createapp-step.component.less']
})
export class ProjectSummaryCreateappStepComponent extends LauncherStep implements OnDestroy, OnInit {
@ViewChild('form') form: NgForm;
@Input() id: string;
@Input() depEditorFlag: boolean;

Expand Down Expand Up @@ -67,23 +70,16 @@ export class ProjectSummaryCreateappStepComponent extends LauncherStep implement
* @returns {boolean} True if step is completed
*/
get stepCompleted(): boolean {
let completed = true;
if ((this.launcherComponent.isProjectNameValid !== undefined && this.launcherComponent.isProjectNameValid === false)
|| (this.launcherComponent.isGroupIdValid !== undefined && this.launcherComponent.isGroupIdValid === false)
|| (this.launcherComponent.isArtifactIdValid !== undefined && this.launcherComponent.isArtifactIdValid === false)
|| (this.launcherComponent.isProjectVersionValid !== undefined &&
this.launcherComponent.isProjectVersionValid === false)
|| (this.launcherComponent.isProjectNameAvailable !== undefined &&
this.launcherComponent.isProjectNameAvailable === false )) {
if (this.form.invalid) {
return false;
}
for (let i = 0; i < this.launcherComponent.steps.length - 1; i++) {
let step = this.launcherComponent.steps[i];
if (!(step.optional === true || step.completed === true) && step.hidden !== true) {
completed = false;
return false;
}
}
return completed;
return true;
}

// Steps
Expand Down Expand Up @@ -138,13 +134,6 @@ export class ProjectSummaryCreateappStepComponent extends LauncherStep implement
);
}

/**
* Validate the project name
*/
validateProjectName(): void {
this.launcherComponent.validateProjectName();
}

/**
* Validate the project version
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,15 @@ <h2 class="card-pf-title">
<label class="col-xs-4 control-label">Application Name</label>
<div class="col-xs-8 f8launcher-project-summary-data-field f8launcher-application-text-field">
<input class="f8launcher-project-summary-data-field_input f8launcher-application-text-field_input"
name="applicationTitle" placeholder="New Application" type="text"
[(ngModel)]="dependencyCheck.projectName"
(keyup.enter)="$event.target.blur();"
(keyup)="validateProjectName()">
name="applicationTitle" placeholder="New Application" type="text" #projectName="ngModel"
[(ngModel)]="dependencyCheck.projectName" lowercase validateProjectName
(keyup.enter)="$event.target.blur();">
</div>
<div class="col-xs-8 col-xs-offset-4" [ngClass]="{'has-error': launcherComponent.isProjectNameValid === false}">
<span class="help-block" *ngIf="launcherComponent.isProjectNameValid === false">
<div class="col-xs-8 col-xs-offset-4" *ngIf="projectName.invalid && (projectName.dirty || projectName.touched)">
<span *ngIf="projectName.errors.pattern" class="help-block f8launcher-vertical-bar_application-name-help-text">
Please enter a valid Application Name.
</span>
</div>
<div class="col-xs-8 col-xs-offset-4" [ngClass]="{'has-error': launcherComponent.isProjectNameAvailable === false}">
<span class="help-block" *ngIf="launcherComponent.isProjectNameAvailable === false">
<span *ngIf="projectName.errors.duplicate" class="help-block f8launcher-vertical-bar_application-name-help-text">
Application name is already used. Please enter a new one.
</span>
</div>
Expand Down Expand Up @@ -234,7 +231,7 @@ <h2 class="card-pf-title">
</div>
<div class="card-pf-body card-column">
<div class="card-column-70">
<form class="form-horizontal">
<form class="form-horizontal" #form="ngForm">
<div class="form-group f8launcher-project-summary-data-form-group">
<label class="col-xs-4 control-label">Username</label>
<div class="f8launcher-project-summary-data-field-account">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
Input,
OnDestroy,
OnInit,
ViewEncapsulation
ViewEncapsulation,
ViewChild
} from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { DomSanitizer } from '@angular/platform-browser';
Expand All @@ -19,6 +20,7 @@ import { LauncherStep } from '../../launcher-step';
import { DependencyCheck } from '../../model/dependency-check.model';
import { Summary } from '../../model/summary.model';
import { broadcast } from '../../shared/telemetry.decorator';
import { NgForm } from '@angular/forms';

@Component({
encapsulation: ViewEncapsulation.None,
Expand All @@ -27,6 +29,7 @@ import { broadcast } from '../../shared/telemetry.decorator';
styleUrls: ['./project-summary-importapp-step.component.less']
})
export class ProjectSummaryImportappStepComponent extends LauncherStep implements OnDestroy, OnInit {
@ViewChild('form') form: NgForm;
@Input() id: string;

public setUpErrResponse: Array<any> = [];
Expand Down Expand Up @@ -68,23 +71,16 @@ export class ProjectSummaryImportappStepComponent extends LauncherStep implement
* @returns {boolean} True if step is completed
*/
get stepCompleted(): boolean {
let completed = true;
if ((this.launcherComponent.isProjectNameValid !== undefined && this.launcherComponent.isProjectNameValid === false)
|| (this.launcherComponent.isGroupIdValid !== undefined && this.launcherComponent.isGroupIdValid === false)
|| (this.launcherComponent.isArtifactIdValid !== undefined && this.launcherComponent.isArtifactIdValid === false)
|| (this.launcherComponent.isProjectVersionValid !== undefined &&
this.launcherComponent.isProjectVersionValid === false)
|| (this.launcherComponent.isProjectNameAvailable !== undefined &&
this.launcherComponent.isProjectNameAvailable === false)) {
if (this.form.invalid) {
return false;
}
for (let i = 0; i < this.launcherComponent.steps.length - 1; i++) {
let step = this.launcherComponent.steps[i];
if (!(step.optional === true || step.completed === true) && step.hidden !== true) {
completed = false;
return false;
}
}
return completed;
return true;
}

// Steps
Expand Down Expand Up @@ -137,13 +133,6 @@ export class ProjectSummaryImportappStepComponent extends LauncherStep implement
);
}

/**
* Validate the application name
*/
validateProjectName(): void {
this.launcherComponent.validateProjectName();
}

/**
* Validate the project version
*/
Expand Down
47 changes: 0 additions & 47 deletions src/app/launcher/launcher.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ export class LauncherComponent implements AfterViewInit, OnInit {
public isGroupIdValid: boolean;
public isProjectVersionValid: boolean;
public applicationNames: string[];
public isProjectNameAvailable: boolean;
private _selectedSection: string;
private _showCancelOverlay: boolean = false;
private _steps: LauncherStep[] = [];
private _summary: Summary;
private summaryCompleted: boolean = false;
private _isProjectNameValid: boolean;
private spaceId: string;

constructor(private route: ActivatedRoute,
Expand Down Expand Up @@ -194,24 +192,6 @@ export class LauncherComponent implements AfterViewInit, OnInit {
return this._summary;
}

/**
* Checks if the project name is valid
*
* @returns boolean
*/
get isProjectNameValid(): boolean {
return this._isProjectNameValid;
}

/**
* Set the boolean value for isProjectNameValid
*
* @param {boolean} isValid
*/
set isProjectNameValid(isValid: boolean) {
this._isProjectNameValid = isValid;
}

/**
* Set user summary
*
Expand Down Expand Up @@ -298,33 +278,6 @@ export class LauncherComponent implements AfterViewInit, OnInit {
}, 10);
}

/**
* Validate the project name
*
* @returns void
*/
validateProjectName(): void {
this.isProjectNameValid =
this.dependencyCheckService.validateProjectName(this.summary.dependencyCheck.projectName);
if (this.flow === 'osio') {
if (this.summary.dependencyCheck.projectName) {
this.summary.dependencyCheck.projectName =
this.summary.dependencyCheck.projectName.toLowerCase();
}
this.checkIfProjectNameAvailable();
}
}

/**
* Check if the application name is already used
*
* @returns void
*/
checkIfProjectNameAvailable(): void {
this.isProjectNameAvailable =
this.applicationNames.indexOf(this.summary.dependencyCheck.projectName) === -1 ? true : false;
}

/**
* Validate the project version
*/
Expand Down
5 changes: 3 additions & 2 deletions src/app/launcher/launcher.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { GitproviderCreateappStepComponent }
from './create-app/gitprovider-createapp-step/gitprovider-createapp-step.component';
import { GitProviderRepositoryValidatorDirective }
from './create-app/gitprovider-createapp-step/gitprovider-repository.validator';
import { LowerCaseDirective }
from './create-app/gitprovider-createapp-step/gitprovider-lowercase';
import { LowerCaseDirective } from './shared/lowercase.directive';
import { ProjectNameValidatorDirective } from './shared/project-name.validator'
import { MissionRuntimeCreateappStepComponent }
from './create-app/mission-runtime-createapp-step/mission-runtime-createapp-step.component';
import { ProjectProgressCreateappNextstepComponent }
Expand Down Expand Up @@ -85,6 +85,7 @@ export const providers: Provider[] = [
DependencyEditorCreateappStepComponent,
GitproviderCreateappStepComponent,
LowerCaseDirective,
ProjectNameValidatorDirective,
GitProviderRepositoryValidatorDirective,
GitproviderImportappStepComponent,
MissionRuntimeCreateappStepComponent,
Expand Down
Loading

0 comments on commit 5209268

Please sign in to comment.