diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/app/result-type.ts	Fri Mar 17 20:16:52 2017 +0100
@@ -0,0 +1,49 @@
+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;
+    }
+    
+    /**
+     * Return columns for the given list of attributes.
+     */
+    getColumns(attributes: string[], allAttributes=true): ResultColumn[] {
+        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, '', true));
+                atts[idx] = null;
+            }
+        });
+        // then other attributes
+        if (allAttributes) {
+            atts.forEach(att => {
+                if (att != null && att[0] != '_' && this.deniedAttributes.indexOf(att) < 0) {
+                    cols.push(new ResultColumn(att, att, '', false));
+                }
+            });           
+        }        
+        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