Skip to content

Commit 6215c14

Browse files
author
SherazAmeer
committed
contact_dnc table update nebular
1 parent bbbea28 commit 6215c14

File tree

9 files changed

+23256
-16350
lines changed

9 files changed

+23256
-16350
lines changed

package-lock.json

Lines changed: 23103 additions & 16192 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<nb-card>
22
<nb-card-header>
33
{{ 'contact_dnc.list' | translate}}
4-
<input style="float: right" class="form-control cc" type="text" #filter placeholder="{{ 'contact_dnc.filter' | translate}}"/>
4+
<input nbInput fullWidth placeholder="{{ 'contact_dnc.filter' | translate }}" [nbFilterInput]="dataSource" id="search" class="form-control cc" style="float:right">
5+
56
</nb-card-header>
67
<nb-card-body>
78
<button type="button" mat-raised-button color="primary" style="font-size: 15px" [routerLink]="['/pages/contact_dnc/contact_dnc/new']"><i class="fa fa-plus"></i> {{ 'contact_dnc.add' | translate}}</button>&nbsp;
@@ -28,62 +29,55 @@
2829
<button (click)="dialog.showModal()" type="button" mat-raised-button color="primary" style="font-size: 15px">
2930
<i class="fa fa-upload" title="Import DNC file"> {{'contact_dnc.import' | translate}}</i>
3031
</button> <br /><br />
31-
<div class="example-container mat-elevation-z8">
32-
<mat-table table [dataSource]="aContactDNC" matSort>
33-
<ng-container matColumnDef="ID"><mat-header-cell *matHeaderCellDef mat-sort-header>ID</mat-header-cell>
34-
<mat-cell *matCellDef="let contact_dnc">{{contact_dnc.contact_dnc_id}}</mat-cell>
35-
</ng-container>
36-
37-
<ng-container matColumnDef="first_name">
38-
<mat-header-cell *matHeaderCellDef mat-sort-header>{{'contact_dnc.first_name' | translate}}</mat-header-cell>
39-
<mat-cell *matCellDef="let contact_dnc">{{contact_dnc.first_name}}</mat-cell>
40-
</ng-container>
41-
42-
<ng-container matColumnDef="last_name">
43-
<mat-header-cell *matHeaderCellDef mat-sort-header>{{'contact_dnc.last_name' | translate}}</mat-header-cell >
44-
<mat-cell *matCellDef="let contact_dnc">{{contact_dnc.last_name}}</mat-cell>
45-
</ng-container>
46-
47-
<ng-container matColumnDef="phone">
48-
<mat-header-cell *matHeaderCellDef mat-sort-header>{{'contact_dnc.phone' | translate}}</mat-header-cell>
49-
<mat-cell *matCellDef="let contact_dnc">{{contact_dnc.phone}}</mat-cell>
50-
</ng-container>
51-
52-
<!-- <ng-container matColumnDef="date_created">
53-
<mat-header-cell *matHeaderCellDef mat-sort-header>{{'outbound_fax.date_time' | translate }}</mat-header-cell>
54-
<mat-cell *matCellDef="let sendfax">
55-
{{sendfax.last_run * 1000 | date:'yyyy-MM-dd HH:mm:ss a'}}
56-
</mat-cell>
57-
</ng-container> -->
58-
59-
<ng-container matColumnDef="email">
60-
<mat-header-cell *matHeaderCellDef mat-sort-header>{{'contact_dnc.email' | translate}}</mat-header-cell>
61-
<mat-cell *matCellDef="let contact_dnc">{{contact_dnc.email}}</mat-cell>
32+
<table [nbTreeGrid]="dataSource" [nbSort]="dataSource">
33+
<tr nbTreeGridHeaderRow *nbTreeGridHeaderRowDef="displayedColumns"></tr>
34+
<tr nbTreeGridRow *nbTreeGridRowDef="let row; columns: displayedColumns"></tr>
35+
<ng-container nbTreeGridColumnDef="contact_dnc_id">
36+
<th nbTreeGridHeaderCell *nbTreeGridHeaderCellDef [nbSortHeader]>{{ 'general.ID' | translate }} </th>
37+
<td nbTreeGridCell *nbTreeGridCellDef="let row">{{ row.data.contact_dnc_id }}</td>
38+
</ng-container>
39+
<ng-container nbTreeGridColumnDef="first_name">
40+
<th nbTreeGridHeaderCell *nbTreeGridHeaderCellDef [nbSortHeader]>{{ 'contact_dnc.first_name' | translate }}</th>
41+
<td nbTreeGridCell *nbTreeGridCellDef="let row">{{ row.data.first_name }}</td>
42+
</ng-container>
43+
<ng-container nbTreeGridColumnDef="last_name">
44+
<th nbTreeGridHeaderCell *nbTreeGridHeaderCellDef [nbSortHeader]>{{ 'contact_dnc.last_name' | translate }}</th>
45+
<td nbTreeGridCell *nbTreeGridCellDef="let row">{{ row.data.last_name }}</td>
46+
</ng-container>
47+
<ng-container nbTreeGridColumnDef="phone">
48+
<th nbTreeGridHeaderCell *nbTreeGridHeaderCellDef [nbSortHeader]>{{ 'contact_dnc.phone' | translate }}</th>
49+
<td nbTreeGridCell *nbTreeGridCellDef="let row">{{ row.data.phone }}</td>
50+
</ng-container>
51+
<ng-container nbTreeGridColumnDef="email">
52+
<th nbTreeGridHeaderCell *nbTreeGridHeaderCellDef [nbSortHeader] style="width: 300px;" >{{ 'contact_dnc.email' | translate }}</th>
53+
<td nbTreeGridCell *nbTreeGridCellDef="let row">{{ row.data.email }}</td>
6254
</ng-container>
63-
64-
<ng-container matColumnDef="operation">
65-
<mat-header-cell *matHeaderCellDef mat-sort-header>{{'general.operations' | translate}}</mat-header-cell>
66-
<mat-cell *matCellDef="let contact_dnc">{{contact_dnc.operation}}
55+
<ng-container nbTreeGridColumnDef="operation">
56+
<th nbTreeGridHeaderCell *nbTreeGridHeaderCellDef>{{ 'general.operations' | translate }}</th>
57+
<td nbTreeGridCell *nbTreeGridCellDef="let contact_dnc">
58+
{{contact_dnc.operation}}
6759
<button mat-icon-button color="accent" style="font-size: 20px">
68-
<mat-icon><a routerLink="/pages/contact_dnc/contact_dnc/{{contact_dnc.contact_dnc_id}}" title="Edit"><nb-icon icon="edit-2-outline"></nb-icon></a></mat-icon>
60+
<mat-icon><a routerLink="/pages/contact_dnc/contact_dnc/{{contact_dnc.data.contact_dnc_id}}" title="Edit"><nb-icon icon="edit-2-outline"></nb-icon></a></mat-icon>
6961
</button>
70-
<button mat-icon-button color="warn" style="font-size: 20px" (click)="deleteContactDNC(contact_dnc.contact_dnc_id)"(click)="showStaticModal(contact_dnc.first_name, contact_dnc.contact_dnc_id)">
62+
<button mat-icon-button color="warn" style="font-size: 20px" (click)="deleteContactDNC(contact_dnc.data.contact_dnc_id)"(click)="showStaticModal(contact_dnc.first_name, contact_dnc.contact_dnc_id)">
7163
<nb-icon icon="trash-2-outline" title="Delete"> </nb-icon>
7264
</button>
73-
</mat-cell>
65+
</td>
7466
</ng-container>
75-
76-
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
77-
<mat-row *matRowDef="let contact_dnc; columns: displayedColumns"></mat-row>
78-
</mat-table>
79-
<mat-paginator
80-
paginator
81-
[length]="length"
82-
[pageIndex]="0"
83-
[pageSize]="5"
84-
[pageSizeOptions]="[5, 10, 25, 100]"
85-
>
86-
</mat-paginator>
87-
</div>
67+
</table>
68+
<div style="padding: 30px; display: flex; justify-content: flex-end;">
69+
<span style="text-align: center; padding-top: 10px;">Items per page: &nbsp;&nbsp;</span>
70+
<nb-select [(ngModel)]="pageSize" (ngModelChange)="paginate($event)">
71+
<nb-option *ngFor="let option of items_page" [value]="option">{{ option }}</nb-option>
72+
</nb-select>
73+
<div style="padding-top: 10px;">
74+
<nb-icon style="margin: 0 25px;" icon="arrowhead-left-outline" (click)="startIndex > 0 ? paginate('previous') : null" [ngClass]="{'disabled-icon': startIndex === 0}"></nb-icon>
75+
<span>Page {{ currentPage }} of {{ total_pages }}</span>
76+
<nb-icon style="margin: 0 25px;" icon="arrowhead-right-outline" (click)="startIndex + pageSize < contactArray?.length ? paginate('next') : null" [ngClass]="{'disabled-icon': startIndex + pageSize >= contactArray?.length}"> </nb-icon>
77+
<span *ngIf="contactArray?.length > 0">
78+
| Showing {{ startIndex }} - {{ minimumItems }} of {{ length }} items
79+
</span>
80+
</div>
81+
</div>
8882
</nb-card-body>
8983
</nb-card>

src/app/pages/contact_dnc/contact_dnc-component.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ dialog {
1919
}
2020

2121

22+
th {
23+
font-size: 12px;
24+
}

src/app/pages/contact_dnc/contact_dnc-component.ts

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { Observable } from 'rxjs/Rx';
1010
import { FileUploader, FileUploaderOptions } from 'ng2-file-upload';
1111
import { AppService } from '../../app.service';
1212
import { ContactDNC } from './contact_dnc';
13+
import { NbTreeGridDataSource, NbTreeGridDataSourceBuilder } from '@nebular/theme';
14+
1315

1416

1517
@Component({
@@ -20,19 +22,31 @@ import { ContactDNC } from './contact_dnc';
2022

2123

2224
export class FormsContactDNCComponent implements OnInit {
23-
constructor(private contact_dnc_service: ContactDNCService, private modalService: NgbModal, private app_service: AppService) { }
25+
constructor(private contact_dnc_service: ContactDNCService,
26+
private dataSourceBuilder: NbTreeGridDataSourceBuilder<ContactDNC>,
27+
private modalService: NgbModal, private app_service: AppService) { }
2428

2529
URL = `${this.app_service.apiUrlContactDNC}/import/csv`
2630
public uploader: FileUploader = new FileUploader({ url: this.URL, disableMultipart: true });
2731

28-
aContactDNC: ContactDNCDataSource | null;
32+
// aContactDNC: ContactDNCDataSource | null;
33+
contactArray: ContactDNC[] =[]
34+
dataSource: NbTreeGridDataSource<ContactDNC>;
2935
length: number;
3036
closeResult: any;
3137
unsupportedErr: any = false;
3238
file: any;
3339
contact_dnc: ContactDNC = new ContactDNC;
3440

35-
displayedColumns = ['ID', 'first_name', 'last_name', 'phone','email', 'operation'];
41+
items_page = [5, 10, 25, 100];
42+
pageSize = 10;
43+
startIndex: number = 0;
44+
currentPage: number;
45+
total_pages: number;
46+
minimumItems: number;
47+
current_items: any[] = [];
48+
49+
displayedColumns = ['contact_dnc_id', 'first_name', 'last_name', 'phone','email', 'operation'];
3650

3751
@ViewChild(MatSort) sort: MatSort;
3852

@@ -63,23 +77,55 @@ export class FormsContactDNCComponent implements OnInit {
6377
}
6478
getContactDNClist() {
6579
this.contact_dnc_service.get_ContactDNCList().then(data => {
80+
this.contactArray = data.sort((a, b) => b.contact_dnc_id - a.contact_dnc_id);
81+
6682
this.length = data.length;
67-
this.aContactDNC = new ContactDNCDataSource(new ContactDNCDatabase(data), this.sort, this.paginator);
83+
// this.aContactDNC = new ContactDNCDataSource(new ContactDNCDatabase(data), this.sort, this.paginator);
84+
this.paginate(this.pageSize);
85+
86+
this.dataSource = this.dataSourceBuilder.create(this.current_items.map(item => ({ data: item })));
87+
6888
// Observable for the filter
69-
Observable.fromEvent(this.filter.nativeElement, 'keyup')
70-
.debounceTime(150)
71-
.distinctUntilChanged()
72-
.subscribe(() => {
73-
if (!this.aContactDNC) { return; }
74-
this.aContactDNC.filter = this.filter.nativeElement.value;
75-
});
76-
//Sort the data automatically
77-
const sortState: Sort = { active: 'ID', direction: 'desc' };
78-
this.sort.active = sortState.active;
79-
this.sort.direction = sortState.direction;
80-
this.sort.sortChange.emit(sortState);
89+
// Observable.fromEvent(this.filter.nativeElement, 'keyup')
90+
// .debounceTime(150)
91+
// .distinctUntilChanged()
92+
// .subscribe(() => {
93+
// if (!this.aContactDNC) { return; }
94+
// this.aContactDNC.filter = this.filter.nativeElement.value;
95+
// });
96+
// //Sort the data automatically
97+
// const sortState: Sort = { active: 'ID', direction: 'desc' };
98+
// this.sort.active = sortState.active;
99+
// this.sort.direction = sortState.direction;
100+
// this.sort.sortChange.emit(sortState);
81101
});
82102
}
103+
104+
paginate(page_Items: string | number) {
105+
if (typeof page_Items === 'string') {
106+
if (page_Items === 'next') {
107+
if (this.startIndex + this.pageSize < this.length) {
108+
this.startIndex += this.pageSize;
109+
}
110+
} else if (page_Items === 'previous') {
111+
if (this.startIndex > 0) {
112+
this.startIndex -= this.pageSize;
113+
}
114+
}
115+
} else {
116+
this.pageSize = page_Items;
117+
this.startIndex = 0;
118+
}
119+
this.currentPage = Math.floor(this.startIndex / this.pageSize) + 1;
120+
this.total_pages = Math.ceil(this.length / this.pageSize);
121+
this.minimumItems = Math.min(this.startIndex + this.pageSize, this.length);
122+
123+
const end = Math.min(this.startIndex + this.pageSize, this.length);
124+
this.current_items = this.contactArray.slice(this.startIndex, end);
125+
this.dataSource = this.dataSourceBuilder.create(this.current_items.map(item => ({ data: item })));
126+
}
127+
128+
83129
private refreshData(): void {
84130
this.contact_dnc_service.get_ContactDNCList().then(data => {
85131
this.length = data.length;
@@ -88,15 +134,17 @@ export class FormsContactDNCComponent implements OnInit {
88134
element.contact_phone = 'N/A';
89135
}
90136
})
91-
this.aContactDNC = new ContactDNCDataSource(new ContactDNCDatabase(data), this.sort, this.paginator);
137+
// this.aContactDNC = new ContactDNCDataSource(new ContactDNCDatabase(data), this.sort, this.paginator);
138+
this.dataSource = this.dataSourceBuilder.create(this.current_items.map(item => ({ data: item })));
139+
92140
// Observable for the filter
93-
Observable.fromEvent(this.filter.nativeElement, 'keyup')
94-
.debounceTime(150)
95-
.distinctUntilChanged()
96-
.subscribe(() => {
97-
if (!this.aContactDNC) { return; }
98-
this.aContactDNC.filter = this.filter.nativeElement.value;
99-
});
141+
// Observable.fromEvent(this.filter.nativeElement, 'keyup')
142+
// .debounceTime(150)
143+
// .distinctUntilChanged()
144+
// .subscribe(() => {
145+
// if (!this.aContactDNC) { return; }
146+
// this.aContactDNC.filter = this.filter.nativeElement.value;
147+
// });
100148
});
101149

102150
}

src/app/pages/contact_dnc/contact_dnc-form-component.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ <h1>{{ 'contact_dnc.add' | translate}}</h1>
99
<div class="col-sm-6">
1010
<div class="form-group">
1111
<label for="first_name">{{ 'contact_dnc.first_name' | translate}}:</label>
12-
<input [(ngModel)]="contact_dnc.first_name" [ngModelOptions]="{ standalone: true }" class="form-control" placeholder="" id="first_name" required/>
12+
<input [(ngModel)]="contact_dnc.first_name" [ngModelOptions]="{ standalone: true }" class="form-control" nbInput fullWidth placeholder="" id="first_name" required/>
1313
</div>
1414
</div>
1515
<div class="col-sm-6">
1616
<div class="form-group">
1717
<label for="last_name"> {{ 'contact_dnc.last_name' | translate}}:</label>
18-
<input [(ngModel)]="contact_dnc.last_name" [ngModelOptions]="{ standalone: true }" type="text" class="form-control" placeholder="" id="last_name" required />
18+
<input [(ngModel)]="contact_dnc.last_name" [ngModelOptions]="{ standalone: true }" type="text" class="form-control" nbInput fullWidth placeholder="" id="last_name" required />
1919
</div>
2020
</div>
2121
</div>
@@ -24,7 +24,7 @@ <h1>{{ 'contact_dnc.add' | translate}}</h1>
2424
<div class="col-sm-6">
2525
<div class="form-group">
2626
<label for="phone">{{ 'contact_dnc.phone' | translate}}:</label>
27-
<input [(ngModel)]="contact_dnc.phone" [ngModelOptions]="{standalone: true}" type="phone" id="phone" class="form-control" pattern="[0-9]*" minlength="11" maxlength="16" #phone="ngModel" required/>
27+
<input [(ngModel)]="contact_dnc.phone" [ngModelOptions]="{standalone: true}" type="phone" id="phone" class="form-control" nbInput fullWidth pattern="[0-9]*" minlength="11" maxlength="16" #phone="ngModel" required/>
2828
<div
2929
[hidden]="phone.valid || phone.pristine" class="alert alert-danger">
3030
<div [hidden]="!phone.hasError('required')"> {{ 'contact_dnc.required_error' | translate}}
@@ -36,7 +36,7 @@ <h1>{{ 'contact_dnc.add' | translate}}</h1>
3636
<div class="col-sm-6">
3737
<div class="form-group">
3838
<label for="email"> {{ 'contact_dnc.email' | translate}}:</label>
39-
<input [(ngModel)]="contact_dnc.email" [ngModelOptions]="{ standalone: true }" type="email" id="email" placeholder="" class="form-control" email pattern="[a-zA-Z0-9.-_]{1,}@[a-zA-Z.-]{2,}[.]{1}[a-zA-Z]{2,}" #email="ngModel" required />
39+
<input [(ngModel)]="contact_dnc.email" [ngModelOptions]="{ standalone: true }" type="email" id="email" placeholder="" class="form-control" nbInput fullWidth email pattern="[a-zA-Z0-9.-_]{1,}@[a-zA-Z.-]{2,}[.]{1}[a-zA-Z]{2,}" #email="ngModel" required />
4040
</div>
4141
<div class="md-errors-spacer" [hidden]="email.valid || email.untouched" class="alert alert-danger" >
4242
<div *ngIf="email.errors && email.errors.pattern"> {{ 'contact_dnc.invalid_email' | translate}} </div>
@@ -52,7 +52,7 @@ <h1>{{ 'contact_dnc.add' | translate}}</h1>
5252
<div class="col-sm-12">
5353
<div class="form-group">
5454
<label for="address">{{ 'contact_dnc.address' | translate}}:</label>
55-
<textarea [(ngModel)]="contact_dnc.address" [ngModelOptions]="{standalone: true}" type="text" id="address" placeholder="{{ 'contact_dnc.address' | translate}}" class="form-control" required ></textarea>
55+
<textarea [(ngModel)]="contact_dnc.address" [ngModelOptions]="{standalone: true}" type="text" id="address" placeholder="{{ 'contact_dnc.address' | translate}}" class="form-control" nbInput fullWidth required ></textarea>
5656
</div>
5757
</div>
5858
</nb-card-body>
@@ -63,19 +63,19 @@ <h1>{{ 'contact_dnc.add' | translate}}</h1>
6363
<div class="col-sm-6">
6464
<div class="form-group">
6565
<label for="custom1">{{ 'contact_dnc.custom_1' | translate}}:</label>
66-
<input [(ngModel)]="contact_dnc.custom1" [ngModelOptions]="{standalone: true}" type="text" id="custom1" class="form-control" required />
66+
<input [(ngModel)]="contact_dnc.custom1" [ngModelOptions]="{standalone: true}" type="text" id="custom1" class="form-control" nbInput fullWidth required />
6767
</div>
6868
</div>
6969
<div class="col-sm-6">
7070
<div class="form-group">
7171
<label for="custom2">{{ 'contact_dnc.custom_2' | translate}}:</label>
72-
<input [(ngModel)]="contact_dnc.custom2" [ngModelOptions]="{standalone: true}" type="text" id="custom2" class="form-control" required/>
72+
<input [(ngModel)]="contact_dnc.custom2" [ngModelOptions]="{standalone: true}" type="text" id="custom2" class="form-control" nbInput fullWidth required/>
7373
</div>
7474
</div>
7575
<div class="col-sm-6">
7676
<div class="form-group">
7777
<label for="custom3">{{ 'contact_dnc.custom_3' | translate}}:</label>
78-
<input [(ngModel)]="contact_dnc.custom3" [ngModelOptions]="{standalone: true}" type="text" id="custom3" class="form-control" required/>
78+
<input [(ngModel)]="contact_dnc.custom3" [ngModelOptions]="{standalone: true}" type="text" id="custom3" class="form-control" nbInput fullWidth required/>
7979
</div>
8080
</div>
8181
</nb-card-body>
@@ -87,7 +87,7 @@ <h1>{{ 'contact_dnc.add' | translate}}</h1>
8787
<div class="col-sm-6">
8888
<div class="form-group">
8989
<label for="description">{{ 'contact_dnc.description' | translate}}:</label>
90-
<input [(ngModel)]="this.contact_dnc.description" [ngModelOptions]="{standalone: true}" type="text" class="form-control" id="description" required />
90+
<input [(ngModel)]="this.contact_dnc.description" [ngModelOptions]="{standalone: true}" type="text" class="form-control" nbInput fullWidth id="description" required />
9191
</div>
9292
</div>
9393
</nb-card-body>

src/app/pages/contact_dnc/contact_dnc.module.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { RouterModule } from '@angular/router';
4-
import { NbCardModule } from '@nebular/theme';
4+
import { NbButtonModule, NbCardModule, NbInputModule, NbOptionModule, NbSelectModule, NbTreeGridModule } from '@nebular/theme';
55
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
66
import { MatTableModule } from '@angular/material/table';
77
import { MatIconModule } from '@angular/material/icon';
@@ -34,7 +34,12 @@ import { MatDialogModule } from '@angular/material/dialog';
3434
FileUploadModule,
3535
TranslateModule,
3636
MatCardModule,
37-
MatDialogModule
37+
MatDialogModule,
38+
NbInputModule,
39+
NbTreeGridModule,
40+
NbSelectModule,
41+
NbOptionModule,
42+
NbButtonModule,
3843
],
3944
exports: [
4045

src/app/pages/pages-routing.module.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ const routes: Routes = [{
2626
path: 'Changepass',
2727
component: ChangePasswordComponent
2828
},
29-
{
29+
// {
3030

31-
path: 'faxsettings',
32-
component: FaxSettingsComponent,
33-
},
31+
// path: 'faxsettings',
32+
// component: FaxSettingsComponent,
33+
// },
3434
{
3535
path: 'cid',
3636
component: CIDComponent,

0 commit comments

Comments
 (0)