import { catchError, map, tap } from 'rxjs/operators';
import { NotificationService } from '~/app/shared/services/notification.service';
import { NotificationType } from '~/app/shared/enum/notification-type.enum';
+import { Lifecycle, Rule } from '../models/rgw-bucket-lifecycle';
@Component({
selector: 'cd-rgw-bucket-lifecycle-list',
const allLifecycleRules$ = this.rgwBucketService
.getLifecycle(this.bucket.bucket, this.bucket.owner)
.pipe(
- tap((lifecycle) => {
+ tap((lifecycle: Lifecycle) => {
this.lifecycleRuleList = lifecycle;
}),
catchError(() => {
this.filteredLifecycleRules$ = allLifecycleRules$.pipe(
map(
(lifecycle: any) =>
- lifecycle?.LifecycleConfiguration?.Rules?.filter((rule: object) =>
+ lifecycle?.LifecycleConfiguration?.Rule?.filter((rule: Rule) =>
rule.hasOwnProperty('Transition')
) || []
)
deleteAction() {
const ruleNames = this.selection.selected.map((rule) => rule.ID);
- const filteredRules = this.lifecycleRuleList.LifecycleConfiguration.Rules.filter(
- (rule: any) => !ruleNames.includes(rule.ID)
+ const filteredRules = this.lifecycleRuleList.LifecycleConfiguration.Rule.filter(
+ (rule: Rule) => !ruleNames.includes(rule.ID)
);
- const rules = filteredRules.length > 0 ? { Rules: filteredRules } : {};
+ const rules = filteredRules.length > 0 ? { Rule: filteredRules } : {};
this.modalRef = this.modalService.show(DeleteConfirmationModalComponent, {
itemDescription: $localize`Rule`,
itemNames: ruleNames,
import { CdForm } from '~/app/shared/forms/cd-form';
import { Router } from '@angular/router';
import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
+import { Lifecycle, Rule, Tag } from '../models/rgw-bucket-lifecycle';
export interface Tags {
tagKey: number;
tieringForm: CdFormGroup;
tagsToRemove: Tags[] = [];
storageClassList: StorageClass[] = null;
- configuredLifecycle: any;
+ configuredLifecycle: Lifecycle;
isStorageClassFetched = false;
constructor(
@Inject('bucket') public bucket: Bucket,
- @Optional() @Inject('selectedLifecycle') public selectedLifecycle: any,
+ @Optional() @Inject('selectedLifecycle') public selectedLifecycle: Rule,
@Optional() @Inject('editing') public editing = false,
public actionLabels: ActionLabelsI18n,
private rgwBucketService: RgwBucketService,
ngOnInit() {
this.rgwBucketService
.getLifecycle(this.bucket.bucket, this.bucket.owner)
- .subscribe((lifecycle) => {
- this.configuredLifecycle = lifecycle || { LifecycleConfiguration: { Rules: [] } };
+ .subscribe((lifecycle: Lifecycle) => {
+ if (lifecycle === null) {
+ lifecycle = { LifecycleConfiguration: { Rule: [] } };
+ }
+ lifecycle.LifecycleConfiguration.Rule = lifecycle.LifecycleConfiguration.Rule.map(
+ (rule: Rule) => {
+ if (rule?.['Filter']?.['Tag'] && !Array.isArray(rule?.['Filter']?.['Tag'])) {
+ rule['Filter']['Tag'] = [rule['Filter']['Tag']];
+ }
+ if (
+ rule?.['Filter']?.['And']?.['Tag'] &&
+ !Array.isArray(rule?.['Filter']?.['And']?.['Tag'])
+ ) {
+ rule['Filter']['And']['Tag'] = [rule['Filter']['And']['Tag']];
+ }
+ return rule;
+ }
+ );
+ this.configuredLifecycle = lifecycle;
if (this.editing) {
- const ruleToEdit = this.configuredLifecycle?.['LifecycleConfiguration']?.['Rules'].filter(
- (rule: any) => rule?.['ID'] === this.selectedLifecycle?.['ID']
+ const ruleToEdit = this.configuredLifecycle?.['LifecycleConfiguration']?.['Rule'].filter(
+ (rule: Rule) => rule?.['ID'] === this.selectedLifecycle?.['ID']
)[0];
this.tieringForm.patchValue({
name: ruleToEdit?.['ID'],
this.loadStorageClass();
}
- checkIfRuleHasFilters(rule: any) {
+ checkIfRuleHasFilters(rule: Rule) {
if (
this.isValidPrefix(rule?.['Prefix']) ||
this.isValidPrefix(rule?.['Filter']?.['Prefix']) ||
- this.isValidArray(rule?.['Filter']?.['Tags']) ||
+ this.isValidArray(rule?.['Filter']?.['Tag']) ||
this.isValidPrefix(rule?.['Filter']?.['And']?.['Prefix']) ||
- this.isValidArray(rule?.['Filter']?.['And']?.['Tags'])
+ this.isValidArray(rule?.['Filter']?.['And']?.['Tag'])
) {
return true;
}
}
isValidPrefix(value: string) {
- return value !== undefined && value !== '';
+ return !!value;
}
- isValidArray(value: object[]) {
+ isValidArray(value: Tag | Tag[]) {
return Array.isArray(value) && value.length > 0;
}
- setTags(rule: any) {
- if (rule?.['Filter']?.['Tags']?.length > 0) {
- rule?.['Filter']?.['Tags']?.forEach((tag: { Key: string; Value: string }) =>
+ setTags(rule: Rule) {
+ if (Array.isArray(rule?.Filter?.Tag) && rule?.Filter?.Tag?.length > 0) {
+ rule?.['Filter']?.['Tag']?.forEach((tag: { Key: string; Value: string }) =>
this.addTags(tag.Key, tag.Value)
);
}
- if (rule?.['Filter']?.['And']?.['Tags']?.length > 0) {
- rule?.['Filter']?.['And']?.['Tags']?.forEach((tag: { Key: string; Value: string }) =>
+ if (Array.isArray(rule?.Filter?.And?.Tag) && rule?.Filter?.And?.Tag?.length > 0) {
+ rule?.['Filter']?.['And']?.['Tag']?.forEach((tag: { Key: string; Value: string }) =>
this.addTags(tag.Key, tag.Value)
);
}
addTags(key?: string, value?: string) {
this.tags.push(
new FormGroup({
- Key: new FormControl(key),
- Value: new FormControl(value)
+ Key: new FormControl(key || '', Validators.required),
+ Value: new FormControl(value || '', Validators.required)
})
);
this.cd.detectChanges();
}
duplicateConfigName(control: AbstractControl): ValidationErrors | null {
- if (this.configuredLifecycle?.LifecycleConfiguration?.Rules?.length > 0) {
- const ruleIds = this.configuredLifecycle.LifecycleConfiguration.Rules.map(
- (rule: any) => rule.ID
+ if (this.configuredLifecycle?.LifecycleConfiguration?.Rule?.length > 0) {
+ const ruleIds = this.configuredLifecycle.LifecycleConfiguration.Rule.map(
+ (rule: Rule) => rule.ID
);
return ruleIds.includes(control.value) ? { duplicate: true } : null;
}
return;
}
- let lifecycle: any = {
+ let lifecycle: Rule = {
ID: this.tieringForm.getRawValue().name,
Status: formValue.status,
- Transition: [
- {
- Days: formValue.days,
- StorageClass: formValue.storageClass
- }
- ]
+ Transition: {
+ Days: formValue.days,
+ StorageClass: formValue.storageClass
+ }
};
if (formValue.hasPrefix) {
if (this.tags.length > 0) {
}
} else {
Object.assign(lifecycle, {
- Filter: {}
+ Prefix: ''
});
}
if (!this.editing) {
- this.configuredLifecycle.LifecycleConfiguration.Rules.push(lifecycle);
+ this.configuredLifecycle.LifecycleConfiguration.Rule.push(lifecycle);
this.rgwBucketService
.setLifecycle(
this.bucket.bucket,
}
});
} else {
- const rules = this.configuredLifecycle.LifecycleConfiguration.Rules;
- const index = rules.findIndex((rule: any) => rule?.['ID'] === this.selectedLifecycle?.['ID']);
+ const rules = this.configuredLifecycle.LifecycleConfiguration.Rule;
+ const index = rules.findIndex(
+ (rule: Rule) => rule?.['ID'] === this.selectedLifecycle?.['ID']
+ );
rules.splice(index, 1, lifecycle);
this.rgwBucketService
.setLifecycle(
goToCreateStorageClass() {
this.router.navigate(['rgw/tiering/create']);
+ this.closeModal();
}
}