bug fix: new features, code generation

main
Steve Nyemba 2 weeks ago
parent 308f7fad79
commit 5eea2d67f3

@ -1,2 +1,2 @@
xlsxwriter
openpyxl
openpyxl

@ -0,0 +1,255 @@
/* PrismJS 1.30.0
https://prismjs.com/download#themes=prism&languages=clike+javascript+mongodb+nasm+python+sql&plugins=line-highlight+line-numbers */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/
code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: 1em;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}
@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}
/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}
:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #f5f2f0;
}
/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}
.token.punctuation {
color: #999;
}
.token.namespace {
opacity: .7;
}
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #9a6e3a;
/* This background color was intended by the author of this theme. */
background: hsla(0, 0%, 100%, .5);
}
.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}
.token.function,
.token.class-name {
color: #DD4A68;
}
.token.regex,
.token.important,
.token.variable {
color: #e90;
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}
pre[data-line] {
position: relative;
padding: 1em 0 1em 3em;
}
.line-highlight {
position: absolute;
left: 0;
right: 0;
padding: inherit 0;
margin-top: 1em; /* Same as .prisms padding-top */
background: hsla(24, 20%, 50%,.08);
background: linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
pointer-events: none;
line-height: inherit;
white-space: pre;
}
@media print {
.line-highlight {
/*
* This will prevent browsers from replacing the background color with white.
* It's necessary because the element is layered on top of the displayed code.
*/
-webkit-print-color-adjust: exact;
color-adjust: exact;
}
}
.line-highlight:before,
.line-highlight[data-end]:after {
content: attr(data-start);
position: absolute;
top: .4em;
left: .6em;
min-width: 1em;
padding: 0 .5em;
background-color: hsla(24, 20%, 50%,.4);
color: hsl(24, 20%, 95%);
font: bold 65%/1.5 sans-serif;
text-align: center;
vertical-align: .3em;
border-radius: 999px;
text-shadow: none;
box-shadow: 0 1px white;
}
.line-highlight[data-end]:after {
content: attr(data-end);
top: auto;
bottom: .4em;
}
.line-numbers .line-highlight:before,
.line-numbers .line-highlight:after {
content: none;
}
pre[id].linkable-line-numbers span.line-numbers-rows {
pointer-events: all;
}
pre[id].linkable-line-numbers span.line-numbers-rows > span:before {
cursor: pointer;
}
pre[id].linkable-line-numbers span.line-numbers-rows > span:hover:before {
background-color: rgba(128, 128, 128, .2);
}
pre[class*="language-"].line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}
pre[class*="language-"].line-numbers > code {
position: relative;
white-space: inherit;
}
.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em; /* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.line-numbers-rows > span {
display: block;
counter-increment: linenumber;
}
.line-numbers-rows > span:before {
content: counter(linenumber);
color: #999;
display: block;
padding-right: 0.8em;
text-align: right;
}

@ -39,6 +39,14 @@
border-color:transparent;
font-family: courier;
padding:8px; line-height: 1.5; background-color: #f3f3f3;
/** ------------------ **/
font-family: monospace;
white-space: pre; /* Ensures whitespace is rendered correctly */
word-wrap: normal; /* Prevents wrapping */
overflow: auto; /* Adds scrollbars if needed */
/* Add more styles as needed */
/* height:350px; */
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

File diff suppressed because it is too large Load Diff

@ -178,9 +178,9 @@ studio.grid = function (){
$(_id)[0].spreadsheet = spreadsheet
// console.log([' **** ',(_id+' .e-input-group')])
// $(_id+' .e-input-group').remove()
spreadsheet.hideFileMenuItems(["File"], true);
spreadsheet.refresh()
spreadsheet.refresh()
spreadsheet.hideFileMenuItems(["File"], true);
}
}
@ -256,8 +256,8 @@ studio.frame = function (_args){
}else{
$(_bench).css({display:'grid'})
_id = '.'+_label+' .output'
console.log(_id)
$(_id)[0].spreadsheet.refresh()
$(_id)[0].spreadsheet.hideFileMenuItems(["File"], true);
}
})
@ -338,7 +338,7 @@ studio.frame = function (_args){
var _label = $('<div class="bold"></div>').html(this._args.label+'<div style="font-weight:lighter; font-size:11px;">'+this._args.provider+'</div>')
read = this.read
_compute = this.compute
_xbutton = $('<div class="border-left"><div class="active apply" align="center"><i class="fa-solid fa-play"></i></div></div>').on('click',function (){
_xbutton = $('<div class="border-left"><div class="active apply" align="center" title="Run Query"><i class="fa-solid fa-play"></i></div></div>').on('click',function (){
var _id = '.code.'+_args.label.trim()
@ -351,7 +351,19 @@ studio.frame = function (_args){
}
})
_pythonCode = ('<div class="border-left" title="Python Code"><div class="active" align="center"><img src="api/disk/read?uri=www/html/_assets/images/python.png" style="width:20px" /></div></div>')
_pythonCode = $('<div class="border-left" title="Python Code"><div class="active" align="center"><img src="api/disk/read?uri=www/html/_assets/images/python.png" style="width:20px" /></div></div>')
_pythonCode.on('click',()=>{
_query = $(`.${_args.label} textarea`).val()
sessionStorage._label = _args.label
sessionStorage._query = _query
var _kwargs = {uri:'www/html/sheet.html',title:'Generated Python Code',context:''}
dialog.show(_kwargs)
})
_openFile = $('<div class="border-left"><div class="active" title="Open File"><i class="fa-regular fa-folder-open"></i></div></div>')
$(_openFile).on('click',()=>{
var _id = '.'+_args.label+' .open-file'
@ -390,6 +402,7 @@ studio.frame = function (_args){
$(_id+' .expand').empty().html(_icon).attr('title',_title)
var spreadsheet = $(_id+' .output')[0].spreadsheet
spreadsheet.refresh()
spreadsheet.hideFileMenuItems(["File"], true);
})
var _buttons = $('<div style="display:grid; grid-template-columns: auto repeat(6,64px); gap:4px;" align="center"><div>&nbsp;</div></div>')
@ -406,7 +419,7 @@ studio.frame = function (_args){
_query = studio.defaults[_args.provider]
$(_textarea).val(_query)
}
$(_textarea).on('keydown',function (_e){
if (_e.shiftKey && (_e.keyCode == 13 || _e.key == 'Enter')){
var _id = $(this).attr('label')
@ -414,13 +427,17 @@ studio.frame = function (_args){
$(_id).click()
}
})
_outputframe = $('<div class="output" ></div><div class="status"></div><input type="file" class="open-file" style="display:none" accept=".csv, .xls, .xlsx"/>')
// $(_frame).append(_inputframe, _outputframe)
$(_frame).append(_ctrl,_textarea,_outputframe)
$('.studio-pane').append(_frame)
$(_textarea).focus()
var _id = this._args.label
_id = `.${_id} code`
this.compute()
}

@ -1,13 +1,13 @@
import cms
#
# register this in config.plugins: {"demo":["info"]}
import cms
#
# register this in config.plugins: {"demo":["info"]}
@cms.plugins(mimetype='application/json') :
def info (**_args):
_request= _args['request']
_config = _args['config']
return {"version":_config['system']['version'],'title':_config['layout']['header']['title']}
pass
@cms.plugins(mimetype='application/json') :
def info (**_args):
_request= _args['request']
_config = _args['config']
return {"version":_config['system']['version'],'title':_config['layout']['header']['title']}
pass

@ -40,6 +40,22 @@ def format (file,_mimetype) :
return {'Workbook':{'sheets':sheets}}
@cms.Plugin(mimetype="text/plain")
def python (**_args) :
_request = _args['request']
_code ="""
# generated code
import pandas as pd
import transport
#
# genereric data reader
dreader = transport.get.reader(label='{_label}')
_df = dreader.read(sql=_sql)
"""
@cms.Plugin(mimetype="application/json",method="POST")
def open(**_args):

@ -56,6 +56,8 @@ $(document).ready(()=>{
var layout = {on:{load:{}}}
layout.on.load.intro = ['www/html/features.html']
bootup.init('{{system.context}}',layout)
})
</script>
@ -119,5 +121,6 @@ $(document).ready(()=>{
</ul>
</div>
</div>
</div>

@ -30,6 +30,9 @@
<script src="www/html/_assets/lib/spreadsheet/syncfusion/shim.min.js"></script>
<script src="www/html/_assets/lib/spreadsheet/syncfusion/syncfusion-helper.js"></script>
<link href="www/html/_assets/css/prism.css" type="text/css" rel="stylesheet">
<script src="www/html/_assets/js/prism.js"></script>
<script src="www/html/_assets/js/forms.js"></script>
<!-- <script src="https://bossanova.uk/jspreadsheet/v5/jspreadsheet.js"></script>

@ -160,7 +160,7 @@
</div>
<div class="_border-round border" style="margin-top:4px;padding:4px; background-color: #f3f3f3;">
<div class="active" style="margin:4px" onclick='window.open("https://dev.the-phi.com/git/data-transport")'>
<i class="fa-brands fa-git-alt"></i> Check <b>github</b>
<i class="fa-brands fa-git-alt"></i> <b>github</b>
</div>
</div>

@ -1,60 +1,63 @@
<!-- Jspreadsheet CSS & JS -->
<script src="https://cdn.jsdelivr.net/npm/jspreadsheet-ce"></script>
<link rel="stylesheet" href="https://bossanova.uk/jspreadsheet/v5/jspreadsheet.css" type="text/css" />
<!-- Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<canvas id="chartCanvas" width="600" height="400"></canvas>
<button onclick="renderChart()">Generate Chart</button>
<script>
const data = [
['Year', 'Sales'],
['2020', 100],
['2021', 150],
['2022', 130],
['2023', 180]
];
async function ToClipboard(text) {
try {
await navigator.clipboard.writeText(text);
console.log('Text copied to clipboard successfully!');
} catch (err) {
console.error('Failed to copy text:', err);
}
}
var copy = function(){
_i = $('<i class="fa-solid fa-check"></i>')
_button = $('.generated-code .copy')
$(_button).empty()
$(_button).append(_i)
var _code = $('.generated-code code').text()
ToClipboard(_code)
}
$(document).ready(()=>{
var _element = $('.generated-code code')[0]
_html = $('.generated-code code').html()
_html = _html.replace(/:label/g,sessionStorage._label)
if (sessionStorage._query.startsWith('{')){
pass
}else{
_html = _html.replace(/:_query/,`{'sql':"""${sessionStorage._query.replace(/\n/g,' ')}"""}`)
}
$('.generated-code code').html(_html)
Prism.highlightElement(_element)
$('.generated-code .copy').on('click',copy)
})
</script>
const spreadsheet = jspreadsheet(document.getElementById('spreadsheet'), {
data,
columns: [
{ type: 'text', title: 'Year', width: 100 },
{ type: 'numeric', title: 'Sales', width: 100 },
]
});
function renderChart() {
const sheetData = spreadsheet.getData();
const labels = sheetData.slice(1).map(row => row[0]);
const values = sheetData.slice(1).map(row => parseFloat(row[1]));
<div style="width:650px;">
const ctx = document.getElementById('chartCanvas').getContext('2d');
<div class="generated-code">
<span class="active copy" style="float:right; padding:4px" >
<i class="fa-solid fa-copy" ></i>
</span>
<pre style="margin:4px; padding:4px; background-color: transparent;">
<code class="code language-python" style="line-height:1.5;text-wrap: wrap;">
"""
install data-transport
pip install data-transport[all]@git+https://github.com/lnyemba/data-transport
"""
import transport
import pandas as pd
// Clear previous chart instance if any
if (window.myChart) window.myChart.destroy();
# data-transport instance to read data
#
reader = transport.get.reader(label=':label')
_args = :_query
window.myChart = new Chart(ctx, {
type: 'bar', // or 'line', 'pie', etc.
data: {
labels,
datasets: [{
label: 'Sales',
data: values,
backgroundColor: 'rgba(75, 192, 192, 0.5)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
}
</script>
<div id="spreadsheet"></div>
# reading the query from ":label" into a pandas data-frame
_df = reader.read(**_args)
print(_df.head())
</code>
</pre>
</div>
</div>
Loading…
Cancel
Save