| 1 | /* Generated by tools/gen_ui.py from src/ui.html. Do not edit by hand. */ |
| 2 | #ifndef SX_MEMORY_UI_HTML_H |
| 3 | #define SX_MEMORY_UI_HTML_H |
| 4 | |
| 5 | static const char *UI_HTML = |
| 6 | "<!DOCTYPE html>\n" |
| 7 | "<html lang=\"en\"><head><meta charset=\"utf-8\">\n" |
| 8 | "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n" |
| 9 | "<title>memory - knowledge graph</title>\n" |
| 10 | "\001\n" |
| 11 | "<style>\n" |
| 12 | "*{box-sizing:border-box}\n" |
| 13 | "html,body{margin:0;height:100%}\n" |
| 14 | "body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px;\n" |
| 15 | " line-height:1.5;-webkit-font-smoothing:antialiased;overflow:hidden}\n" |
| 16 | "#app{display:grid;grid-template-columns:320px minmax(0,1fr);height:100%;min-height:0}\n" |
| 17 | ".pane{min-width:0;min-height:0;display:flex;flex-direction:column}\n" |
| 18 | "#side{background:var(--bg-2);border-right:1px solid var(--line)}\n" |
| 19 | ".hd{display:flex;align-items:center;gap:8px;padding:11px 12px 9px}\n" |
| 20 | ".brand{font-size:12px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;\n" |
| 21 | " color:var(--text-2);flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n" |
| 22 | ".icon{display:inline-flex;align-items:center;justify-content:center;background:var(--surface-2);\n" |
| 23 | " border:1px solid var(--line);color:var(--text);border-radius:9px;width:30px;height:30px;\n" |
| 24 | " padding:0;cursor:pointer;font-family:inherit;font-size:13px;font-weight:600;flex:none}\n" |
| 25 | ".icon:hover{background:var(--surface-hover);border-color:var(--line-2)}\n" |
| 26 | ".icon:active{transform:scale(.96)}\n" |
| 27 | ".icon svg{width:15px;height:15px;display:block;fill:none;stroke:currentColor;stroke-width:1.8;\n" |
| 28 | " stroke-linecap:round;stroke-linejoin:round}\n" |
| 29 | ".search{margin:0 12px 8px;padding:8px 11px;border-radius:9px;border:1px solid var(--line);\n" |
| 30 | " background:var(--input-bg);color:var(--text);font-family:inherit;font-size:13px;width:calc(100% - 24px)}\n" |
| 31 | ".search:focus{outline:2px solid var(--blue);outline-offset:-1px}\n" |
| 32 | ".chips{display:flex;flex-wrap:wrap;gap:5px;padding:0 12px 8px}\n" |
| 33 | ".chip{background:var(--surface-2);border:1px solid var(--line);color:var(--text-2);\n" |
| 34 | " border-radius:980px;padding:2px 9px;font-size:11px;font-family:inherit;cursor:pointer;\n" |
| 35 | " max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n" |
| 36 | ".chip.on{background:var(--blue);border-color:var(--blue);color:#fff}\n" |
| 37 | ".list{flex:1 1 auto;overflow-y:auto;padding:0 8px 8px}\n" |
| 38 | ".item{display:block;width:100%;text-align:left;background:transparent;border:0;border-radius:10px;\n" |
| 39 | " padding:8px 10px;color:var(--text);cursor:pointer;font-family:inherit;margin-bottom:2px}\n" |
| 40 | ".item:hover{background:var(--surface-hover)}\n" |
| 41 | ".item.sel{background:var(--surface-2);box-shadow:inset 2px 0 0 var(--blue)}\n" |
| 42 | ".irow{display:flex;align-items:baseline;gap:7px}\n" |
| 43 | ".iname{font-weight:600;flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n" |
| 44 | ".icount{font-size:11px;color:var(--text-2);font-variant-numeric:tabular-nums;flex:none}\n" |
| 45 | ".itype{display:inline-block;margin-top:2px;font-size:10.5px;letter-spacing:.03em;text-transform:uppercase;\n" |
| 46 | " color:var(--teal);background:var(--surface-2);border-radius:5px;padding:1px 6px;max-width:100%;\n" |
| 47 | " overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n" |
| 48 | "#main{overflow-y:auto}\n" |
| 49 | ".mainhd{display:flex;align-items:center;gap:8px;padding:11px 14px;border-bottom:1px solid var(--line);\n" |
| 50 | " position:sticky;top:0;background:var(--bg);z-index:2;flex-wrap:wrap}\n" |
| 51 | ".title{font-size:15px;font-weight:700;flex:1;min-width:0;overflow-wrap:anywhere}\n" |
| 52 | ".btn{background:var(--blue);color:#fff;border:0;border-radius:980px;padding:6px 13px;font-weight:600;\n" |
| 53 | " font-size:12.5px;cursor:pointer;font-family:inherit;white-space:nowrap}\n" |
| 54 | ".btn:active{transform:scale(.98)}\n" |
| 55 | ".btn.ghost{background:var(--surface-2);color:var(--text);border:1px solid var(--line)}\n" |
| 56 | ".btn.danger{background:transparent;color:var(--red);border:1px solid var(--line);padding:3px 9px;\n" |
| 57 | " font-size:11.5px;font-weight:600}\n" |
| 58 | ".body{padding:14px;display:flex;flex-direction:column;gap:16px}\n" |
| 59 | ".card{background:var(--bg-card);border:1px solid var(--line);border-radius:14px;padding:13px 14px}\n" |
| 60 | ".card h3{margin:0 0 9px;font-size:11px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;\n" |
| 61 | " color:var(--text-2)}\n" |
| 62 | ".obs{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}\n" |
| 63 | ".obs li{display:flex;gap:9px;align-items:flex-start;background:var(--surface-2);border-radius:9px;\n" |
| 64 | " padding:7px 10px;font-size:13px}\n" |
| 65 | ".obs li span{flex:1;min-width:0;overflow-wrap:anywhere}\n" |
| 66 | ".rel{display:flex;gap:9px;align-items:baseline;padding:6px 0;border-top:1px solid var(--line);font-size:13px}\n" |
| 67 | ".rel:first-of-type{border-top:0;padding-top:0}\n" |
| 68 | ".rel .arrow{color:var(--text-2);flex:none;font-size:12px}\n" |
| 69 | ".rel b{font-weight:600;overflow-wrap:anywhere}\n" |
| 70 | ".rel .rt{color:var(--orange);font-size:11.5px;font-weight:600;overflow-wrap:anywhere}\n" |
| 71 | ".row{display:flex;gap:8px;flex-wrap:wrap;align-items:center}\n" |
| 72 | "input,select{background:var(--input-bg);border:1px solid var(--line);color:var(--text);\n" |
| 73 | " border-radius:9px;padding:7px 10px;font-family:inherit;font-size:13px;min-width:0;flex:1 1 130px}\n" |
| 74 | "input:focus,select:focus{outline:2px solid var(--blue);outline-offset:-1px}\n" |
| 75 | ".hint{font-size:11.5px;color:var(--text-2);margin:0}\n" |
| 76 | ".empty{text-align:center;padding:56px 22px;color:var(--text-2)}\n" |
| 77 | ".empty b{display:block;color:var(--text);font-size:15px;margin-bottom:6px;font-weight:600}\n" |
| 78 | ".svgwrap{margin:0 auto 12px;width:74px;height:74px;opacity:.85}\n" |
| 79 | ".svgwrap svg{width:100%;height:100%;fill:none;stroke:var(--blue);stroke-width:1.6}\n" |
| 80 | ".status{font-size:11.5px;color:var(--text-2);padding:0 14px 12px;min-height:16px;overflow-wrap:anywhere}\n" |
| 81 | ".status.bad{color:var(--red)}\n" |
| 82 | ".status.ok{color:var(--green)}\n" |
| 83 | ".ft{border-top:1px solid var(--line);display:flex;align-items:center;gap:8px;padding:8px 12px;\n" |
| 84 | " font-size:11px;color:var(--text-2)}\n" |
| 85 | ".ft .grow{flex:1}\n" |
| 86 | ".sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}\n" |
| 87 | "@media (max-width:820px){\n" |
| 88 | " #app{grid-template-columns:1fr}\n" |
| 89 | " #side{border-right:0;border-bottom:1px solid var(--line);max-height:46vh}\n" |
| 90 | " body[data-view=\"detail\"] #side{display:none}\n" |
| 91 | " body:not([data-view=\"detail\"]) #main{display:none}\n" |
| 92 | "}\n" |
| 93 | "</style>\n" |
| 94 | "</head><body>\n" |
| 95 | "<div id=\"app\">\n" |
| 96 | " <section class=\"pane\" id=\"side\">\n" |
| 97 | " <div class=\"hd\">\n" |
| 98 | " <span class=\"brand\">knowledge graph</span>\n" |
| 99 | " <button class=\"icon\" id=\"btnTheme\" title=\"Theme\" aria-label=\"Toggle theme\">\n" |
| 100 | " <svg viewBox=\"0 0 24 24\"><circle cx=\"12\" cy=\"12\" r=\"4.2\"/><path d=\"M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6l1.4 1.4M17 17l1.4 1.4M18.4 5.6L17 7M7 17l-1.4 1.4\"/></svg>\n" |
| 101 | " </button>\n" |
| 102 | " </div>\n" |
| 103 | " <input class=\"search\" id=\"q\" type=\"search\" placeholder=\"Search names, types, observations\" aria-label=\"Search the graph\">\n" |
| 104 | " <div class=\"chips\" id=\"chips\"></div>\n" |
| 105 | " <div class=\"list\" id=\"list\"></div>\n" |
| 106 | " <div class=\"ft\">\n" |
| 107 | " <span class=\"grow\" id=\"tally\">loading</span>\n" |
| 108 | " <button class=\"icon\" id=\"btnNew\" title=\"New entity\" aria-label=\"New entity\">\n" |
| 109 | " <svg viewBox=\"0 0 24 24\"><path d=\"M12 5v14M5 12h14\"/></svg>\n" |
| 110 | " </button>\n" |
| 111 | " </div>\n" |
| 112 | " </section>\n" |
| 113 | "\n" |
| 114 | " <section class=\"pane\" id=\"main\">\n" |
| 115 | " <div class=\"mainhd\">\n" |
| 116 | " <button class=\"icon\" id=\"btnBack\" title=\"Back to list\" aria-label=\"Back to list\" style=\"display:none\">\n" |
| 117 | " <svg viewBox=\"0 0 24 24\"><path d=\"M14 6l-6 6 6 6\"/></svg>\n" |
| 118 | " </button>\n" |
| 119 | " <span class=\"title\" id=\"title\">Select an entity</span>\n" |
| 120 | " <button class=\"btn ghost\" id=\"btnReload\" title=\"Reload\">Reload</button>\n" |
| 121 | " </div>\n" |
| 122 | " <div id=\"detail\" class=\"body\"></div>\n" |
| 123 | " <div class=\"status\" id=\"status\"></div>\n" |
| 124 | " </section>\n" |
| 125 | "</div>\n" |
| 126 | "\n" |
| 127 | "<script>\n" |
| 128 | "(function(){\n" |
| 129 | "\"use strict\";\n" |
| 130 | "var q=new URLSearchParams(location.search);\n" |
| 131 | "var node=q.get('node')||'';\n" |
| 132 | "var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))||\n" |
| 133 | " localStorage.getItem('bot_active_pwd')||'';\n" |
| 134 | "/* Two ways to reach us: the bot's hub proxies /plugins?plugin=plugin_memory,\n" |
| 135 | " * while a directly-opened node route is /plugin_memory. Hitting the wrong one\n" |
| 136 | " * renders the plugin-LIST JSON instead of the page, so branch on the URL\n" |
| 137 | " * rather than assuming the hub. */\n" |
| 138 | "var ROUTE=q.has('plugin')?'plugins':'plugin_memory';\n" |
| 139 | "\n" |
| 140 | "function url(action,extra){\n" |
| 141 | " var p=[];\n" |
| 142 | " if(q.has('plugin'))p.push('plugin=plugin_memory');\n" |
| 143 | " p.push('action='+encodeURIComponent(action));\n" |
| 144 | " if(node)p.push('node='+encodeURIComponent(node));\n" |
| 145 | " if(pwd)p.push('pwd='+encodeURIComponent(pwd));\n" |
| 146 | " if(extra)for(var k in extra)p.push(encodeURIComponent(k)+'='+encodeURIComponent(extra[k]));\n" |
| 147 | " return '/'+ROUTE+'?'+p.join('&');\n" |
| 148 | "}\n" |
| 149 | "function hdr(x){var h={};for(var k in x)h[k]=x[k];if(pwd)h['X-Bot-Password']=pwd;return h;}\n" |
| 150 | "function api(action,extra){\n" |
| 151 | " return fetch(url(action,extra),{headers:hdr({})}).then(function(r){\n" |
| 152 | " if(!r.ok)throw new Error('HTTP '+r.status);\n" |
| 153 | " return r.json();\n" |
| 154 | " });\n" |
| 155 | "}\n" |
| 156 | "function post(action,obj){\n" |
| 157 | " return fetch(url(action),{method:'POST',headers:hdr({'Content-Type':'application/json'}),\n" |
| 158 | " body:JSON.stringify(obj)}).then(function(r){return r.json().then(function(j){j.__s=r.status;return j;});});\n" |
| 159 | "}\n" |
| 160 | "\n" |
| 161 | "var el=function(id){return document.getElementById(id);};\n" |
| 162 | "var listEl=el('list'),titleEl=el('title'),detailEl=el('detail'),statusEl=el('status'),\n" |
| 163 | " tallyEl=el('tally'),chipsEl=el('chips'),qEl=el('q');\n" |
| 164 | "var entities=[],sel=null,typeFilter='',timer=null;\n" |
| 165 | "\n" |
| 166 | "function say(msg,cls){statusEl.textContent=msg||'';statusEl.className='status'+(cls?' '+cls:'');}\n" |
| 167 | "\n" |
| 168 | "function esc(s){return String(s==null?'':s).replace(/[&<>\"']/g,function(c){\n" |
| 169 | " return {'&':'&','<':'<','>':'>','\"':'"',\"'\":'''}[c];});}\n" |
| 170 | "\n" |
| 171 | "function graphThen(fn){\n" |
| 172 | " api('graph',{limit:'2000'}).then(function(j){\n" |
| 173 | " if(j.ok===false){say(j.error,'bad');return;}\n" |
| 174 | " entities=j.entities||[];\n" |
| 175 | " fn&&fn();\n" |
| 176 | " }).catch(function(e){say('could not read the graph: '+e.message,'bad');});\n" |
| 177 | "}\n" |
| 178 | "\n" |
| 179 | "function tally(){\n" |
| 180 | " var n=0,i;\n" |
| 181 | " for(i=0;i<entities.length;i++)n+=entities[i].observations.length;\n" |
| 182 | " tallyEl.textContent=entities.length+' entities, '+n+' observations';\n" |
| 183 | "}\n" |
| 184 | "\n" |
| 185 | "function chips(){\n" |
| 186 | " var seen={},out=[],i;\n" |
| 187 | " for(i=0;i<entities.length;i++){var t=entities[i].entityType;if(!seen[t]){seen[t]=1;out.push(t);}}\n" |
| 188 | " out.sort(function(a,b){return a.toLowerCase()<b.toLowerCase()?-1:1;});\n" |
| 189 | " var h='<button class=\"chip'+(typeFilter===''?' on':'')+'\" data-t=\"\">all</button>';\n" |
| 190 | " for(i=0;i<out.length&&i<40;i++)\n" |
| 191 | " h+='<button class=\"chip'+(typeFilter===out[i]?' on':'')+'\" data-t=\"'+esc(out[i])+'\">'+esc(out[i])+'</button>';\n" |
| 192 | " chipsEl.innerHTML=h;\n" |
| 193 | " Array.prototype.forEach.call(chipsEl.querySelectorAll('.chip'),function(b){\n" |
| 194 | " b.onclick=function(){typeFilter=b.getAttribute('data-t')||'';renderList();};\n" |
| 195 | " });\n" |
| 196 | "}\n" |
| 197 | "\n" |
| 198 | "function renderList(){\n" |
| 199 | " var term=(qEl.value||'').toLowerCase().trim(),rows=[],i,j,hit;\n" |
| 200 | " for(i=0;i<entities.length;i++){\n" |
| 201 | " var e=entities[i];\n" |
| 202 | " if(typeFilter&&e.entityType!==typeFilter)continue;\n" |
| 203 | " if(term){\n" |
| 204 | " hit=e.name.toLowerCase().indexOf(term)>=0||\n" |
| 205 | " e.entityType.toLowerCase().indexOf(term)>=0;\n" |
| 206 | " for(j=0;!hit&&j<e.observations.length;j++)\n" |
| 207 | " if(e.observations[j].toLowerCase().indexOf(term)>=0)hit=true;\n" |
| 208 | " if(!hit)continue;\n" |
| 209 | " }\n" |
| 210 | " rows.push(e);\n" |
| 211 | " }\n" |
| 212 | " if(!rows.length){\n" |
| 213 | " listEl.innerHTML='<div class=\"empty\"><b>Nothing here</b>'+\n" |
| 214 | " (entities.length?'No entity matches this filter.':'Add your first entity with the plus below.')+\n" |
| 215 | " '</div>';\n" |
| 216 | " chips();tally();return;\n" |
| 217 | " }\n" |
| 218 | " listEl.innerHTML=rows.map(function(e){\n" |
| 219 | " return '<button class=\"item'+(sel&&sel===e.name?' sel':'')+'\" data-n=\"'+esc(e.name)+'\">'+\n" |
| 220 | " '<span class=\"irow\"><span class=\"iname\">'+esc(e.name)+'</span>'+\n" |
| 221 | " '<span class=\"icount\">'+e.observations.length+'</span></span>'+\n" |
| 222 | " '<span class=\"itype\">'+esc(e.entityType)+'</span></button>';\n" |
| 223 | " }).join('');\n" |
| 224 | " Array.prototype.forEach.call(listEl.querySelectorAll('.item'),function(b){\n" |
| 225 | " b.onclick=function(){open(b.getAttribute('data-n'));};\n" |
| 226 | " });\n" |
| 227 | " chips();tally();\n" |
| 228 | "}\n" |
| 229 | "\n" |
| 230 | "function relationRows(rels,dir){\n" |
| 231 | " if(!rels.length)return '<p class=\"hint\">None yet.</p>';\n" |
| 232 | " return rels.map(function(r){\n" |
| 233 | " var other=dir==='out'?r.to:r.from;\n" |
| 234 | " return '<div class=\"rel\"><b>'+esc(dir==='out'?r.from:r.to)+'</b>'+\n" |
| 235 | " '<span class=\"arrow\">'+(dir==='out'?'to':'from')+'</span>'+\n" |
| 236 | " '<span class=\"rt\">'+esc(r.relationType)+'</span>'+\n" |
| 237 | " '<span style=\"flex:1\"></span>'+\n" |
| 238 | " '<button class=\"btn danger\" data-delrel=\"'+esc(r.from)+'|'+esc(r.to)+'|'+esc(r.relationType)+'\">remove</button>'+\n" |
| 239 | " '</div>';\n" |
| 240 | " }).join('');\n" |
| 241 | "}\n" |
| 242 | "\n" |
| 243 | "function open(name){\n" |
| 244 | " sel=name;\n" |
| 245 | " document.body.setAttribute('data-view','detail');\n" |
| 246 | " el('btnBack').style.display='';\n" |
| 247 | " renderList();\n" |
| 248 | " api('entity',{name:name}).then(function(j){\n" |
| 249 | " if(j.ok===false){say(j.error,'bad');return;}\n" |
| 250 | " var ents=j.entities||[],rels=j.relations||[];\n" |
| 251 | " if(!ents.length){titleEl.textContent=name;detailEl.innerHTML=\n" |
| 252 | " '<div class=\"empty\"><b>Gone</b>That entity is no longer in the graph.</div>';return;}\n" |
| 253 | " var e=ents[0],i,out=[],inn=[];\n" |
| 254 | " for(i=0;i<rels.length;i++){\n" |
| 255 | " if(rels[i].from===e.name)out.push(rels[i]);\n" |
| 256 | " if(rels[i].to===e.name)inn.push(rels[i]);\n" |
| 257 | " }\n" |
| 258 | " titleEl.textContent=e.name;\n" |
| 259 | " detailEl.innerHTML=\n" |
| 260 | " '<div class=\"card\"><h3>'+esc(e.entityType)+'</h3><div class=\"row\">'+\n" |
| 261 | " '<button class=\"btn danger\" data-dele=\"'+esc(e.name)+'\">Delete entity</button>'+\n" |
| 262 | " '<span class=\"hint\">'+e.observations.length+' observation(s), '+rels.length+' relation(s)</span>'+\n" |
| 263 | " '</div></div>'+\n" |
| 264 | " '<div class=\"card\"><h3>Observations</h3><ul class=\"obs\">'+\n" |
| 265 | " (e.observations.length?e.observations.map(function(o){\n" |
| 266 | " return '<li><span>'+esc(o)+'</span><button class=\"btn danger\" data-delo=\"'+\n" |
| 267 | " esc(e.name)+'|'+esc(o)+'\">remove</button></li>';}).join('')\n" |
| 268 | " :'<li><span class=\"hint\">No observations yet.</span></li>')+\n" |
| 269 | " '</ul><div class=\"row\" style=\"margin-top:10px\">'+\n" |
| 270 | " '<input id=\"newObs\" placeholder=\"Add an observation\" aria-label=\"New observation\">'+\n" |
| 271 | " '<button class=\"btn\" id=\"addObs\">Add</button></div></div>'+\n" |
| 272 | " '<div class=\"card\"><h3>Relations out</h3>'+relationRows(out,'out')+'</div>'+\n" |
| 273 | " '<div class=\"card\"><h3>Relations in</h3>'+relationRows(inn,'in')+'</div>'+\n" |
| 274 | " '<div class=\"card\"><h3>New relation from '+esc(e.name)+'</h3><div class=\"row\">'+\n" |
| 275 | " '<select id=\"relTo\"><option value=\"\">target entity...</option>'+\n" |
| 276 | " entities.filter(function(x){return x.name!==e.name;}).map(function(x){\n" |
| 277 | " return '<option value=\"'+esc(x.name)+'\">'+esc(x.name)+'</option>';}).join('')+\n" |
| 278 | " '</select><input id=\"relType\" placeholder=\"relation type (active voice)\" style=\"flex:1 1 160px\">'+\n" |
| 279 | " '<button class=\"btn\" id=\"addRel\">Link</button></div>'+\n" |
| 280 | " '<p class=\"hint\">Both ends must already exist. The link is skipped if it is already there.</p></div>';\n" |
| 281 | "\n" |
| 282 | " Array.prototype.forEach.call(detailEl.querySelectorAll('[data-delo]'),function(b){\n" |
| 283 | " b.onclick=function(){\n" |
| 284 | " var p=b.getAttribute('data-delo').split('|'),nm=p[0];\n" |
| 285 | " post('delete_obs',{name:nm,observations:[p.slice(1).join('|')]}).then(function(r){\n" |
| 286 | " if(r.ok===false){say(r.error,'bad');return;}\n" |
| 287 | " say('observation removed','ok');open(nm);});\n" |
| 288 | " };\n" |
| 289 | " });\n" |
| 290 | " Array.prototype.forEach.call(detailEl.querySelectorAll('[data-delrel]'),function(b){\n" |
| 291 | " b.onclick=function(){\n" |
| 292 | " var p=b.getAttribute('data-delrel').split('|');\n" |
| 293 | " post('delete_relation',{from:p[0],to:p[1],relationType:p.slice(2).join('|')}).then(function(r){\n" |
| 294 | " if(r.ok===false){say(r.error,'bad');return;}\n" |
| 295 | " say(r.message||'relation removed','ok');refreshAll();});\n" |
| 296 | " };\n" |
| 297 | " });\n" |
| 298 | " Array.prototype.forEach.call(detailEl.querySelectorAll('[data-dele]'),function(b){\n" |
| 299 | " b.onclick=function(){\n" |
| 300 | " var nm=b.getAttribute('data-dele');\n" |
| 301 | " if(!window.confirm('Delete '+nm+' and every relation touching it? This cannot be undone.'))return;\n" |
| 302 | " post('delete_entity',{name:nm}).then(function(r){\n" |
| 303 | " if(r.ok===false){say(r.error,'bad');return;}\n" |
| 304 | " sel=null;document.body.removeAttribute('data-view');\n" |
| 305 | " el('btnBack').style.display='none';\n" |
| 306 | " say(r.message||'deleted','ok');refreshAll();});\n" |
| 307 | " };\n" |
| 308 | " });\n" |
| 309 | " var ao=el('addObs');\n" |
| 310 | " if(ao)ao.onclick=function(){\n" |
| 311 | " var v=el('newObs').value.trim();\n" |
| 312 | " if(!v)return;\n" |
| 313 | " post('add_obs',{name:e.name,contents:[v]}).then(function(r){\n" |
| 314 | " if(r.ok===false){say(r.error,'bad');return;}\n" |
| 315 | " el('newObs').value='';say('observation added','ok');open(e.name);});\n" |
| 316 | " };\n" |
| 317 | " var nmo=el('newObs');\n" |
| 318 | " if(nmo)nmo.onkeydown=function(ev){if(ev.key==='Enter')ao.onclick();};\n" |
| 319 | " var ar=el('addRel');\n" |
| 320 | " if(ar)ar.onclick=function(){\n" |
| 321 | " var to=el('relTo').value,ty=el('relType').value.trim();\n" |
| 322 | " if(!to){say('pick a target entity','bad');return;}\n" |
| 323 | " if(!ty){say('a relation needs a type','bad');return;}\n" |
| 324 | " post('add_relation',{from:e.name,to:to,relationType:ty}).then(function(r){\n" |
| 325 | " if(r.ok===false){say(r.error,'bad');return;}\n" |
| 326 | " el('relType').value='';say('linked','ok');\n" |
| 327 | " refreshAll(function(){open(e.name);});});\n" |
| 328 | " };\n" |
| 329 | " }).catch(function(e){say('could not read the entity: '+e.message,'bad');});\n" |
| 330 | "}\n" |
| 331 | "\n" |
| 332 | "function back(){\n" |
| 333 | " sel=null;\n" |
| 334 | " document.body.removeAttribute('data-view');\n" |
| 335 | " el('btnBack').style.display='none';\n" |
| 336 | " titleEl.textContent='Select an entity';\n" |
| 337 | " detailEl.innerHTML='<div class=\"empty\"><div class=\"svgwrap\"><svg viewBox=\"0 0 64 64\">'+\n" |
| 338 | " '<circle cx=\"16\" cy=\"18\" r=\"6\"/><circle cx=\"47\" cy=\"14\" r=\"5\"/>'+\n" |
| 339 | " '<circle cx=\"34\" cy=\"38\" r=\"7\"/><circle cx=\"14\" cy=\"50\" r=\"5\"/><circle cx=\"51\" cy=\"46\" r=\"6\"/>'+\n" |
| 340 | " '<path d=\"M21.5 21.5 28 33M42.5 17.5 39 31M28.5 43 18.5 47.5M40.5 41.5 46 44\"/></svg></div>'+\n" |
| 341 | " '<b>No entity selected</b>Pick one on the left, or search to find it by keyword.</div>';\n" |
| 342 | " renderList();\n" |
| 343 | "}\n" |
| 344 | "\n" |
| 345 | "function newEntity(){\n" |
| 346 | " var nm=window.prompt('Entity name');\n" |
| 347 | " if(!nm||!nm.trim())return;\n" |
| 348 | " var ty=window.prompt('Entity type','note');\n" |
| 349 | " if(ty===null)return;\n" |
| 350 | " post('add_entity',{name:nm.trim(),entityType:(ty||'note').trim(),observations:[]})\n" |
| 351 | " .then(function(r){\n" |
| 352 | " if(r.ok===false){say(r.error,'bad');return;}\n" |
| 353 | " say('created '+nm.trim()+'','ok');\n" |
| 354 | " refreshAll(function(){open(nm.trim());});\n" |
| 355 | " });\n" |
| 356 | "}\n" |
| 357 | "\n" |
| 358 | "function refreshAll(fn){\n" |
| 359 | " api('stats').then(function(s){\n" |
| 360 | " if(s.ok!==false){\n" |
| 361 | " tallyEl.textContent=s.entities+' entities, '+s.observations+' observations, '+\n" |
| 362 | " s.relations+' relations';\n" |
| 363 | " }\n" |
| 364 | " });\n" |
| 365 | " graphThen(function(){renderList();if(fn)fn();});\n" |
| 366 | "}\n" |
| 367 | "\n" |
| 368 | "el('btnReload').onclick=function(){say('');refreshAll();};\n" |
| 369 | "el('btnBack').onclick=back;\n" |
| 370 | "el('btnNew').onclick=newEntity;\n" |
| 371 | "qEl.oninput=function(){clearTimeout(timer);timer=setTimeout(renderList,140);};\n" |
| 372 | "qEl.onkeydown=function(e){\n" |
| 373 | " if(e.key==='Escape'){qEl.value='';renderList();}\n" |
| 374 | " if(e.key==='Enter'){\n" |
| 375 | " for(var i=0;i<entities.length;i++)\n" |
| 376 | " if(entities[i].name.toLowerCase()===(qEl.value||'').toLowerCase().trim()){\n" |
| 377 | " open(entities[i].name);return;}\n" |
| 378 | " }\n" |
| 379 | "};\n" |
| 380 | "\n" |
| 381 | "var tb=el('btnTheme');\n" |
| 382 | "if(tb&&window.sxApplyTheme){\n" |
| 383 | " tb.onclick=function(){window.sxApplyTheme(window.sxTheme&&window.sxTheme()==='dark'?'light':'dark');};\n" |
| 384 | "}\n" |
| 385 | "\n" |
| 386 | "refreshAll();\n" |
| 387 | "})();\n" |
| 388 | "</script>\n" |
| 389 | "\002</body></html>\n" |
| 390 | ; |
| 391 | |
| 392 | #endif /* SX_MEMORY_UI_HTML_H */ |