diff --git a/static/js/shop/ProductCartItem.jsx b/static/js/shop/ProductCartItem.jsx index 9a0aca9..7831f29 100644 --- a/static/js/shop/ProductCartItem.jsx +++ b/static/js/shop/ProductCartItem.jsx @@ -5,6 +5,7 @@ import {OverlayTrigger} from "react-bootstrap"; import {DialogPopup} from "./options/DialogPopup.jsx"; import {productStyle} from "./utils"; import {Resources} from "./Resources.jsx"; +import {Warnings} from "./Warnings"; /** * Component that renders a product. @@ -132,21 +133,7 @@ export class ProductCartItem extends PureComponent {
{warning && - ( ( -
-

- {warning.message} -

-
) - } - rootClose - > - -
) + () } {options && ( diff --git a/static/js/shop/Warnings.jsx b/static/js/shop/Warnings.jsx new file mode 100644 index 0000000..1a8bb0c --- /dev/null +++ b/static/js/shop/Warnings.jsx @@ -0,0 +1,25 @@ +import {OverlayTrigger} from "react-bootstrap"; +import React from "react"; + + + +export function Warnings({warnings}) { + return ( + ( +
+ +

+ {warnings.message} +

+
) + } + rootClose + > + +
+ ) +} \ No newline at end of file diff --git a/static/js/shop/count_resources.js b/static/js/shop/count_resources.js index 9aaf3a2..ff39334 100644 --- a/static/js/shop/count_resources.js +++ b/static/js/shop/count_resources.js @@ -1,47 +1,51 @@ -function EEMCounter(data, index) { - const process_slots = (item) => { - if (!item.options_data - || item.options_data.ext_pwr === false - || item.options_data.mono_eem === false - ) - return item.slotOccupied; - else if (item.options_data.ext_pwr === true) - return 0; - else if (item.options_data.mono_eem === true || item.options_data.n_eem === "1 EEM") - return 1; - else if (item.options_data.n_eem === "3 EEM") - return 3; - return item.slotOccupied || 0; - } +export const count_item_occupied_eem = (item) => { + if (!item.options_data + || item.options_data.ext_pwr === false + || item.options_data.mono_eem === false + ) + return item.slotOccupied; + else if (item.options_data.ext_pwr === true) + return 0; + else if (item.options_data.mono_eem === true || item.options_data.n_eem === "1 EEM") + return 1; + else if (item.options_data.n_eem === "3 EEM") + return 3; + + return item.slotOccupied || 0; +} + +export const count_item_occupied_clock = (item) => { + return (item.options_data && item.options_data.ext_clk === true) ? 0 : (item.clockOccupied || 0); +} + +export const count_item_occupied_idc = (item) => { + return item.idcOccupied || 0; +} + +function EEMCounter(data, index) { let count = 0; for (let i = index + 1; i < data.length; i++) { - if (data[i].resources.filter((value, _i) => value.name === "eem").length > 0) break; - count += process_slots(data[i]); + if (!!data[i].resources.find((value, _i) => value.name === "eem")) break; + count += count_item_occupied_eem(data[i]); } return count; } function ClockCounter(data, index) { - const process_slots = (item) => { - return (item.options_data && item.options_data.ext_clk === true) ? 0 : (item.clockOccupied || 0); - } let count = 0; for (let i = index + 1; i < data.length; i++) { - if (data[i].resources.filter((value, _i) => value.name === "clk").length > 0) break; - count += process_slots(data[i]); + if (!!data[i].resources.find((value, _i) => value.name === "clk")) break; + count += count_item_occupied_clock(data[i]); } return count; } function IDCCounter(data, index) { - const process_slots = (item) => { - return item.idcOccupied || 0; - } let count = 0; for (let i = index + 1; i < data.length; i++) { - if (data[i].resources.filter((value, _i) => value.name === "idc").length > 0) break; - count += process_slots(data[i]); + if (!!data[i].resources.find((value, _i) => value.name === "idc")) break; + count += count_item_occupied_idc(data[i]); } return count; } diff --git a/static/js/shop/warnings.js b/static/js/shop/warnings.js index 0052716..6a7b662 100644 --- a/static/js/shop/warnings.js +++ b/static/js/shop/warnings.js @@ -3,4 +3,69 @@ * 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 - */ \ No newline at end of file + */ + +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.' + }, +} +