Skip to content

Commit

Permalink
🌌 Run all unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed May 5, 2020
1 parent 98728e0 commit 8fef806
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Pluto"
uuid = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
license = "MIT"
authors = ["Fons van der Plas <fonsvdplas@gmail.com>", "MikoΕ‚aj Bochenski <iceflamecode@gmail.com>"]
version = "0.8.0"
version = "0.8.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ We are happy to say that Pluto.jl runs smoothly for most users, and is **ready t

That being said, the Pluto project is an ambition to [_rethink what a programming environment should be_](http://worrydream.com/#!/LearnableProgramming). We believe that scientific programming can be a lot simpler. Not by adding more buttons to a text editor β€” by giving space to creative thought, and automating the rest.

If you feel the same, give Pluto a try! We would love to hear your what you think. 😊
If you feel the same, give Pluto a try! We would love to hear what you think. 😊

<img alt="feedback screencap" src="https://user-images.githubusercontent.com/6933510/78135402-22d02d80-7422-11ea-900f-a8b01bdbd8d3.png" width="70%">

Expand Down
14 changes: 9 additions & 5 deletions assets/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,12 @@
position: relative;
}

body.loading>main>preamble>button {
opacity: 0%;
main>preamble>button {
display: none;
}

body.code-differs>main>preamble>button {
display: block;
}

cell {
Expand Down Expand Up @@ -360,8 +364,8 @@
pointer-events: none;
}

button.runall>span::after {
content: "Run all β–Άβ–Ά";
button.runallchanged>span::after {
content: "Submit all changes β–Άβ–Ά";
}

button.addcell>span::after {
Expand Down Expand Up @@ -644,7 +648,7 @@ <h1>

<main>
<preamble>
<button class="runall" title="Run all"><span></span></button>
<button class="runallchanged" title="Save and run all changed cells"><span></span></button>
</preamble>
<notebook>
</notebook>
Expand Down
77 changes: 44 additions & 33 deletions assets/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function updateRemoteNotebooks(list) {

/* DOM THINGIES */

document.querySelector("preamble>button.runall").onclick = (e) => {
requestRunAllRemoteCells()
document.querySelector("preamble>button.runallchanged").onclick = (e) => {
requestRunAllChangedRemoteCells()
}

cellTemplate = document.querySelector("#celltemplate").content.firstElementChild
Expand Down Expand Up @@ -88,7 +88,7 @@ window.localCells = {}
window.codeMirrors = {}

function createCodeMirrorInsideCell(cellNode, code) {
var editor = CodeMirror((elt) => {
var cm = CodeMirror((elt) => {
cellNode.querySelector("cellinput").appendChild(elt)
}, {
value: code,
Expand All @@ -107,10 +107,10 @@ function createCodeMirrorInsideCell(cellNode, code) {
matchBrackets: true,
});

window.codeMirrors[cellNode.id] = editor
//editor.setOption("readOnly", true);
window.codeMirrors[cellNode.id] = cm
//cm.setOption("readOnly", true);

editor.setOption("extraKeys", {
cm.setOption("extraKeys", {
"Ctrl-Enter": () => requestChangeRemoteCell(cellNode.id),
"Shift-Enter": () => {
requestNewRemoteCell(indexOfLocalCell(cellNode) + 1)
Expand All @@ -127,24 +127,27 @@ function createCodeMirrorInsideCell(cellNode, code) {
"Tab": onTabKey,
});

editor.on("change", (cm, change) => {
cm.on("change", (cm, change) => {
// TODO: optimise
if (cm.getValue() != cellNode.remoteCode) {
cellNode.classList.add("code-differs")
} else {
cellNode.classList.remove("code-differs")
}
const differs = cm.getValue() != cellNode.remoteCode

cellNode.classList.toggle("code-differs", differs)
updateAnyCodeDiffers()
})

editor.on("cursorActivity", (cm) => {
cm.on("cursorActivity", (cm) => {
const token = cm.getTokenAt(cm.getCursor())

if (token.type != null && token.type != "string") {
updateDocQuery(token.string)
}
});

return editor
return cm
}

function updateAnyCodeDiffers(hint=false) {
document.body.classList.toggle("code-differs", hint || (document.querySelector("notebook>cell.code-differs") != null))
}

function prettytime(time_ns) {
Expand Down Expand Up @@ -285,6 +288,7 @@ function updateLocalCellInput(byMe, cellNode, code, folded) {
cellNode.classList.remove("code-differs")
}

updateAnyCodeDiffers()
foldLocalCell(cellNode, folded)
}

Expand Down Expand Up @@ -422,31 +426,38 @@ function requestChangeRemoteCell(uuid, createPromise = false) {
return client.send("changecell", { code: newCode }, uuid, createPromise)
}

function requestRunAllRemoteCells(setInputs = true) {
if (!window.allCellsCompleted) {
return
}
function requestRunAllChangedRemoteCells() {
refreshAllCompletionPromise()
const promises = []

for (var uuid in window.localCells) {
const cellNode = window.localCells[uuid]
const changed = Array.from(notebookNode.querySelectorAll("cell.code-differs"))
const promises = changed.map(cellNode => {
const uuid = cellNode.id
cellNode.classList.add("running")
if (setInputs) {
promises.push(
client.sendreceive("setinput", {
code: window.codeMirrors[uuid].getValue()
}, uuid).then(u => {
updateLocalCellInput(true, cellNode, u.message.code, u.message.folded)
})
)
}
}
return client.sendreceive("setinput", {
code: window.codeMirrors[uuid].getValue()
}, uuid).then(u => {
updateLocalCellInput(true, cellNode, u.message.code, u.message.folded)
})
})
Promise.all(promises).then(() => {
client.send("runall", {})
client.send("runmultiple", {
cells: changed.map(c => c.id)
})
}).catch(console.error)
}

function requestRunAllRemoteCells() {
refreshAllCompletionPromise()

const uuids = Array.from(window.localCells).map(cellNode => {
cellNode.classList.add("running")
return cellNode.id
})
client.send("runmultiple", {
cells: uuids
})
}

function requestInterruptRemote() {
client.send("interruptall", {})
}
Expand Down Expand Up @@ -560,7 +571,7 @@ function onEstablishConnection() {
if (runAll
&& !document.querySelector("notebook>cell.running")
&& document.querySelector("notebook>cell.output-notinsync")) {
requestRunAllRemoteCells(false)
requestRunAllRemoteCells()
window.allCellsCompletedPromise.then(happy)
} else {
// We do a code completion request to trigger starting the workpsace
Expand Down
4 changes: 2 additions & 2 deletions assets/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ preamble>button {
preamble>button>span::after {
background-size: 17px 17px;
display: block;
content: "Run all" !important;
background-image: url(https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.0.0/src/svg/play-skip-forward-circle-outline.svg);
content: "Submit all changes" !important;
background-image: url(https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.0.0/src/svg/sync-circle-outline.svg);
background-repeat: no-repeat;
background-position-x: right;
background-position-y: 1px;
Expand Down
1 change: 0 additions & 1 deletion sample/ui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ function onmove(e){
}
canvas.onmousedown = e => {
console.log(e)
startX = e.layerX
startY = e.layerY
canvas.onmousemove = onmove
Expand Down
9 changes: 2 additions & 7 deletions src/notebookserver/Notebook.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ end
Notebook(path::String, cells::Array{Cell,1}) = Notebook(path, cells, uuid1())
Notebook(cells::Array{Cell,1}) = Notebook(tempname() * ".jl", cells)

function selectcell_byuuid(notebook::Notebook, uuid::UUID)::Union{Cell,Nothing}
cellIndex = findfirst(c->c.uuid == uuid, notebook.cells)
if cellIndex === nothing
@warn "Requested non-existing cell with UUID $(uuid)\nTry refreshing the page in your browser."
return nothing
end
notebook.cells[cellIndex]
function cellindex_fromuuid(notebook::Notebook, uuid::UUID)::Union{Int,Nothing}
findfirst(c->c.uuid == uuid, notebook.cells)
end

# We use a creative delimiter to avoid accidental use in code
Expand Down
6 changes: 4 additions & 2 deletions src/webserver/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ responses[:run] = (body, notebook::Notebook, cell::Cell; initiator::Union{Initia
run_reactive_async!(notebook, cell)
end

responses[:runall] = (body, notebook::Notebook; initiator::Union{Initiator, Missing}=missing) -> begin
run_reactive_async!(notebook, notebook.cells)
responses[:runmultiple] = (body, notebook::Notebook; initiator::Union{Initiator, Missing}=missing) -> begin
indices = cellindex_fromuuid.([notebook], UUID.(body["cells"]))
cells = [notebook.cells[i] for i in indices if i !== nothing]
run_reactive_async!(notebook, cells)
end

responses[:getinput] = (body, notebook::Notebook, cell::Cell; initiator::Union{Initiator, Missing}=missing) -> begin
Expand Down
10 changes: 4 additions & 6 deletions src/webserver/WebServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,12 @@ function process_ws_message(parentbody::Dict{String, Any}, clientstream::HTTP.We
end

if haskey(parentbody, "cellID")
cell = let
cellID = UUID(parentbody["cellID"])
selectcell_byuuid(notebook, cellID)
end
if cell === nothing
cellID = UUID(parentbody["cellID"])
index = cellindex_fromuuid(notebook, cellID)
if index === nothing
@warn "Remote cell not found locally!"
else
push!(args, cell)
push!(args, notebook.cells[index])
end
end

Expand Down

4 comments on commit 8fef806

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 8fef806 May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops the title should the opposite

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 8fef806 May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#83

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 8fef806 May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/14223

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.1 -m "<description of version>" 8fef806a2d811edeee9054fd616413150d9d7a89
git push origin v0.8.1

Please sign in to comment.