console/content/action/regenerate-auto.sql
-- code provenance: `ConsoleSqlPages.infoSchemaContentDML` (file:///app/www.surveilr.com/lib/std/web-ui-content/console.ts)
-- the "auto-generated" tables will be in '*.auto.sql' with redirects
DELETE FROM sqlpage_files WHERE path like 'console/content/table/%.auto.sql';
DELETE FROM sqlpage_files WHERE path like 'console/content/view/%.auto.sql';
INSERT OR REPLACE INTO sqlpage_files (path, contents)
SELECT
'console/content/' || tabular_nature || '/' || tabular_name || '.auto.sql',
'SELECT ''dynamic'' AS component, sqlpage.run_sql(''shell/shell.sql'') AS properties;
SELECT ''breadcrumb'' AS component;
SELECT ''Home'' as title,sqlpage.environment_variable(''SQLPAGE_SITE_PREFIX'') || ''/'' AS link;
SELECT ''Console'' as title,sqlpage.environment_variable(''SQLPAGE_SITE_PREFIX'') || ''/console'' AS link;
SELECT ''Content'' as title,sqlpage.environment_variable(''SQLPAGE_SITE_PREFIX'') || ''/console/content'' AS link;
SELECT ''' || tabular_name || ' ' || tabular_nature || ''' as title, ''#'' AS link;
SELECT ''title'' AS component, ''' || tabular_name || ' (' || tabular_nature || ') Content'' as contents;
SET total_rows = (SELECT COUNT(*) FROM ' || tabular_name || ');
SET limit = COALESCE($limit, 50);
SET offset = COALESCE($offset, 0);
SET total_pages = ($total_rows + $limit - 1) / $limit;
SET current_page = ($offset / $limit) + 1;
SELECT ''text'' AS component, ''' || info_schema_link_full_md || ''' AS contents_md
SELECT ''text'' AS component,
''- Start Row: '' || $offset || ''
'' ||
''- Rows per Page: '' || $limit || ''
'' ||
''- Total Rows: '' || $total_rows || ''
'' ||
''- Current Page: '' || $current_page || ''
'' ||
''- Total Pages: '' || $total_pages as contents_md
WHERE $stats IS NOT NULL;
-- Display uniform_resource table with pagination
SELECT ''table'' AS component,
TRUE AS sort,
TRUE AS search,
TRUE AS hover,
TRUE AS striped_rows,
TRUE AS small;
SELECT * FROM ' || tabular_name || '
LIMIT $limit
OFFSET $offset;
SELECT ''text'' AS component,
(SELECT CASE WHEN $current_page > 1 THEN ''[Previous](?limit='' || $limit || ''&offset='' || ($offset - $limit) || '')'' ELSE '''' END) || '' '' ||
''(Page '' || $current_page || '' of '' || $total_pages || '') '' ||
(SELECT CASE WHEN $current_page < $total_pages THEN ''[Next](?limit='' || $limit || ''&offset='' || ($offset + $limit) || '')'' ELSE '''' END)
AS contents_md;'
FROM console_content_tabular;
INSERT OR IGNORE INTO sqlpage_files (path, contents)
SELECT
'console/content/' || tabular_nature || '/' || tabular_name || '.sql',
'SELECT ''redirect'' AS component,sqlpage.environment_variable(''SQLPAGE_SITE_PREFIX'') || ''/console/content/' || tabular_nature || '/' || tabular_name || '.auto.sql'' AS link WHERE $stats IS NULL;
' ||
'SELECT ''redirect'' AS component,sqlpage.environment_variable(''SQLPAGE_SITE_PREFIX'') || ''/console/content/' || tabular_nature || '/' || tabular_name || '.auto.sql?stats='' || $stats AS link WHERE $stats IS NOT NULL;'
FROM console_content_tabular;
-- TODO: add ${this.upsertNavSQL(...)} if we want each of the above to be navigable through DB rows
-- code provenance: `ConsoleSqlPages.console/content/action/regenerate-auto.sql` (file:///app/www.surveilr.com/lib/std/web-ui-content/console.ts)
SELECT 'redirect' AS component, sqlpage.environment_variable('SQLPAGE_SITE_PREFIX') || '/console/sqlpage-files/content.sql' as link WHERE $redirect is NULL;
SELECT 'redirect' AS component, sqlpage.environment_variable('SQLPAGE_SITE_PREFIX') || $redirect as link WHERE $redirect is NOT NULL;