##// END OF EJS Templates
fixing path redirects, cleaning path logic
Zachary Sailer -
Show More
@@ -100,7 +100,7 b' class NotebookHandler(IPythonHandler):'
100 notebook_name = nbm.save_new_notebook(body, notebook_path=notebook_path, name=name, format=format)
100 notebook_name = nbm.save_new_notebook(body, notebook_path=notebook_path, name=name, format=format)
101 else:
101 else:
102 notebook_name = nbm.new_notebook(notebook_path=notebook_path)
102 notebook_name = nbm.new_notebook(notebook_path=notebook_path)
103 if path==None:
103 if notebook_path==None:
104 self.set_header('Location', nbm.notebook_dir + '/'+ notebook_name)
104 self.set_header('Location', nbm.notebook_dir + '/'+ notebook_name)
105 else:
105 else:
106 self.set_header('Location', nbm.notebook_dir + '/'+ notebook_path + '/' + notebook_name)
106 self.set_header('Location', nbm.notebook_dir + '/'+ notebook_path + '/' + notebook_name)
@@ -50,8 +50,16 b' var IPython = (function (IPython) {'
50 return this._baseProjectUrl || $('body').data('baseProjectUrl');
50 return this._baseProjectUrl || $('body').data('baseProjectUrl');
51 };
51 };
52
52
53 MenuBar.prototype.notebookPath = function(){
53 MenuBar.prototype.notebookPath = function() {
54 return this._notebookPath || $('body').data('notebookPath');
54 var path = $('body').data('notebookPath');
55 if (path != 'None') {
56 if (path[path.length-1] != '/') {
57 path = path.substring(0,path.length);
58 };
59 return path;
60 } else {
61 return '';
62 }
55 };
63 };
56
64
57 MenuBar.prototype.style = function () {
65 MenuBar.prototype.style = function () {
@@ -69,60 +77,30 b' var IPython = (function (IPython) {'
69 MenuBar.prototype.bind_events = function () {
77 MenuBar.prototype.bind_events = function () {
70 // File
78 // File
71 var that = this;
79 var that = this;
72 if (this.notebookPath() != 'None') {
80 this.element.find('#new_notebook').click(function () {
73 this.element.find('#new_notebook').click(function () {
81 window.open(that.baseProjectUrl() + 'notebooks/' + that.notebookPath() +'new');
74 window.open(that.baseProjectUrl() + 'notebooks/' + that.notebookPath() +'/new');
82 });
75 });
83 this.element.find('#open_notebook').click(function () {
76 this.element.find('#open_notebook').click(function () {
84 window.open(that.baseProjectUrl() + 'tree/' + that.notebookPath());
77 window.open(that.baseProjectUrl() + 'tree/' + that.notebookPath());
85 });
78 });
86 this.element.find('#copy_notebook').click(function () {
79 this.element.find('#copy_notebook').click(function () {
87 var notebook_name = IPython.notebook.get_notebook_name();
80 var notebook_name = IPython.notebook.get_notebook_name();
88 var url = that.baseProjectUrl() + 'notebooks/' + that.notebookPath() + notebook_name + '/copy';
81 var url = that.baseProjectUrl() + 'notebooks/' + that.notebookPath() + '/'+ notebook_name + '/copy';
89 window.open(url,'_blank');
82 window.open(url,'_blank');
90 return false;
83 return false;
91 });
84 });
92 this.element.find('#download_ipynb').click(function () {
85 this.element.find('#download_ipynb').click(function () {
93 var notebook_name = IPython.notebook.get_notebook_name();
86 var notebook_name = IPython.notebook.get_notebook_name();
94 var url = that.baseProjectUrl() + 'api/notebooks/' +
87 var url = that.baseProjectUrl() + 'api/notebooks/' +
95 notebook_name + '?format=json';
88 notebook_name + '?format=json';
96 window.location.assign(url);
89 window.location.assign(url);
97 });
90 });
98 this.element.find('#download_py').click(function () {
91 this.element.find('#download_py').click(function () {
99 var notebook_name = IPython.notebook.get_notebook_name();
92 var notebook_name = IPython.notebook.get_notebook_name();
100 var url = that.baseProjectUrl() + 'api/notebooks/' +
93 var url = that.baseProjectUrl() + 'api/notebooks/' +
101 notebook_name + '?format=py';
94 notebook_name + '?format=py';
102 window.location.assign(url);
95 window.location.assign(url);
103 });
96 });
97 }
98 else {
99 this.element.find('#new_notebook').click(function () {
100 window.open(that.baseProjectUrl()+'notebooks/new');
101 });
102 this.element.find('#open_notebook').click(function () {
103 window.open(that.baseProjectUrl() + 'tree');
104 });
105 this.element.find('#copy_notebook').click(function () {
106 var notebook_name = IPython.notebook.get_notebook_name();
107 var url = that.baseProjectUrl() + 'notebooks/' + notebook_name + '/copy';
108 window.open(url,'_blank');
109 return false;
110 });
111 this.element.find('#download_ipynb').click(function () {
112 var notebook_name = IPython.notebook.get_notebook_name();
113 var url = that.baseProjectUrl() + 'api/notebooks/' +
114 notebook_name + '?format=json';
115 window.location.assign(url);
116 });
117 this.element.find('#download_py').click(function () {
118 var notebook_name = IPython.notebook.get_notebook_name();
119 var url = that.baseProjectUrl() + 'api/notebooks/' +
120 notebook_name + '?format=py';
121 window.location.assign(url);
122 });
123
124
125 }
126 this.element.find('#rename_notebook').click(function () {
104 this.element.find('#rename_notebook').click(function () {
127 IPython.save_widget.rename_notebook();
105 IPython.save_widget.rename_notebook();
128 });
106 });
@@ -1391,7 +1391,6 b' var IPython = (function (IPython) {'
1391 */
1391 */
1392 Notebook.prototype.start_session = function () {
1392 Notebook.prototype.start_session = function () {
1393 var notebook_info = this.notebookPath() + this.notebook_name;
1393 var notebook_info = this.notebookPath() + this.notebook_name;
1394 console.log(notebook_info)
1395 this.session = new IPython.Session(notebook_info, this);
1394 this.session = new IPython.Session(notebook_info, this);
1396 this.session.start();
1395 this.session.start();
1397 };
1396 };
@@ -1654,12 +1653,7 b' var IPython = (function (IPython) {'
1654 error : $.proxy(this.save_notebook_error, this)
1653 error : $.proxy(this.save_notebook_error, this)
1655 };
1654 };
1656 $([IPython.events]).trigger('notebook_saving.Notebook');
1655 $([IPython.events]).trigger('notebook_saving.Notebook');
1657 if (this.notebook_path != "") {
1656 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebookPath()+ this.notebook_name;
1658 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebook_path+ this.notebook_name;
1659 }
1660 else {
1661 var url = this.baseProjectUrl() + 'api/notebooks/' +this.notebook_name;
1662 }
1663 $.ajax(url, settings);
1657 $.ajax(url, settings);
1664 };
1658 };
1665
1659
@@ -1734,7 +1728,7 b' var IPython = (function (IPython) {'
1734 error : $.proxy(this.load_notebook_error,this),
1728 error : $.proxy(this.load_notebook_error,this),
1735 };
1729 };
1736 $([IPython.events]).trigger('notebook_loading.Notebook');
1730 $([IPython.events]).trigger('notebook_loading.Notebook');
1737 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebook_path + this.notebook_name;
1731 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebookPath() + this.notebook_name;
1738 $.ajax(url, settings);
1732 $.ajax(url, settings);
1739 };
1733 };
1740
1734
@@ -1867,12 +1861,7 b' var IPython = (function (IPython) {'
1867 * @method list_checkpoints
1861 * @method list_checkpoints
1868 */
1862 */
1869 Notebook.prototype.list_checkpoints = function () {
1863 Notebook.prototype.list_checkpoints = function () {
1870 if (this.notebook_path != "") {
1864 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebookPath() + this.notebook_name + '/checkpoints';
1871 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebook_path+ this.notebook_name + '/checkpoints';
1872 }
1873 else {
1874 var url = this.baseProjectUrl() + 'api/notebooks/' +this.notebook_name + '/checkpoints';
1875 }
1876 $.get(url).done(
1865 $.get(url).done(
1877 $.proxy(this.list_checkpoints_success, this)
1866 $.proxy(this.list_checkpoints_success, this)
1878 ).fail(
1867 ).fail(
@@ -1917,12 +1906,7 b' var IPython = (function (IPython) {'
1917 * @method create_checkpoint
1906 * @method create_checkpoint
1918 */
1907 */
1919 Notebook.prototype.create_checkpoint = function () {
1908 Notebook.prototype.create_checkpoint = function () {
1920 if (this.notebook_path != "") {
1909 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebookPath() + this.notebook_name + '/checkpoints';
1921 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebook_path + this.notebook_name + '/checkpoints';
1922 }
1923 else {
1924 var url = this.baseProjectUrl() + 'api/notebooks/' +this.notebook_name + '/checkpoints';
1925 }
1926 $.post(url).done(
1910 $.post(url).done(
1927 $.proxy(this.create_checkpoint_success, this)
1911 $.proxy(this.create_checkpoint_success, this)
1928 ).fail(
1912 ).fail(
@@ -2002,6 +1986,7 b' var IPython = (function (IPython) {'
2002 * @param {String} checkpoint ID
1986 * @param {String} checkpoint ID
2003 */
1987 */
2004 Notebook.prototype.restore_checkpoint = function (checkpoint) {
1988 Notebook.prototype.restore_checkpoint = function (checkpoint) {
1989 <<<<<<< HEAD
2005 $([IPython.events]).trigger('checkpoint_restoring.Notebook', checkpoint);
1990 $([IPython.events]).trigger('checkpoint_restoring.Notebook', checkpoint);
2006 if (this.notebook_path != "") {
1991 if (this.notebook_path != "") {
2007 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebook_path + this.notebook_name + '/checkpoints/' + checkpoint;
1992 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebook_path + this.notebook_name + '/checkpoints/' + checkpoint;
@@ -2009,6 +1994,10 b' var IPython = (function (IPython) {'
2009 else {
1994 else {
2010 var url = this.baseProjectUrl() + 'api/notebooks/' +this.notebook_name + '/checkpoints/' + checkpoint;
1995 var url = this.baseProjectUrl() + 'api/notebooks/' +this.notebook_name + '/checkpoints/' + checkpoint;
2011 }
1996 }
1997 =======
1998 $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
1999 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebookPath() + this.notebook_name + '/checkpoints/' + checkpoint;
2000 >>>>>>> fixing path redirects, cleaning path logic
2012 $.post(url).done(
2001 $.post(url).done(
2013 $.proxy(this.restore_checkpoint_success, this)
2002 $.proxy(this.restore_checkpoint_success, this)
2014 ).fail(
2003 ).fail(
@@ -2048,13 +2037,8 b' var IPython = (function (IPython) {'
2048 * @param {String} checkpoint ID
2037 * @param {String} checkpoint ID
2049 */
2038 */
2050 Notebook.prototype.delete_checkpoint = function (checkpoint) {
2039 Notebook.prototype.delete_checkpoint = function (checkpoint) {
2051 $([IPython.events]).trigger('checkpoint_restoring.Notebook', checkpoint);
2040 $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
2052 if (this.notebook_path != "") {
2041 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebookPath() + this.notebook_name + '/checkpoints/' + checkpoint;
2053 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebook_path + this.notebook_name + '/checkpoints/' + checkpoint;
2054 }
2055 else {
2056 var url = this.baseProjectUrl() + 'api/notebooks/' +this.notebook_name + '/checkpoints/' + checkpoint;
2057 }
2058 $.ajax(url, {
2042 $.ajax(url, {
2059 type: 'DELETE',
2043 type: 'DELETE',
2060 success: $.proxy(this.delete_checkpoint_success, this),
2044 success: $.proxy(this.delete_checkpoint_success, this),
@@ -63,6 +63,13 b' class TreeRedirectHandler(IPythonHandler):'
63 url = self.base_project_url + 'tree'
63 url = self.base_project_url + 'tree'
64 self.redirect(url)
64 self.redirect(url)
65
65
66 class TreePathRedirectHandler(IPythonHandler):
67
68 @authenticate_unless_readonly
69 def get(self, notebook_path):
70 url = self.base_project_url + 'tree/'+ notebook_path
71 self.redirect(url)
72
66 class ProjectRedirectHandler(IPythonHandler):
73 class ProjectRedirectHandler(IPythonHandler):
67
74
68 @authenticate_unless_readonly
75 @authenticate_unless_readonly
@@ -78,6 +85,7 b' class ProjectRedirectHandler(IPythonHandler):'
78 _notebook_path_regex = r"(?P<notebook_path>.+)"
85 _notebook_path_regex = r"(?P<notebook_path>.+)"
79
86
80 default_handlers = [
87 default_handlers = [
88 (r"/tree/%s/" % _notebook_path_regex, TreePathRedirectHandler),
81 (r"/tree/%s" % _notebook_path_regex, ProjectPathDashboardHandler),
89 (r"/tree/%s" % _notebook_path_regex, ProjectPathDashboardHandler),
82 (r"/tree", ProjectDashboardHandler),
90 (r"/tree", ProjectDashboardHandler),
83 (r"/tree/", TreeRedirectHandler),
91 (r"/tree/", TreeRedirectHandler),
General Comments 0
You need to be logged in to leave comments. Login now