update flap and add latest output button

This commit is contained in:
2019-08-14 10:03:19 -05:00
parent 5afe24ed52
commit 287cd0107d
6 changed files with 149 additions and 44 deletions

View File

@@ -69,46 +69,63 @@ dbsetup({
// ===========================================================
// DEVBUG INLINE DEBUGGING HELPER - FOR USE WITH DEVBUG SERVER
// TODO: REMOVE BEFORE COMMITTING
$dev_outs = [];
function devbug_microtime($difftime = 0){
$time = explode(' ', microtime()); return ((float)$time[1]+(float)$time[0])-$difftime; }
$GLOBALS['devbug_dev_outs'] = [];
$GLOBALS['devbug_dev_out_iters'] = [];
$GLOBALS['devbug_mark_time'] = devbug_microtime();
function out($key, $what, $group = null){
global $dev_outs;
if ( $group ){
if ( !array_key_exists($group, $dev_outs) ){
$dev_outs[$group] = [ $key => $what ];
}
else {
$dev_outs[$group][$key] = $what;
}
}
else {
$dev_outs[$key] = $what;
}
$dev_outs = $GLOBALS['devbug_dev_outs'];
if ( $group ){
if ( !array_key_exists($group, $dev_outs) ) $dev_outs[$group] = [ $key => $what ];
else $dev_outs[$group][$key] = $what;
}
else $dev_outs[$key] = $what;
$GLOBALS['devbug_dev_outs'] = $dev_outs;
}
function breakpoint($continue = false, $name = null){
global $dev_outs;
$devbug = "{{ Server URL }}";
$project_api_key = "{{ Project API Key }}";
$bt = debug_backtrace();
$caller = array_shift($bt);
$dev_outs = $GLOBALS['devbug_dev_outs'];
$devbug = "{{ Server URL }}/";
$project_api_key = "{{ Project API Key }}";
$bt = debug_backtrace();
$caller = array_shift($bt);
$time = devbug_microtime();
$dev_outs['DevBug Summary'] = [
'Start Time' => $GLOBALS['devbug_mark_time'],
'Breakpoint Time' => $time,
'Total Execution Time' => $time - $GLOBALS['devbug_mark_time'],
'Breakpoint Stacktrace' => $caller,
];
// Send to devbug server
$ch = curl_init();
$url = $devbug.'api/v1/out/'.$project_api_key;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'data' => json_encode([
'brief' => ($name ? $name : 'Breakpoint').': '.$caller['file'].': '.$caller['line'],
'data' => $dev_outs,
])
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$odata = curl_exec($ch);
if ( !$continue ) { exit(); }
// Send to devbug server
$ch = curl_init();
$url = $devbug.'api/v1/out/'.$project_api_key;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'data' => json_encode([
'brief' => ($name ? $name : 'Breakpoint').': '.$caller['file'].': '.$caller['line'],
'data' => $dev_outs,
])
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$odata = curl_exec($ch);
if ( !$continue ) { exit(); }
}
function devbugtime($prefix = 'time: '){ $mt = explode(' ', microtime()); $mt = $mt[1].' '.$mt[0]; return $prefix.$mt; }
function outtime($key, $what, $group = null){ out(devbugtime($key), $what, $group); }
function outiter($key, $what, $group = null){
$keyname = $group ? $key.$group : $key;
if ( !$GLOBALS['devbug_dev_out_iters'][$keyname] ) $GLOBALS['devbug_dev_out_iters'][$keyname] = 0;
out($key.'_'.$GLOBALS['devbug_dev_out_iters'][$keyname], $what, $group);
$GLOBALS['devbug_dev_out_iters'][$keyname]++;
}
function outpoint($group){
$bt = debug_backtrace();
$caller = array_shift($bt);
out('point: '.$caller['file'].': '.$caller['line'], devbugtime(), $group);
}
function devbug_chop($string, $at=120){ return substr($string, 0, 30); }
// ===========================================================`,
},
permission: {

View File

@@ -196,6 +196,29 @@ class v1 {
return _flitter.view(res, 'dash_v1:out', {project, user: req.session.auth.user, out, prettyd:pretty, show_back: true, title: out.brief, title_small: true });
}
async out_latest(req, res, next){
const project = await Project.findById(req.params.project)
if ( !project || (!await devbug.permission.project.view(project, req.session.auth.user)) ){
return _flitter.error(res, 401, {reason: 'You do not have permission to view this project.'})
}
const out = await Out.findOne({}, {}, { sort: { 'created': -1 } })
if ( !out ){
return _flitter.error(res, 404, {reason: 'This project has no outputs yet.'})
}
let pretty
try {
pretty = JSON.stringify(JSON.parse(out.data), null, 4)
console.log('Pretty out: ', pretty)
}
catch (e){
return _flitter.error(res, 500, {reason: 'Unable to parse output data. Data contains invalid JSON.'})
}
return _flitter.view(res, 'dash_v1:out', {project, user: req.session.auth.user, out, prettyd:pretty, show_back: true, title: 'Latest output: '+out.brief, title_small: true });
}
async out_delete(req, res, next){
const out = await Out.findById(req.params.id)

View File

@@ -57,6 +57,7 @@ const v1 = {
'/using_devbug/:page': [ _flitter.controller('dash:v1').show_usage_page ],
'/out/view/:id': [ _flitter.controller('dash:v1').out_view ],
'/out/view-latest/:project': [ _flitter.controller('dash:v1').out_latest ],
'/out/delete/:id/:project': [ _flitter.controller('dash:v1').out_delete ],
'/code': [ _flitter.controller('dash:v1').view_code ],

View File

@@ -43,6 +43,7 @@ block content
a.action(href='/dash/v1/snippet/share/'+snippet.id) Share
h2 Development Outputs
a.btn(href='/dash/v1/out/view-latest/'+project.id) Latest
table
thead
tr