Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ottomatica/docable-notebooks into…
Browse files Browse the repository at this point in the history
… master
  • Loading branch information
ssmirr committed Sep 18, 2020
2 parents 5f62584 + 2939deb commit cae2ad6
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 52 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Your Docable Notebooks can be interacted with at http://localhost:3000.
#### Install help

* If you have problems with `gyp` on MacOs, [see this simple guide](https://medium.com/flawless-app-stories/gyp-no-xcode-or-clt-version-detected-macos-catalina-anansewaa-38b536389e8d) for setting up/reinstalling CommandLineTools.
* If updating existing repository, make sure to run `npm update && npm install` to get updates from modules.

## Advanced Features

Expand Down
7 changes: 1 addition & 6 deletions docs/examples/advanced/runbooks/deploy-hosted-notebooks.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<!--
setup:
ssh:
host: user@ip
privateKey: ~/.ssh/id_rsa
-->



# Deploy Docable Notebooks (Ubuntu)
Expand Down
6 changes: 0 additions & 6 deletions docs/examples/advanced/runbooks/install-letsencrypt-ssl.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<!--
setup:
ssh:
host: user@ip
privateKey: ~/.ssh/id_rsa
-->

# Install Let's encrypt SSL for a nginx webserver

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/advanced/runbooks/ottomatica/www.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ server {
proxy_pass http://127.0.0.1:3333;
proxy_read_timeout 90;
proxy_redirect http://127.0.0.1:3333 https://services.ottomatica.com;
proxy_redirect http://127.0.0.1:3333 https://services.ottomatica.io;
}
}
```
Expand Down
5 changes: 4 additions & 1 deletion index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#! /usr/bin/env node
const path = require("path");

const yargs = require('yargs');
Expand Down Expand Up @@ -42,6 +43,8 @@ const notebookSlug = require('./lib/notebook/slug');

const app = express();

const isHosted = process.env.prod ? true: false;

app.use(session({
secret: "Shh, its a secret!",
resave: true,
Expand Down Expand Up @@ -94,7 +97,7 @@ if (process.env.NODE_ENV == 'dev') {
user.gravatar = `https://www.gravatar.com/avatar/${hash}`;
}

res.render("home", { github_imports, notebook_tree, user });
res.render("home", { github_imports, notebook_tree, user, isHosted });
});

app.get('/variables', workspace_routes.variables);
Expand Down
24 changes: 15 additions & 9 deletions lib/notebook/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const policy = require('./policy');

var uuid = require('uuid');

const isHosted = process.env.prod ? true: false;

class NotebookRender
{
async notebookRender(session, rootDir, md, ir) {
Expand Down Expand Up @@ -113,15 +115,19 @@ class NotebookRender
// cell is parent to overlay
overlay.wrap(cell);

// add buttons
let more_btn =
`<button class="docable-overlay-btn-reveal btn-more">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 560 560" id="more-icon-560" aria-hidden="true" class="option-menu">
<path d="M350 280c0 38.634-31.366 70-70 70s-70-31.366-70-70 31.366-70 70-70 70 31.366 70 70m0-210c0 38.634-31.366 70-70 70s-70-31.366-70-70 31.366-70 70-70 70 31.366 70 70m0 420c0 38.634-31.366 70-70 70s-70-31.366-70-70 31.366-70 70-70 70 31.366 70 70"></path>
</svg>
</button>
`;
overlay.append(more_btn);
if( !isHosted )
{

// add buttons
let more_btn =
`<button class="docable-overlay-btn-reveal btn-more">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 560 560" id="more-icon-560" aria-hidden="true" class="option-menu">
<path d="M350 280c0 38.634-31.366 70-70 70s-70-31.366-70-70 31.366-70 70-70 70 31.366 70 70m0-210c0 38.634-31.366 70-70 70s-70-31.366-70-70 31.366-70 70-70 70 31.366 70 70m0 420c0 38.634-31.366 70-70 70s-70-31.366-70-70 31.366-70 70-70 70 31.366 70 70"></path>
</svg>
</button>
`;
overlay.append(more_btn);
}

if( executable )
{
Expand Down
1 change: 1 addition & 0 deletions lib/routes/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { setNonEnumerableProperties } = require('got/dist/source');

let {logger, notebook_dir, configPath, config, githubImportsDir} = env.vars();

const isHosted = process.env.prod ? true: false;

exports.get_notebook = async function (req, res) {

Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"description": "Notebooks for CM and DevOps",
"main": "index.js",
"bin": "index.js",
"scripts": {
"dev": "cross-env LOG_LEVEL=debug NODE_ENV=dev nodemon ./index.js --notebook_dir docs/examples/ | pino-pretty",
"prod": "cross-env LOG_LEVEL=debug NODE_ENV=prod pm2 start ./index.js -- --notebook_dir docs/examples/ ",
Expand Down
49 changes: 26 additions & 23 deletions public/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function run(endPoint, body, stepIndex)
}
}
else {
output.append(`<span>${data}</span>\n`);
output.append(`<span>${data}</span>`);
}

});
Expand Down Expand Up @@ -268,35 +268,38 @@ const EditForm = ({stepIndex}) =>
</div>
`;

// We use the parent, with child selector because if cells are dynamically updated, then they will not be registered.
$('main').on('click', '.btn-more', function () {
let stepIndex = $('pre[data-docable="true"]').index($(this).siblings('pre[data-docable="true"]'));
let cell = $('[data-docable="true"]').eq(stepIndex);
if( !isHosted )
{
// We use the parent, with child selector because if cells are dynamically updated, then they will not be registered.
$('main').on('click', '.btn-more', function () {
let stepIndex = $('pre[data-docable="true"]').index($(this).siblings('pre[data-docable="true"]'));
let cell = $('[data-docable="true"]').eq(stepIndex);

let cell_overlay = $(this).parent();
$(cell_overlay).hide();
let cell_overlay = $(this).parent();
$(cell_overlay).hide();

cell_overlay.parent().append( EditForm({stepIndex}) );
cell_overlay.parent().append( EditForm({stepIndex}) );

$('#btn-cancel-cell').on('click', function () {
$("#update-cell-form").remove();
$(cell_overlay).show();
});
$('#btn-cancel-cell').on('click', function () {
$("#update-cell-form").remove();
$(cell_overlay).show();
});

$('#btn-update-cell').on('click', function () {
editCell($(`textarea[id="docable-edit-area-${stepIndex}"`).val())
.then(data => {
let cell = $('[data-docable="true"]').eq(stepIndex);
cell.parent().parent().replaceWith( data );
$('#btn-update-cell').on('click', function () {
editCell($(`textarea[id="docable-edit-area-${stepIndex}"`).val())
.then(data => {
let cell = $('[data-docable="true"]').eq(stepIndex);
cell.parent().parent().replaceWith( data );
});
});
});

viewCell($(cell)[0].outerHTML, stepIndex)
.then(data => {
console.log(data);
$(`#docable-edit-area-${stepIndex}`).val(data.cell);
viewCell($(cell)[0].outerHTML, stepIndex)
.then(data => {
console.log(data);
$(`#docable-edit-area-${stepIndex}`).val(data.cell);
});
});
});
}

// new ClipboardJS('.copy-btn', {
// text: function (trigger) {
Expand Down
5 changes: 5 additions & 0 deletions views/home.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<h2>📓 Your Notebooks</h2>

<div class="tree-actions">
<% if (!locals.isHosted) { %>
<button id="btn-openFolder" type="button" data-toggle="tooltip" data-placement="right" class="btn btn-outline-dark py-0" title="Open Folder in System">
<i class="far fa-folder-open"></i>
</button>
Expand All @@ -153,6 +154,7 @@
<path class="icon-path" d="m218.62 29.953-105.41 96.92-58.909-44.403l-24.346 14.17 58.068 53.359-58.068 53.359 24.346 14.212 58.909-44.402 105.41 96.878 51.424-24.976v-190.14zm0 63.744v112.6l-74.719-56.302z" fill="#000" stroke-width="17.15"/>
</svg>
</button>
<% } %>
</div>

<div id="tree"></div>
Expand Down Expand Up @@ -216,6 +218,8 @@
// }
// });
<% if (!locals.isHosted) { %>
$('#btn-openFolder').click(function()
{
var tree = $.ui.fancytree.getTree("#tree");
Expand All @@ -241,6 +245,7 @@
openEditor(dir);
});
<% } %>
});
Expand Down
8 changes: 7 additions & 1 deletion views/notebook.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@
<%- include('templates/environment'); -%>
<% } %>

<!-- Turn off whole notebook execution when hosted -->
<% if (!locals.isHosted) { %>
<button type="button" class="ml-auto btn btn-outline-success" id="submit">
<span class="" role="status" id="submit-button" aria-hidden="true"></span>
Run Notebook
</button>
<% } %>

</nav>
</header>

Expand All @@ -88,8 +92,10 @@
<%- notebookHtml %>
</div>

<!--- style customization not supported by css -->
<!--- init and style customization not supported by css -->
<script>
var isHosted = locals.isHosted;
$("[data-type='command'][data-spawn='true']")
.parents('.docable-cell').children('.sideAnnotation').append('🖥️ ');
$("[data-type='script'][data-lang='js']")
Expand Down

0 comments on commit cae2ad6

Please sign in to comment.