Skip to content

Commit dbfeccc

Browse files
committed
add load_data function
1 parent b55c733 commit dbfeccc

4 files changed

Lines changed: 110 additions & 53 deletions

File tree

notebookjs/src/public/javascripts/index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ $(document).on("click", "button.add-text", function () {
324324
add_new_text_cell(this.id, where)
325325
})
326326

327-
// $(document).on("dblclick", "textarea.text-box", function () {
328-
// let id = this.id.split("_")[1]
329-
// show_md(id, this.value)
327+
$(document).on("dblclick", "textarea.text-box", function () {
328+
let id = this.id.split("_")[1]
329+
show_md(id, this.value)
330330

331-
// })
331+
})
332332

333333
function show_md(id, value) {
334334
div_id = `text-div_${id}`
@@ -395,3 +395,17 @@ $("#uploadnb").click(function() {
395395
reader.readAsText(content);
396396
}
397397
})
398+
399+
400+
401+
async function load_data(path) {
402+
document.getElementById("cell-running").style.display = "block"
403+
let df = await dfd.read_csv(path)
404+
document.getElementById("cell-running").style.display = "none"
405+
return df
406+
407+
}
408+
409+
410+
411+

notebookjs/src/public/javascripts/utils.js

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -144,27 +144,27 @@ function table(df) {
144144

145145
}
146146

147-
function notebook_json(scope,md_scope){
147+
function notebook_json(scope, md_scope) {
148148

149149
var store = {}
150150

151151
for (let key in scope) {
152152

153153
let key_split = key.split("-")
154154
let id = key_split[1]
155-
155+
156156
let type = key_split[0].split("_")[1]
157157

158-
if(type == "text"){
158+
if (type == "text") {
159159

160160
let md_out = md_scope[`text-div_${Number(id)}`]
161161
let text_output = $(`#cell-${id}`).html()
162162
store[`cell-${id}`] = {
163163
"out": text_output,
164-
"md" : md_out
164+
"md": md_out
165165
}
166166
}
167-
else{
167+
else {
168168
let cell_content = scope[key].getValue()
169169

170170
let cell_output = $(`#out_${key}`).html()
@@ -174,7 +174,7 @@ function notebook_json(scope,md_scope){
174174
"out": cell_output
175175
}
176176
}
177-
177+
178178
}
179179

180180
store = JSON.stringify(store);
@@ -204,14 +204,14 @@ function LoadPackage(array, callback) {
204204
})();
205205
}
206206

207-
function md_load(id){
207+
function md_load(id) {
208208

209209
let md = `<div class="row" style="margin-top: 10px;" id="cell-${id}"></div>`
210210

211211
return md;
212212
}
213213

214-
function html_load(new_id){
214+
function html_load(new_id) {
215215

216216
let html = `
217217
<div class="row" style="margin-top: 10px;" id="cell-${new_id}">
@@ -257,17 +257,17 @@ function html_load(new_id){
257257
<div class="col-md-2"></div>
258258
</div>
259259
`
260-
return html;
260+
return html;
261261
}
262262

263-
function load_notebook(json){
263+
function load_notebook(json) {
264+
265+
266+
for (let key in json) {
264267

265-
266-
for(let key in json){
267-
268268
let id = key.split("-")[1]
269269

270-
if(Object.prototype.hasOwnProperty.call(json[key], "in")){
270+
if (Object.prototype.hasOwnProperty.call(json[key], "in")) {
271271
let html = html_load(id)
272272

273273
$(".content").append(html)
@@ -289,44 +289,43 @@ function load_notebook(json){
289289
$(`#out_div-${id}`).html(out);
290290

291291
$(`#div-${id}`)
292-
.mouseover(function () {
293-
$(`#btn-actions-${id}`).show()
294-
})
295-
.mouseout(function () {
296-
$(`#btn-actions-${id}`).hide()
297-
});
292+
.mouseover(function () {
293+
$(`#btn-actions-${id}`).show()
294+
})
295+
.mouseout(function () {
296+
$(`#btn-actions-${id}`).hide()
297+
});
298298

299-
}else{
299+
} else {
300300

301-
let md = md_load(id)
301+
let md = md_load(id)
302302

303-
$(".content").append(md);
303+
$(".content").append(md);
304304

305-
let out = json[key]["out"]
306-
$(`#cell-${id}`).html(out)
305+
let out = json[key]["out"]
306+
$(`#cell-${id}`).html(out)
307307

308-
let md_out = json[key]["md"]
309-
// console.log(md_out)
310-
md_texts[`text-div_${Number(id)}`] = md_out;
308+
let md_out = json[key]["md"]
309+
// console.log(md_out)
310+
md_texts[`text-div_${Number(id)}`] = md_out;
311311

312-
vars_in_scope[`div_text-${id}`] = ""
312+
vars_in_scope[`div_text-${id}`] = ""
313313

314-
$(`textarea#text-box_${id}`).addClass("text-box")
315-
$(`textarea#text-box_${id}`).val(md_out)
316-
// update_text_box_size()
314+
$(`textarea#text-box_${id}`).addClass("text-box")
315+
$(`textarea#text-box_${id}`).val(md_out)
316+
// update_text_box_size()
317317

318-
$(`#text-div_${id}`)
319-
.mouseover(function () {
320-
document.getElementById(`btn-actions-${id}`).style.display = "block"
321-
})
322-
.mouseout(function () {
323-
document.getElementById(`btn-actions-${id}`).style.display = "none"
324-
});
318+
$(`#text-div_${id}`)
319+
.mouseover(function () {
320+
document.getElementById(`btn-actions-${id}`).style.display = "block"
321+
})
322+
.mouseout(function () {
323+
document.getElementById(`btn-actions-${id}`).style.display = "none"
324+
});
325325
}
326326

327327
__code_cell_count = parseInt(id)
328-
328+
329329
}
330330
}
331331

332-

notebookjs/src/public/stylesheets/style.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,16 @@ a {
4545

4646
}
4747

48+
49+
.inputfileholder {
50+
overflow: hidden;
51+
max-width: 200px;
52+
height: 21px;
53+
position: relative
54+
}
55+
56+
.inputfileholder .inputfile {
57+
position: absolute;
58+
left: -90px;
59+
outline: none;
60+
}

notebookjs/src/views/layout.hbs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,10 @@
7474
aria-haspopup="true" aria-expanded="false">
7575
Options
7676
</a>
77-
Import: <input type="file"
78-
id="import-notebook-file" name="import-notebook-file" style="display: inline;">
79-
<button type="button" class="btn btn-lg btn-primary" id="uploadnb">Import</button>
8077
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
8178
<a class="dropdown-item" id="download" href="#">Download Notebook</a>
82-
<a class="dropdown-item" id="upload" href="#">Upload Notebook</a>
83-
<a class="dropdown-item" id="add-data" href="#">Add Data</a>
79+
<a class="dropdown-item" data-toggle="modal" data-target="#uploadNoteModal" href="#">Upload Notebook</a>
80+
{{!-- <a class="dropdown-item" id="add-data" href="#">Add Data</a> --}}
8481

8582
<div class="dropdown-divider"></div>
8683
<a class="nav-link" href="#">Getting Started</a>
@@ -89,9 +86,12 @@
8986
<a class="dropdown-item" id="add-data" href="#">About Dnotebooks</a>
9087
</div>
9188
</li>
92-
{{!-- <li class="nav-item">
93-
<a class="nav-link" href="#">Getting Started</a>
94-
</li> --}}
89+
90+
<li class="nav-item">
91+
<div id="cell-running" class="spinner-border text-info code_symbol" style="display: none;" role="status">
92+
<span class="sr-only">Loading...</span>
93+
</div>
94+
</li>
9595
{{!-- <li class="nav-item">
9696
<a class="nav-link" href="https://github.com/opensource9ja/notebookjs">Github</a>
9797
</li> --}}
@@ -118,6 +118,37 @@
118118
</div>
119119
</nav>
120120

121+
122+
123+
124+
{{!-- Notebook upload --}}
125+
<div class="modal" id="uploadNoteModal" tabindex="-1">
126+
<div class="modal-dialog">
127+
<div class="modal-content">
128+
<div class="modal-header">
129+
<h5 class="modal-title">Upload a Notebook</h5>
130+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
131+
<span aria-hidden="true">&times;</span>
132+
</button>
133+
</div>
134+
<div class="modal-body">
135+
136+
{{!-- Import: <input type="file" id="import-notebook-file" name="import-notebook-file" style="display: inline;"> --}}
137+
<form>
138+
<div class="form-group">
139+
<label for="exampleFormControlFile1">Select a Notebook File</label>
140+
<input type="file" class="form-control-file" id="import-notebook-file" name="import-notebook-file">
141+
</div>
142+
</form>
143+
</div>
144+
<div class="modal-footer">
145+
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
146+
<button type="button" class="btn btn-primary" id="uploadnb">Import</button>
147+
</div>
148+
</div>
149+
</div>
150+
</div>
151+
121152
{{{body}}}
122153

123154

0 commit comments

Comments
 (0)