Project

General

Profile

1
// import { Pipe, PipeTransform} from '@angular/core';
2
// import { Filter, Value} from '../../searchPages/searchUtils/searchHelperClasses.class';
3
// import { SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
4
// import { ErrorCodes} from '../properties/openaireProperties';
5
//
6
// @Pipe({
7
//   name: 'contentProvidersDatatable'
8
// })
9
// export class ContentProvidersDatatablePipe implements PipeTransform  {
10
//
11
//   transform(array: any[], args: any[]): any {
12
//     if(array.length > 0) {
13
//       let searchUtils: SearchUtilsClass = args[0];
14
//       let filters:Filter[] = args[1];
15
//
16
//
17
//       var errorCodes:ErrorCodes = new ErrorCodes();
18
//       searchUtils.status = errorCodes.LOADING;
19
//
20
//       var result = array.filter(row=>this.filterAll(row, searchUtils.keyword.toLowerCase(), filters));
21
//
22
//       let oldTotal = searchUtils.totalResults;
23
//
24
//       searchUtils.totalResults = result.length;
25
//
26
//       var errorCodes:ErrorCodes = new ErrorCodes();
27
//       searchUtils.status = errorCodes.DONE;
28
//       if(searchUtils.totalResults == 0 ){
29
//         searchUtils.status = errorCodes.NONE;
30
//       }
31
//
32
//       if(oldTotal != searchUtils.totalResults) {
33
//         args[3].detectChanges();
34
//       }
35
//       return result;
36
//     }
37
//     return [];
38
//   }
39
//
40
//   filterAll(row: any, query: string, filters:Filter[]) {
41
//     let returnValue: boolean = false;
42
//
43
//     if(query) {
44
//       if(row.title.name.toLowerCase().indexOf(query) > -1) {
45
//         returnValue = true;
46
//       }
47
//
48
//       if(row.type.toLowerCase().indexOf(query) > -1) {
49
//         returnValue = true;
50
//       }
51
//
52
//       if(row.countries && row.countries.length > 0) {
53
//         for(let country of row.countries) {
54
//           if(country.toLowerCase().indexOf(query) > -1) {
55
//             returnValue = true;
56
//             break;
57
//           }
58
//         }
59
//       }
60
//
61
//       if(row.compatibility && row.compatibility.toLowerCase().indexOf(query) > -1) {
62
//         returnValue = true;
63
//       }
64
//
65
//       if(row.organizations && row.organizations.length > 0) {
66
//         for(let organization of row.organizations) {
67
//           if(organization.name.toLowerCase().indexOf(query) > -1) {
68
//             returnValue = true;
69
//             break;
70
//           }
71
//         }
72
//       }
73
//
74
//       if(!returnValue) {
75
//         return false;
76
//       }
77
//     }
78
//
79
//     for (let filter of filters){
80
//       if(filter.countSelectedValues > 0){
81
//         for (let value of filter.values){
82
//           if(value.selected == true){
83
//
84
//             // make it generic in future commit
85
//             let field:string = "";
86
//             if(filter.title == "Type") {
87
//               field = "type";
88
//             } else if(filter.title == "Compatibility Level") {
89
//               field = "compatibility";
90
//             }
91
//
92
//             if(row[field] == value.name) {
93
//               returnValue = true;
94
//               if(filter.filterOperator == "or") {
95
//                 break;
96
//               }
97
//             } else {
98
//                 if(filter.filterOperator == "and") {
99
//                   return false;
100
//                 }
101
//                 returnValue = false;
102
//             }
103
//           }
104
//         }
105
//         if(!returnValue) {
106
//           return false;
107
//         }
108
//       }
109
//     }
110
//
111
//     return true;
112
//   }
113
// }
(2-2/4)