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/20 14:13:26 UTC

[incubator-dlab] 02/03: [DLAB-747]: patch project creation form with file; validation added

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 3e6be349efb8ae67787e1a0cf9ffdefe65f7c0ef
Author: Andriana Kovalyshyn <An...@epam.com>
AuthorDate: Thu Jun 20 15:23:32 2019 +0300

    [DLAB-747]: patch project creation form with file; validation added
---
 .../project/project-form/project-form.component.ts | 36 ++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

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 5a1e2ea..a332f9e 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,7 +17,7 @@
  * under the License.
  */
 
-import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
+import { Component, OnInit, Input, Output, EventEmitter, ViewChild, ChangeDetectorRef } from '@angular/core';
 import { FormGroup, FormBuilder, Validators } from '@angular/forms';
 import { ToastrService } from 'ngx-toastr';
 import { Subscription } from 'rxjs';
@@ -38,6 +38,8 @@ export class ProjectFormComponent implements OnInit {
   public groupsList: any = [];
   public endpointsList: any = [];
   public projectList: Project[] = [];
+  public accessKeyValid: boolean;
+  public keyLabel: string = '';
 
   @Input() item: any;
   @Output() update: EventEmitter<{}> = new EventEmitter();
@@ -51,7 +53,8 @@ export class ProjectFormComponent implements OnInit {
     private projectService: ProjectService,
     private projectDataService: ProjectDataService,
     private rolesService: RolesGroupsService,
-    private endpointService: EndpointService
+    private endpointService: EndpointService,
+    private cd: ChangeDetectorRef
   ) { }
 
   ngOnInit() {
@@ -94,6 +97,25 @@ export class ProjectFormComponent implements OnInit {
     this.projectForm.controls.tag.setValue(user_tag.toLowerCase());
   }
 
+  public onFileChange($event) {
+    const reader = new FileReader();
+
+    if($event.target.files && $event.target.files.length) {
+      const [file] = $event.target.files;
+      reader.readAsDataURL(file);
+
+      reader.onload = () => {
+        this.projectForm.patchValue({
+          key: reader.result
+        });
+
+        this.accessKeyValid = this.isValidKey(file.name);
+        this.keyLabel = this.getLabel(file);
+        this.cd.markForCheck();
+      };
+    }
+  }
+
   public selectOptions(list, key, select?) {
     let filter = key === 'endpoints' ? list.map(el => el.name) : list;
     this.projectForm.controls[key].setValue(select ? filter : []);
@@ -111,6 +133,7 @@ export class ProjectFormComponent implements OnInit {
   public editSpecificProject(item: Project) {
 
     this.projectForm = this._fb.group({
+      'key': [''],
       'name': [item.name, Validators.required],
       'endpoints': [item.endpoints],
       'tag': [item.tag, Validators.required],
@@ -118,6 +141,15 @@ export class ProjectFormComponent implements OnInit {
     });
   }
 
+  private getLabel(file: File): string {
+    debugger;
+    return file ? !this.accessKeyValid ? 'Public key is required.' : file.name : '';
+  }
+
+  private isValidKey(value): boolean {
+    return value.toLowerCase().endsWith('.pub');
+  }
+
   private getGroupsData() {
     this.rolesService.getGroupsData().subscribe(
       (list: any) => this.groupsList = list.map(el => el.group),


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