##// END OF EJS Templates
Merge pull request #2291 from ellisonbg/rmplugin...
Merge pull request #2291 from ellisonbg/rmplugin Remove old plugin system

File last commit:

r7976:3acd4878
r8514:2e9bf5c2 merge
Show More
notebooklist.js
328 lines | 11.5 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
r4609 //----------------------------------------------------------------------------
// Copyright (C) 2008-2011 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488
//============================================================================
Brian E. Granger
More review changes....
r4609 // NotebookList
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 //============================================================================
var IPython = (function (IPython) {
var NotebookList = function (selector) {
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
this.style();
this.bind_events();
}
};
NotebookList.prototype.style = function () {
Brian Granger
Draft of the cluster list UI....
r6195 $('#notebook_toolbar').addClass('list_toolbar');
$('#drag_info').addClass('toolbar_info');
$('#notebook_buttons').addClass('toolbar_buttons');
$('div#project_name').addClass('list_header ui-widget ui-widget-header');
$('#refresh_notebook_list').button({
icons : {primary: 'ui-icon-arrowrefresh-1-s'},
text : false
});
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
NotebookList.prototype.bind_events = function () {
MinRK
move drag_info show/hide to page.ready, to avoid flouc
r5705 if (IPython.read_only){
return;
}
Brian E. Granger
File upload/import working from notebook browser.
r4491 var that = this;
Brian Granger
Draft of the cluster list UI....
r6195 $('#refresh_notebook_list').click(function () {
that.load_list();
});
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){
Matthias BUSSONNIER
remove extra console.log
r6851 that.handelFilesUpload(event,'drop');
Brian E. Granger
File upload/import working from notebook browser.
r4491 return false;
});
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
Matthias BUSSONNIER
alternate notebook upload methods...
r6838 NotebookList.prototype.handelFilesUpload = function(event, dropOrForm) {
var that = this;
var files;
if(dropOrForm =='drop'){
files = event.originalEvent.dataTransfer.files;
} else
{
files = event.originalEvent.target.files
}
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
reader.readAsText(f);
var fname = f.name.split('.');
var nbname = fname.slice(0,-1).join('.');
var nbformat = fname.slice(-1)[0];
if (nbformat === 'ipynb') {nbformat = 'json';};
if (nbformat === 'py' || nbformat === 'json') {
var item = that.new_notebook_item(0);
that.add_name_input(nbname, item);
item.data('nbformat', nbformat);
// Store the notebook 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 nbitem = $(event.target).data('item');
that.add_notebook_data(event.target.result, nbitem);
that.add_upload_button(nbitem);
};
};
}
return false;
};
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488
Brian Granger
Draft of the cluster list UI....
r6195 NotebookList.prototype.clear_list = function () {
this.element.children('.list_item').remove();
Matthias BUSSONNIER
pep8
r7941 };
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 () {
Matthias BUSSONNIER
show message on notebook list if server is unreachable...
r7881 var that = this;
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 var settings = {
processData : false,
cache : false,
type : "GET",
dataType : "json",
Matthias BUSSONNIER
show message on notebook list if server is unreachable...
r7881 success : $.proxy(this.list_loaded, this),
Matthias BUSSONNIER
pep8
r7941 error : $.proxy( function(){
that.list_loaded([], null, null, {msg:"Error connecting to server."});
},this)
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
Matthias BUSSONNIER
show message on notebook list if server is unreachable...
r7881
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 var url = $('body').data('baseProjectUrl') + 'notebooks';
Brian E. Granger
Updating JS URL scheme to use embedded data....
r5106 $.ajax(url, settings);
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
Matthias BUSSONNIER
show message on notebook list if server is unreachable...
r7881 NotebookList.prototype.list_loaded = function (data, status, xhr, param) {
MinRK
handle undefined param in notebooklist...
r7976 var message = 'Notebook list empty.';
if (param !== undefined && param.msg) {
var message = param.msg;
}
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 var len = data.length;
Matthias BUSSONNIER
proof of concept
r6842 this.clear_list();
Matthias BUSSONNIER
Drag target bigger for empty notebook dashboard...
r6857
if(len == 0)
{
$(this.new_notebook_item(0))
.append(
$('<div style="margin:auto;text-align:center;color:grey"/>')
Matthias BUSSONNIER
show message on notebook list if server is unreachable...
r7881 .text(message)
Matthias BUSSONNIER
Drag target bigger for empty notebook dashboard...
r6857 )
}
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 for (var i=0; i<len; i++) {
Brian E. Granger
Implemented delete functionality in nb browser....
r4490 var notebook_id = data[i].notebook_id;
var nbname = data[i].name;
Matthias BUSSONNIER
rename kernel_status -> kernel_id
r6846 var kernel = data[i].kernel_id;
Brian E. Granger
File upload/import working from notebook browser.
r4491 var item = this.new_notebook_item(i);
this.add_link(notebook_id, nbname, item);
MinRK
move read_only flag to page-level...
r5213 if (!IPython.read_only){
MinRK
add read-only view for notebooks...
r5200 // hide delete buttons when readonly
Matthias BUSSONNIER
Check for null rather than undefined...
r6848 if(kernel == null){
Matthias BUSSONNIER
proof of concept
r6842 this.add_delete_button(item);
} else {
this.add_shutdown_button(item,kernel);
}
MinRK
add read-only view for notebooks...
r5200 }
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
NotebookList.prototype.new_notebook_item = function (index) {
var item = $('<div/>');
Brian Granger
Draft of the cluster list UI....
r6195 item.addClass('list_item ui-widget ui-widget-content ui-helper-clearfix');
Brian Granger
Major refactoring of notebook....
r6193 item.css('border-top-style','none');
Brian E. Granger
File upload/import working from notebook browser.
r4491 var item_name = $('<span/>').addClass('item_name');
item.append(item_name);
if (index === -1) {
Brian E. Granger
Implemented delete functionality in nb browser....
r4490 this.element.append(item);
Brian E. Granger
File upload/import working from notebook browser.
r4491 } else {
this.element.children().eq(index).after(item);
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 }
Brian E. Granger
File upload/import working from notebook browser.
r4491 return item;
};
NotebookList.prototype.add_link = function (notebook_id, nbname, item) {
item.data('nbname', nbname);
item.data('notebook_id', notebook_id);
var new_item_name = $('<span/>').addClass('item_name');
new_item_name.append(
$('<a/>').
Brian Granger
Solid first go at jquery-ui based menus.
r5869 attr('href', $('body').data('baseProjectUrl')+notebook_id).
Brian E. Granger
File upload/import working from notebook browser.
r4491 attr('target','_blank').
text(nbname)
);
var e = item.find('.item_name');
if (e.length === 0) {
item.append(new_item_name);
} else {
e.replaceWith(new_item_name);
};
};
NotebookList.prototype.add_name_input = function (nbname, item) {
item.data('nbname', nbname);
var new_item_name = $('<span/>').addClass('item_name');
new_item_name.append(
$('<input/>').addClass('ui-widget ui-widget-content').
attr('value', nbname).
attr('size', '30').
attr('type', 'text')
);
var e = item.find('.item_name');
if (e.length === 0) {
item.append(new_item_name);
} else {
e.replaceWith(new_item_name);
};
};
NotebookList.prototype.add_notebook_data = function (data, item) {
item.data('nbdata',data);
};
Matthias BUSSONNIER
proof of concept
r6842 NotebookList.prototype.add_shutdown_button = function (item,kernel) {
var new_buttons = $('<span/>').addClass('item_buttons');
var that = this;
var shutdown_button = $('<button>Shutdown</button>').button().
click(function (e) {
var settings = {
processData : false,
cache : false,
type : "DELETE",
dataType : "json",
success : function (data, status, xhr) {
that.load_list();
}
};
var url = $('body').data('baseProjectUrl') + 'kernels/'+kernel;
$.ajax(url, settings);
});
new_buttons.append(shutdown_button);
var e = item.find('.item_buttons');
if (e.length === 0) {
item.append(new_buttons);
} else {
e.replaceWith(new_buttons);
};
};
Brian E. Granger
File upload/import working from notebook browser.
r4491 NotebookList.prototype.add_delete_button = function (item) {
var new_buttons = $('<span/>').addClass('item_buttons');
var delete_button = $('<button>Delete</button>').button().
click(function (e) {
// $(this) is the button that was clicked.
var that = $(this);
// We use the nbname and notebook_id from the parent notebook_item element's
// data because the outer scopes values change as we iterate through the loop.
Brian Granger
Draft of the cluster list UI....
r6195 var parent_item = that.parents('div.list_item');
Brian E. Granger
File upload/import working from notebook browser.
r4491 var nbname = parent_item.data('nbname');
var notebook_id = parent_item.data('notebook_id');
var dialog = $('<div/>');
dialog.html('Are you sure you want to permanently delete the notebook: ' + nbname + '?');
parent_item.append(dialog);
dialog.dialog({
resizable: false,
modal: true,
title: "Delete notebook",
buttons : {
"Delete": function () {
var settings = {
processData : false,
cache : false,
type : "DELETE",
dataType : "json",
success : function (data, status, xhr) {
parent_item.remove();
}
};
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id;
Brian E. Granger
Updating JS URL scheme to use embedded data....
r5106 $.ajax(url, settings);
Brian E. Granger
File upload/import working from notebook browser.
r4491 $(this).dialog('close');
},
"Cancel": function () {
$(this).dialog('close');
}
}
});
});
new_buttons.append(delete_button);
var e = item.find('.item_buttons');
if (e.length === 0) {
item.append(new_buttons);
} else {
e.replaceWith(new_buttons);
};
};
NotebookList.prototype.add_upload_button = function (item) {
var that = this;
var new_buttons = $('<span/>').addClass('item_buttons');
var upload_button = $('<button>Upload</button>').button().
Matthias BUSSONNIER
prevent autorefresh when pending upload...
r6849 addClass('upload-button').
Brian E. Granger
File upload/import working from notebook browser.
r4491 click(function (e) {
var nbname = item.find('.item_name > input').attr('value');
var nbformat = item.data('nbformat');
var nbdata = item.data('nbdata');
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 var content_type = 'text/plain';
Brian E. Granger
Making JSON the default .ipynb format.
r4633 if (nbformat === 'json') {
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 content_type = 'application/json';
} else if (nbformat === 'py') {
content_type = 'application/x-python';
};
Brian E. Granger
File upload/import working from notebook browser.
r4491 var settings = {
processData : false,
cache : false,
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 type : 'POST',
dataType : 'json',
Brian E. Granger
File upload/import working from notebook browser.
r4491 data : nbdata,
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 headers : {'Content-Type': content_type},
Brian E. Granger
File upload/import working from notebook browser.
r4491 success : function (data, status, xhr) {
that.add_link(data, nbname, item);
that.add_delete_button(item);
}
};
var qs = $.param({name:nbname, format:nbformat});
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 var url = $('body').data('baseProjectUrl') + 'notebooks?' + qs;
Brian E. Granger
Updating JS URL scheme to use embedded data....
r5106 $.ajax(url, settings);
Brian E. Granger
File upload/import working from notebook browser.
r4491 });
var cancel_button = $('<button>Cancel</button>').button().
click(function (e) {
item.remove();
});
upload_button.addClass('upload_button');
new_buttons.append(upload_button).append(cancel_button);
var e = item.find('.item_buttons');
if (e.length === 0) {
item.append(new_buttons);
} else {
e.replaceWith(new_buttons);
};
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
IPython.NotebookList = NotebookList;
return IPython;
}(IPython));