comparison app/result-type.ts @ 30:193271b6b9d2

configure attributes per result type. select number of items per result page.
author casties
date Mon, 01 Feb 2016 17:29:04 +0100
parents
children 4926885f8a99
comparison
equal deleted inserted replaced
29:52af480a843e 30:193271b6b9d2
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 getColumns(attributes: string[], allAttributes=false) {
17 let atts = attributes.slice();
18 let cols = [];
19 // allowed attributes
20 this.allowedAttributes.forEach(att => {
21 let idx = atts.indexOf(att);
22 if (idx > -1) {
23 cols.push(new ResultColumn(att, att));
24 atts[idx] = null;
25 }
26 });
27 // then other attributes
28 if (allAttributes) {
29 atts.forEach(att => {
30 if (att != null && this.deniedAttributes.indexOf(att) > -1) {
31 cols.push(new ResultColumn(att, att));
32 }
33 });
34 }
35 return cols;
36 }
37
38 }
39
40 export function getResultType(name: string, resultTypes: {[name:string]: ResultType}): ResultType {
41 let rt = resultTypes[name];
42 if (rt == null) {
43 rt = resultTypes['*'];
44 }
45 return rt;
46 }