/
volumeaddkey-form.component.ts
121 lines (107 loc) · 3.67 KB
/
volumeaddkey-form.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
ApplicationRef,
Component,
Injector
} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import * as _ from 'lodash';
import { RestService, WebSocketService, StorageService } from '../../../../services/';
import {
FieldConfig
} from '../../../common/entity/entity-form/models/field-config.interface';
import { DialogService } from 'app/services/dialog.service';
import { MatSnackBar, MatDialog } from '@angular/material';
import { Formconfiguration } from 'app/pages/common/entity/entity-form/entity-form.component';
import { AppLoaderService } from '../../../../services/app-loader/app-loader.service';
import { T } from '../../../../translate-marker';
import { DownloadKeyModalDialog } from '../../../../components/common/dialog/downloadkey/downloadkey-dialog.component';
import helptext from '../../../../helptext/storage/volumes/volume-key';
@Component({
selector : 'app-addkey-form',
template : `<entity-form [conf]="this"></entity-form>`
})
export class VolumeAddkeyFormComponent implements Formconfiguration {
saveSubmitText = T("Add Recovery Key");
resource_name = 'storage/volume';
route_success: string[] = [ 'storage', 'pools'];
isNew = false;
isEntity = true;
entityData = {
name: "",
passphrase: ""
};
fieldConfig: FieldConfig[] = [
{
type: 'paragraph',
name: 'addkey-instructions',
paraText: helptext.add_key_instructions,
},
{
type : 'input',
name : 'name',
isHidden: true,
validation: helptext.add_key_name_validation,
required: true
},{
type : 'input',
inputType: 'password',
name : 'password',
placeholder: helptext.add_key_password_placeholder,
tooltip: helptext.add_key_password_tooltip,
validation: helptext.add_key_password_validation,
required: true
}
];
resourceTransformIncomingRestData(data:any): any {
return data;
};
pk: any;
constructor(
protected router: Router,
protected route: ActivatedRoute,
protected rest: RestService,
protected ws: WebSocketService,
protected _injector: Injector,
protected _appRef: ApplicationRef,
protected dialogService: DialogService,
protected loader: AppLoaderService,
protected storage: StorageService,
protected snackBar: MatSnackBar,
protected mdDialog: MatDialog
) {
}
preInit(entityForm: any) {
this.route.params.subscribe(params => {
this.pk = params['pk'];
});
}
afterInit(entityForm: any) {
}
customSubmit(value) {
this.loader.open();
this.ws.call('auth.check_user', ['root', value.password]).subscribe(res => {
if (res) {
this.rest.post(this.resource_name + "/" + this.pk + "/recoverykey/", {}).subscribe((restPostResp) => {
this.loader.close();
this.snackBar.open(T("Recovery key added to pool ") + value.name, 'close', { duration: 5000 });
let dialogRef = this.mdDialog.open(DownloadKeyModalDialog, {disableClose:true});
dialogRef.componentInstance.volumeId = this.pk;
dialogRef.afterClosed().subscribe(result => {
this.router.navigate(new Array('/').concat(
this.route_success));
})
}, (res) => {
this.loader.close();
this.dialogService.errorReport(T("Error adding recovery key to pool."), res.error.error_message, res.error.traceback);
});
}
else {
this.loader.close();
this.dialogService.Info(T("Invalid password"), T("Please enter the correct password."));
}
}, (res) => {
this.loader.close();
this.dialogService.errorReport(res.error, res.reason, res.trace.formatted);
});
}
}