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
0b776b6b
Commit
0b776b6b
authored
Nov 20, 2017
by
Sebastian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add: Getting list from ERP5, getting notebook JSON loaded into page (buggy)
parent
3231315b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
42 deletions
+86
-42
gadget_jiocontents.js
gadget_jiocontents.js
+83
-39
gadget_jupyter_page.js
gadget_jupyter_page.js
+1
-1
jiocontents.js
jiocontents.js
+2
-2
No files found.
gadget_jiocontents.js
View file @
0b776b6b
...
...
@@ -5,22 +5,59 @@
(
function
(
window
,
rJS
)
{
"
use strict
"
;
function
toNotebookModel
(
obj
)
{
console
.
log
(
obj
);
return
{
"
name
"
:
obj
.
value
.
title
,
// TODO: THIS PATH TO NOTEBOOK FILE
"
path
"
:
"
foo/bar/notebook1.ipynb
"
,
//"path": "/localhost/Test-Notebook.ipynb",
/*
Next two functions deal with a weird issue of unlin-ed strings, ie. list
of strings instead a single joined string. See
https://github.com/jupyter/jupyter-drive/blob/master/jupyterdrive/gdrive/notebook_model.js#L45
*/
function
unsplit_lines
(
multiline_string
)
{
if
(
Array
.
isArray
(
multiline_string
))
{
return
multiline_string
.
join
(
''
);
}
else
{
return
multiline_string
;
}
}
function
transform_notebook
(
notebook
,
transform_fn
)
{
if
(
!
notebook
[
'
cells
'
])
{
return
null
;
}
notebook
[
'
cells
'
].
forEach
(
function
(
cell
)
{
if
(
cell
[
'
source
'
])
{
cell
[
'
source
'
]
=
transform_fn
(
cell
[
'
source
'
]);
}
if
(
cell
[
'
outputs
'
])
{
cell
[
'
outputs
'
].
forEach
(
function
(
output
)
{
if
(
output
[
'
data
'
])
{
output
[
'
data
'
]
=
transform_fn
(
output
[
'
data
'
]);
}
});
}
});
}
function
toNotebookModel
(
id
,
obj
,
keepContent
)
{
//console.log(obj.value.text_content);
var
cont
=
null
;
if
(
keepContent
)
{
cont
=
JSON
.
parse
(
obj
.
text_content
);
transform_notebook
(
cont
,
unsplit_lines
);
cont
.
metadata
=
cont
.
metadata
||
{};
}
var
nbobj
=
{
"
name
"
:
obj
.
title
,
"
path
"
:
id
,
"
type
"
:
"
notebook
"
,
"
format
"
:
"
json
"
,
"
writable
"
:
true
,
"
last_modified
"
:
"
2013-10-02T11:29:27.616675+00:00
"
,
"
created
"
:
"
2013-10-01T12:21:20.123456+00:00
"
,
"
content
"
:
null
"
mimetype
"
:
"
application/ipynb
"
,
"
content
"
:
cont
,
//"content": keepContent ? obj.text_content
: null
};
return
nbobj
;
}
function
handleEvent
(
e
)
{
if
(
e
.
detail
.
path
===
""
)
{
this
.
jio_allDocs
({
query
:
'
portal_type: "Web JSON"
'
,
select_list
:
[
'
text_content
'
,
'
title
'
,
'
reference
'
],
//, 'modification_date'], NOT WORKING
...
...
@@ -28,11 +65,9 @@
limit
:
[
0
,
5
]
})
.
push
(
function
(
result
)
{
console
.
log
(
"
Querying Web JSON List
"
);
console
.
log
(
result
.
data
.
rows
);
var
nbs
=
[];
for
(
var
i
=
0
;
i
<
result
.
data
.
rows
.
length
;
i
++
)
{
nbs
.
push
(
toNotebookModel
(
result
.
data
.
rows
[
i
]
));
nbs
.
push
(
toNotebookModel
(
result
.
data
.
rows
[
i
].
id
,
result
.
data
.
rows
[
i
].
value
,
false
));
}
var
root_dir
=
{
"
name
"
:
""
,
"
path
"
:
""
,
...
...
@@ -40,25 +75,34 @@
"
created
"
:
"
2017-09-06T03:33:29.781159Z
"
,
"
content
"
:
nbs
,
};
console
.
log
(
root_dir
);
e
.
detail
.
resolve
(
root_dir
);
},
function
(
err
)
{
e
.
detail
.
reject
();
console
.
log
(
err
);
});
}
else
{
this
.
jio_get
(
e
.
detail
.
path
)
.
push
(
function
(
result
)
{
e
.
detail
.
resolve
(
toNotebookModel
(
e
.
detail
.
path
,
result
,
true
));
},
function
(
err
)
{
console
.
log
(
err
);
});
}
}
rJS
(
window
)
.
ready
(
function
(
gadget
)
{
console
.
log
(
"
Jio Contents Gadget yes yes.
"
);
document
.
jiocontentsReady
=
true
;
return
gadget
;
})
.
declareMethod
(
'
render
'
,
function
(
options
)
{
})
.
declareAcquiredMethod
(
"
jio_allDocs
"
,
"
jio_allDocs
"
)
.
onEvent
(
"
custom_event
"
,
handleEvent
,
false
,
true
);
.
declareAcquiredMethod
(
"
jio_get
"
,
"
jio_get
"
)
.
onEvent
(
"
custom_event
"
,
handleEvent
,
false
,
true
)
.
declareMethod
(
'
render
'
,
function
()
{
console
.
log
(
"
Rendering!
"
);
document
.
jiocontentsReady
=
true
;
return
this
;
});
}(
window
,
rJS
));
gadget_jupyter_page.js
View file @
0b776b6b
...
...
@@ -99,7 +99,7 @@
return
gadget
.
getDeclaredGadget
(
"
jiocontents_gadget
"
);
})
.
push
(
function
(
jiocontents_gadget
)
{
jiocontents_gadget
.
render
(
{}
);
jiocontents_gadget
.
render
();
});
})
.
allowPublicAcquisition
(
"
getSetting
"
,
function
(
argument_list
)
{
...
...
jiocontents.js
View file @
0b776b6b
...
...
@@ -8,7 +8,7 @@ define(function(require) {
var
utils
=
require
(
'
base/js/utils
'
);
var
baseUrl
=
"
nbextensions/jiocontents
"
;
var
baseUrl
=
"
/
nbextensions/jiocontents
"
;
var
gadget_main_div
=
document
.
createElement
(
"
div
"
);
gadget_main_div
.
setAttribute
(
"
data-gadget-url
"
,
baseUrl
+
"
/gadget_jupyter_page.html
"
);
...
...
@@ -42,7 +42,7 @@ define(function(require) {
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
timerId
=
window
.
setInterval
(
function
()
{
if
(
document
.
jiocontentsReady
)
{
window
.
setTimeout
(
function
()
{
resolve
();
},
200
);
// to allow for aquiredmethod to load
resolve
();
clearInterval
(
timerId
);
}
},
100
);
// Check every 100ms to see if rjs-setup is complete and eventlistener available
...
...
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