This commit is contained in:
+77
-3
@@ -29,6 +29,7 @@ import { SyncAlignmentReview } from './sync-alignment-review';
|
||||
import { SystemNonstartReview } from './system-nonstart-review';
|
||||
|
||||
const unknown = 'Nicht gemeldet';
|
||||
const noPurpose = 'Nicht hinterlegt';
|
||||
const number = new Intl.NumberFormat('de-DE', { maximumFractionDigits: 1 });
|
||||
const date = new Intl.DateTimeFormat('de-DE', { dateStyle: 'medium', timeStyle: 'short' });
|
||||
function label(value: unknown) {
|
||||
@@ -127,6 +128,64 @@ function devicePath(customer: string, asset: string) {
|
||||
return tenantPath(customer, '/devices/' + encodeURIComponent(asset));
|
||||
}
|
||||
|
||||
function DevicePurpose({ value, path, customer, editor, success, onSaved }: {
|
||||
value: string;
|
||||
path: string;
|
||||
customer: string;
|
||||
editor: Session | null;
|
||||
success: boolean;
|
||||
onSaved: () => void;
|
||||
}) {
|
||||
const [draft, setDraft] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const tooLong = Array.from(draft?.trim() ?? '').length > 500;
|
||||
const close = () => { setDraft(null); setError(null); };
|
||||
return (
|
||||
<section className="device-purpose">
|
||||
<h2>Zweck</h2>
|
||||
{editor && draft !== null ? (
|
||||
<form onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
if (busy || tooLong) return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await request(path + '/purpose', {
|
||||
method: 'PATCH', tenantId: customer, csrf: editor.csrf_token, body: { purpose: draft }
|
||||
});
|
||||
close();
|
||||
onSaved();
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}}>
|
||||
<label>
|
||||
Zweck des Geräts
|
||||
<textarea autoFocus rows={3} value={draft} disabled={busy}
|
||||
aria-describedby="device-purpose-help" aria-invalid={tooLong}
|
||||
onChange={(e) => setDraft(e.target.value)} />
|
||||
</label>
|
||||
<p id="device-purpose-help" className={tooLong ? 'error' : 'muted'}>
|
||||
{tooLong ? 'Der Zweck ist zu lang. ' : ''}Maximal 500 Zeichen. Zum Entfernen das Feld leeren.
|
||||
</p>
|
||||
<ErrorBox error={error} />
|
||||
<button type="submit" disabled={busy || tooLong}>{busy ? 'Speichert …' : 'Zweck speichern'}</button>{' '}
|
||||
<button type="button" className="quiet" disabled={busy} onClick={close}>Abbrechen</button>
|
||||
</form>
|
||||
) : (
|
||||
<>
|
||||
<p className={'purpose-text' + (value ? '' : ' muted')}>{value || noPurpose}</p>
|
||||
{editor && <button className="quiet" onClick={() => setDraft(value)}>Zweck bearbeiten</button>}
|
||||
{success && <p role="status">Zweck gespeichert.</p>}
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function reportedScriptProfiles(device: RecordValue) {
|
||||
const os = devicePlatform(device);
|
||||
if (!os || !Array.isArray(device.capabilities)) return 'Nicht gemeldet';
|
||||
@@ -176,6 +235,7 @@ function DeviceDetail({
|
||||
[error, setError] = useState<string | null>(null);
|
||||
const [confirmDelete, setConfirmDelete] = useState(false);
|
||||
const [managing, setManaging] = useState(false);
|
||||
const [purposeSaved, setPurposeSaved] = useState(false);
|
||||
const d = detail.data;
|
||||
const scoped = membership.data;
|
||||
const volumes = Array.isArray(d?.volumes) ? d.volumes.map((v) => record(v)) : [];
|
||||
@@ -221,6 +281,14 @@ function DeviceDetail({
|
||||
))}
|
||||
</dl>
|
||||
</section>
|
||||
<DevicePurpose
|
||||
value={typeof d.purpose === 'string' ? d.purpose : ''}
|
||||
path={path}
|
||||
customer={customer}
|
||||
editor={scoped && allowed(scoped, 'devices:revoke') && allowed(scoped, 'inventory:read') ? scoped : null}
|
||||
success={purposeSaved}
|
||||
onSaved={() => { setPurposeSaved(true); detail.reload(); }}
|
||||
/>
|
||||
<DeviceInventoryPanels device={d} />
|
||||
{volumes.length > 0 && (
|
||||
<section>
|
||||
@@ -557,9 +625,9 @@ export function Devices({
|
||||
<span className="sr-only">Ziel auswählen</span>
|
||||
</th>
|
||||
)}
|
||||
{['Hostname', 'Type', 'OS', 'Status', 'Speicher frei / gesamt', 'RAM frei / gesamt', 'CPU', 'Kunde'].map(
|
||||
{['Hostname', 'Type', 'Zweck', 'OS', 'Status', 'Speicher frei / gesamt', 'RAM frei / gesamt', 'CPU', 'Kunde'].map(
|
||||
(h) => (
|
||||
<th scope="col" key={h}>
|
||||
<th scope="col" key={h} className={h === 'Zweck' ? 'purpose-col' : undefined}>
|
||||
{h}
|
||||
</th>
|
||||
)
|
||||
@@ -571,7 +639,8 @@ export function Devices({
|
||||
const asset = objectId(d, 'asset'),
|
||||
agent = objectId(d, 'agent'),
|
||||
customer = objectId(d, 'tenant'),
|
||||
model = cpu(d);
|
||||
model = cpu(d),
|
||||
purpose = typeof d.purpose === 'string' ? d.purpose : '';
|
||||
const show = () => {
|
||||
setDeletionNotice('');
|
||||
window.location.hash = ['geraete', customer, asset, agent]
|
||||
@@ -608,6 +677,11 @@ export function Devices({
|
||||
<HypervisorLabel device={d} />
|
||||
</td>
|
||||
<td data-label="Type">{label(d.device_type)}</td>
|
||||
<td data-label="Zweck" className="purpose-col">
|
||||
<span className={'purpose-text' + (purpose ? '' : ' muted')} title={purpose || undefined}>
|
||||
{purpose || noPurpose}
|
||||
</span>
|
||||
</td>
|
||||
<td data-label="OS">{label(d.os)}</td>
|
||||
<td data-label="Status" className="device-presence">
|
||||
<Presence d={d} />
|
||||
|
||||
@@ -97,6 +97,10 @@ section.fleet { padding:0; overflow:hidden; }
|
||||
.vm-hypervisor { display:flex; align-items:baseline; gap:6px; margin-top:5px; color:var(--subtle); font-size:.78rem; overflow-wrap:anywhere; }
|
||||
.vm-hypervisor .nav-icon { width:13px; height:13px; flex:none; align-self:flex-start; margin-top:2px; }
|
||||
.fleet-table .target-col { width:35px; }
|
||||
.fleet-table th.purpose-col { width:17%; }
|
||||
.purpose-text { white-space:pre-wrap; overflow-wrap:anywhere; }
|
||||
.fleet-table .purpose-text { display:-webkit-box; -webkit-box-orient:vertical; -webkit-line-clamp:3; overflow:hidden; }
|
||||
.device-purpose textarea { font-family:inherit; }
|
||||
.fleet-table td[data-label="Type"] { overflow-wrap:anywhere; }
|
||||
.fleet-table input[type=checkbox] { margin:0; }
|
||||
.host-link { padding:0; background:none; color:var(--accent); text-align:left; font-weight:680; margin:0; overflow-wrap:anywhere; }
|
||||
@@ -156,6 +160,7 @@ section.fleet { padding:0; overflow:hidden; }
|
||||
.fleet-table td,.fleet-table td:first-child,.fleet-table td:last-child {display:block;padding:0;border:0;font-size:.9rem;}
|
||||
.fleet-table td[data-label]::before {content:attr(data-label);display:block;color:var(--subtle);font-size:.73rem;}
|
||||
.fleet-table .hostname {grid-column:1/-1;padding-right:28px;} .host-link {font-size:1rem;}
|
||||
.fleet-table .purpose-col {grid-column:1/-1;}
|
||||
.fleet-table .target-col {position:absolute;right:14px;top:14px;width:auto;} .capacity-track {width:76px;}
|
||||
.list-footer {border-top:1px solid var(--line);flex-wrap:wrap;} .facts {grid-template-columns:1fr 1fr;gap:12px;}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user