before reduce optimization

This commit is contained in:
zino
2021-05-15 23:50:04 +02:00
parent 5e9289f6dd
commit 3f8e19d0b6

View File

@@ -4,26 +4,29 @@ import * as I from "../types/types";
import * as UI from "./ui";
import * as Events from "./events";
export function addItem(inSeatObj: I.JSCSelectedSeat) {
const color = `#${XMLHelper.getVenuePricescalePropertyByPricescaleID("color", inSeatObj.data.seatsObj.id[0])}`;
const category = XMLHelper.getVenuePricescalePropertyByPricescaleID("desc", inSeatObj.data.seatsObj.id[0]);
const seat = config.state.layoutRows[inSeatObj.id][5];
const row = config.state.layoutRows[inSeatObj.id][4];
const sectionID = config.state.layoutRows[inSeatObj.id][3];
const sectionDesc = XMLHelper.getSectionDescBySectionID(sectionID);
const seatStr = `${sectionDesc}<br/>Reihe ${row} Platz ${seat}`;
const buyerTypes: (string | undefined)[][] | undefined = getBuyerTypesByPricescaleID(inSeatObj.data.seatsObj.id[0]);
const cartId = `cartItem-${inSeatObj.id}`;
const dropdownBuyerTypesSelector = `#${cartId} .dropdownBuyerTypes`;
type buyerType = (string | undefined)[][] | undefined;
type buyerTypeArr = (string | undefined)[];
appendHTML(cartId, color, category, seatStr);
addDropdownBuyerTypesOptions(buyerTypes, dropdownBuyerTypesSelector);
export function addItem(inSeatObj: I.JSCSelectedSeat): void {
const color: string = `#${XMLHelper.getVenuePricescalePropertyByPricescaleID("color", inSeatObj.data.seatsObj.id[0])}`;
const category: string | undefined = XMLHelper.getVenuePricescalePropertyByPricescaleID("desc", inSeatObj.data.seatsObj.id[0]);
const seat: string = config.state.layoutRows[inSeatObj.id][5];
const row: string = config.state.layoutRows[inSeatObj.id][4];
const sectionID: string = config.state.layoutRows[inSeatObj.id][3];
const sectionDesc: string | undefined = XMLHelper.getSectionDescBySectionID(sectionID);
const seatStr: string | undefined = `${sectionDesc}<br/>Reihe ${row} Platz ${seat}`;
const buyerTypes: buyerType = getBuyerTypesByPricescaleID(inSeatObj.data.seatsObj.id[0]);
const cartID: string = `cartItem-${inSeatObj.id}`;
const dropdownBuyerTypesSelector: string = `#${cartID} .dropdownBuyerTypes`;
appendHTML(cartID, color, category, seatStr);
addDropdownBuyerTypeOptions(buyerTypes, dropdownBuyerTypesSelector);
Events.addCartDropdownBuyerTypes(dropdownBuyerTypesSelector, inSeatObj);
}
function appendHTML(inCartId: string, inColor: string, inCategory: string | undefined, inSeatStr: string) {
function appendHTML(inCartID: string, inColor: string, inCategory: string | undefined, inSeatStr: string): void {
jQuery("#cartItemHTML .fl-html").append(`
<div class="cartItem" id="${inCartId}">
<div class="cartItem" id="${inCartID}">
<div class="cartItemColoredSquare" style="background: ${inColor};"></div>
<div class="cartItemCategory">${inCategory}</div>
<h5 class="cartItemSeat">${inSeatStr}</h5>
@@ -32,26 +35,29 @@ function appendHTML(inCartId: string, inColor: string, inCategory: string | unde
}
// todo: generalize dropdown fill options
function addDropdownBuyerTypesOptions(inBuyerTypes: (string | undefined)[][] | undefined, inSelector: string) {
function addDropdownBuyerTypeOptions(inBuyerTypes: buyerType, inSelector: string) {
if (!inBuyerTypes)
return;
const dropdownBuyerTypes = jQuery(inSelector).get(0);
const dropdownBuyerTypes: HTMLElement = jQuery(inSelector).get(0);
inBuyerTypes.forEach(arr => {
if (!arr[0])
return;
let opt = document.createElement('option');
opt.value = arr[0];
opt.innerHTML = `${arr[2]}${arr[1]}`;
dropdownBuyerTypes.appendChild(opt);
inBuyerTypes.forEach(arr => {
if (arr[0])
appendOption(dropdownBuyerTypes, arr)
});
}
function appendOption(inDropdownBuyerTypes: HTMLElement, inArr: buyerTypeArr) {
let opt: HTMLOptionElement = document.createElement('option');
opt.value = <string>inArr[0];
opt.innerHTML = `${inArr[2]}${inArr[1]}`;
inDropdownBuyerTypes.appendChild(opt);
}
function getBuyerTypesByPricescaleID(inPricescaleID: string) {
const venueXML = config.state.inVenueXML!;
const venuePricescaleArr = venueXML.price_structure[0].pricescale;
const venueXML: I.VenueXML = config.state.inVenueXML!;
const venuePricescaleArr: I.Pricescale5[] = venueXML.price_structure[0].pricescale;
const buyerTypesArr = venuePricescaleArr.find(obj => {
return obj.id[0] === inPricescaleID;
})?.buyer_type;
@@ -59,7 +65,7 @@ function getBuyerTypesByPricescaleID(inPricescaleID: string) {
if (!buyerTypesArr)
return;
const buyerTypes: (string | undefined)[][] = buyerTypesArr.map(arr => {
const buyerTypes: buyerType = buyerTypesArr.map(arr => {
const buyerTypeDesc = venueXML.venue[0].buyer_types[0].buyer_type.find(obj => {
return obj.id[0] === arr.id[0] ? obj.desc[0] : undefined;
})?.desc[0];