Fossil SCM

Add click-to-sort on columns of the admin-log display.

drh 2017-08-30 13:12 trunk
Commit 703b57cfd1504b429768c4216c93fce43b659d88f8f43c5b7545cc01d9108be7
1 file changed +23 -36
+23 -36
--- src/setup.c
+++ src/setup.c
@@ -2154,64 +2154,46 @@
21542154
}
21552155
}
21562156
style_footer();
21572157
}
21582158
2159
-static void admin_log_render_limits(){
2160
- int const count = db_int(0,"SELECT COUNT(*) FROM admin_log");
2161
- int i;
2162
- int limits[] = {
2163
- 10, 20, 50, 100, 250, 500, 0
2164
- };
2165
- for(i = 0; limits[i]; ++i ){
2166
- cgi_printf("%s<a href='?n=%d'>%d</a>",
2167
- i ? " " : "",
2168
- limits[i], limits[i]);
2169
- if(limits[i]>count) break;
2170
- }
2171
-}
2172
-
21732159
/*
21742160
** WEBPAGE: admin_log
21752161
**
21762162
** Shows the contents of the admin_log table, which is only created if
21772163
** the admin-log setting is enabled. Requires Admin or Setup ('a' or
21782164
** 's') permissions.
21792165
*/
21802166
void page_admin_log(){
2181
- Stmt stLog = empty_Stmt;
2182
- Blob qLog = empty_blob;
2183
- int limit;
2167
+ Stmt stLog;
2168
+ int limit; /* How many entries to show */
2169
+ int ofst; /* Offset to the first entry */
21842170
int fLogEnabled;
21852171
int counter = 0;
21862172
login_check_credentials();
21872173
if( !g.perm.Setup && !g.perm.Admin ){
21882174
login_needed(0);
21892175
return;
21902176
}
21912177
style_header("Admin Log");
21922178
create_admin_log_table();
2193
- limit = atoi(PD("n","20"));
2179
+ limit = atoi(PD("n","200"));
2180
+ ofst = atoi(PD("x","0"));
21942181
fLogEnabled = db_get_boolean("admin-log", 0);
21952182
@ <div>Admin logging is %s(fLogEnabled?"on":"off").
21962183
@ (Change this on the <a href="setup_settings">settings</a> page.)</div>
21972184
2198
-
2199
- @ <div>Limit results to: <span>
2200
- admin_log_render_limits();
2201
- @ </span></div>
2202
-
2203
- blob_append_sql(&qLog,
2204
- "SELECT datetime(time,'unixepoch'), who, page, what "
2205
- "FROM admin_log "
2206
- "ORDER BY time DESC ");
2207
- if(limit>0){
2208
- @ %d(limit) Most recent entries:
2209
- blob_append_sql(&qLog, "LIMIT %d", limit);
2210
- }
2211
- db_prepare(&stLog, "%s", blob_sql_text(&qLog));
2212
- blob_reset(&qLog);
2185
+ if( ofst>0 ){
2186
+ int prevx = ofst - limit;
2187
+ if( prevx<0 ) prevx = 0;
2188
+ @ <p><a href="admin_log?n=%d(limit)&x=%d(prevx)">[Newer]</a></p>
2189
+ }
2190
+ db_prepare(&stLog,
2191
+ "SELECT datetime(time,'unixepoch'), who, page, what "
2192
+ "FROM admin_log "
2193
+ "ORDER BY time DESC");
2194
+
22132195
@ <table id="adminLogTable" class="adminLogTable" width="100%%">
22142196
@ <thead>
22152197
@ <th>Time</th>
22162198
@ <th>User</th>
22172199
@ <th>Page</th>
@@ -2220,21 +2202,26 @@
22202202
while( SQLITE_ROW == db_step(&stLog) ){
22212203
const char *zTime = db_column_text(&stLog, 0);
22222204
const char *zUser = db_column_text(&stLog, 1);
22232205
const char *zPage = db_column_text(&stLog, 2);
22242206
const char *zMessage = db_column_text(&stLog, 3);
2225
- @ <tr class="row%d(counter++%2)">
2207
+ counter++;
2208
+ if( counter<ofst ) continue;
2209
+ if( counter>ofst+limit ) break;
2210
+ @ <tr class="row%d(counter%2)">
22262211
@ <td class="adminTime">%s(zTime)</td>
22272212
@ <td>%s(zUser)</td>
22282213
@ <td>%s(zPage)</td>
22292214
@ <td>%h(zMessage)</td>
22302215
@ </tr>
22312216
}
22322217
@ </tbody></table>
2233
- if(limit>0 && counter<limit){
2234
- @ <div>%d(counter) entries shown.</div>
2218
+ if( counter>ofst+limit ){
2219
+ @ <p><a href="admin_log?n=%d(limit)&x=%d(limit+ofst)">[Older]</a></p>
22352220
}
2221
+
2222
+ output_table_sorting_javascript("adminLogTable", "Tttx", 1);
22362223
style_footer();
22372224
}
22382225
22392226
/*
22402227
** WEBPAGE: srchsetup
22412228
--- src/setup.c
+++ src/setup.c
@@ -2154,64 +2154,46 @@
2154 }
2155 }
2156 style_footer();
2157 }
2158
2159 static void admin_log_render_limits(){
2160 int const count = db_int(0,"SELECT COUNT(*) FROM admin_log");
2161 int i;
2162 int limits[] = {
2163 10, 20, 50, 100, 250, 500, 0
2164 };
2165 for(i = 0; limits[i]; ++i ){
2166 cgi_printf("%s<a href='?n=%d'>%d</a>",
2167 i ? " " : "",
2168 limits[i], limits[i]);
2169 if(limits[i]>count) break;
2170 }
2171 }
2172
2173 /*
2174 ** WEBPAGE: admin_log
2175 **
2176 ** Shows the contents of the admin_log table, which is only created if
2177 ** the admin-log setting is enabled. Requires Admin or Setup ('a' or
2178 ** 's') permissions.
2179 */
2180 void page_admin_log(){
2181 Stmt stLog = empty_Stmt;
2182 Blob qLog = empty_blob;
2183 int limit;
2184 int fLogEnabled;
2185 int counter = 0;
2186 login_check_credentials();
2187 if( !g.perm.Setup && !g.perm.Admin ){
2188 login_needed(0);
2189 return;
2190 }
2191 style_header("Admin Log");
2192 create_admin_log_table();
2193 limit = atoi(PD("n","20"));
 
2194 fLogEnabled = db_get_boolean("admin-log", 0);
2195 @ <div>Admin logging is %s(fLogEnabled?"on":"off").
2196 @ (Change this on the <a href="setup_settings">settings</a> page.)</div>
2197
2198
2199 @ <div>Limit results to: <span>
2200 admin_log_render_limits();
2201 @ </span></div>
2202
2203 blob_append_sql(&qLog,
2204 "SELECT datetime(time,'unixepoch'), who, page, what "
2205 "FROM admin_log "
2206 "ORDER BY time DESC ");
2207 if(limit>0){
2208 @ %d(limit) Most recent entries:
2209 blob_append_sql(&qLog, "LIMIT %d", limit);
2210 }
2211 db_prepare(&stLog, "%s", blob_sql_text(&qLog));
2212 blob_reset(&qLog);
2213 @ <table id="adminLogTable" class="adminLogTable" width="100%%">
2214 @ <thead>
2215 @ <th>Time</th>
2216 @ <th>User</th>
2217 @ <th>Page</th>
@@ -2220,21 +2202,26 @@
2220 while( SQLITE_ROW == db_step(&stLog) ){
2221 const char *zTime = db_column_text(&stLog, 0);
2222 const char *zUser = db_column_text(&stLog, 1);
2223 const char *zPage = db_column_text(&stLog, 2);
2224 const char *zMessage = db_column_text(&stLog, 3);
2225 @ <tr class="row%d(counter++%2)">
 
 
 
2226 @ <td class="adminTime">%s(zTime)</td>
2227 @ <td>%s(zUser)</td>
2228 @ <td>%s(zPage)</td>
2229 @ <td>%h(zMessage)</td>
2230 @ </tr>
2231 }
2232 @ </tbody></table>
2233 if(limit>0 && counter<limit){
2234 @ <div>%d(counter) entries shown.</div>
2235 }
 
 
2236 style_footer();
2237 }
2238
2239 /*
2240 ** WEBPAGE: srchsetup
2241
--- src/setup.c
+++ src/setup.c
@@ -2154,64 +2154,46 @@
2154 }
2155 }
2156 style_footer();
2157 }
2158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2159 /*
2160 ** WEBPAGE: admin_log
2161 **
2162 ** Shows the contents of the admin_log table, which is only created if
2163 ** the admin-log setting is enabled. Requires Admin or Setup ('a' or
2164 ** 's') permissions.
2165 */
2166 void page_admin_log(){
2167 Stmt stLog;
2168 int limit; /* How many entries to show */
2169 int ofst; /* Offset to the first entry */
2170 int fLogEnabled;
2171 int counter = 0;
2172 login_check_credentials();
2173 if( !g.perm.Setup && !g.perm.Admin ){
2174 login_needed(0);
2175 return;
2176 }
2177 style_header("Admin Log");
2178 create_admin_log_table();
2179 limit = atoi(PD("n","200"));
2180 ofst = atoi(PD("x","0"));
2181 fLogEnabled = db_get_boolean("admin-log", 0);
2182 @ <div>Admin logging is %s(fLogEnabled?"on":"off").
2183 @ (Change this on the <a href="setup_settings">settings</a> page.)</div>
2184
2185 if( ofst>0 ){
2186 int prevx = ofst - limit;
2187 if( prevx<0 ) prevx = 0;
2188 @ <p><a href="admin_log?n=%d(limit)&x=%d(prevx)">[Newer]</a></p>
2189 }
2190 db_prepare(&stLog,
2191 "SELECT datetime(time,'unixepoch'), who, page, what "
2192 "FROM admin_log "
2193 "ORDER BY time DESC");
2194
 
 
 
 
 
2195 @ <table id="adminLogTable" class="adminLogTable" width="100%%">
2196 @ <thead>
2197 @ <th>Time</th>
2198 @ <th>User</th>
2199 @ <th>Page</th>
@@ -2220,21 +2202,26 @@
2202 while( SQLITE_ROW == db_step(&stLog) ){
2203 const char *zTime = db_column_text(&stLog, 0);
2204 const char *zUser = db_column_text(&stLog, 1);
2205 const char *zPage = db_column_text(&stLog, 2);
2206 const char *zMessage = db_column_text(&stLog, 3);
2207 counter++;
2208 if( counter<ofst ) continue;
2209 if( counter>ofst+limit ) break;
2210 @ <tr class="row%d(counter%2)">
2211 @ <td class="adminTime">%s(zTime)</td>
2212 @ <td>%s(zUser)</td>
2213 @ <td>%s(zPage)</td>
2214 @ <td>%h(zMessage)</td>
2215 @ </tr>
2216 }
2217 @ </tbody></table>
2218 if( counter>ofst+limit ){
2219 @ <p><a href="admin_log?n=%d(limit)&x=%d(limit+ofst)">[Older]</a></p>
2220 }
2221
2222 output_table_sorting_javascript("adminLogTable", "Tttx", 1);
2223 style_footer();
2224 }
2225
2226 /*
2227 ** WEBPAGE: srchsetup
2228

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button