<cds-modal size="md"
[open]="open"
- [hasScrollingContent]="true"
- (overlaySelected)="closeModal()">
+ [hasScrollingContent]="true">
<cds-modal-header (closeSelect)="closeModal()">
<h3 cdsModalHeaderHeading
i18n>{{ action | titlecase }} {{ resource | upperFirst }}</h3>
<div cdsModalContent>
<!-- Hostname -->
<div class="form-item">
- <cds-text-label label="Hostname"
- for="hostname"
- cdRequiredField="Hostname"
+ <cds-text-label for="hostname"
[invalid]="!hostForm.controls.hostname.valid && hostForm.controls.hostname.dirty"
- [invalidText]="hostnameError"
- i18n>Hostname
+ [invalidText]="hostnameError">
+ <ng-container i18n>Hostname (required)</ng-container>
<input cdsText
type="text"
placeholder="mon-123"
name="hostname"
formControlName="hostname"
autofocus
+ [invalid]="!hostForm.controls.hostname.valid && hostForm.controls.hostname.dirty"
(keyup)="checkHostNameValue()">
</cds-text-label>
<ng-template #hostnameError>
</ng-template>
<cd-help-text>
To add multiple hosts at once, you can enter:
- <ul>
- <li>a comma-separated list of hostnames <samp>(e.g.: example-01,example-02,example-03)</samp>,</li>
- <li>a range expression <samp>(e.g.: example-[01-03].ceph)</samp>,</li>
- <li>a comma separated range expression <samp>(e.g.: example-[01-05].lab.com,example2-[1-4].lab.com,example3-[001-006].lab.com)</samp></li>
+ <ul cdsList>
+ <li cdsListItem
+ i18n>a comma-separated list of hostnames <b>(e.g.: example-01,example-02,example-03)</b>,</li>
+ <li cdsListItem
+ i18n>a range expression <b>(e.g.: example-[01-03].ceph)</b>,</li>
+ <li cdsListItem
+ i18n>a comma separated range expression <b>(e.g.: example-[01-05].lab.com,example2-[1-4].lab.com,example3-[001-006].lab.com)</b></li>
</ul>
</cd-help-text>
</div>
-import { Component, OnInit } from '@angular/core';
+import { Component, Inject, OnInit, Optional } from '@angular/core';
import { UntypedFormControl, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import expand from 'brace-expansion';
import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
import { FinishedTask } from '~/app/shared/models/finished-task';
import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
-import { Location } from '@angular/common';
+const HOSTS = 'hosts';
@Component({
selector: 'cd-host-form',
templateUrl: './host-form.component.html',
pageURL: string;
hostPattern = false;
labelsOption: Array<SelectOption> = [];
- hideMaintenance: boolean;
messages = new SelectMessages({
empty: $localize`There are no labels.`,
private hostService: HostService,
private taskWrapper: TaskWrapperService,
private route: ActivatedRoute,
- private location: Location
+
+ @Inject('hideMaintenance') @Optional() public hideMaintenance?: boolean
) {
super();
this.resource = $localize`host`;
}
ngOnInit() {
+ if (this.router.url.includes(HOSTS)) {
+ this.pageURL = HOSTS;
+ }
this.open = this.route.outlet === 'modal';
this.createForm();
const hostContext = new CdTableFetchDataContext(() => undefined);
this.addr = this.hostForm.get('addr').value;
this.status = this.hostForm.get('maintenance').value ? 'maintenance' : '';
this.allLabels = this.hostForm.get('labels').value;
- if (this.pageURL !== 'hosts' && !this.allLabels.includes('_no_schedule')) {
+ if (this.pageURL !== HOSTS && !this.allLabels.includes('_no_schedule')) {
this.allLabels.push('_no_schedule');
}
this.hostnameArray.forEach((hostName: string) => {
this.hostForm.setErrors({ cdSubmitButton: true });
},
complete: () => {
- this.pageURL === 'hosts'
- ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
- : this.location.back();
+ this.closeModal();
}
});
});
}
closeModal(): void {
- this.location.back();
+ this.pageURL === HOSTS
+ ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
+ : (this.open = false);
}
}