Skip to content

Commit 7db6eca

Browse files
committed
add function to add new package
1 parent c8e32da commit 7db6eca

4 files changed

Lines changed: 49 additions & 29 deletions

File tree

notebookjs/src/public/javascripts/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ function add_new_code_cell(c_id, where) {
9292
<i class="fas fa-sort-up"></i> Text
9393
</button>
9494
</div>
95-
96-
<button type="button" id="del_btn-${new_id}" class="btn btn-sm btn-danger del"><i
95+
<button type="button" id="del-btn_${new_id}" class="btn btn-sm btn-danger del"><i
9796
class="fas fa-trash-alt"></i>
9897
</button>
9998
</div>
@@ -247,7 +246,6 @@ function delete_text_cell(id) {
247246

248247
$(document).on("click", "button.run", function () {
249248
if (this.id.split("_").includes("md")) {
250-
console.log("md");
251249
let id = this.id.split("-")[1]
252250
let val = document.getElementById(`text-box_${id}`).value
253251
show_md(id, val)
@@ -257,10 +255,8 @@ $(document).on("click", "button.run", function () {
257255
})
258256

259257
$(document).on("click", "button.del", function () {
260-
console.log(this.id);
261-
let id = this.id.split("-")[1]
262-
console.log(id);
263-
// delete_cell(id)
258+
let id = this.id.split("_")[1]
259+
delete_cell(id)
264260
})
265261

266262

notebookjs/src/public/javascripts/utils.js

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,39 +90,39 @@ function viz(name, callback) {
9090
return cb
9191
}
9292

93-
function table(df){
93+
function table(df) {
94+
95+
const { col_types, series, columns, index, values } = df;
9496

95-
const {col_types, series, columns, index, values} = df;
9697

97-
9898
let head = ""
99-
if(series){
99+
if (series) {
100100
head += `<th class="${col_types[0]}">${columns}</th>`
101-
}else{
101+
} else {
102102

103-
columns.forEach((name,i)=>{
104-
head +=`<th class="${col_types[i]}">${name}</th>`
103+
columns.forEach((name, i) => {
104+
head += `<th class="${col_types[i]}">${name}</th>`
105105
});
106106
}
107107

108108
let body = ""
109109

110-
values.forEach((row,i)=>{
110+
values.forEach((row, i) => {
111111

112112
let b_String = `<tr><th>${index[i]}</th>`
113113

114-
if(series){
114+
if (series) {
115115
b_String += `<td class="${col_types[0]}">${row}</td>`
116-
}else{
116+
} else {
117117

118-
row.forEach((v,j)=>{
119-
b_String +=`<td class="${col_types[j]}">${v}</td>`
118+
row.forEach((v, j) => {
119+
b_String += `<td class="${col_types[j]}">${v}</td>`
120120
});
121121
}
122122

123-
b_String +="</tr>"
123+
b_String += "</tr>"
124124

125-
body +=b_String;
125+
body += b_String;
126126
});
127127

128128
const table = `
@@ -140,29 +140,52 @@ function table(df){
140140
</div>
141141
`;
142142

143-
return table;
143+
return table;
144144

145145
}
146146

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

149149
var store = {}
150150

151-
for(let key in scope){
151+
for (let key in scope) {
152152

153153
let id = key.split("-")[1]
154-
154+
155155
let cell_content = scope[key].getValue()
156156

157157
let cell_output = $(`#out_${key}`).html()
158158

159159
store[`cell-${id}`] = {
160160
"in": cell_content,
161-
"out": cell_output
161+
"out": cell_output
162162
}
163163
}
164164

165165
store = JSON.stringify(store);
166166

167167
return store
168-
}
168+
}
169+
170+
171+
//load package scripts
172+
function LoadPackage(array, callback) {
173+
let loader = function (src, handler) {
174+
let script = document.createElement("script");
175+
script.src = src;
176+
script.onload = script.onreadystatechange = function () {
177+
script.onreadystatechange = script.onload = null;
178+
handler();
179+
}
180+
let head = document.getElementsByTagName("head")[0];
181+
(head || document.body).appendChild(script);
182+
};
183+
(function run() {
184+
if (array.length != 0) {
185+
loader(array.shift(), run);
186+
} else {
187+
callback && callback();
188+
}
189+
})();
190+
}
191+

notebookjs/src/views/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</button>
3131
</div>
3232

33-
<button type="button" id="del_btn-1" class="btn btn-sm btn-danger del"><i
33+
<button type="button" id="del-btn_1" class="btn btn-sm btn-danger del"><i
3434
class="fas fa-trash-alt"></i>
3535
</button>
3636
</div>

notebookjs/src/views/layout.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<script type="text/javascript"
1111
src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/mode/javascript/javascript.min.js"></script>
1212
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/theme/monokai.min.css">
13-
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.1.1/dist/index.min.js"></script>
13+
{{!-- <script src="https://cdn.jsdelivr.net/npm/danfojs@0.1.1/dist/index.min.js"></script> --}}
14+
{{!-- <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"> </script> --}}
1415
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
1516
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
1617
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"

0 commit comments

Comments
 (0)