Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiocontents-nbextension
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastian
jiocontents-nbextension
Commits
9048229a
Commit
9048229a
authored
Nov 24, 2017
by
Sebastian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add: remaining functionality, updated title/reference handling
parent
3a3978b5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
117 deletions
+60
-117
gadget_jiocontents.js
gadget_jiocontents.js
+35
-12
jiocontents.js
jiocontents.js
+25
-105
No files found.
gadget_jiocontents.js
View file @
9048229a
...
@@ -40,15 +40,18 @@
...
@@ -40,15 +40,18 @@
});
});
}
}
function
toNotebookModel
(
id
,
obj
,
keepContent
)
{
function
toNotebookModel
(
id
,
obj
,
isRootDir
)
{
//console.log(obj.value.text_content);
//console.log(obj.value.text_content);
var
cont
=
null
;
var
cont
=
null
;
if
(
keepContent
)
{
var
title
=
obj
.
title
;
if
(
isRootDir
)
{
title
+=
"
[ref:
"
+
obj
.
reference
+
"
]
"
;
}
else
{
cont
=
JSON
.
parse
(
obj
.
text_content
);
cont
=
JSON
.
parse
(
obj
.
text_content
);
transform_notebook
(
cont
,
unsplit_lines
);
transform_notebook
(
cont
,
unsplit_lines
);
cont
.
metadata
=
cont
.
metadata
||
{};
cont
.
metadata
=
cont
.
metadata
||
{};
}
}
var
nbobj
=
{
"
name
"
:
obj
.
title
,
var
nbobj
=
{
"
name
"
:
title
,
"
path
"
:
id
,
"
path
"
:
id
,
"
type
"
:
"
notebook
"
,
"
type
"
:
"
notebook
"
,
"
format
"
:
"
json
"
,
"
format
"
:
"
json
"
,
...
@@ -81,7 +84,7 @@
...
@@ -81,7 +84,7 @@
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
var
nbs
=
[];
var
nbs
=
[];
for
(
var
i
=
0
;
i
<
result
.
data
.
rows
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
result
.
data
.
rows
.
length
;
i
++
)
{
nbs
.
push
(
toNotebookModel
(
result
.
data
.
rows
[
i
].
id
,
result
.
data
.
rows
[
i
].
value
,
fals
e
));
nbs
.
push
(
toNotebookModel
(
result
.
data
.
rows
[
i
].
id
,
result
.
data
.
rows
[
i
].
value
,
tru
e
));
}
}
var
root_dir
=
{
"
name
"
:
""
,
var
root_dir
=
{
"
name
"
:
""
,
"
path
"
:
""
,
"
path
"
:
""
,
...
@@ -95,7 +98,7 @@
...
@@ -95,7 +98,7 @@
// Get the notebook file
// Get the notebook file
this
.
jio_get
(
e
.
detail
.
path
)
this
.
jio_get
(
e
.
detail
.
path
)
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
e
.
detail
.
resolve
(
toNotebookModel
(
e
.
detail
.
path
,
result
,
tru
e
));
e
.
detail
.
resolve
(
toNotebookModel
(
e
.
detail
.
path
,
result
,
fals
e
));
},
function
(
err
)
{
},
function
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
e
.
detail
.
reject
(
err
);
e
.
detail
.
reject
(
err
);
...
@@ -114,7 +117,7 @@
...
@@ -114,7 +117,7 @@
})
})
.
push
(
function
(
result_put
)
{
.
push
(
function
(
result_put
)
{
console
.
log
(
"
Notebook saved in ERP5
"
,
result_put
);
console
.
log
(
"
Notebook saved in ERP5
"
,
result_put
);
e
.
detail
.
resolve
(
toNotebookModel
(
e
.
detail
.
path
,
result
,
tru
e
));
e
.
detail
.
resolve
(
toNotebookModel
(
e
.
detail
.
path
,
result
,
fals
e
));
},
function
(
err
)
{
},
function
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
e
.
detail
.
reject
(
err
);
e
.
detail
.
reject
(
err
);
...
@@ -126,12 +129,12 @@
...
@@ -126,12 +129,12 @@
}
}
function
handleCreate
(
e
)
{
function
handleCreate
(
e
)
{
var
now
=
new
Date
()
.
toUTCString
()
;
var
now
=
new
Date
();
var
jioObj
=
{
var
jioObj
=
{
portal_type
:
"
Web JSON
"
,
portal_type
:
"
Web JSON
"
,
parent_relative_url
:
"
web_page_module
"
,
parent_relative_url
:
"
web_page_module
"
,
title
:
"
untitled_notebook
.ipynb
"
,
title
:
"
untitled_notebook
"
,
reference
:
"
u
ntitled notebook from
"
+
now
,
reference
:
"
u
t_nb_from_
"
+
now
.
getTime
()
,
text_content
:
JSON
.
stringify
(
createBlankNotebook
())
text_content
:
JSON
.
stringify
(
createBlankNotebook
())
};
};
var
gadget
=
this
;
var
gadget
=
this
;
...
@@ -139,11 +142,30 @@
...
@@ -139,11 +142,30 @@
.
push
(
function
(
newId
)
{
.
push
(
function
(
newId
)
{
gadget
.
jio_get
(
newId
)
gadget
.
jio_get
(
newId
)
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
e
.
detail
.
resolve
(
toNotebookModel
(
newId
,
result
,
true
));
e
.
detail
.
resolve
(
toNotebookModel
(
newId
,
result
,
false
));
},
function
(
err
)
{
console
.
log
(
err
);
e
.
detail
.
reject
(
err
);
});
},
function
(
err
)
{
},
function
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
e
.
detail
.
reject
(
err
);
e
.
detail
.
reject
(
err
);
});
});
}
function
handleRename
(
e
)
{
var
gadget
=
this
;
gadget
.
jio_put
(
e
.
detail
.
path
,
{
title
:
e
.
detail
.
new_title
,
})
.
push
(
function
(
id
)
{
gadget
.
jio_get
(
id
)
.
push
(
function
(
result
)
{
e
.
detail
.
resolve
(
toNotebookModel
(
id
,
result
,
false
));
},
function
(
err
)
{
console
.
log
(
err
);
e
.
detail
.
reject
(
err
);
})
},
function
(
err
)
{
},
function
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
e
.
detail
.
reject
(
err
);
e
.
detail
.
reject
(
err
);
...
@@ -168,13 +190,14 @@
...
@@ -168,13 +190,14 @@
.
onEvent
(
"
get_event
"
,
handleGet
,
false
,
true
)
.
onEvent
(
"
get_event
"
,
handleGet
,
false
,
true
)
.
onEvent
(
"
save_event
"
,
handleSave
,
false
,
true
)
.
onEvent
(
"
save_event
"
,
handleSave
,
false
,
true
)
.
onEvent
(
"
create_event
"
,
handleCreate
,
false
,
true
)
.
onEvent
(
"
create_event
"
,
handleCreate
,
false
,
true
)
.
onEvent
(
"
rename_event
"
,
handleRename
,
false
,
true
)
.
declareMethod
(
'
render
'
,
function
()
{
.
declareMethod
(
'
render
'
,
function
()
{
console
.
log
(
"
Rendering!
"
);
console
.
log
(
"
Rendering!
"
);
document
.
jiocontentsReady
=
true
;
document
.
jiocontentsReady
=
true
;
return
this
;
return
this
;
});
});
function
createBlankNotebook
()
{
function
createBlankNotebook
(
kernel_type
)
{
return
{
return
{
"
cells
"
:
[
"
cells
"
:
[
{
"
cell_type
"
:
"
code
"
,
{
"
cell_type
"
:
"
code
"
,
...
...
jiocontents.js
View file @
9048229a
...
@@ -88,10 +88,6 @@ define(function(require) {
...
@@ -88,10 +88,6 @@ define(function(require) {
Contents
.
DIRECTORY_NOT_EMPTY_ERROR
=
'
DirectoryNotEmptyError
'
;
Contents
.
DIRECTORY_NOT_EMPTY_ERROR
=
'
DirectoryNotEmptyError
'
;
Contents
.
DirectoryNotEmptyError
=
function
()
{
Contents
.
DirectoryNotEmptyError
=
function
()
{
// Constructor
//
// An error representing the result of attempting to delete a
// non-empty directory.
this
.
message
=
'
A directory must be empty before being deleted.
'
;
this
.
message
=
'
A directory must be empty before being deleted.
'
;
};
};
...
@@ -100,7 +96,6 @@ define(function(require) {
...
@@ -100,7 +96,6 @@ define(function(require) {
Contents
.
DirectoryNotEmptyError
.
prototype
.
name
=
Contents
.
DirectoryNotEmptyError
.
prototype
.
name
=
Contents
.
DIRECTORY_NOT_EMPTY_ERROR
;
Contents
.
DIRECTORY_NOT_EMPTY_ERROR
;
Contents
.
prototype
.
api_url
=
function
()
{
Contents
.
prototype
.
api_url
=
function
()
{
var
url_parts
=
[
var
url_parts
=
[
this
.
base_url
,
'
api/contents
'
,
this
.
base_url
,
'
api/contents
'
,
...
@@ -109,17 +104,6 @@ define(function(require) {
...
@@ -109,17 +104,6 @@ define(function(require) {
return
utils
.
url_path_join
.
apply
(
null
,
url_parts
);
return
utils
.
url_path_join
.
apply
(
null
,
url_parts
);
};
};
/**
* Creates a basic error handler that wraps a jqXHR error as an Error.
*
* Takes a callback that accepts an Error, and returns a callback that can
* be passed directly to $.ajax, which will wrap the error from jQuery
* as an Error, and pass that to the original callback.
*
* @method create_basic_error_handler
* @param{Function} callback
* @return{Function}
*/
Contents
.
prototype
.
create_basic_error_handler
=
function
(
callback
)
{
Contents
.
prototype
.
create_basic_error_handler
=
function
(
callback
)
{
if
(
!
callback
)
{
if
(
!
callback
)
{
return
utils
.
log_ajax_error
;
return
utils
.
log_ajax_error
;
...
@@ -133,16 +117,6 @@ define(function(require) {
...
@@ -133,16 +117,6 @@ define(function(require) {
* File Functions (including notebook operations)
* File Functions (including notebook operations)
*/
*/
/**
* Get a file.
*
* @method get
* @param {String} path
* @param {Object} options
* type : 'notebook', 'file', or 'directory'
* format: 'text' or 'base64'; only relevant for type: 'file'
* content: true or false; // whether to include the content
*/
Contents
.
prototype
.
get
=
function
(
path
,
options
)
{
Contents
.
prototype
.
get
=
function
(
path
,
options
)
{
return
waitForReadyPromise
()
return
waitForReadyPromise
()
.
then
(
function
()
{
.
then
(
function
()
{
...
@@ -159,22 +133,10 @@ define(function(require) {
...
@@ -159,22 +133,10 @@ define(function(require) {
});
});
};
};
/**
* Creates a new untitled file or directory in the specified directory
* path.
*
* @method new
* @param {String} path: the directory in which to create the new
* file/directory
* @param {Object} options:
* ext: file extension to use
* type: model type to create ('notebook', 'file', or 'directory')
*/
Contents
.
prototype
.
new_untitled
=
function
(
path
,
options
)
{
Contents
.
prototype
.
new_untitled
=
function
(
path
,
options
)
{
if
(
options
.
type
!==
"
notebook
"
)
{
if
(
options
.
type
!==
"
notebook
"
)
{
console
.
log
(
"
Creation of non-notebooks is not supported!
"
);
console
.
log
(
"
Creation of non-notebooks is not supported!
"
);
return
Promise
.
reject
();
return
Promise
.
reject
(
"
Creation of non-notebooks is not supported!
"
);
}
}
return
waitForReadyPromise
()
return
waitForReadyPromise
()
.
then
(
function
()
{
.
then
(
function
()
{
...
@@ -192,36 +154,25 @@ define(function(require) {
...
@@ -192,36 +154,25 @@ define(function(require) {
};
};
Contents
.
prototype
.
delete
=
function
(
path
)
{
Contents
.
prototype
.
delete
=
function
(
path
)
{
var
settings
=
{
return
Promise
.
reject
(
"
Delete is currently not supported!
"
);
processData
:
false
,
type
:
"
DELETE
"
,
dataType
:
"
json
"
,
};
var
url
=
this
.
api_url
(
path
);
return
utils
.
promising_ajax
(
url
,
settings
).
catch
(
// Translate certain errors to more specific ones.
function
(
error
)
{
// TODO: update IPEP27 to specify errors more precisely, so
// that error types can be detected here with certainty.
if
(
error
.
xhr
.
status
===
400
)
{
throw
new
Contents
.
DirectoryNotEmptyError
();
}
throw
error
;
}
);
};
};
Contents
.
prototype
.
rename
=
function
(
path
,
new_path
)
{
Contents
.
prototype
.
rename
=
function
(
path
,
new_path
)
{
var
data
=
{
path
:
new_path
};
return
waitForReadyPromise
()
var
settings
=
{
.
then
(
function
()
{
processData
:
false
,
return
new
Promise
(
function
(
resolve
,
reject
)
{
type
:
"
PATCH
"
,
var
ev
=
new
CustomEvent
(
"
rename_event
"
,
{
data
:
JSON
.
stringify
(
data
),
detail
:
{
dataType
:
"
json
"
,
path
:
path
,
contentType
:
'
application/json
'
,
// get rid of path-prefix web_page_module. Not used in titles!
};
new_title
:
new_path
.
split
(
"
/
"
)[
1
],
var
url
=
this
.
api_url
(
path
);
resolve
:
resolve
,
return
utils
.
promising_ajax
(
url
,
settings
);
reject
:
reject
}
});
getJiocontentsDiv
().
dispatchEvent
(
ev
);
});
});
};
};
Contents
.
prototype
.
save
=
function
(
path
,
model
)
{
Contents
.
prototype
.
save
=
function
(
path
,
model
)
{
...
@@ -242,20 +193,7 @@ define(function(require) {
...
@@ -242,20 +193,7 @@ define(function(require) {
};
};
Contents
.
prototype
.
copy
=
function
(
from_file
,
to_dir
)
{
Contents
.
prototype
.
copy
=
function
(
from_file
,
to_dir
)
{
/**
return
Promise
.
reject
(
"
Copy is currently not supported!
"
);
* Copy a file into a given directory via POST
* The server will select the name of the copied file
*/
var
url
=
this
.
api_url
(
to_dir
);
var
settings
=
{
processData
:
false
,
type
:
"
POST
"
,
data
:
JSON
.
stringify
({
copy_from
:
from_file
}),
contentType
:
'
application/json
'
,
dataType
:
"
json
"
,
};
return
utils
.
promising_ajax
(
url
,
settings
);
};
};
/**
/**
...
@@ -263,40 +201,22 @@ define(function(require) {
...
@@ -263,40 +201,22 @@ define(function(require) {
*/
*/
Contents
.
prototype
.
create_checkpoint
=
function
(
path
)
{
Contents
.
prototype
.
create_checkpoint
=
function
(
path
)
{
var
url
=
this
.
api_url
(
path
,
'
checkpoints
'
);
return
Promise
.
resolve
({
var
settings
=
{
id
:
"
dummy-id
"
,
type
:
"
POST
"
,
last_modified
:
"
2013-10-18T23:54:40+00:00
"
//dummy
contentType
:
false
,
// no data
});
dataType
:
"
json
"
,
};
return
utils
.
promising_ajax
(
url
,
settings
);
};
};
Contents
.
prototype
.
list_checkpoints
=
function
(
path
)
{
Contents
.
prototype
.
list_checkpoints
=
function
(
path
)
{
var
url
=
this
.
api_url
(
path
,
'
checkpoints
'
);
return
Promise
.
resolve
([]);
var
settings
=
{
type
:
"
GET
"
,
cache
:
false
,
dataType
:
"
json
"
,
};
return
utils
.
promising_ajax
(
url
,
settings
);
};
};
Contents
.
prototype
.
restore_checkpoint
=
function
(
path
,
checkpoint_id
)
{
Contents
.
prototype
.
restore_checkpoint
=
function
(
path
,
checkpoint_id
)
{
var
url
=
this
.
api_url
(
path
,
'
checkpoints
'
,
checkpoint_id
);
return
Promise
.
resolve
();
var
settings
=
{
type
:
"
POST
"
,
contentType
:
false
,
// no data
};
return
utils
.
promising_ajax
(
url
,
settings
);
};
};
Contents
.
prototype
.
delete_checkpoint
=
function
(
path
,
checkpoint_id
)
{
Contents
.
prototype
.
delete_checkpoint
=
function
(
path
,
checkpoint_id
)
{
var
url
=
this
.
api_url
(
path
,
'
checkpoints
'
,
checkpoint_id
);
return
Promise
.
resolve
();
var
settings
=
{
type
:
"
DELETE
"
,
};
return
utils
.
promising_ajax
(
url
,
settings
);
};
};
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment