Skip to content

Commit

Permalink
feature (migration): migrating backoffice to new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-kerjean committed Aug 18, 2023
1 parent f14a07e commit 7405adb
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 228 deletions.
3 changes: 0 additions & 3 deletions public/assets/css/designsystem_formbuilder.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
.formbuilder .formbuilder_password {
display: flex;
}
.formbuilder .formbuilder_password:focus-within img.component_icon {
border-color: var(--emphasis-primary);
}
.formbuilder .formbuilder_password img.component_icon {
height: 20px;
border: none;
Expand Down
52 changes: 52 additions & 0 deletions public/index.frontoffice.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/assets/css/reset.css">
<script type="module" src="/components/loader.js"></script>
<title></title>
</head>
<body>
<div role="main" id="app">
<component-loader delay="500"></component-loader>
</div>
<script type="module">
import main from "/lib/skeleton/index.js";
const routes = {
"/login": "/pages/ctrl_connectpage.js",
"/logout": "/pages/ctrl_logout.js",

"/": "/pages/ctrl_homepage.js",
"/files/.*": "/pages/ctrl_filespage.js",
"/view/.*": "/pages/ctrl_viewerpage.js",
// /tags/.* -> "pages/ctrl_tags.js",
// /s/.* -> "/pages/ctrl_share.js",

"/admin/backend": "/pages/adminpage/ctrl_backend.js",
"/admin/settings": "/pages/adminpage/ctrl_settings.js",
"/admin/logs": "/pages/adminpage/ctrl_logger.js",
"/admin/about": "/pages/adminpage/ctrl_about.js",
"/admin/setup": "/pages/adminpage/ctrl_setup.js",
"/admin/": "/pages/ctrl_adminpage.js",

"": "/pages/ctrl_notfound.js",
};
main(document.getElementById("app"), routes, {
spinner: `<component-loader></component-loader>`,
beforeStart: import("/pages/ctrl_boot.js"),
});
</script>

<script type="module" src="/components/modal.js"></script>
<component-modal></component-modal>

<noscript>
<div>
<h2>Error: Javascript is off</h2>
<p>You need to enable Javascript to run this application</p>
</div>
</noscript>
</body>
</html>
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
const routes = {
"/admin/backend": "/pages/adminpage/ctrl_backend.js",
"/admin/settings": "/pages/adminpage/ctrl_settings.js",
"/admin/logs": "/pages/adminpage/ctrl_logger.js",
"/admin/logs": "/pages/adminpage/ctrl_log.js",
"/admin/about": "/pages/adminpage/ctrl_about.js",
"/admin/setup": "/pages/adminpage/ctrl_setup.js",
"/admin/": "/pages/ctrl_adminpage.js",
Expand Down
82 changes: 4 additions & 78 deletions public/pages/adminpage/ctrl_backend.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createElement, createRender } from "../../lib/skeleton/index.js";
import rxjs, { effect, applyMutation } from "../../lib/rx.js";
import { qs } from "../../lib/dom.js";
import { CSS } from "../../helpers/loader.js";

import backend$ from "../connectpage/model_backend.js";

import transition from "./animate.js";
import AdminHOC from "./decorator.js";
import componentStorageBackend from "./ctrl_backend_component_storage.js";
import componentAuthenticationMiddleware from "./ctrl_backend_component_authentication.js";

export default AdminHOC(function(render) {
export default AdminHOC(async function(render) {
const css = await CSS(import.meta.url, "ctrl_backend.css");
const $page = createElement(`
<div class="component_dashboard sticky">
<div data-bind="backend"></div>
Expand All @@ -24,77 +24,3 @@ export default AdminHOC(function(render) {
componentStorageBackend(createRender(qs($page, `[data-bind="backend"]`)));
componentAuthenticationMiddleware(createRender(qs($page, `[data-bind="authentication_middleware"]`)));
});

function componentStorageBackend(render) {
const $page = createElement(`
<div class="component_storagebackend">
<h2>Storage Backend</h2>
<div class="box-container" data-bind="backend-available"></div>
<form data-bind="backend-enabled"></form>
</div>
`);
render($page);

effect(backend$.pipe(
rxjs.mergeMap((specs) => Object.keys(specs)),
rxjs.map((label) => [createElement(`
<div class="box-item pointer no-select">
<div>
${label}
<span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
`)]),
applyMutation(qs($page, "[data-bind=\"backend-available\"]"), "appendChild")
));
}

function componentAuthenticationMiddleware(render) {
const $page = createElement(`
<div class="box-container">
<div class="box-item pointer no-select">
<div>admin <span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
<div class="box-item pointer no-select">
<div>htpasswd <span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
<div class="box-item pointer no-select">
<div>ldap <span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
<div class="box-item pointer no-select active">
<div>openid <span class="no-select">
<span class="icon">
<img class="component_icon" draggable="false" src="/assets/icons/delete.svg" alt="delete">
</span>
</span>
</div>
</div>
<div class="box-item pointer no-select">
<div>passthrough <span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
<div class="box-item pointer no-select">
<div>saml <span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
</div>
`);
render($page);
}

const css = await CSS(import.meta.url, "ctrl_backend.css");
47 changes: 47 additions & 0 deletions public/pages/adminpage/ctrl_backend_component_authentication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { createElement } from "../../lib/skeleton/index.js";

export default function(render) {
const $page = createElement(`
<div class="box-container">
<div class="box-item pointer no-select">
<div>admin <span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
<div class="box-item pointer no-select">
<div>htpasswd <span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
<div class="box-item pointer no-select">
<div>ldap <span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
<div class="box-item pointer no-select active">
<div>openid <span class="no-select">
<span class="icon">
<img class="component_icon" draggable="false" src="/assets/icons/delete.svg" alt="delete">
</span>
</span>
</div>
</div>
<div class="box-item pointer no-select">
<div>passthrough <span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
<div class="box-item pointer no-select">
<div>saml <span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
</div>
`);
render($page);
}
30 changes: 30 additions & 0 deletions public/pages/adminpage/ctrl_backend_component_storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createElement } from "../../lib/skeleton/index.js";
import rxjs, { effect, applyMutation } from "../../lib/rx.js";
import { qs } from "../../lib/dom.js";
import backend$ from "../connectpage/model_backend.js";

export default function(render) {
const $page = createElement(`
<div class="component_storagebackend">
<h2>Storage Backend</h2>
<div class="box-container" data-bind="backend-available"></div>
<form data-bind="backend-enabled"></form>
</div>
`);
render($page);

effect(backend$.pipe(
rxjs.mergeMap((specs) => Object.keys(specs)),
rxjs.map((label) => [createElement(`
<div class="box-item pointer no-select">
<div>
${label}
<span class="no-select">
<span class="icon">+</span>
</span>
</div>
</div>
`)]),
applyMutation(qs($page, "[data-bind=\"backend-available\"]"), "appendChild")
));
}
29 changes: 29 additions & 0 deletions public/pages/adminpage/ctrl_log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createElement, createRender } from "../../lib/skeleton/index.js";
import rxjs, { effect, stateMutation, applyMutation } from "../../lib/rx.js";
import { qs } from "../../lib/dom.js";

import componentLogForm from "./ctrl_log_form.js";
import componentLogViewer from "./ctrl_log_viewer.js";
import componentAuditor from "./ctrl_log_audit.js";
import transition from "./animate.js";
import AdminHOC from "./decorator.js";

function Page(render) {
const $page = createElement(`
<div class="component_logpage sticky">
<h2>Logging</h2>
<div class="component_logviewer"></div>
<div class="component_logger"></div>
<h2>Activity Report</h2>
<div class="component_reporter"></div>
<div>
`);
render(transition($page));

componentLogForm(createRender($page.querySelector(".component_logger")));
componentLogViewer(createRender($page.querySelector(".component_logviewer")));
componentAuditor(createRender($page.querySelector(".component_reporter")));
}

export default AdminHOC(Page);
32 changes: 32 additions & 0 deletions public/pages/adminpage/ctrl_log_audit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createElement } from "../../lib/skeleton/index.js";
import rxjs, { effect, stateMutation, applyMutation } from "../../lib/rx.js";
import { qs } from "../../lib/dom.js";
import { createForm } from "../../lib/form.js";
import { formTmpl } from "../../components/form.js";

import Audit from "./model_audit.js";

export default function(render) {
const $page = createElement(`
<div>
<form></form>
<div data-bind="auditor"></div>
</div>
`);
render($page);

// setup the form
effect(Audit.get().pipe(
rxjs.map(({ form }) => form),
rxjs.map((formSpec) => createForm(formSpec, formTmpl())),
rxjs.mergeMap((promise) => rxjs.from(promise)),
rxjs.map(($form) => [$form]),
applyMutation(qs($page, "form"), "appendChild")
));

// setup the result
effect(Audit.get().pipe(
rxjs.map(({ render }) => render),
stateMutation(qs($page, "[data-bind=\"auditor\"]"), "innerHTML")
));
}
29 changes: 29 additions & 0 deletions public/pages/adminpage/ctrl_log_form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createElement } from "../../lib/skeleton/index.js";
import rxjs, { effect, applyMutation } from "../../lib/rx.js";
import { generateSkeleton } from "../../components/skeleton.js";
import { createForm } from "../../lib/form.js";
import { formTmpl } from "../../components/form.js";

import { get as getConfig } from "./model_config.js";
import { renderLeaf } from "./helper_form.js";

export default function(render) {
const $form = createElement(`
<form style="min-height: 240px; margin-top:20px;">
${generateSkeleton(4)}
</form>
`);

render($form);

// feature1: render the form
effect(getConfig().pipe(
rxjs.map(({ log }) => ({ params: log })),
rxjs.map((formSpec) => createForm(formSpec, formTmpl({ renderLeaf }))),
rxjs.mergeMap((promise) => rxjs.from(promise)),
rxjs.map(($form) => [$form]),
applyMutation($form, "replaceChildren")
));

// TODO feature2: response to form change
}
13 changes: 13 additions & 0 deletions public/pages/adminpage/ctrl_log_viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createElement } from "../../lib/skeleton/index.js";
import rxjs, { effect, stateMutation } from "../../lib/rx.js";

import Log from "./model_log.js";

export default function(render) {
const $page = createElement(`<pre style="height:350px; max-height: 350px">…</pre>`);
render($page);

effect(Log.get().pipe(
stateMutation($page, "textContent")
));
}
Loading

0 comments on commit 7405adb

Please sign in to comment.