-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
540 lines (449 loc) · 20.8 KB
/
index.html
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<!--<link type="text/css" rel="stylesheet" href="css/main.css"/>-->
<script type="text/javascript" src="libs/d3.min.js"></script>
<!--<script src="http://d3js.org/d3.v3.min.js"></script>-->
<!--<script type="text/javascript" src="settings.js"></script>-->
<style type="text/css">
body { font-family: "Arial"; font-size: 0.9em; }
.currentSelection { font-weight: bold ; color: red ; }
#metricsView { position:absolute; top:0px; right:0px; margin:1em; background-color:white ; }
</style>
</head>
<body>
<div id="configurationsView">
<h2>Configurations</h2>
<div id="resourceConfigurationID"><span>current: </span><span class="value"> ... </span></div>
</div>
<div id="resourcesView">
<h2>Resources</h2>
<input id="updateInputDatamodel" type="checkbox" value="false"/>Update current input data model instead of creating a new data model during ingest
</div>
<h2>Current Transform (Task) Configuration</h2>
<ul id="currentTaskConfigView">
<li id="projectID"><span>projectID: </span><span class="value"> ... </span></li>
<li id="inputDatamodelID"><span>inputDatamodelID: </span><span class="value"> ... </span></li>
<li id="outputDatamodelID"><span>outputDatamodelID: </span><span class="value"> ... </span></li>
</ul>
<div style="margin-top:1em">
<button style="color:green" onClick="queueTaskConfig(currentTaskConfig,false)">Build job from project and queue task (Preview)</button>
<button style="color:red" onClick="queueTaskConfig(currentTaskConfig,true)">Build job from project and queue task</button>
<button style="color:grey" onClick="queueExportConfig(currentTaskConfig.outputDatamodelID,'application/xml')">Export output model (XML, queued)</button>
</div>
<div id="projectsView"><h2>Projects</h2></div>
<div id="datamodelsView"><h2>Datamodels</h2></div>
<div id="metricsView">
<h2>Process Step Log+Metrics</h2>
<ol id="metricsList" style="font-size:0.75em;">
</ol>
<h2>Task Queue</h2>
<button style="color:green" onClick="consumeConfig()">Consume next Task</button>
<ul id="queueList" style="font-size:0.75em;">
</ul>
</div>
<script type="text/javascript">
/* SETTINGS */
var baseUrlBackend = "http://127.0.0.1:8087/dmp/";
// var baseUrlBackend = "http://sdvdmpdev.slub-dresden.de/dmp/";
/* CLASSES */
var TaskConfiguration = function(inputDatamodelID, outputDatamodelID, projectID, persist) {
this.processStep = buildJobAndRunTask;
this.inputDatamodelID = inputDatamodelID;
this.outputDatamodelID = outputDatamodelID;
this.projectID = projectID;
this.persist = persist;
this.configID = configCount++;
}
TaskConfiguration.prototype.toString = function taskConfigToString() {
var ret = "transform " + this.inputDatamodelID + " --> " + this.outputDatamodelID;
return ret;
}
var ExportConfiguration = function(datamodelID,format) {
this.processStep = exportDatamodel;
this.datamodelID = datamodelID;
this.format = format;
this.configID = configCount++;
}
ExportConfiguration.prototype.toString = function exportConfigToString() {
var ret = "export " + this.datamodelID + " as " + this.format ;
return ret;
}
var IngestConfiguration = function(resourceID) {
this.processStep = ingestAsNewDatamodel;
this.resourceID = resourceID;
this.configID = configCount++;
}
IngestConfiguration.prototype.toString = function ingestConfigToString() {
var ret = "ingest " + this.resourceID;
return ret;
}
/* PARAMETERS */
var resourceConfigurationID = "";
var currentTaskConfig = new TaskConfiguration(null, null, null);
/* GLOBALS */
var configCount = 0;
var transformRequestCount = 0;
var exportRequestCount = 0;
var ingestRequestCount = 0;
var configQueue;
/* FUNCTIONS */
var buildJob = function(project) {
var job = {};
job.name = "Job derived from project '" + project.name + "'";
job.mappings = project.mappings;
return job;
};
var buildTask = function(job, inputDatamodel, outputDatamodel) {
var task = {};
task.name = "" +
"Task (based on project '" + job.name +
"', in: " + inputDatamodel.id +
", out: " + outputDatamodel.id;
task.job = job;
task.input_data_model = inputDatamodel;
task.output_data_model = outputDatamodel;
return task;
};
function updateParameterView() {
contents.select("#projectID").select(".value").text(currentTaskConfig.projectID);
contents.select("#inputDatamodelID").select(".value").text(currentTaskConfig.inputDatamodelID);
contents.select("#outputDatamodelID").select(".value").text(currentTaskConfig.outputDatamodelID);
contents.select("#resourceConfigurationID").select(".value").text(resourceConfigurationID);
}
function queueTaskConfig(taskConfig,persist) {
if(taskConfig.inputDatamodelID == null || taskConfig.outputDatamodelID == null || taskConfig.projectID == null)
{alert("check transform task config"); return;}
if (persist == null) persist = false;
configQueue.push(new TaskConfiguration(taskConfig.inputDatamodelID, taskConfig.outputDatamodelID, taskConfig.projectID, persist));
updateQueueList();
}
function queueExportConfig(dataModelID,format) {
configQueue.push(new ExportConfiguration(dataModelID,format));
updateQueueList();
}
function queueIngestConfig(resourceID) {
configQueue.push(new IngestConfiguration(resourceID));
updateQueueList();
}
function consumeConfig() {
if(configQueue.getLength()>0) {
var config = configQueue.shift();
config.processStep(config);
}
}
function buildJobAndRunTask(taskConfig) {
console.log(taskConfig.projectID);
// get project and build job
d3.json(baseUrlBackend + "projects/" + taskConfig.projectID, function (error, result) {
var currentProject = result;
var currentJob = buildJob(currentProject);
// get input data model
d3.json(baseUrlBackend + "datamodels/" + taskConfig.inputDatamodelID, function (error, result) {
var currentInputDatamodel = result;
// get output data model
d3.json(baseUrlBackend + "datamodels/" + taskConfig.outputDatamodelID, function (error, result) {
var currentOutputDatamodel = result;
var currentTask = buildTask(currentJob, currentInputDatamodel, currentOutputDatamodel);
// metrics
var transformNumber = transformRequestCount++;
performance.mark(createStartMark("transformation",transformNumber));
// run task
d3.xhr(baseUrlBackend + "tasks?persist=" + taskConfig.persist)
.header("Content-Type", "application/json;charset=utf-8")
.header("Accept", "application/json, text/plain, */*")
.post(
JSON.stringify(currentTask),
function(err, rawData){
// metrics
var taskName = "transform"; if (!taskConfig.persist) taskName += " (preview)";
performance.mark(createEndMark("transformation",transformNumber));
performance.measure(createMeasure(rawData.status,taskName,transformNumber,currentInputDatamodel.name), createStartMark("transformation",transformNumber), createEndMark("transformation",transformNumber));
updateQueueList(); updateMetricsList();
consumeConfig();
var transformationResult = JSON.parse(rawData.response);
console.log("Transformation results:");
console.log(transformationResult);
});
});
});
});
}
function exportDatamodel(exportConfig) {
// metrics
var exportNumber = exportRequestCount++;
performance.mark(createStartMark("export",exportNumber));
d3.xhr(baseUrlBackend + "datamodels/" + exportConfig.datamodelID + "/export?format=" + encodeURIComponent(exportConfig.format))
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
// .header("Accept", "application/octet-stream")
.get(
function(err, rawData) {
// metrics
performance.mark(createEndMark("export",exportNumber));
performance.measure(createMeasure(rawData.status,"export",exportNumber,exportConfig.datamodelID), createStartMark("export",exportNumber), createEndMark("export",exportNumber));
updateQueueList(); updateMetricsList();
consumeConfig();
// console.log(err); console.log(rawData.response);
// http://www.html5rocks.com/en/tutorials/file/filesystem/ and https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
// if (rawData.status === 200) {
// var blob = new Blob([rawData.response], {type: "application/rdf+xml"});
// var objectUrl = URL.createObjectURL(blob);
// window.open(objectUrl);
// }
}
);
}
function ingestAsNewDatamodel(ingestConfig) {
console.log("Building datamodel from resource " + ingestConfig.resourceID + " using the default config (XML/record) ... ");
// get resource
d3.json(baseUrlBackend + "resources/" + ingestConfig.resourceID, function (error, resource) {
// get config
d3.json(baseUrlBackend + "configurations/" + resourceConfigurationID, function (error, configuration) {
var configuredDatamodel = {
"data_resource": resource ,
"name" : resource.name,
"description" : resource.description,
"configuration" : configuration
};
if (updateInputDatamodelOnIngest() && currentTaskConfig.inputDatamodelID != null) {
alert("deactivated, since updating not yet implemented in the BE (only metadata is getting updated)");
// console.log("Will update the current input data model " + currentTaskConfig.inputDatamodelID + " using the config " + configuration.uuid);
//
// metrics
// var ingestNumber = ingestRequestCount++;
// performance.mark(createStartMark("ingest-update",ingestNumber));
//
// var xhr = new XMLHttpRequest();
// xhr.onload = function(){
// // metrics
// performance.mark(createEndMark("ingest-update",ingestNumber));
// performance.measure(createMeasure(this.status, "ingest-update",ingestNumber,resource.name), createStartMark("ingest-update",ingestNumber), createEndMark("ingest-update",ingestNumber));
// updateMetricsList();
//
// var configurationResult = JSON.parse(this.responseText);
// console.log("updated datamodel:");
// console.log(configurationResult);
// };
// xhr.open( "PUT", baseUrlBackend + "datamodels/" + currentTaskConfig.inputDatamodelID, true );
// xhr.setRequestHeader( "Content-Type", "application/json;charset=utf-8" );
// xhr.setRequestHeader( "Accept", "application/json, text/plain, */*" );
// xhr.send(JSON.stringify(configuredDatamodel));
} else {
// metrics
var ingestNumber = ingestRequestCount++;
performance.mark(createStartMark("ingest",ingestNumber));
d3.xhr(baseUrlBackend + "datamodels")
.header("Content-Type", "application/json;charset=utf-8")
.header("Accept", "application/json, text/plain, */*")
.post(
JSON.stringify(configuredDatamodel),
function(err, rawData){
// console.log(err); console.log(rawData.response);
// metrics
performance.mark(createEndMark("ingest",ingestNumber));
console.log("status: " + rawData.status);
performance.measure(createMeasure(rawData.status,"ingest",ingestNumber,resource.name), createStartMark("ingest",ingestNumber), createEndMark("ingest",ingestNumber));
updateQueueList(); updateMetricsList();
consumeConfig();
var configurationResult = JSON.parse(rawData.response);
console.log("configurationResult:");
console.log(configurationResult);
}
);
}
});
});
}
function updateMetricsList() {
var updatedMeasurements = window.performance.getEntriesByType('measure');
// console.log(updatedMeasurements);
// for (var i = 0; i < updatedMeasurements.length; ++i) {
// var req = updatedMeasurements[i];
// console.log('Process step ' + req.name + ' took ' + formatedTime(req.duration));
// }
d3.select("#metricsList").selectAll("li").data(updatedMeasurements, function(d){return d.startTime}).enter().append("li")
.text(function(d) {console.log(d.duration); return d.name + ": " + formatedTime(d.duration) ; })
.call(highlightTemporarily)
;
}
function updateQueueList() {
var updatedQueue = configQueue.getCurrentArray();
// for(i = 0; i < updatedQueue.length; i++ )
// console.log(updatedQueue[i].inputDatamodelID);
var li = d3.select("#queueList").selectAll("li").data(updatedQueue, function(d){return d.configID ;});
li.enter().append("li")
.call(highlightTemporarily);
li.text(function(d) { return d.toString() ;});
li.exit().fadeAway();
}
function setCurrent(inputElement, className) {
d3.select("."+className).classed(className + " " + "currentSelection",false);
d3.select(inputElement.parentNode).classed(className + " " + "currentSelection",true);
}
updateInputDatamodelOnIngest = function () {
return d3.select("#updateInputDatamodel").property("checked");
}
function formatedTime(timeInMs) {
var mydate = new Date(timeInMs);
var hours = mydate.getUTCHours();
var minutes = mydate.getUTCMinutes();
var seconds = mydate.getUTCSeconds();
var formatedTime = "";
if (hours>0) formatedTime+=hours + "hours, ";
if (minutes>0) formatedTime+=minutes + " min and ";
if (seconds>0) {formatedTime+=seconds +" sec"} else {formatedTime = "< 1s"};
return formatedTime;
}
// after http://insertafter.com/en/blog/fifo_lifo_javascript.html / https://gist.githubusercontent.com/nfroidure/5472445/raw/Queue.js
var Queue = function() {
var functionSet=(function() {
var _elements=[]; // creating a private array
return [
// push function
function()
{ return _elements.push .apply(_elements,arguments); },
// shift function
function()
{ return _elements.shift .apply(_elements,arguments); },
function() { return _elements.length; },
function(n) { return _elements.length=n; },
function() { return _elements; }];
})();
this.push=functionSet[0];
this.shift=functionSet[1];
this.getLength=functionSet[2];
this.setLength=functionSet[3];
this.getCurrentArray=functionSet[4];
// initializing the queue with given arguments
this.push.apply(this,arguments);
};
function createStartMark(eventType,count) { return "start_" + eventType + "_" + count }
function createEndMark(eventType,count) { return "end_" + eventType + "_" + count }
function createMeasure(status,eventType,count,descriptor) {return eventType + " (" + descriptor + ") # " + count + " (" + status + ")"}
function highlightTemporarily(selection) {
selection.style("background-color", "lightgreen").transition().duration(1000).style("background-color", "white");
}
d3.selection.prototype.fadeAway = function () {
return this.style("opacity", 1).transition().duration(1000).style("opacity", 0).remove();
};
function isInternalModel(model){ return model.configuration == null ; }
/* PAGE BUILDING */
var contents = d3.select("body");
configQueue = new Queue();
// list resources
d3.json(baseUrlBackend + "resources", function (error, result) {
var lis = contents.select("#resourcesView")
.append("div").append("ul")
.selectAll("li.resource")
.data(result.sort(function(a, b) { return d3.ascending(a.name, b.name); }))
;
lis.enter()
.append("li")
.attr("class", "resource")
.text(function(d){ return d.description + " " + d.name ; })
.attr("title", function(d){ return d.description + " (" + d.uuid + ")"; })
;
lis.append("button")
.attr("onclick", function(d){
return "setCurrent(this, 'resource'); queueIngestConfig('" + d.uuid + "');";
})
.text(function(d){return "Queued Ingest" ;})
;
});
// list configurations
d3.json(baseUrlBackend + "configurations", function (error, result) {
var lis = contents.select("#configurationsView")
.append("div").append("ul")
.selectAll("li.configuration")
.data(result.sort(function(a, b) { return d3.ascending(a.uuid, b.uuid); }))
;https://gist.githubusercontent.com/nfroidure/5472445/raw/Queue.js
lis.enter()
.append("li")
.attr("class", "configuration")
.text(function(d){ return JSON.stringify(d.parameters) ; })
.attr("title", function(d){ return d.name + " " + d.description + " (" + d.uuid + ")"; })
;
lis.append("button")
.attr("onclick", function(d){
return "setCurrent(this, 'configuration'); resourceConfigurationID = '" + d.uuid + "'; updateParameterView() ; ";
})
.text(function(d){return "Use for ingest" ;})
;
});
// list projects
d3.json(baseUrlBackend + "projects", function (error, result) {
var lis = contents.select("#projectsView")
.append("div").append("ul")
.selectAll("li.project")
.data(result.sort(function(a, b) { return d3.ascending(a.name, b.name); }))
;
lis.enter()
.append("li")
.attr("class", "project")
.text(function(d){ return d.name + " " ; })
.attr("title", function(d){ return d.description + " (" + d.uuid + ")"; })
;
lis.append("button")
.attr("onclick", function(d){
return "setCurrent(this, 'project'); currentTaskConfig.projectID = '" + d.uuid + "'; updateParameterView() ; ";
})
.text(function(d){return "Use for job" ;})
;
});
// list datamodels
d3.json(baseUrlBackend + "datamodels", function (error, result) {
var lis = contents.select("#datamodelsView")
.append("div").append("ul")
.selectAll("li.datamodel")
.data(result.sort(function(a,b){if (isInternalModel(a)) return -1 ; else return d3.ascending(a.name, b.name) ;}))
;
lis.enter()
.append("li")
.attr("class", "datamodel")
.text(function(d){ return d.description + " - " + d.name + " " ; })
.attr("title", function(d){ return d.uuid; })
;
// input
lis.filter(function(d){return !isInternalModel(d);})
.append("button")
.attr("onclick", function(d){
return "setCurrent(this, 'input') ; currentTaskConfig.inputDatamodelID = '" + d.uuid + "'; updateParameterView() ; ";
})
.text(function(d){return "Use as input";})
;
// output
lis.filter(function(d){return isInternalModel(d);})
.style("font-weight","bold")
.append("button")
.attr("onclick", function(d){
return "setCurrent(this, 'output'); currentTaskConfig.outputDatamodelID = '" + d.uuid + "'; updateParameterView() ; ";
})
.text(function(d){return "Use as output";})
;
// export
lis.append("button")
.attr("onclick", function(d){
return "queueExportConfig('" + d.uuid + "','application/rdf+xml') ; ";
})
.text(function(d){return "Queued RDF/XML-Export";})
;
lis.append("button")
.attr("onclick", function(d){
return "queueExportConfig('" + d.uuid + "','application/xml') ; ";
})
.text(function(d){return "XML";})
;
// quick transform
lis.filter(function(d){return !isInternalModel(d);})
.append("button")
.attr("onclick", function(d){
return "setCurrent(this, 'input') ; currentTaskConfig.inputDatamodelID = '" + d.uuid + "'; queueTaskConfig(currentTaskConfig,true) ; updateParameterView() ; ";
})
.text(function(d){return "Queue transform (non-preview)";})
;
});
</script>
</body>
</html>