Display alert box on wrong file upload 08/82108/1
authorArundathi Patil <arundpil@in.ibm.com>
Wed, 13 Mar 2019 10:35:00 +0000 (16:05 +0530)
committerIBM602-PC0F1E3C\Arundathi <arundpil@in.ibm.com>
Wed, 13 Mar 2019 10:35:06 +0000 (16:05 +0530)
Implemeted code to display error message to user when user uploads
incorrect file

Issue-ID: CCSDK-1135
Change-Id: I66674391858386ec0579314d2bd1858e7cdbd98e
Signed-off-by: Arundathi Patil <arundpil@in.ibm.com>
cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-template.component.html
cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-template.component.ts

index bb00d7f..66e3aeb 100644 (file)
@@ -22,5 +22,5 @@ limitations under the License.
     <input type="file" accept=".zip" (change)="fileChanged($event)">
 </div>
 <div>
-    <button mat-button matStepperNext class="matStepNextBtn" (click)="updateBlueprintState()">Upload</button>
+    <button mat-button matStepperNext class="matStepNextBtn" (click)="updateBlueprintState()" [disabled]="!validfile">Upload</button>
 </div>
\ No newline at end of file
index 1ce33f6..777faee 100644 (file)
@@ -41,6 +41,7 @@ export class SearchTemplateComponent implements OnInit {
   fileText: object[];
   blueprintState: IBlueprintState;
   bpState: Observable<IBlueprintState>;
+  validfile: boolean = false;
 
   @ViewChild('fileInput') fileInput;
   result: string = '';
@@ -60,7 +61,7 @@ export class SearchTemplateComponent implements OnInit {
 
   fileChanged(e: any) {
     this.file = e.target.files[0];
-
+    this.zipFile.files = {};
     this.zipFile.loadAsync(this.file)
       .then((zip) => {
         if(zip) {            
@@ -70,14 +71,6 @@ export class SearchTemplateComponent implements OnInit {
   }
 
   updateBlueprintState() {
-    // let fileReader = new FileReader();
-    // fileReader.readAsText(this.file);
-    // var me = this;
-    // fileReader.onload = function () {
-    //   var data: IBlueprint = JSON.parse(fileReader.result.toString());
-    //   me.store.dispatch(new LoadBlueprintSuccess(data));
-    // }
-
     let data: IBlueprint = this.activationBlueprint ? JSON.parse(this.activationBlueprint.toString()) : this.activationBlueprint;
     let blueprintState = {
       blueprint: data,
@@ -90,6 +83,8 @@ export class SearchTemplateComponent implements OnInit {
   }
 
   async buildFileViewData(zip) {
+    this.validfile = false;
+    this.paths = [];
     for (var file in zip.files) {
       this.fileObject = {
         name: zip.files[file].name,
@@ -99,8 +94,23 @@ export class SearchTemplateComponent implements OnInit {
       this.fileObject.data = value;
       this.paths.push(this.fileObject); 
     }
-    this.fetchTOSACAMetadata();
-   this.tree = this.arrangeTreeData(this.paths);
+
+    if(this.paths) {
+      this.paths.forEach(path =>{
+        if(path.name.includes("TOSCA.meta")) {
+          this.validfile = true
+        }
+      });
+    } else {
+      alert('Please update proper file');
+    }
+
+    if(this.validfile) {      
+      this.fetchTOSACAMetadata();
+      this.tree = this.arrangeTreeData(this.paths);
+    } else {
+      alert('Please update proper file with TOSCA metadata');
+    }
   }
 
   arrangeTreeData(paths) {