Skip to content

Commit 0112703

Browse files
authored
Merge pull request #2911 from gnestor/issue-2203
Improve Edit/View behavior
2 parents 12592ef + 2fdc532 commit 0112703

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

notebook/static/tree/js/notebooklist.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ define([
2525
};
2626

2727
var item_in = function(item, list) {
28-
return list.indexOf(item) != -1;
28+
// Normalize list and item to lowercase
29+
var normalized_list = list.map(function(_item) {
30+
return _item.toLowerCase();
31+
});
32+
return normalized_list.indexOf(item.toLowerCase()) != -1;
2933
};
3034

3135
var includes_extension = function(filepath, extensionslist) {
@@ -536,30 +540,30 @@ define([
536540
this._selection_changed();
537541
};
538542

539-
NotebookList.ipynb_extensions = ['ipynb'];
540-
// List of text file extensions from
541-
// https://github.com/sindresorhus/text-extensions/blob/master/text-extensions.json
542-
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'];
543-
NotebookList.editable_extensions = editable_extensions.concat(['ipynb', 'geojson', 'plotly', 'plotly.json', 'vg', 'vg.json', 'vl', 'vl.json']);
544-
NotebookList.viewable_extensions = ['htm', 'html', 'xhtml', 'mht', 'mhtml'];
545-
546543
NotebookList.prototype._is_notebook = function(model) {
547-
return includes_extension(model.path, NotebookList.ipynb_extensions);
544+
var ipynb_extensions = ['ipynb'];
545+
return includes_extension(model.path, ipynb_extensions);
548546
};
549547

550548
NotebookList.prototype._is_editable = function(model) {
551-
// Editable: any text/ mimetype, specific mimetypes defined as editable,
552-
// +json and +xml mimetypes, specific extensions listed as editable.
553-
return model.mimetype &&
554-
(model.mimetype.indexOf('text/') === 0
555-
|| item_in(model.mimetype, this.EDIT_MIMETYPES)
556-
|| json_or_xml_container_mimetype(model.mimetype))
557-
|| includes_extension(model.path, NotebookList.editable_extensions);
549+
// Allow any file to be "edited"
550+
// Non-text files will display the following error:
551+
// Error: [FILE] is not UTF-8 encoded
552+
// Saving is disabled.
553+
// See Console for more details.
554+
return true;
558555
};
559556

560557
NotebookList.prototype._is_viewable = function(model) {
558+
var html_types = ['htm', 'html', 'xhtml', 'xml', 'mht', 'mhtml'];
559+
var media_extension = ['3gp', 'avi', 'mov', 'mp4', 'm4v', 'm4a', 'mp3', 'mkv', 'ogv', 'ogm', 'ogg', 'oga', 'webm', 'wav'];
560+
var image_type = ['bmp', 'gif', 'jpg', 'jpeg', 'png', 'webp'];
561+
var archive_type = ['zip', 'rar'];
562+
var other_type = ['txt', 'pdf', 'ico'];
563+
var office_types = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'];
564+
var viewable_extensions = [].concat(html_types, media_extension, image_type, archive_type, other_type, office_types);
561565
return model.mimetype === 'text/html'
562-
|| includes_extension(model.path, NotebookList.viewable_extensions);
566+
|| includes_extension(model.path, viewable_extensions);
563567
};
564568

565569
/**
@@ -726,18 +730,10 @@ define([
726730
icon = 'running_' + icon;
727731
}
728732
var uri_prefix = NotebookList.uri_prefixes[model.type];
729-
if (model.type === 'file' && !this._is_editable(model))
730-
{
731-
uri_prefix = 'files';
732-
}
733733
if (model.type === 'file' && this._is_viewable(model))
734734
{
735735
uri_prefix = 'view';
736736
}
737-
if (model.type === 'file' && this._is_editable(model))
738-
{
739-
uri_prefix = 'edit';
740-
}
741737
if (model.type === 'file' && this._is_notebook(model))
742738
{
743739
uri_prefix = 'notebooks';

0 commit comments

Comments
 (0)