web/admin: improve persistence for test forms
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
a237ae3363
commit
3a9f081e1b
|
@ -5,10 +5,10 @@ import { html, TemplateResult } from "lit-html";
|
||||||
import { DEFAULT_CONFIG } from "../../api/Config";
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
||||||
import { Form } from "../../elements/forms/Form";
|
import { Form } from "../../elements/forms/Form";
|
||||||
import { until } from "lit-html/directives/until";
|
import { until } from "lit-html/directives/until";
|
||||||
import { ifDefined } from "lit-html/directives/if-defined";
|
|
||||||
import "../../elements/forms/HorizontalFormElement";
|
import "../../elements/forms/HorizontalFormElement";
|
||||||
import "../../elements/CodeMirror";
|
import "../../elements/CodeMirror";
|
||||||
import YAML from "yaml";
|
import YAML from "yaml";
|
||||||
|
import { first } from "../../utils";
|
||||||
|
|
||||||
@customElement("ak-policy-test-form")
|
@customElement("ak-policy-test-form")
|
||||||
export class PolicyTestForm extends Form<PolicyTestRequest> {
|
export class PolicyTestForm extends Form<PolicyTestRequest> {
|
||||||
|
@ -19,11 +19,15 @@ export class PolicyTestForm extends Form<PolicyTestRequest> {
|
||||||
@property({ attribute: false})
|
@property({ attribute: false})
|
||||||
result?: PolicyTestResult;
|
result?: PolicyTestResult;
|
||||||
|
|
||||||
|
@property({ attribute: false})
|
||||||
|
request?: PolicyTestRequest;
|
||||||
|
|
||||||
getSuccessMessage(): string {
|
getSuccessMessage(): string {
|
||||||
return t`Successfully sent test-request.`;
|
return t`Successfully sent test-request.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
send = (data: PolicyTestRequest): Promise<PolicyTestResult> => {
|
send = (data: PolicyTestRequest): Promise<PolicyTestResult> => {
|
||||||
|
this.request = data;
|
||||||
return new PoliciesApi(DEFAULT_CONFIG).policiesAllTestCreate({
|
return new PoliciesApi(DEFAULT_CONFIG).policiesAllTestCreate({
|
||||||
policyUuid: this.policy?.pk || "",
|
policyUuid: this.policy?.pk || "",
|
||||||
policyTestRequest: data
|
policyTestRequest: data
|
||||||
|
@ -67,7 +71,7 @@ export class PolicyTestForm extends Form<PolicyTestRequest> {
|
||||||
ordering: "username",
|
ordering: "username",
|
||||||
}).then(users => {
|
}).then(users => {
|
||||||
return users.results.map(user => {
|
return users.results.map(user => {
|
||||||
return html`<option value=${ifDefined(user.pk)}>${user.username}</option>`;
|
return html`<option ?selected=${this.request?.user.toString() === user.pk.toString()} value=${user.pk}>${user.username}</option>`;
|
||||||
});
|
});
|
||||||
}), html`<option>${t`Loading...`}</option>`)}
|
}), html`<option>${t`Loading...`}</option>`)}
|
||||||
</select>
|
</select>
|
||||||
|
@ -75,7 +79,7 @@ export class PolicyTestForm extends Form<PolicyTestRequest> {
|
||||||
<ak-form-element-horizontal
|
<ak-form-element-horizontal
|
||||||
label=${t`Context`}
|
label=${t`Context`}
|
||||||
name="context">
|
name="context">
|
||||||
<ak-codemirror mode="yaml" value=${YAML.stringify({})}>>
|
<ak-codemirror mode="yaml" value=${YAML.stringify(first(this.request?.context, {}))}>>
|
||||||
</ak-codemirror>
|
</ak-codemirror>
|
||||||
<p class="pf-c-form__helper-text">${t`Set custom attributes using YAML or JSON.`}</p>
|
<p class="pf-c-form__helper-text">${t`Set custom attributes using YAML or JSON.`}</p>
|
||||||
</ak-form-element-horizontal>
|
</ak-form-element-horizontal>
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { ifDefined } from "lit-html/directives/if-defined";
|
||||||
import "../../elements/forms/HorizontalFormElement";
|
import "../../elements/forms/HorizontalFormElement";
|
||||||
import "../../elements/CodeMirror";
|
import "../../elements/CodeMirror";
|
||||||
import YAML from "yaml";
|
import YAML from "yaml";
|
||||||
|
import { first } from "../../utils";
|
||||||
|
|
||||||
@customElement("ak-property-mapping-test-form")
|
@customElement("ak-property-mapping-test-form")
|
||||||
export class PolicyTestForm extends Form<PolicyTestRequest> {
|
export class PolicyTestForm extends Form<PolicyTestRequest> {
|
||||||
|
@ -19,11 +20,15 @@ export class PolicyTestForm extends Form<PolicyTestRequest> {
|
||||||
@property({ attribute: false})
|
@property({ attribute: false})
|
||||||
result?: PropertyMappingTestResult;
|
result?: PropertyMappingTestResult;
|
||||||
|
|
||||||
|
@property({ attribute: false })
|
||||||
|
request?: PolicyTestRequest;
|
||||||
|
|
||||||
getSuccessMessage(): string {
|
getSuccessMessage(): string {
|
||||||
return t`Successfully sent test-request.`;
|
return t`Successfully sent test-request.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
send = (data: PolicyTestRequest): Promise<PropertyMappingTestResult> => {
|
send = (data: PolicyTestRequest): Promise<PropertyMappingTestResult> => {
|
||||||
|
this.request = data;
|
||||||
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsAllTestCreate({
|
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsAllTestCreate({
|
||||||
pmUuid: this.mapping?.pk || "",
|
pmUuid: this.mapping?.pk || "",
|
||||||
policyTestRequest: data,
|
policyTestRequest: data,
|
||||||
|
@ -57,7 +62,7 @@ export class PolicyTestForm extends Form<PolicyTestRequest> {
|
||||||
ordering: "username",
|
ordering: "username",
|
||||||
}).then(users => {
|
}).then(users => {
|
||||||
return users.results.map(user => {
|
return users.results.map(user => {
|
||||||
return html`<option value=${ifDefined(user.pk)}>${user.username}</option>`;
|
return html`<option ?selected=${this.request?.user.toString() === user.pk.toString()} value=${user.pk}>${user.username}</option>`;
|
||||||
});
|
});
|
||||||
}), html`<option>${t`Loading...`}</option>`)}
|
}), html`<option>${t`Loading...`}</option>`)}
|
||||||
</select>
|
</select>
|
||||||
|
@ -65,7 +70,7 @@ export class PolicyTestForm extends Form<PolicyTestRequest> {
|
||||||
<ak-form-element-horizontal
|
<ak-form-element-horizontal
|
||||||
label=${t`Context`}
|
label=${t`Context`}
|
||||||
name="context">
|
name="context">
|
||||||
<ak-codemirror mode="yaml" value=${YAML.stringify({})}>
|
<ak-codemirror mode="yaml" value=${YAML.stringify(first(this.request?.context, {}))}>>
|
||||||
</ak-codemirror>
|
</ak-codemirror>
|
||||||
</ak-form-element-horizontal>
|
</ak-form-element-horizontal>
|
||||||
${this.result ? this.renderResult(): html``}
|
${this.result ? this.renderResult(): html``}
|
||||||
|
|
Reference in New Issue