Integrate clock/slots configuration into the calculator

Also adjust sizes

Signed-off-by: Egor Savkin <es@m-labs.hk>
Egor Savkin 2023-09-19 10:59:34 +08:00
parent 1b1736ea15
commit 718a4509f4
4 changed files with 41 additions and 27 deletions

View File

@ -268,7 +268,8 @@ button {
.overlayVariant {
min-width: 100px;
height: 150px;
max-height: 150px;
min-height: 50px;
overflow-y: scroll;
position: absolute;
display: flex;
@ -532,8 +533,8 @@ button {
.overlayVariant {
top: 24px;
width: 132px;
min-height: 70px;
width: 140px;
min-height: 40px;
max-height: 320px;
overflow-y: scroll;
position: absolute;
@ -544,6 +545,7 @@ button {
color: black;
flex-direction: column;
cursor: pointer;
padding: 0.2rem 0;
p {
font-size: .65rem;
@ -579,10 +581,10 @@ button {
}
.overlay-smallcard {
right: -34.5px;
right: -38.5px; // (card width (63) - overlay width (140)) / 2
}
.overlay-bigcard {
right: -3px;
right: -7px; // (card width (126) - overlay width (140)) / 2
}
.hovered {

View File

@ -6,7 +6,7 @@ import { createRoot } from "react-dom/client";
import PropTypes from "prop-types";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
import { v4 as uuidv4 } from 'uuid';
import { OptionsDialogPopup, OptionsSummaryPopup, FilterOptions, fill_ext_data } from "./shop_components.jsx";
import { OptionsDialogPopup, OptionsSummaryPopup, FilterOptions, FillExtData } from "./shop_components.jsx";
const data = window.shop_data;
const itemsUnfoldedList = Array.from(data.columns.backlog.categories.map(groupId => groupId.itemIds).flat());
@ -878,7 +878,7 @@ class Cart extends React.PureComponent {
const products = data.items.map((item, index) => {
let itemData;
let ext_data = fill_ext_data(data.itemsData, index);
let ext_data = FillExtData(data.itemsData, index);
if (data.itemsData && index in data.itemsData) {
itemData = data.itemsData[index];
}
@ -1892,7 +1892,7 @@ class Shop extends React.PureComponent {
isProcessing: false,
shouldShowRFQFeedback: true,
RFQBodyType: 'show',
RFQBodyOrder: JSON.stringify(crate),
RFQBodyOrder: JSON.stringify(crate, null, 2),
});
}
@ -1908,8 +1908,6 @@ class Shop extends React.PureComponent {
if (!customconf) {return; }
const items = this.props.data.items;
console.trace(customconf);
const self = this;
let new_items = [];
let new_items_data = [];
@ -1935,7 +1933,7 @@ class Shop extends React.PureComponent {
id: uuidv4(),
options_data: item.options ? item.options : null,
}));
new_items_data.push({options_data: item.options? item.options : null});
new_items_data.push({options_data: item.options ? item.options : null});
}
});
@ -2106,6 +2104,13 @@ class Shop extends React.PureComponent {
const itemsData = [];
const rules = {};
itemsCloned.forEach((elem, idx) => {
if (!(idx in itemsData)) itemsData[idx] = elem;
if (idx in this.state.columns.cart.itemsData && this.state.columns.cart.itemsData[idx].options_data) {
itemsCloned[idx].options_data = this.state.columns.cart.itemsData[idx].options_data;
}
});
// check number of slot in crate
const nbrOccupied = nbrOccupiedSlotsInCrate(newItems);
@ -2155,14 +2160,31 @@ class Shop extends React.PureComponent {
}
}
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;
}
nbUsedSlot = slots
.filter(item => item.type !== 'idc-bnc')
.reduce((prev, next) => {
return prev + next.slotOccupied;
return prev + process_slots(next);
}, 0);
nbrCurrentClock = slots
.reduce((prev, next) => {
return next.type === 'clocker' ? prev + next.clockOccupied : prev;
return next.type === 'clocker' ? prev + ((next.options_data && next.options_data.ext_clk === true) ? 0 : next.clockOccupied) : prev;
}, 0);
if (idx in itemsData) {
@ -2238,7 +2260,7 @@ class Shop extends React.PureComponent {
}
nbrCurrentClock = slots.reduce((prev, next) => {
return prev + next.clockOccupied;
return prev + ((next.options_data && next.options_data.ext_clk && next.options_data.ext_clk.checked) ? 0 : next.clockOccupied);
}, 0);
if (idx in itemsData) {
@ -2379,13 +2401,6 @@ class Shop extends React.PureComponent {
}
}
itemsCloned.forEach((elem, idx) => {
if (!(idx in itemsData)) itemsData[idx] = elem;
if (idx in this.state.columns.cart.itemsData && this.state.columns.cart.itemsData[idx].options_data) {
itemsData[idx].options_data = this.state.columns.cart.itemsData[idx].options_data;
}
});
// update state with rules
this.setState({
...this.state,

View File

@ -23,10 +23,6 @@ class Radio extends Component {
this.props.target.construct(this.props.outvar, this.state.variant);
}
componentWillUnmount() {
this.props.target.unmount(this.props.outvar);
}
handleClick(variant) {
// Update the state object with the new value for outvar
this.setState({
@ -481,7 +477,7 @@ export function OptionsSummaryPopup({id, options, data}) {
);
}
export function fill_ext_data(data, index) {
export function FillExtData(data, index) {
return {
has_other_dio: data.filter((value, item_index) => index !== item_index && value.name.endsWith("-TTL")).length > 0,
has_dds: data.filter(((value, _) => value.name === "DDS")).length > 0,

View File

@ -552,6 +552,7 @@ const shop_data = {
datasheet_name: '4410/4412 Urukul datasheet',
options: [
{type: "Switch", args: {title: "AD9912", outvar: "ad9912", tip: "AD9912 chip instead of AD9910"}},
{type: "Switch", args: {title: "Use 1 EEM", outvar: "mono_eem", tip: "Use one EEM port setup. RF switch and synchronization will be unavailable."}},
{
"if": [
{"var": "ad9912"},
@ -559,7 +560,7 @@ const shop_data = {
{type: "SwitchLine", args: {title: "Ext CLK", outvar: "ext_clk", fallback: {text: "125 MHz", checked: false}}},
],
[
{type: "Switch", args: {title: "Synchronization", outvar: "sync"}},
{type: "Switch", args: {title: "Synchronization", outvar: "sync", tip: "Synchronize phases across Urukuls"}},
{
"if": [
{"var": "sync"},