Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
feat: add DRH logo and links in edge UI #222
Browse files Browse the repository at this point in the history
  • Loading branch information
Siju Joseph committed Sep 25, 2024
1 parent af39c36 commit 23c8f11
Show file tree
Hide file tree
Showing 3 changed files with 332 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
234 changes: 234 additions & 0 deletions service/diabetes-research-hub/sqlpage/templates/shell.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
<!DOCTYPE html>
<html lang="{{language}}" style="font-size: {{default font_size 18}}px" {{#if class}}class="{{class}}" {{/if}}>
<head>
<meta charset="utf-8" />
<title>{{default title "SQLPage"}}</title>
<link rel="icon" href="{{#if favicon}}{{favicon}}{{else}}{{static_path 'favicon.svg'}}{{/if}}">
{{#if manifest}}
<link rel="manifest" href="{{manifest}}">
{{/if}}
<link rel="stylesheet" href="{{static_path 'sqlpage.css'}}">
{{#each (to_array css)}}
{{#if this}}
<link rel="stylesheet" href="{{this}}">
{{/if}}
{{/each}}

{{#if font}}
{{#if (starts_with font "/")}}
<style>
@font-face {
font-family: 'LocalFont';
src: url('{{font}}') format('woff2');
font-weight: normal;
font-style: normal;
}
:root {
--tblr-font-sans-serif: 'LocalFont', Arial, sans-serif;
}
</style>
{{else}}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family={{font}}&display=fallback">
<style>
:root {
--tblr-font-sans-serif: '{{font}}',
Arial,
sans-serif;
}
</style>
{{/if}}
{{/if}}

<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,container-queries"></script>
<script src="https://unpkg.com/@alenaksu/[email protected]/dist/json-viewer.bundle.js"></script>

<script src="{{static_path 'sqlpage.js'}}" defer nonce="{{@csp_nonce}}"></script>
{{#each (to_array javascript)}}
{{#if this}}
<script src="{{this}}" defer nonce="{{@../csp_nonce}}"></script>
{{/if}}
{{/each}}
{{#each (to_array javascript_module)}}
{{#if this}}
<script src="{{this}}" type="module" defer nonce="{{@../csp_nonce}}"></script>
{{/if}}
{{/each}}

<meta name="viewport" content="width=device-width, initial-scale=1" />
{{#if title}}
<meta property="og:title" content="{{title}}" />
{{/if}}
{{#if description}}
<meta name="description" content="{{description}}" />
<meta property="og:description" content="{{description}}" />
{{/if}}
{{#if preview_image}}
<meta property="og:image" content="{{preview_image}}" />
<meta name="twitter:image" content="{{preview_image}}" />
{{/if}}

{{#if norobot}}
<meta name="robots" content="noindex,nofollow">
{{/if}}

{{#if refresh}}
<meta http-equiv="refresh" content="{{refresh}}">
{{/if}}
{{#if rss}}
<link rel="alternate" type="application/rss+xml" title="{{title}}" href="{{rss}}">
{{/if}}
<meta name="generator" content="SQLPage" />
{{#if social_image}}
<meta property="og:image" content="{{social_image}}" />
{{/if}}
</head>

{{!-- Partial for menu_items to not duplicate logic --}}
{{#*inline "menu-items"}}
<ul class="navbar-nav {{#if sidebar}}pt-lg-3{{else}}ms-auto{{/if}}">
{{~#each (to_array menu_item)~}}
{{~#if (or (eq (typeof this) 'object') (and (eq (typeof this) 'string') (starts_with this '{')))}}
{{~#with (parse_json this)}}
{{#if (or (or this.title this.icon) this.image)}}
<li class="nav-item{{#if this.submenu}} dropdown{{/if}}">
<a class="nav-link {{#if this.submenu}}dropdown-toggle{{/if}}" href="{{#if this.link}}{{this.link}}{{else}}#{{/if}}"
{{~#if this.submenu}} data-bs-toggle="dropdown" data-bs-auto-close="outside" {{/if~}}
role="button"
>
{{~#if this.image~}}
<span {{~#if this.title}} class="me-1"{{/if}}>
{{~#if (eq this.size 'sm')}}
<img width=16 height=16 src="{{this.image}}">
{{~else~}}
<img width=24 height=24 src="{{this.image}}">
{{~/if~}}
</span>
{{~/if~}}
{{#if this.icon}}
{{#if this.title}}<span class="me-1">{{/if}}
{{~icon_img this.icon~}}
{{#if this.title}}</span>{{/if}}
{{/if}}
{{~this.title~}}
</a>
{{~#if this.submenu~}}
<div class="dropdown-menu dropdown-menu-end" data-bs-popper="static">
{{~#each this.submenu~}}
{{#if (or (or this.title this.icon) this.image)}}
<a class="dropdown-item" href="{{this.link}}">
{{~#if this.image~}}
<span {{~#if this.title}} class="me-1"{{/if}}>
{{~#if (eq ../this.size 'sm')}}
<img width=16 height=16 src="{{this.image}}">
{{~else~}}
<img width=24 height=24 src="{{this.image}}">
{{~/if~}}
</span>
{{~/if~}}
{{#if this.icon}}
{{#if this.title}}<span class="me-1">{{/if}}
{{~icon_img this.icon~}}
{{#if this.title}}</span>{{/if}}
{{/if}}
{{~this.title~}}
</a>
{{~/if~}}
{{~/each~}}
</div>
{{/if}}
</li>
{{/if}}
{{/with}}
{{~else}}
{{~#if (gt (len this) 0)~}}
<li class="nav-item">
<a class="nav-link text-capitalize" href="{{this}}.sql">{{this}}</a>
</li>
{{~/if~}}
{{~/if~}}
{{~/each}}
</ul>
{{#if search_target}}
<form class="d-flex" role="search" action="{{search_target}}">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search" name="search" value="{{search_value}}">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
{{/if}}
{{/inline}}

<body class="layout-{{#if sidebar}}fluid{{else}}{{default layout 'boxed'}}{{/if}}" {{#if theme}}data-bs-theme="{{theme}}" {{/if}}>
<div class="page">
{{#if (or (or title (or icon image)) menu_item)}}
<header id="sqlpage_header">
{{#if sidebar}}
<aside class="navbar navbar-vertical navbar-expand-lg" {{#if sidebar_theme}}data-bs-theme="{{sidebar_theme}}" {{/if}}>
<div class="container-fluid">
<button class="navbar-toggler collapsed" type="button" data-bs-target="#sidebar-menu" aria-controls="sidebar-menu" data-bs-toggle="collapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<h1 class="navbar-brand navbar-brand-autodark d-inline ps-2 text-truncate">
<a style="text-decoration: none" href="{{#if link}}{{link}}{{else}}/{{/if}}">
{{#if image}}
<img src="{{image}}" alt="{{title}}" height="32" class="navbar-brand-image">
{{/if}}
{{#if icon}}
{{~icon_img icon~}}
{{/if}}
<span class="pe-2 pe-lg-0 align-middle">{{title}}</span>
</a>
</h1>
<div class="navbar-collapse collapse" id="sidebar-menu">
{{> menu-items menu_item=menu_item}}
</div>
</div>
</aside>
{{else}}
<nav class="navbar navbar-expand-md navbar-light{{#if fixed_top_menu}} fixed-top{{/if}}">
<div class="container-fluid gap-2 justify-content-start" style="min-width:0">
{{!-- Site Logo --}}
<a class="navbar-brand" href="{{#if link}}{{link}}{{else}}/{{/if}}" target="_blank">
{{#if image}}
<img src="{{image}}" alt="{{title}}" width="32" height="32" class="navbar-brand-image">

{{/if}}
{{#if icon}}
{{~icon_img icon~}}
{{/if}}


</a>
{{!-- Site Logo --}}
<h1 class="mb-0 fs-2 text-truncate flex-grow-1" style="flex-basis:0">
<a class="text-decoration-none" href="{{#if link}}{{link}}{{else}}/{{/if}}" target="_blank">{{default navbar_title title}}</a>
</h1>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar-menu" aria-controls="navbar-menu" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse flex-grow-0" id="navbar-menu">
{{> menu-items menu_item=menu_item}}
</div>
</div>
</nav>
</header>
{{/if}}
{{/if}}
<div class="page-wrapper">
<main class="page-body container-xl px-md-5 px-sm-3 {{#if fixed_top_menu}}mt-5{{#unless (eq layout 'boxed')}} pt-5{{/unless}}{{else}} mt-3{{/if}}" id="sqlpage_main_wrapper">
{{~#each_row~}}{{~/each_row~}}
</main>

<footer class="w-100 text-center fs-6 my-2 text-secondary" id="sqlpage_footer">
{{#if footer}}
{{{markdown footer}}}
{{else}}
<!-- You can change this footer using the 'footer' parameter of the 'shell' component -->
Built with <a class="text-reset" href="https://sql.datapage.app"
title="SQLPage v{{buildinfo 'CARGO_PKG_VERSION'}}">SQLPage</a>
{{/if}}
</footer>
</div>
</div>
</body>
</html>
99 changes: 98 additions & 1 deletion service/diabetes-research-hub/ux.sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
shell as sh,
uniformResource as ur,
} from "../../prime/web-ui-content/mod.ts";

import { sqlPageNB as spn } from "./deps.ts";

// custom decorator that makes navigation for this notebook type-safe
Expand All @@ -15,6 +16,92 @@ function drhNav(route: Omit<spn.RouteConfig, "path" | "parentPath">) {
});
}

export class DrhShellSqlPages extends sh.ShellSqlPages {
defaultShell() {
const shellConfig = super.defaultShell();
shellConfig.title = "Diabetes Research Hub";
shellConfig.image = "./assets/diabetic-research-hub-logo.png";
shellConfig.icon = "";
shellConfig.link = "https://drh.diabetestechnology.org/";
return shellConfig;
}

@spn.shell({ eliminate: true })
"shell/shell.json"() {
return this.SQL`
${JSON.stringify(this.defaultShell(), undefined, " ")}
`;
}

@spn.shell({ eliminate: true })
"shell/shell.sql"() {
const literal = (value: unknown) =>
typeof value === "number"
? value
: value
? this.emitCtx.sqlTextEmitOptions.quotedLiteral(value)[1]
: "NULL";
const selectNavMenuItems = (rootPath: string, caption: string) =>
`json_object(
'link', '${rootPath}',
'title', ${literal(caption)},
'submenu', (
SELECT json_group_array(
json_object(
'title', title,
'link', link,
'description', description
)
)
FROM (
SELECT
COALESCE(abbreviated_caption, caption) as title,
COALESCE(url, path) as link,
description
FROM sqlpage_aide_navigation
WHERE namespace = 'prime' AND parent_path = '${rootPath}'
ORDER BY sibling_order
)
)
) as menu_item`;

const handlers = {
DEFAULT: (key: string, value: unknown) => `${literal(value)} AS ${key}`,
menu_item: (key: string, items: Record<string, unknown>[]) =>
items.map((item) => `${literal(JSON.stringify(item))} AS ${key}`),
javascript: (key: string, scripts: string[]) => {
const items = scripts.map((s) => `${literal(s)} AS ${key}`);
items.push(selectNavMenuItems("/ur", "Uniform Resource"));
items.push(selectNavMenuItems("/console", "Console"));
items.push(selectNavMenuItems("/orchestration", "Orchestration"));
items.push(selectNavMenuItems("/site", "DRH"));
return items;
},
footer: () =>
// TODO: add "open in IDE" feature like in other Shahid apps
literal(`Resource Surveillance Web UI (v`) +
` || sqlpage.version() || ') ' || ` +
`'📄 [' || substr(sqlpage.path(), 2) || '](/console/sqlpage-files/sqlpage-file.sql?path=' || substr(sqlpage.path(), 2) || ')' as footer`,
};
const shell = this.defaultShell();
const sqlSelectExpr = Object.entries(shell).flatMap(([k, v]) => {
switch (k) {
case "menu_item":
return handlers.menu_item(k, v as Record<string, unknown>[]);
case "javascript":
return handlers.javascript(k, v as string[]);
case "footer":
return handlers.footer();
default:
return handlers.DEFAULT(k, v);
}
});
return this.SQL`
SELECT ${sqlSelectExpr.join(",\n ")};
`;
}
}

/**
* These pages depend on ../../prime/ux.sql.ts being loaded into RSSD (for nav).
*/
Expand All @@ -29,6 +116,15 @@ export class DRHSqlPages extends spn.TypicalSqlPageNotebook {
`;
}

menuDDL() {
return this.SQL`
INSERT OR IGNORE INTO sqlpage_aide_navigation ("path", caption, namespace, parent_path, sibling_order, url, title, abbreviated_caption, description) VALUES
('/site', 'DRH Menus', 'prime', '/', 1, '/site', NULL, NULL, NULL),
('/site/public.sql', 'DRH Public Site', 'prime', '/site', 1, 'https://drh.diabetestechnology.org/', NULL, NULL, NULL),
('/site/dtsorg.sql', 'DTS Main Site', 'prime', '/site', 2, 'https://www.diabetestechnology.org/index.shtml', NULL, NULL, NULL);
`;
}

@spn.navigationPrimeTopLevel({
caption: "DRH Home",
description: "Welcome to Diabetes Research Hub",
Expand Down Expand Up @@ -818,7 +914,8 @@ export async function drhSQL() {
// );
}
}(),
new sh.ShellSqlPages(),
// new sh.ShellSqlPages(),
new DrhShellSqlPages(),
new c.ConsoleSqlPages(),
new ur.UniformResourceSqlPages(),
new orch.OrchestrationSqlPages(),
Expand Down

1 comment on commit 23c8f11

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on 23c8f11 Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

Your deployment uses decorators. The default for 'experimentalDecorators' will be changing to 'false'. In the meantime, please explicitly set the 'experimentalDecorators' compiler option. For more information, see https://deno.com/deploy/changelog#es-decorators-are-enabled-on-deno-deploy-replacing-experimental-ts-decorators

Please sign in to comment.