Ctrl+C/Ctrl+V copy and paste grid cells without opening an editor, using the document copy/paste events so it also works over plain HTTP in the LAN. Protection and cable summaries copy the complete circuit record; tab-separated blocks from Excel spread over visible rows and columns. With a Ctrl/Shift multi-selection, typing, pasting and the protection dialog apply to every selected row that can take the value, including device power and GZF; other cells are skipped and reported. All of these writes use the new circuit-list.bulk-update command. It carries complete circuit.update, circuit-device-row.update and circuit-protection.update commands, applies them with the single-command rules in one transaction and stores the reversed inverses, so each edit is one undo step. The single-command apply logic is extracted for reuse. A right-click menu (also context-menu key / Shift+F10) offers copy, paste, edit, protection, cable sizing, insert circuit below, add device and delete. The protection summary is now selected by click and opened by double click, Enter or F2. Existing numbers open in the inline editor with a decimal comma, so confirming an unchanged decimal no longer fails. Refs #26 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.8 KiB
TypeScript
69 lines
2.8 KiB
TypeScript
import { circuitDeviceRowUpdateCommandType } from "../../domain/models/circuit-device-row-project-command.model.js";
|
|
import {
|
|
assertCircuitListBulkUpdateProjectCommand,
|
|
createCircuitListBulkUpdateProjectCommand,
|
|
type CircuitListBulkUpdateEntry,
|
|
} from "../../domain/models/circuit-list-bulk-update-project-command.model.js";
|
|
import { circuitUpdateCommandType } from "../../domain/models/circuit-project-command.model.js";
|
|
import type {
|
|
CircuitListBulkUpdateProjectCommandStore,
|
|
ExecuteCircuitListBulkUpdateCommandInput,
|
|
} from "../../domain/ports/circuit-list-bulk-update-project-command.store.js";
|
|
import type { AppDatabase } from "../database-context.js";
|
|
import { applyCircuitDeviceRowUpdateCommand } from "./circuit-device-row-project-command.repository.js";
|
|
import { applyCircuitUpdateCommand } from "./circuit-project-command.repository.js";
|
|
import { applyCircuitProtectionUpdateCommand } from "./circuit-protection-project-command.repository.js";
|
|
import { executeProjectCommandTransactionWithAppliedForward } from "./project-command-transaction.persistence.js";
|
|
|
|
export class CircuitListBulkUpdateProjectCommandRepository
|
|
implements CircuitListBulkUpdateProjectCommandStore
|
|
{
|
|
constructor(private readonly database: AppDatabase) {}
|
|
|
|
// Applies every update with the same rules as its single command inside
|
|
// one transaction. Any rejected update rolls the whole edit back.
|
|
execute(input: ExecuteCircuitListBulkUpdateCommandInput) {
|
|
assertCircuitListBulkUpdateProjectCommand(input.command);
|
|
return executeProjectCommandTransactionWithAppliedForward(
|
|
this.database,
|
|
input,
|
|
(tx) => {
|
|
const forward: CircuitListBulkUpdateEntry[] = [];
|
|
const inverse: CircuitListBulkUpdateEntry[] = [];
|
|
for (const update of input.command.payload.updates) {
|
|
const applied = applyBulkUpdateEntry(tx, input, update);
|
|
forward.push(applied.forward);
|
|
inverse.unshift(applied.inverse);
|
|
}
|
|
return {
|
|
forward: createCircuitListBulkUpdateProjectCommand(forward),
|
|
inverse: createCircuitListBulkUpdateProjectCommand(inverse),
|
|
};
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
function applyBulkUpdateEntry(
|
|
tx: AppDatabase,
|
|
input: ExecuteCircuitListBulkUpdateCommandInput,
|
|
update: CircuitListBulkUpdateEntry
|
|
): { forward: CircuitListBulkUpdateEntry; inverse: CircuitListBulkUpdateEntry } {
|
|
const context = { projectId: input.projectId, source: input.source };
|
|
if (update.type === circuitUpdateCommandType) {
|
|
return applyCircuitUpdateCommand(tx, { ...context, command: update });
|
|
}
|
|
if (update.type === circuitDeviceRowUpdateCommandType) {
|
|
return applyCircuitDeviceRowUpdateCommand(tx, {
|
|
...context,
|
|
command: update,
|
|
});
|
|
}
|
|
return {
|
|
forward: update,
|
|
inverse: applyCircuitProtectionUpdateCommand(tx, {
|
|
...context,
|
|
command: update,
|
|
}),
|
|
};
|
|
}
|