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