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 5 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 @@ -15,4 +15,3 @@ src/config.js
static/fontawesome_*.min.js

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
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 units 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 excludedUnits: 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.excludedUnits = await settings.getSetting<string[]>({
moduleId,
settingId: 'excludeUnits',
defaultValue: [],
});
}

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

public isVehicleTypeExcluded(typeId: number) {
return this.excludedUnits.some(id => Number(id) === typeId);
}
}
138 changes: 138 additions & 0 deletions src/modules/nameSchema/assets/helper/numeral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* 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(65 + 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.
*/
export const convertNumberToICAOAlpha = (num: number): string => {
const alphabet = [
'Alpha',
'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 % 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 % 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;
};
56 changes: 56 additions & 0 deletions src/modules/nameSchema/assets/helper/rename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { ModuleMainFunction } from 'typings/Module';

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

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

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

try {
await LSSM.$stores.api.request({
url: `/vehicles/${vehicleId}`,
feature: `${MODULE_ID}-rename-vehicle`,
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',
},
});

return {
newCaption,
};
} catch (e: unknown) {
if (e instanceof Response && e.type === 'opaqueredirect') {
// expected redirect
return {
newCaption,
};
}

// rethrow error
throw e;
}
}
}
Loading