2021-05-07 23:33:58 +01:00
|
|
|
import { Page } from "../../types/Page";
|
2021-05-07 23:21:38 +01:00
|
|
|
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";
|
2021-05-07 11:53:26 +01:00
|
|
|
import { createOrUpdateSecret } from "../../api/createOrUpdateSecret";
|
2021-05-07 22:23:52 +01:00
|
|
|
import { makeElement } from "../../htmlUtils";
|
2021-05-07 23:08:02 +01:00
|
|
|
import { pageState } from "../../globalPageState.ts";
|
2021-04-20 20:38:30 +01:00
|
|
|
import i18next from 'i18next';
|
2021-04-15 13:01:58 +01:00
|
|
|
|
|
|
|
export class KeyValueNewPage extends Page {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
goBack() {
|
2021-04-17 11:24:43 +01:00
|
|
|
changePage("KEY_VALUE_VIEW");
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
render() {
|
|
|
|
setTitleElement(pageState);
|
|
|
|
this.addKVNewForm = makeElement({
|
|
|
|
tag: "form",
|
|
|
|
id: "addKVNewForm",
|
|
|
|
children: [
|
|
|
|
makeElement({
|
|
|
|
tag: "div",
|
|
|
|
class: "uk-margin",
|
|
|
|
children: makeElement({
|
|
|
|
tag: "input",
|
|
|
|
class: ["uk-input", "uk-form-width-medium"],
|
|
|
|
attributes: {
|
|
|
|
required: true,
|
|
|
|
type: "text",
|
2021-04-20 20:38:30 +01:00
|
|
|
placeholder: i18next.t("kv_new_path"),
|
2021-04-15 13:01:58 +01:00
|
|
|
name: "path"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "p",
|
|
|
|
id: "errorText",
|
|
|
|
class: "uk-text-danger"
|
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "button",
|
|
|
|
class: ["uk-button", "uk-button-primary"],
|
2021-04-20 20:38:30 +01:00
|
|
|
text: i18next.t("kv_new_create_btn"),
|
2021-04-15 13:01:58 +01:00
|
|
|
attributes: {
|
|
|
|
type: "submit",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
|
|
|
setPageContent(this.addKVNewForm);
|
|
|
|
|
|
|
|
this.addKVNewForm.addEventListener("submit", function (e) {
|
|
|
|
e.preventDefault();
|
2021-05-05 22:05:57 +01:00
|
|
|
this.newKVSecretHandleForm();
|
|
|
|
}.bind(this));
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
newKVSecretHandleForm() {
|
|
|
|
let formData = new FormData(this.addKVNewForm);
|
|
|
|
let path = formData.get("path");
|
|
|
|
let keyData = {};
|
|
|
|
|
|
|
|
if (["kv-v1", "cubbyhole"].includes(pageState.currentMountType)) {
|
|
|
|
keyData = { "key": "value" };
|
|
|
|
}
|
|
|
|
|
|
|
|
createOrUpdateSecret(
|
|
|
|
pageState.currentBaseMount,
|
2021-05-05 21:56:25 +01:00
|
|
|
pageState.currentMountType,
|
|
|
|
pageState.currentSecretPath,
|
2021-05-05 17:09:38 +01:00
|
|
|
path,
|
2021-04-15 13:01:58 +01:00
|
|
|
keyData
|
|
|
|
).then(_ => {
|
2021-04-17 11:24:43 +01:00
|
|
|
changePage("KEY_VALUE_VIEW");
|
2021-04-15 13:01:58 +01:00
|
|
|
return;
|
|
|
|
}).catch(e => {
|
|
|
|
setErrorText(e.message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-20 20:32:57 +01:00
|
|
|
get titleSuffix() {
|
2021-04-20 20:38:30 +01:00
|
|
|
return i18next.t("kv_new_suffix");
|
2021-04-17 11:06:34 +01:00
|
|
|
}
|
2021-04-15 13:01:58 +01:00
|
|
|
|
|
|
|
get name() {
|
2021-04-20 20:38:30 +01:00
|
|
|
return i18next.t("kv_new_title");
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
}
|