2021-05-16 10:27:21 +01:00
|
|
|
import { PageRouter } from "z-pagerouter";
|
2021-05-19 10:27:00 +01:00
|
|
|
import { PageState } from "../../PageState";
|
2021-05-16 18:17:12 +01:00
|
|
|
import { makeElement } from "z-makeelement";
|
2021-05-15 10:54:39 +01:00
|
|
|
|
2021-05-16 09:42:43 +01:00
|
|
|
function currentTitleSecretText(state: PageState, suffix = ""): string {
|
|
|
|
let currentSecretText = state.currentSecret;
|
2021-05-15 10:54:39 +01:00
|
|
|
currentSecretText += suffix;
|
2021-05-16 10:35:35 +01:00
|
|
|
if (state.currentSecretVersion !== null) currentSecretText += ` (v${state.currentSecretVersion})`;
|
2021-05-15 10:54:39 +01:00
|
|
|
return currentSecretText;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function SecretTitleElement(router: PageRouter, suffix = ""): Promise<HTMLElement> {
|
2021-05-16 10:35:35 +01:00
|
|
|
const state = router.state as PageState;
|
2021-05-15 10:54:39 +01:00
|
|
|
const titleElement = makeElement({
|
|
|
|
tag: "div",
|
|
|
|
children: [
|
|
|
|
makeElement({
|
|
|
|
tag: "a",
|
2021-05-16 09:42:43 +01:00
|
|
|
text: state.currentBaseMount + " ",
|
2021-05-15 10:54:39 +01:00
|
|
|
onclick: async () => {
|
2021-05-16 09:42:43 +01:00
|
|
|
state.currentSecretPath = [];
|
|
|
|
state.currentSecret = "";
|
|
|
|
state.currentSecretVersion = null;
|
2021-05-15 10:54:39 +01:00
|
|
|
|
2021-05-16 10:35:35 +01:00
|
|
|
if (state.currentMountType.startsWith("kv") || state.currentMountType == "cubbyhole") {
|
2021-05-15 10:54:39 +01:00
|
|
|
await router.changePage("KEY_VALUE_VIEW");
|
2021-05-16 09:42:43 +01:00
|
|
|
} else if (state.currentMountType == "totp") {
|
2021-05-15 10:54:39 +01:00
|
|
|
await router.changePage("TOTP");
|
2021-05-16 09:42:43 +01:00
|
|
|
} else if (state.currentMountType == "transit") {
|
2021-05-15 10:54:39 +01:00
|
|
|
await router.changePage("TRANSIT_VIEW");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}),
|
2021-05-16 09:42:43 +01:00
|
|
|
...state.currentSecretPath.map((secretPath, index, secretPaths) => {
|
2021-05-15 10:54:39 +01:00
|
|
|
return makeElement({
|
|
|
|
tag: "a",
|
|
|
|
text: secretPath + " ",
|
|
|
|
onclick: async () => {
|
2021-05-16 09:42:43 +01:00
|
|
|
state.currentSecretVersion = null;
|
|
|
|
if (state.currentMountType.startsWith("kv")) {
|
|
|
|
state.currentSecretPath = secretPaths.slice(0, index + 1);
|
2021-05-15 10:54:39 +01:00
|
|
|
await router.changePage("KEY_VALUE_VIEW");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "span",
|
2021-05-16 09:42:43 +01:00
|
|
|
condition: state.currentSecret.length != 0,
|
|
|
|
text: currentTitleSecretText(state, suffix),
|
2021-05-15 10:54:39 +01:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
return titleElement;
|
|
|
|
}
|