From 1c0bdffc68327c940c2104c041d9eb9c07de2d2a Mon Sep 17 00:00:00 2001 From: Garrett Mills Date: Wed, 7 Aug 2019 13:01:05 -0500 Subject: [PATCH] add back to project button; pre-filled inline snippets from projects --- app/MiscUnit.js | 15 ++++++++---- app/controllers/dash/v1.controller.js | 33 ++++++++++++++++++++++++++- app/routing/routers/dash/v1.routes.js | 1 + app/views/dash_v1/confirm.pug | 2 +- app/views/dash_v1/editor_template.pug | 5 +++- app/views/dash_v1/in_editor.pug | 17 ++++++++++++++ app/views/dash_v1/template.pug | 5 +++- app/views/dash_v1/view.pug | 15 ++++++++++++ 8 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 app/views/dash_v1/in_editor.pug diff --git a/app/MiscUnit.js b/app/MiscUnit.js index 75f1566..b20aed6 100644 --- a/app/MiscUnit.js +++ b/app/MiscUnit.js @@ -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/ @@ -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); diff --git a/app/controllers/dash/v1.controller.js b/app/controllers/dash/v1.controller.js index cfc15e5..e1d18b1 100644 --- a/app/controllers/dash/v1.controller.js +++ b/app/controllers/dash/v1.controller.js @@ -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){ diff --git a/app/routing/routers/dash/v1.routes.js b/app/routing/routers/dash/v1.routes.js index 7f6c527..43214c0 100644 --- a/app/routing/routers/dash/v1.routes.js +++ b/app/routing/routers/dash/v1.routes.js @@ -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 ], diff --git a/app/views/dash_v1/confirm.pug b/app/views/dash_v1/confirm.pug index cd8d5c0..fcdeb84 100644 --- a/app/views/dash_v1/confirm.pug +++ b/app/views/dash_v1/confirm.pug @@ -2,4 +2,4 @@ extends ./template block content p #{text} form(method='post' action=destination) - button(type='submit') Yes, I'm sure. \ No newline at end of file + button.btn(type='submit') Yes, I'm sure. \ No newline at end of file diff --git a/app/views/dash_v1/editor_template.pug b/app/views/dash_v1/editor_template.pug index 26b2828..6f3b31f 100644 --- a/app/views/dash_v1/editor_template.pug +++ b/app/views/dash_v1/editor_template.pug @@ -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 diff --git a/app/views/dash_v1/in_editor.pug b/app/views/dash_v1/in_editor.pug new file mode 100644 index 0000000..4d01c3a --- /dev/null +++ b/app/views/dash_v1/in_editor.pug @@ -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) + } diff --git a/app/views/dash_v1/template.pug b/app/views/dash_v1/template.pug index 0cbcdaf..4d508d7 100644 --- a/app/views/dash_v1/template.pug +++ b/app/views/dash_v1/template.pug @@ -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 diff --git a/app/views/dash_v1/view.pug b/app/views/dash_v1/view.pug index 5749be2..bae26eb 100644 --- a/app/views/dash_v1/view.pug +++ b/app/views/dash_v1/view.pug @@ -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