Skip to content

Commit

Permalink
Show number of visits in member table (fixes #2030) (#2077)
Browse files Browse the repository at this point in the history
  • Loading branch information
yubaraj poudel authored and paulbert committed Sep 20, 2018
1 parent d677f1b commit 4a5b25f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/app/users/users.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
<mat-header-cell *matHeaderCellDef mat-sort-header i18n>User Name</mat-header-cell>
<mat-cell *matCellDef="let element">{{element.doc.name}}</mat-cell>
</ng-container>

<ng-container matColumnDef="visits">
<mat-header-cell *matHeaderCellDef mat-sort-header i18n>No. of Visits</mat-header-cell>
<mat-cell *matCellDef="let element">{{element.visitCount}}</mat-cell>
</ng-container>
<ng-container matColumnDef="roles">
<mat-header-cell *matHeaderCellDef mat-sort-header i18n>Roles</mat-header-cell>
<mat-cell *matCellDef="let element">
Expand Down
17 changes: 12 additions & 5 deletions src/app/users/users.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class UsersComponent implements OnInit, OnDestroy, AfterViewInit {
this.filterAssociated = true;
break;
default:
this.displayedColumns = [ 'select', 'profile', 'name', 'roles', 'action' ];
this.displayedColumns = [ 'select', 'profile', 'name', 'visits', 'roles', 'action' ];
this.filterAssociated = false;
break;
}
Expand Down Expand Up @@ -125,20 +125,23 @@ export class UsersComponent implements OnInit, OnDestroy, AfterViewInit {
this.allUsers.data.slice(start, end).forEach((row: any) => this.selection.select(row.doc._id));
}

getUsers() {
return this.couchService.findAll(this.dbName, { 'selector': {}, 'limit': 3 });
getUsersAndLoginActivities() {
return forkJoin([
this.couchService.findAll(this.dbName, { 'selector': {}, 'limit': 100 }),
this.couchService.findAll('login_activities', { 'selector': {}, 'limit': 100 })
]);
}

initializeData() {
const currentLoginUser = this.userService.get().name;
this.selection.clear();
this.getUsers().pipe(debug('Getting user list')).subscribe((users: any) => {
this.getUsersAndLoginActivities().pipe(debug('Getting user list')).subscribe(([ users, loginActivities ]) => {
this.allUsers.data = users.filter((user: any) => {
// Removes current user and special satellite user from list. Users should not be able to change their own roles,
// so this protects from that. May need to unhide in the future.
return currentLoginUser !== user.name && user.name !== 'satellite';
}).map((user: any) => {
const userInfo = { doc: user, imageSrc: '' };
const userInfo = { doc: user, imageSrc: '', visitCount: this.userLoginCount(user, loginActivities) };
if (user._attachments) {
userInfo.imageSrc = this.urlPrefix + 'org.couchdb.user:' + user.name + '/' + Object.keys(user._attachments)[0];
}
Expand Down Expand Up @@ -278,4 +281,8 @@ export class UsersComponent implements OnInit, OnDestroy, AfterViewInit {
this.selectedRoles = newSelection;
}

userLoginCount(user: any, loginActivities: any[]) {
return loginActivities.filter((logItem: any) => logItem.user === user.name).length;
}

}

0 comments on commit 4a5b25f

Please sign in to comment.