open-energy-view icon indicating copy to clipboard operation
open-energy-view copied to clipboard

Keep customized time partitions after logout

Open thomasssino opened this issue 2 years ago • 1 comments

Customization of daily time periods seems now to work until logout. When logging back in, previous customizations are forgotten.

thomasssino avatar Feb 23 '22 19:02 thomasssino

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:
    [
      { 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%)" },
    ];
    
    where the list can be any length (including 0?) see: 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 of open_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 of DatabaseService.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 into getData

JPHutchins avatar Feb 25 '22 03:02 JPHutchins