Skip to content

Commit

Permalink
Merge pull request primefaces#307 from atretyak1985/issue_#301
Browse files Browse the repository at this point in the history
Improve agent upgrade
  • Loading branch information
Alfred Hall authored Nov 8, 2019
2 parents 27f5486 + d8c92d6 commit 2c6fbaf
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 144 deletions.
4 changes: 2 additions & 2 deletions src/assets/less/forms.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
border-color: #e4e3e2;
}

#export-csv-modal .ui-dropdown.ui-widget {
#export-csv-modal, #export-upgrade-modal .ui-dropdown.ui-widget {
height: 20px;
margin: 0 0 0 10px;
width: auto;
}

#export-csv-modal .ui-dropdown.ui-widget .ui-inputtext {
#export-csv-modal, #export-upgrade-modal .ui-dropdown.ui-widget .ui-inputtext {
height: auto;
width: auto;
font-size: inherit;
Expand Down
2 changes: 1 addition & 1 deletion src/common/list/base-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { BreadcrumbService } from 'common/breadcrumb/breadcrumb.service';
export abstract class BaseList implements OnInit {
@ViewChild(TextFilterComponent, { static: true }) textFilter: TextFilterComponent;
@ViewChild('ptable', { static: false }) ptable: Table;
@ViewChild('selectAllCheckbox', { static: true }) selectAllCheckbox: ElementRef;
@ViewChild('selectAllCheckbox', { static: false }) selectAllCheckbox: ElementRef;
public selectedItems: Array<any>;
public HEADER_HEIGHT: number;
public FILTER_WIDTH: number;
Expand Down
4 changes: 2 additions & 2 deletions src/organization/collector/collector_detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ColumnWithSort } from 'common/object';
})

export class CollectorDetailComponent implements OnInit {
@ViewChild('headerInfo', { static: true }) set content(content: ElementRef) { this.headerInfoEl = content; }
@ViewChild('headerInfo', { static: false }) set content(content: ElementRef) { this.headerInfoEl = content; }

private headerInfoEl: ElementRef;
private window = window;
Expand Down Expand Up @@ -102,7 +102,7 @@ export class CollectorDetailComponent implements OnInit {
return this.service.accountService.navigateOrganization(subPath);
}

onResize($event) {
onResize(event) {
this.listHeight = this.getListHeight();
}

Expand Down
13 changes: 0 additions & 13 deletions src/organization/device/base/base_device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@ export class BaseDevice extends BaseList implements OnInit, AfterViewInit {
return item.upgrade_status == DeviceUpgradeStatus.StatusWaiting || item.upgrade_status == DeviceUpgradeStatus.StatusRequested;
}

isUpgradable(item: DeviceListItem) {
if (item.agent_version < '1.7.0') {
return false;
}
if (item.agent_version >= item.latest_agent_version) {
return false;
}
if (this.upgradeWaiting(item)) {
return false;
}
return true;
}

isAgentUpToDate(item: DeviceListItem) {
if (item.agent_version >= item.latest_agent_version) {
return true;
Expand Down
10 changes: 8 additions & 2 deletions src/organization/device/device.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ export class DeviceService extends BaseListService {
return this.accountService.executePost(`/organization/${this.accountService.getOrganizationId()}/device/${deviceId}/update`, data);
}

upgradeDevices(deviceIds: any) {
return this.accountService.executePost(`/organization/${this.accountService.getOrganizationId()}/device/request_upgrade`, deviceIds);
upgradeDevices(ids: Array<number>, limit: number) {
let data = {
selected_ids: ids,
filters: this.getFilters(),
sort: this.listSorting,
limit: limit
};
return this.accountService.executePost(`/organization/${this.accountService.getOrganizationId()}/device/request_upgrade`, data);
}

updateLabels(deviceIds: number[], updateLabelItems: any[]) {
Expand Down
62 changes: 21 additions & 41 deletions src/organization/device/device_list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@
<div class="panel-heading">
<h1 class="panel-title">
Devices
<button class="btn btn-sm btn-primary pull-right" (click)="refresh()" id="refresh-button" title="Refresh"><i class="fa fa-refresh"></i></button>
<button class="btn btn-sm btn-primary pull-right" (click)="chooseExportCSVParams()" id="export-button" title="Export as CSV"><i class="fa fa-upload"></i></button>
<button class="btn btn-sm btn-primary pull-right" (click)="clickOpenColumnsDialog()" id="columns-dialog-button" title="Customize Columns"><i class="fa fa-window-maximize" aria-hidden="true"></i></button>
<button class="btn btn-sm btn-primary pull-right" [class.nanitor-disable]="upgradableItemsSelected.length < 1" (click)="clickUpgrade($event)" title="Upgrade"><i class="fa fa-arrow-up"></i></button>
<button class="btn btn-sm btn-primary pull-right" *ngIf="isCurrentOrgAdmin()" [class.nanitor-disable]="selectedItems.length < 1" (click)="clickApplyLabel()" id="apply-label-button" title="Apply label"><i class="fa fa-tag"></i></button>
<button class="btn btn-sm btn-primary pull-right" (click)="refresh()" id="refresh-button" title="Refresh">
<i class="fa fa-refresh"></i>
</button>
<button class="btn btn-sm btn-primary pull-right" (click)="chooseLimitParams()" id="export-button" title="Export as CSV">
<i class="fa fa-upload"></i>
</button>
<button class="btn btn-sm btn-primary pull-right" (click)="clickOpenColumnsDialog()" id="columns-dialog-button" title="Customize Columns">
<i class="fa fa-window-maximize" aria-hidden="true"></i>
</button>
<button class="btn btn-sm btn-primary pull-right" (click)="chooseLimitParams(true)" id="upgrade-button" title="Upgrade">
<i class="fa fa-arrow-up"></i>
</button>
<button class="btn btn-sm btn-primary pull-right" *ngIf="isCurrentOrgAdmin()" [class.nanitor-disable]="selectedItems.length < 1" (click)="clickApplyLabel()" id="apply-label-button" title="Apply label">
<i class="fa fa-tag"></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>
Expand Down Expand Up @@ -131,34 +141,6 @@ <h1 class="panel-title">
</div>

<!-- Modals -->
<div id="upgrade-confirm" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h2 *ngIf="upgradableItemsSelected.length > 1" >Upgrade {{ upgradableItemsSelected.length }} devices?</h2>
<h2 *ngIf="upgradableItemsSelected.length == 1" >Upgrade {{ upgradableItemsSelected.length }} device?</h2>
</div>

<div class="modal-body" style="padding:40px;">
<h4 *ngIf="upgradableItemsSelected.length > 1" >Are you sure you want to upgrade these devices?</h4>
<h4 *ngIf="upgradableItemsSelected.length == 1" >Are you sure you want to upgrade this device?</h4>
</div>

<div class="modal-device-list">
<table>
<tr *ngFor="let item of upgradableItemsSelected">
<p>{{item.hostname}}</p>
</tr>
</table>
</div>

<div class="modal-footer">
<a href="#" data-dismiss="modal" class="btn btn-default btn-lg">No</a>
<a href="#" (click)="clickUpgradeConfirm($event)" class="btn btn-lg btn-success btn-delete-confirm">Yes</a>
</div>
</div>
</div>
</div>

<div id="apply-label" class="modal fade">
<div class="modal-dialog">
Expand All @@ -167,7 +149,6 @@ <h4 *ngIf="upgradableItemsSelected.length == 1" >Are you sure you want to upgrad
<h2>Labels</h2>
<label style="color: white">{{ selectedItems.length }} selected devices</label>
</div>

<div class="modal-body" style="padding:40px;">
<form role="form" [formGroup]="labelApplyForm">
<div class="list">
Expand All @@ -178,7 +159,6 @@ <h2>Labels</h2>
</div>
</form>
</div>

<div class="modal-footer">
<button href="#" data-dismiss="modal" class="btn btn-default btn-lg">Cancel</button>
<button href="#" (click)="clickApplyLabelConfirm()" [disabled]="disableApplyConfirmButton()" class="btn btn-lg btn-success btn-delete-confirm">Confirm</button>
Expand All @@ -195,7 +175,6 @@ <h2>Labels</h2>
<div class="modal-header">
<h2 class="modal-title">Customize Columns</h2>
</div>

<div class="modal-body" style="padding:40px 0; background-color: #ffffff">
<div style="display: inline-block; text-align: left;" (cdkDropListDropped)="drop($event)" cdkDropList>
<ng-container *ngFor="let col of customizedColumns">
Expand All @@ -208,7 +187,6 @@ <h2 class="modal-title">Customize Columns</h2>
</ng-container>
</div>
</div>

<div class="modal-footer">
<button type="button" href="#" data-dismiss="modal" class="btn btn-default btn-lg btn-lg-width">Cancel</button>
<button type="button" class="btn btn-lg btn-success btn-lg-width" (click)="saveDisabledColumns()">Save</button>
Expand All @@ -217,25 +195,27 @@ <h2 class="modal-title">Customize Columns</h2>
</div>
</div>

<div id="export-csv-modal" class="modal fade" role="dialog" tabindex="-1">
<div id="export-upgrade-modal" class="modal fade" role="dialog" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title">Export device list</h2>
<h2 *ngIf="!isUpgrade" class="modal-title">Export device list</h2>
<h2 *ngIf="isUpgrade" class="modal-title">Upgrade device</h2>
</div>
<div class="modal-body" style="padding:40px 0; background-color: #ffffff">
<div style="display: inline-block; text-align: left;">
<ng-container>
<div class="customize-column-item">
<label for="limit" style="margin-left: 0;">Limit</label>
<p-dropdown [options]="exportLimitOptions" [(ngModel)]="itemExportForm.limit"></p-dropdown>
<p-dropdown [options]="exportLimitOptions" [(ngModel)]="itemExportForm.limit"></p-dropdown>
</div>
</ng-container>
</div>
</div>
<div class="modal-footer">
<button type="button" href="#" data-dismiss="modal" class="btn btn-default btn-lg btn-lg-width">Cancel</button>
<button type="button" class="btn btn-lg btn-success btn-lg-width" (click)="exportCSV()">Export CSV</button>
<button *ngIf="!isUpgrade" type="button" class="btn btn-lg btn-success btn-lg-width" (click)="exportCSV()">Export CSV</button>
<button *ngIf="isUpgrade" type="button" class="btn btn-lg btn-success btn-lg-width" (click)="clickUpgradeConfirm()">Upgrade Devices</button>
</div>
</div>
</div>
Expand Down
93 changes: 18 additions & 75 deletions src/organization/device/device_list.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, ChangeDetectorRef, ViewChild, Injector } from '@angular/core';
import { Component, ChangeDetectorRef, ViewChild, Injector } from '@angular/core';
import { Location } from '@angular/common';
import { Router, ActivatedRoute } from '@angular/router';
import { CustomReuseStrategyService } from '../../custom-reuse-strategy.service';
Expand Down Expand Up @@ -26,17 +26,23 @@ import * as FileSaver from 'file-saver';
}
})

export class DeviceListComponent extends BaseDevice implements OnInit {
export class DeviceListComponent extends BaseDevice {
@ViewChild(LabelCreateDialogComponent, { static: true }) labelCreateDialog: LabelCreateDialogComponent;
private disabledColumns: Object;
public upgradableItemsSelected: Array<any>;
public labelApplyForm: FormGroup;
private initialLabelStates: ApplyLabelListItem[];
public labels: ApplyLabelListItem[];
public vulnerabilityEnabled: boolean;
public customizedColumns: Array<ColumnWithSort>;
public itemExportForm: RequestExportForm;
public exportLimitOptions: any;
public exportLimitOptions: any = [
{ label: '50', value: 50 },
{ label: '200', value: 200 },
{ label: '1000', value: 1000 },
{ label: '5000', value: 5000 },
{ label: '10000', value: 10000 }
];
public isUpgrade: boolean = false;

constructor(
service: DeviceService,
Expand All @@ -57,11 +63,8 @@ export class DeviceListComponent extends BaseDevice implements OnInit {
this.FILTER_WIDTH = 300;
this.LIST_BASE_PADDING = 120;
this.disabledColumns = {};
this.upgradableItemsSelected = [];
this.labelApplyForm = new FormGroup({});
this.vulnerabilityEnabled = false;
this.response = null;
this.items = [];
this.itemExportForm = {} as RequestExportForm;
}

Expand Down Expand Up @@ -100,14 +103,6 @@ export class DeviceListComponent extends BaseDevice implements OnInit {
this.service.setDeviceColumns(this.cols);
}

this.exportLimitOptions = [
{ label: '50', value: 50 },
{ label: '200', value: 200 },
{ label: '1000', value: 1000 },
{ label: '5000', value: 5000 },
{ label: '10000', value: 10000 }
];

this.vulnerabilityEnabled = this.service.accountService.isVulnerabilityEnabled(this.service.accountService.getCurrentOrganization());
const disabledColumns = this.service.getDisabledColumns();
this.disabledColumns = this.mergeDisabledColumns(disabledColumns, defaultDisabledColumns);
Expand Down Expand Up @@ -195,21 +190,12 @@ export class DeviceListComponent extends BaseDevice implements OnInit {
this.labelCreateDialog.show();
}

clickUpgrade(event) {
event.preventDefault();
jQuery('#upgrade-confirm').modal('show');
}

clickUpgradeConfirm(event) {
event.preventDefault();
let payload = {};
payload['device_ids'] = [];

this.upgradableItemsSelected.forEach((item) => {
payload['device_ids'].push(item.id);
clickUpgradeConfirm() {
const selectedItemIds = this.selectedItems.map((item) => {
return item.id;
});

this.service.upgradeDevices(payload).subscribe(
this.service.upgradeDevices(selectedItemIds, this.itemExportForm.limit).subscribe(
(data: any) => {
let obj: BasicResponse = data;
this.flashService.addItemFromStatus(data.status, obj.message);
Expand All @@ -219,10 +205,7 @@ export class DeviceListComponent extends BaseDevice implements OnInit {
this.accountService.handleError(err);
}
);

this.upgradableItemsSelected = [];
this.selectedItems = [];
jQuery('#upgrade-confirm').modal('hide');
jQuery('#export-upgrade-modal').modal('hide');
}

countDevicesInLabel(label: ApplyLabelListItem) {
Expand Down Expand Up @@ -287,11 +270,12 @@ export class DeviceListComponent extends BaseDevice implements OnInit {
return labels;
}

chooseExportCSVParams() {
chooseLimitParams(isUpgrade: boolean = false) {
this.isUpgrade = isUpgrade;
this.itemExportForm = {
limit: 200
} as RequestExportForm;
jQuery('#export-csv-modal').modal('show');
jQuery('#export-upgrade-modal').modal('show');
}

exportCSV() {
Expand All @@ -317,47 +301,6 @@ export class DeviceListComponent extends BaseDevice implements OnInit {
this.labelApplyForm.controls[label.name].setValue(null);
}
}

markItemSelected(event, item: any) {
if (event.target.checked) {
this.selectedItems.push(item);
if (this.isUpgradable(item)) {
this.upgradableItemsSelected.push(item);
}

if (this.isAllselectedItems()) {
this.selectAllCheckbox.nativeElement.checked = true;
}
}
else {
let index = this.selectedItems.findIndex(e => e.id === item.id);
this.selectedItems.splice(index, 1);
index = this.upgradableItemsSelected.findIndex(e => e.id === item.id);
this.upgradableItemsSelected.splice(index, 1);
this.selectAllCheckbox.nativeElement.checked = false;
}
}

markAllItemsSelected(event) {
if (event.target.checked) {
let allItems = this.service.pagesToArray(1, Math.ceil(this.totalRecords / this.ROWS));
this.selectedItems = [];
if (allItems) {
for (let item of allItems) {
if (!item.archived) {
this.selectedItems.push(item);
if (this.isUpgradable(item)) {
this.upgradableItemsSelected.push(item);
}
}
}
}
} else {
this.selectedItems = [];
this.upgradableItemsSelected = [];
}
}

}

interface ApplyLabelListItem extends LabelListItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { GroupPolicyItem } from './group_policy_response';
})

export class GroupPolicyDetailComponent extends BaseList implements OnInit, AfterViewInit {
@ViewChild('headerInfo', { static: true }) headerInfoEl: ElementRef;
@ViewChild('headerInfo', { static: false }) headerInfoEl: ElementRef;

private groupPolicyId: string;
public listHeight: string;
Expand Down Expand Up @@ -94,7 +94,6 @@ export class GroupPolicyDetailComponent extends BaseList implements OnInit, Afte
}

onResize(event) {
super.onResize(event);
this.listHeight = this.getListHeight();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Breadcrumb } from '../../common/breadcrumb/breadcrumb.model';
})

export class LoggedInUserDetailComponent extends BaseList implements OnInit, AfterViewInit {
@ViewChild('headerInfo', { static: true }) headerInfoEl: ElementRef;
@ViewChild('headerInfo', { static: false }) headerInfoEl: ElementRef;

private loggedInUserId: string;
public listHeight: string;
Expand Down
Loading

0 comments on commit 2c6fbaf

Please sign in to comment.