@calf/angular
Version:
Angular module of Calf framework.
90 lines (89 loc) • 2.28 kB
JavaScript
/**
* Abstract stat service class
*/
export class StatService {
/**
* Constructor
* @param e
*/
constructor(e) {
// Is constant flag
this.isConstant = false;
// Assign values
this.enumeration = e;
// Check constant
this.checkIsConstant();
}
/**
* Get values
*/
getValues() {
// Init result array
const values = [];
// Iterate through enum values
for (var n in this.enumeration) {
// Check for constant or typeof number
if (this.isConstant || typeof this.enumeration[n] === "number") {
// Add value to array of values
values.push(this.enumeration[n]);
}
}
// Return result
return values;
}
/**
* Get labelled values
*/
getLabelledValues() {
// Map values
return this.getValues().map((v) => {
// Create labelled value
return {
label: this.getLabel(v),
value: v
};
});
}
/**
* Get color
* @param value
* @param args
* @returns
*/
getColor(value, ...args) { return ""; }
/**
* Get icon
* @param value
* @param args
* @returns
*/
getIcon(value, ...args) { return ""; }
/**
* Get description
* @param value
* @returns
*/
getDescription(value, ...args) { return ""; }
/**
* Check if enumeration is constant
*/
checkIsConstant() {
// Need to find at least one number value and one
// string value
let hasString = false;
let hasNumber = false;
// Iterate through enum values
for (var n in this.enumeration) {
// Check for number
if (typeof this.enumeration[n] === "number") {
hasNumber = true;
}
// Check for string
else if (typeof this.enumeration[n] === "string") {
hasString = true;
}
}
// Assign value for isConstant flag
this.isConstant = !hasNumber || !hasString;
}
}