Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(orb-ui) #685 All list pages, header checkbox #2419

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ui/src/app/common/services/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ export class FilterService {
const filterDef = filterOptions.find(
(_item) => _item.name === _filter.name,
);
const {filter: filterFn, prop, exact} = filterDef;
const result =
if (filterDef) {
const {filter: filterFn, prop, exact} = filterDef;
const result =
!!filterFn && filterFn(value, prop, paramValue, exact);
return result;
return result;
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,8 @@ <h4>All Policies</h4>
<ng-template #checkboxTemplateCell let-i="index" let-row="row" let-value="value">
<input type="checkbox" [checked]="getChecked(row)"
(change)="onCheckboxChange($event, row)">
</ng-template>
</ng-template>

<ng-template #checkboxTemplateHeader>
<input type="checkbox" (change)="onHeaderCheckboxChange($event)">
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { NotificationsService } from 'app/common/services/notifications/notifica
import { OrbService } from 'app/common/services/orb.service';
import { AgentPolicyDeleteComponent } from 'app/pages/datasets/policies.agent/delete/agent.policy.delete.component';
import { DeleteSelectedComponent } from 'app/shared/components/delete/delete.selected.component';
import { combineLatest, Observable } from 'rxjs';
import { combineLatest, Observable, Subscription } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { STRINGS } from '../../../../../assets/text/strings';

Expand All @@ -50,6 +50,8 @@ export class AgentPolicyListComponent

selected: any[] = [];

private policiesSubscription: Subscription;

@ViewChild('nameTemplateCell') nameTemplateCell: TemplateRef<any>;

@ViewChild('versionTemplateCell') versionTemplateCell: TemplateRef<any>;
Expand All @@ -60,6 +62,8 @@ export class AgentPolicyListComponent

@ViewChild('checkboxTemplateCell') checkboxTemplateCell: TemplateRef<any>;

@ViewChild('checkboxTemplateHeader') checkboxTemplateHeader: TemplateRef<any>;

tableSorts = [
{
prop: 'name',
Expand Down Expand Up @@ -92,7 +96,7 @@ export class AgentPolicyListComponent
private filters: FilterService,
) {
this.filters$ = this.filters.getFilters();

this.selected = [];
this.policies$ = combineLatest([
this.orb.getPolicyListView(),
this.orb.getDatasetListView()
Expand Down Expand Up @@ -165,6 +169,9 @@ export class AgentPolicyListComponent
}

ngOnDestroy(): void {
if (this.policiesSubscription) {
this.policiesSubscription.unsubscribe();
}
this.orb.killPolling.next();
}

Expand Down Expand Up @@ -193,6 +200,7 @@ export class AgentPolicyListComponent
canAutoResize: true,
sortable: false,
cellTemplate: this.checkboxTemplateCell,
headerTemplate: this.checkboxTemplateHeader,
},
{
prop: 'name',
Expand Down Expand Up @@ -349,12 +357,31 @@ export class AgentPolicyListComponent
}
}
}
console.log(this.selected);
}

public getChecked(row: any): boolean {
const item = this.selected.filter((e) => e.id === row.id);
return item.length > 0 ? true : false;
}
}

onHeaderCheckboxChange(event: any) {
if (event.target.checked && this.filteredPolicies$) {
this.policiesSubscription = this.filteredPolicies$.subscribe(rows => {
this.selected = [];
rows.forEach(row => {
const policySelected = {
id: row.id,
name: row.name,
usage: row.policy_usage,
}
this.selected.push(policySelected);
});
});
} else {
if (this.policiesSubscription) {
this.policiesSubscription.unsubscribe();
}
this.selected = [];
}
}
}
6 changes: 5 additions & 1 deletion ui/src/app/pages/fleet/agents/list/agent.list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ <h4>All Agents</h4>
(change)="onCheckboxChange($event, row)">
</ng-template>

<ng-template #checkboxTemplateHeader>
<input type="checkbox" (change)="onHeaderCheckboxChange($event)">
</ng-template>

<ng-template
#agentVersionTemplateCell
let-i="index"
Expand All @@ -179,4 +183,4 @@ <h4>All Agents</h4>
>
<span [nbTooltip]="value">
{{ value }}</span>
</ng-template>
</ng-template>
37 changes: 35 additions & 2 deletions ui/src/app/pages/fleet/agents/list/agent.list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { AgentDeleteComponent } from 'app/pages/fleet/agents/delete/agent.delete
import { AgentDetailsComponent } from 'app/pages/fleet/agents/details/agent.details.component';
import { DeleteSelectedComponent } from 'app/shared/components/delete/delete.selected.component';
import { STRINGS } from 'assets/text/strings';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import { AgentResetComponent } from '../reset/agent.reset.component';

Expand All @@ -53,6 +53,9 @@ export class AgentListComponent implements AfterViewInit, AfterViewChecked, OnDe
canResetAgents: boolean;

isResetting: boolean;

private agentsSubscription: Subscription;


// templates
@ViewChild('agentNameTemplateCell') agentNameTemplateCell: TemplateRef<any>;
Expand All @@ -72,6 +75,8 @@ export class AgentListComponent implements AfterViewInit, AfterViewChecked, OnDe

@ViewChild('agentVersionTemplateCell') agentVersionTemplateCell: TemplateRef<any>;

@ViewChild('checkboxTemplateHeader') checkboxTemplateHeader: TemplateRef<any>;

tableSorts = [
{
prop: 'name',
Expand Down Expand Up @@ -161,6 +166,9 @@ export class AgentListComponent implements AfterViewInit, AfterViewChecked, OnDe
}

ngOnDestroy() {
if (this.agentsSubscription) {
this.agentsSubscription.unsubscribe();
}
this.orb.killPolling.next();
}

Expand Down Expand Up @@ -188,6 +196,7 @@ export class AgentListComponent implements AfterViewInit, AfterViewChecked, OnDe
canAutoResize: true,
sortable: false,
cellTemplate: this.checkboxTemplateCell,
headerTemplate: this.checkboxTemplateHeader,
},
{
prop: 'name',
Expand Down Expand Up @@ -283,7 +292,6 @@ export class AgentListComponent implements AfterViewInit, AfterViewChecked, OnDe
}
const reset = this.selected.filter((e) => e.resetable === false);
this.canResetAgents = reset.length > 0 ? true : false;
console.log(this.selected);
}


Expand Down Expand Up @@ -382,6 +390,31 @@ export class AgentListComponent implements AfterViewInit, AfterViewChecked, OnDe
this.isResetting = false;
}
}

onHeaderCheckboxChange(event: any) {
if (event.target.checked && this.filteredAgents$) {
this.agentsSubscription = this.filteredAgents$.subscribe(rows => {
this.selected = [];
rows.forEach(row => {
const policySelected = {
id: row.id,
name: row.name,
state: row.state,
resetable: row.state === 'new' || row.state === 'offline' ? false : true,
}
this.selected.push(policySelected);
});
});
} else {
if (this.agentsSubscription) {
this.agentsSubscription.unsubscribe();
}
this.selected = [];
}
const reset = this.selected.filter((e) => e.resetable === false);
this.canResetAgents = reset.length > 0 ? true : false;
}

openDetailsModal(row: any) {
this.dialogService
.open(AgentDetailsComponent, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ export class AgentGroupAddComponent
const payload = this.wrapPayload(false);

// // remove line bellow
// console.log(payload)
if (this.isEdit) {
this.agentGroupsService
.editAgentGroup({ ...payload, id: this.agentGroupID })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,8 @@ <h4>{{ strings.list.header }}</h4>
<ng-template #checkboxTemplateCell let-i="index" let-row="row" let-value="value">
<input type="checkbox" [checked]="getChecked(row)"
(change)="onCheckboxChange($event, row)">
</ng-template>
</ng-template>

<ng-template #checkboxTemplateHeader>
<input type="checkbox" (change)="onHeaderCheckboxChange($event)">
</ng-template>
31 changes: 29 additions & 2 deletions ui/src/app/pages/fleet/groups/list/agent.group.list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { AgentGroupDeleteComponent } from 'app/pages/fleet/groups/delete/agent.g
import { AgentGroupDetailsComponent } from 'app/pages/fleet/groups/details/agent.group.details.component';
import { DeleteSelectedComponent } from 'app/shared/components/delete/delete.selected.component';
import { STRINGS } from 'assets/text/strings';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';

@Component({
selector: 'ngx-agent-group-list-component',
Expand All @@ -52,6 +52,8 @@ export class AgentGroupListComponent

selected: any[] = [];

private groupsSubscription: Subscription;

// templates
@ViewChild('agentGroupNameTemplateCell')
agentGroupNameTemplateCell: TemplateRef<any>;
Expand All @@ -66,6 +68,8 @@ export class AgentGroupListComponent

@ViewChild('checkboxTemplateCell') checkboxTemplateCell: TemplateRef<any>;

@ViewChild('checkboxTemplateHeader') checkboxTemplateHeader: TemplateRef<any>;

filterValue = null;

tableSorts = [
Expand Down Expand Up @@ -139,6 +143,9 @@ export class AgentGroupListComponent
}

ngOnDestroy(): void {
if (this.groupsSubscription) {
this.groupsSubscription.unsubscribe();
}
this.orb.killPolling.next();
}

Expand Down Expand Up @@ -166,6 +173,7 @@ export class AgentGroupListComponent
canAutoResize: true,
sortable: false,
cellTemplate: this.checkboxTemplateCell,
headerTemplate: this.checkboxTemplateHeader,
},
{
prop: 'name',
Expand Down Expand Up @@ -317,11 +325,30 @@ export class AgentGroupListComponent
}
}
}
console.log(this.selected);
}

public getChecked(row: any): boolean {
const item = this.selected.filter((e) => e.id === row.id);
return item.length > 0 ? true : false;
}

onHeaderCheckboxChange(event: any) {
if (event.target.checked && this.filteredGroups$) {
this.groupsSubscription = this.filteredGroups$.subscribe(rows => {
this.selected = [];
rows.forEach(row => {
const policySelected = {
id: row.id,
name: row.name,
}
this.selected.push(policySelected);
});
});
} else {
if (this.groupsSubscription) {
this.groupsSubscription.unsubscribe();
}
this.selected = [];
}
}
}
4 changes: 4 additions & 0 deletions ui/src/app/pages/sinks/list/sink.list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,7 @@ <h4>{{ strings.list.header }}</h4>
<input type="checkbox" [checked]="getChecked(row)"
(change)="onCheckboxChange($event, row)">
</ng-template>

<ng-template #checkboxTemplateHeader>
<input type="checkbox" (change)="onHeaderCheckboxChange($event)">
</ng-template>
31 changes: 29 additions & 2 deletions ui/src/app/pages/sinks/list/sink.list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { SinksService } from 'app/common/services/sinks/sinks.service';
import { SinkDeleteComponent } from 'app/pages/sinks/delete/sink.delete.component';
import { SinkDetailsComponent } from 'app/pages/sinks/details/sink.details.component';
import { STRINGS } from 'assets/text/strings';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { DeleteSelectedComponent } from 'app/shared/components/delete/delete.selected.component';

@Component({
Expand All @@ -52,6 +52,8 @@ export class SinkListComponent implements AfterViewInit, AfterViewChecked, OnDes

selected: any[] = [];

private sinksSubscription: Subscription;

// templates
@ViewChild('sinkNameTemplateCell') sinkNameTemplateCell: TemplateRef<any>;

Expand All @@ -63,6 +65,8 @@ export class SinkListComponent implements AfterViewInit, AfterViewChecked, OnDes

@ViewChild('checkboxTemplateCell') checkboxTemplateCell: TemplateRef<any>;

@ViewChild('checkboxTemplateHeader') checkboxTemplateHeader: TemplateRef<any>;

tableSorts = [
{
prop: 'name',
Expand Down Expand Up @@ -139,6 +143,9 @@ export class SinkListComponent implements AfterViewInit, AfterViewChecked, OnDes
}

ngOnDestroy(): void {
if (this.sinksSubscription) {
this.sinksSubscription.unsubscribe();
}
this.orb.killPolling.next();
}

Expand Down Expand Up @@ -166,6 +173,7 @@ export class SinkListComponent implements AfterViewInit, AfterViewChecked, OnDes
canAutoResize: true,
sortable: false,
cellTemplate: this.checkboxTemplateCell,
headerTemplate: this.checkboxTemplateHeader,
},
{
prop: 'name',
Expand Down Expand Up @@ -318,11 +326,30 @@ export class SinkListComponent implements AfterViewInit, AfterViewChecked, OnDes
}
}
}
console.log(this.selected);
}

public getChecked(row: any): boolean {
const item = this.selected.filter((e) => e.id === row.id);
return item.length > 0 ? true : false;
}
onHeaderCheckboxChange(event: any) {
if (event.target.checked && this.filteredSinks$) {
this.sinksSubscription = this.filteredSinks$.subscribe(rows => {
this.selected = [];
rows.forEach(row => {
const sinkSelected = {
id: row.id,
name: row.name,
state: row.state,
}
this.selected.push(sinkSelected);
});
});
} else {
if (this.sinksSubscription) {
this.sinksSubscription.unsubscribe();
}
this.selected = [];
}
}
}
Loading