adding implementation for imports tab 81/100581/1
authorshaaban Altanany <shaaban.eltanany.ext@orange.com>
Wed, 22 Jan 2020 08:06:57 +0000 (10:06 +0200)
committershaaban Altanany <shaaban.eltanany.ext@orange.com>
Wed, 22 Jan 2020 08:06:57 +0000 (10:06 +0200)
Issue-ID: CCSDK-2014
Signed-off-by: shaaban Altanany <shaaban.eltanany.ext@orange.com>
Change-Id: Ib11325f0c7d01103eff05f237c3c0d7fb515d59c

cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.html
cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/imports-tab/imports-tab.component.ts

index affba1b..baf1b88 100644 (file)
@@ -1,4 +1,3 @@
-
 <div class="import-container-all">
     <div class="import-container">
         <div class="import-container-input">
                 <label class="label-name">File</label>
             </div>
         </div>
-        <div id="accordion">
+        <div id="accordion" *ngFor="let file of definitionFiles | keyvalue">
             <div class="card">
-                <div class="card-header" id="headingOne">
+                <div class="card-header" [id]="file.key">
                     <h5 class="mb-0 d-flex justify-content-between">
-                        <button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
-                            <i class="icon-file-code"></i>  Definitions/data_types.json
+                        <button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne"
+                                aria-expanded="true" aria-controls="collapseOne">
+                            <i class="icon-file-code"></i> Definitions/{{file.key}}
                         </button>
                         <a class="accordion-delete" href="#"><i class="icon-delete"></i></a>
                     </h5>
                 </div>
 
-                <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
-                    <div class="card-body">
-                        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
-                    </div>
-                </div>
-            </div>
-            <div class="card">
-                <div class="card-header" id="headingTwo">
-                    <h5 class="mb-0">
-                        <button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
-                            <i class="icon-file-code"></i>  Definitions/relationship_types.json
-                        </button>
-                    </h5>
-                </div>
-                <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
-                    <div class="card-body">
-                        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
-                    </div>
-                </div>
-            </div>
-            <div class="card">
-                <div class="card-header" id="headingThree">
-                    <h5 class="mb-0">
-                        <button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
-                            <i class="icon-file-code"></i>  Definitions/artifact_types.json
-                        </button>
-                    </h5>
-                </div>
-                <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordion">
+                <div [id]="file.key" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
                     <div class="card-body">
-                        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
+                        {{file.value | json}}
                     </div>
                 </div>
             </div>
-        </div>
+            <!--   <div class="card">
+                   <div class="card-header" id="headingTwo">
+                       <h5 class="mb-0">
+                           <button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo"
+                                   aria-expanded="false" aria-controls="collapseTwo">
+                               <i class="icon-file-code"></i> Definitions/relationship_types.json
+                           </button>
+                       </h5>
+                   </div>
+                   <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
+                       <div class="card-body">
+                           Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.
+                           3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt
+                           laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin
+                           coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes
+                           anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings
+                           occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard
+                           of them accusamus labore sustainable VHS.
+                       </div>
+                   </div>
+               </div>
+               <div class="card">
+                   <div class="card-header" id="headingThree">
+                       <h5 class="mb-0">
+                           <button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree"
+                                   aria-expanded="false" aria-controls="collapseThree">
+                               <i class="icon-file-code"></i> Definitions/artifact_types.json
+                           </button>
+                       </h5>
+                   </div>
+                   <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordion">
+                       <div class="card-body">
+                           Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.
+                           3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt
+                           laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin
+                           coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes
+                           anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings
+                           occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard
+                           of them accusamus labore sustainable VHS.
+                       </div>
+                   </div>
+               </div>
+           --></div>
     </div>
 
 </div>
 
-<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
+<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
+     aria-hidden="true">
     <div class="modal-dialog" role="document">
         <div class="modal-content">
             <div class="modal-header">
                             Drag & Drop file
                         </div>
                         <div class="folder-upload-text">or
-                            <button type="button" class="btn btn-sm btn-primary" (click)="openFileSelector()">Browse Files</button>
+                            <button type="button" class="btn btn-sm btn-primary" (click)="openFileSelector()">Browse
+                                Files
+                            </button>
                         </div>
                         <div class="folder-upload-type">Allowed file type: json</div>
                     </ng-template>
                 </ngx-file-drop>
-                <div class="upload-table"  *ngFor="let item of files; let i=index">
+                <div class="upload-table" *ngFor="let item of uploadedFiles; let i=index">
                     <table class="table">
                         <thead>
                         <tr>
-                            <th>Name : {{ item.relativePath }}</th>
+                            <th>Name : {{ item.name }}</th>
                         </tr>
                         </thead>
                     </table>
                 </div>
             </div>
             <div class="modal-footer">
-                <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Cancel</button>
-                <button type="button" class="btn btn-sm btn-primary">Import</button>
+                <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal"
+                        (click)="resetTheUploadedFiles()">Cancel
+                </button>
+                <button type="button" class="btn btn-sm btn-primary" data-dismiss="modal" (click)="setFilesToStore()">
+                    Import
+                </button>
             </div>
         </div>
     </div>
index 9b65885..6cd5201 100644 (file)
@@ -1,8 +1,7 @@
 import {Component, OnInit} from '@angular/core';
 import {NgxFileDropEntry, FileSystemFileEntry, FileSystemDirectoryEntry} from 'ngx-file-drop';
 import {PackageCreationStore} from '../package-creation.store';
-import {Observable} from 'rxjs';
-import {HttpClient} from '@angular/common/http';
+import {PackageCreationUtils} from '../package-creation.utils';
 
 
 @Component({
@@ -12,13 +11,19 @@ import {HttpClient} from '@angular/common/http';
 })
 export class ImportsTabComponent {
 
-    fileContent: string | ArrayBuffer = '';
-
-    constructor(private packageCreationStore: PackageCreationStore, private http: HttpClient) {
-    }
+    public definitionFiles: Map<string, string> = new Map<string, string>();
+    public uploadedFiles: FileSystemFileEntry[] = [];
 
     public files: NgxFileDropEntry[] = [];
 
+    constructor(private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils) {
+        this.packageCreationStore.state$.subscribe(cbaPackage => {
+            if (cbaPackage.definitions && cbaPackage.definitions.files && cbaPackage.definitions.files.size > 0) {
+                this.definitionFiles = cbaPackage.definitions.files;
+            }
+        });
+    }
+
     public dropped(files: NgxFileDropEntry[]) {
         this.files = files;
         for (const droppedFile of files) {
@@ -26,30 +31,29 @@ export class ImportsTabComponent {
             // Is it a file?
             if (droppedFile.fileEntry.isFile) {
                 const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
+                this.uploadedFiles.push(fileEntry);
 
-                fileEntry.file((file: File) => {
-                    console.log(droppedFile.relativePath, file);
-
-                    const formData = new FormData();
-                    formData.append('logo', file, droppedFile.relativePath);
-                    console.log(formData);
-
-                    this.packageCreationStore.addDefinition(droppedFile.relativePath, this.getContent(droppedFile.relativePath));
 
-                });
-            } else {
-                // It was a directory (empty directories are added, otherwise only files)
-                const fileEntry = droppedFile.fileEntry as FileSystemDirectoryEntry;
-                console.log(droppedFile.relativePath, fileEntry);
-
-
-               /* const formData = new FormData();
-                formData.append('logo', droppedFile, droppedFile.relativePath);
+            } /*else {
+                const directorEntry = droppedFile.fileEntry as FileSystemDirectoryEntry;
+                this.filesUnderDirectory = directorEntry.getFile('');
+               // const fileEntry = droppedFile.fileEntry as FileSystemDirectoryEntry;
+               /* this.uploadedFile.push(droppedFile);
+                const formData = new FormData()
+                formData.append('logo', fileEntry, droppedFile.relativePath);
                 console.log(formData);*/
+            /* // It was a directory (empty directories are added, otherwise only files)
+             const fileEntry = droppedFile.fileEntry as FileSystemDirectoryEntry;
+             console.log(droppedFile.relativePath, fileEntry);
 
-                this.packageCreationStore.addDefinition(droppedFile.relativePath, this.getContent(droppedFile.relativePath));
 
-            }
+              const formData = new FormData();
+              formData.append('logo', droppedFile, droppedFile.relativePath);
+              console.log(formData);
+
+             //this.packageCreationStore.addDefinition(droppedFile.relativePath, this.getContent(droppedFile.relativePath));
+*/
+            /* }*/
         }
     }
 
@@ -62,15 +66,31 @@ export class ImportsTabComponent {
     }
 
 
-    getContent(filePath: string) {
-        let content = '';
-        this.getJSON(filePath).subscribe(data => {
-            content = data;
-        });
-        return content;
+    /* readFileContent(file: File): string | ArrayBuffer {
+         const fileReader = new FileReader();
+        // let content: string | ArrayBuffer = '';
+         fileReader.onload = (e) => {
+             content = fileReader.result;
+         };
+         fileReader.readAsText(file);
+         return content;
+     }
+ */
+    setFilesToStore() {
+        for (const droppedFile of this.uploadedFiles) {
+            droppedFile.file((file: File) => {
+                const fileReader = new FileReader();
+                fileReader.onload = (e) => {
+                    this.packageCreationStore.addDefinition(droppedFile.name,
+                        this.packageCreationUtils.transformToJson(fileReader.result));
+                };
+                fileReader.readAsText(file);
+            });
+
+        }
     }
 
-    public getJSON(filePath: string): Observable<any> {
-        return this.http.get(filePath);
+    resetTheUploadedFiles() {
+        this.uploadedFiles = [];
     }
 }