fix variants stats
Created by: alpianon
fix for #37 (closed)
.progress
and .workload
properties are calculated in AlienPackage constructor method.
from AlienPackage.js, line 60-onwards:
constructor(data = {}) {
if (data.id) this.id = data.id;
if (data.tags) this.tags = data.tags;
if (data.name) this.name = data.name;
if (data.version) this.version = data.version;
if (data.revision) this.revision = data.revision;
if (data.variant) this.variant = data.variant;
if (data.debian_matching) this.debian_matching = data.debian_matching;
if (data.statistics) this.statistics = data.statistics;
if (data.source_files) this.source_files = data.source_files;
if (data.binary_packages) this.binary_packages = data.binary_packages;
if (data.session_state) this.session_state = data.session_state
if (data.cve_metadata && data.cve_metadata.result) {
this.cve_metadata = data.cve_metadata
this.collectCves();
}
var filestats = this.statistics.files;
this.progress =
filestats.audit_total == 0
? 100
: parseInt(
(filestats.audit_done / filestats.audit_total) * 100
);
this.workload = filestats.audit_done;
this.workload_total = filestats.audit_total;
this.match = this.debian_matching
? (this.debian_matching.ip_matching_files /
filestats.upstream_source_total) *
100
: 0;
}
However, when creating an AlienPackage without immediately setting .statistics.*
properties, .progress
and .workload
are wrongly set, respectively, to 100% and 0. This happens when creating merged (i.e. with variants) packages, here (from Solda.vue, line 877 onwards):
var merged_package = new AlienPackage({
name: variants[a][0].name,
version: variants[a][0].version,
revision: variants[a][0].revision,
variant: true,
session_state: variants[a][0].session_state
});
So a separate method has been created to do such calculation, that is called by the constructor method but can be separately called also after creating an object.