##// END OF EJS Templates
run all travis tests
run all travis tests

File last commit:

r13121:1fff66c4
r13291:e2dc90dd
Show More
notebooklist.js
397 lines | 13.6 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
r4609 //----------------------------------------------------------------------------
MinRK
add utils.url_path_join...
r13063 // Copyright (C) 2011 The IPython Development Team
Brian E. Granger
More review changes....
r4609 //
// 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) {
MinRK
add utils.url_path_join...
r13063 "use strict";
var utils = IPython.utils;
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488
var NotebookList = function (selector) {
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 = {};
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 };
Bussonnier Matthias
make base project url a method on notebook list
r9502 NotebookList.prototype.baseProjectUrl = function () {
Zachary Sailer
manual rebase static/tree/
r12988 return $('body').data('baseProjectUrl');
};
Zachary Sailer
allow spaces in notebook path
r13012
Zachary Sailer
manual rebase static/tree/
r12988 NotebookList.prototype.notebookPath = function() {
MinRK
add utils.url_path_join...
r13063 return $('body').data('notebookPath');
Zachary Sailer
manual rebase static/tree/
r12988 };
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 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');
MinRK
use row-fluid for tree_list
r10919 $('#notebook_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;
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
{
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];
Matthias BUSSONNIER
alternate notebook upload methods...
r6838 var reader = new FileReader();
reader.readAsText(f);
MinRK
use splitext in notebook_list...
r13121 var name_and_ext = utils.splitext(f.name);
var nbname = name_and_ext[0];
var file_ext = name_and_ext[-1];
if (file_ext === '.ipynb') {
Matthias BUSSONNIER
alternate notebook upload methods...
r6838 var item = that.new_notebook_item(0);
that.add_name_input(nbname, item);
// 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);
};
Brian E. Granger
Fully removing .py file upload....
r13115 } else {
var dialog = 'Uploaded notebooks must be .ipynb files';
IPython.dialog.modal({
title : 'Invalid file type',
body : dialog,
buttons : {'OK' : {'class' : 'btn-primary'}}
});
MinRK
add utils.url_path_join...
r13063 }
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
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
Zachary Sailer
manual rebase static/tree/
r12988 NotebookList.prototype.load_sessions = function(){
Zachary Sailer
fixed shutdown button refresh on dashboard
r12996 var that = this;
Zachary Sailer
manual rebase static/tree/
r12988 var settings = {
processData : false,
cache : false,
type : "GET",
dataType : "json",
Zachary Sailer
fixed shutdown button refresh on dashboard
r12996 success : $.proxy(that.sessions_loaded, this)
Zachary Sailer
manual rebase static/tree/
r12988 };
var url = this.baseProjectUrl() + 'api/sessions';
$.ajax(url,settings);
};
NotebookList.prototype.sessions_loaded = function(data){
MinRK
add utils.url_path_join...
r13063 this.sessions = {};
Zachary Sailer
manual rebase static/tree/
r12988 var len = data.length;
MinRK
add utils.url_path_join...
r13063 if (len > 0) {
Zachary Sailer
manual rebase static/tree/
r12988 for (var i=0; i<len; i++) {
MinRK
mixup notebook_list
r13069 var nb_path;
MinRK
add utils.url_path_join...
r13063 if (!data[i].notebook.path) {
nb_path = data[i].notebook.name;
Zachary Sailer
manual rebase static/tree/
r12988 }
else {
MinRK
add utils.url_path_join...
r13063 nb_path = utils.url_path_join(
data[i].notebook.path,
data[i].notebook.name
);
Zachary Sailer
manual rebase static/tree/
r12988 }
MinRK
add utils.url_path_join...
r13063 this.sessions[nb_path] = data[i].id;
Zachary Sailer
manual rebase static/tree/
r12988 }
MinRK
add utils.url_path_join...
r13063 }
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 () {
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
MinRK
add utils.url_path_join...
r13063 var url = utils.url_path_join(
this.baseProjectUrl(),
'api',
'notebooks',
this.notebookPath()
);
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) {
MinRK
add utils.url_path_join...
r13063 message = param.msg;
MinRK
handle undefined param in notebooklist...
r7976 }
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();
MinRK
add utils.url_path_join...
r13063 if (len === 0) {
Matthias BUSSONNIER
Drag target bigger for empty notebook dashboard...
r6857 $(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)
MinRK
add utils.url_path_join...
r13063 );
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++) {
Zachary Sailer
change standard money keys
r13015 var name = data[i].name;
Zachary Sailer
manual rebase static/tree/
r12988 var path = this.notebookPath();
MinRK
use splitext in notebook_list...
r13121 var nbname = utils.splitext(name)[0];
Brian E. Granger
File upload/import working from notebook browser.
r4491 var item = this.new_notebook_item(i);
Zachary Sailer
manual rebase static/tree/
r12988 this.add_link(path, nbname, item);
MinRK
mixup notebook_list
r13069 name = utils.url_path_join(this.notebookPath(), name);
MinRK
add utils.url_path_join...
r13063 if(this.sessions[name] === undefined){
MinRK
remove notebook read-only view...
r11644 this.add_delete_button(item);
} else {
Zachary Sailer
manual rebase static/tree/
r12988 this.add_shutdown_button(item,this.sessions[name]);
MinRK
add read-only view for notebooks...
r5200 }
MinRK
add utils.url_path_join...
r13063 }
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) {
MinRK
use row-fluid for tree_list
r10919 var item = $('<div/>').addClass("list_item").addClass("row-fluid");
MinRK
bootstrap tree
r10891 // item.addClass('list_item ui-widget ui-widget-content ui-helper-clearfix');
// item.css('border-top-style','none');
MinRK
use row-fluid for tree_list
r10919 item.append($("<div/>").addClass("span12").append(
$("<a/>").addClass("item_link").append(
MinRK
bootstrap tree
r10891 $("<span/>").addClass("item_name")
)
MinRK
use row-fluid for tree_list
r10919 ).append(
$('<div/>').addClass("item_buttons btn-group pull-right")
));
MinRK
bootstrap tree
r10891
Brian E. Granger
File upload/import working from notebook browser.
r4491 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;
};
Zachary Sailer
manual rebase static/tree/
r12988 NotebookList.prototype.add_link = function (path, nbname, item) {
Brian E. Granger
File upload/import working from notebook browser.
r4491 item.data('nbname', nbname);
Zachary Sailer
manual rebase static/tree/
r12988 item.data('path', path);
MinRK
use row-fluid for tree_list
r10919 item.find(".item_name").text(nbname);
item.find("a.item_link")
MinRK
add utils.url_path_join...
r13063 .attr('href',
utils.url_path_join(
this.baseProjectUrl(),
"notebooks",
this.notebookPath(),
nbname + ".ipynb"
)
).attr('target','_blank');
Brian E. Granger
File upload/import working from notebook browser.
r4491 };
NotebookList.prototype.add_name_input = function (nbname, item) {
item.data('nbname', nbname);
MinRK
use row-fluid for tree_list
r10919 item.find(".item_name").empty().append(
MinRK
tree style tweaks
r10896 $('<input/>')
.addClass("nbname_input")
.attr('value', nbname)
.attr('size', '30')
.attr('type', 'text')
Brian E. Granger
File upload/import working from notebook browser.
r4491 );
};
NotebookList.prototype.add_notebook_data = function (data, item) {
MinRK
fix dashboard upload
r13072 item.data('nbdata', data);
Brian E. Granger
File upload/import working from notebook browser.
r4491 };
Zachary Sailer
manual rebase static/tree/
r12988 NotebookList.prototype.add_shutdown_button = function (item, session) {
Matthias BUSSONNIER
proof of concept
r6842 var that = this;
MinRK
bootstrap tree
r10891 var shutdown_button = $("<button/>").text("Shutdown").addClass("btn btn-mini").
Matthias BUSSONNIER
proof of concept
r6842 click(function (e) {
var settings = {
processData : false,
cache : false,
type : "DELETE",
dataType : "json",
Zachary Sailer
fixed shutdown button refresh on dashboard
r12996 success : function () {
Zachary Sailer
manual rebase static/tree/
r12988 that.load_sessions();
Matthias BUSSONNIER
proof of concept
r6842 }
};
MinRK
add utils.url_path_join...
r13063 var url = utils.url_path_join(
that.baseProjectUrl(),
'api/sessions',
session
);
Matthias BUSSONNIER
proof of concept
r6842 $.ajax(url, settings);
MinRK
bootstrap tree
r10891 return false;
Matthias BUSSONNIER
proof of concept
r6842 });
MinRK
bootstrap tree
r10891 // var new_buttons = item.find('a'); // shutdown_button;
item.find(".item_buttons").html("").append(shutdown_button);
Matthias BUSSONNIER
proof of concept
r6842 };
Brian E. Granger
File upload/import working from notebook browser.
r4491 NotebookList.prototype.add_delete_button = function (item) {
MinRK
bootstrap tree
r10891 var new_buttons = $('<span/>').addClass("btn-group pull-right");
Matthias BUSSONNIER
fix notebook deletion....
r9787 var notebooklist = this;
MinRK
don't color delete buton
r10936 var delete_button = $("<button/>").text("Delete").addClass("btn btn-mini").
Brian E. Granger
File upload/import working from notebook browser.
r4491 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');
MinRK
bootstrapify delete dialog
r10921 var message = 'Are you sure you want to permanently delete the notebook: ' + nbname + '?';
IPython.dialog.modal({
title : "Delete notebook",
body : message,
Brian E. Granger
File upload/import working from notebook browser.
r4491 buttons : {
MinRK
bootstrapify delete dialog
r10921 Delete : {
class: "btn-danger",
click: function() {
var settings = {
processData : false,
cache : false,
type : "DELETE",
dataType : "json",
success : function (data, status, xhr) {
parent_item.remove();
}
};
MinRK
add utils.url_path_join...
r13063 var url = utils.url_path_join(
notebooklist.baseProjectUrl(),
'api/notebooks',
notebooklist.notebookPath(),
nbname + '.ipynb'
);
MinRK
bootstrapify delete dialog
r10921 $.ajax(url, settings);
}
Brian E. Granger
File upload/import working from notebook browser.
r4491 },
MinRK
bootstrapify delete dialog
r10921 Cancel : {}
Brian E. Granger
File upload/import working from notebook browser.
r4491 }
});
MinRK
bootstrap tree
r10891 return false;
Brian E. Granger
File upload/import working from notebook browser.
r4491 });
MinRK
bootstrap tree
r10891 item.find(".item_buttons").html("").append(delete_button);
Brian E. Granger
File upload/import working from notebook browser.
r4491 };
NotebookList.prototype.add_upload_button = function (item) {
var that = this;
MinRK
tree style tweaks
r10896 var upload_button = $('<button/>').text("Upload")
.addClass('btn btn-primary btn-mini upload_button')
.click(function (e) {
MinRK
update upload and copy...
r13074 var nbname = item.find('.item_name > input').val();
Brian E. Granger
File upload/import working from notebook browser.
r4491 var nbdata = item.data('nbdata');
MinRK
fix dashboard upload
r13072 var content_type = 'application/json';
var model = {
content : JSON.parse(nbdata),
};
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',
MinRK
fix dashboard upload
r13072 data : JSON.stringify(model),
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);
MinRK
fix dashboard upload
r13072 },
error : function (data, status, xhr) {
console.log(data, status);
Brian E. Granger
File upload/import working from notebook browser.
r4491 }
};
MinRK
add utils.url_path_join...
r13063 var url = utils.url_path_join(
that.baseProjectUrl(),
MinRK
fix dashboard upload
r13072 'api/notebooks',
MinRK
update upload and copy...
r13074 that.notebookPath(),
nbname + '.ipynb'
MinRK
add utils.url_path_join...
r13063 );
Brian E. Granger
Updating JS URL scheme to use embedded data....
r5106 $.ajax(url, settings);
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")
.addClass("btn btn-mini")
.click(function (e) {
console.log('cancel click');
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 };
Zachary Sailer
Change new/copy URLS to POST requests
r13017 NotebookList.prototype.new_notebook = function(){
var path = this.notebookPath();
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 var base_project_url = this.baseProjectUrl();
Zachary Sailer
Change new/copy URLS to POST requests
r13017 var settings = {
processData : false,
cache : false,
type : "POST",
dataType : "json",
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 async : false,
success : function (data, status, xhr) {
MinRK
add utils.url_path_join...
r13063 var notebook_name = data.name;
window.open(
utils.url_path_join(
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 base_project_url,
MinRK
add utils.url_path_join...
r13063 'notebooks',
MinRK
mixup notebook_list
r13069 path,
MinRK
add utils.url_path_join...
r13063 notebook_name),
'_blank'
);
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 }
Zachary Sailer
Change new/copy URLS to POST requests
r13017 };
MinRK
add utils.url_path_join...
r13063 var url = utils.url_path_join(
MinRK
use `async : false` to avoid pop-up blocker on New / Copy notebook
r13075 base_project_url,
MinRK
add utils.url_path_join...
r13063 'api/notebooks',
path
);
$.ajax(url, settings);
Zachary Sailer
Change new/copy URLS to POST requests
r13017 };
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 IPython.NotebookList = NotebookList;
return IPython;
}(IPython));