From 04cf55e4fed58af1d8d587835a0d7fe6500c34f1 Mon Sep 17 00:00:00 2001 From: zino Date: Wed, 24 Mar 2021 21:37:06 +0100 Subject: [PATCH] implemented check tick selected seat --- client/src/inject.ts | 1 + client/src/modules/communication.ts | 2 +- client/src/modules/jsc.ts | 57 +++++++-- client/src/modules/parser.ts | 35 ++++-- client/src/modules/ui.ts | 46 ++++++- client/src/modules/utils.ts | 44 ++++--- client/src/modules/{xml.ts => xmlhelper.ts} | 0 client/src/seatmap.ts | 127 ++++++++++++++------ client/src/types/types.d.ts | 16 ++- client/tsconfig.json | 2 +- 10 files changed, 252 insertions(+), 78 deletions(-) rename client/src/modules/{xml.ts => xmlhelper.ts} (100%) diff --git a/client/src/inject.ts b/client/src/inject.ts index 6cd975a..06c25d7 100644 --- a/client/src/inject.ts +++ b/client/src/inject.ts @@ -64,6 +64,7 @@ window.addEventListener('load', function () { Utils.inject(config.urlCSSParentStaging, "css", "body"); Communication.listenToMessages(messagesHandler); inputsWithValue = { ...inputsWithValue, ...Parser.getAdditionalInputs(content) }; + inputsWithValue = { ...inputsWithValue, ...Parser.getVenueImage() }; const importantNote = Parser.getImportantNote(); if (importantNote) diff --git a/client/src/modules/communication.ts b/client/src/modules/communication.ts index 01fee45..9e73efc 100644 --- a/client/src/modules/communication.ts +++ b/client/src/modules/communication.ts @@ -1,5 +1,5 @@ import * as I from "../types/types"; -import * as xml from "./xml"; +import * as xml from "./xmlhelper"; // rework try/catch ? export function sendMessage(data: I.Message, to: string): void { diff --git a/client/src/modules/jsc.ts b/client/src/modules/jsc.ts index bc8f6dc..74789e5 100644 --- a/client/src/modules/jsc.ts +++ b/client/src/modules/jsc.ts @@ -1,13 +1,12 @@ import * as I from "../types/types"; - export function getSeats(inXML: any): I.JSCSeats { const pricescaleArr: I.SeatmapPricescale[] = inXML.seatmap[0].pricescale_config[0].pricescale; let object: any = {}; for (let key in pricescaleArr) { const seatsObj: I.JSCSeats2 = { - "classes": "foobar", + "classes": `_${pricescaleArr[key].id[0]}`, "seatsObj": pricescaleArr[key] } const seatsKey: string = String.fromCharCode(97 + parseInt(key)).toLocaleUpperCase(); @@ -19,6 +18,17 @@ export function getSeats(inXML: any): I.JSCSeats { return seatmapInitSeats; } +export function activateSeatsBySectionID(inXML: any, seatmap: any, inValue: string, ) { + const pricescaleArr: I.SeatmapPricescale[] = inXML.seatmap[0].pricescale_config[0].pricescale; + + pricescaleArr.forEach(element => { + if (element.id[0] === inValue) { + const seatsArr = element.mask[0].split(","); + seatmap.status(seatsArr, "available"); + } + }); +} + export function getRows(inXML: any): number[] { const layout: I.SeatmapLayout = inXML.seatmap[0].layouts[0].layout[0]; const height: number = parseInt(layout.height[0]); @@ -41,6 +51,34 @@ export function generateMap(inXML: any): string[] { return stringArrMatrix; } +export function generateLegend(inXML: any, inNode: string): I.JSCLegend { + const pricescaleArr: I.SeatmapPricescale[] = inXML.seatmap[0].pricescale_config[0].pricescale; + console.log(pricescaleArr); + let legend: I.JSCLegend = { + node: jQuery(inNode), + items: [] + } + + for (let key in pricescaleArr) { + const seatsKey: string = String.fromCharCode(97 + parseInt(key)).toLocaleUpperCase(); + const price: string = `€${pricescaleArr[key].ref_price[0]}`; + const legendItem = [ seatsKey, "available", price ]; + legend.items.push(legendItem); + } + + 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]; + + if (availabilityArr.unavailable_unselectable_mask[0] === "") + return; + + const unavailableArr: string[] = availabilityArr.unavailable_unselectable_mask[0].split(","); + seatmap.status(unavailableArr, "unavailable"); +} + export function generateStringArrMatrix(inArrMatrix: string[][]): string[] { const stringArrMatrix: string[] = []; @@ -65,14 +103,15 @@ export function enterSeatsInMatrix(inRows: I.LayoutRow2[], inArrMatrix: string[] const seatArr: string[] = splitSeatStr(seatStr); // Form: - // 0: "568528" - // 1: "568528" - // 2: "21" - // 3: "7024" - // 4: "13" - // 5: "4" + // 0: "568528" -> ID + // 1: "568528" -> ID + // 2: "21" -> X-Coord benutzen + // 3: "7024" -> section ID + // 4: "13" -> Reihenbezeichnung + // 5: "4" -> ? - const X: number = parseInt(seatArr[5]); + // const X: number = parseInt(seatArr[5]); + const X: number = parseInt(seatArr[2]); const seatsKey = getSeatsKey(seatArr[0], inPricescaleArr); if (seatsKey) diff --git a/client/src/modules/parser.ts b/client/src/modules/parser.ts index 1e4c80a..bd643b1 100644 --- a/client/src/modules/parser.ts +++ b/client/src/modules/parser.ts @@ -1,8 +1,9 @@ import * as I from "../types/types"; +var jQuery = require("jquery"); export function getVenueLocation(): string { let span: string[] = []; - jQuery(".venue span").each(function () { + jQuery(".venue span").each(function (this: any) { span.push(jQuery(this).text()); }); @@ -25,15 +26,17 @@ export function getInputs(inContent: string): I.Inputs { // todo: check with different venues export function getImportantNote(): { importantNote: string, importantNoteEncoded: string } | undefined { - const importantNote: string | null = jQuery(".important_note")[0].textContent; + if (jQuery(".important_note").length) { + const importantNote: string | null = jQuery(".important_note")[0].textContent; - if (importantNote?.trim().length) { - const importantNoteEncoded: string = encodeURIComponent(importantNote); - return { - "importantNote": importantNote, - "importantNoteEncoded": importantNoteEncoded - } - } + if (importantNote?.trim().length) { + const importantNoteEncoded: string = encodeURIComponent(importantNote); + return { + "importantNote": importantNote, + "importantNoteEncoded": importantNoteEncoded + } + } + } return undefined; } @@ -54,4 +57,18 @@ export function getAdditionalInputs(inContent: string): { [key: string]: string "posturl": posturl, "venueLocation": venueLocation } +} + +export function getVenueImage(): { venueImageSrc: string, venueImageHeight: number, venueImageWidth: number } | undefined { + const img: HTMLImageElement = jQuery("#static_venue_map img").get(0); + + if (img) { + return { + venueImageSrc: img.src, + venueImageHeight: img.height, + venueImageWidth: img.width + } + } + + return undefined; } \ No newline at end of file diff --git a/client/src/modules/ui.ts b/client/src/modules/ui.ts index f1ef54c..56bf968 100644 --- a/client/src/modules/ui.ts +++ b/client/src/modules/ui.ts @@ -1,6 +1,7 @@ import * as I from "../types/types"; import * as Communication from "./communication"; import Panzoom from '@panzoom/panzoom'; +import { PanzoomObject } from "@panzoom/panzoom/dist/src/types"; export function setOptionSelect(inSeatmapListing: I.Seatmap[], inId: string) { const seatmapDropdown: HTMLElement | null = document.getElementById(inId); @@ -72,10 +73,35 @@ export function injectBookingBtn(): void { `); } -export function destroyCurrentSeatmap(): void { +export function convertLegendToDropdown(inID: string) { + jQuery('ul.seatCharts-legendList').each(function() { + let select = jQuery(document.createElement('select')).insertBefore(jQuery(this).hide()); + select.attr({ id: inID}); + let option = jQuery('