Skip to content

Commit

Permalink
fix(logs): fixes error in API and UI when 0 result
Browse files Browse the repository at this point in the history
  • Loading branch information
naholyr committed Sep 26, 2017
1 parent 8302d76 commit 1d4971f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 4 additions & 4 deletions client/src/app/log-table/log-table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@
</table>

<div class="pagination">
<ul>
<li><a md-button (click)="navigatePrev()"><md-icon>navigate_before</md-icon></a>
<li *ngIf="data"><span>{{ firstIndex }}-{{ lastIndex }} / {{ data.count }}</span></li>
<li><a md-button (click)="navigateNext()"><md-icon>navigate_next</md-icon></a>
<ul *ngIf="hasPagination()">
<li><a md-button (click)="navigatePrev()" *ngIf="hasPrev()"><md-icon>navigate_before</md-icon></a>
<li><span>{{ firstIndex }}-{{ lastIndex }} / {{ data.count }}</span></li>
<li><a md-button (click)="navigateNext()" *ngIf="hasNext()"><md-icon>navigate_next</md-icon></a>
</ul>

<md-select style="align-self:flex-end" [placeholder]="'editLogs.limit' | translate" [formControl]="filterForm.controls['limit']" *ngIf="filterForm.controls['limit']">
Expand Down
10 changes: 10 additions & 0 deletions client/src/app/log-table/log-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ export class LogTableComponent implements OnInit, OnChanges {
}
}

hasPagination () {
return this.data && this.data.count > this.options.limit
}
hasNext () {
return this.hasPagination() && this.lastIndex <= this.data.count
}
hasPrev () {
return this.hasPagination() && this.firstIndex > 1
}

navigatePrev() {
if (this.options.skip === 0) return;
this.emitOptions(Object.assign(this.options, {
Expand Down
3 changes: 2 additions & 1 deletion server/routes/editLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function getEditLog(req, res){
.concat([{'$group': { '_id' : null, 'count' : {$sum : 1} }}])

const countP = EditLog.aggregate(countPipeline)
.then(([ { count } ]) => count)
.then(data => (data && data[0] && data[0].count) || 0)
const resultsP = EditLog.aggregate(resultsPipeline)
.then(data => formatEdits(data, model, !canViewConfidential))

Expand All @@ -320,6 +320,7 @@ function getEditLog(req, res){
return editsP
.then(edits => res.status(200).send(edits))
.catch(err => {
console.error(err) // eslint-disable-line no-console
if (!err.status) {
err = new ServerError({ title: err.message })
}
Expand Down

0 comments on commit 1d4971f

Please sign in to comment.