Skip to content

Commit

Permalink
working whitelist import
Browse files Browse the repository at this point in the history
  • Loading branch information
fantinodavide committed Jun 16, 2022
1 parent e825297 commit 1b50157
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 21 deletions.
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ function main() {

if (err) console.log("error", err)//serverError(res, err);
else if (dbResC != null) {
if (dbResC.player_count == '' || dbResC.player_count < parseInt(dbResC.player_limit)) {
if (dbResC.player_limit == '' || dbResC.player_count < parseInt(dbResC.player_limit) || req.userSession.access_level <= 5) {
let insWlPlayer = {
id_clan: dbResC._id,
username: parm.username,
Expand Down
7 changes: 5 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
<editGameGroup v-if="popups.editGameGroup" @cancelBtnClick="popups.editGameGroup = false" :group_data="game_groups[inEditingGroup]" @edited="game_groups[inEditingGroup] = $event" />
<editClanUsers v-if="popups.editClanUsers" :clan_data="clans[inUserEditingClan]" @cancelBtnClick="popups.editClanUsers = false" />
<addNewWhitelistUser v-if="popups.addNewWhitelistUser" @cancelBtnClick="popups.addNewWhitelistUser = false" :add_data="tabData.Whitelist.add_data" />
<importWhitelist v-if="popups.importWhitelist" @cancelBtnClick="popups.importWhitelist = false" />
<importWhitelist v-if="popups.importWhitelist" @cancelBtnClick="popups.importWhitelist = false" :add_data="tabData.Whitelist.add_data" />
</blackoutBackground>

<!--<button @click="setLoginRequired(!loginRequired)">Toggle</button>-->
Expand Down Expand Up @@ -312,7 +312,10 @@
tabData.Whitelist.add_data = $event;
"
@confirm="removeWhitelistPlayer"
@import_whitelist="popups.importWhitelist = true"
@import_whitelist="
popups.importWhitelist = true;
tabData.Whitelist.add_data = $event;
"
/>
</tab>
<tab v-else-if="currentTab == 'Approvals'" :currentTab="currentTab">
Expand Down
8 changes: 8 additions & 0 deletions src/assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ label {
.overflow {
overflow: auto;
}
.overflow.y {
overflow: hidden;
overflow-y: auto;
}
.overflow.x {
overflow: hidden;
overflow-x: auto;
}

.hoverMenu {
position: absolute;
Expand Down
135 changes: 118 additions & 17 deletions src/components/importWhitelist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,69 @@
confBtnText: 'Next',
},
{
title: 'Import',
title: 'Player Names',
confBtnText: 'Import',
},
],
currentStep: 0,
importFoundGroups: [] as Array<any>,
parListImport: [] as Array<any>,
game_groups: [] as Array<any>,
conv_gameGroups: {} as any,
player_name_conv: {} as any,
};
},
props: {
add_data: {
required: true,
type: Object,
},
},
methods: {
confirmBtnClick(dt: any) {
if (this.currentStep < this.importSteps.length - 1) {
this.currentStep++;
confirmBtnClick: function (dt: any) {
if (this.currentStep == 0) {
const listImport = this.$el
.querySelector('textarea')
.value.split('\n')
.filter((a: any) => a != '' && a.startsWith('Admin'));
const reg = /^Admin=(?<steamid>\d{17}):(?<group>.[a-zA-Z_]{1,})((\s\/{2}\s?)(?<comment>.{1,}))?/gm;
listImport.forEach((elm: any, key: any) => {
const r = elm;
const regRes = this.regexExec(r, reg) as any;
const regResGr = regRes.groups;
this.parListImport.push(regResGr);
if (!this.importFoundGroups.includes(regResGr.group)) this.importFoundGroups.push(regResGr.group);
});
this.parListImport = this.parListImport.filter((a: any) => a != null);
console.log('List Import', this.parListImport);
// console.log('Found Groups', this.importFoundGroups);
} else if (this.currentStep == 1) {
for (let fg of this.importFoundGroups) {
this.conv_gameGroups[fg] = dt['sel-' + fg];
}
console.log(this.conv_gameGroups);
} else if (this.currentStep == 2) {
console.log(dt);
this.player_name_conv = dt;
}
if (this.currentStep == 1) {
const listImport = this.$el
.querySelector('textarea')
.value.split('\n')
.filter((a: any) => a != '' && a.startsWith('Admin'));
let parListImport = [] as Array<any>;
const reg = /^Admin=(?<steamid>\d{17}):(?<group>.[a-zA-Z_]{1,})((\s\/{2}\s?)(?<comment>.{1,}))?/gm;
if (this.currentStep + 1 < this.importSteps.length) this.currentStep++;
else {
const delay = 50;
let c = 0;
for (let p of this.parListImport) {
const player = {
username: this.player_name_conv[p.steamid],
steamid64: p.steamid,
group: this.conv_gameGroups[p.group],
sel_clan_id: this.add_data.sel_clan,
};
console.log('Importing whitelist', player);
listImport.forEach((elm: any, key: any) => {
const r = elm;
const regRes = reg.exec(r);
parListImport.push(regRes?.groups);
});
console.log('List Import', listImport, parListImport);
setTimeout(() => {
this.requestAddToWhitelist(player);
}, delay * c++);
}
}
// console.log(dt);
Expand All @@ -65,6 +102,49 @@
// },
// });
},
requestAddToWhitelist: function (dt: any) {
$.ajax({
url: '/api/whitelist/write/addPlayer',
type: 'post',
data: JSON.stringify(dt),
dataType: 'json',
contentType: 'application/json',
timeout: 60000,
success: (dt) => {
if (dt.status == 'inserted_new_player') {
const plDt = { ...dt.player, group_full_data: this.game_groups.filter((g) => g._id == dt.player.id_group) };
console.log(plDt);
this.add_data.callback(plDt);
this.$emit('cancelBtnClick');
} else {
console.error(dt);
this.$emit('cancelBtnClick');
}
},
error: (err) => {
console.error(err);
this.$emit('cancelBtnClick');
},
});
},
regexExec: function (str: string, regex: RegExp) {
if (str.match(regex)) {
const r = regex.exec(str);
if (r == null) this.regexExec(str, regex);
else return r;
} else return null;
},
getGameGroups: function () {
fetch('/api/gameGroups/read/getAllGroups')
.then((res) => res.json())
.then((dt) => {
console.log('Game Groups', dt);
this.game_groups = dt;
});
},
},
created() {
this.getGameGroups();
},
components: { popup },
};
Expand All @@ -74,6 +154,20 @@
<popup id="popup" :class="{ big: currentStep == 0 }" ref="popupComp" title="Import List" :confirmText="importSteps[currentStep].confBtnText" @cancelBtnClick="$emit('cancelBtnClick', $event)" @confirmBtnClick="confirmBtnClick">
<h3>{{ importSteps[currentStep].title }}</h3>
<textarea ref="txtList" v-show="currentStep == 0" placeholder="Paste here your whitelist"></textarea>
<div v-if="currentStep == 1">
<div v-for="g of importFoundGroups" class="grTranslation">
<span class="tag">{{ g }}</span>
<select :name="'sel-' + g">
<option v-for="allG of game_groups" :value="allG._id">{{ allG.group_name }}</option>
</select>
</div>
</div>
<div v-if="currentStep == 2" class="overflow">
<div v-for="p of parListImport" class="grTranslation">
<input :name="p.steamid" type="text" :value="p.comment.split(' ')[0]" /><span class="tag">{{ game_groups.filter((g) => g._id == conv_gameGroups[p.group])[0].group_name }}</span
><span class="tag">{{ p.steamid }}</span>
</div>
</div>
</popup>
</template>

Expand All @@ -93,4 +187,11 @@
flex-grow: 1;
white-space: nowrap;
}
.grTranslation {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
align-items: center;
justify-content: center;
}
</style>
2 changes: 1 addition & 1 deletion src/components/whitelistTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<select name="clan_selector" ref="clan_selector" :disabled="whitelist_clans.length == 1" @change="selectClanChanged">
<option v-for="c of whitelist_clans" :value="c._id">{{ c.full_name }}</option>
</select>
<button v-if="editor" @click="$emit('import_whitelist')">Import</button>
<button v-if="editor" @click="$emit('import_whitelist', { sel_clan: sel_clan, callback: appendPlayer })">Import</button>
<span class="playerCounter">{{ sel_clan_obj.player_count }}/ {{ sel_clan_obj.player_limit && sel_clan_obj.player_limit != '' ? sel_clan_obj.player_limit : '&infin;' }}</span>
</div>

Expand Down

0 comments on commit 1b50157

Please sign in to comment.