revised parser
This commit is contained in:
@@ -88,15 +88,7 @@ export function generateLegend(inNode: string): I.JSCLegend {
|
||||
}
|
||||
}
|
||||
|
||||
function createLegendItems(pricescaleArr: I.SeatmapPricescale[], venuePricescaleArr: I.Pricescale2[]): string[][] {
|
||||
return pricescaleArr.map((arr, index: number) => {
|
||||
const id: string = arr.id[0];
|
||||
const seatsKey: string = String.fromCharCode(97 + index).toLocaleUpperCase();
|
||||
const desc: string | undefined = venuePricescaleArr.find(obj => obj.id[0] === id)?.desc[0];
|
||||
const description: string = `${desc} €${pricescaleArr[index].ref_price[0]}`;
|
||||
return [seatsKey, "available", description];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function setUnavailableSeats(): void {
|
||||
const seatmapXML: any = config.state.seatmapXML;
|
||||
@@ -109,6 +101,80 @@ export function setUnavailableSeats(): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function getSeatsKey(inSeatID: string, inPricescaleArr: I.SeatmapPricescale[]): string | undefined {
|
||||
for (let key in inPricescaleArr) {
|
||||
if (inPricescaleArr[key].mask[0].includes(inSeatID))
|
||||
return String.fromCharCode(97 + parseInt(key)).toLocaleUpperCase();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function splitSeatStr(inSeatStr: string): string[] {
|
||||
return inSeatStr.split(",").map((item) => item.trim());
|
||||
}
|
||||
|
||||
export function createArrMatrix(inNumrows: number, inNumcols: number, inCharacter: string): string[][] {
|
||||
// let matrixArr: string[][] = [];
|
||||
|
||||
// for (let i: number = 0; i < inNumrows; ++i) {
|
||||
// let columns: string[] = [];
|
||||
|
||||
// for (let j: number = 0; j < inNumcols; ++j)
|
||||
// columns[j] = inCharacter;
|
||||
|
||||
// matrixArr[i] = columns;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// return matrixArr;
|
||||
|
||||
return Array(inNumrows).fill(null).map(() => Array(inNumcols).fill(inCharacter));
|
||||
}
|
||||
|
||||
export function selectSeatsInCart(): void {
|
||||
const seatmap: any = config.state.seatmap;
|
||||
config.state.selectedSeatsArr.forEach(arr => {
|
||||
const seatID: string = arr[0];
|
||||
|
||||
if (seatmap.get(seatID))
|
||||
seatmap.status(seatID, "selected");
|
||||
});
|
||||
}
|
||||
|
||||
export function addSeatmap(inSelector: string, inMap: string[], inRowsNaming: string[], inSeats: I.JSCSeats, inLegend: I.JSCLegend): void {
|
||||
const containerSeatmap: any = (<any>window).jQuery(inSelector);
|
||||
|
||||
// console.log(inSeatmapInitMap);
|
||||
// console.log(inSeats);
|
||||
// console.log(inLegend);
|
||||
|
||||
config.state.seatmap = containerSeatmap.seatCharts({
|
||||
naming: {
|
||||
top: false,
|
||||
left: false,
|
||||
rows: inRowsNaming,
|
||||
},
|
||||
map: inMap,
|
||||
seats: inSeats,
|
||||
legend: inLegend,
|
||||
click: function () {
|
||||
return clickedSeat(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createLegendItems(pricescaleArr: I.SeatmapPricescale[], venuePricescaleArr: I.Pricescale2[]): string[][] {
|
||||
return pricescaleArr.map((arr, index: number) => {
|
||||
const id: string = arr.id[0];
|
||||
const seatsKey: string = String.fromCharCode(97 + index).toLocaleUpperCase();
|
||||
const desc: string | undefined = venuePricescaleArr.find(obj => obj.id[0] === id)?.desc[0];
|
||||
const description: string = `${desc} €${pricescaleArr[index].ref_price[0]}`;
|
||||
return [seatsKey, "available", description];
|
||||
});
|
||||
}
|
||||
|
||||
function enterSeatsInMatrix(inRows: I.LayoutRow2[], inArrMatrix: string[][], inPricescaleArr: I.SeatmapPricescale[], inAvailabilityArr: I.JSCAvailability): string[][] {
|
||||
const availableArr: string[] = inAvailabilityArr.available_selectable_mask[0].split(",");
|
||||
const unavailableArr: string[] = inAvailabilityArr.unavailable_unselectable_mask[0].split(",");
|
||||
@@ -142,7 +208,7 @@ function enterSeatsInMatrix(inRows: I.LayoutRow2[], inArrMatrix: string[][], inP
|
||||
|
||||
if (seatsKey)
|
||||
inArrMatrix[Y][X] = `${seatsKey}[${seatArr[0]}, ]`;
|
||||
|
||||
|
||||
|
||||
// save seatArr in state with seatID as key
|
||||
config.state.layoutRows[seatArr[0]] = seatArr;
|
||||
@@ -152,153 +218,40 @@ function enterSeatsInMatrix(inRows: I.LayoutRow2[], inArrMatrix: string[][], inP
|
||||
return inArrMatrix;
|
||||
}
|
||||
|
||||
export function getSeatsKey(inSeatID: string, inPricescaleArr: I.SeatmapPricescale[]): string | undefined {
|
||||
// for (let key in inPricescaleArr) {
|
||||
// if (inPricescaleArr[key].mask[0].includes(inSeatID))
|
||||
// return String.fromCharCode(97 + parseInt(key)).toLocaleUpperCase();
|
||||
// }
|
||||
|
||||
return inPricescaleArr.map((arr, index) => {
|
||||
if (arr.mask[0].includes(inSeatID))
|
||||
return String.fromCharCode(97 + index).toLocaleUpperCase();
|
||||
else
|
||||
return undefined;
|
||||
})[0];
|
||||
}
|
||||
|
||||
export function splitSeatStr(inSeatStr: string): string[] {
|
||||
return inSeatStr.split(",").map((item) => item.trim());
|
||||
}
|
||||
|
||||
export function createArrMatrix(inNumrows: number, inNumcols: number, inCharacter: string): string[][] {
|
||||
// let matrixArr: string[][] = [];
|
||||
|
||||
// for (let i: number = 0; i < inNumrows; ++i) {
|
||||
// let columns: string[] = [];
|
||||
|
||||
// for (let j: number = 0; j < inNumcols; ++j)
|
||||
// columns[j] = inCharacter;
|
||||
|
||||
// matrixArr[i] = columns;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// return matrixArr;
|
||||
|
||||
return Array(inNumrows).fill(null).map(() => Array(inNumcols).fill(inCharacter));
|
||||
}
|
||||
|
||||
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);
|
||||
const x = xTrim / 20;
|
||||
const y = Math.round(yTrim / 21.25);
|
||||
|
||||
console.log(`xTrim: ${xTrim} yTrim: ${yTrim} -> x: ${x} y: ${y}`);
|
||||
|
||||
decodeAddTrims(textArr, x, y);
|
||||
});
|
||||
}
|
||||
|
||||
function decodeAddTrims(textArr: string[], x: number, y: number) {
|
||||
let i = 0;
|
||||
const specialChar = new Map([
|
||||
["Ž", "Ä"],
|
||||
["™", "Ö"],
|
||||
["š", "Ü"],
|
||||
["„", "ä"],
|
||||
["”", "ö"],
|
||||
["", "ü"],
|
||||
["á", "ß"]
|
||||
]);
|
||||
|
||||
textArr.forEach(element => {
|
||||
let character;
|
||||
|
||||
if (specialChar.has(element))
|
||||
character = specialChar.get(element);
|
||||
else {
|
||||
const charCode = element.replace(/^\&\#/, "0");
|
||||
character = String.fromCharCode(parseInt(charCode, 16));
|
||||
}
|
||||
|
||||
if (character)
|
||||
applyTrim(x, y, i, character);
|
||||
|
||||
i++;
|
||||
});
|
||||
}
|
||||
|
||||
function applyTrim(x: number, y: number, i: number, character: string) {
|
||||
if (!/[^a-zA-Z0-9äöüÄÖÜß$]/.test(character)) {
|
||||
const _x = (x - 1) + i;
|
||||
const _y = y - 1;
|
||||
console.log(`${character} -> ${_x} ${_y}`);
|
||||
jQuery(".seatCharts-row")[_y].children[_x].innerHTML = `<span class="trimChar">${character}</span>`
|
||||
function clickedSeat(inSeatmap: any) {
|
||||
if (inSeatmap.status() == 'available') {
|
||||
return clickAvailableSeat(inSeatmap);
|
||||
}
|
||||
else if (inSeatmap.status() === "selected") {
|
||||
return clickedSelectedSeat(inSeatmap);
|
||||
}
|
||||
else if (inSeatmap.status() == 'unavailable') {
|
||||
return "unavailable";
|
||||
}
|
||||
else {
|
||||
return inSeatmap.style();
|
||||
}
|
||||
}
|
||||
|
||||
export function selectSeatsInCart() {
|
||||
const seatmapXML = config.state.seatmapXML;
|
||||
config.state.selectedSeatsArr.forEach(arr => {
|
||||
const seatID: string = arr[0];
|
||||
function clickAvailableSeat(inSeatmap: any) {
|
||||
const selectedSeat: I.JSCSelectedSeat = inSeatmap.settings;
|
||||
console.log(selectedSeat);
|
||||
|
||||
if (seatmapXML.get(seatID))
|
||||
seatmapXML.status(seatID, "selected");
|
||||
});
|
||||
if (State.maximumSelectedSeatsReached(selectedSeat))
|
||||
return "available";
|
||||
|
||||
State.addSeatToState(selectedSeat);
|
||||
Cart.calcOverallPrice();
|
||||
UI.setBtnCartText();
|
||||
|
||||
return "selected";
|
||||
}
|
||||
|
||||
export function addSeatmap(inSelector: string, inMap: string[], inRowsNaming: string[], inSeats: I.JSCSeats, inLegend: I.JSCLegend): void {
|
||||
const containerSeatmap: any = (<any>window).jQuery(inSelector);
|
||||
function clickedSelectedSeat(inSeatmap: any) {
|
||||
const selectedSeat: I.JSCSelectedSeat = inSeatmap.settings;
|
||||
State.removeSeatFromState(selectedSeat);
|
||||
Cart.calcOverallPrice();
|
||||
UI.setBtnCartText();
|
||||
|
||||
// console.log(inSeatmapInitMap);
|
||||
// console.log(inSeats);
|
||||
// console.log(inLegend);
|
||||
|
||||
config.state.seatmap = containerSeatmap.seatCharts({
|
||||
naming: {
|
||||
top: false,
|
||||
left: false,
|
||||
rows: inRowsNaming,
|
||||
},
|
||||
map: inMap,
|
||||
seats: inSeats,
|
||||
legend: inLegend,
|
||||
click: function () {
|
||||
if (this.status() == 'available') {
|
||||
const selectedSeat: I.JSCSelectedSeat = this.settings;
|
||||
|
||||
console.log(selectedSeat);
|
||||
|
||||
if (State.maximumSelectedSeatsReached(selectedSeat))
|
||||
return "available";
|
||||
|
||||
State.addSeatToState(selectedSeat);
|
||||
Cart.calcOverallPrice();
|
||||
UI.setBtnCartText();
|
||||
|
||||
return "selected";
|
||||
}
|
||||
else if (this.status() === "selected") {
|
||||
const selectedSeat: I.JSCSelectedSeat = this.settings;
|
||||
|
||||
State.removeSeatFromState(selectedSeat);
|
||||
Cart.calcOverallPrice();
|
||||
UI.setBtnCartText();
|
||||
console.log(config.state.selectedSeatsArr);
|
||||
|
||||
return "available";
|
||||
}
|
||||
else if (this.status() == 'unavailable') {
|
||||
return "unavailable";
|
||||
}
|
||||
else {
|
||||
return this.style();
|
||||
}
|
||||
}
|
||||
});
|
||||
return "available";
|
||||
}
|
||||
Reference in New Issue
Block a user