Skip to content

Commit

Permalink
Add SSH selection form field.
Browse files Browse the repository at this point in the history
Signed-off-by: Volker Theile <votdev@gmx.de>
  • Loading branch information
votdev committed Jul 14, 2021
1 parent d4f815e commit 0da7af7
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 1 deletion.
@@ -0,0 +1,20 @@
<mat-form-field fxFlex
[formGroup]="formGroup">
<mat-label>{{ config.label }}</mat-label>
<mat-select [formControlName]="config.name"
[placeholder]="config.placeholder"
[required]="config.validators?.required">
<mat-option *ngFor="let option of config.store.data"
[value]="option[config.valueField]">
{{ option[config.textField] }}
</mat-option>
</mat-select>
<mat-error *ngIf="formGroup.invalid">
<span *ngIf="formGroup.hasError('required', config.name)">
This field is required.
</span>
</mat-error>
<mat-hint *ngIf="config.hint?.length > 0"
[innerHTML]="config.hint | sanitizeHtml">
</mat-hint>
</mat-form-field>
@@ -0,0 +1,3 @@
mat-hint {
margin-bottom: 5px;
}
@@ -0,0 +1,37 @@
/* eslint-disable max-len */
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { FormBuilder } from '@angular/forms';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

import { FormSshcertSelectComponent } from '~/app/core/components/limn-ui/form/components/form-sshcert-select/form-sshcert-select.component';
import { LimnUiModule } from '~/app/core/components/limn-ui/limn-ui.module';

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

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, LimnUiModule, NoopAnimationsModule]
}).compileComponents();
})
);

beforeEach(() => {
fixture = TestBed.createComponent(FormSshcertSelectComponent);
component = fixture.componentInstance;
component.config = {
type: 'sslCertSelect',
name: 'foo'
};
const formBuilder = TestBed.inject(FormBuilder);
component.formGroup = formBuilder.group({ foo: [null] });
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,55 @@
/**
* This file is part of OpenMediaVault.
*
* @license http://www.gnu.org/licenses/gpl.html GPL Version 3
* @author Volker Theile <volker.theile@openmediavault.org>
* @copyright Copyright (c) 2009-2021 Volker Theile
*
* OpenMediaVault is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* OpenMediaVault is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
import { Component } from '@angular/core';
import * as _ from 'lodash';

import { FormSelectComponent } from '~/app/core/components/limn-ui/form/components/form-select/form-select.component';

@Component({
selector: 'omv-form-sshcert-select',
templateUrl: './form-sshcert-select.component.html',
styleUrls: ['./form-sshcert-select.component.scss']
})
export class FormSshcertSelectComponent extends FormSelectComponent {
protected sanitizeConfig() {
super.sanitizeConfig();
_.merge(this.config, {
valueField: 'uuid',
textField: 'comment',
placeholder: 'Select a SSH certificate ...',
store: {
proxy: {
service: 'CertificateMgmt',
get: {
method: 'getSshList',
params: {
start: 0,
limit: -1
}
}
},
sorters: [
{
dir: 'asc',
field: 'name'
}
]
}
});
}
}
Expand Up @@ -71,6 +71,12 @@
</omv-form-sharedfolder-select>
</ng-template>

<ng-template [ngSwitchCase]="'sshCertSelect'">
<omv-form-sshcert-select [config]="field"
[formGroup]="formGroup">
</omv-form-sshcert-select>
</ng-template>

<ng-template [ngSwitchCase]="'sslCertSelect'">
<omv-form-sslcert-select [config]="field"
[formGroup]="formGroup">
Expand Down
Expand Up @@ -21,6 +21,7 @@ import { FormPasswordInputComponent } from '~/app/core/components/limn-ui/form/c
import { FormSelectComponent } from '~/app/core/components/limn-ui/form/components/form-select/form-select.component';
import { FormSharedfolderSelectComponent } from '~/app/core/components/limn-ui/form/components/form-sharedfolder-select/form-sharedfolder-select.component';
import { FormSliderComponent } from '~/app/core/components/limn-ui/form/components/form-slider/form-slider.component';
import { FormSshcertSelectComponent } from '~/app/core/components/limn-ui/form/components/form-sshcert-select/form-sshcert-select.component';
import { FormSslcertSelectComponent } from '~/app/core/components/limn-ui/form/components/form-sslcert-select/form-sslcert-select.component';
import { FormTextInputComponent } from '~/app/core/components/limn-ui/form/components/form-text-input/form-text-input.component';
import { FormTextareaComponent } from '~/app/core/components/limn-ui/form/components/form-textarea/form-textarea.component';
Expand Down Expand Up @@ -55,6 +56,7 @@ import { SharedModule } from '~/app/shared/shared.module';
FormParagraphComponent,
FormSliderComponent,
TextPageComponent,
FormSshcertSelectComponent,
FormSslcertSelectComponent,
TabsPageComponent,
FormFolderbrowserComponent,
Expand Down
Expand Up @@ -50,6 +50,7 @@ export type FormFieldConfig = {
| 'fileInput'
| 'select'
| 'sharedFolderSelect'
| 'sshCertSelect'
| 'sslCertSelect'
| 'passwordInput'
| 'datePicker'
Expand Down
Expand Up @@ -252,7 +252,7 @@ export class RsyncTaskFormPageComponent {
}
},
{
type: 'sslCertSelect',
type: 'sshCertSelect',
name: 'sshcertificateref',
hasEmptyOption: true,
value: '',
Expand Down

0 comments on commit 0da7af7

Please sign in to comment.