web2019/static/js/shop/warnings.js

72 lines
2.4 KiB
JavaScript

/**
* This module should contain warnings subsystem.
* First idea - there should be either definitive list of available warnings,
* or defined as some json logic leading to the warning message(s), similar way how FillExtData works.
* Second - resources indicator should be separate component
*/
import {count_item_occupied_eem, count_item_occupied_clock, count_item_occupied_idc} from "./count_resources";
const Levels = {
"reminder": {priority: 0, icon: '/images/shop/icon-reminder.svg'},
"warning": {priority: 1, icon: '/images/shop/icon-warning.svg'},
}
const find_in_counters = (counters, name) => {
return counters.find((element) => element.name === name)
}
const find_previous_source = (data, index, source) => {
return data.slice(0, index).find((element) => {element.resources.find((value) => value.name === source)})
}
const not_enough_resource_trigger = (name) => {
return (_data, _index, counters) => {
const eem = find_in_counters(counters, name);
return eem.occupied > eem.max;
}
}
const no_source_trigger = (name) => {
return (data, index, _counters) => {
const occupied = count_item_occupied_eem(data[index]);
if (occupied > 0)
return !!find_previous_source(data, index, name);
return false;
}
}
const Types = {
"eem_resource": {
level: "warning",
trigger: not_enough_resource_trigger("eem"),
message: "Insufficient EEM connectors"
},
"no_eem_source" : {
level: "warning",
trigger: no_source_trigger("eem"),
message: 'This card needs a card that provides a EEM connector (e.g. Kasli) at its left.'
},
"idc_resource": {
level: "warning",
trigger: not_enough_resource_trigger("idc"),
message: "Insufficient IDC connectors."
},
"no_idc_source" : {
level: "warning",
trigger: no_source_trigger("idc"),
message: 'Should be after a Zotino or a HD68-IDC or with another IDC-BNC.'
},
"clk_resource": {
level: "warning",
trigger: not_enough_resource_trigger("clk"),
message: "Insufficient clock connectors."
},
"no_clk_source" : {
level: "warning",
trigger: no_source_trigger("clk"),
message: 'This card needs either a card that provides a clock source (e.g. Kasli or Clocker) at its left or use external clock source.'
},
}