CCSDK-1308- Files sorting 24/88524/1
authorArundathi Patil <arundpil@in.ibm.com>
Mon, 27 May 2019 09:44:14 +0000 (15:14 +0530)
committerArundathi Patil <arundpil@in.ibm.com>
Mon, 27 May 2019 09:44:37 +0000 (15:14 +0530)
Files are now sorted in ascending order

Issue-ID: CCSDK-1308
Change-Id: I4143a132a946815363f1c80b6ab37b6590ee242c
Signed-off-by: Arundathi Patil <arundpil@in.ibm.com>
cds-ui/client/src/app/common/shared/pipes/sort.pipe.ts [new file with mode: 0644]
cds-ui/client/src/app/common/shared/shared.module.ts
cds-ui/client/src/app/feature-modules/blueprint/modify-template/editor/editor.component.ts
cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-template.component.ts

diff --git a/cds-ui/client/src/app/common/shared/pipes/sort.pipe.ts b/cds-ui/client/src/app/common/shared/pipes/sort.pipe.ts
new file mode 100644 (file)
index 0000000..f878a22
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2019 IBM Intellectual propertyNameerty. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+import { Pipe, PipeTransform } from '@angular/core';  
+  
+@Pipe({  
+  name: 'sort',  
+  pure:false,  
+})  
+export class SortPipe implements PipeTransform {  
+  
+  transform(arrayData: any[], direcion: string, propertyName?: string): any {  
+    if (!arrayData) {  
+      return [];  
+    }  
+    if (!direcion || !propertyName) {  
+      return arrayData  
+    }  
+    if (arrayData.length > 0) {  
+      const _direction = direcion === 'asc' ? -1 : 1,  
+        isArray = Array.isArray(arrayData),  
+        arrayDataType = typeof arrayData[0],  
+        flag = isArray && arrayDataType === 'object' ? true : isArray && arrayDataType !== 'object' ? false : true;  
+      arrayData.sort((a, b) => {  
+        a = flag ? a[propertyName] : a;  
+        b = flag ? b[propertyName] : b;  
+        if (typeof a === 'string') {  
+          return a.toLowerCase() > b.toLowerCase() ? -1 * _direction : 1 * _direction;  
+        } else if (typeof a === 'number') {  
+          return a - b > 0 ? -1 * _direction : 1 * _direction;  
+        }  
+      });  
+    }  
+    return arrayData;  
+  }
+}  
\ No newline at end of file
index 6ca5b13..b036f59 100644 (file)
@@ -29,20 +29,22 @@ import { RouterModule } from "@angular/router";
 import { SearchPipe } from './pipes/search.pipe';
 import { SearchDialog } from './components/search-dialog/search-dialog.component';
 import { AppMaterialModule }  from '../modules/app-material.module';
+import { SortPipe } from './pipes/sort.pipe';
 
 @NgModule({
   declarations: [
     HomeComponent,
     CBAWizardComponent,
     SearchPipe,
-    SearchDialog
-
+    SearchDialog,
+    SortPipe
   ],
   exports: [
     HomeComponent,
     CBAWizardComponent,
     SearchPipe,
-    SearchDialog
+    SearchDialog,
+    SortPipe
   ],
   imports: [
     AppMaterialModule,
index 09fa003..b982fa2 100644 (file)
@@ -38,6 +38,7 @@ import { LoadBlueprintSuccess, SetBlueprintState } from '../../../../common/core
 import { ApiService } from 'src/app/common/core/services/api.service';
 import { IMetaData } from 'src/app/common/core/store/models/metadata.model';
 import { EditorService } from './editor.service';
+import { SortPipe } from '../../../../common/shared/pipes/sort.pipe';
 
 interface Node {
   name: string;
@@ -390,6 +391,7 @@ export class EditorComponent implements OnInit {
         newFileNode.data = '';
         this.filesData.push(newFileNode);
       }
+      this.filesData = new SortPipe().transform(this.filesData, 'asc', 'name');
       this.arrangeTreeData(this.filesData);
     }
   }
@@ -431,7 +433,9 @@ export class EditorComponent implements OnInit {
 
     if (this.validfile) {
       this.fetchTOSACAMetadata();
+      this.paths = new SortPipe().transform(this.paths, 'asc', 'name');
       this.filesData = this.paths;
+      this.paths = new SortPipe().transform(this.paths, 'asc', 'name');
       this.tree = this.arrangeTreeData(this.paths);
     } else {
       alert('Please update proper file with TOSCA metadata');
@@ -505,6 +509,7 @@ export class EditorComponent implements OnInit {
         i = i - 1;
       }
     }
+    this.filesData = new SortPipe().transform(this.filesData, 'asc', 'name');
     this.arrangeTreeData(this.filesData);
   }
 
index c232414..92003c9 100644 (file)
@@ -29,6 +29,7 @@ import { IBlueprintState } from '../../../../common/core/store/models/blueprintS
 import { IAppState } from '../../../../common/core/store/state/app.state';
 import { LoadBlueprintSuccess, SET_BLUEPRINT_STATE, SetBlueprintState } from '../../../../common/core/store/actions/blueprint.action';
 import { json } from 'd3';
+import { SortPipe } from '../../../../common/shared/pipes/sort.pipe';
 
 @Component({
   selector: 'app-search-template',
@@ -116,6 +117,7 @@ export class SearchTemplateComponent implements OnInit {
 
     if(this.validfile) {      
       this.fetchTOSACAMetadata();
+      this.paths = new SortPipe().transform(this.paths, 'asc', 'name');
       this.tree = this.arrangeTreeData(this.paths);
     } else {
       alert('Please update proper file with TOSCA metadata');