Show the bound script source alongside order results
This commit is contained in:
+69
-24
@@ -366,6 +366,48 @@ function Operations({ tenantId, open, customerName }: { tenantId: string; open:
|
||||
{list.data && <PageButtons pages={pages} next={list.data.next_cursor} change={setPages}/>}
|
||||
</section>;
|
||||
}
|
||||
function OrderScript({ tenantId, operation, names }: { tenantId: string; operation: RecordValue; names: RecordValue[] }) {
|
||||
const operationId = objectId(operation, 'operation');
|
||||
const planId = objectId(operation, 'plan');
|
||||
const planHash = stringField(operation, 'plan_hash');
|
||||
const scripts = useResource(async signal => {
|
||||
const plan = record(await request(tenantPath(tenantId, '/operation-plans/' + encodeURIComponent(planId)), { signal }));
|
||||
const stored = record(plan.plan_payload);
|
||||
if (plan.operation_id !== operationId || plan.plan_hash !== planHash ||
|
||||
plan.plan_id !== planId || stored.plan_id !== planId || stored.tenant_id !== tenantId) {
|
||||
throw new Error('Der Skriptinhalt konnte diesem Auftrag nicht zugeordnet werden.');
|
||||
}
|
||||
await verifyScriptPlan(plan);
|
||||
const jobs = scriptPlanJobs(plan);
|
||||
if (!jobs.length) throw new Error('Für diesen Auftrag ist kein Skriptinhalt gespeichert.');
|
||||
const variants = new Map<string, typeof jobs>();
|
||||
for (const job of jobs) {
|
||||
const key = JSON.stringify([job.scriptHash, job.interpreter]);
|
||||
const group = variants.get(key);
|
||||
if (group) group.push(job);
|
||||
else variants.set(key, [job]);
|
||||
}
|
||||
return [...variants.values()];
|
||||
}, [tenantId, operationId, planId, planHash]);
|
||||
|
||||
const variants = scripts.error ? [] : scripts.data ?? [];
|
||||
return <article className="order-script" aria-label="Skriptinhalt">
|
||||
<h3>Skriptinhalt</h3>
|
||||
<ErrorBox error={scripts.error}/>
|
||||
{!scripts.data && !scripts.error && <p>Skriptinhalt wird geladen …</p>}
|
||||
{variants.map(group => {
|
||||
const script = group[0]!;
|
||||
return <div key={script.scriptHash + '/' + script.interpreter}>
|
||||
{variants.length > 1 && <h4>{group.map(job => {
|
||||
const target = names.find(item => item.asset_id === job.assetId && item.agent_id === job.agentId);
|
||||
return target ? deviceName(target) : job.assetId;
|
||||
}).join(', ')}</h4>}
|
||||
<p className="muted">{script.revision ? 'Version ' + script.revision.version : 'Einmaliges Skript'} · {script.interpreter}</p>
|
||||
<pre className="script-body" aria-label="Gespeicherter Skripttext" tabIndex={0}>{outputText(new TextEncoder().encode(script.script.replace(/\r\n/g, '\n'))).text}</pre>
|
||||
</div>;
|
||||
})}
|
||||
</article>;
|
||||
}
|
||||
function OperationDetail({ tenantId, id, auth, openPlan, customerName }: {
|
||||
tenantId: string; id: string; auth: Session; openPlan: (id: string) => void; customerName?: string
|
||||
}) {
|
||||
@@ -385,29 +427,32 @@ function OperationDetail({ tenantId, id, auth, openPlan, customerName }: {
|
||||
<Fact label="Status"><Status value={statusOf(data)}/></Fact><Fact label="Eingereicht">{when(data.created_at)}</Fact>
|
||||
<Fact label="Antragsteller"><Requester id={data.requester} ownId={auth.principal.id}/></Fact>
|
||||
<Fact label="Anlass">{display(data.reason, 'Kein Anlass angegeben')}</Fact></dl>
|
||||
{singleJob ? <JobDetail key={objectId(singleJob, 'job')} tenantId={tenantId}
|
||||
id={objectId(singleJob, 'job')} hostname={name(singleJob)} auth={auth}/>
|
||||
: <div className="order-results">
|
||||
<h3>Geräte und Ergebnisse</h3>
|
||||
{jobs.length ? <ul className="job-list">{jobs.map(job => {
|
||||
const resultId = objectId(job, 'job');
|
||||
const hostname = name(job);
|
||||
const expanded = jobId === resultId;
|
||||
const action = expanded ? 'Ergebnis schließen' : 'Ergebnis anzeigen';
|
||||
return <li key={resultId}>
|
||||
<div className="job-row">
|
||||
<strong>{hostname}</strong>
|
||||
<Status value={job.state}/>
|
||||
<button type="button" data-job-id={resultId} aria-expanded={expanded}
|
||||
aria-label={action + ' für ' + hostname}
|
||||
onClick={() => setJobId(expanded ? null : resultId)}>{action}</button>
|
||||
</div>
|
||||
{expanded && <JobDetail tenantId={tenantId} id={resultId} hostname={hostname} auth={auth}/>}
|
||||
</li>;
|
||||
})}</ul>
|
||||
: <><p>{names.map(deviceName).join(', ')}</p><p className="muted">{data.approval_state === 'pending_approval'
|
||||
? 'Nach der Genehmigung erscheint hier der Fortschritt je Gerät.' : 'Für diesen Auftrag liegen keine Ausführungen vor.'}</p></>}
|
||||
</div>}
|
||||
<div className="order-execution">
|
||||
{singleJob ? <JobDetail key={objectId(singleJob, 'job')} tenantId={tenantId}
|
||||
id={objectId(singleJob, 'job')} hostname={name(singleJob)} auth={auth}/>
|
||||
: <div className="order-results">
|
||||
<h3>Geräte und Ergebnisse</h3>
|
||||
{jobs.length ? <ul className="job-list">{jobs.map(job => {
|
||||
const resultId = objectId(job, 'job');
|
||||
const hostname = name(job);
|
||||
const expanded = jobId === resultId;
|
||||
const action = expanded ? 'Ergebnis schließen' : 'Ergebnis anzeigen';
|
||||
return <li key={resultId}>
|
||||
<div className="job-row">
|
||||
<strong>{hostname}</strong>
|
||||
<Status value={job.state}/>
|
||||
<button type="button" data-job-id={resultId} aria-expanded={expanded}
|
||||
aria-label={action + ' für ' + hostname}
|
||||
onClick={() => setJobId(expanded ? null : resultId)}>{action}</button>
|
||||
</div>
|
||||
{expanded && <JobDetail tenantId={tenantId} id={resultId} hostname={hostname} auth={auth}/>}
|
||||
</li>;
|
||||
})}</ul>
|
||||
: <><p>{names.map(deviceName).join(', ')}</p><p className="muted">{data.approval_state === 'pending_approval'
|
||||
? 'Nach der Genehmigung erscheint hier der Fortschritt je Gerät.' : 'Für diesen Auftrag liegen keine Ausführungen vor.'}</p></>}
|
||||
</div>}
|
||||
{data.action === 'run_script' && <OrderScript tenantId={tenantId} operation={data} names={names}/>}
|
||||
</div>
|
||||
{allowed(auth, 'plans:approve') && <button className="quiet" onClick={() => openPlan(objectId(data,'plan'))}>
|
||||
{data.approval_state === 'pending_approval' ? 'Antrag prüfen' : 'Genehmigungsdetail öffnen'}
|
||||
</button>}
|
||||
@@ -660,7 +705,7 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
|
||||
{route.page === 'auftraege' && (
|
||||
route.tab === 'neu' ? <>
|
||||
<a href="#auftraege" className="back-link">← Zu den Aufträgen</a>
|
||||
<OrderComposer tenantId={customer} customerName={customerName} auth={scoped} initialAssetIds={selected} onSubmitted={afterSubmission} />
|
||||
<OrderComposer tenantId={customer} customerName={customerName} auth={scoped} initialAssetIds={selected} onSubmitted={afterSubmission} onDraft={showDraft} />
|
||||
<details className="advanced-order"><summary>Weitere Wartungsaktionen</summary>
|
||||
<p>Inventur, Dienstverwaltung und weitere Wartungsaufträge planen.</p>
|
||||
<a className="quiet" href="#auftraege/wartung">Wartungsauftrag planen</a>
|
||||
|
||||
@@ -122,6 +122,13 @@ section.fleet { padding:0; overflow:hidden; }
|
||||
.job-result > section > p:first-child { margin-top:0; }
|
||||
.job-result .console-output { background:var(--surface); }
|
||||
.job-list .job-result { margin:8px 0 2px; }
|
||||
.order-script { margin-top:22px; }
|
||||
.order-script > h3 { font-size:1.15rem; }
|
||||
.order-script .script-body { max-height:24rem; }
|
||||
.order-script .script-body:last-child { margin-bottom:0; }
|
||||
@media (min-width:1101px) {
|
||||
.order-execution:has(> .order-script) { display:grid; grid-template-columns:minmax(0, 3fr) minmax(0, 2fr); gap:16px; align-items:start; }
|
||||
}
|
||||
.device-detail > .quiet { margin-bottom:18px; }
|
||||
.sr-only { position:absolute; width:1px; height:1px; margin:-1px; padding:0; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
|
||||
@media(max-width:1100px) and (min-width:761px) { .workbench {grid-template-columns:165px minmax(0,1fr);} .content {padding-left:18px;padding-right:18px;} .brand {font-size:1rem;} .fleet-table th,.fleet-table td {padding-inline:6px;} }
|
||||
|
||||
Reference in New Issue
Block a user