From 58fc326fb25621233fd98528f9b4d8867c9b6c61 Mon Sep 17 00:00:00 2001 From: Steven Zou Date: Fri, 9 Jun 2017 13:07:26 +0800 Subject: [PATCH 1/2] use *ngFor to replace *clrDgItems in user datagird --- src/ui_ng/src/app/user/user.component.html | 8 ++-- src/ui_ng/src/app/user/user.component.ts | 46 +++++++++++++++++++--- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/ui_ng/src/app/user/user.component.html b/src/ui_ng/src/app/user/user.component.html index 6c351efd73..516adf19a5 100644 --- a/src/ui_ng/src/app/user/user.component.html +++ b/src/ui_ng/src/app/user/user.component.html @@ -6,18 +6,18 @@ - +
- + {{'USER.COLUMN_NAME' | translate}} {{'USER.COLUMN_ADMIN' | translate}} {{'USER.COLUMN_EMAIL' | translate}} {{'USER.COLUMN_REG_NAME' | translate}} - + @@ -28,7 +28,7 @@ {{user.creation_time | date: 'short'}} {{pagination.firstItem + 1}} - {{pagination.lastItem + 1}} of {{pagination.totalItems}} users - {{'USER.ITEMS' | translate}} + {{'USER.ITEMS' | translate}} diff --git a/src/ui_ng/src/app/user/user.component.ts b/src/ui_ng/src/app/user/user.component.ts index 3195d9ff6b..ff2589755d 100644 --- a/src/ui_ng/src/app/user/user.component.ts +++ b/src/ui_ng/src/app/user/user.component.ts @@ -14,6 +14,7 @@ import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core'; import 'rxjs/add/operator/toPromise'; import { Subscription } from 'rxjs/Subscription'; +import { State } from 'Clarity-Angular'; import { UserService } from './user.service'; import { User } from './user'; @@ -27,6 +28,16 @@ import { MessageHandlerService } from '../shared/message-handler/message-handler import { SessionService } from '../shared/session.service'; import { AppConfigService } from '../app-config.service'; +/** + * NOTES: + * Pagination for this component is a temporary workaround solution. It will be replaced in future release. + * + * @export + * @class UserComponent + * @implements {OnInit} + * @implements {OnDestroy} + */ + @Component({ selector: 'harbor-user', templateUrl: 'user.component.html', @@ -44,6 +55,8 @@ export class UserComponent implements OnInit, OnDestroy { private deletionSubscription: Subscription; currentTerm: string; + totalCount: number = 0; + currentPage: number = 1; @ViewChild(NewUserModalComponent) private newUserDialog: NewUserModalComponent; @@ -76,7 +89,7 @@ export class UserComponent implements OnInit, OnDestroy { } private isMatchFilterTerm(terms: string, testedItem: string): boolean { - return testedItem.indexOf(terms) != -1; + return testedItem.toLowerCase().indexOf(terms.toLowerCase()) != -1; } public get canCreateUser(): boolean { @@ -111,7 +124,6 @@ export class UserComponent implements OnInit, OnDestroy { } ngOnInit(): void { - this.refreshUser(); } ngOnDestroy(): void { @@ -125,7 +137,7 @@ export class UserComponent implements OnInit, OnDestroy { this.currentTerm = terms; this.originalUsers.then(users => { if (terms.trim() === "") { - this.users = users; + this.refreshUser((this.currentPage-1)*15,this.currentPage*15); } else { this.users = users.filter(user => { return this.isMatchFilterTerm(terms, user.username); @@ -203,7 +215,7 @@ export class UserComponent implements OnInit, OnDestroy { } //Refresh the user list - refreshUser(): void { + refreshUser(from:number, to: number): void { //Start to get this.currentTerm = ''; this.onGoing = true; @@ -212,7 +224,8 @@ export class UserComponent implements OnInit, OnDestroy { .then(users => { this.onGoing = false; - this.users = users; + this.totalCount = users.length; + this.users = users.slice(from, to);//First page return users; }) .catch(error => { @@ -232,7 +245,28 @@ export class UserComponent implements OnInit, OnDestroy { //Add user to the user list addUserToList(user: User): void { //Currently we can only add it by reloading all - this.refreshUser(); + this.refresh(); + } + + //Data loading + load(state: State): void { + if (state && state.page) { + if(this.originalUsers){ + this.originalUsers.then(users => { + this.users = users.slice(state.page.from, state.page.to+1); + }); + }else{ + this.refreshUser(state.page.from, state.page.to+1); + } + } else { + //Refresh + this.refresh(); + } + } + + refresh(): void { + this.currentPage = 1;//Refresh pagination + this.refreshUser(0,15); } } From 2583b19bcf1b8ec6ddeb4f76c59a5cef513ad923 Mon Sep 17 00:00:00 2001 From: Steven Zou Date: Fri, 9 Jun 2017 13:37:15 +0800 Subject: [PATCH 2/2] remove Clarity-Angular module import --- src/ui_ng/src/app/user/user.component.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ui_ng/src/app/user/user.component.ts b/src/ui_ng/src/app/user/user.component.ts index ff2589755d..4c7d7f5ff9 100644 --- a/src/ui_ng/src/app/user/user.component.ts +++ b/src/ui_ng/src/app/user/user.component.ts @@ -14,7 +14,6 @@ import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core'; import 'rxjs/add/operator/toPromise'; import { Subscription } from 'rxjs/Subscription'; -import { State } from 'Clarity-Angular'; import { UserService } from './user.service'; import { User } from './user'; @@ -249,7 +248,7 @@ export class UserComponent implements OnInit, OnDestroy { } //Data loading - load(state: State): void { + load(state: any): void { if (state && state.page) { if(this.originalUsers){ this.originalUsers.then(users => {