Mercurial > hg > ng2-query-ismi
comparison src/app/result-type.ts @ 47:b65a031c4967 ng2-final
first step to angular2-final (2.4) version of the query browser.
author | casties |
---|---|
date | Fri, 17 Mar 2017 20:16:52 +0100 |
parents | app/result-type.ts@7578b21cdf2e |
children |
comparison
equal
deleted
inserted
replaced
46:1f3fed01aef6 | 47:b65a031c4967 |
---|---|
1 import {ResultColumn} from './result-column'; | |
2 | |
3 export class ResultType { | |
4 public name: string; | |
5 public idAttribute: string; | |
6 public allowedAttributes: string[]; | |
7 public deniedAttributes: string[]; | |
8 | |
9 constructor (name: string, idAttribute: string, allowedAttributes: string[]=[], deniedAttributes: string[]=[]) { | |
10 this.name = name; | |
11 this.idAttribute = idAttribute; | |
12 this.allowedAttributes = allowedAttributes; | |
13 this.deniedAttributes = deniedAttributes; | |
14 } | |
15 | |
16 /** | |
17 * Return columns for the given list of attributes. | |
18 */ | |
19 getColumns(attributes: string[], allAttributes=true): ResultColumn[] { | |
20 let atts = attributes.slice(); | |
21 let cols = []; | |
22 // allowed attributes | |
23 this.allowedAttributes.forEach(att => { | |
24 let idx = atts.indexOf(att); | |
25 if (idx > -1) { | |
26 cols.push(new ResultColumn(att, att, '', true)); | |
27 atts[idx] = null; | |
28 } | |
29 }); | |
30 // then other attributes | |
31 if (allAttributes) { | |
32 atts.forEach(att => { | |
33 if (att != null && att[0] != '_' && this.deniedAttributes.indexOf(att) < 0) { | |
34 cols.push(new ResultColumn(att, att, '', false)); | |
35 } | |
36 }); | |
37 } | |
38 return cols; | |
39 } | |
40 | |
41 } | |
42 | |
43 export function getResultType(name: string, resultTypes: {[name:string]: ResultType}): ResultType { | |
44 let rt = resultTypes[name]; | |
45 if (rt == null) { | |
46 rt = resultTypes['*']; | |
47 } | |
48 return rt; | |
49 } |