import { Component, OnInit, ViewChild } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
-import { Router } from '@angular/router';
+import { ActivatedRoute, Router } from '@angular/router';
import _ from 'lodash';
import { NgbNav, NgbTooltip, NgbTypeahead } from '@ng-bootstrap/ng-bootstrap';
hosts: any;
labels: string[];
hasOrchestrator: boolean;
+ currentVolumeName: string;
constructor(
private router: Router,
private formBuilder: CdFormBuilder,
public actionLabels: ActionLabelsI18n,
private hostService: HostService,
- private cephfsService: CephfsService
+ private cephfsService: CephfsService,
+ private route: ActivatedRoute
) {
super();
- this.editing = this.router.url.startsWith(`/pool/${URLVerbs.EDIT}`);
+ this.editing = this.router.url.startsWith(`/cephfs/${URLVerbs.EDIT}`);
this.action = this.editing ? this.actionLabels.EDIT : this.actionLabels.CREATE;
this.resource = $localize`File System`;
this.hosts = {
}
ngOnInit() {
- const hostContext = new CdTableFetchDataContext(() => undefined);
- this.hostService.list(hostContext.toParams(), 'false').subscribe((resp: object[]) => {
- const options: SelectOption[] = [];
- _.forEach(resp, (host: object) => {
- if (_.get(host, 'sources.orchestrator', false)) {
- const option = new SelectOption(false, _.get(host, 'hostname'), '');
- options.push(option);
- }
+ if (this.editing) {
+ this.route.params.subscribe((params: { name: string }) => {
+ this.currentVolumeName = params.name;
+ this.form.get('name').setValue(this.currentVolumeName);
});
- this.hosts.options = [...options];
- });
- this.hostService.getLabels().subscribe((resp: string[]) => {
- this.labels = resp;
- });
+ } else {
+ const hostContext = new CdTableFetchDataContext(() => undefined);
+ this.hostService.list(hostContext.toParams(), 'false').subscribe((resp: object[]) => {
+ const options: SelectOption[] = [];
+ _.forEach(resp, (host: object) => {
+ if (_.get(host, 'sources.orchestrator', false)) {
+ const option = new SelectOption(false, _.get(host, 'hostname'), '');
+ options.push(option);
+ }
+ });
+ this.hosts.options = [...options];
+ });
+ this.hostService.getLabels().subscribe((resp: string[]) => {
+ this.labels = resp;
+ });
+ }
this.orchStatus$ = this.orchService.status();
}
};
submit() {
- let values = this.form.getRawValue();
- const serviceSpec: object = {
- placement: {},
- unmanaged: values['unmanaged']
- };
- switch (values['placement']) {
- case 'hosts':
- if (values['hosts'].length > 0) {
- serviceSpec['placement']['hosts'] = values['hosts'];
- }
- break;
- case 'label':
- serviceSpec['placement']['label'] = values['label'];
- break;
- }
-
const volumeName = this.form.get('name').value;
- const self = this;
- let taskUrl = `cephfs/${URLVerbs.CREATE}`;
- this.taskWrapperService
- .wrapTaskAroundCall({
- task: new FinishedTask(taskUrl, {
- volumeName: volumeName
- }),
- call: this.cephfsService.create(this.form.get('name').value, serviceSpec)
- })
- .subscribe({
- error() {
- self.form.setErrors({ cdSubmitButton: true });
- },
- complete: () => {
- this.router.navigate(['cephfs']);
- }
- });
+ const BASE_URL = 'cephfs';
+
+ if (this.editing) {
+ this.taskWrapperService
+ .wrapTaskAroundCall({
+ task: new FinishedTask(`${BASE_URL}/${URLVerbs.EDIT}`, {
+ volumeName: volumeName
+ }),
+ call: this.cephfsService.rename(this.currentVolumeName, volumeName)
+ })
+ .subscribe({
+ error: () => {
+ this.form.setErrors({ cdSubmitButton: true });
+ },
+ complete: () => {
+ this.router.navigate([BASE_URL]);
+ }
+ });
+ } else {
+ let values = this.form.getRawValue();
+ const serviceSpec: object = {
+ placement: {},
+ unmanaged: values['unmanaged']
+ };
+ switch (values['placement']) {
+ case 'hosts':
+ if (values['hosts'].length > 0) {
+ serviceSpec['placement']['hosts'] = values['hosts'];
+ }
+ break;
+ case 'label':
+ serviceSpec['placement']['label'] = values['label'];
+ break;
+ }
+
+ const self = this;
+ let taskUrl = `${BASE_URL}/${URLVerbs.CREATE}`;
+ this.taskWrapperService
+ .wrapTaskAroundCall({
+ task: new FinishedTask(taskUrl, {
+ volumeName: volumeName
+ }),
+ call: this.cephfsService.create(this.form.get('name').value, serviceSpec)
+ })
+ .subscribe({
+ error() {
+ self.form.setErrors({ cdSubmitButton: true });
+ },
+ complete: () => {
+ this.router.navigate([BASE_URL]);
+ }
+ });
+ }
}
}
import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
import { Icons } from '~/app/shared/enum/icons.enum';
import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
-import { NotificationType } from '~/app/shared/enum/notification-type.enum';
-import { FormModalComponent } from '~/app/shared/components/form-modal/form-modal.component';
import { CdTableAction } from '~/app/shared/models/cd-table-action';
import { CdTableColumn } from '~/app/shared/models/cd-table-column';
import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
-import { CdDatePipe } from '~/app/shared/pipes/cd-date.pipe';
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
import { URLBuilderService } from '~/app/shared/services/url-builder.service';
import { ModalService } from '~/app/shared/services/modal.service';
constructor(
private authStorageService: AuthStorageService,
private cephfsService: CephfsService,
- private cdDatePipe: CdDatePipe,
public actionLabels: ActionLabelsI18n,
private router: Router,
private urlBuilder: URLBuilderService,
name: $localize`Created`,
prop: 'mdsmap.created',
flexGrow: 1,
- pipe: this.cdDatePipe,
cellTransformation: CellTemplate.timeAgo
}
];
name: this.actionLabels.EDIT,
permission: 'update',
icon: Icons.edit,
- click: () => this.editAction()
+ click: () =>
+ this.router.navigate([this.urlBuilder.getEdit(this.selection.first().mdsmap.fs_name)])
},
{
permission: 'delete',
return true;
}
-
- editAction() {
- const selectedVolume = this.selection.first().mdsmap['fs_name'];
-
- this.modalService.show(FormModalComponent, {
- titleText: $localize`Edit File System: ${selectedVolume}`,
- fields: [
- {
- type: 'text',
- name: 'name',
- value: selectedVolume,
- label: $localize`Name`,
- required: true
- }
- ],
- submitButtonText: $localize`Edit File System`,
- onSubmit: (values: any) => {
- this.cephfsService.rename(selectedVolume, values.name).subscribe(() => {
- this.notificationService.show(
- NotificationType.success,
- $localize`Updated File System '${selectedVolume}'`
- );
- });
- }
- });
- }
}