Newer
Older
anttil
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
define([
"base/js/dialog",
"base/js/utils",
"jquery",
"./state",
"./common",
],
function (dialog, utils, $, state, common) {
function getDatasetTypes(env, connection_name, dataset_types, input_fields) {
// get all DatasetTypes of a given connection
var url = env.notebook.base_url + 'openbis/datasetTypes/' + connection_name
fetch(url)
.then(function (response) {
if (response.ok) {
response.json()
.then(function (data) {
//console.log(data.dataSetTypes)
var change_input_fields = function () {
// remove existing input fields
while (input_fields.firstChild) {
input_fields.removeChild(input_fields.firstChild)
}
// for every property assignment, create an input field.
for (pa of dts[dataset_types.selectedIndex].propertyAssignments) {
//var input_title = document.createTextNode(pa.label + ": ")
var input_field = document.createElement("INPUT")
input_field.type = "text"
input_field.name = pa.code
input_field.placeholder = pa.description ? pa.label + ": " + pa.description : pa.label
input_field.size = 90
//input_fields.appendChild(input_title)
input_fields.appendChild(input_field)
input_fields.appendChild(document.createElement("BR"))
}
}
dataset_types.onchange = change_input_fields
// remove the old and add the new dataset-types
dts = data.dataSetTypes
while (dataset_types.firstChild) {
dataset_types.removeChild(dataset_types.firstChild);
}
for (dt of dts) {
var option = document.createElement("OPTION")
option.value = dt.code
option.textContent = dt.description ? dt.code + ": " + dt.description : dt.code
dataset_types.appendChild(option)
}
// change the input fields, since we just received new datasetTypes
change_input_fields()
})
.catch(function (error) {
console.error("Error while parsing dataset types", error)
})
} else {
while (dataset_types.firstChild) {
dataset_types.removeChild(dataset_types.firstChild);
}
}
})
.catch(function (error) {
console.error("Error while fetching dataset types:", error)
})
}
return {
help: 'upload Notebook and Data to openBIS',
icon: 'fa-upload',
help_index: '',
handler: function (env) {
conn_table = document.createElement("DIV")
var dst_title = document.createElement("STRONG")
dst_title.textContent = "DataSet type"
var dataset_types = document.createElement("SELECT")
dataset_types.id = "dataset_type"
dataset_types.className = "form-control select-xs"
var input_fields = document.createElement("DIV")
conn_table.id = "openbis_connections"
getDatasetTypes(env, state.connection.name, dataset_types, input_fields)
var sample_title = document.createElement("STRONG")
sample_title.textContent = "Sample Identifier"
var sampleIdentifier = document.createElement("INPUT")
sampleIdentifier.type = "text"
sampleIdentifier.name = 'sampleIdentifier'
sampleIdentifier.placeholder = "Sample Identifier or permId"
sampleIdentifier.value = ''
sampleIdentifier.size = "90"
var ds_title = document.createElement("STRONG")
ds_title.textContent = "DataSet files"
var ds_files = document.createElement("INPUT")
ds_files.type = "text"
ds_files.placeholder = "filenames"
ds_files.name = "ds_files"
ds_files.size = "90"
var inputs = document.createElement("DIV")
inputs.style.marginTop = '10px'
inputs.appendChild(dst_title)
inputs.appendChild(dataset_types)
inputs.appendChild(input_fields)
inputs.appendChild(sample_title)
inputs.appendChild(sampleIdentifier)
inputs.appendChild(ds_title)
inputs.appendChild(ds_files)
var uploadDialogBox = $('<div/>').append(conn_table).append(inputs)
function onOk() {
var connection_name = state.connection.name
if (!connection_name) {
alert("No connection selected")
return false
}
var uploadUrl = env.notebook.base_url + 'openbis/dataset/' + connection_name
var notebook = IPython.notebook
var re = /\/notebooks\/(.*?)$/
var files = []
var filepath = window.location.pathname.match(re)[1]
files.push(filepath)
// FIXME
//if (ds_files.val()) {
// files.push(ds_files.value)
//}
var dataSetInfo = {
"type": dataset_types.value,
"files": files,
"sampleIdentifier": sampleIdentifier.value
}
var settings = {
url: uploadUrl,
processData: false,
type: 'POST',
dataType: 'json',
data: JSON.stringify(dataSetInfo),
contentType: 'application/json',
success: function (data) {
// display feedback to user
common.createFeedback('success', data.statusText)
// write statusText from returned data to notebooks metadata
if (typeof notebook.metadata.openbis === 'undefined') {
notebook.metadata.openbis = {}
}
if (typeof notebook.metadata.openbis.permIds === 'undefined') {
notebook.metadata.openbis.permIds = {}
}
if (data.permId) {
notebook.metadata.openbis.permIds[data.permId] = data.statusText
}
},
error: function (data) {
// display feedback to user
var feedback = "<strong>Error: </strong>Dataset was not uploaded.<div>" +
data.statusText +
"</div>"
common.createFeedback('danger', feedback)
}
}
// display preloader during commit and push
var preloader = '<img class="openbis-feedback" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.8/ajax-loader.gif">'
// commit and push
utils.ajax(settings)
}
if (IPython.notebook.dirty === true) {
dialog.modal({
body: 'Please save the notebook before uploading it to openBIS.',
title: 'Save notebook first',
buttons: {
'Back': {}
},
notebook: env.notebook,
keyboard_manager: env.notebook.keyboard_manager
})
} else {
dialog.modal({
body: uploadDialogBox,
title: 'Upload openBIS DataSet',
buttons: {
'Cancel': {},
'Upload': {
class: 'btn-primary btn-large',
click: onOk
}
},
notebook: env.notebook,
keyboard_manager: env.notebook.keyboard_manager
})
}
}
}
}
)