Skip to content

Commit

Permalink
Convert connection details checkbox to drop down
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-cox committed Apr 14, 2020
1 parent 3a6547c commit c218907
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 273 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<mat-form-field>
<mat-select [(value)]="service.state[row.guid][backupType.CONNECT]"
[disabled]="!service.state[row.guid][backupType.ENDPOINT]">
<mat-option [value]="connectionTypes.NONE">None</mat-option>
<mat-option [value]="connectionTypes.CURRENT">Current User</mat-option>
<mat-option [value]="connectionTypes.ALL">All Users</mat-option>
</mat-select>
</mat-form-field>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { BackupConnectionCellComponent } from './backup-connection-cell.component';

describe('BackupConnectionCellComponent', () => {
let component: BackupConnectionCellComponent;
let fixture: ComponentFixture<BackupConnectionCellComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BackupConnectionCellComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(BackupConnectionCellComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component } from '@angular/core';

import { EndpointModel } from '../../../../../../store/src/types/endpoint.types';
import { TableCellCustom } from '../../../../shared/components/list/list.types';
import { BackupEndpointsService } from '../backup-endpoints.service';
import { BackupEndpointConnectionTypes, BackupEndpointTypes } from '../backup-restore-endpoints.service';

@Component({
selector: 'app-backup-connection-cell',
templateUrl: './backup-connection-cell.component.html',
styleUrls: ['./backup-connection-cell.component.scss']
})
export class BackupConnectionCellComponent extends TableCellCustom<EndpointModel> {

backupType = BackupEndpointTypes;
connectionTypes = BackupEndpointConnectionTypes;
selected: BackupEndpointConnectionTypes;

constructor(public service: BackupEndpointsService) {
super();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { EndpointModel } from '../../../../../store/src/types/endpoint.types';
import { BrowserStandardEncoder } from '../../../helper';
import {
BackupEndpointConfigUI,
BackupEndpointConnectionTypes,
BackupEndpointsConfig,
BackupEndpointTypes,
BackupRestoreEndpointService,
Expand Down Expand Up @@ -51,8 +52,7 @@ export class BackupEndpointsService extends BackupRestoreEndpointService {
endpoints.forEach(entity => {
this.state[entity.guid] = {
[BackupEndpointTypes.ENDPOINT]: false,
[BackupEndpointTypes.CONNECT]: false,
[BackupEndpointTypes.ALL_CONNECT]: false,
[BackupEndpointTypes.CONNECT]: BackupEndpointConnectionTypes.NONE,
entity
};
});
Expand All @@ -63,25 +63,19 @@ export class BackupEndpointsService extends BackupRestoreEndpointService {
const endpoints = Object.values(this.state);
endpoints.forEach(endpoint => {
if (!endpoint[BackupEndpointTypes.ENDPOINT]) {
endpoint[BackupEndpointTypes.CONNECT] = false;
endpoint[BackupEndpointTypes.ALL_CONNECT] = false;
}
if (endpoint[BackupEndpointTypes.ALL_CONNECT] && this.canBackup(endpoint.entity, BackupEndpointTypes.CONNECT)) {
endpoint[BackupEndpointTypes.CONNECT] = true;
endpoint[BackupEndpointTypes.CONNECT] = BackupEndpointConnectionTypes.NONE;
}
});

const hasChanges = !!endpoints.find(endpoint =>
endpoint[BackupEndpointTypes.ENDPOINT] ||
endpoint[BackupEndpointTypes.CONNECT] ||
endpoint[BackupEndpointTypes.ALL_CONNECT]
endpoint[BackupEndpointTypes.CONNECT] !== BackupEndpointConnectionTypes.NONE
);
this.hasChanges.next(hasChanges);
const allChanged = endpoints.every(endpoint => {
const e = !this.canBackup(endpoint.entity, BackupEndpointTypes.ENDPOINT) || endpoint[BackupEndpointTypes.ENDPOINT];
const c = !this.canBackup(endpoint.entity, BackupEndpointTypes.CONNECT) || endpoint[BackupEndpointTypes.CONNECT];
const aC = !this.canBackup(endpoint.entity, BackupEndpointTypes.ALL_CONNECT) || endpoint[BackupEndpointTypes.ALL_CONNECT];
return e && c && aC;
const c = !this.canBackup(endpoint.entity, BackupEndpointTypes.CONNECT) || endpoint[BackupEndpointTypes.CONNECT] !== BackupEndpointConnectionTypes.NONE;
return e && c;
}

);
Expand All @@ -105,14 +99,6 @@ export class BackupEndpointsService extends BackupRestoreEndpointService {
return false;
}

// Are all connection details backed up anyway?
// Does the user have connection details for this endpoint?
if (type === BackupEndpointTypes.CONNECT) {
return !this.state[endpoint.guid][BackupEndpointTypes.ALL_CONNECT] &&
endpoint.connectionStatus === 'connected';
// return !this.service.state[endpoint.guid][BackupRestoreTypes.CONNECT];
}

return true;
}

Expand All @@ -122,10 +108,7 @@ export class BackupEndpointsService extends BackupRestoreEndpointService {
endpoint[BackupEndpointTypes.ENDPOINT] = true;
}
if (this.canBackup(endpoint.entity, BackupEndpointTypes.CONNECT)) {
endpoint[BackupEndpointTypes.CONNECT] = true;
}
if (this.canBackup(endpoint.entity, BackupEndpointTypes.ALL_CONNECT)) {
endpoint[BackupEndpointTypes.ALL_CONNECT] = true;
endpoint[BackupEndpointTypes.CONNECT] = BackupEndpointConnectionTypes.CURRENT;
}
});
this.validate();
Expand All @@ -134,8 +117,7 @@ export class BackupEndpointsService extends BackupRestoreEndpointService {
selectNone() {
Object.values(this.state).forEach(endpoint => {
endpoint[BackupEndpointTypes.ENDPOINT] = false;
endpoint[BackupEndpointTypes.CONNECT] = false;
endpoint[BackupEndpointTypes.ALL_CONNECT] = false;
endpoint[BackupEndpointTypes.CONNECT] = BackupEndpointConnectionTypes.NONE;
});
this.validate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ <h1>Backup Endpoints</h1>
<p>Protect the backup by providing as password. You will need this password when restoring from this backup</p>
<form [formGroup]="passwordForm" class="stepper-form">
<mat-form-field>
<input matInput formControlName="password" placeholder="Password" required type="password">
<mat-label>Password</mat-label>
<input matInput formControlName="password" required [type]="!show ? 'password' : 'text'">
<button mat-icon-button matSuffix (click)="show = !show" [attr.aria-label]="'Hide password'"
[attr.aria-pressed]="!show">
<mat-icon>{{!show ? 'visibility_off' : 'visibility'}}</mat-icon>
</button>
</mat-form-field>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { filter, first, map, tap } from 'rxjs/operators';

import { GetAllEndpoints } from '../../../../../../store/src/actions/endpoint.actions';
import { AppState } from '../../../../../../store/src/app-state';
import { entityCatalog } from '../../../../../../store/src/entity-catalog/entity-catalog.service';
import { PaginationMonitorFactory } from '../../../../../../store/src/monitors/pagination-monitor.factory';
import { getPaginationObservables } from '../../../../../../store/src/reducers/pagination-reducer/pagination-reducer.helper';
import { EndpointModel } from '../../../../../../store/src/types/endpoint.types';
Expand All @@ -15,6 +16,7 @@ import { ConfirmationDialogService } from '../../../../shared/components/confirm
import { ITableListDataSource } from '../../../../shared/components/list/data-sources-controllers/list-data-source-types';
import { ITableColumn } from '../../../../shared/components/list/list-table/table.types';
import { StepOnNextFunction, StepOnNextResult } from '../../../../shared/components/stepper/step/step.component';
import { BackupConnectionCellComponent } from '../backup-connection-cell/backup-connection-cell.component';
import { BackupEndpointsService } from '../backup-endpoints.service';
import { BackupRestoreCellComponent } from '../backup-restore-cell/backup-restore-cell.component';
import { BackupEndpointTypes } from '../backup-restore-endpoints.service';
Expand All @@ -38,6 +40,13 @@ export class BackupEndpointsComponent implements OnInit {
valuePath: 'name'
}
},
{
columnId: 'type',
headerCell: () => 'Type',
cellDefinition: {
getValue: this.getEndpointTypeString
},
},
{
columnId: 'endpoint',
headerCell: () => 'Backup',
Expand All @@ -48,19 +57,8 @@ export class BackupEndpointsComponent implements OnInit {
},
{
columnId: 'connect',
headerCell: () => 'Backup Your Connection Details',
cellComponent: BackupRestoreCellComponent,
cellConfig: {
type: BackupEndpointTypes.CONNECT
}
},
{
columnId: 'all-connect',
headerCell: () => 'Backup All Users Connection Details',
cellComponent: BackupRestoreCellComponent,
cellConfig: {
type: BackupEndpointTypes.ALL_CONNECT
}
headerCell: () => 'Connection Details',
cellComponent: BackupConnectionCellComponent,
},
];
endpointDataSource: ITableListDataSource<EndpointModel>;
Expand All @@ -71,6 +69,7 @@ export class BackupEndpointsComponent implements OnInit {
// Step 2
passwordValid$: Observable<boolean>;
passwordForm: FormGroup;
show = false;

constructor(
public service: BackupEndpointsService,
Expand All @@ -82,6 +81,7 @@ export class BackupEndpointsComponent implements OnInit {
this.setupPasswordStep();
}


setupSelectStep() {
const action = new GetAllEndpoints();
const endpointObs = getPaginationObservables<EndpointModel>({
Expand Down Expand Up @@ -181,4 +181,7 @@ export class BackupEndpointsComponent implements OnInit {
}


private getEndpointTypeString(endpoint: EndpointModel): string {
return entityCatalog.getEndpoint(endpoint.cnsi_type, endpoint.sub_type).definition.label;
}
}
Loading

0 comments on commit c218907

Please sign in to comment.