forked from primefaces/primeng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incidents list and detail pages need an overhaul primefaces#158
- Loading branch information
1 parent
44f176d
commit 4d3f553
Showing
6 changed files
with
194 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<org-navigator [mainNavbarEnabled]="false"></org-navigator> | ||
|
||
<div class="flex-container"> | ||
<side-filter #filterPanel (onFilterChange)="updateProfileFilters($event)"> | ||
<context-filter-section #section (clearSectionEvent)="clearContextFilter($event)"> | ||
<text-filter (filterChanged)="filterChanged($event)" [model]="service.userFiltersState" key="hostname" label="Search" placeholder="Hostname"></text-filter> | ||
</context-filter-section> | ||
<os-filter-section #section></os-filter-section> | ||
<label-filter-section #section></label-filter-section> | ||
</side-filter> | ||
|
||
<div class="container-fluid" [class.nanitor-fade-in]="response" [class.nanitor-hide]="!response"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<h1 class="panel-title"> | ||
Incident devices | ||
<button class="btn btn-sm btn-primary pull-right" (click)="refresh()" id="refresh-button" title="Refresh"><i class="fa fa-refresh"></i></button> | ||
<span class="label label-black pull-right m-r-15" style="color:white; width: auto;" *ngIf="response">Total: {{ response.total }}</span> | ||
</h1> | ||
</div> | ||
<div class="panel-body"> | ||
<div class="no-data" *ngIf="emptyResponse"> | ||
<p>There is currently nothing to display.</p> | ||
</div> | ||
<div> | ||
<p-table #ptable class="p-table" [columns]="cols" [value]="items" [paginator]="true" | ||
[rows]="ROWS" [totalRecords]="totalRecords" scrollable="true" [scrollHeight]="window.innerHeight - HEADER_HEIGHT + 'px'" [customSort]="true" sortMode="multiple" | ||
(onPage)="onPage($event)"> | ||
<!-- [style]="{width: window.innerWidth - (filterPanel.isCollapsed ? LIST_BASE_PADDING : LIST_BASE_PADDING + FILTER_WIDTH) + 'px'}" --> | ||
<ng-template pTemplate="colgroup" let-columns> | ||
<colgroup> | ||
<col *ngFor="let col of columns" [ngStyle]="{'width': col.width}"> | ||
</colgroup> | ||
</ng-template> | ||
<ng-template pTemplate="header" let-columns> | ||
<tr valign="top" class="defence" width="100%"> | ||
<th *ngFor="let col of columns" class="table-header-cell" [pSortableColumn]="col.field" [pSortableColumnDisabled]="col.disabled" [ngStyle]="{'width': col.width}"> | ||
<div>{{col.header}}<p-sortIcon *ngIf="!col.disabled" [field]="col.field"></p-sortIcon></div> | ||
</th> | ||
</tr> | ||
</ng-template> | ||
<ng-template pTemplate="body" let-rowData let-columns="columns"> | ||
<tr id="item-{{ rowData.id }}" class="table-row"> | ||
<td class="table-cell" [ngStyle]="{'width': getColumnWidth('created')}">{{rowData.created_at*1000 | moment:'MMM Do YYYY HH:mm'}}</td> | ||
<td class="table-cell" [ngStyle]="{'width': getColumnWidth('device')}">{{rowData.device_hostname}}</td> | ||
<td class="table-cell" [ngStyle]="{'width': getColumnWidth('profile')}">{{rowData.profile_title}}</td> | ||
</tr> | ||
</ng-template> | ||
</p-table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
115 changes: 115 additions & 0 deletions
115
src/organization/incident/incident_devices.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import {Component, OnInit, ViewChild} from '@angular/core'; | ||
import {ColumnWithSort} from '../../common/object' | ||
import { IncidentService } from './incident.service'; | ||
import { Table } from 'primeng/table'; | ||
import { SideFilterComponent } from 'common/side_filter/side-filter.component'; | ||
import { SortableTableComponent } from '../../common/sortable_table/sortable-table.component'; | ||
import { TextFilterComponent } from '../../common/filter_pane/text-filter.component'; | ||
import { IncidentDeviceListItem, IncidentItemListItem } from './incident_response'; | ||
import { BasicListRequest } from 'common/request'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
|
||
@Component({ | ||
templateUrl: 'incident_devices.component.html', | ||
providers: [IncidentService] | ||
}) | ||
|
||
export class IncidentDevicesComponent implements OnInit { | ||
@ViewChild(SortableTableComponent) table: SortableTableComponent; | ||
@ViewChild(TextFilterComponent) textFilter: TextFilterComponent; | ||
@ViewChild('ptable') ptable: Table; | ||
@ViewChild('filterPanel') filterPanel: SideFilterComponent; | ||
|
||
public HEADER_HEIGHT: number = 310; | ||
public FILTER_WIDTH: number = 300; | ||
public LIST_BASE_PADDING: number = 120; | ||
public ROWS: number = 20; | ||
public window = window; | ||
private savedScrollPos: number = 0; | ||
public emptyResponse: boolean = false; | ||
private cols: Array<ColumnWithSort>; | ||
public response: IncidentDeviceListItem; | ||
public items: Array<IncidentItemListItem>; | ||
public totalRecords: number; | ||
private itemListRequest: BasicListRequest; | ||
private incidentId: string; | ||
|
||
constructor(public service: IncidentService, private router: Router, private route: ActivatedRoute) { | ||
this.incidentId = route.snapshot.params['id']; | ||
this.itemListRequest = new BasicListRequest(); | ||
this.response = null; | ||
this.items = []; | ||
} | ||
|
||
ngOnInit() { | ||
this.cols = [ | ||
{ field: 'created', header: 'Created', order: 0, width: '160px', disabled: true }, | ||
{ field: 'device', header: 'Device', order: 0, width: '200px', disabled: true }, | ||
{ field: 'profile', header: 'Profile', order: 0, width: '120px', disabled: true } | ||
]; | ||
|
||
this.clearContextFilter(() => {}); | ||
|
||
this.service.getItemList(this.incidentId, this.itemListRequest).subscribe((data: any) => { | ||
this.response = data; | ||
this.items = this.response.items; | ||
this.totalRecords = this.response.total; | ||
|
||
console.log(this.response); | ||
}); | ||
} | ||
|
||
refresh() { | ||
let currentPage = this.ptable.first / this.ROWS + 1; | ||
this.emptyResponse = false; | ||
this.ptable.setScrollPosition(0); | ||
this.savedScrollPos = 0; | ||
this.service.reset(); | ||
jQuery('#refresh-button').blur(); | ||
} | ||
|
||
filterChanged(e) { | ||
setTimeout(() => { | ||
if (this.ptable) { | ||
this.ptable.first = 0; | ||
} | ||
this.refresh(); | ||
}); | ||
} | ||
|
||
onPage(event) { | ||
this.setFocusToList(); | ||
this.ptable.setScrollPosition(0); | ||
this.savedScrollPos = 0; | ||
} | ||
|
||
setFocusToList() { | ||
this.ptable.setFocusToList(); | ||
} | ||
|
||
getColumnWidth(field) { | ||
let fieldd = this.cols.filter(function (item) { | ||
return item.field === field; | ||
})[0]; | ||
return fieldd.width; | ||
} | ||
|
||
updateProfileFilters(event) { | ||
if (this.ptable) { | ||
this.ptable.first = 0; | ||
} | ||
this.refresh(); | ||
} | ||
|
||
clearContextFilter(callback: Function) { | ||
// Clear UI | ||
this.textFilter.clear(); | ||
this.service.profileFilters = []; | ||
|
||
|
||
if (this.ptable) { | ||
this.ptable.first = 0; | ||
} | ||
callback(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters