add back to project button; pre-filled inline snippets from projects

master
Garrett Mills 3 years ago
parent 84e3e94920
commit 1c0bdffc68
  1. 15
      app/MiscUnit.js
  2. 33
      app/controllers/dash/v1.controller.js
  3. 1
      app/routing/routers/dash/v1.routes.js
  4. 2
      app/views/dash_v1/confirm.pug
  5. 5
      app/views/dash_v1/editor_template.pug
  6. 17
      app/views/dash_v1/in_editor.pug
  7. 5
      app/views/dash_v1/template.pug
  8. 15
      app/views/dash_v1/view.pug

@ -40,11 +40,18 @@ class MiscUnit extends Unit {
// do stuff here
global.devbug = {
version: '0.6.0',
get_inline: function(type, project){
let code = this.code[type];
if (!code) return false
code = code.replace(/{{ Project API Key }}/g, project.uuid).replace(/{{ Server URL }}/g, _flitter.config('server.url'))
return code
},
code: {
node: `require("devbugjs")
dbsetup({
\tserver: "https://CHANGEME:8000/", // DevBug Server URL
\tproject: "CHANGEME", // Project API Key
\tserver: "{{ Server URL }}", // DevBug Server URL
\tproject: "{{ Project API Key }}", // Project API Key
})`,
api: `// Send a multipart/form-data POST request to:
// http://#{_flitter.config('server.url')}/api/v1/out/<project api key>
@ -79,8 +86,8 @@ function out($key, $what, $group = null){
}
function breakpoint($continue = false, $name = null){
global $dev_outs;
$devbug = "http://localhost:8000/";
$project_api_key = "CHANGEME";
$devbug = "{{ Server URL }}";
$project_api_key = "{{ Project API Key }}";
$bt = debug_backtrace();
$caller = array_shift($bt);

@ -138,7 +138,38 @@ class v1 {
return _flitter.error(res, 401, {reason: 'You do not have permission to view this project.'})
}
return _flitter.view(res, 'dash_v1:view', {user: req.session.auth.user, snippets, project, outs, show_back: true, title: 'View: '+project.name })
return _flitter.view(res, 'dash_v1:view', {user: req.session.auth.user, snippets, project, outs, show_back: true, window_back: true, title: 'View: '+project.name })
}
async project_view_inline_helper(req, res, next){
const project = await Project.findById(req.params.id)
if ( !project ){
return _flitter.error(res, 404, {reason: 'Project not found with the specified ID.'})
}
if ( !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 code = devbug.get_inline(req.params.type, project)
if ( !code ) return _flitter.error(res, 404, {reason: 'Inline helper snippet not found with the specified type.'})
let type;
if ( req.params.type === 'node' ) type = 'javascript'
else if ( req.params.type === 'php' ) type = 'php'
else type = 'text'
return _flitter.view(res, 'dash_v1:in_editor', {
user: req.session.auth.user,
project,
show_back: true,
readonly: true,
editor_code: code,
editor_lang: 'ace/mode/'+type,
title: 'Inline Helper for '+project.name+' ('+req.params.type+')'
})
}
async out_view(req, res, next){

@ -39,6 +39,7 @@ const v1 = {
'/project/new': [ _flitter.controller('dash:v1').new_project_show ],
'/project/view/:id': [ _flitter.controller('dash:v1').project_view ],
'/project/view/:id/inline/:type': [ _flitter.controller('dash:v1').project_view_inline_helper ],
'/project/delete/:id': [ _flitter.controller('dash:v1').project_delete_show ],
'/project/edit/:id': [ _flitter.controller('dash:v1').project_edit_show ],
'/:api/share/:id': [ _flitter.controller('dash:v1').project_share_show ],

@ -2,4 +2,4 @@ extends ./template
block content
p #{text}
form(method='post' action=destination)
button(type='submit') Yes, I'm sure.
button.btn(type='submit') Yes, I'm sure.

@ -26,8 +26,11 @@ html
a#navbar-usage(href='/dash/v1/using_devbug/main') Using DevBug
li.navbar-right
a#navbar-logout(href='/auth/logout') Logout
if show_back
if show_back && (!project || window_back)
li.navbar-right
a#navbar-back(href='javascript:window.history.back()') Back
else if show_back && project
li.navbar-right
a#navbar-back(href='/dash/v1/project/view/'+project.id) Back to Project
script(src="/assets/dash_v1.js")
block scripts

@ -0,0 +1,17 @@
extends ./editor_template
block content
pre#editor #{ editor_code ? editor_code : '' }
input#preset_mode(type='hidden' value=editor_lang ? editor_lang : 'ace/mode/text')
block scripts
script(src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.5/ace.js")
script.
const readonly = #{!!readonly}
const preset_mode = document.getElementById('preset_mode').value
const editor = ace.edit('editor');
editor.setTheme(window.devbug_editor_theme);
console.log('preset mode: ', preset_mode);
editor.session.setMode(preset_mode);
if ( readonly ){
editor.setOption('readOnly', true)
}

@ -17,9 +17,12 @@ html
block navbar-left
li.navbar-right
a#navbar-logout(href='/auth/logout') Logout
if show_back
if show_back && (!project || window_back)
li.navbar-right
a#navbar-back(href='javascript:window.history.back()') Back
else if show_back && project
li.navbar-right
a#navbar-back(href='/dash/v1/project/view/'+project.id) Back to Project
block navbar-right
.content
block content

@ -2,6 +2,21 @@ extends ./template
block content
h3 Project API Key: #{project.uuid}
h2 Inline Helpers
p You can use the links below to generate inline helper scripts which are pre-configured for this project.
ul(style='list-style-type: none; margin: 0; padding: 0;')
li.action-li
a.btn(href=project.id+'/inline/node') Node.js
//li.action-li
// a.btn(href=project.id+'/inline/ecma') JavaScript (Web)
li.action-li
a.btn(href=project.id+'/inline/php') PHP
//li.action-li
// a.btn(href=project.id+'/inline/api') DevBug API
br
br
h2 Code Snippets
a.btn(href='/dash/v1/project/snippet/'+project.id+'/new') +
table

Loading…
Cancel
Save