You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by an...@apache.org on 2019/06/04 14:26:52 UTC

[incubator-dlab] 01/02: [DLAB-738]: added project duplication validation

This is an automated email from the ASF dual-hosted git repository.

ankovalyshyn pushed a commit to branch feature/projects
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git

commit 51168a5c8ffb3fa11146e815d602013774c5b989
Author: Andriana Kovalyshyn <An...@epam.com>
AuthorDate: Tue Jun 4 16:33:40 2019 +0300

    [DLAB-738]: added project duplication validation
---
 .../project-form/project-form.component.html       |  1 +
 .../project-form/project-form.component.scss       | 11 +++++--
 .../project/project-form/project-form.component.ts | 37 ++++++++++++++++------
 .../webapp/src/app/core/util/checkUtils.ts         |  6 ++++
 .../resources/webapp/src/app/core/util/patterns.ts |  1 +
 5 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.html b/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.html
index 85ea1c5..b3880fe 100644
--- a/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.html
+++ b/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.html
@@ -30,6 +30,7 @@
               <div class="control">
                 <input type="text" formControlName="name" placeholder="Enter project name"
                   (blur)="generateProjectTag($event)" [ngClass]="{ 'not-allowed' : item }">
+                <span class="error" *ngIf="projectForm?.controls.name.hasError('duplication')">This project name already exists.</span>
               </div>
             </div>
             <div class="control-group">
diff --git a/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.scss b/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.scss
index 981fd5d..5a7d3e3 100644
--- a/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.scss
+++ b/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.scss
@@ -19,9 +19,6 @@
 
 .form-block {
   width: 600px;
-  .next {
-    // margin-left: 25px;
-  }
   &.split {
     flex-direction: column;
     display: flex;
@@ -35,4 +32,12 @@
       }
     }
   }
+
+  .error {
+    font-family: 'Open Sans', sans-serif;
+    position: absolute;
+    right: 0;
+    bottom: 2px;
+    font-weight: 300;
+  }
 }
diff --git a/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.ts b/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.ts
index 4c0e92f..5a1e2ea 100644
--- a/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.ts
+++ b/services/self-service/src/main/resources/webapp/src/app/administration/project/project-form/project-form.component.ts
@@ -17,13 +17,15 @@
  * under the License.
  */
 
- import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
- import { FormGroup, FormBuilder, Validators } from '@angular/forms';
- import { ToastrService } from 'ngx-toastr';
+import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
+import { FormGroup, FormBuilder, Validators } from '@angular/forms';
+import { ToastrService } from 'ngx-toastr';
+import { Subscription } from 'rxjs';
 
- import { ProjectService,RolesGroupsService, EndpointService } from '../../../core/services';
- import { ProjectDataService } from '../project-data.service';
- import { Project } from '../project.component';
+import { ProjectService, RolesGroupsService, EndpointService } from '../../../core/services';
+import { ProjectDataService } from '../project-data.service';
+import { CheckUtils, PATTERNS } from '../../../core/util';
+import { Project } from '../project.component';
 
 @Component({
   selector: 'project-form',
@@ -31,16 +33,18 @@
   styleUrls: ['./project-form.component.scss']
 })
 export class ProjectFormComponent implements OnInit {
-  namePattern = '[-_a-zA-Z0-9]+';
 
   public projectForm: FormGroup;
   public groupsList: any = [];
   public endpointsList: any = [];
+  public projectList: Project[] = [];
 
   @Input() item: any;
   @Output() update: EventEmitter<{}> = new EventEmitter();
   @ViewChild('stepper') stepper;
 
+  private subscriptions: Subscription = new Subscription();
+
   constructor(
     public toastr: ToastrService,
     private _fb: FormBuilder,
@@ -55,6 +59,10 @@ export class ProjectFormComponent implements OnInit {
     this.getGroupsData();
     this.getEndpointsData();
 
+    this.subscriptions.add(this.projectDataService._projects.subscribe(
+      (value: Project[]) => {
+        if (value) this.projectList = value;
+      }));
     if (this.item) {
       this.editSpecificProject(this.item);
       this.stepper.selectedIndex = 1;
@@ -82,7 +90,7 @@ export class ProjectFormComponent implements OnInit {
   }
 
   public generateProjectTag($event) {
-    let user_tag = `dlab-${ $event.target.value }`;
+    let user_tag = `dlab-${$event.target.value}`;
     this.projectForm.controls.tag.setValue(user_tag.toLowerCase());
   }
 
@@ -93,9 +101,9 @@ export class ProjectFormComponent implements OnInit {
 
   private initFormModel(): void {
     this.projectForm = this._fb.group({
-      'name': ['', Validators.compose([Validators.required, Validators.pattern(this.namePattern)])],
+      'name': ['', Validators.compose([Validators.required, Validators.pattern(PATTERNS.namePattern), this.checkDuplication.bind(this)])],
       'endpoints': [[], Validators.required],
-      'tag': ['',Validators.compose([Validators.required, Validators.pattern(this.namePattern)])],
+      'tag': ['', Validators.compose([Validators.required, Validators.pattern(PATTERNS.namePattern)])],
       'groups': [[], Validators.required]
     });
   }
@@ -121,4 +129,13 @@ export class ProjectFormComponent implements OnInit {
       list => this.endpointsList = list,
       error => this.toastr.error(error.message, 'Oops!'));
   }
+
+  private checkDuplication(control) {
+    if (control.value) {
+      for (let index = 0; index < this.projectList.length; index++) {
+        if (CheckUtils.delimitersFiltering(control.value) === CheckUtils.delimitersFiltering(this.projectList[index].name))
+          return { duplication: true };
+      }
+    }
+  }
 }
diff --git a/services/self-service/src/main/resources/webapp/src/app/core/util/checkUtils.ts b/services/self-service/src/main/resources/webapp/src/app/core/util/checkUtils.ts
index 36f8a63..bad6764 100644
--- a/services/self-service/src/main/resources/webapp/src/app/core/util/checkUtils.ts
+++ b/services/self-service/src/main/resources/webapp/src/app/core/util/checkUtils.ts
@@ -17,6 +17,8 @@
  * under the License.
  */
 
+import { PATTERNS } from './patterns';
+
 export class CheckUtils {
   public static isJSON(str) {
     try {
@@ -35,4 +37,8 @@ export class CheckUtils {
     }
     return true;
   }
+
+  public static delimitersFiltering(resource): string {
+    return resource.replace(PATTERNS.delimitersRegex, '').toString().toLowerCase();
+  }
 }
diff --git a/services/self-service/src/main/resources/webapp/src/app/core/util/patterns.ts b/services/self-service/src/main/resources/webapp/src/app/core/util/patterns.ts
index 071bb84..c68d764 100644
--- a/services/self-service/src/main/resources/webapp/src/app/core/util/patterns.ts
+++ b/services/self-service/src/main/resources/webapp/src/app/core/util/patterns.ts
@@ -19,4 +19,5 @@
 
 export const PATTERNS = {
   namePattern: '[-_a-zA-Z0-9]*[_-]*[a-zA-Z0-9]+',
+  delimitersRegex: '/[-_]?/g'
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org