changeset 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 52af480a843e
children 4926885f8a99
files app/ismi-result-types.ts app/query-result-table.component.ts app/query.service.ts app/result-type.ts config.js package.json
diffstat 6 files changed, 111 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/ismi-result-types.ts	Mon Feb 01 17:29:04 2016 +0100
@@ -0,0 +1,11 @@
+import {ResultType} from './result-type';
+
+
+export var ISMI_RESULT_TYPES: {[name:string]: ResultType} = {
+    '*': new ResultType('*', 'ismi_id', [
+            'ismi_id', 'label'
+        ]),
+    'PERSON': new ResultType('PERSON', 'ismi_id', [
+        'ismi_id', 'name_translit', 'name', 'birth_date', 'death_date', 'link'
+    ])
+}
--- a/app/query-result-table.component.ts	Wed Jan 27 16:25:00 2016 +0100
+++ b/app/query-result-table.component.ts	Mon Feb 01 17:29:04 2016 +0100
@@ -16,6 +16,14 @@
         <div *ngIf="showTable"><button (click)="showTable=false">hide results</button></div>
         <div *ngIf="!showTable"><button (click)="showTable=true">show results</button></div>
         <div *ngIf="showTable">
+            <div>Show 
+                <select (change)="onSelectNumItems($event)">
+                    <option value="10">10</option>
+                    <option value="100">100</option>
+                    <option value="0">all</option>
+                </select>
+                results per page.
+            </div>
             <div *ngIf="config.paging">Page {{page}} of {{numPages}}</div>
             <pagination *ngIf="config.paging"
                         class="pagination-sm"
@@ -76,6 +84,17 @@
         console.debug("result table init!");
     }
     
+    onSelectNumItems(event: any) {
+        let selected = event.target.value;
+        console.debug("selected number of items:", selected);
+        let num = parseInt(selected);
+        if (num == 0) {
+            this.itemsPerPage = this.length;
+        } else {
+            this.itemsPerPage = num;
+        }
+    }
+    
     changePage(page:any, data:Array<any> = this.data):Array<any> {
         let start = (page.page - 1) * page.itemsPerPage;
         let end = page.itemsPerPage > -1 ? (start + page.itemsPerPage) : data.length;
--- a/app/query.service.ts	Wed Jan 27 16:25:00 2016 +0100
+++ b/app/query.service.ts	Mon Feb 01 17:29:04 2016 +0100
@@ -7,7 +7,8 @@
 import {QueryMode, QUERY_MODES} from './query-mode';
 import {QueryState} from './query-state';
 import {QueryStep} from './query-step';
-import {ResultColumn} from './result-column';
+import {getResultType} from './result-type';
+import {ISMI_RESULT_TYPES} from './ismi-result-types';
 
 @Injectable()
 export class QueryService {
@@ -239,9 +240,14 @@
                  */
                 if (this.state.attributesCypherQuery) {
                     resIdx += 1;
-                    var atts = data.results[resIdx].data.map(elem => elem.row[0]);
-                    this.state.resultAttributes = atts;                   
-                    this.state.resultColumns = this.getColumns(atts);
+                    let atts = data.results[resIdx].data.map(elem => elem.row[0]);
+                    this.state.resultAttributes = atts;
+                    // the following assumes only one type in the result
+                    for (let t in resTypes) {
+                        this.state.resultType = getResultType(t, ISMI_RESULT_TYPES);
+                        break;
+                    }
+                    this.state.resultColumns = this.state.resultType.getColumns(atts);
                 }
                 /*
                  * results for relations list
@@ -276,26 +282,6 @@
     }
     
     /**
-     * Return nice column objects  
-     */
-    getColumns(attributes: string[]) {
-        var cols = [];
-        if (attributes.indexOf('ismi_id') > -1) {
-            cols.push(new ResultColumn('ismi_id', 'ISMI ID'));
-        }
-        if (attributes.indexOf('label') > -1) {
-            cols.push(new ResultColumn('label', 'Label', 'asc'));
-        }
-        attributes.forEach((att) => {
-            if (att != 'ismi_id' && att != 'label' && att != 'type' && att[0] != '_') {
-                cols.push(new ResultColumn(att, att));
-            }
-        });
-           
-        return cols;
-    }
-    
-    /**
      * Run the given queries on the Neo4J server.
      * 
      * Returns an Observable with the results. 
--- /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
--- a/config.js	Wed Jan 27 16:25:00 2016 +0100
+++ b/config.js	Mon Feb 01 17:29:04 2016 +0100
@@ -23,12 +23,12 @@
     "angular2": "npm:angular2@2.0.0-beta.1",
     "ng2-bootstrap": "npm:ng2-bootstrap@1.0.1-beta.2",
     "ng2-table": "npm:ng2-table@1.0.0-beta.0",
-    "plugin-typescript": "github:frankwallis/plugin-typescript@2.5.2",
-    "reflect-metadata": "npm:reflect-metadata@0.1.3",
+    "plugin-typescript": "github:frankwallis/plugin-typescript@2.5.8",
+    "reflect-metadata": "npm:reflect-metadata@0.1.2",
     "rxjs": "npm:rxjs@5.0.0-beta.0",
-    "typescript": "npm:typescript@1.7.5",
+    "typescript": "npm:typescript@1.8.0",
     "zone.js": "npm:zone.js@0.5.10",
-    "github:frankwallis/plugin-typescript@2.5.2": {
+    "github:frankwallis/plugin-typescript@2.5.8": {
       "typescript": "npm:typescript@1.7.5"
     },
     "github:jspm/nodelibs-assert@0.1.0": {
@@ -78,7 +78,7 @@
     },
     "npm:asn1.js@4.3.0": {
       "assert": "github:jspm/nodelibs-assert@0.1.0",
-      "bn.js": "npm:bn.js@4.8.1",
+      "bn.js": "npm:bn.js@4.10.0",
       "buffer": "github:jspm/nodelibs-buffer@0.1.0",
       "inherits": "npm:inherits@2.0.1",
       "minimalistic-assert": "npm:minimalistic-assert@1.0.0",
@@ -87,6 +87,9 @@
     "npm:assert@1.3.0": {
       "util": "npm:util@0.10.3"
     },
+    "npm:bn.js@4.10.0": {
+      "buffer": "github:jspm/nodelibs-buffer@0.1.0"
+    },
     "npm:browserify-aes@1.0.6": {
       "buffer": "github:jspm/nodelibs-buffer@0.1.0",
       "buffer-xor": "npm:buffer-xor@1.0.3",
@@ -113,20 +116,20 @@
       "inherits": "npm:inherits@2.0.1"
     },
     "npm:browserify-rsa@4.0.0": {
-      "bn.js": "npm:bn.js@4.8.1",
+      "bn.js": "npm:bn.js@4.10.0",
       "buffer": "github:jspm/nodelibs-buffer@0.1.0",
       "constants": "github:jspm/nodelibs-constants@0.1.0",
       "crypto": "github:jspm/nodelibs-crypto@0.1.0",
       "randombytes": "npm:randombytes@2.0.2"
     },
     "npm:browserify-sign@4.0.0": {
-      "bn.js": "npm:bn.js@4.8.1",
+      "bn.js": "npm:bn.js@4.10.0",
       "browserify-rsa": "npm:browserify-rsa@4.0.0",
       "buffer": "github:jspm/nodelibs-buffer@0.1.0",
       "create-hash": "npm:create-hash@1.1.2",
       "create-hmac": "npm:create-hmac@1.1.4",
       "crypto": "github:jspm/nodelibs-crypto@0.1.0",
-      "elliptic": "npm:elliptic@6.2.2",
+      "elliptic": "npm:elliptic@6.2.3",
       "inherits": "npm:inherits@2.0.1",
       "parse-asn1": "npm:parse-asn1@5.0.0",
       "stream": "github:jspm/nodelibs-stream@0.1.0"
@@ -164,10 +167,10 @@
       "buffer": "github:jspm/nodelibs-buffer@0.1.0"
     },
     "npm:create-ecdh@4.0.0": {
-      "bn.js": "npm:bn.js@4.8.1",
+      "bn.js": "npm:bn.js@4.10.0",
       "buffer": "github:jspm/nodelibs-buffer@0.1.0",
       "crypto": "github:jspm/nodelibs-crypto@0.1.0",
-      "elliptic": "npm:elliptic@6.2.2"
+      "elliptic": "npm:elliptic@6.2.3"
     },
     "npm:create-hash@1.1.2": {
       "buffer": "github:jspm/nodelibs-buffer@0.1.0",
@@ -191,7 +194,7 @@
       "create-ecdh": "npm:create-ecdh@4.0.0",
       "create-hash": "npm:create-hash@1.1.2",
       "create-hmac": "npm:create-hmac@1.1.4",
-      "diffie-hellman": "npm:diffie-hellman@5.0.1",
+      "diffie-hellman": "npm:diffie-hellman@5.0.2",
       "inherits": "npm:inherits@2.0.1",
       "pbkdf2": "npm:pbkdf2@3.0.4",
       "public-encrypt": "npm:public-encrypt@4.0.0",
@@ -202,16 +205,16 @@
       "inherits": "npm:inherits@2.0.1",
       "minimalistic-assert": "npm:minimalistic-assert@1.0.0"
     },
-    "npm:diffie-hellman@5.0.1": {
-      "bn.js": "npm:bn.js@4.8.1",
+    "npm:diffie-hellman@5.0.2": {
+      "bn.js": "npm:bn.js@4.10.0",
       "buffer": "github:jspm/nodelibs-buffer@0.1.0",
       "crypto": "github:jspm/nodelibs-crypto@0.1.0",
       "miller-rabin": "npm:miller-rabin@4.0.0",
       "randombytes": "npm:randombytes@2.0.2",
       "systemjs-json": "github:systemjs/plugin-json@0.1.0"
     },
-    "npm:elliptic@6.2.2": {
-      "bn.js": "npm:bn.js@4.8.1",
+    "npm:elliptic@6.2.3": {
+      "bn.js": "npm:bn.js@4.10.0",
       "brorand": "npm:brorand@1.0.5",
       "hash.js": "npm:hash.js@1.0.3",
       "inherits": "npm:inherits@2.0.1",
@@ -235,7 +238,7 @@
       "util": "github:jspm/nodelibs-util@0.1.0"
     },
     "npm:miller-rabin@4.0.0": {
-      "bn.js": "npm:bn.js@4.8.1",
+      "bn.js": "npm:bn.js@4.10.0",
       "brorand": "npm:brorand@1.0.5"
     },
     "npm:ng2-bootstrap@1.0.1-beta.2": {
@@ -277,7 +280,7 @@
       "assert": "github:jspm/nodelibs-assert@0.1.0"
     },
     "npm:public-encrypt@4.0.0": {
-      "bn.js": "npm:bn.js@4.8.1",
+      "bn.js": "npm:bn.js@4.10.0",
       "browserify-rsa": "npm:browserify-rsa@4.0.0",
       "buffer": "github:jspm/nodelibs-buffer@0.1.0",
       "create-hash": "npm:create-hash@1.1.2",
@@ -315,10 +318,6 @@
       "assert": "github:jspm/nodelibs-assert@0.1.0",
       "process": "github:jspm/nodelibs-process@0.1.2"
     },
-    "npm:reflect-metadata@0.1.3": {
-      "assert": "github:jspm/nodelibs-assert@0.1.0",
-      "process": "github:jspm/nodelibs-process@0.1.2"
-    },
     "npm:ripemd160@1.0.1": {
       "buffer": "github:jspm/nodelibs-buffer@0.1.0",
       "process": "github:jspm/nodelibs-process@0.1.2"
--- a/package.json	Wed Jan 27 16:25:00 2016 +0100
+++ b/package.json	Mon Feb 01 17:29:04 2016 +0100
@@ -7,13 +7,13 @@
   },
   "jspm": {
     "dependencies": {
-      "angular2": "npm:angular2@^2.0.0-beta.1",
+      "angular2": "npm:angular2@2.0.0-beta.1",
       "ng2-bootstrap": "npm:ng2-bootstrap@^1.0.1-beta.2",
       "ng2-table": "npm:ng2-table@^1.0.0-beta.0",
       "plugin-typescript": "github:frankwallis/plugin-typescript@^2.5.2",
-      "reflect-metadata": "npm:reflect-metadata@^0.1.3",
+      "reflect-metadata": "npm:reflect-metadata@0.1.2",
       "rxjs": "npm:rxjs@5.0.0-beta.0",
-      "zone.js": "npm:zone.js@^0.5.10"
+      "zone.js": "npm:zone.js@0.5.10"
     },
     "devDependencies": {
       "typescript": "npm:typescript@^1.7.3"
@@ -21,8 +21,7 @@
   },
   "dependencies": {},
   "devDependencies": {
-    "angular2": "^2.0.0-beta.1",
-    "jspm": "0.16.19",
-    "rxjs": "5.0.0-beta.0"
+    "angular2": "2.0.0-beta.1",
+    "jspm": "0.16.19"
   }
 }