Moves list_notebooks to ContentManager

This commit is contained in:
KesterTong 2014-07-25 01:04:30 -04:00 committed by Thomas Kluyver
parent dfcf14f26c
commit e3ef5d3b70
2 changed files with 76 additions and 29 deletions

View File

@ -24,6 +24,10 @@ define([
this.base_url = options.base_url;
};
/**
* Notebook Functions
*/
/**
* Creates a new notebook file at the specified path, and
* opens that notebook in a new window.
@ -165,6 +169,10 @@ define([
$.ajax(url, settings);
};
/**
* Checkpointing Functions
*/
ContentManager.prototype.save_checkpoint = function() {
// This is not necessary - integrated into save
};
@ -203,6 +211,44 @@ define([
);
};
/**
* File management functions
*/
/**
* List notebooks and directories at a given path
*
* On success, load_callback is called with an array of dictionaries
* representing individual files or directories. Each dictionary has
* the keys:
* type: "notebook" or "directory"
* name: the name of the file or directory
* created: created date
* last_modified: last modified dat
* path: the path
* @method list_notebooks
* @param {String} path The path to list notebooks in
* @param {Function} load_callback called with list of notebooks on success
* @param {Function} error_callback called with ajax results on error
*/
ContentManager.prototype.list_contents = function(path, load_callback,
error_callback) {
var that = this;
var settings = {
processData : false,
cache : false,
type : "GET",
dataType : "json",
success : load_callback,
error : error_callback
};
var url = utils.url_join_encode(this.base_url, 'api', 'notebooks',
path);
$.ajax(url, settings);
}
IPython.ContentManager = ContentManager;
return {'ContentManager': ContentManager};

View File

@ -156,37 +156,26 @@ define([
};
NotebookList.prototype.load_list = function () {
var that = this;
var settings = {
processData : false,
cache : false,
type : "GET",
dataType : "json",
success : $.proxy(this.list_loaded, this),
error : $.proxy( function(xhr, status, error){
this.content_manager.list_contents(
this.notebook_path,
$.proxy(this.draw_notebook_list, this),
$.proxy( function(xhr, status, error) {
utils.log_ajax_error(xhr, status, error);
that.list_loaded([], null, null, {msg:"Error connecting to server."});
},this)
};
var url = utils.url_join_encode(
this.base_url,
'api',
'contents',
this.notebook_path
that.draw_notebook_list([], "Error connecting to server.");
}, this)
);
$.ajax(url, settings);
};
NotebookList.prototype.list_loaded = function (data, status, xhr, param) {
var message = 'Notebook list empty.';
if (param !== undefined && param.msg) {
message = param.msg;
}
/**
* Draw the list of notebooks
* @method draw_notebook_list
* @param {Array} list An array of dictionaries representing files or
* direcotories.
* @param {String} error_msg An error message
*/
NotebookList.prototype.draw_notebook_list = function (list, error_msg) {
var message = error_msg || 'Notebook list empty.';
var item = null;
var model = null;
var list = data.content;
var len = list.length;
this.clear_list();
var n_uploads = this.element.children('.list_item').length;
@ -209,9 +198,21 @@ define([
offset += 1;
}
for (var i=0; i<len; i++) {
model = list[i];
item = this.new_item(i+offset);
this.add_link(model, item);
if (list[i].type === 'directory') {
var name = list[i].name;
item = this.new_notebook_item(i+offset);
this.add_dir(path, name, item);
} else {
var name = list[i].name;
item = this.new_notebook_item(i+offset);
this.add_link(path, name, item);
name = utils.url_path_join(path, name);
if(this.sessions[name] === undefined){
this.add_delete_button(item);
} else {
this.add_shutdown_button(item,this.sessions[name]);
}
}
}
};