From: Metabox Date: Fri, 4 Oct 2019 22:10:57 +0000 (+1000) Subject: bug fixes 9,10. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=6345e0bf2418a2c4b46ab1359054db373210d142;p=LifeLog.git bug fixes 9,10. --- diff --git a/Current Development Check List.md b/Current Development Check List.md index 3b05c75..f8fbfb7 100644 --- a/Current Development Check List.md +++ b/Current Development Check List.md @@ -1,22 +1,22 @@ # Branch Development LifeLog in Perl - Sun Stage v. 1.6 -*This page lists current development and issues being worked on in the LifeLog app. Being in the **Sun** stage, means there is a production environment. And usable, used. When the project reaches **Earth** stage. It will be at its final specification. No data structures or major new features can be added or requested anymore. Only bug fixes, enhancements and efficiency fixes, if any at the **Earth** stage.* +*This page lists current development and issues being worked on in the LifeLog app. Being in the **Sun** stage, means there is a production environment. And usable, used. When, the project reaches **Earth** stage. It will be at its final specification. No data structures or major new features can be added or requested anymore. Only bug fixes, enhancements and efficiency fixes, if any at the **Earth** stage.* This version is not compatible in data structure to prior versions. Data migration is required, to transfer previous data (see ../dbLifeLog/main.cnf). -## LifeLog +## LifeLog * Implement sticky log entries. * $CUR_MTH_SVIEW - Start view page is for current month, and the sticky set. * Some System settings to be stored in session. As these are known even before logon. > i.e. $SESSN_EXPR, $RELEASE_VER, $TIME_ZONE, $LOG_PATH -*✔ Dropdown for type of log amount (Mark as Expense). Default is Asset. Asset is neither, income or expense. -*✔ Implement RTF Documents. +* ✔ Dropdown for type of log amount (Mark as Expense). Default is Asset. Asset is neither, income or expense. +* ✔ Implement RTF Documents. > Useful as more document style formated details can be added instead of just plain text. *✔ Preserve Search view selections. After edits and submit. > * ✔ Preserve from to date selections. > * ✔ Date View not working on Local entered date format. -*✔ Sum selected, income, expense, totals. +*✔ Sum selected, income, expense, totals. ✔ Sum on view. @@ -69,8 +69,8 @@ This version is not compatible in data structure to prior versions. Data migrati >✔ Deletion of log, deletes the document. ## Bugs -* Bug - 10 Expense type entries don't field ammount field on edit button clicked. -* Bug - 09 RTF documents lost on data renumeration of log. Data fix options in config. Needs urgent revision. +* ✔ Bug - 10 Expense type entries don't fill ammount field on edit button clicked. +* ✔ Bug - 09 RTF documents lost on data renumeration of log. Data fix options in config. Needs urgent revision. * Bug - 08 CSV imports duplicate on DB Fix in config page. * Bug - 07, Editing and RTF entry, Dosen't strip the attached html to view in place. * ✔ Bug - 06, Invalid Time 00. Javascript error thrown, when 00am used. diff --git a/htdocs/cgi-bin/config.cgi b/htdocs/cgi-bin/config.cgi index 6865a28..3f1100f 100755 --- a/htdocs/cgi-bin/config.cgi +++ b/htdocs/cgi-bin/config.cgi @@ -704,7 +704,7 @@ sub processDBFix { my $wipe_ss = $cgi->param("wipe_syst"); - my $issue; + my $sql; my $date; my $cntr_upd =0; try{ @@ -717,7 +717,7 @@ try{ my $cntr_del =0; my $existing; my @row; - + $db->do('BEGIN TRANSACTION;'); #Check for duplicates, which are possible during imports or migration as internal rowid is not primary in log. $dbs = dbExecute('SELECT rowid, DATE FROM LOG ORDER BY DATE;'); @@ -733,48 +733,13 @@ try{ } foreach my $del (@dlts){ - $issue = "DELETE FROM LOG WHERE rowid=$del;"; - #print "$issue\n
"; - my $st_del = $db->prepare($issue); + $sql = "DELETE FROM LOG WHERE rowid=$del;"; + #print "$sql\n
"; + my $st_del = $db->prepare($sql); $st_del->execute(); } - #Renumerate Log! Copy into temp. table. - $dbs = dbExecute("CREATE TABLE life_log_temp_table AS SELECT * FROM LOG;"); - $dbs = dbExecute('SELECT rowid, DATE FROM LOG WHERE RTF == 1 ORDER BY DATE;'); - #update notes with new log id - while(@row = $dbs->fetchrow_array()) { - my $sql_date = $row[1]; - #$sql_date =~ s/T/ /; - $sql_date = DateTime::Format::SQLite->parse_datetime($sql_date); - $issue = "SELECT rowid, DATE FROM life_log_temp_table WHERE RTF = 1 AND DATE = '".$sql_date."';"; - $dbs = dbExecute($issue); - my @new = $dbs->fetchrow_array(); - if(scalar @new > 0){ - $db->do("UPDATE NOTES SET LID =". $new[0]." WHERE LID==".$row[0].";"); - } - } - - # Delete Orphaned Notes entries. - $dbs = dbExecute("SELECT LID, LOG.rowid from NOTES LEFT JOIN LOG ON - NOTES.LID = LOG.rowid WHERE LOG.rowid is NULL;"); - while(my @row = $dbs->fetchrow_array()) { - $db->do("DELETE FROM NOTES WHERE LID=$row[0];"); - } - $dbs = dbExecute('DROP TABLE LOG;'); - $dbs = dbExecute(qq(CREATE TABLE LOG ( - ID_CAT TINY NOT NULL, - DATE DATETIME NOT NULL, - LOG VCHAR (128) NOT NULL, - AMOUNT INTEGER, - AFLAG TINY DEFAULT 0, - RTF BOOL DEFAULT 0);)); - $dbs = dbExecute('INSERT INTO LOG (ID_CAT,DATE,LOG,AMOUNT,AFLAG, RTF) - SELECT ID_CAT, DATE, LOG, AMOUNT, AFLAG, RTF - FROM life_log_temp_table ORDER by DATE;'); - $dbs = dbExecute('DROP TABLE life_log_temp_table;'); - - + &renumerate; &resetCategories if $rs_cats; &resetSystemConfiguration($db) if $rs_syst; &wipeSystemConfiguration if $wipe_ss; @@ -792,7 +757,7 @@ try{ } catch{ $db->do('ROLLBACK;'); - die qq(@&processDBFix error:$_ with statement->$issue for $date update counter:$cntr_upd); + die qq(@&processDBFix error:$_ with statement->$sql for $date update counter:$cntr_upd); } } @@ -979,20 +944,20 @@ sub importCatCSV { updateCATDB(@flds); }else{ warn "Data could not be parsed: $line\n"; - } + } } } sub updateCATDB { my @flds = @_; if(@flds>2){ - try{ + try{ my $id = $flds[0]; my $name = $flds[1]; my $desc = $flds[2]; - + #is it existing entry? - $dbs = dbExecute("SELECT ID, NAME, DESCRIPTION FROM CAT WHERE ID = '$id';"); + $dbs = dbExecute("SELECT ID, NAME, DESCRIPTION FROM CAT WHERE ID = '$id';"); if(not defined $dbs->fetchrow_array()){ $dbs = $db->prepare('INSERT INTO CAT VALUES (?,?,?)'); $dbs->execute($id, $name, $desc); @@ -1001,25 +966,28 @@ sub updateCATDB { else{ #TODO Update } - + } catch{ print "SERVER ERROR->updateCATDB:".$_; } } } + sub importLogCSV { my $hndl = $cgi->upload("data_log"); - my $csv = Text::CSV->new ( { binary => 1, strict => 1, eol => $/ } ); + my $csv = Text::CSV->new ( { binary => 1, strict => 1, eol => $/ } ); + while (my $line = <$hndl>) { chomp $line; - if ($csv->parse($line)) { + if ($csv->parse($line)) { my @flds = $csv->fields(); updateLOGDB(@flds); }else{ warn "Data could not be parsed: $line\n"; - } - } + } + } + &renumerate; $db->disconnect(); print $cgi->redirect('main.cgi'); exit; @@ -1028,7 +996,7 @@ sub importLogCSV { sub updateLOGDB { my @flds = @_; if(@flds>3){ - try{ + try{ my $id_cat = $flds[0]; my $date = $flds[1]; my $log = $flds[2]; @@ -1042,24 +1010,15 @@ sub updateLOGDB { return; } #is it existing entry? - $dbs = $db->prepare("SELECT ID_CAT, DATE, LOG, AMOUNT, AFLAG, RTF FROM LOG WHERE date = '$date';"); + my $sql = "SELECT DATE FROM LOG WHERE DATE is '$pdate';"; + $dbs = $db->prepare($sql); $dbs->execute(); - if(!$dbs->fetchrow_array()){ - $dbs = $db->prepare('INSERT INTO LOG VALUES (?,?,?,?,?,?, ?)'); - $dbs->execute( $id_cat, $pdate, $log, $amv, $amf, $rtf, $sticky); + my @rows = $dbs->fetchrow_array(); + if(scalar @rows == 0){ + $dbs = $db->prepare('INSERT INTO LOG VALUES (?,?,?,?,?,?,?)'); + $dbs->execute( $id_cat, $pdate, $log, $amv, $amf, $rtf, $sticky); } - #Renumerate - # $dbs = $db->prepare('select rowid from LOG ORDER BY DATE;'); - # $dbs->execute(); - # my @row = $dbs->fetchrow_array(); - # my $cnt = 1; - # while(my @row = $dbs->fetchrow_array()) { - # my $st_upd = $db->prepare("UPDATE LOG SET rowid=".$cnt. - # " WHERE rowid='".$row[0]."';"); - # $st_upd->execute(); - # $cnt = $cnt + 1; - # } - #$dbs->finish; + $dbs->finish(); } catch{ print "SERVER ERROR->exportLogToCSV:".$_; @@ -1141,4 +1100,45 @@ sub getTheme{ $BGCOL = 'green'; } +} + + +sub renumerate { + #Renumerate Log! Copy into temp. table. + my $sql; + $dbs = dbExecute("CREATE TABLE life_log_temp_table AS SELECT * FROM LOG;"); + $dbs = dbExecute('SELECT rowid, DATE FROM LOG WHERE RTF == 1 ORDER BY DATE;'); + #update notes with new log id + while(my @row = $dbs->fetchrow_array()) { + my $sql_date = $row[1]; + #$sql_date =~ s/T/ /; + $sql_date = DateTime::Format::SQLite->parse_datetime($sql_date); + $sql = "SELECT rowid, DATE FROM life_log_temp_table WHERE RTF = 1 AND DATE = '".$sql_date."';"; + $dbs = dbExecute($sql); + my @new = $dbs->fetchrow_array(); + if(scalar @new > 0){ + $db->do("UPDATE NOTES SET LID =". $new[0]." WHERE LID==".$row[0].";"); + } + } + + # Delete Orphaned Notes entries. + $dbs = dbExecute("SELECT LID, LOG.rowid from NOTES LEFT JOIN LOG ON + NOTES.LID = LOG.rowid WHERE LOG.rowid is NULL;"); + while(my @row = $dbs->fetchrow_array()) { + $db->do("DELETE FROM NOTES WHERE LID=$row[0];"); + } + $dbs = dbExecute('DROP TABLE LOG;'); + $dbs = dbExecute(qq(CREATE TABLE LOG ( + ID_CAT TINY NOT NULL, + DATE DATETIME NOT NULL, + LOG VCHAR (128) NOT NULL, + AMOUNT INTEGER, + AFLAG TINY DEFAULT 0, + RTF BOOL DEFAULT 0, + STICKY BOOL DEFAULT 0 + );)); + $dbs = dbExecute('INSERT INTO LOG (ID_CAT,DATE,LOG,AMOUNT,AFLAG, RTF) + SELECT ID_CAT, DATE, LOG, AMOUNT, AFLAG, RTF + FROM life_log_temp_table ORDER by DATE;'); + $dbs = dbExecute('DROP TABLE life_log_temp_table;'); } \ No newline at end of file diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 83147fa..791b9ac 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -909,7 +909,7 @@ return $today; #last_insert_id() -> Not reliable commented out. #my $gzero = $db->last_insert_id();#//$db->prepare('SELECT last_insert_rowid();'); $st->finish(); - $st = $db->prepare('SELECT rowid FROM LOG ORDER BY rowid DESC LIMIT 1;'); + $st = $db->prepare('SELECT rowid FROM LOG ORDER BY rowid DESC LIMIT 1;'); $st -> execute(); my @lid = $st->fetchrow_array(); $st = $db->prepare("SELECT DOC FROM NOTES WHERE LID = '0';"); diff --git a/htdocs/cgi-bin/wsrc/main.js b/htdocs/cgi-bin/wsrc/main.js index d11ae21..9426696 100644 --- a/htdocs/cgi-bin/wsrc/main.js +++ b/htdocs/cgi-bin/wsrc/main.js @@ -144,15 +144,14 @@ function loadedBody(toggle) { // toggleDocument(); } + var rgb = $('#editor-container').css('background-color'); + if(rgb){ + DEF_BACKGROUND = RGBToHex(rgb); + $("#fldBG").val(DEF_BACKGROUND); + var amf = $( "#amf" );//Amount Field Type dropdown + var ec = $( "#ec" ); //Category dropdown - DEF_BACKGROUND = RGBToHex($('#editor-container').css('background-color')); - $("#fldBG").val(DEF_BACKGROUND); - - // $( function() { - var amf = $( "#amf" );//Amount Field Type dropdown - var ec = $( "#ec" ); //Category dropdown - - $( amf ).selectmenu({style: "dropdown", width:120, + $( amf ).selectmenu({style: "dropdown", width:120, change: function( event, data ) { var evv =ec.val(); if(ec.val()<2||evv==32||evv==35||data.item.value == 0){ @@ -166,8 +165,7 @@ function loadedBody(toggle) { } } }}); - - + } } @@ -292,7 +290,7 @@ function edit(row) { var tag = $("#g" + row); //orig. tagged log text. var log = $("#v" + row); //log var rtf = $("#r" + row); //RTF doc - var amf = $("#f" + row); //Amount type. + var amt = $("#f" + row); //Amount type. var isRTF = (rtf.val()>0?true:false); if(!isRTF){ $('#rtf_doc').hide(); @@ -306,11 +304,11 @@ function edit(row) { $("#el").val(decodeToHTMLText(tag.val())); } else { - $("#el").val(decodeToText(log.html())); + $("#el").val(decodeToText(log.text())); } $("#ed").val(ed_v.val() + " " + et_v.html()); //Time field - var val = ea_v.html(); + var val = ea_v.text(); val = val.replace(/\,/g,""); $("#am").val(val); //Amount field, fix 04-08-2019 HTML input doesn't accept formated string. $("#RTF").prop('checked', isRTF); @@ -324,8 +322,8 @@ function edit(row) { $("#ec option:contains(" + ec_v + ")").prop('selected', true); $("#submit_is_edit").val(row); - - ec_v = amf.val(); + //Amount type + ec_v = amt.val(); $("#amf").focus(); $("#amf").val(ec_v); $("#amf").selectmenu('refresh');