diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/result-type.ts	Mon Feb 01 17:29:04 2016 +0100
@@ -0,0 +1,46 @@
+import {ResultColumn} from './result-column';
+
+export class ResultType {
+    public name: string;
+    public idAttribute: string;
+    public allowedAttributes: string[];
+    public deniedAttributes: string[];
+    
+    constructor (name: string, idAttribute: string, allowedAttributes: string[]=[], deniedAttributes: string[]=[]) {
+        this.name = name;
+        this.idAttribute = idAttribute;
+        this.allowedAttributes = allowedAttributes;
+        this.deniedAttributes = deniedAttributes;
+    }
+    
+    getColumns(attributes: string[], allAttributes=false) {
+        let atts = attributes.slice();
+        let cols = [];
+        // allowed attributes
+        this.allowedAttributes.forEach(att =>  {
+            let idx = atts.indexOf(att);
+            if (idx > -1) {
+                cols.push(new ResultColumn(att, att));
+                atts[idx] = null;
+            }
+        });
+        // then other attributes
+        if (allAttributes) {
+            atts.forEach(att => {
+                if (att != null && this.deniedAttributes.indexOf(att) > -1) {
+                    cols.push(new ResultColumn(att, att));
+                }
+            });           
+        }        
+        return cols;
+    }
+    
+}
+
+export function getResultType(name: string, resultTypes: {[name:string]: ResultType}): ResultType {
+    let rt = resultTypes[name];
+    if (rt == null) {
+        rt = resultTypes['*'];
+    }
+    return rt;
+}
\ No newline at end of file