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
af0452bc
Commit
af0452bc
authored
Nov 23, 2017
by
Sebastian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add: save functionality and slight modifications to get
parent
b8b3a8ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
27 deletions
+72
-27
gadget_jiocontents.js
gadget_jiocontents.js
+56
-13
jiocontents.js
jiocontents.js
+16
-14
No files found.
gadget_jiocontents.js
View file @
af0452bc
...
...
@@ -7,8 +7,9 @@
/*
Next two functions deal with a weird issue of unlin-ed strings, ie. list
of strings instead a single joined string.
See
of strings instead a single joined string.
Adpoted from
https://github.com/jupyter/jupyter-drive/blob/master/jupyterdrive/gdrive/notebook_model.js#L45
with adjustment to match updates in jupyter's data model.
*/
function
unsplit_lines
(
multiline_string
)
{
if
(
Array
.
isArray
(
multiline_string
))
{
...
...
@@ -29,7 +30,10 @@
if
(
cell
[
'
outputs
'
])
{
cell
[
'
outputs
'
].
forEach
(
function
(
output
)
{
if
(
output
[
'
data
'
])
{
output
[
'
data
'
]
=
transform_fn
(
output
[
'
data
'
]);
for
(
var
key
in
output
[
'
data
'
])
{
var
t
=
transform_fn
(
output
[
'
data
'
][
key
]);
output
[
'
data
'
][
key
]
=
t
;
}
}
});
}
...
...
@@ -51,18 +55,28 @@
"
writable
"
:
true
,
"
mimetype
"
:
"
application/ipynb
"
,
"
content
"
:
cont
,
//"content": keepContent ? obj.text_content : null
// TODO: Fix date representation. Might cause problems!
"
created
"
:
obj
.
creation_date
,
"
last_modified
"
:
obj
.
modification_date
,
};
return
nbobj
;
}
/*
*
* Event handlers API <-> JIO connection points
*
*/
function
handle
Even
t
(
e
)
{
function
handle
Ge
t
(
e
)
{
if
(
e
.
detail
.
path
===
""
)
{
// We a querying for the root directory. Should return a list of contents which themselves have no
// content
this
.
jio_allDocs
({
query
:
'
portal_type: "Web JSON"
'
,
select_list
:
[
'
text_content
'
,
'
title
'
,
'
reference
'
],
//, 'modification_date'], NOT WORKING
// sort_on: [["modification_date", "descending"]], // NOT WORKING
limit
:
[
0
,
5
]
select_list
:
[
"
text_content
"
,
"
title
"
,
"
reference
"
,
"
creation_date
"
,
"
modification_date
"
],
sort_on
:
[[
"
modification_date
"
,
"
descending
"
]],
limit
:
[
0
,
20
]
})
.
push
(
function
(
result
)
{
var
nbs
=
[];
...
...
@@ -71,24 +85,51 @@
}
var
root_dir
=
{
"
name
"
:
""
,
"
path
"
:
""
,
"
last_modified
"
:
"
2017-09-06T03:33:29.781159Z
"
,
"
created
"
:
"
2017-09-06T03:33:29.781159Z
"
,
"
content
"
:
nbs
,
};
"
content
"
:
nbs
};
e
.
detail
.
resolve
(
root_dir
);
},
function
(
err
)
{
e
.
detail
.
reject
();
console
.
log
(
err
);
e
.
detail
.
reject
(
err
);
});
}
else
{
// Get the notebook file
this
.
jio_get
(
e
.
detail
.
path
)
.
push
(
function
(
result
)
{
e
.
detail
.
resolve
(
toNotebookModel
(
e
.
detail
.
path
,
result
,
true
));
},
function
(
err
)
{
console
.
log
(
err
);
e
.
detail
.
reject
(
err
);
});
}
}
function
handleSave
(
e
)
{
var
gadget
=
this
;
gadget
.
jio_get
(
e
.
detail
.
path
)
.
push
(
function
(
result
)
{
gadget
.
jio_put
(
e
.
detail
.
path
,
{
title
:
result
.
title
,
reference
:
result
.
reference
,
text_content
:
e
.
detail
.
model
})
.
push
(
function
(
result_put
)
{
console
.
log
(
"
Notebook saved in ERP5
"
,
result_put
);
e
.
detail
.
resolve
(
toNotebookModel
(
e
.
detail
.
path
,
result
,
true
));
},
function
(
err
)
{
console
.
log
(
err
);
e
.
detail
.
reject
(
err
);
});
},
function
(
err
)
{
console
.
log
(
err
);
e
.
detail
.
reject
(
err
);
});
}
/*
*
* RJS Stuffs
*
*/
rJS
(
window
)
.
ready
(
function
(
gadget
)
{
...
...
@@ -97,7 +138,9 @@
})
.
declareAcquiredMethod
(
"
jio_allDocs
"
,
"
jio_allDocs
"
)
.
declareAcquiredMethod
(
"
jio_get
"
,
"
jio_get
"
)
.
onEvent
(
"
custom_event
"
,
handleEvent
,
false
,
true
)
.
declareAcquiredMethod
(
"
jio_put
"
,
"
jio_put
"
)
.
onEvent
(
"
get_event
"
,
handleGet
,
false
,
true
)
.
onEvent
(
"
save_event
"
,
handleSave
,
false
,
true
)
.
declareMethod
(
'
render
'
,
function
()
{
console
.
log
(
"
Rendering!
"
);
document
.
jiocontentsReady
=
true
;
...
...
jiocontents.js
View file @
af0452bc
...
...
@@ -147,7 +147,7 @@ define(function(require) {
return
waitForReadyPromise
()
.
then
(
function
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
ev
=
new
CustomEvent
(
"
custom
_event
"
,
{
var
ev
=
new
CustomEvent
(
"
get
_event
"
,
{
detail
:
{
path
:
path
,
resolve
:
resolve
,
...
...
@@ -217,20 +217,22 @@ define(function(require) {
};
Contents
.
prototype
.
save
=
function
(
path
,
model
)
{
/**
* We do the call with settings so we can set cache to false.
*/
var
settings
=
{
processData
:
false
,
type
:
"
PUT
"
,
dataType
:
"
json
"
,
data
:
JSON
.
stringify
(
model
),
contentType
:
'
application/json
'
,
};
var
url
=
this
.
api_url
(
path
);
return
utils
.
promising_ajax
(
url
,
settings
);
return
waitForReadyPromise
()
.
then
(
function
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
ev
=
new
CustomEvent
(
"
save_event
"
,
{
detail
:
{
path
:
path
,
model
:
JSON
.
stringify
(
model
.
content
),
resolve
:
resolve
,
reject
:
reject
}
});
getJiocontentsDiv
().
dispatchEvent
(
ev
);
});
});
};
Contents
.
prototype
.
copy
=
function
(
from_file
,
to_dir
)
{
/**
* Copy a file into a given directory via POST
...
...
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