##// END OF EJS Templates
Reverse hscrollbar min-height hack on OS X...
Reverse hscrollbar min-height hack on OS X OS X has optional behavior to only draw scrollbars during scroll, which causes problems for CodeMirror's scrollbars. CodeMirror's solution is to set a minimum size for their scrollbars, which is always present. The trade is that the container overlays most of the last line, swallowing click events when there is scrolling to do, even when no scrollbar is visible. This reverses the trade, recovering the click events at the expense of never showing the horizontal scrollbar on OS X when this option is enabled.

File last commit:

r20259:a41eba58 merge
r20298:2907e856
Show More
notebooklist.js
771 lines | 27.9 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Started work to make tree requirejs friendly.
r17189 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
Jonathan Frederic
MWE,...
r17200 'jquery',
Jonathan Frederic
Started work to make tree requirejs friendly.
r17189 'base/js/utils',
'base/js/dialog',
Scott Sanderson
DEV: Add various events.
r19031 'base/js/events',
Jonathan Frederic
New new button
r19694 'base/js/keyboard',
], function(IPython, $, utils, dialog, events, keyboard) {
MinRK
add utils.url_path_join...
r13063 "use strict";
jon
In person review with @ellisonbg
r17210 var NotebookList = function (selector, options) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Constructor
*
* Parameters:
* selector: string
* options: dictionary
* Dictionary of keyword arguments.
* session_list: SessionList instance
* element_name: string
* base_url: string
* notebook_path: string
* contents: Contents instance
*/
Jonathan Frederic
Started work to make tree requirejs friendly.
r17189 var that = this;
jon
In person review with @ellisonbg
r17210 this.session_list = options.session_list;
Paul Ivanov
ok, Running tab is working now
r15454 // allow code re-use by just changing element_name in kernellist.js
jon
In person review with @ellisonbg
r17210 this.element_name = options.element_name || 'notebook';
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
this.style();
this.bind_events();
}
MinRK
add utils.url_path_join...
r13063 this.notebooks_list = [];
this.sessions = {};
Jonathan Frederic
Almost done!...
r17198 this.base_url = options.base_url || utils.get_body_data("baseUrl");
this.notebook_path = options.notebook_path || utils.get_body_data("notebookPath");
Jeff Hemmelgarn
Move contentmanager to contents
r18643 this.contents = options.contents;
Jonathan Frederic
Fixed events
r17195 if (this.session_list && this.session_list.events) {
this.session_list.events.on('sessions_loaded.Dashboard',
function(e, d) { that.sessions_loaded(d); });
}
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
NotebookList.prototype.style = function () {
Jonathan Frederic
Started work to make tree requirejs friendly.
r17189 var prefix = '#' + this.element_name;
Paul Ivanov
small whitespace cleanup, renamed drag_info...
r15518 $(prefix + '_toolbar').addClass('list_toolbar');
$(prefix + '_list_info').addClass('toolbar_info');
$(prefix + '_buttons').addClass('toolbar_buttons');
$(prefix + '_list_header').addClass('list_header');
MinRK
use row-fluid for cluster list
r10920 this.element.addClass("list_container");
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
NotebookList.prototype.bind_events = function () {
Brian E. Granger
File upload/import working from notebook browser.
r4491 var that = this;
Paul Ivanov
refresh of Notebook list should reload sessions
r15456 $('#refresh_' + this.element_name + '_list').click(function () {
that.load_sessions();
Brian Granger
Draft of the cluster list UI....
r6195 });
Brian E. Granger
File upload/import working from notebook browser.
r4491 this.element.bind('dragover', function () {
return false;
});
Matthias BUSSONNIER
alternate notebook upload methods...
r6838 this.element.bind('drop', function(event){
Paul Ivanov
fix typo in method name
r15455 that.handleFilesUpload(event,'drop');
Brian E. Granger
File upload/import working from notebook browser.
r4491 return false;
});
Jonathan Frederic
New new button
r19694
// Bind events for singleton controls.
if (!NotebookList._bound_singletons) {
NotebookList._bound_singletons = true;
$('#new-file').click(function(e) {
Jonathan Frederic
New file open editor
r19699 var w = window.open();
that.contents.new_untitled(that.notebook_path || '', {type: 'file', ext: '.txt'}).then(function(data) {
var url = utils.url_join_encode(
that.base_url, 'edit', data.path
);
w.location = url;
Min RK
add missing error dialogs to tree actions...
r20238 }).catch(function (e) {
w.close();
dialog.modal({
title: 'Creating File Failed',
body: $('<div/>')
.text("An error occurred while creating a new file.")
.append($('<div/>')
.addClass('alert alert-danger')
.text(e.message || e)),
buttons: {
OK: {'class': 'btn-primary'}
}
});
Jonathan Frederic
New file open editor
r19699 });
Jonathan Frederic
Dont prompt for name.
r19696 that.load_sessions();
Jonathan Frederic
New new button
r19694 });
$('#new-folder').click(function(e) {
Matthias Bussonnier
Reload list after creating a new folder in promises....
r19983 that.contents.new_untitled(that.notebook_path || '', {type: 'directory'})
.then(function(){
that.load_list();
Min RK
add missing error dialogs to tree actions...
r20238 }).catch(function (e) {
dialog.modal({
title: 'Creating Folder Failed',
body: $('<div/>')
.text("An error occurred while creating a new folder.")
.append($('<div/>')
.addClass('alert alert-danger')
.text(e.message || e)),
buttons: {
OK: {'class': 'btn-primary'}
}
});
Matthias Bussonnier
Reload list after creating a new folder in promises....
r19983 });
Min RK
add missing error dialogs to tree actions...
r20238 that.load_sessions();
Jonathan Frederic
New new button
r19694 });
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157
$('.rename-button').click($.proxy(this.rename_selected, this));
$('.shutdown-button').click($.proxy(this.shutdown_selected, this));
$('.duplicate-button').click($.proxy(this.duplicate_selected, this));
$('.delete-button').click($.proxy(this.delete_selected, this));
Jonathan Frederic
New new button
r19694 }
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
Paul Ivanov
fix typo in method name
r15455 NotebookList.prototype.handleFilesUpload = function(event, dropOrForm) {
Matthias BUSSONNIER
alternate notebook upload methods...
r6838 var that = this;
var files;
if(dropOrForm =='drop'){
files = event.originalEvent.dataTransfer.files;
} else
{
MinRK
add utils.url_path_join...
r13063 files = event.originalEvent.target.files;
Matthias BUSSONNIER
alternate notebook upload methods...
r6838 }
MinRK
add utils.url_path_join...
r13063 for (var i = 0; i < files.length; i++) {
var f = files[i];
Jonathan Frederic
Almost done!...
r17198 var name_and_ext = utils.splitext(f.name);
Matthias BUSSONNIER
fix notebook upload...
r13322 var file_ext = name_and_ext[1];
MinRK
various upload fixes...
r17536
var reader = new FileReader();
MinRK
use splitext in notebook_list...
r13121 if (file_ext === '.ipynb') {
MinRK
various upload fixes...
r17536 reader.readAsText(f);
Brian E. Granger
Fully removing .py file upload....
r13115 } else {
MinRK
various upload fixes...
r17536 // read non-notebook files as binary
reader.readAsArrayBuffer(f);
MinRK
add utils.url_path_join...
r13063 }
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 var item = that.new_item(0, true);
MinRK
various upload fixes...
r17536 item.addClass('new-file');
Jeffrey Bush
Minor improvements to file upload....
r17643 that.add_name_input(f.name, item, file_ext == '.ipynb' ? 'notebook' : 'file');
MinRK
various upload fixes...
r17536 // Store the list item in the reader so we can use it later
// to know which item it belongs to.
$(reader).data('item', item);
reader.onload = function (event) {
var item = $(event.target).data('item');
that.add_file_data(event.target.result, item);
that.add_upload_button(item);
};
Jeffrey Bush
Fixed many edge cases in file uploads....
r17650 reader.onerror = function (event) {
var item = $(event.target).data('item');
Min RK
update frontend with path/name changes...
r18752 var name = item.data('name');
Jeffrey Bush
Fixed many edge cases in file uploads....
r17650 item.remove();
dialog.modal({
title : 'Failed to read file',
body : "Failed to read file '" + name + "'",
buttons : {'OK' : { 'class' : 'btn-primary' }}
});
};
Matthias BUSSONNIER
alternate notebook upload methods...
r6838 }
Brian E. Granger
Reset file upload form after an upload.
r14926 // Replace the file input form wth a clone of itself. This is required to
// reset the form. Otherwise, if you upload a file, delete it and try to
// upload it again, the changed event won't fire.
var form = $('input.fileinput');
form.replaceWith(form.clone(true));
Matthias BUSSONNIER
alternate notebook upload methods...
r6838 return false;
MinRK
add utils.url_path_join...
r13063 };
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488
Jonathan Frederic
Don't remove upload items unless explicitly requested.
r16213 NotebookList.prototype.clear_list = function (remove_uploads) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Clears the navigation tree.
*
* Parameters
* remove_uploads: bool=False
* Should upload prompts also be removed from the tree.
*/
Jonathan Frederic
Don't remove upload items unless explicitly requested.
r16213 if (remove_uploads) {
this.element.children('.list_item').remove();
} else {
this.element.children('.list_item:not(.new-file)').remove();
}
Matthias BUSSONNIER
pep8
r7941 };
Brian Granger
Draft of the cluster list UI....
r6195
Zachary Sailer
manual rebase static/tree/
r12988 NotebookList.prototype.load_sessions = function(){
Jonathan Frederic
Started work to make tree requirejs friendly.
r17189 this.session_list.load_sessions();
Zachary Sailer
manual rebase static/tree/
r12988 };
NotebookList.prototype.sessions_loaded = function(data){
Paul Ivanov
added IPython.session_list...
r15479 this.sessions = data;
Zachary Sailer
manual rebase static/tree/
r12988 this.load_list();
};
Brian Granger
Draft of the cluster list UI....
r6195
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 NotebookList.prototype.load_list = function () {
Min RK
update frontend with path/name changes...
r18752 var that = this;
Thomas Kluyver
Use promises for GET requests
r18827 this.contents.list_contents(that.notebook_path).then(
$.proxy(this.draw_notebook_list, this),
function(error) {
Thomas Kluyver
Fix passing empty list to draw_notebook_list()
r18678 that.draw_notebook_list({content: []}, "Server error: " + error.message);
Thomas Kluyver
Make contents JS API consistent
r18653 }
Thomas Kluyver
Use promises for GET requests
r18827 );
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
KesterTong
Moves list_notebooks to ContentManager
r18636 /**
* Draw the list of notebooks
* @method draw_notebook_list
* @param {Array} list An array of dictionaries representing files or
Thomas Kluyver
Fix spelling
r18660 * directories.
KesterTong
Moves list_notebooks to ContentManager
r18636 * @param {String} error_msg An error message
*/
Bussonnier Matthias
fix ordering dirs > notebook> files
r19479
var type_order = {'directory':0,'notebook':1,'file':2};
KesterTong
Moves list_notebooks to ContentManager
r18636 NotebookList.prototype.draw_notebook_list = function (list, error_msg) {
Bussonnier Matthias
sort dashbord in frontend
r19449 list.content.sort(function(a, b) {
Bussonnier Matthias
fix ordering dirs > notebook> files
r19479 if (type_order[a['type']] < type_order[b['type']]) {
Bussonnier Matthias
sort dashbord in frontend
r19449 return -1;
}
Bussonnier Matthias
fix ordering dirs > notebook> files
r19479 if (type_order[a['type']] > type_order[b['type']]) {
Bussonnier Matthias
sort dashbord in frontend
r19449 return 1;
}
if (a['name'] < b['name']) {
return -1;
}
if (a['name'] > b['name']) {
return 1;
}
return 0;
});
KesterTong
Moves list_notebooks to ContentManager
r18636 var message = error_msg || 'Notebook list empty.';
Brian E. Granger
Cleaning up the dashboard CSS and fixing small visual problems.
r15078 var item = null;
Jeff Hemmelgarn
Fix a few problems with cherry-picked commits...
r18640 var model = null;
var len = list.content.length;
Matthias BUSSONNIER
proof of concept
r6842 this.clear_list();
Jeffrey Bush
File list refreshes no longer move the upload filename boxes....
r17651 var n_uploads = this.element.children('.list_item').length;
MinRK
add utils.url_path_join...
r13063 if (len === 0) {
MinRK
teach tree view about non-notebook files
r17526 item = this.new_item(0);
Brian E. Granger
Cleaning up the dashboard CSS and fixing small visual problems.
r15078 var span12 = item.children().first();
span12.empty();
MinRK
don't strip '.ipynb' from notebook names in nblist...
r15094 span12.append($('<div style="margin:auto;text-align:center;color:grey"/>').text(message));
Matthias BUSSONNIER
Drag target bigger for empty notebook dashboard...
r6857 }
MinRK
various unicode fixes...
r15234 var path = this.notebook_path;
Jeffrey Bush
File list refreshes no longer move the upload filename boxes....
r17651 var offset = n_uploads;
Brian E. Granger
Add directory browsing to the dashboard.
r15071 if (path !== '') {
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 item = this.new_item(offset, false);
MinRK
teach tree view about non-notebook files
r17526 model = {
type: 'directory',
name: '..',
Min RK
update frontend with path/name changes...
r18752 path: utils.url_path_split(path)[0],
MinRK
teach tree view about non-notebook files
r17526 };
this.add_link(model, item);
Jeffrey Bush
File list refreshes no longer move the upload filename boxes....
r17651 offset += 1;
Brian E. Granger
Add directory browsing to the dashboard.
r15071 }
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 for (var i=0; i<len; i++) {
Jeff Hemmelgarn
Fix a few problems with cherry-picked commits...
r18640 model = list.content[i];
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 item = this.new_item(i+offset, true);
Jeff Hemmelgarn
Fix a few problems with cherry-picked commits...
r18640 this.add_link(model, item);
MinRK
add utils.url_path_join...
r13063 }
Scott Sanderson
DEV: Add various events.
r19031 // Trigger an event when we've finished drawing the notebook list.
events.trigger('draw_notebook_list.NotebookList');
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 this._selection_changed();
Brian E. Granger
File upload/import working from notebook browser.
r4491 };
Brian E. Granger
Implemented delete functionality in nb browser....
r4490
Brian E. Granger
File upload/import working from notebook browser.
r4491
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 /**
* Creates a new item.
* @param {integer} index
* @param {boolean} [selectable] - tristate, undefined: don't draw checkbox,
* false: don't draw checkbox but pad
* where it should be, true: draw checkbox.
* @return {JQuery} row
*/
NotebookList.prototype.new_item = function (index, selectable) {
var row = $('<div/>')
.addClass("list_item")
.addClass("row");
var item = $("<div/>")
.addClass("col-md-12")
.appendTo(row);
var checkbox;
if (selectable !== undefined) {
checkbox = $('<input/>')
.attr('type', 'checkbox')
Jonathan Frederic
Use trash bin icon,...
r20163 .attr('title', 'Click here to rename, delete, etc.')
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 .appendTo(item);
}
$('<i/>')
.addClass('item_icon')
.appendTo(item);
var link = $("<a/>")
.addClass("item_link")
.appendTo(item);
$("<span/>")
.addClass("item_name")
.appendTo(link);
if (selectable === false) {
checkbox.css('visibility', 'hidden');
} else if (selectable === true) {
var that = this;
link.click(function(e) {
e.stopPropagation();
});
checkbox.click(function(e) {
e.stopPropagation();
that._selection_changed();
});
row.click(function(e) {
e.stopPropagation();
checkbox.prop('checked', !checkbox.prop('checked'));
that._selection_changed();
});
}
var buttons = $('<div/>')
.addClass("item_buttons pull-right")
.appendTo(item);
Jonathan Frederic
Use running text instead of icon.
r20161 $('<div/>')
.addClass('running-indicator')
.text('Running')
.css('visibility', 'hidden')
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 .appendTo(buttons);
MinRK
bootstrap tree
r10891
Brian E. Granger
File upload/import working from notebook browser.
r4491 if (index === -1) {
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 this.element.append(row);
Brian E. Granger
File upload/import working from notebook browser.
r4491 } else {
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 this.element.children().eq(index).after(row);
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 }
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 return row;
Brian E. Granger
File upload/import working from notebook browser.
r4491 };
MinRK
teach tree view about non-notebook files
r17526 NotebookList.icons = {
directory: 'folder_icon',
notebook: 'notebook_icon',
file: 'file_icon',
};
NotebookList.uri_prefixes = {
directory: 'tree',
notebook: 'notebooks',
Min RK
link to /edit/ on files
r19307 file: 'edit',
MinRK
teach tree view about non-notebook files
r17526 };
Jonathan Frederic
Add some more comments...
r20241 /**
* Handles when any row selector checkbox is toggled.
*/
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 NotebookList.prototype._selection_changed = function() {
Jonathan Frederic
Add some more comments...
r20241
// Use a JQuery selector to find each row with a checked checkbox. If
// we decide to add more checkboxes in the future, this code will need
// to be changed to distinguish which checkbox is the row selector.
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 var selected = [];
Jonathan Frederic
Change shutdown button display behavior,...
r20160 var has_running_notebook = false;
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 var has_directory = false;
Jonathan Frederic
Only show shutdown when notebooks are the only thing selected.
r20165 var has_file = false;
Jonathan Frederic
That this typo
r20162 var that = this;
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 $('.list_item :checked').each(function(index, item) {
var parent = $(item).parent().parent();
Jonathan Frederic
Add some more comments...
r20241 // If the item doesn't have an upload button, it can be selected.
Jonathan Frederic
Make upload work with new UI
r20239 if (parent.find('.upload_button').length === 0) {
selected.push({
name: parent.data('name'),
path: parent.data('path'),
type: parent.data('type')
});
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157
Jonathan Frederic
Add some more comments...
r20241 // Set flags according to what is selected. Flags are later
// used to decide which action buttons are visible.
Jonathan Frederic
Make upload work with new UI
r20239 has_running_notebook = has_running_notebook ||
(parent.data('type') == 'notebook' && that.sessions[parent.data('path')] !== undefined);
has_file = has_file || parent.data('type') == 'file';
has_directory = has_directory || parent.data('type') == 'directory';
}
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 });
this.selected = selected;
// Rename is only visible when one item is selected.
if (selected.length==1) {
$('.rename-button').css('display', 'inline-block');
} else {
$('.rename-button').css('display', 'none');
}
Jonathan Frederic
Add some more comments...
r20241 // Shutdown is only visible when one or more notebooks running notebooks
// are selected and no non-notebook items are selected.
Jonathan Frederic
Only show shutdown when notebooks are the only thing selected.
r20165 if (has_running_notebook && !(has_file || has_directory)) {
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 $('.shutdown-button').css('display', 'inline-block');
} else {
$('.shutdown-button').css('display', 'none');
}
Jonathan Frederic
Add some more comments...
r20241 // Duplicate isn't visible when a directory is selected.
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 if (selected.length > 0 && !has_directory) {
$('.duplicate-button').css('display', 'inline-block');
} else {
$('.duplicate-button').css('display', 'none');
}
// Delete is visible if one or more items are selected.
if (selected.length > 0) {
$('.delete-button').css('display', 'inline-block');
} else {
$('.delete-button').css('display', 'none');
}
};
MinRK
teach tree view about non-notebook files
r17526
NotebookList.prototype.add_link = function (model, item) {
var path = model.path,
name = model.name;
Mathieu
add running indication for notebook icon in dashboard
r20235 var running = (model.type == 'notebook' && this.sessions[path] !== undefined);
Brian E. Granger
Add directory browsing to the dashboard.
r15071 item.data('name', name);
item.data('path', path);
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 item.data('type', model.type);
Brian E. Granger
Add directory browsing to the dashboard.
r15071 item.find(".item_name").text(name);
MinRK
teach tree view about non-notebook files
r17526 var icon = NotebookList.icons[model.type];
Mathieu
add running indication for notebook icon in dashboard
r20235 if (running) {
icon = 'running_' + icon;
}
MinRK
teach tree view about non-notebook files
r17526 var uri_prefix = NotebookList.uri_prefixes[model.type];
item.find(".item_icon").addClass(icon).addClass('icon-fixed-width');
MinRK
updates per review...
r17535 var link = item.find("a.item_link")
Brian E. Granger
Add directory browsing to the dashboard.
r15071 .attr('href',
Jonathan Frederic
Almost done!...
r17198 utils.url_join_encode(
MinRK
s/base_project_url/base_url/...
r15238 this.base_url,
MinRK
teach tree view about non-notebook files
r17526 uri_prefix,
Min RK
update frontend with path/name changes...
r18752 path
Brian E. Granger
Add directory browsing to the dashboard.
r15071 )
);
Jonathan Frederic
Add actions dropdown to tree view
r20156
Jonathan Frederic
Use running text instead of icon.
r20161 item.find(".item_buttons .running-indicator").css('visibility', running ? '' : 'hidden');
Jonathan Frederic
Add actions dropdown to tree view
r20156
MinRK
updates per review...
r17535 // directory nav doesn't open new tabs
// files, notebooks do
if (model.type !== "directory") {
link.attr('target','_blank');
}
Brian E. Granger
Add directory browsing to the dashboard.
r15071 };
Jeffrey Bush
Minor improvements to file upload....
r17643 NotebookList.prototype.add_name_input = function (name, item, icon_type) {
MinRK
teach tree view about non-notebook files
r17526 item.data('name', name);
Jeffrey Bush
Minor improvements to file upload....
r17643 item.find(".item_icon").addClass(NotebookList.icons[icon_type]).addClass('icon-fixed-width');
MinRK
use row-fluid for tree_list
r10919 item.find(".item_name").empty().append(
MinRK
tree style tweaks
r10896 $('<input/>')
MinRK
various upload fixes...
r17536 .addClass("filename_input")
.attr('value', name)
MinRK
tree style tweaks
r10896 .attr('size', '30')
.attr('type', 'text')
Jeffrey Bush
Added ESC keep to upload textbox to cancel.
r17646 .keyup(function(event){
if(event.keyCode == 13){item.find('.upload_button').click();}
else if(event.keyCode == 27){item.remove();}
})
Brian E. Granger
File upload/import working from notebook browser.
r4491 );
};
MinRK
various upload fixes...
r17536 NotebookList.prototype.add_file_data = function (data, item) {
item.data('filedata', data);
Brian E. Granger
File upload/import working from notebook browser.
r4491 };
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 NotebookList.prototype.shutdown_selected = function() {
Matthias BUSSONNIER
proof of concept
r6842 var that = this;
Jonathan Frederic
Re-add shutdown button to running tab
r20164 this.selected.forEach(function(item) {
if (item.type == 'notebook') {
that.shutdown_notebook(item.path);
}
});
};
NotebookList.prototype.shutdown_notebook = function(path) {
var that = this;
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 var settings = {
processData : false,
cache : false,
type : "DELETE",
dataType : "json",
success : function () {
that.load_sessions();
},
error : utils.log_ajax_error,
};
Jonathan Frederic
Re-add shutdown button to running tab
r20164 var session = this.sessions[path];
if (session) {
var url = utils.url_join_encode(
this.base_url,
'api/sessions',
session
);
$.ajax(url, settings);
}
Min RK
add missing error dialogs to tree actions...
r20238 };
David Neto
Add the "Duplicate" button in the main dashboard...
r18927
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 NotebookList.prototype.rename_selected = function() {
if (this.selected.length != 1) return;
Jonathan Frederic
Add actions dropdown to tree view
r20156
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 var that = this;
var path = this.selected[0].path;
var input = $('<input/>').attr('type','text').attr('size','25').addClass('form-control')
.val(path);
var dialog_body = $('<div/>').append(
$("<p/>").addClass("rename-message")
.text('Enter a new directory name:')
).append(
$("<br/>")
).append(input);
var d = dialog.modal({
title : "Rename directory",
body : dialog_body,
buttons : {
OK : {
class: "btn-primary",
click: function() {
that.contents.rename(path, input.val()).then(function() {
that.load_list();
}).catch(function(e) {
dialog.modal({
Min RK
add missing error dialogs to tree actions...
r20238 title: "Rename Failed",
body: $('<div/>')
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 .text("An error occurred while renaming \"" + path + "\" to \"" + input.val() + "\".")
Min RK
add missing error dialogs to tree actions...
r20238 .append($('<div/>')
.addClass('alert alert-danger')
.text(e.message || e)),
buttons: {
OK: {'class': 'btn-primary'}
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 }
});
});
}
},
Cancel : {}
},
open : function () {
// Upon ENTER, click the OK button.
input.keydown(function (event) {
if (event.which === keyboard.keycodes.enter) {
d.find('.btn-primary').first().click();
return false;
}
});
input.focus().select();
}
});
Jonathan Frederic
Add actions dropdown to tree view
r20156 };
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 NotebookList.prototype.delete_selected = function() {
var message;
if (this.selected.length == 1) {
message = 'Are you sure you want to permanently delete: ' + this.selected[0].name + '?';
} else {
Jonathan Frederic
files/folders
r20225 message = 'Are you sure you want to permanently delete the ' + this.selected.length + ' files/folders selected?';
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 }
var that = this;
dialog.modal({
title : "Delete",
body : message,
buttons : {
Delete : {
class: "btn-danger",
click: function() {
Jonathan Frederic
Shutdown the selected notebooks before deleting them
r20159 // Shutdown any/all selected notebooks before deleting
// the files.
that.shutdown_selected();
// Delete selected.
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 that.selected.forEach(function(item) {
that.contents.delete(item.path).then(function() {
that.notebook_deleted(item.path);
Jonathan Frederic
Add actions dropdown to tree view
r20156 }).catch(function(e) {
dialog.modal({
Min RK
add missing error dialogs to tree actions...
r20238 title: "Delete Failed",
body: $('<div/>')
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 .text("An error occurred while deleting \"" + item.path + "\".")
Min RK
add missing error dialogs to tree actions...
r20238 .append($('<div/>')
.addClass('alert alert-danger')
.text(e.message || e)),
buttons: {
OK: {'class': 'btn-primary'}
Jonathan Frederic
Add actions dropdown to tree view
r20156 }
Min RK
simplify NotebookList.duplicate with recent changes...
r18930 });
Jonathan Frederic
Add actions dropdown to tree view
r20156 });
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 });
}
Jonathan Frederic
Add actions dropdown to tree view
r20156 },
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 Cancel : {}
}
});
Matthias BUSSONNIER
proof of concept
r6842 };
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 NotebookList.prototype.duplicate_selected = function() {
var message;
if (this.selected.length == 1) {
message = 'Are you sure you want to duplicate: ' + this.selected[0].name + '?';
} else {
message = 'Are you sure you want to duplicate the ' + this.selected.length + ' files selected?';
}
var that = this;
dialog.modal({
title : "Delete",
body : message,
buttons : {
Duplicate : {
class: "btn-primary",
click: function() {
that.selected.forEach(function(item) {
that.contents.copy(item.path, that.notebook_path).then(function () {
that.load_list();
Jonathan Frederic
Add actions dropdown to tree view
r20156 }).catch(function(e) {
dialog.modal({
Min RK
add missing error dialogs to tree actions...
r20238 title: "Delete Failed",
body: $('<div/>')
.text("An error occurred while deleting \"" + item.path + "\".")
.append($('<div/>')
.addClass('alert alert-danger')
.text(e.message || e)),
buttons: {
OK: {'class': 'btn-primary'}
Thomas Kluyver
Miscellaneous JS fixes
r18656 }
Jonathan Frederic
Add actions dropdown to tree view
r20156 });
});
Jonathan Frederic
Use checkbox layout instead of actions dropdown
r20157 });
}
},
Cancel : {}
}
});
Brian E. Granger
File upload/import working from notebook browser.
r4491 };
Min RK
update frontend with path/name changes...
r18752 NotebookList.prototype.notebook_deleted = function(path) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Remove the deleted notebook.
*/
Min RK
add missing `that = this`
r20184 var that = this;
Thomas Kluyver
Fix some bugs in deleting notebooks from the dashboard
r18772 $( ":data(path)" ).each(function() {
Min RK
update frontend with path/name changes...
r18752 var element = $(this);
Min RK
add missing `that = this`
r20184 if (element.data("path") === path) {
Thomas Kluyver
Some more event cleanup
r18655 element.remove();
Scott Sanderson
DEV: Add various events.
r19031 events.trigger('notebook_deleted.NotebookList');
Min RK
add missing `that = this`
r20184 that._selection_changed();
Thomas Kluyver
Some more event cleanup
r18655 }
});
Min RK
update frontend with path/name changes...
r18752 };
Thomas Kluyver
Some more event cleanup
r18655
Brian E. Granger
File upload/import working from notebook browser.
r4491
Min RK
update frontend with path/name changes...
r18752 NotebookList.prototype.add_upload_button = function (item) {
Brian E. Granger
File upload/import working from notebook browser.
r4491 var that = this;
MinRK
tree style tweaks
r10896 var upload_button = $('<button/>').text("Upload")
Jonathan Frederic
Fix automation errors.
r16914 .addClass('btn btn-primary btn-xs upload_button')
MinRK
tree style tweaks
r10896 .click(function (e) {
MinRK
various upload fixes...
r17536 var filename = item.find('.item_name > input').val();
Min RK
update frontend with path/name changes...
r18752 var path = utils.url_path_join(that.notebook_path, filename);
MinRK
various upload fixes...
r17536 var filedata = item.data('filedata');
var format = 'text';
Jeffrey Bush
Fixed many edge cases in file uploads....
r17650 if (filename.length === 0 || filename[0] === '.') {
dialog.modal({
title : 'Invalid file name',
body : "File names must be at least one character and not start with a dot",
buttons : {'OK' : { 'class' : 'btn-primary' }}
});
return false;
}
MinRK
various upload fixes...
r17536 if (filedata instanceof ArrayBuffer) {
// base64-encode binary file data
var bytes = '';
var buf = new Uint8Array(filedata);
var nbytes = buf.byteLength;
for (var i=0; i<nbytes; i++) {
bytes += String.fromCharCode(buf[i]);
}
filedata = btoa(bytes);
format = 'base64';
}
Min RK
update frontend with path/name changes...
r18752 var model = {};
MinRK
various upload fixes...
r17536
var name_and_ext = utils.splitext(filename);
var file_ext = name_and_ext[1];
var content_type;
if (file_ext === '.ipynb') {
model.type = 'notebook';
model.format = 'json';
MinRK
update contents per further review...
r17537 try {
model.content = JSON.parse(filedata);
} catch (e) {
dialog.modal({
title : 'Cannot upload invalid Notebook',
body : "The error was: " + e,
buttons : {'OK' : {
'class' : 'btn-primary',
click: function () {
item.remove();
}
}}
});
Jeffrey Bush
Fixed many edge cases in file uploads....
r17650 return false;
MinRK
update contents per further review...
r17537 }
MinRK
various upload fixes...
r17536 content_type = 'application/json';
} else {
model.type = 'file';
model.format = format;
model.content = filedata;
content_type = 'application/octet-stream';
}
Min RK
update frontend with path/name changes...
r18752 filedata = item.data('filedata');
MinRK
various upload fixes...
r17536
Thomas Kluyver
All aboard the promise train
r18829 var on_success = function () {
item.removeClass('new-file');
that.add_link(model, item);
that.session_list.load_sessions();
Brian E. Granger
File upload/import working from notebook browser.
r4491 };
Jeffrey Bush
Uploading a file with a name that already exists asks the user if they want to overwrite....
r17648
var exists = false;
$.each(that.element.find('.list_item:not(.new-file)'), function(k,v){
if ($(v).data('name') === filename) { exists = true; return false; }
});
Min RK
update frontend with path/name changes...
r18752
Jeffrey Bush
Uploading a file with a name that already exists asks the user if they want to overwrite....
r17648 if (exists) {
dialog.modal({
title : "Replace file",
body : 'There is already a file named ' + filename + ', do you want to replace it?',
buttons : {
Overwrite : {
class: "btn-danger",
Min RK
update frontend with path/name changes...
r18752 click: function () {
Thomas Kluyver
All aboard the promise train
r18829 that.contents.save(path, model).then(on_success);
}
Jeffrey Bush
Uploading a file with a name that already exists asks the user if they want to overwrite....
r17648 },
Cancel : {
click: function() { item.remove(); }
}
}
});
} else {
Thomas Kluyver
All aboard the promise train
r18829 that.contents.save(path, model).then(on_success);
Jeffrey Bush
Uploading a file with a name that already exists asks the user if they want to overwrite....
r17648 }
MinRK
bootstrap tree
r10891 return false;
Brian E. Granger
File upload/import working from notebook browser.
r4491 });
MinRK
tree style tweaks
r10896 var cancel_button = $('<button/>').text("Cancel")
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .addClass("btn btn-default btn-xs")
MinRK
tree style tweaks
r10896 .click(function (e) {
Brian E. Granger
File upload/import working from notebook browser.
r4491 item.remove();
MinRK
bootstrap tree
r10891 return false;
Brian E. Granger
File upload/import working from notebook browser.
r4491 });
MinRK
tree style tweaks
r10896 item.find(".item_buttons").empty()
MinRK
bootstrap tree
r10891 .append(upload_button)
.append(cancel_button);
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
Min RK
update frontend with path/name changes...
r18752 // Backwards compatability.
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 IPython.NotebookList = NotebookList;
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'NotebookList': NotebookList};
Jonathan Frederic
Started work to make tree requirejs friendly.
r17189 });