From 5e9289f6dd9003df0f78421d3f241d4c7af99c58 Mon Sep 17 00:00:00 2001 From: zino Date: Sat, 15 May 2021 23:19:43 +0200 Subject: [PATCH] removed state vars from function params --- client/src/modules/events.ts | 5 +- client/src/modules/jsc.ts | 92 ++++++++---------------------------- client/src/modules/state.ts | 5 +- client/src/modules/ui.ts | 12 +++-- client/src/modules/utils.ts | 8 +--- client/src/seatmap.ts | 20 +++----- 6 files changed, 39 insertions(+), 103 deletions(-) diff --git a/client/src/modules/events.ts b/client/src/modules/events.ts index a20abcc..e15f761 100644 --- a/client/src/modules/events.ts +++ b/client/src/modules/events.ts @@ -79,7 +79,6 @@ export function addCartBack() { export function dropdownLegendOnChange(inSelector: string) { const seatmap = config.state.seatmap; - const seatmapXML = config.state.seatmapXML; const dropdownLegend = jQuery(inSelector).get(0); dropdownLegend.addEventListener("change", function (this: HTMLSelectElement) { const value: string = this.value; @@ -89,12 +88,12 @@ export function dropdownLegendOnChange(inSelector: string) { if (value === "all") { seatmap.find('unavailable').status('available'); - JSC.setUnavailableSeats(seatmapXML, seatmap); + JSC.setUnavailableSeats(); } else { seatmap.find('available').status('unavailable'); JSC.activateSeatsBySectionID(value); - JSC.setUnavailableSeats(seatmapXML, seatmap); + JSC.setUnavailableSeats(); } }); diff --git a/client/src/modules/jsc.ts b/client/src/modules/jsc.ts index a0a5fef..57a4f35 100644 --- a/client/src/modules/jsc.ts +++ b/client/src/modules/jsc.ts @@ -55,66 +55,6 @@ export function getRowsNaming(): string[] { return namingArr; } -// export function getColumnNaming(inXML: any): string[] { -// const layout: I.SeatmapLayout = inXML.seatmap[0].layouts[0].layout[0]; - - - -// const width: number = parseInt(layout.width[0]); - - -// const namingArr = Array.from({ length: width }, (_) => ""); -// const rowsArr = layout.rows[0].row; - -// // let seats: number[] = []; -// // let x: number[] = []; -// rowsArr.forEach(element => { -// // const index: number = parseInt(element.y_cell_coord[0]); -// const seatsArr: string[] = element.seats[0].split("|"); - -// seatsArr.forEach(seatStr => { -// const seatArr: string[] = splitSeatStr(seatStr); -// // seats.push(parseInt(seatArr[5])); -// // x.push(parseInt(seatArr[2])); - -// const x = parseInt(seatArr[2]); - -// // Form: -// // 0: "568528" -> ID -// // 1: "568528" -> ID -// // 2: "21" -> X-Coord benutzen -// // 3: "7024" -> section ID -// // 4: "13" -> Reihenbezeichnung -// // 5: "4" -> Platznummer -// namingArr[x] = seatArr[5]; - - -// }); - -// // const row = seatArr[4]; -// // namingArr[index] = row; -// }); - -// // console.log(seats); -// // console.log(x); -// // console.log(Math.min.apply(Math, seats)); -// // console.log(Math.max.apply(Math, seats)); -// // console.log(Math.min.apply(Math, x)); -// // console.log(Math.max.apply(Math, x)); - -// // const minimum = Math.min.apply(Math, seats); -// // let i = 0; -// // for (let index = Math.min.apply(Math, x); index < Math.max.apply(Math, x); index++) { -// // // const element = array[index]; - -// // namingArr[index] = (minimum + i).toString(); -// // i++; -// // } - -// console.log(namingArr); -// return namingArr; -// } - export function generateMap(): string[] { const seatmapXML = config.state.seatmapXML; const layout: I.SeatmapLayout = seatmapXML.seatmap[0].layouts[0].layout[0]; @@ -130,9 +70,11 @@ export function generateMap(): string[] { return stringArrMatrix; } -export function generateLegend(inVenueXML: I.VenueXML, inSeatmapXML: any, inNode: string): I.JSCLegend { - const pricescaleArr: I.SeatmapPricescale[] = inSeatmapXML.seatmap[0].pricescale_config[0].pricescale; - const venuePricescaleArr: I.Pricescale2[] = inVenueXML.venue[0].pricescales[0].pricescale; +export function generateLegend(inNode: string): I.JSCLegend { + const seatmapXML = config.state.seatmapXML; + const venueXML = config.state.inVenueXML!; + const pricescaleArr: I.SeatmapPricescale[] = seatmapXML.seatmap[0].pricescale_config[0].pricescale; + const venuePricescaleArr: I.Pricescale2[] = venueXML.venue[0].pricescales[0].pricescale; let legend: I.JSCLegend = { node: jQuery(inNode), items: [] @@ -157,8 +99,10 @@ export function generateLegend(inVenueXML: I.VenueXML, inSeatmapXML: any, inNode return legend; } -export function setUnavailableSeats(inXML: any, seatmap: any): void { - const availabilityArr: I.JSCAvailability = inXML.seatmap[0].view_modes[0].view_mode[0].availability[0]; +export function setUnavailableSeats(): void { + const seatmapXML = config.state.seatmapXML; + const seatmap = config.state.seatmap; + const availabilityArr: I.JSCAvailability = seatmapXML.seatmap[0].view_modes[0].view_mode[0].availability[0]; if (availabilityArr.unavailable_unselectable_mask[0] === "") return; @@ -254,8 +198,9 @@ export function createArrMatrix(inNumrows: number, inNumcols: number, inInitial: return arr; } -export function addTrims(inSeatmapXML: any) { - const trimArr: I.Trim[] = inSeatmapXML.seatmap[0].trims[0].trim; +export function addTrims() { + const seatmapXML = config.state.seatmapXML; + const trimArr: I.Trim[] = seatmapXML.seatmap[0].trims[0].trim; trimArr.forEach(arr => { const [xTrim, yTrim] = arr.coord[0].split(",").map(Number); const textArr: string[] = arr.text[0].split(";").filter(Boolean); @@ -306,23 +251,24 @@ function applyTrim(x: number, y: number, i: number, character: string) { } } -export function selectSeatsInCart(inSeatmap: any) { +export function selectSeatsInCart() { + const seatmapXML = config.state.seatmapXML; config.state.selectedSeatsArr.forEach(arr => { const seatID: string = arr[0]; - if (inSeatmap.get(seatID)) - inSeatmap.status(seatID, "selected"); + if (seatmapXML.get(seatID)) + seatmapXML.status(seatID, "selected"); }); } -export function addSeatmap(inSelector: string, inMap: string[], inRowsNaming: string[], inSeats: I.JSCSeats, inLegend: I.JSCLegend, inSeatmap: any): void { +export function addSeatmap(inSelector: string, inMap: string[], inRowsNaming: string[], inSeats: I.JSCSeats, inLegend: I.JSCLegend): void { const containerSeatmap: any = (window).jQuery(inSelector); // console.log(inSeatmapInitMap); // console.log(inSeats); // console.log(inLegend); - inSeatmap = containerSeatmap.seatCharts({ + config.state.seatmap = containerSeatmap.seatCharts({ naming: { top: false, left: false, @@ -337,7 +283,7 @@ export function addSeatmap(inSelector: string, inMap: string[], inRowsNaming: st console.log(selectedSeat); - if (State.maximumSelectedSeatsReached(selectedSeat, inSeatmap)) + if (State.maximumSelectedSeatsReached(selectedSeat)) return "available"; State.addSeatToState(selectedSeat); diff --git a/client/src/modules/state.ts b/client/src/modules/state.ts index 3b7058c..e1ff737 100644 --- a/client/src/modules/state.ts +++ b/client/src/modules/state.ts @@ -44,10 +44,11 @@ export function removeSeatFromState(inSelectedSeat: I.JSCSelectedSeat) { jQuery("#modalCart-overlay").hide(); } -export function maximumSelectedSeatsReached(inSeatObj: I.JSCSelectedSeat, inSeatmap: any): boolean { +export function maximumSelectedSeatsReached(inSeatObj: I.JSCSelectedSeat): boolean { + const seatmap = config.state.seatmap; if (config.state.selectedSeatsArr.length >= config.maxSelectedSeats) { UI.showJBoxNotice(`Sie können maximal ${config.maxSelectedSeats} Plätze auswählen.`); - inSeatmap.status(inSeatObj.id, "available"); + seatmap.status(inSeatObj.id, "available"); return true; } diff --git a/client/src/modules/ui.ts b/client/src/modules/ui.ts index 6c7c799..17582d5 100644 --- a/client/src/modules/ui.ts +++ b/client/src/modules/ui.ts @@ -18,10 +18,11 @@ export function setOptionSelect(inSeatmapListing: I.Seatmap[], inId: string) { } } -export function setEventInfo(inEventInfo: I.EventInfo, inInputswithValue: I.InputsWithValue): void { +export function setEventInfo(inEventInfo: I.EventInfo): void { + const inputsWithValue = config.state.inputsWithValue!; jQuery("#eventInfoDesc span.fl-heading-text")[0].childNodes[0].textContent = inEventInfo.desc[0]; jQuery("#eventInfoDate p")[0].childNodes[0].textContent = inEventInfo.start[0]; - jQuery("#eventInfoLocation p")[0].childNodes[0].textContent = inInputswithValue.venueLocation; + jQuery("#eventInfoLocation p")[0].childNodes[0].textContent = inputsWithValue.venueLocation; jQuery("#eventInfoCapacity p")[0].childNodes[0].textContent = `Verfügbare Plätze: ${inEventInfo.seats_available} von ${inEventInfo.venue_config_capacity[0]}`; } @@ -150,9 +151,10 @@ export function addPanzoom(inSelector: string, inBtnZoomIn: string | null = null return undefined; } -export function changeVenueImage(inInputsWithValue: I.InputsWithValue) { - if (inInputsWithValue.venueImageSrc !== undefined) - jQuery("#venueImage img").attr("src", inInputsWithValue.venueImageSrc); +export function changeVenueImage() { + const inputsWithValue = config.state.inputsWithValue!; + if (inputsWithValue.venueImageSrc !== undefined) + jQuery("#venueImage img").attr("src", inputsWithValue.venueImageSrc); } export function showHideBtnCartLoading(inSwitch: string) { diff --git a/client/src/modules/utils.ts b/client/src/modules/utils.ts index 7e15f7f..8025126 100644 --- a/client/src/modules/utils.ts +++ b/client/src/modules/utils.ts @@ -99,12 +99,6 @@ export default class Utils { static getDayName(date: Date, locale: string) { return date.toLocaleDateString(locale, { weekday: 'long' }); - } - - static generateRandomColor(): string { - const randomNumber: number = Math.floor((Math.random() * 10000) + 1); - const hue = randomNumber * 137.508; // use golden angle approximation - return `hsl(${hue},100%,75%)`; - } + } } diff --git a/client/src/seatmap.ts b/client/src/seatmap.ts index ceef108..137399d 100644 --- a/client/src/seatmap.ts +++ b/client/src/seatmap.ts @@ -77,7 +77,6 @@ function messageHandler(inE: any) { case "parent_init_sendVenueXML": { config.state.inVenueXML = data.message.map_response; const venueXML = config.state.inVenueXML!; - const inputsWithValue = config.state.inputsWithValue!; // Generate pricescale css classes const css = XMLHelper.generatePricescaleCSS(); @@ -85,7 +84,7 @@ function messageHandler(inE: any) { // Fill event info const eventInfo = XMLHelper.getEventInfo(); - UI.setEventInfo(eventInfo, inputsWithValue); + UI.setEventInfo(eventInfo); // Fill select dropdown const seatmapListing: I.Seatmap[] = venueXML.seatmap_config[0].seatmap; @@ -104,29 +103,24 @@ function messageHandler(inE: any) { case "parent_init_sendInputsWithValue": { config.state.inputsWithValue = data.message; - const inputsWithValue = config.state.inputsWithValue!; - - UI.changeVenueImage(inputsWithValue!); + UI.changeVenueImage(); Communication.sendEventToParent("child_init_needVenueXML"); break; } case "parent_sendSeatmapXML": { config.state.seatmapXML = data.message.map_response; - const seatmapXML = config.state.seatmapXML; - const venueXML = config.state.inVenueXML!; - const seatmap = config.state.seatmap; const map: string[] = JSC.generateMap(); const rowsNaming: string[] = JSC.getRowsNaming(); const seats: I.JSCSeats = JSC.getSeats(); - const legend: I.JSCLegend = JSC.generateLegend(venueXML, seatmapXML, "#JSCLegendInner"); + const legend: I.JSCLegend = JSC.generateLegend("#JSCLegendInner"); - JSC.addSeatmap("#containerSeatmapInner", map, rowsNaming, seats, legend, seatmap); - JSC.setUnavailableSeats(seatmapXML, seatmap); - JSC.selectSeatsInCart(seatmap); + JSC.addSeatmap("#containerSeatmapInner", map, rowsNaming, seats, legend); + JSC.setUnavailableSeats(); + JSC.selectSeatsInCart(); UI.convertLegendToDropdown("dropdownLegend"); Events.dropdownLegendOnChange("#dropdownLegend"); - JSC.addTrims(seatmapXML); + JSC.addTrims(); XMLHelper.processSMAP(); config.state.panzoom = UI.addPanzoom("#containerSeatmapInner", ".panzoomZoomIn", ".panzoomZoomOut", "#panzoomResetZoom"); UI.controlLoftloader("hide");