Mercurial > hg > ng2-query-ismi
changeset 21:930fe7460f6b
result table shows all attributes now.
author | casties |
---|---|
date | Fri, 22 Jan 2016 20:33:26 +0100 |
parents | 34cd764e234b |
children | 9343e43a17d1 |
files | app/query-result-row.component.ts app/query-result.component.ts app/query-state.ts app/query.service.ts |
diffstat | 4 files changed, 65 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/app/query-result-row.component.ts Fri Jan 22 17:32:33 2016 +0100 +++ b/app/query-result-row.component.ts Fri Jan 22 20:33:26 2016 +0100 @@ -3,19 +3,25 @@ @Component({ selector: 'tr.resultRow', template: ` - <td *ngIf="rowType=='node'">[{{rowData.ismi_id}}]</td> - <td *ngIf="rowType=='node'">{{rowData.label}}</td> - <td *ngIf="rowType=='node' && rowData.link"> - <a href="https://ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/browse/entityDetails.xhtml?eid={{rowData.ismi_id}}" target="_blank">view in OpenMind</a> + <td style="vertical-align: top;" + *ngIf="rowType=='node'" *ngFor="#col of columns"> + <a *ngIf="col && col.name=='link'" href="{{rowData[col.name]}}" target="_blank">Link</a> + <span *ngIf="col && col.name!='link'">{{rowData[col.name]}}</span> </td> - <td *ngIf="rowType=='text'">{{rowData}}</td> + + <td style="vertical-align: top;" + *ngIf="rowType=='text'">{{rowData}}</td> `, - inputs: ['rowData', 'rowType'] + inputs: ['rowData', 'rowType', 'columns'] }) export class QueryResultRowComponent { + public rowType: string; public rowData: any; - public rowType: string; + public columns: any[]; + /* ngOnInit() { + console.debug("row init! columns=", this.columns, " rowData=", this.rowData); + } */ }
--- a/app/query-result.component.ts Fri Jan 22 17:32:33 2016 +0100 +++ b/app/query-result.component.ts Fri Jan 22 20:33:26 2016 +0100 @@ -12,12 +12,12 @@ <p>Query results ({{queryState.resultInfo}}):</p> <table> <tr> - <th *ngIf="queryState.resultTypes=='node'">ID</th> - <th *ngIf="queryState.resultTypes=='node'">Label</th> - <th *ngIf="queryState.resultTypes=='node'">Link</th> + <th *ngIf="queryState.resultTypes=='node' && queryState.resultColumns" + *ngFor="#col of queryState.resultColumns">{{col?col.label:col}}</th> </tr> <tr class="resultRow" *ngFor="#row of queryState.results" - [rowData]="row" [rowType]="queryState.resultTypes"> + [rowData]="row" [rowType]="queryState.resultTypes" + [columns]="queryState.resultColumns"> </tr> </table> </div> @@ -26,20 +26,8 @@ inputs: ['queryState'] }) -export class QueryResultComponent implements OnInit { +export class QueryResultComponent { public queryState: QueryState; - - ngOnChanges() { - console.debug("result changed!"); - } - - ngOnInit() { - this.setup(); - } - - setup() { - console.debug("result init!"); - } - + }
--- a/app/query-state.ts Fri Jan 22 17:32:33 2016 +0100 +++ b/app/query-state.ts Fri Jan 22 20:33:26 2016 +0100 @@ -12,8 +12,8 @@ public numResults: number; public resultTypes: string; public resultInfo: string; - - public nextQueryRelations: any[]; - public nextQueryAttributes: any[]; + public resultAttributes: string[]; + public resultRelations: any[]; + public resultColumns: any[]; } \ No newline at end of file
--- a/app/query.service.ts Fri Jan 22 17:32:33 2016 +0100 +++ b/app/query.service.ts Fri Jan 22 20:33:26 2016 +0100 @@ -44,13 +44,13 @@ if (queryMode.id === 'type_is') { options = this.objectTypes; } else if (queryMode.id === 'relation_is') { - options = this.state.nextQueryRelations; + options = this.state.resultRelations; } else if (queryMode.id === 'att_contains') { - options = this.state.nextQueryAttributes; + options = this.filterAttributes(this.state.resultAttributes); } else if (queryMode.id === 'att_contains_norm') { - options = this.state.nextQueryAttributes; + options = this.filterAttributes(this.state.resultAttributes, true); } else if (queryMode.id === 'att_num_range') { - options = this.state.nextQueryAttributes; + options = this.filterAttributes(this.state.resultAttributes); } console.debug("getQueryOptions returns: ", options); return options; @@ -237,8 +237,9 @@ */ if (this.state.attributesCypherQuery) { resIdx += 1; - this.state.nextQueryAttributes = data.results[resIdx].data.map(elem => elem.row[0]) - .filter(elem => elem[0] != "_" && !this.excludedAttributes[elem]); + var atts = data.results[resIdx].data.map(elem => elem.row[0]); + this.state.resultAttributes = atts; + this.state.resultColumns = this.getColumns(atts); } /* * results for relations list @@ -249,7 +250,7 @@ .filter(elem => elem[0] != "_"); // add inverse relations var invrels = rels.concat(rels.map((r) => this.invRelPrefix + r)); - this.state.nextQueryRelations = invrels; + this.state.resultRelations = invrels; } }, err => console.error("neo4j result error=", err), @@ -257,6 +258,41 @@ ); } + + filterAttributes(attributes: string[], normalized=false) { + var atts = []; + if (normalized) { + attributes.forEach((att) => { + if (att.substr(0, 3) == "_n_") { + atts.push(att.substr(3)); + } + }); + } else { + atts = attributes.filter(elem => elem[0] != "_" && !this.excludedAttributes[elem]); + } + return atts; + } + + /** + * Return nice column objects + */ + getColumns(attributes: string[]) { + var cols = []; + if (attributes.indexOf('ismi_id') > -1) { + cols.push({'name': 'ismi_id', 'label': 'ISMI ID'}); + } + if (attributes.indexOf('label') > -1) { + cols.push({'name': 'label', 'label': 'Label'}); + } + attributes.forEach((att) => { + if (att != 'ismi_id' && att != 'label' && att != 'type' && att[0] != '_') { + cols.push({'name': att, 'label': att}); + } + }); + + return cols; + } + /** * Run the given queries on the Neo4J server. *