mirror of https://github.com/MISP/misp-dashboard
better management of data relation
parent
aca58eb9e7
commit
ca1005d165
|
@ -20,7 +20,7 @@
|
|||
|
||||
this.result.dates = [];
|
||||
|
||||
this.mappingDate = {};
|
||||
this.mappingI2 = {};
|
||||
this.perform_mapping();
|
||||
return this.result;
|
||||
};
|
||||
|
@ -36,7 +36,7 @@
|
|||
this.c_labels(this.data, this.mapping.labels); // probe and fetch all labels
|
||||
}
|
||||
if (this.mapping.labels.length > 0 && this.mapping.values.length > 0) {
|
||||
this.c_values(this.data, this.mapping.labels); // fetch values and overwrite default values
|
||||
this.c_values(this.data, this.mapping.values); // fetch values and overwrite default values
|
||||
for (var k in this.result) {
|
||||
this.result[k] = this.result[k].filter(function(n){ return n != undefined });
|
||||
}
|
||||
|
@ -48,8 +48,10 @@
|
|||
var matchingFun = function (intermediate, instructions, additionalData) {
|
||||
let index = instructions;
|
||||
let val = intermediate[index];
|
||||
that.mappingDate[val] = that.result['dates'].length;
|
||||
that.result['dates'].push(val);
|
||||
if (that.mappingI2[val] === undefined) {
|
||||
that.mappingI2[val] = that.result['dates'].length;
|
||||
that.result['dates'].push(val);
|
||||
}
|
||||
};
|
||||
this.iter(intermediate, instructions, matchingFun, {});
|
||||
},
|
||||
|
@ -58,14 +60,26 @@
|
|||
var that = this;
|
||||
var matchingFun = function (intermediate, instructions, additionalData) {
|
||||
let index = instructions;
|
||||
let label = intermediate[index];
|
||||
let val = [];
|
||||
for (var i=0; i<additionalData.valueLength; i++) {
|
||||
if ((that.options.fillValue !== undefined && that.options.fillValue != '')) {
|
||||
val.push(that.options.fillValue);
|
||||
if (index == 'l') { // labels are the key themself
|
||||
for (let label in intermediate) {
|
||||
let val = [];
|
||||
for (var i=0; i<additionalData.valueLength; i++) {
|
||||
if ((that.options.fillValue !== undefined && that.options.fillValue != '')) {
|
||||
val.push(that.options.fillValue);
|
||||
}
|
||||
}
|
||||
that.result[label] = val;
|
||||
}
|
||||
} else {
|
||||
let label = intermediate[index];
|
||||
let val = [];
|
||||
for (var i=0; i<additionalData.valueLength; i++) {
|
||||
if ((that.options.fillValue !== undefined && that.options.fillValue != '')) {
|
||||
val.push(that.options.fillValue);
|
||||
}
|
||||
}
|
||||
that.result[label] = val;
|
||||
}
|
||||
that.result[label] = val;
|
||||
};
|
||||
this.iter(intermediate, instructions, matchingFun, {valueLength: this.result.dates.length});
|
||||
},
|
||||
|
@ -74,10 +88,11 @@
|
|||
var that = this;
|
||||
var matchingFun = function (intermediate, instructions, additionalData) {
|
||||
let index = instructions;
|
||||
let label = intermediate[index];
|
||||
let val = that.fetch_value(intermediate, additionalData.mapping.values);
|
||||
let curDateIndex = that.mappingDate[additionalData.curDate];
|
||||
that.result[label][curDateIndex] = val;
|
||||
let val = intermediate[index];
|
||||
let i1 = additionalData.i1;
|
||||
let i2 = additionalData.i2;
|
||||
let i2_adjusted = that.mappingI2[i2];
|
||||
that.result[i1][i2_adjusted] = val;
|
||||
};
|
||||
this.iter(intermediate, instructions, matchingFun, {mapping: this.mapping});
|
||||
},
|
||||
|
@ -97,14 +112,22 @@
|
|||
return;
|
||||
}
|
||||
|
||||
var flag_register_date = false;
|
||||
var flag_register_i = false;
|
||||
var i_type;
|
||||
if (instructions.length == 1) {
|
||||
matchingFun(intermediate, instructions[0], additionalData);
|
||||
} else {
|
||||
switch (instructions[0]) {
|
||||
case 'd':
|
||||
case 'i1':
|
||||
if (additionalData.mapping) {
|
||||
flag_register_date = true;
|
||||
flag_register_i = true;
|
||||
i_type = 'i1';
|
||||
}
|
||||
break;
|
||||
case 'i2':
|
||||
if (additionalData.mapping) {
|
||||
flag_register_i = true;
|
||||
i_type = 'i2';
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
|
@ -122,19 +145,31 @@
|
|||
|
||||
if (Array.isArray(intermediate)) {
|
||||
for (var node of intermediate) {
|
||||
if (flag_register_date) {
|
||||
let curDate = this.fetch_value(node, additionalData.mapping.dateFromNode);
|
||||
additionalData.curDate = curDate;
|
||||
if (flag_register_i) {
|
||||
let sub_instructions = additionalData.mapping.index[i_type]
|
||||
let curI;
|
||||
if (sub_instructions.length > 0) {
|
||||
curI = this.fetch_value(node, sub_instructions);
|
||||
} else {
|
||||
console.log('Should never happend');
|
||||
}
|
||||
additionalData[i_type] = curI;
|
||||
}
|
||||
this.iter(node, instructions.slice(1), matchingFun, additionalData);
|
||||
}
|
||||
} else if (this.isObject(intermediate)) {
|
||||
for (var k in intermediate) {
|
||||
if (flag_register_date) {
|
||||
let curDate = this.fetch_value(node, additionalData.mapping.dateFromNode);
|
||||
additionalData.curDate = curDate;
|
||||
}
|
||||
var node = intermediate[k];
|
||||
if (flag_register_i) {
|
||||
let sub_instructions = additionalData.mapping.index[i_type]
|
||||
let curI;
|
||||
if (sub_instructions.length > 0) {
|
||||
curI = this.fetch_value(node, sub_instructions);
|
||||
} else {
|
||||
curI = k;
|
||||
}
|
||||
additionalData[i_type] = curI;
|
||||
}
|
||||
this.iter(node, instructions.slice(1), matchingFun, additionalData);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -411,7 +411,7 @@
|
|||
tbody.append(row2);
|
||||
this.mappingDomTable.append(thead);
|
||||
this.mappingDomTable.append(tbody);
|
||||
this.fillValueDomInput = $('<input class="form-control" placeholder="0" value=0>');
|
||||
this.fillValueDomInput = $('<input class="form-control" placeholder="0" value="empty">');
|
||||
var configDiv = $('<div class="form-group mappingTableDivConfig"></div>')
|
||||
.append($('<label>Fill value</label>'))
|
||||
.append(this.fillValueDomInput);
|
||||
|
@ -482,40 +482,53 @@
|
|||
interaction: false
|
||||
};
|
||||
|
||||
var adjusted_instructions = $.extend(true, {}, this.instructions);
|
||||
var res=[];
|
||||
var l = adjusted_instructions.labels;
|
||||
var v = adjusted_instructions.values;
|
||||
for (var i=0; i<v.length; i++) {
|
||||
if (l[i] != v[i]) { res.push(v[i]); }
|
||||
}
|
||||
adjusted_instructions.values = res;
|
||||
|
||||
var res=[];
|
||||
var matchingIndex;
|
||||
var l = adjusted_instructions.labels;
|
||||
var v = adjusted_instructions.dates;
|
||||
for (var i=0; i<v.length; i++) {
|
||||
if (l[i] != v[i]) {
|
||||
if (matchingIndex === undefined) {
|
||||
matchingIndex = i-1;
|
||||
}
|
||||
res.push(v[i]);
|
||||
}
|
||||
}
|
||||
adjusted_instructions.dateFromNode = res;
|
||||
adjusted_instructions.labels[matchingIndex] = 'd';
|
||||
|
||||
|
||||
//var result = new $.proxyMapper(this.instructions, this.data, {});
|
||||
var pm_options = {
|
||||
fillValue: this.fillValueDomInput.val()
|
||||
};
|
||||
var result = new $.proxyMapper(adjusted_instructions, this.data, pm_options);
|
||||
var adjustedInstructions = this.adjust_instruction();
|
||||
var result = new $.proxyMapper(adjustedInstructions, this.data, pm_options);
|
||||
this.treeDivResult[0].innerHTML = '';
|
||||
new TreeFromJson(this.treeDivResult, result, options);
|
||||
},
|
||||
|
||||
adjust_instruction: function() {
|
||||
var adjustedInstructions = $.extend(true, {}, this.instructions);
|
||||
adjustedInstructions.index = {};
|
||||
var matchingIndex = 0;
|
||||
var l = this.instructions.labels;
|
||||
var v = this.instructions.values;
|
||||
var d = this.instructions.dates;
|
||||
// label & value
|
||||
if (l.length != 0 && v.length != 0) {
|
||||
var smaller_array = v.length < l.length ? v : l;
|
||||
for (var i=0; i<smaller_array.length; i++) {
|
||||
if (v[i] != l[i]) {
|
||||
matchingIndex = i-1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
adjustedInstructions.values[matchingIndex] = 'i1';
|
||||
adjustedInstructions.index['i1'] = adjustedInstructions.labels.slice(matchingIndex+1);
|
||||
}
|
||||
|
||||
var matchingIndex = 0;
|
||||
// date & value
|
||||
if (d.length != 0 && v.length != 0) {
|
||||
smaller_array = v.length < d.length ? v : d;
|
||||
for (var i=0; i<smaller_array.length; i++) {
|
||||
if (v[i] != d[i]) {
|
||||
matchingIndex = i-1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
adjustedInstructions.values[matchingIndex] = 'i2';
|
||||
adjustedInstructions.index['i2'] = adjustedInstructions.dates.slice(matchingIndex+1);
|
||||
}
|
||||
|
||||
return adjustedInstructions;
|
||||
},
|
||||
|
||||
isObject: function(v) {
|
||||
return v !== null && typeof v === 'object';
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue