Skip to content

Commit

Permalink
Add confirm to delete integration
Browse files Browse the repository at this point in the history
  • Loading branch information
boblemaire committed Oct 20, 2021
1 parent ae7d9a6 commit e3d315d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Firmware/IotaWatt/IotaWatt.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
***********************************************************************************/
#define IOTAWATT_VERSION "02_07_01"
#define IOTAWATT_VERSION "02_07_02"
#define DEVICE_NAME "IotaWatt"

#define PRINT(txt,val) Serial.print(txt); Serial.print(val); // Quick debug aids
Expand Down
1 change: 1 addition & 0 deletions Firmware/IotaWatt/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
* 09/25/21 02_06_06 Support alternate RTC, datalog low-write, influxDB2 restart query, more robust Script
* 09/27/21 02_07_00 Add integrations
* 10/05/21 02_07_01 Modify integrations algorithm to simplify and improve query range
* 10/18/21 02_07_02 More changes to integrations and add synchronization of logs updates
*
*****************************************************************************************************/

Expand Down
28 changes: 20 additions & 8 deletions Firmware/IotaWatt/integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
// takes over with direct calls to create new entries at the
// same time as datalog records, eliminating race conditions.

uint32_t integrator_dispatch(struct serviceBlock* serviceBlock) {
const char intDirectory_P[] PROGMEM = IOTA_INTEGRATIONS_DIR;

uint32_t integrator_dispatch(struct serviceBlock* serviceBlock) {
trace(T_integrator,0);
integrator *_this = (integrator *)serviceBlock->serviceParm;
trace(T_integrator,1);
Expand Down Expand Up @@ -36,6 +38,20 @@ uint32_t integrator::dispatch(struct serviceBlock *serviceBlock)
return 0;
}

integrator::~integrator(){
_log->end();
String filepath(FPSTR(intDirectory_P));
filepath += "/";
filepath += _name;
filepath += ".log";
SD.remove(filepath.c_str());
log("%s: Integration log %s deleted.", _id, _name);
delete _log;
delete[] _name;
delete _oldRec;
delete _newRec;
};

uint32_t integrator::handle_initialize_s(){
trace(T_integrator,10);

Expand All @@ -47,21 +63,17 @@ uint32_t integrator::handle_initialize_s(){

// Insure /iotawatt/integrations exists.

char *dir = charstar(F(IOTA_INTEGRATIONS_DIR));

if( ! SD.exists(dir)){
if(!SD.mkdir(dir)){
if( ! SD.exists(FPSTR(intDirectory_P))){
if(!SD.mkdir(FPSTR(intDirectory_P))){
log("%s: could not create integration directory.", _id);
delete[] dir;
return 0;
}
}

// Open the integration log

trace(T_integrator,10);
String filepath(dir);
delete[] dir;
String filepath(FPSTR(intDirectory_P));
filepath += '/';
filepath += _name;
filepath += ".log";
Expand Down
9 changes: 2 additions & 7 deletions Firmware/IotaWatt/integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ class integrator {
_newRec(0),
_state(initialize_s){};

~integrator(){
delete _log;
delete[] _name;
delete _oldRec;
delete _newRec;
};

~integrator();

bool config(Script* script);
void setScript(Script* script);
void getStatusJson(JsonObject&);
Expand Down
2 changes: 1 addition & 1 deletion Firmware/IotaWatt/setConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ bool configIntegrations(const char* JsonStr){
oldScript = oldScript->next();
}

// Create integrators for new integratioons and call config for all.
// Create integrators for new integrations and call config for all.

newScript = newIntegrations->first();
while(newScript){
Expand Down
10 changes: 10 additions & 0 deletions SD/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ <h3 id="calcDisplay">0</h3>
var scriptEditIndex = -1;
var scriptEditSave;
var scriptEditReturn;
var scriptEditDelete;
var scriptEditNameList = [];
var scriptEditNameTitle = "";
var scriptEditNamePattern = "^[a-zA-Z]{1}[a-zA-Z0-9_]{0,15}$";
Expand Down Expand Up @@ -1473,6 +1474,9 @@ <h3 id="calcDisplay">0</h3>
EbyId("divIntegrations").style.display = "table";
configIntegrations();
};
scriptEditDelete = function(script){
return confirm("Deleting the integration will delete the integration log.");
}
scriptEditTable = EbyId("integrationsTable");
scriptEditTable.innerHTML = "";
scriptEditSet = config.integrations === undefined ? [] : config.integrations;
Expand Down Expand Up @@ -1614,6 +1618,7 @@ <h3 id="calcDisplay">0</h3>
editingScript = false;
scriptEditReturn();
}


function calcSave() {
if (scriptEditIndex < scriptEditSet.length) {
Expand All @@ -1639,6 +1644,11 @@ <h3 id="calcDisplay">0</h3>
}

function calcDelete() {
if(scriptEditDelete != undefined){
if(! scriptEditDelete(scriptEditSet[scriptEditIndex])){
return;
}
}
scriptEditSet.splice(scriptEditIndex, 1);
scriptEditSave();
currentBodyPop();
Expand Down

0 comments on commit e3d315d

Please sign in to comment.