Skip to content

Commit

Permalink
✨ [missionKeywords] allow as prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jxn-30 committed Sep 23, 2020
1 parent a08e1d9 commit 7598eb8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 13 deletions.
14 changes: 10 additions & 4 deletions src/modules/extendedCallWindow/assets/missionKeywords.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export default (
LSSM: Vue,
settings: { keyword: string; color: string; missions: number[] }[]
settings: {
keyword: string;
color: string;
prefix: boolean;
missions: number[];
}[]
): void => {
const missionHelpBtn = document.getElementById('mission_help');
const missionTitle = document.getElementById('missionH1');
Expand All @@ -12,7 +17,7 @@ export default (
);
if (missionType < 0) return;

const addLabel = (text: string, color: string) => {
const addLabel = (text: string, color: string, prefix: boolean) => {
const label = document.createElement('span');
label.classList.add('label');
label.style.backgroundColor = color;
Expand All @@ -23,11 +28,12 @@ export default (
textNode.style.color = 'transparent';
textNode.style.filter = 'invert(1) grayscale(1) contrast(9)';
label.appendChild(textNode);
missionTitle.appendChild(label);
if (!prefix) missionTitle.appendChild(label);
else missionTitle.insertBefore(label, missionTitle.firstChild);
};

settings.forEach(s => {
if (!s.missions.includes(missionType)) return;
addLabel(s.keyword, s.color);
addLabel(s.keyword, s.color, s.prefix);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
{{ updateName }}
</span>
</span>
<div>
<toggle-button
labels
v-model="updatePrefix"
class="pull-right"
></toggle-button>
</div>
<v-select
placeholder="types"
:multiple="true"
Expand Down Expand Up @@ -80,6 +87,14 @@ export default Vue.extend<
this.$emit('input', { ...this.value, color });
},
},
updatePrefix: {
get(): SettingsItemComputed['updatePrefix'] {
return this.value.prefix;
},
set(prefix) {
this.$emit('input', { ...this.value, prefix });
},
},
updateMissions: {
get(): SettingsItemComputed['updateMissions'] {
return (this.value.missions
Expand Down Expand Up @@ -111,14 +126,14 @@ export default Vue.extend<
);
},
},
beforeMount() {
this.$store.dispatch('api/getMissions', false).then(
(missions: Mission[]) =>
(this.missions = missions.map(({ id, name }) => ({
value: id,
label: `${name} (ID: ${id})`,
})))
);
async beforeMount() {
this.missions = ((await this.$store.dispatch(
'api/getMissions',
false
)) as Mission[]).map(({ id, name }) => ({
value: id,
label: `${name} (ID: ${id})`,
}));
},
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<b>{{
$t('modules.extendedCallWindow.settings.missionKeywords.preview')
}}</b>
<b>{{
$t('modules.extendedCallWindow.settings.missionKeywords.prepend')
}}</b>
<b>{{
$t('modules.extendedCallWindow.settings.missionKeywords.missions')
}}</b>
Expand Down
1 change: 1 addition & 0 deletions src/modules/extendedCallWindow/i18n/de_DE.root.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"description": "Lasse dir ein eigenes Stichwort neben dem Einsatznamen anzeigen",
"keyword": "Stichwort",
"color": "Hintergrundfarbe",
"prepend": "Vor dem Einsatznamen anzeigen",
"missions": "Einsätze",
"preview": "Vorschau"
},
Expand Down
8 changes: 7 additions & 1 deletion src/modules/extendedCallWindow/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default (async (LSSM, MODULE_ID, $m) => {
defaultItem: {
keyword: '',
color: '#777777',
prefix: false,
missions: [],
},
},
Expand Down Expand Up @@ -193,7 +194,12 @@ export default (async (LSSM, MODULE_ID, $m) => {
).default(LSSM, getSetting, $m);

const missionKeywordsSettings = await getSetting<
{ keyword: string; color: string; missions: number[] }[]
{
keyword: string;
color: string;
prefix: boolean;
missions: number[];
}[]
>('missionKeywords');

if (missionKeywordsSettings.length)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface item {
keyword: string;
color: string;
prefix: boolean;
missions: number[];
}

Expand All @@ -20,6 +21,7 @@ export interface SettingsItemProps {
export interface SettingsItemComputed {
updateName: item['keyword'];
updateColor: item['color'];
updatePrefix: item['prefix'];
updateMissions: Option[];
selectableMissions: Option[];
}

0 comments on commit 7598eb8

Please sign in to comment.