Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔀🎉 nameSchema module as replacement for v3 renameFz #2872

Draft
wants to merge 23 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
eb6981a
✨ get vehicles and buildings by dispatch center
buffcode Feb 4, 2024
5c2a4e7
🗑️ remove renameFz module leftovers
buffcode Feb 4, 2024
73e54c9
📝 Update v3 comparison documentation
buffcode Feb 4, 2024
b8f2200
🎉 nameSchema module for template-based renaming of vehicles
buffcode Feb 4, 2024
c2e4838
Merge branch 'dev' into feat/name-schema
jxn-30 Feb 5, 2024
2f8699a
✨ integration of LiquidJS for templating
buffcode Feb 5, 2024
daafd02
📝 update docs to match new templating options, fix module name
buffcode Feb 5, 2024
211aef1
♻️ change wording from unit to vehicle
buffcode Feb 5, 2024
0050149
🍻 use padStart instead of custom padding function
buffcode Feb 5, 2024
41bbe52
🎨 move interfaces / types to typings
buffcode Feb 5, 2024
3603ceb
🐛 fix ICAO alphabet
buffcode Feb 5, 2024
bfe1bae
✨ remove duplicate whitespace after rendering
buffcode Feb 5, 2024
721065b
✨ add german and austrian phonetic alphabet
buffcode Feb 5, 2024
74cebc0
📝 fix docs
buffcode Feb 5, 2024
252f88a
✨ renaming of buildings
buffcode Feb 5, 2024
9eddbcc
📝 fix typos in docs
buffcode Feb 8, 2024
b47651b
✨ add dispatch to template variables, change default grouping for bui…
buffcode Feb 8, 2024
b0636b5
📝 update grouping options
buffcode Feb 8, 2024
8b43745
Merge branch 'dev' into feat/name-schema
buffcode Feb 8, 2024
fc53769
✨ import settings from v3 renameFz
buffcode Feb 9, 2024
95121bd
Merge remote-tracking branch 'refs/remotes/origin/dev' into feat/name…
buffcode Feb 29, 2024
2b486eb
🎨 fix ESLint style / component naming
buffcode Feb 29, 2024
2306051
Merge branch 'dev' into feat/name-schema
jxn-30 Mar 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ static/missions/*
static/releasenotes/*

src/modules/support/*
src/modules/renameFz/*
2 changes: 1 addition & 1 deletion docs/.vuepress/utils/v3Comparison.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"overview": { "module": "overview" },
"Redesign01": { "module": "redesign" },
"releaseNotes": { "module": "" },
"RenameFz": { "module": "nameSchema" },
"ShareAlliancePost": { "module": "shareAlliancePost" },
"showChatButtonAbove": {
"module": "chatExtras",
Expand All @@ -65,7 +66,6 @@
"Layout02",
"Layout03",
"Layout04",
"RenameFZ",
"WachenplanungOnMap",
"fms7Target",
"geoBorders",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"highcharts": "11.3.0",
"highcharts-vue": "1.4.3",
"leaflet.heat": "0.2.0",
"liquidjs": "10.10.0",
"localforage": "1.10.0",
"lodash": "4.17.21",
"mini-svg-data-uri": "1.4.4",
Expand Down
4 changes: 4 additions & 0 deletions src/generated/libraries.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@
"url": "https://github.com/Leaflet/Leaflet.heat",
"version": "0.2.0"
},
"liquidjs": {
"url": "https://github.com/harttle/liquidjs#readme",
"version": "10.10.0"
},
"local-web-server": {
"version": "5.3.1"
},
Expand Down
3 changes: 3 additions & 0 deletions src/modules/nameSchema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Name Schema

Provides bulk-renaming of vehicles and buildings.
39 changes: 39 additions & 0 deletions src/modules/nameSchema/assets/helper/exclusion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { ModuleMainFunction } from 'typings/Module';

export default class ExclusionHelper {
private excludedBuildings: string[] = [];
private excludedVehicles: string[] = [];

constructor(
private readonly moduleParams: Parameters<ModuleMainFunction>[0]
) {}

public async init() {
const {
MODULE_ID: moduleId,
LSSM: {
$stores: { settings },
},
} = this.moduleParams;

this.excludedBuildings = await settings.getSetting<string[]>({
moduleId,
settingId: 'excludeBuildings',
defaultValue: [],
});

this.excludedVehicles = await settings.getSetting<string[]>({
moduleId,
settingId: 'excludeVehicles',
defaultValue: [],
});
}

public isBuildingTypeExcluded(typeId: number) {
return this.excludedBuildings.some(id => Number(id) === typeId);
}

public isVehicleTypeExcluded(typeId: number) {
return this.excludedVehicles.some(id => Number(id) === typeId);
}
}
216 changes: 216 additions & 0 deletions src/modules/nameSchema/assets/helper/numeral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/**
* Convert a number to a roman numeral.
* @param num - Number to convert.
* @returns Roman numeral.
* @see https://stackoverflow.com/a/41358305
*/
export const convertNumberToRoman = (num: number): string => {
const roman: Record<string, number> = {
M: 1000,
CM: 900,
D: 500,
CD: 400,
C: 100,
XC: 90,
L: 50,
XL: 40,
X: 10,
IX: 9,
V: 5,
IV: 4,
I: 1,
};
let str = '';
let rest = num;

for (const i of Object.keys(roman)) {
const q = Math.floor(rest / roman[i]);
rest -= q * roman[i];
str += i.repeat(q);
}

return str;
};

/**
* Convert a number to a string of letters.
* @param num - Number to convert.
* @returns String of letters.
*/
export const convertNumberToAlpha = (num: number): string => {
let str = '';
let rest = num;

do {
const q = rest % 26;
rest = Math.floor(rest / 26);
str = String.fromCharCode(64 + q) + str;
} while (rest > 0);

return str;
};

/**
* Convert a number to ICAO alphabet word.
buffcode marked this conversation as resolved.
Show resolved Hide resolved
* @param num - Number to convert.
* @returns ICAO alphabet word.
* @see https://de.wikipedia.org/wiki/ICAO-Alphabet
*/
export const convertNumberToICAOAlpha = (num: number): string => {
const alphabet = [
'Alfa',
'Bravo',
'Charlie',
'Delta',
'Echo',
'Foxtrot',
'Golf',
'Hotel',
'India',
'Juliett',
'Kilo',
'Lima',
'Mike',
'November',
'Oscar',
'Papa',
'Quebec',
'Romeo',
'Sierra',
'Tango',
'Uniform',
'Victor',
'Whiskey',
'X-Ray',
'Yankee',
'Zulu',
];
return alphabet[(num - 1) % alphabet.length];
};

/**
* Convert a number to a greek letter.
* @param num - Number to convert.
* @returns Greek letter.
*/
export const convertNumberToGreek = (num: number): string => {
const alphabet = [
'Alpha',
'Beta',
'Gamma',
'Delta',
'Epsilon',
'Zeta',
'Eta',
'Theta',
'Iota',
'Kappa',
'Lambda',
'My',
'Ny',
'Xi',
'Omikron',
'Pi',
'Rho',
'Sigma',
'Tau',
'Ypsilon',
'Phi',
'Chi',
'Psi',
'Omega',
];
return alphabet[(num - 1) % alphabet.length];
};

/**
* Convert a string number to a string of emoji digits.
* @param string - String number to convert.
* @returns String of emoji digits.
*/
export const convertStringNumberToEmoji = (string: string): string => {
const emojiNum = (digit: number) =>
`${String.fromCodePoint(48 + (digit % 10))}\ufe0f\u20e3`;

let str = '';
for (const element of string) str += emojiNum(Number(element));

return str;
};

/**
* Convert a number to a german phonetic alphabet word.
* @param num - Number to convert.
* @returns German phonetic alphabet word.
* @see https://de.wikipedia.org/wiki/Buchstabiertafel
*/
export const convertNumberToGermanPhonetic = (num: number): string => {
const alphabet = [
'Anton',
'Berta',
'Cäsar',
'Dora',
'Emil',
'Friedrich',
'Gustav',
'Heinrich',
'Ida',
'Julius',
'Kaufmann',
'Ludwig',
'Martha',
'Nordpol',
'Otto',
'Paula',
'Quelle',
'Richard',
'Samuel',
'Theodor',
'Ulrich',
'Viktor',
'Wilhelm',
'Xanthippe',
'Ypsilon',
'Zacharias',
Cr4zyc4k3 marked this conversation as resolved.
Show resolved Hide resolved
];

return alphabet[(num - 1) % alphabet.length];
};

/**
* Convert a number to an austrian phonetic alphabet word.
* @param num - Number to convert.
* @returns Austrian phonetic alphabet word.
* @see https://de.wikipedia.org/wiki/Buchstabiertafel
*/
export const convertNumberToAustrianPhonetic = (num: number): string => {
const alphabet = [
'Anton',
'Berta',
'Cäsar',
'Dora',
'Emil',
'Friedrich',
'Gustav',
'Heinrich',
'Ida',
'Julius',
'Konrad',
'Ludwig',
'Martha',
'Nordpol',
'Otto',
'Paula',
'Richard',
'Siegfried',
'Theodor',
'Ulrich',
'Viktor',
'Wilhelm',
'Xaver',
'Ypsilon',
'Zürich',
];

return alphabet[(num - 1) % alphabet.length];
};
63 changes: 63 additions & 0 deletions src/modules/nameSchema/assets/helper/rename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { ModuleMainFunction } from 'typings/Module';

export default class RenameHelper {
constructor(
private readonly moduleParams: Parameters<ModuleMainFunction>[0]
) {}

private async request(url: URL, feature: string) {
const { LSSM, MODULE_ID } = this.moduleParams;

url.searchParams.append('_method', 'put');
url.searchParams.append('utf8', '✓');
url.searchParams.append(
'authenticity_token',
document
.querySelector('meta[name="csrf-token"]')
?.getAttribute('content') || ''
);

try {
await LSSM.$stores.api.request({
url: url.pathname,
feature: `${MODULE_ID}-${feature}`,
dialogOnError: false,
init: {
redirect: 'manual',
credentials: 'include',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Upgrade-Insecure-Requests': '1',
},
referrer: window.location.href,
body: url.searchParams.toString(),
method: 'POST',
mode: 'cors',
},
});
} catch (e: unknown) {
if (e instanceof Response && e.type === 'opaqueredirect') {
// expected redirect
return;
}

// rethrow error
throw e;
}
}

public async renameVehicle(vehicleId: number, newCaption: string) {
const url = new URL(`/vehicles/${vehicleId}`, window.location.origin);

url.searchParams.append('vehicle[caption]', newCaption);

return this.request(url, 'rename-vehicle');
}
public async renameBuilding(buildingId: number, newCaption: string) {
const url = new URL(`/buildings/${buildingId}`, window.location.origin);

url.searchParams.append('building[name]', newCaption);

return this.request(url, 'rename-building');
}
}
Loading
Loading