From: Will Budicm Date: Fri, 25 Dec 2020 09:14:01 +0000 (+1100) Subject: Page view by category exclusion from tody option. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=4522b03cd33cf5dc3fbf036f09d6264813f5ac16;p=LifeLog.git Page view by category exclusion from tody option. --- diff --git a/Current Development Check List.md b/Current Development Check List.md index a2957f7..4cb4fb4 100644 --- a/Current Development Check List.md +++ b/Current Development Check List.md @@ -6,6 +6,8 @@ ### v.2.2 EARTH RC 1 +* ✔ Page categories exclusion option in main.cnf. Log view server side is modified not to include excluded categories +older by certain amount of days, default is 0, for from today older. * Search on multiple words should rank by encounter of words specified and display first. (That one is difficult) * Auto collapse/expand on multi line logs by 0-none as default. Setting to 1 or more shows only that number of lines. (That one is difficult) diff --git a/dbLifeLog/main.cnf b/dbLifeLog/main.cnf index 8f2d551..92c1a6a 100644 --- a/dbLifeLog/main.cnf +++ b/dbLifeLog/main.cnf @@ -25,9 +25,14 @@ and override any previously set from now on, top to end of file approach. # By default this setting is disabled with 0, making alias name, its own log database, per user. < -#Timezoning, if set to 1, country locale setting for timezone in config page is ignored. +# Timezoning, if set to 1, country locale setting for timezone in config page is ignored. < +# Setting to modify the page view to exclude older log entries by a list of categories from today minus days back. +# This is to avoid and page only list relevant logs on logon. Searching by category will list them and still make visible. +# value: {days=}{category id},.. days default to zero, if you don't want from yesterday to the past category entries listed. +< <- (Diary,System Log,Poetry) category id's only, does set in the config page also work. + # Public, enabled list of categories. Remove -> '!' prefix before tag name, to enable. Be careful what category you add/enable here. # Public records view feature only, it doesn't allow new log entries to be added and have pin point searching of all existing. diff --git a/htdocs/cgi-bin/config.cgi b/htdocs/cgi-bin/config.cgi index fe2f679..b63228c 100755 --- a/htdocs/cgi-bin/config.cgi +++ b/htdocs/cgi-bin/config.cgi @@ -1103,9 +1103,9 @@ sub restore { print "\n\nMerging from backup LOG table...\n"; my $insLOG = $db->prepare('INSERT INTO LOG (ID_CAT, ID_RTF, DATE, LOG, AMOUNT, AFLAG, STICKY) VALUES(?,?,?,?,?,?,?);')or die "Failed LOG prepare."; - $b_pst = Settings::selectRecords($b_db,'SELECT ID, ID_CAT, ID_RTF, DATE, LOG, AMOUNT, AFLAG, STICKY FROM VW_LOG;'); + $b_pst = Settings::selectRecords($b_db,'SELECT ID, ID_CAT, ID_RTF, DATE, LOG, AMOUNT, AFLAG, STICKY FROM '.Settings->VW_LOG); while ( @br = $b_pst->fetchrow_array() ) { - my $pst = Settings::selectRecords($db,"SELECT DATE FROM VW_LOG WHERE DATE='".$br[3]."';"); + my $pst = Settings::selectRecords($db,"SELECT DATE FROM ".Settings->VW_LOG." WHERE DATE='".$br[3]."';"); my @ext = $pst->fetchrow_array(); if(scalar(@ext)==0){ $insLOG->execute($br[1],$br[2],$br[3],$br[4],$br[5],$br[6],$br[7]); diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi index 4630bbd..3272927 100755 --- a/htdocs/cgi-bin/login_ctr.cgi +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -32,7 +32,7 @@ my $SCRIPT_RELEASE = Settings::release(); my $BACKUP_ENABLED = 0; my $AUTO_SET_TIMEZONE = 0; my $TIME_ZONE_MAP = 0; -my $DB_NAME; +my ($DB_NAME,$PAGE_EXCLUDES); try{ checkAutologinSet(); @@ -157,10 +157,13 @@ sub checkAutologinSet { $TIME_ZONE_MAP .= $line . "\n"; } next; - } + } + $v = Settings::parseAutonom('PAGE_VIEW_EXCLUDES',$line); + if($v){$PAGE_EXCLUDES=$v;next} last if Settings::parseAutonom('CONFIG',$line); #By specs the config tag, is not an autonom, if found we stop reading. So better be last one spec. in file. } close $fh; + # Autologin credential in file next. if(@cre &&scalar(@cre)>1){ if($alias && $passw && $alias ne $cre[0]){ # Is this an new alias login attempt? If so, autologin is of the agenda. @@ -170,7 +173,8 @@ sub checkAutologinSet { $db = Settings::connectDB($alias, $passw); #check if autologin enabled. my $st = Settings::selectRecords($db,"SELECT VALUE FROM CONFIG WHERE NAME='AUTO_LOGIN';"); - if($st){my @set = $st->fetchrow_array(); + if($st){ + my @set = $st->fetchrow_array(); if($set[0]=="1"){ $alias = $cre[0]; $passw = $passw; @@ -183,7 +187,6 @@ sub checkAutologinSet { } - sub checkPreparePGDB { my $create =1; $passw = $cgi->param('passw'); #We let PG handles password encryption (security) itself. @@ -321,7 +324,7 @@ try{ } if($DB_VERSION > 1.6){ #is above v.1.6 notes table. - $db->do('DROP TABLE VW_LOG;'); + $db->do('DROP TABLE '.Settings->VW_LOG); } $db->do('DROP TABLE LOG;'); #v.1.8 Has fixes, time also properly to take into the sort. Not crucial to drop. @@ -358,8 +361,8 @@ try{ } elsif($hasLogTbl && $SCRIPT_RELEASE > $DB_VERSION && $DB_VERSION < 2.0){ #dev 1.9 main log view has changed in 1.8..1.9, above scope will perform anyway, its drop, to be recreated later. - $db->do('DROP VIEW VW_LOG;');delete($curr_tables{'VW_LOG'}); - delete($curr_tables{'VW_LOG'}); + $db->do('DROP VIEW '.Settings->VW_LOG);delete($curr_tables{Settings->VW_LOG}); + delete($curr_tables{Settings->VW_LOG}); $changed = 1; }elsif($SCRIPT_RELEASE > $DB_VERSION){$changed = 1;} @@ -382,8 +385,31 @@ try{ # From v.1.6 view uses server side views, for pages and correct record by ID and PID lookups. # This should make queries faster, less convulsed, and log renumeration less needed for accurate pagination. - if(!$curr_tables{'VW_LOG'}) { - $db->do(Settings::createViewLOGStmt()) or LifeLogException -> throw("ERROR:".$@) ; + if(!$curr_tables{Settings->VW_LOG}) { + $db->do(Settings::createViewLOGStmt()) or LifeLogException -> throw("ERROR:".$@); + } + if(!$curr_tables{Settings->VW_LOG_WITH_EXCLUDES}) { + # To cover all possible situations, this test elses too. + # As an older existing view might need to be recreated, to keep in synch. + if($PAGE_EXCLUDES){ + $db->do(createPageViewExcludeSQL()); + Settings::configProperty($db, 204, '^PAGE_EXCLUDES',$PAGE_EXCLUDES); + } + }else{ # Updating here too if excludes in config file have been removed. + my @ret=Settings::selectRecords($db, "SELECT value FROM CONFIG WHERE NAME='^PAGE_EXCLUDES';")->fetchrow_array(); + if(!$ret[0] && $PAGE_EXCLUDES){ + $db->do('DROP VIEW '.Settings->VW_LOG_WITH_EXCLUDES); + $db->do(createPageViewExcludeSQL()); + Settings::configProperty($db, 204, '^PAGE_EXCLUDES',$PAGE_EXCLUDES); + + }elsif($ret[0]){ + if($PAGE_EXCLUDES && $PAGE_EXCLUDES ne $ret[0]){ + $db->do('DROP VIEW '.Settings->VW_LOG_WITH_EXCLUDES); + $db->do(createPageViewExcludeSQL()); + }{ + $db->do("DELETE FROM CONFIG WHERE NAME='^PAGE_EXCLUDES'"); + } + } } if(!$curr_tables{'CAT'}) { @@ -427,8 +453,8 @@ try{ my $t = uc substr($_,7); $curr_tables{$t} = 1; } - if(!$curr_tables{'VW_LOG'}) { - LifeLogException -> throw("VW_LOG not created! Try logging in again."); + if(!$curr_tables{Settings->VW_LOG}) { + LifeLogException -> throw(Settings->VW_LOG." not created! Try logging in again."); } } @@ -472,6 +498,26 @@ try{ } } +sub createPageViewExcludeSQL { + + my $days = 0; + my $parse = $PAGE_EXCLUDES; + my @a = split('=',$parse); + if(scalar(@a)==2){ + $days = $a[0]; + $parse = $a[1]; + } + my $where =qq(WHERE date >= date('now', '-$days day') OR); + @a = split(',',$parse); + foreach (@a){ + $where .= " ID_CAT!=$_ AND"; + } + $where =~ s/\s+OR$//; + $where =~ s/\s+AND$//; + return Settings::createViewLOGStmt(Settings->VW_LOG_WITH_EXCLUDES,$where); + +} + sub populate { diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 9e8eed5..06bae75 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -29,6 +29,7 @@ my $sid = Settings::sid(); my $dbname = Settings::dbName(); my $alias = Settings::alias(); my $passw = Settings::pass(); +my $VW_PAGE = Settings->VW_LOG; my $sssCDB = $sss->param('cdb'); my ($vmode, $imgw, $imgh ); @@ -56,7 +57,13 @@ my $rs_dat_to = $cgi->param('v_to'); my $rs_prev = $cgi->param('rs_prev'); my $rs_cur = $cgi->param('rs_cur'); my $rs_page = $cgi->param('rs_page'); -my $sqlView = 'SELECT ID, ID_CAT, ID_RTF, DATE, LOG, AMOUNT, AFLAG, STICKY, PID FROM VW_LOG';#Only to be found here, the main SQL select statement. +if(Settings::anon('^PAGE_EXCLUDES')){ + if(!$cgi->param('srch_reset')&&!$prm_vc&&!$prm_vc_lst&&!$prm_aa&&!$prm_rtf&&!$prm_xc&&!$prm_xc_lst&&!$rs_dat_from&&!$rs_dat_to&&!$rs_keys){ + $VW_PAGE = Settings->VW_LOG_WITH_EXCLUDES; + } +} + +my $sqlView = 'SELECT ID, ID_CAT, ID_RTF, DATE, LOG, AMOUNT, AFLAG, STICKY, PID FROM '.$VW_PAGE;#Only to be found here, the main SQL select statement. my $stmS = $sqlView." WHERE"; my $stmE = ' LIMIT '.&Settings::viewAllLimit.';'; my $stmD = ""; @@ -367,7 +374,7 @@ qq(
if ( $log_start > 0 ) { #check if we are at the beggining of the LOG table? - my $stc = traceDBExe('SELECT PID from VW_LOG LIMIT 1;'); + my $stc = traceDBExe('SELECT PID from '.$VW_PAGE.' LIMIT 1;'); my @row = $stc->fetchrow_array(); $log_top = $row[0]; if ($log_top == $rs_prev && $rs_cur == $rs_prev ) { @@ -403,10 +410,10 @@ sub traceDBExe { return $st; }catch{ #BUG 31 fix. - if(Settings::isProgressDB() && index($sql,'VW_LOG')>0){ + if(Settings::isProgressDB() && index($sql,Settings->VW_LOG)>0){ $db -> do(Settings::createViewLOGStmt()); my $st = $db->prepare($sql); - $st -> execute() or LifeLogException->throw("Execute failed [$DBI::errstri]", show_trace=>1); + $st -> execute() or LifeLogException->throw("Execute failed [$DBI::errstri]", show_trace=>1); return $st; } LifeLogException->throw(error=>"DSN: [".Settings::dsn()."] Error encountered -> $@", show_trace=>1); @@ -1151,7 +1158,7 @@ try { } if($rtf){ #Update 0 ground NOTES entry to the just inserted log. - $st = traceDBExe('SELECT ID FROM VW_LOG LIMIT 1;'); + $st = traceDBExe('SELECT ID FROM '.Settings->VW_LOG.' LIMIT 1;'); my @lid = $st->fetchrow_array(); $st = traceDBExe('SELECT DOC FROM NOTES WHERE LID = 0;'); my @gzero = $st->fetchrow_array(); @@ -1304,7 +1311,7 @@ sub authenticate { } sub fetchAutocomplete { - my $st = traceDBExe('SELECT LOG from LOG' . $stmE ); + my $st = traceDBExe('SELECT LOG from LOG' . $stmE.';;' ); while ( my @row = $st->fetchrow_array() ) { my ($wl,$log) = ("",$row[0]); diff --git a/htdocs/cgi-bin/testSettings.pl b/htdocs/cgi-bin/testSettings.pl index bd9ca92..009057c 100755 --- a/htdocs/cgi-bin/testSettings.pl +++ b/htdocs/cgi-bin/testSettings.pl @@ -39,16 +39,41 @@ require CNFParser; # Settings obtains from file escalated for anons to database configuration # Currently we don't have an database set, and don't need it for this tester script. # So we read and process the main.cnf file in via parser and transfer into Settings; -my $cnf = CNFParser->new($ENV{'PWD'}.'/dbLifeLog/main.cnf'); -my $ptr = $cnf->anons(); -Settings::anonsSet($ptr); -my $time = Settings::today(); -my $cnf_tz = Settings::timezone(); -my $ret = Settings::setTimezone(undef, 'America/Texas'); -my $a = Settings::anon('TIME_ZONE_MAP'); +# my $cnf = CNFParser->new($ENV{'PWD'}.'/dbLifeLog/main.cnf'); +# my $ptr = $cnf->anons(); +# Settings::anonsSet($ptr); +# my $time = Settings::today(); +# my $cnf_tz = Settings::timezone(); +# my $ret = Settings::setTimezone(undef, 'America/Texas'); +# my $a = Settings::anon('TIME_ZONE_MAP'); +use constant VW_LOG_WITH_EXCLUDES => "TEST_VIEW"; +# print "tz:".$cnf_tz." time:". $time. "\n", $a , "\n\nTime America/Texas:$ret\n"; +my $PAGE_EXCLUDES = "1=88,6"; + +print "SELECT * from LOG ",createPageViewSQL(), "\n"; + +# SELECT rowid as ID,*, (select count(rowid) from LOG as recount where a.rowid >= recount.rowid) as PID +# FROM LOG as a WHERE (ID_CAT!=88 AND ID_CAT!=6) OR date >= date('now', '-1 day') ORDER BY Date(DATE) DESC, Time(DATE) DESC; + + sub createPageViewSQL { + my $days = 1; + my $parse = $PAGE_EXCLUDES; + my @a = split('=',$parse); + if(scalar(@a)==2){ + $days = $a[0]; + $parse = $a[1]; + } + my $where =qq(WHERE date >= date('now', '-$days day') OR); + @a = split(',',$parse); + foreach (@a){ + $where .= " ID_CAT!=$_ AND"; + } + $where =~ s/\s+OR$//; + $where =~ s/\s+AND$//; + return Settings::createViewLOGStmt(VW_LOG_WITH_EXCLUDES,$where); + } -print "tz:".$cnf_tz." time:". $time. "\n", $a , "\n\nTime America/Texas:$ret\n"; 1; \ No newline at end of file