Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Restore function!
Browse files Browse the repository at this point in the history
  • Loading branch information
fferegrino committed Jul 22, 2018
1 parent 242ac27 commit 90edefc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
15 changes: 15 additions & 0 deletions jupygit/GitHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@

from notebook.base.handlers import IPythonHandler

class GitRestoreHandler(IPythonHandler):

file_suffix = "-jupygit___.ipynb"

def post(self):
data = parse_qs(self.request.body.decode('utf8'))
dirty_path = data["path"][0]

clean_path = dirty_path[:-len(self.file_suffix)] + ".ipynb"
os.remove(clean_path)

self.write({'status':200,'content':'Hola'})
self.flush()


class GitCleanHandler(IPythonHandler):

file_suffix = "-jupygit___.ipynb"
Expand Down
6 changes: 4 additions & 2 deletions jupygit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from notebook.utils import url_path_join

from .GitHandlers import GitCleanHandler
from .GitHandlers import GitCleanHandler, GitRestoreHandler

def load_jupyter_server_extension(nb_server_app):
web_app = nb_server_app.web_app
host_pattern = '.*$'
web_app.add_handlers(host_pattern, [
(url_path_join(web_app.settings['base_url'], r'/git/clean'),
GitCleanHandler)
GitCleanHandler),
(url_path_join(web_app.settings['base_url'], r'/git/restore'),
GitRestoreHandler)
])

def _jupyter_nbextension_paths():
Expand Down
29 changes: 25 additions & 4 deletions jupygit/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ define([
Jupyter.original_name = "";

function make_request() {
var clean_url = utils.url_path_join(utils.get_body_data('baseUrl'), 'git/clean')
var restore_url = utils.url_path_join(utils.get_body_data('baseUrl'), 'git/restore')
var cookies = getCookies(document.cookie);
var _xsrf = cookies["_xsrf"];
var notebook_path = Jupyter.notebook.notebook_path;

if(Jupyter.original_name === "") {
var clean_url = utils.url_path_join(utils.get_body_data('baseUrl'), 'git/clean')
var cookies = getCookies(document.cookie);
var _xsrf = cookies["_xsrf"];
var notebook_path = Jupyter.notebook.notebook_path;
Jupyter.original_name = Jupyter.notebook.notebook_name;
var new_name = Jupyter.original_name.substring(0, Jupyter.original_name.length - 6) + file_suffix

Expand All @@ -37,6 +39,25 @@ define([
}
});
});
} else {
data = {
'name': Jupyter.original_name,
'path': notebook_path
}
$.ajax({
type: "POST",
headers: {
"X-XSRFToken": cookies["_xsrf"]
},
url: restore_url,
data: data,
success: function(d) {
Jupyter.notebook.rename(Jupyter.original_name).then(function (){
Jupyter.original_name = "";
alert("You can now keep working");
});
}
});
}
}

Expand Down
4 changes: 4 additions & 0 deletions make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pip install -e .
jupyter serverextension enable --py jupygit --sys-prefix
jupyter nbextension install --py jupygit --sys-prefix
jupyter nbextension enable --py jupygit --sys-prefix

0 comments on commit 90edefc

Please sign in to comment.