diff --git a/offshore-wind-dispatch/lib/DispatchApp.js b/offshore-wind-dispatch/lib/DispatchApp.js index 25bd377..627ffb2 100644 --- a/offshore-wind-dispatch/lib/DispatchApp.js +++ b/offshore-wind-dispatch/lib/DispatchApp.js @@ -47,12 +47,6 @@ export default class DispatchApp extends Panel.mixin(Responsive) { // The map fits itself to the selected trip or turbine. Off until the user selects one, and after Show all mapFollows : false, - // The ID of the team dragged from the tray - lifted : null, - - // The ID of the waiting team whose booking the engine is placing (DropController#dropTeam) - booking : null, - /** * The team held and its check, `{ id, target, trip, team, job, result, reach, close, at }` * (DropController#previewDrop), `null` while it is over nothing @@ -210,19 +204,6 @@ export default class DispatchApp extends Panel.mixin(Responsive) { this.redrawSide?.(); } - // At once: the lifted card dims as the drag starts - updateLifted(lifted) { - if (this.parts) { - this.parts.tray.lifted = lifted; - } - } - - updateBooking(booking) { - if (this.parts) { - this.parts.tray.booking = booking; - } - } - /** * Shows the plan with T-41 and its trip selected, and the forecast chart drawn * @param {Object} [options] @@ -254,7 +235,7 @@ export default class DispatchApp extends Panel.mixin(Responsive) { await me.applyForecast(); } else if (state === 'drag' && me.dispatch.waitingStore.count) { - await me.drag.showHeld(me.dispatch.waitingStore.first.id, first); + me.drag.showHeld(me.dispatch.waitingStore.first.id, first); } await scheduler.features.forecastHeader.refresh(); diff --git a/offshore-wind-dispatch/lib/DropController.js b/offshore-wind-dispatch/lib/DropController.js index b5b0577..48866f3 100644 --- a/offshore-wind-dispatch/lib/DropController.js +++ b/offshore-wind-dispatch/lib/DropController.js @@ -27,7 +27,7 @@ export default class DropController { * @param {Object} options * @param {DispatchState} options.dispatch * @param {DispatchScheduler} options.scheduler The Day view - * @param {DispatchApp} options.state Holds `held` (see previewDrop), `lifted` and `booking` + * @param {DispatchApp} options.state Holds `held`, see previewDrop * @param {Function} options.onBooked Called with `{ trip, turbine }` once a team is booked: on a trip of the Day * view, or (no `trip`) on a new trip on a day of the Week view */ @@ -40,13 +40,15 @@ export default class DropController { return this.dispatch.waitingStore.getById(teamId); } - // The chip stays in the tray, dimmed, until the team is booked. The trips it fits on are outlined, checked once + // The card stays in the tray, dimmed (the record's `lifted`), until the team is booked. The trips it fits on are + // outlined, checked once liftTeam(teamId) { const me = this, entry = me.waitingTeam(teamId); - me.state.lifted = teamId; + me.lifted = entry; + entry?.set('lifted', true); me.scheduler.features.dropTarget.fitting = entry ? me.scheduler.trips.filter(trip => me.checkDrop(trip, entry.team, entry.job).valid) : []; } @@ -242,7 +244,7 @@ export default class DropController { * moved is still back in its window and clear of its vessel's other trips (planBreak). Else the trip is put back * and the reason shown. * One change of the plan at a time (DispatchProject#runChange): while the engine places it, the team is reserved - * (`state.booking`, its card in the tray shows it pending) and no other change starts + * (its record's `pending`, the card in the tray shows it) and no other change starts * @param {String} teamId * @param {TripModel|VesselModel|Object|null} target * @param {Number|null} [at] Minutes since midnight at the point released, see previewDrop @@ -266,14 +268,17 @@ export default class DropController { return false; } + // The record, not its ID: it has left the store once booked + const entry = me.waitingTeam(drop.id); + return project.runChange(async() => { - me.state.booking = drop.id; + entry.set('pending', true); try { return await me.commitDrop(drop, target); } finally { - me.state.booking = null; + entry.set('pending', false); } }); } @@ -344,8 +349,11 @@ export default class DropController { } endDrag() { - this.scheduler.features.dropTarget.fitting = []; - this.state.held = null; - this.state.lifted = null; + const me = this; + + me.lifted?.set('lifted', false); + me.lifted = null; + me.scheduler.features.dropTarget.fitting = []; + me.state.held = null; } } diff --git a/offshore-wind-dispatch/lib/TeamTray.js b/offshore-wind-dispatch/lib/TeamTray.js index b282f87..bdddf3d 100644 --- a/offshore-wind-dispatch/lib/TeamTray.js +++ b/offshore-wind-dispatch/lib/TeamTray.js @@ -21,15 +21,10 @@ export default class TeamTray extends Container { static configurable = { port : null, - // WaitingTeamModel records + // WaitingTeamModel records. A record changed redraws its card only (List#refreshItem syncs it in place, so the + // element a drag holds stays) store : null, - // The ID of the team dragged: its card stays in the tray, dimmed - lifted : null, - - // The ID of the team whose booking the engine is placing: its card is dimmed and cannot be dragged - booking : null, - cls : 'ow-tray', layout : { type : 'hbox', align : 'center' }, items : { @@ -58,13 +53,14 @@ export default class TeamTray extends Container { } }; - // Two short lines that never wrap: "Team F · 2" over "T-34 fault · 48 min" - cardHtml({ id, team, job, fault }) { - const cls = `ow-team${fault ? ' ow-team-fault' : ''}${id === this.lifted ? ' ow-team-lifted' : ''}` + - `${id === this.booking ? ' ow-team-pending' : ''}`; + // Two short lines that never wrap: "Team F · 2" over "T-34 fault · 48 min". A team dragged stays in the tray, + // dimmed (`lifted`); one whose booking the engine is placing is dimmed and cannot be dragged (`pending`) + cardHtml({ id, team, job, fault, lifted, pending }) { + const cls = `ow-team${fault ? ' ow-team-fault' : ''}${lifted ? ' ow-team-lifted' : ''}` + + `${pending ? ' ow-team-pending' : ''}`; - return StringHelper.xss`
` + - `${icon('users')}` + StringHelper.xss` + return StringHelper.xss`
` + + `${icon('users')}` + StringHelper.xss` ${team.name} · ${team.techs} ${jobText(job, fault)} · ${duration(job.minutes)}
`; @@ -93,21 +89,6 @@ export default class TeamTray extends Container { title.html = `Crews waiting at ${StringHelper.encodeHtml(this.port ?? 'the port')} · ${count}`; hint.hidden = !count; } - - // On the card itself, not by redrawing the list: the drag holds the card's element - updateLifted(lifted) { - this.element?.querySelectorAll('.ow-team[data-team]').forEach(card => - card.classList.toggle('ow-team-lifted', card.dataset.team === lifted)); - } - - updateBooking(booking) { - this.element?.querySelectorAll('.ow-team[data-team]').forEach(card => { - const pending = card.dataset.team === booking; - - card.classList.toggle('ow-team-pending', pending); - card.setAttribute('aria-busy', String(pending)); - }); - } } TeamTray.initClass(); diff --git a/offshore-wind-dispatch/lib/drag/TeamDrag.js b/offshore-wind-dispatch/lib/drag/TeamDrag.js index 40d2aeb..b375d7c 100644 --- a/offshore-wind-dispatch/lib/drag/TeamDrag.js +++ b/offshore-wind-dispatch/lib/drag/TeamDrag.js @@ -97,13 +97,11 @@ export default class TeamDrag { * outline of its stop would, with no pointer. Escape puts it back * @param {String} teamId * @param {TripModel} trip - * @returns {Promise} Resolves once it is shown */ - async showHeld(teamId, trip) { + showHeld(teamId, trip) { const me = this, - { handler } = me, - outline = () => me.scheduler.element.querySelector('.ow-drop-outline'); + { handler } = me; me.lift(teamId); me.target = trip; @@ -112,19 +110,13 @@ export default class TeamDrag { document.addEventListener('keydown', me.onKey); handler.previewDrop(teamId, trip); - // The outline is drawn a frame later - for (let frame = 0; frame < 30 && !outline(); frame++) { - await new Promise(resolve => requestAnimationFrame(resolve)); - } - - const rect = outline()?.getBoundingClientRect(); + // The check draws the outline as it is set (DropTarget#updateDrop) + const rect = me.scheduler.element.querySelector('.ow-drop-outline')?.getBoundingClientRect(); - if (me.team === teamId) { - me.point = rect ? { x : rect.left + rect.width / 2, y : rect.top + rect.height / 2 } : - { x : innerWidth / 2, y : innerHeight / 2 }; - DomHelper.setTranslateXY(me.proxy, me.point.x - 20, me.point.y + 8); - me.hover(trip, me.point); - } + me.point = rect ? { x : rect.left + rect.width / 2, y : rect.top + rect.height / 2 } : + { x : innerWidth / 2, y : innerHeight / 2 }; + DomHelper.setTranslateXY(me.proxy, me.point.x - 20, me.point.y + 8); + me.hover(trip, me.point); } onDragStart(context) { diff --git a/offshore-wind-dispatch/lib/feature/DropTarget.js b/offshore-wind-dispatch/lib/feature/DropTarget.js index ae679d8..3795c95 100644 --- a/offshore-wind-dispatch/lib/feature/DropTarget.js +++ b/offshore-wind-dispatch/lib/feature/DropTarget.js @@ -21,8 +21,8 @@ export default class DropTarget extends SchedulerFeature { drop : null, /** - * The trips the team fits on, checked once when it is lifted. Not a field of the trip: changing the record - * would redraw the trip and its legs + * The trips the team fits on, checked once when it is lifted. Not a field of the trip: it is the screen's, not + * the plan's * @prp {TripModel[]} */ fitting : [] @@ -44,12 +44,17 @@ export default class DropTarget extends SchedulerFeature { } } - // The class goes on the trips' elements now, no redraw; the renderer keeps it on a later one (isFitting) + // The trip renderer outlines them (isFitting): only the vessels of the trips that start or stop fitting redraw updateFitting(trips, was = []) { - const outline = (each, on) => this.client.getElementFromEventRecord(each)?.classList.toggle('ow-trip-fits', on); + if (this.isConfiguring) { + return; + } + + const + changed = trip => !trip.isDestroyed && was.includes(trip) !== trips.includes(trip), + vessels = new Set([...was, ...trips].filter(changed).map(trip => trip.resource)); - was.forEach(trip => outline(trip, false)); - trips.forEach(trip => outline(trip, true)); + vessels.forEach(vessel => vessel && this.client.repaintEventsForResource(vessel)); } isFitting(trip) { diff --git a/offshore-wind-dispatch/lib/feature/ForecastHeader.js b/offshore-wind-dispatch/lib/feature/ForecastHeader.js index e4da78a..791a3db 100644 --- a/offshore-wind-dispatch/lib/feature/ForecastHeader.js +++ b/offshore-wind-dispatch/lib/feature/ForecastHeader.js @@ -5,8 +5,8 @@ import WaveChart from '../schedule/WaveChart.js'; /** * The time axis rows of the Day view (hours, wave height, wind) and the vessel column's header naming them, for the * forecast of the Scheduler's `dispatch` state. The wave height row is one cell over the day; the chart lives in an - * element of its own, moved into that cell whenever the time axis is drawn, never recreated. A new forecast updates the - * wind values and the label in place, the time axis itself does not change. + * element of its own, moved into that cell whenever the time axis is drawn, never recreated. The wind values and the + * label are the header renderers' output, a new forecast draws the headers again. * * Learn more: * https://bryntum.com/docs/api/Scheduler/preset/ViewPreset#config-headers @@ -85,7 +85,7 @@ export default class ForecastHeader extends SchedulerFeature { windHtml(hour) { const { wind, over } = this.windAt(hour); - return `${wind ?? ''}`; + return `${wind ?? ''}`; } windAt(hour) { @@ -137,26 +137,17 @@ export default class ForecastHeader extends SchedulerFeature { } /** - * Shows the dispatch state's forecast: the chart, the wind values and the label, updated in place + * Shows the dispatch state's forecast: the chart, and the headers drawn again for the wind values and the label * @returns {Promise} Resolves once the chart is drawn */ refresh() { const - me = this, - { element, dispatch } = me.client; + me = this, + { client } = me, + { dispatch } = client; - element?.querySelectorAll('.ow-wind[data-hour]').forEach(wind => { - const { wind : value, over } = me.windAt(Number(wind.dataset.hour)); - - wind.textContent = value ?? ''; - wind.classList.toggle('ow-wind-over', over); - }); - - const label = element?.querySelector('.ow-axis-row-head'); - - if (label) { - label.innerHTML = me.forecastLabel; - } + client.timeAxisColumn.refreshHeader(); + client.columns.get('name').refreshHeader(); return me.chart.show({ hs : dispatch.forecast.hs, diff --git a/offshore-wind-dispatch/lib/model/WaitingTeamModel.js b/offshore-wind-dispatch/lib/model/WaitingTeamModel.js index 3e603e2..ebb0c29 100644 --- a/offshore-wind-dispatch/lib/model/WaitingTeamModel.js +++ b/offshore-wind-dispatch/lib/model/WaitingTeamModel.js @@ -17,6 +17,11 @@ export default class WaitingTeamModel extends Model { { name : 'job', type : 'object' }, // The turbine is stopped { name : 'fault', type : 'boolean' }, + // Screen state for the tray's card, not data: dragged (`lifted`), its booking being placed by the engine + // (`pending`). Not persisted, which also keeps them out of the forecast's undo history (the STM records no + // change of a `persist : false` field) + { name : 'lifted', type : 'boolean', persist : false }, + { name : 'pending', type : 'boolean', persist : false }, // What the tray's List reads out for it { name : 'text', calculate : ({ team, job }) => `${team.name}, ${job.turbine} ${job.job}` } ]; diff --git a/offshore-wind-dispatch/lib/schedule/WaveChart.js b/offshore-wind-dispatch/lib/schedule/WaveChart.js index c94941a..f77c8f6 100644 --- a/offshore-wind-dispatch/lib/schedule/WaveChart.js +++ b/offshore-wind-dispatch/lib/schedule/WaveChart.js @@ -1,6 +1,7 @@ import { AgCharts, AllCommunityModule, CrosshairModule, LicenseManager, ModuleRegistry, RangeAreaSeriesModule } from 'ag-charts-enterprise'; +import { GlobalEvents } from '@bryntum/core-enterprise'; import { hhmm } from '../util/Time.js'; // AG Charts Enterprise is licensed separately. The key is read at build time from `VITE_AG_LICENSE_KEY` (a gitignored @@ -75,9 +76,10 @@ export default class WaveChart { Object.assign(me, { element, limits, day, forecast : null }); - // Redrawn on a theme switch: the shell's switch sets `data-theme` on the root, or the system setting changes - me.observer = new MutationObserver(() => me.redraw()); - me.observer.observe(document.documentElement, { attributes : true, attributeFilter : ['data-theme'] }); + // Redrawn on a light / dark switch: Bryntum's `theme` event fires when the shell's toggle pins a mode + // (DomHelper.colorScheme). Bryntum reports a change of the system setting only once a widget has asked for the + // mode, so that one is watched here too + me.detachTheme = GlobalEvents.on({ theme : () => me.redraw() }); me.media = matchMedia('(prefers-color-scheme: dark)'); me.media.onchange = () => me.redraw(); // AG Charts sizes itself to its container. A chart created while the container had no size (the header being @@ -120,7 +122,7 @@ export default class WaveChart { } destroy() { - this.observer.disconnect(); + this.detachTheme(); this.sized.disconnect(); this.media.onchange = null; this.chart?.destroy();