open-energy-view
open-energy-view copied to clipboard
Keep customized time partitions after logout
Customization of daily time periods seems now to work until logout. When logging back in, previous customizations are forgotten.
Hey @thomasssino ! Unfortunately that's expected. TLDR the "daily partitions config" needs to be saved to the server's database and recalled on next login.
For future reference:
- The database already has a "partition_options" field that is intended to be the save location for this, see https://github.dev/JPHutchins/open-energy-view/blob/master/open_energy_view/models.py
- partion_options, in the database, python, or javascript should be this shape:
where the list can be any length (including 0?) see:[ { name: "Night", start: 0, color: "hsl(240, 40%, 37%)" }, { name: "Day", start: 7, color: "hsl(173, 40%, 57%)" }, { name: "Evening", start: 18, color: "hsl(296, 40%, 57%)" }, ];
open_energy_view/frontend/js/data-structures/helpers/defaultPartitions.js
- Add API POST endpoint to
open_energy_view/resources.py
that handles saving partition options - register it in__init__.py
under the#User interactions
section - Add "save" button to this file that makes the POST above:https://github.com/JPHutchins/open-energy-view/blob/master/open_energy_view/frontend/js/components/Settings/SetPartitions.jsx
- Currently, the frontend handles updating partitions by checking for
partitionUpdate
at line 101 ofopen_energy_view/frontend/js/App.jsx
. Honestly, it needs to be redone but can still work for now. - Use the API endpoint
api/web/partition-options
,resources.py/GetPartitionOptions
to retrieve partition options. See line 22 ofDatabaseService.js
, it looks like this was just never hooked up. - Request from the partition options endpoint before calling
getData
so that the partition options saved server side can be passed intogetData