From 63bca420670d62d69ff8d90a4d6adb63262adc37 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Thu, 27 Apr 2017 11:17:55 -0700 Subject: [PATCH 01/10] Open all files with `/files` path except for `.html` and .svg` --- notebook/static/tree/js/notebooklist.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 4164362d96..235b6f3a4a 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -543,8 +543,9 @@ define([ }; NotebookList.ipynb_extensions = ['ipynb']; - NotebookList.non_editable_extensions = 'jpeg jpeg png zip gif tif tiff bmp ico pdf doc xls xlsx'.split(' '); - NotebookList.editable_extensions = 'txt py cson json yaml html'.split(' '); + NotebookList.not_safe = ['html', 'svg']; + NotebookList.non_editable_extensions = ['jpeg', 'jpeg', 'png', 'zip', 'gif', 'tif', 'tiff', 'bmp', 'ico', 'pdf', 'doc', 'xls', 'xlsx']; + NotebookList.editable_extensions = ['txt', 'py', 'cson', 'json', 'yaml', 'html']; NotebookList.prototype._is_editable = function(filepath){ return filepath_of_extension(filepath, NotebookList.editable_extensions); @@ -557,6 +558,10 @@ define([ NotebookList.prototype._is_notebook = function(filepath){ return filepath_of_extension(filepath, NotebookList.ipynb_extensions) }; + + NotebookList.prototype._is_not_safe = function(filepath){ + return filepath_of_extension(filepath, NotebookList.not_safe) + }; /** * Handles when any row selector checkbox is toggled. @@ -731,6 +736,11 @@ define([ var uri_prefix = NotebookList.uri_prefixes[model.type]; if (model.type === 'file' && !this._is_editable(path)) + { + uri_prefix = 'files'; + } + if (model.type === 'file' + && this._is_not_safe(path)) { uri_prefix = 'view'; } From 6871dc81dbc6a526c611688d65d1e59e608c51ae Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Sat, 6 May 2017 10:19:49 -0700 Subject: [PATCH 02/10] Use `is_viewable` vs. `is_not_safe` --- notebook/static/tree/js/notebooklist.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 235b6f3a4a..f83de3ff1e 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -543,9 +543,9 @@ define([ }; NotebookList.ipynb_extensions = ['ipynb']; - NotebookList.not_safe = ['html', 'svg']; NotebookList.non_editable_extensions = ['jpeg', 'jpeg', 'png', 'zip', 'gif', 'tif', 'tiff', 'bmp', 'ico', 'pdf', 'doc', 'xls', 'xlsx']; NotebookList.editable_extensions = ['txt', 'py', 'cson', 'json', 'yaml', 'html']; + NotebookList.viewable_extensions = ['htm', 'html']; NotebookList.prototype._is_editable = function(filepath){ return filepath_of_extension(filepath, NotebookList.editable_extensions); @@ -559,8 +559,8 @@ define([ return filepath_of_extension(filepath, NotebookList.ipynb_extensions) }; - NotebookList.prototype._is_not_safe = function(filepath){ - return filepath_of_extension(filepath, NotebookList.not_safe) + NotebookList.prototype._is_viewable = function(filepath){ + return filepath_of_extension(filepath, NotebookList.viewable_extensions) }; /** @@ -740,7 +740,7 @@ define([ uri_prefix = 'files'; } if (model.type === 'file' - && this._is_not_safe(path)) + && this._is_viewable(path)) { uri_prefix = 'view'; } From c43d258aa2d73807c77dce7538b6232285853ea2 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Sat, 6 May 2017 10:19:59 -0700 Subject: [PATCH 03/10] Update list of editable extensions --- notebook/static/tree/js/notebooklist.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index f83de3ff1e..705c273e13 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -544,7 +544,8 @@ define([ NotebookList.ipynb_extensions = ['ipynb']; NotebookList.non_editable_extensions = ['jpeg', 'jpeg', 'png', 'zip', 'gif', 'tif', 'tiff', 'bmp', 'ico', 'pdf', 'doc', 'xls', 'xlsx']; - NotebookList.editable_extensions = ['txt', 'py', 'cson', 'json', 'yaml', 'html']; + // List of text file extensions from https://github.com/sindresorhus/text-extensions/blob/master/text-extensions.json + NotebookList.editable_extensions = ['applescript', 'asp', 'aspx', 'atom', 'bashrc', 'bat', 'bbcolors', 'bib', 'bowerrc', 'c', 'cc', 'cfc', 'cfg', 'cfm', 'cmd', 'cnf', 'coffee', 'conf', 'cpp', 'cson', 'css', 'csslintrc', 'csv', 'curlrc', 'cxx', 'diff', 'eco', 'editorconfig', 'ejs', 'emacs', 'eml', 'erb', 'erl', 'eslintignore', 'eslintrc', 'gemrc', 'gitattributes', 'gitconfig', 'gitignore', 'go', 'gvimrc', 'h', 'haml', 'hbs', 'hgignore', 'hpp', 'htaccess', 'htm', 'html', 'iced', 'ini', 'ino', 'irbrc', 'itermcolors', 'jade', 'js', 'jscsrc', 'jshintignore', 'jshintrc', 'json', 'jsonld', 'jsx', 'less', 'log', 'ls', 'm', 'markdown', 'md', 'mdown', 'mdwn', 'mht', 'mhtml', 'mkd', 'mkdn', 'mkdown', 'nfo', 'npmignore', 'npmrc', 'nvmrc', 'patch', 'pbxproj', 'pch', 'php', 'phtml', 'pl', 'pm', 'properties', 'py', 'rb', 'rdoc', 'rdoc_options', 'ron', 'rss', 'rst', 'rtf', 'rvmrc', 'sass', 'scala', 'scss', 'seestyle', 'sh', 'sls', 'sql', 'sss', 'strings', 'styl', 'stylus', 'sub', 'sublime-build', 'sublime-commands', 'sublime-completions', 'sublime-keymap', 'sublime-macro', 'sublime-menu', 'sublime-project', 'sublime-settings', 'sublime-workspace', 'svg', 'terminal', 'tex', 'text', 'textile', 'tmLanguage', 'tmTheme', 'tsv', 'txt', 'vbs', 'vim', 'viminfo', 'vimrc', 'webapp', 'xht', 'xhtml', 'xml', 'xsl', 'yaml', 'yml', 'zsh', 'zshrc']; NotebookList.viewable_extensions = ['htm', 'html']; NotebookList.prototype._is_editable = function(filepath){ From f43ac2f928b8f7ad81294ed4c19f0a69c9469575 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Tue, 30 May 2017 10:44:38 -0700 Subject: [PATCH 04/10] Fix double url-encoding issue on view file --- notebook/static/tree/js/notebooklist.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 705c273e13..604dc6da17 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -1037,7 +1037,7 @@ define([ var item_path = utils.encode_uri_components(item.path); // Handle HTML files differently var item_type = item_path.endsWith('.html') ? 'view' : 'files'; - window.open(utils.url_path_join(that.base_url, item_type, utils.encode_uri_components(item_path)), IPython._target); + window.open(utils.url_path_join(that.base_url, item_type, item_path), IPython._target); }); }; @@ -1047,7 +1047,7 @@ define([ var item_path = utils.encode_uri_components(item.path); // Handle ipynb files differently var item_type = item_path.endsWith('.ipynb') ? 'notebooks' : 'edit'; - window.open(utils.url_path_join(that.base_url, item_type, utils.encode_uri_components(item_path)), IPython._target); + window.open(utils.url_path_join(that.base_url, item_type, item_path), IPython._target); }); }; From 7cb2bae6a075e3aa0e942e83eb452715aa5d00f4 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Tue, 30 May 2017 11:03:10 -0700 Subject: [PATCH 05/10] Always display "View" button and display "Edit" button for all editable files --- notebook/static/tree/js/notebooklist.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 604dc6da17..6310b7c6d3 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -543,19 +543,16 @@ define([ }; NotebookList.ipynb_extensions = ['ipynb']; - NotebookList.non_editable_extensions = ['jpeg', 'jpeg', 'png', 'zip', 'gif', 'tif', 'tiff', 'bmp', 'ico', 'pdf', 'doc', 'xls', 'xlsx']; - // List of text file extensions from https://github.com/sindresorhus/text-extensions/blob/master/text-extensions.json - NotebookList.editable_extensions = ['applescript', 'asp', 'aspx', 'atom', 'bashrc', 'bat', 'bbcolors', 'bib', 'bowerrc', 'c', 'cc', 'cfc', 'cfg', 'cfm', 'cmd', 'cnf', 'coffee', 'conf', 'cpp', 'cson', 'css', 'csslintrc', 'csv', 'curlrc', 'cxx', 'diff', 'eco', 'editorconfig', 'ejs', 'emacs', 'eml', 'erb', 'erl', 'eslintignore', 'eslintrc', 'gemrc', 'gitattributes', 'gitconfig', 'gitignore', 'go', 'gvimrc', 'h', 'haml', 'hbs', 'hgignore', 'hpp', 'htaccess', 'htm', 'html', 'iced', 'ini', 'ino', 'irbrc', 'itermcolors', 'jade', 'js', 'jscsrc', 'jshintignore', 'jshintrc', 'json', 'jsonld', 'jsx', 'less', 'log', 'ls', 'm', 'markdown', 'md', 'mdown', 'mdwn', 'mht', 'mhtml', 'mkd', 'mkdn', 'mkdown', 'nfo', 'npmignore', 'npmrc', 'nvmrc', 'patch', 'pbxproj', 'pch', 'php', 'phtml', 'pl', 'pm', 'properties', 'py', 'rb', 'rdoc', 'rdoc_options', 'ron', 'rss', 'rst', 'rtf', 'rvmrc', 'sass', 'scala', 'scss', 'seestyle', 'sh', 'sls', 'sql', 'sss', 'strings', 'styl', 'stylus', 'sub', 'sublime-build', 'sublime-commands', 'sublime-completions', 'sublime-keymap', 'sublime-macro', 'sublime-menu', 'sublime-project', 'sublime-settings', 'sublime-workspace', 'svg', 'terminal', 'tex', 'text', 'textile', 'tmLanguage', 'tmTheme', 'tsv', 'txt', 'vbs', 'vim', 'viminfo', 'vimrc', 'webapp', 'xht', 'xhtml', 'xml', 'xsl', 'yaml', 'yml', 'zsh', 'zshrc']; + // List of text file extensions from + // https://github.com/sindresorhus/text-extensions/blob/master/text-extensions.json + var editable_extensions = ['applescript', 'asp', 'aspx', 'atom', 'bashrc', 'bat', 'bbcolors', 'bib', 'bowerrc', 'c', 'cc', 'cfc', 'cfg', 'cfm', 'cmd', 'cnf', 'coffee', 'conf', 'cpp', 'cson', 'css', 'csslintrc', 'csv', 'curlrc', 'cxx', 'diff', 'eco', 'editorconfig', 'ejs', 'emacs', 'eml', 'erb', 'erl', 'eslintignore', 'eslintrc', 'gemrc', 'gitattributes', 'gitconfig', 'gitignore', 'go', 'gvimrc', 'h', 'haml', 'hbs', 'hgignore', 'hpp', 'htaccess', 'htm', 'html', 'iced', 'ini', 'ino', 'irbrc', 'itermcolors', 'jade', 'js', 'jscsrc', 'jshintignore', 'jshintrc', 'json', 'jsonld', 'jsx', 'less', 'log', 'ls', 'm', 'markdown', 'md', 'mdown', 'mdwn', 'mht', 'mhtml', 'mkd', 'mkdn', 'mkdown', 'nfo', 'npmignore', 'npmrc', 'nvmrc', 'patch', 'pbxproj', 'pch', 'php', 'phtml', 'pl', 'pm', 'properties', 'py', 'rb', 'rdoc', 'rdoc_options', 'ron', 'rss', 'rst', 'rtf', 'rvmrc', 'sass', 'scala', 'scss', 'seestyle', 'sh', 'sls', 'sql', 'sss', 'strings', 'styl', 'stylus', 'sub', 'sublime-build', 'sublime-commands', 'sublime-completions', 'sublime-keymap', 'sublime-macro', 'sublime-menu', 'sublime-project', 'sublime-settings', 'sublime-workspace', 'svg', 'terminal', 'tex', 'text', 'textile', 'tmLanguage', 'tmTheme', 'tsv', 'txt', 'vbs', 'vim', 'viminfo', 'vimrc', 'webapp', 'xht', 'xhtml', 'xml', 'xsl', 'yaml', 'yml', 'zsh', 'zshrc']; + NotebookList.editable_extensions = editable_extensions.concat(['geojson', 'plotly', 'plotly.json', 'vg', 'vg.json', 'vl', 'vl.json']); NotebookList.viewable_extensions = ['htm', 'html']; NotebookList.prototype._is_editable = function(filepath){ return filepath_of_extension(filepath, NotebookList.editable_extensions); }; - NotebookList.prototype._is_not_editable = function(filepath){ - return filepath_of_extension(filepath, NotebookList.non_editable_extensions); - }; - NotebookList.prototype._is_notebook = function(filepath){ return filepath_of_extension(filepath, NotebookList.ipynb_extensions) }; @@ -657,7 +654,7 @@ define([ // already so no need to show the button. // That should include things like, html, py, txt, json.... if (selected.length == 1 && !has_directory && selected.every(function(el) { - return that._is_editable(el.path) && ! that._is_notebook(el.path); + return !that._is_notebook(el.path); })) { $('.view-button').css('display', 'inline-block'); } else { @@ -672,9 +669,7 @@ define([ // And non editable files should not show edit button. // for unknown we'll assume users know what they are doing. if (selected.length == 1 && !has_directory && selected.find(function(el) { - return !that._is_editable(el.path) - && !that._is_not_editable(el.path) - && !that._is_notebook(el.path); + return that._is_editable(el.path); })) { $('.edit-button').css('display', 'inline-block'); } else { From b51e5d59e71e965494865e1ec1d406b0dc97c3b2 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Tue, 30 May 2017 11:03:52 -0700 Subject: [PATCH 06/10] Support "View" and "Edit" for a selection of multiple files --- notebook/static/tree/js/notebooklist.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 6310b7c6d3..bfa7126c37 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -653,7 +653,7 @@ define([ // If it's not editable or unknown, the default action should be view // already so no need to show the button. // That should include things like, html, py, txt, json.... - if (selected.length == 1 && !has_directory && selected.every(function(el) { + if (selected.length >= 1 && !has_directory && selected.every(function(el) { return !that._is_notebook(el.path); })) { $('.view-button').css('display', 'inline-block'); @@ -668,7 +668,7 @@ define([ // Indeed if it's editable the default action is already to edit. // And non editable files should not show edit button. // for unknown we'll assume users know what they are doing. - if (selected.length == 1 && !has_directory && selected.find(function(el) { + if (selected.length >= 1 && !has_directory && selected.every(function(el) { return that._is_editable(el.path); })) { $('.edit-button').css('display', 'inline-block'); From abba5805360e4779fe7e0a2fc4df9e1b2e8ee986 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Tue, 30 May 2017 11:54:46 -0700 Subject: [PATCH 07/10] Add more HTML-like variants --- notebook/static/tree/js/notebooklist.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index bfa7126c37..e626a86f3c 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -547,7 +547,7 @@ define([ // https://github.com/sindresorhus/text-extensions/blob/master/text-extensions.json var editable_extensions = ['applescript', 'asp', 'aspx', 'atom', 'bashrc', 'bat', 'bbcolors', 'bib', 'bowerrc', 'c', 'cc', 'cfc', 'cfg', 'cfm', 'cmd', 'cnf', 'coffee', 'conf', 'cpp', 'cson', 'css', 'csslintrc', 'csv', 'curlrc', 'cxx', 'diff', 'eco', 'editorconfig', 'ejs', 'emacs', 'eml', 'erb', 'erl', 'eslintignore', 'eslintrc', 'gemrc', 'gitattributes', 'gitconfig', 'gitignore', 'go', 'gvimrc', 'h', 'haml', 'hbs', 'hgignore', 'hpp', 'htaccess', 'htm', 'html', 'iced', 'ini', 'ino', 'irbrc', 'itermcolors', 'jade', 'js', 'jscsrc', 'jshintignore', 'jshintrc', 'json', 'jsonld', 'jsx', 'less', 'log', 'ls', 'm', 'markdown', 'md', 'mdown', 'mdwn', 'mht', 'mhtml', 'mkd', 'mkdn', 'mkdown', 'nfo', 'npmignore', 'npmrc', 'nvmrc', 'patch', 'pbxproj', 'pch', 'php', 'phtml', 'pl', 'pm', 'properties', 'py', 'rb', 'rdoc', 'rdoc_options', 'ron', 'rss', 'rst', 'rtf', 'rvmrc', 'sass', 'scala', 'scss', 'seestyle', 'sh', 'sls', 'sql', 'sss', 'strings', 'styl', 'stylus', 'sub', 'sublime-build', 'sublime-commands', 'sublime-completions', 'sublime-keymap', 'sublime-macro', 'sublime-menu', 'sublime-project', 'sublime-settings', 'sublime-workspace', 'svg', 'terminal', 'tex', 'text', 'textile', 'tmLanguage', 'tmTheme', 'tsv', 'txt', 'vbs', 'vim', 'viminfo', 'vimrc', 'webapp', 'xht', 'xhtml', 'xml', 'xsl', 'yaml', 'yml', 'zsh', 'zshrc']; NotebookList.editable_extensions = editable_extensions.concat(['geojson', 'plotly', 'plotly.json', 'vg', 'vg.json', 'vl', 'vl.json']); - NotebookList.viewable_extensions = ['htm', 'html']; + NotebookList.viewable_extensions = ['htm', 'html', 'xhtml', 'mht', 'mhtml']; NotebookList.prototype._is_editable = function(filepath){ return filepath_of_extension(filepath, NotebookList.editable_extensions); From 5c0495d14e2ac6d289b79b09fb47ae3e19e1ed74 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Wed, 31 May 2017 14:22:41 -0700 Subject: [PATCH 08/10] Inspect mimetype in addition to file extension to determine if a file is editable/viewable --- notebook/static/tree/js/notebooklist.js | 65 +++++++++++++------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index e626a86f3c..80ddabf74a 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -22,14 +22,16 @@ define([ return parts[parts.length-1]; }; - var extension_in = function(extension, extensionslist){ - var res = extensionslist.indexOf(extension) != -1; - return res; - + var item_in = function(item, list) { + return list.indexOf(item) != -1; }; - var filepath_of_extension = function(filepath, extensionslist){ - return extension_in(extension(filepath), extensionslist); + var includes_extension = function(filepath, extensionslist) { + return item_in(extension(filepath), extensionslist); + }; + + var includes_mimetype = function(str, mimetype) { + return item_in(str, mimetype || ''); }; var NotebookList = function (selector, options) { @@ -549,16 +551,18 @@ define([ NotebookList.editable_extensions = editable_extensions.concat(['geojson', 'plotly', 'plotly.json', 'vg', 'vg.json', 'vl', 'vl.json']); NotebookList.viewable_extensions = ['htm', 'html', 'xhtml', 'mht', 'mhtml']; - NotebookList.prototype._is_editable = function(filepath){ - return filepath_of_extension(filepath, NotebookList.editable_extensions); + NotebookList.prototype._is_notebook = function(model) { + return includes_extension(model.path, NotebookList.ipynb_extensions); }; - - NotebookList.prototype._is_notebook = function(filepath){ - return filepath_of_extension(filepath, NotebookList.ipynb_extensions) + + NotebookList.prototype._is_editable = function(model) { + return (includes_mimetype('text/', model.mimetype) || includes_mimetype('application/', model.mimetype)) + || includes_extension(model.path, NotebookList.editable_extensions); }; - NotebookList.prototype._is_viewable = function(filepath){ - return filepath_of_extension(filepath, NotebookList.viewable_extensions) + NotebookList.prototype._is_viewable = function(model) { + return model.mimetype === 'text/html' + || includes_extension(model.path, NotebookList.viewable_extensions); }; /** @@ -669,7 +673,7 @@ define([ // And non editable files should not show edit button. // for unknown we'll assume users know what they are doing. if (selected.length >= 1 && !has_directory && selected.every(function(el) { - return that._is_editable(el.path); + return that._is_editable(el); })) { $('.edit-button').css('display', 'inline-block'); } else { @@ -715,31 +719,30 @@ define([ }; NotebookList.prototype.add_link = function (model, item) { - var path = model.path, - name = model.name, - modified = model.last_modified; - var running = (model.type === 'notebook' && this.sessions[path] !== undefined); + var running = (model.type === 'notebook' && this.sessions[model.path] !== undefined); - item.data('name', name); - item.data('path', path); - item.data('modified', modified); + item.data('name', model.name); + item.data('path', model.path); + item.data('modified', model.modified); item.data('type', model.type); - item.find(".item_name").text(name); + item.find(".item_name").text(model.name); var icon = NotebookList.icons[model.type]; if (running) { icon = 'running_' + icon; } var uri_prefix = NotebookList.uri_prefixes[model.type]; - if (model.type === 'file' - && !this._is_editable(path)) + if (model.type === 'file' && !this._is_editable(model)) { uri_prefix = 'files'; } - if (model.type === 'file' - && this._is_viewable(path)) + if (model.type === 'file' && this._is_viewable(model)) { uri_prefix = 'view'; } + if (model.type === 'file' && this._is_notebook(model)) + { + uri_prefix = 'notebooks'; + } item.find(".item_icon").addClass(icon).addClass('icon-fixed-width'); var link = item.find("a.item_link") @@ -747,7 +750,7 @@ define([ utils.url_path_join( this.base_url, uri_prefix, - utils.encode_uri_components(path) + utils.encode_uri_components(model.path) ) ); @@ -760,8 +763,8 @@ define([ } // Add in the date that the file was last modified - item.find(".item_modified").text(utils.format_datetime(modified)); - item.find(".item_modified").attr("title", moment(modified).format("YYYY-MM-DD HH:mm")); + item.find(".item_modified").text(utils.format_datetime(model.modified)); + item.find(".item_modified").attr("title", moment(model.modified).format("YYYY-MM-DD HH:mm")); }; @@ -1040,9 +1043,7 @@ define([ var that = this; that.selected.forEach(function(item) { var item_path = utils.encode_uri_components(item.path); - // Handle ipynb files differently - var item_type = item_path.endsWith('.ipynb') ? 'notebooks' : 'edit'; - window.open(utils.url_path_join(that.base_url, item_type, item_path), IPython._target); + window.open(utils.url_path_join(that.base_url, 'edit', item_path), IPython._target); }); }; From 226492d1b1b69cbd8383858459c874d8c6ea751d Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Wed, 31 May 2017 14:23:23 -0700 Subject: [PATCH 09/10] All files are viewable by default, handle notebooks and html differently --- notebook/static/tree/js/notebooklist.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 80ddabf74a..aea85dbebe 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -548,7 +548,7 @@ define([ // List of text file extensions from // https://github.com/sindresorhus/text-extensions/blob/master/text-extensions.json var editable_extensions = ['applescript', 'asp', 'aspx', 'atom', 'bashrc', 'bat', 'bbcolors', 'bib', 'bowerrc', 'c', 'cc', 'cfc', 'cfg', 'cfm', 'cmd', 'cnf', 'coffee', 'conf', 'cpp', 'cson', 'css', 'csslintrc', 'csv', 'curlrc', 'cxx', 'diff', 'eco', 'editorconfig', 'ejs', 'emacs', 'eml', 'erb', 'erl', 'eslintignore', 'eslintrc', 'gemrc', 'gitattributes', 'gitconfig', 'gitignore', 'go', 'gvimrc', 'h', 'haml', 'hbs', 'hgignore', 'hpp', 'htaccess', 'htm', 'html', 'iced', 'ini', 'ino', 'irbrc', 'itermcolors', 'jade', 'js', 'jscsrc', 'jshintignore', 'jshintrc', 'json', 'jsonld', 'jsx', 'less', 'log', 'ls', 'm', 'markdown', 'md', 'mdown', 'mdwn', 'mht', 'mhtml', 'mkd', 'mkdn', 'mkdown', 'nfo', 'npmignore', 'npmrc', 'nvmrc', 'patch', 'pbxproj', 'pch', 'php', 'phtml', 'pl', 'pm', 'properties', 'py', 'rb', 'rdoc', 'rdoc_options', 'ron', 'rss', 'rst', 'rtf', 'rvmrc', 'sass', 'scala', 'scss', 'seestyle', 'sh', 'sls', 'sql', 'sss', 'strings', 'styl', 'stylus', 'sub', 'sublime-build', 'sublime-commands', 'sublime-completions', 'sublime-keymap', 'sublime-macro', 'sublime-menu', 'sublime-project', 'sublime-settings', 'sublime-workspace', 'svg', 'terminal', 'tex', 'text', 'textile', 'tmLanguage', 'tmTheme', 'tsv', 'txt', 'vbs', 'vim', 'viminfo', 'vimrc', 'webapp', 'xht', 'xhtml', 'xml', 'xsl', 'yaml', 'yml', 'zsh', 'zshrc']; - NotebookList.editable_extensions = editable_extensions.concat(['geojson', 'plotly', 'plotly.json', 'vg', 'vg.json', 'vl', 'vl.json']); + NotebookList.editable_extensions = editable_extensions.concat(['ipynb', 'geojson', 'plotly', 'plotly.json', 'vg', 'vg.json', 'vl', 'vl.json']); NotebookList.viewable_extensions = ['htm', 'html', 'xhtml', 'mht', 'mhtml']; NotebookList.prototype._is_notebook = function(model) { @@ -657,9 +657,7 @@ define([ // If it's not editable or unknown, the default action should be view // already so no need to show the button. // That should include things like, html, py, txt, json.... - if (selected.length >= 1 && !has_directory && selected.every(function(el) { - return !that._is_notebook(el.path); - })) { + if (selected.length >= 1 && !has_directory) { $('.view-button').css('display', 'inline-block'); } else { $('.view-button').css('display', 'none'); @@ -1033,8 +1031,7 @@ define([ var that = this; that.selected.forEach(function(item) { var item_path = utils.encode_uri_components(item.path); - // Handle HTML files differently - var item_type = item_path.endsWith('.html') ? 'view' : 'files'; + var item_type = that._is_notebook(item) ? 'notebooks' : that._is_viewable(item) ? 'view' : 'files'; window.open(utils.url_path_join(that.base_url, item_type, item_path), IPython._target); }); }; From 6a1f807b89eb693af25961073e9f99087ac27276 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Tue, 20 Jun 2017 09:46:35 -0700 Subject: [PATCH 10/10] Open all editable files with `/edit` path --- notebook/static/tree/js/notebooklist.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index aea85dbebe..9c12ca421c 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -737,6 +737,10 @@ define([ { uri_prefix = 'view'; } + if (model.type === 'file' && this._is_editable(model)) + { + uri_prefix = 'edit'; + } if (model.type === 'file' && this._is_notebook(model)) { uri_prefix = 'notebooks';