ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/layout-basic/test/demo-lens.html

test/demo-lens.html

72 líneas, 4.3 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. <!doctype html>
  2. <html lang="ru">
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="/_pkg/layout-basic/lens.js"></script>
  6. <link rel="stylesheet" href="/_kit/kit.css">
  7. <link rel="stylesheet" href="/_kit/skins/calm.css">
  8. <link rel="stylesheet" href="/_kit/skins/desktop.css">
  9. <style>
  10. html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
  11. .d-wrap { padding: 20px 28px; }
  12. .d-h { font-size: 22px; font-weight: 600; margin: 0 0 16px; }
  13. table { border-collapse: collapse; width: 100%; font-size: 14px; }
  14. th { text-align: left; font-weight: 500; color: var(--lx-muted); border-bottom: 1px solid var(--line); padding: 6px 8px; }
  15. td { border-bottom: 1px solid var(--line); padding: 6px 8px; }
  16. tr.r { cursor: pointer; } tr.r:hover td { background: var(--wash); }
  17. .d-board { display: flex; gap: 12px; align-items: flex-start; }
  18. .d-col { width: 220px; flex: none; }
  19. .d-col h3 { font-size: 13px; font-weight: 500; color: var(--lx-muted); margin: 0 0 8px; }
  20. .d-card { background: var(--lx-card); box-shadow: var(--shadow); border-radius: var(--lx-radius); padding: 10px; margin-bottom: 8px; cursor: pointer; font-size: 14px; }
  21. .d-meta { font-size: 13px; color: var(--lx-muted); margin: 4px 0; }
  22. </style>
  23. </head>
  24. <body>
  25. <div class="d-wrap" id="out"></div>
  26. <script>
  27. // A demo lens for the fake host: its kind comes from its file name (table/board/record).
  28. var kind = location.pathname.split('/').pop().replace('.html', '');
  29. var out = document.getElementById('out');
  30. function esc(s) { return String(s == null ? '' : s).replace(/[&<>"]/g, function (c) { return '&#' + c.charCodeAt(0) + ';'; }); }
  31. function opt(props, key, val) {
  32. var p = props && props[key]; var o = p && p.options && p.options.find(function (x) { return x.name === val; });
  33. return o ? '<span class="lx-chip dot" style="--cc: var(--c-' + esc(o.color) + ')">' + esc(o.label) + '</span>' : esc(val);
  34. }
  35. function draw() {
  36. if (kind === 'record') {
  37. return shtuk.call('records.read', { path: shtuk.path }).then(function (r) {
  38. var m = r.meta || {};
  39. out.innerHTML = '<h1 class="d-h">' + esc(m.icon || '') + ' ' + esc(m.title || r.path) + '</h1>' +
  40. Object.keys(m).filter(function (k) { return typeof m[k] !== 'object'; }).map(function (k) { return '<div class="d-meta">' + esc(k) + ': ' + esc(m[k]) + '</div>'; }).join('') +
  41. '<p>' + esc(r.body) + '</p>' +
  42. (m.status ? '<button class="lx-btn" id="next">Следующий статус</button>' : '');
  43. var b = document.getElementById('next');
  44. if (b) b.onclick = function () {
  45. var s = ['new', 'talk', 'won', 'lost']; var n = s[(s.indexOf(m.status) + 1) % 4];
  46. shtuk.call('records.write', { path: shtuk.path, meta: { status: n } }).then(draw);
  47. };
  48. });
  49. }
  50. return shtuk.call('records.list', { collection: shtuk.path }).then(function (r) {
  51. var props = r.collection.properties || {};
  52. var head = '<h1 class="d-h">' + esc(r.collection.icon || '') + ' ' + esc(r.collection.title) + '</h1>';
  53. if (kind === 'board') {
  54. var cols = (props.status && props.status.options) || [];
  55. out.innerHTML = head + '<div class="d-board">' + cols.map(function (c) {
  56. return '<div class="d-col"><h3>' + opt(props, 'status', c.name) + '</h3>' + r.items.filter(function (i) { return i.meta.status === c.name; }).map(function (i) {
  57. return '<div class="d-card" data-p="' + esc(i.path) + '">' + esc(i.title) + '<div class="d-meta">' + opt(props, 'source', i.meta.source) + '</div></div>';
  58. }).join('') + '</div>';
  59. }).join('') + '</div>';
  60. } else {
  61. out.innerHTML = head + '<table><tr><th>Название</th><th>Статус</th><th>Источник</th><th>Сумма</th></tr>' + r.items.map(function (i) {
  62. return '<tr class="r" data-p="' + esc(i.path) + '"><td>' + esc(i.title) + '</td><td>' + opt(props, 'status', i.meta.status) + '</td><td>' + opt(props, 'source', i.meta.source) + '</td><td>' + esc(i.meta.amount) + '</td></tr>';
  63. }).join('') + '</table>';
  64. }
  65. out.querySelectorAll('[data-p]').forEach(function (el) { el.onclick = function () { shtuk.open(el.dataset.p); }; });
  66. });
  67. }
  68. draw().then(function () { shtuk.ready(); }, function (e) { out.textContent = String(e); shtuk.ready(); });
  69. shtuk.on('changed', draw);
  70. </script>
  71. </body>
  72. </html>