-
Notifications
You must be signed in to change notification settings - Fork 48
Feat: Graph modal upgrade - flex-config integration #1926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joshuaunity
wants to merge
39
commits into
feat/allow-Ssensorstoshow-schema
Choose a base branch
from
feat/sensortoshow-modal-upgrade
base: feat/allow-Ssensorstoshow-schema
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
5530be6
chore: multiple updates
joshuaunity 2123746
chore: stabilized leeft side of modal and kicked off work onteh right…
joshuaunity a8d722d
chore: completed left side of graph modal
joshuaunity ca1e01f
Merge branch 'feat/allow-Ssensorstoshow-schema' of github.com:FlexMea…
joshuaunity f7966b0
Merge branch 'feat/allow-Ssensorstoshow-schema' of github.com:FlexMea…
joshuaunity 79a1c8a
chore: work in progress
joshuaunity 4b75e82
refactor: more stabilization work as well as reactivation of broken f…
joshuaunity 3e03eed
Merge branch 'feat/allow-Ssensorstoshow-schema' of github.com:FlexMea…
joshuaunity b5f7700
Merge branch 'feat/allow-Ssensorstoshow-schema' of github.com:FlexMea…
joshuaunity 9b08119
chore: reorder tabs
joshuaunity 502554d
fix: fixed bug whre options keep gettgin added teh configType dropdow…
joshuaunity ce0a984
fix: fixed error where graph cant be removed
joshuaunity d6d75d8
fix: ixed issue with graph titles not being editable
joshuaunity b5b9876
fix: fixed broken units dropdown as well as some other refactoring to…
joshuaunity f878460
refactor: Major refactor phase 1
joshuaunity 6ff2570
refactor: Major refactor phase 2
joshuaunity f9823c0
feat; new util function to find an asset site_asset
joshuaunity a96ca2b
chore: add extra info icon to form elements
joshuaunity 9419875
chore: update writeup
joshuaunity 66fe145
fix: fix failing util function due to wrong formatting allowing trail…
joshuaunity 5eca7e8
Merge branch 'feat/allow-Ssensorstoshow-schema' into feat/sensortosho…
joshuaunity 88b0449
fix: fixed bug where a new sensor cant be added to an existing graph
joshuaunity 5552322
refactor: Fixed graphs to properly display subcharts and mixed charts…
joshuaunity 25326dd
chore: removed unused code
joshuaunity 1c4635d
Merge branch 'feat/allow-Ssensorstoshow-schema' into feat/sensortosho…
joshuaunity 9582d27
refactor: post resolving conflicts refactoring
joshuaunity 63b4539
tests: remove unsupported edgecase
joshuaunity cafc05b
fix: fix issue where unsuppoerted flexocntext fields are sent to API,…
joshuaunity c77f718
feat: up to date asset data for graph modals
joshuaunity b437123
fix: Fix bug where you cant remove sensors from a grpah with multiple…
joshuaunity 5ee01b4
chore: amek all asset ref inputs equal size
joshuaunity 2850567
Update flexmeasures/ui/templates/assets/asset_graph.html
joshuaunity eb47a6f
Update flexmeasures/ui/templates/assets/asset_graph.html
joshuaunity d02c738
fix: fixed error when trying to remove polts thats not a array of sen…
joshuaunity 5a79e24
fix: Fixed bug where the options to select a felxConfig field disable…
joshuaunity d63a6aa
refactor: imporve fuction to improve readability and also fix edgecas…
joshuaunity c791f5a
fix: Fixed bug where sensors filter sectoin doesnt change after a sel…
joshuaunity d83587c
chore: udpate temp sensor naming sceme
joshuaunity 69a1c9a
chore: persisten root asset selection
joshuaunity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| import { getAsset, getAccount, getSensor, apiBasePath } from "./ui-utils.js"; | ||
|
|
||
| const addInfo = (label, value, infoDiv, Resource, isLink = false) => { | ||
joshuaunity marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const b = document.createElement("b"); | ||
| b.textContent = `${label}: `; | ||
| infoDiv.appendChild(b); | ||
| const isSensor = Resource.hasOwnProperty("unit"); | ||
|
|
||
| if (isLink) { | ||
| const a = document.createElement("a"); | ||
| a.href = `${apiBasePath}/${isSensor ? "sensors" : "assets"}/${Resource.id}`; | ||
| a.textContent = value; | ||
| infoDiv.appendChild(a); | ||
| } else { | ||
| infoDiv.appendChild(document.createTextNode(value)); | ||
| } | ||
| }; | ||
|
|
||
| export async function renderAssetPlotCard(assetPlot, graphIndex, plotIndex) { | ||
| const Asset = await getAsset(assetPlot.asset); | ||
| let IsFlexContext = false; | ||
| let IsFlexModel = false; | ||
| let flexConfigValue = null; | ||
|
|
||
| if ("flex-context" in assetPlot) { | ||
| IsFlexContext = true; | ||
| flexConfigValue = assetPlot["flex-context"]; | ||
| } | ||
|
|
||
| if ("flex-model" in assetPlot) { | ||
| IsFlexModel = true; | ||
| flexConfigValue = assetPlot["flex-model"]; | ||
| } | ||
|
|
||
| const container = document.createElement("div"); | ||
| container.className = "p-1 mb-3 border-bottom border-secondary"; | ||
|
|
||
| const flexDiv = document.createElement("div"); | ||
| flexDiv.className = "d-flex justify-content-between"; | ||
|
|
||
| const infoDiv = document.createElement("div"); | ||
|
|
||
| addInfo("ID", Asset.id, infoDiv, Asset, true); | ||
| infoDiv.appendChild(document.createTextNode(", ")); | ||
| addInfo("Name", Asset.name, infoDiv, Asset); | ||
| infoDiv.appendChild(document.createTextNode(", ")); | ||
| if (IsFlexContext) { | ||
| addInfo("Flex Context", flexConfigValue, infoDiv, Asset); | ||
| } else if (IsFlexModel) { | ||
| addInfo("Flex Model", flexConfigValue, infoDiv, Asset); | ||
| } | ||
|
|
||
| const closeIcon = document.createElement("i"); | ||
| closeIcon.className = "fa fa-times"; | ||
| closeIcon.style.cursor = "pointer"; | ||
| closeIcon.setAttribute("data-bs-toggle", "tooltip"); | ||
| closeIcon.title = "Remove Asset Plot"; | ||
|
|
||
| // Attach the actual function here | ||
| closeIcon.addEventListener("click", (e) => { | ||
| e.stopPropagation(); // Prevent card selection click | ||
| // removeAssetPlotFromGraph(graphIndex, plotIndex); | ||
| }); | ||
|
|
||
| flexDiv.appendChild(infoDiv); | ||
| flexDiv.appendChild(closeIcon); | ||
| container.appendChild(flexDiv); | ||
|
|
||
| return container; | ||
| } | ||
|
|
||
| export async function renderSensorCard(sensorId, graphIndex, sensorIndex) { | ||
| const Sensor = await getSensor(sensorId); | ||
| const Asset = await getAsset(Sensor.generic_asset_id); | ||
| const Account = await getAccount(Asset.account_id); | ||
|
|
||
| const container = document.createElement("div"); | ||
| container.className = "p-1 mb-3 border-bottom border-secondary"; | ||
|
|
||
| const flexDiv = document.createElement("div"); | ||
| flexDiv.className = "d-flex justify-content-between"; | ||
|
|
||
| const infoDiv = document.createElement("div"); | ||
|
|
||
| addInfo("ID", Sensor.id, infoDiv, Sensor, true); | ||
| infoDiv.appendChild(document.createTextNode(", ")); | ||
| addInfo("Unit", Sensor.unit, infoDiv, Sensor); | ||
| infoDiv.appendChild(document.createTextNode(", ")); | ||
| addInfo("Name", Sensor.name, infoDiv, Sensor); | ||
|
|
||
| const spacer = document.createElement("div"); | ||
| spacer.style.paddingTop = "1px"; | ||
| infoDiv.appendChild(spacer); | ||
|
|
||
| addInfo("Asset", Asset.name, infoDiv, Asset); | ||
| infoDiv.appendChild(document.createTextNode(", ")); | ||
| addInfo("Account", Account?.name ? Account.name : "PUBLIC", infoDiv, Account); | ||
|
|
||
| const closeIcon = document.createElement("i"); | ||
| closeIcon.className = "fa fa-times"; | ||
| closeIcon.style.cursor = "pointer"; | ||
| closeIcon.setAttribute("data-bs-toggle", "tooltip"); | ||
| closeIcon.title = "Remove Sensor"; | ||
|
|
||
| // Attach the actual function here | ||
| closeIcon.addEventListener("click", (e) => { | ||
| e.stopPropagation(); // Prevent card selection click | ||
| removeSensorFromGraph(graphIndex, sensorIndex); | ||
| }); | ||
|
|
||
| flexDiv.appendChild(infoDiv); | ||
| flexDiv.appendChild(closeIcon); | ||
| container.appendChild(flexDiv); | ||
|
|
||
| // Return both the element and the unit (so we can check for mixed units later) | ||
| return { element: container, unit: Sensor.unit }; | ||
| } | ||
|
|
||
| export async function renderSensorsList(sensorIds, graphIndex) { | ||
| const listContainer = document.createElement("div"); | ||
| const units = []; | ||
|
|
||
| if (sensorIds.length === 0) { | ||
| listContainer.innerHTML = `<div class="alert alert-warning">No sensors added to this graph.</div>`; | ||
| return { element: listContainer, uniqueUnits: [] }; | ||
| } | ||
|
|
||
| // Using Promise.all to maintain order and wait for all sensors | ||
| const results = await Promise.all( | ||
| sensorIds.map((id, sIdx) => renderSensorCard(id, graphIndex, sIdx)), | ||
| ); | ||
|
|
||
| results.forEach((res) => { | ||
| listContainer.appendChild(res.element); | ||
| units.push(res.unit); | ||
| }); | ||
|
|
||
| return { element: listContainer, uniqueUnits: [...new Set(units)] }; | ||
| } | ||
|
|
||
| /** | ||
| * Renders the header for a graph card. | ||
| * @param {string} title - The current title of the graph. | ||
| * @param {number} index - The index of the graph in the list. | ||
| * @param {boolean} isEditing - Whether this specific graph is in edit mode. | ||
| * @param {Function} onSave - Function to call when "Save" is clicked or "Enter" is pressed. | ||
| * @param {Function} onEdit - Function to call when "Edit" is clicked. | ||
| */ | ||
| export function renderGraphHeader(title, index, isEditing, onSave, onEdit) { | ||
| const header = document.createElement("div"); | ||
| header.className = "d-flex align-items-center mb-2"; | ||
|
|
||
| if (isEditing) { | ||
| // 1. Title Input | ||
| const input = document.createElement("input"); | ||
| input.type = "text"; | ||
| input.className = "form-control me-2"; | ||
| input.id = `editTitle_${index}`; | ||
| input.value = title; | ||
|
|
||
| // Save on Enter key | ||
| input.addEventListener("keydown", (e) => { | ||
| if (e.key === "Enter") { | ||
| e.preventDefault(); | ||
| onSave(index); | ||
| } | ||
| }); | ||
|
|
||
| // 2. Save Button | ||
| const saveBtn = document.createElement("button"); | ||
| saveBtn.className = "btn btn-success btn-sm"; | ||
| saveBtn.textContent = "Save"; | ||
| saveBtn.onclick = (e) => { | ||
| e.stopPropagation(); // Prevent card selection | ||
| onSave(index); | ||
| }; | ||
|
|
||
| header.appendChild(input); | ||
| header.appendChild(saveBtn); | ||
|
|
||
| // Auto-focus the input | ||
| setTimeout(() => input.focus(), 0); | ||
| } else { | ||
| // 1. Display Title | ||
| const h5 = document.createElement("h5"); | ||
| h5.className = "card-title me-2 mb-0"; | ||
| h5.textContent = title; | ||
|
|
||
| // 2. Edit Button | ||
| const editBtn = document.createElement("button"); | ||
| editBtn.className = "btn btn-warning btn-sm"; | ||
| editBtn.textContent = "Edit"; | ||
| editBtn.onclick = (e) => { | ||
| e.stopPropagation(); // Prevent card selection | ||
| onEdit(index); | ||
| }; | ||
|
|
||
| header.appendChild(h5); | ||
| header.appendChild(editBtn); | ||
| } | ||
|
|
||
| return header; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.