Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
metagrover committed Dec 2, 2016
1 parent 5267eb2 commit 456aabf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
6 changes: 3 additions & 3 deletions app/queryBlocks/queryBlocks.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
<i class="fa fa-minus"></i>
Query
</a>
<a [ngClass]="{'selected': result.sort.length > 0}" (click)="toggleSortQuery();">
<a [ngClass]="{'selected': (result.sort) && (result.sort.length > 0)}" (click)="toggleSortQuery();">
<i class="fa fa-plus"></i>
<i class="fa fa-minus"></i>
Sorting
</a>
</div>
</div>
<span *ngIf="result.resultQuery.result.length >= 1 || result.sort.length >= 1" class="col-xs-4 pd-0">
<span *ngIf="result.resultQuery.result.length >= 1 || (result.sort && result.sort.length >= 1)" class="col-xs-4 pd-0">
<button class="btn btn-theme pull-right" style="margin-top: 3px" (click)="openModal();">Save State</button>
</span>
</div>
Expand Down Expand Up @@ -53,7 +53,7 @@
</bool-query>
</div>
</form>
<div *ngIf="result.sort.length">
<div *ngIf="result.sort && result.sort.length">
<sort-block
[mapping]="mapping"
[types]="types"
Expand Down
80 changes: 44 additions & 36 deletions app/queryBlocks/queryBlocks.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,45 +197,47 @@ export class QueryBlocksComponent implements OnInit, OnChanges {
}

// apply sort
self.result.sort.map((sortObj) => {
if (sortObj.selectedField) {
if (!es_final.hasOwnProperty('sort')) {
es_final['sort'] = [];
}
if (self.result.sort) {
self.result.sort.map((sortObj) => {
if (sortObj.selectedField) {
if (!es_final.hasOwnProperty('sort')) {
es_final['sort'] = [];
}

let obj = {};
if (sortObj._geo_distance) {
obj = {
['_geo_distance']: {
let obj = {};
if (sortObj._geo_distance) {
obj = {
['_geo_distance']: {
[sortObj.selectedField]: {
'lat': sortObj._geo_distance.lat,
'lon': sortObj._geo_distance.lon
},
'order': sortObj.order,
'distance_type': sortObj._geo_distance.distance_type,
'unit': sortObj._geo_distance.unit || 'm'
}
}
if (sortObj.mode) {
obj['_geo_distance']['mode'] = sortObj.mode;
}
} else {
obj = {
[sortObj.selectedField]: {
'lat': sortObj._geo_distance.lat,
'lon': sortObj._geo_distance.lon
},
'order': sortObj.order,
'distance_type': sortObj._geo_distance.distance_type,
'unit': sortObj._geo_distance.unit || 'm'
'order': sortObj.order
}
};
if (sortObj.mode) {
obj[sortObj.selectedField]['mode'] = sortObj.mode;
}
}
if (sortObj.mode) {
obj['_geo_distance']['mode'] = sortObj.mode;
}
} else {
obj = {
[sortObj.selectedField]: {
'order': sortObj.order
if (sortObj.missing) {
obj[sortObj.selectedField]['missing'] = sortObj.missing;
}
};
if (sortObj.mode) {
obj[sortObj.selectedField]['mode'] = sortObj.mode;
}
if (sortObj.missing) {
obj[sortObj.selectedField]['missing'] = sortObj.missing;
}
}

es_final['sort'].push(obj);
}
});
es_final['sort'].push(obj);
}
});
}

this.result.resultQuery.final = JSON.stringify(es_final, null, 2);
try {
Expand Down Expand Up @@ -321,10 +323,16 @@ export class QueryBlocksComponent implements OnInit, OnChanges {
}

toggleSortQuery() {
if (this.result.sort.length < 1 && this.selectedTypes.length > 0) {
this.addSortBlock();
if (this.result.sort) {
console.log("coming");
if (this.result.sort.length < 1 && this.selectedTypes.length > 0) {
this.addSortBlock();
} else {
this.removeSortBlock();
}
} else {
this.removeSortBlock();
this.result.sort = [];
this.addSortBlock();
}
}

Expand Down

0 comments on commit 456aabf

Please sign in to comment.