Skip to content

Commit

Permalink
spa fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed May 25, 2024
1 parent c8e98ba commit 7fa607a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 67 deletions.
49 changes: 11 additions & 38 deletions resources/assets/js/components/servers/DsIpSelector.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<div>
<input type="hidden" :name="dsIdFieldName" v-model="selectedDs" />
<input type="hidden" :name="serverIpFieldName" v-model="selectedIp" />
<input type="hidden" :name="dsIdFieldName" v-model="nodeIdModel" />
<input type="hidden" :name="serverIpFieldName" v-model="ipModel" />

<n-form-item :path="nodeIdPath">
<n-select
v-model:value="selectedDs"
v-model:value="nodeIdModel"
:disabled="nodeSelectDisabled"
:options="nodesOptions"
:placeholder="trans('labels.ds_id')"
Expand All @@ -14,8 +14,8 @@

<n-form-item :path="ipPath" :show-label="false">
<n-select
v-model:value="selectedIp"
:disabled="!selectedDs"
v-model:value="ipModel"
:disabled="!nodeIdModel"
:options="ipListOptions"
:placeholder="trans('labels.ip')"
/>
Expand All @@ -24,7 +24,7 @@
</template>

<script setup>
import { computed, watch, onMounted } from 'vue'
import { computed, watch } from 'vue'
import { useStore } from 'vuex'
import {NFormItem} from "naive-ui"
Expand Down Expand Up @@ -61,45 +61,18 @@
return ipList.value.map((ip) => ({ value: ip, label: ip }));
});
const selectedDs = computed({
get: () => {
if (
!store.state.dedicatedServers.dsId ||
store.state.dedicatedServers.dsId === ""
) {
return null;
}
return store.state.dedicatedServers.dsId
},
set: (dsId) => store.dispatch('dedicatedServers/setDsId', dsId)
});
const selectedIp = computed({
get: () => store.state.servers.ip,
set: (ip) => store.dispatch('servers/setIp', ip)
});
watch(ipList, (list) => {
if (list.length >= 1 && !list.includes(selectedIp.value)) {
selectedIp.value = list[0];
if (list.length >= 1 && !list.includes(ipModel.value)) {
ipModel.value = list[0];
}
});
watch(selectedDs, (val) => {
nodeIdModel.value = val;
store.dispatch('dedicatedServers/fetchIpList');
});
watch(selectedIp, (val) => {
ipModel.value = val;
});
watch(nodeIdModel, (val) => {
selectedDs.value = val;
store.dispatch('dedicatedServers/setDsId', nodeIdModel.value);
store.dispatch('dedicatedServers/fetchIpList');
});
watch(ipModel, (val) => {
selectedIp.value = val;
store.dispatch('servers/setIp', ipModel.value)
});
</script>
12 changes: 11 additions & 1 deletion resources/assets/js/components/servers/GameModSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</template>

<script setup>
import { computed, watch, defineModel } from 'vue';
import { computed, watch, defineModel, onUnmounted } from 'vue';
import { useStore } from 'vuex';
import {trans} from "../../i18n/i18n";
import {NFormItem} from "naive-ui";
Expand All @@ -51,6 +51,11 @@
const gameModsList = computed(() => store.state.gameMods.gameModsList);
onUnmounted(() => {
store.dispatch('gameMods/setGameMod', null)
store.dispatch('games/setGameCode', null)
});
const renderGameLabel = (option) => {
return [
h(GameIcon, {game: option.value, class: 'mr-2'}),
Expand All @@ -67,9 +72,14 @@
});
watch(gameModel, () => {
store.dispatch('games/setGameCode', gameModel.value)
store.dispatch('gameMods/fetchGameModsList', gameModel.value);
});
watch(gameModModel, () => {
store.dispatch('gameMods/setGameMod', gameModModel.value)
});
watch(gameModsList, (val) => {
let mod = null
if (val.length > 0) {
Expand Down
52 changes: 26 additions & 26 deletions resources/assets/js/components/servers/SmartPortSelector.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<div>
<n-form-item :label="trans('labels.server_port')" :path="serverPortPath">
<input class="block appearance-none w-full py-1 px-2 mb-1 leading-normal bg-white text-gray-800 border border-gray-200 rounded" name="server_port" type="number" id="server_port" min="1024" max="65535" v-model="serverPort">
<template #feedback>
<span v-if="serverPortWarning" class="help-block"><strong>{{ serverPortWarning }}</strong></span>
</template>
</n-form-item>
<n-form-item :label="trans('labels.server_port')" :path="serverPortPath">
<input class="block appearance-none w-full py-1 px-2 mb-1 leading-normal bg-white text-gray-800 border border-gray-200 rounded" name="server_port" type="number" id="server_port" min="1024" max="65535" v-model="serverPort">
<template #feedback>
<span v-if="serverPortWarning" class="help-block"><strong>{{ serverPortWarning }}</strong></span>
</template>
</n-form-item>

<n-form-item :label="trans('labels.query_port')" :path="queryPortPath">
<input class="block appearance-none w-full py-1 px-2 mb-1 leading-normal bg-white text-gray-800 border border-gray-200 rounded" name="query_port" type="number" id="server_port" min="1024" max="65535" v-model="queryPort">
Expand Down Expand Up @@ -80,30 +80,18 @@ const rconPort = defineModel('rconPort')
const serverPortWarning = ref('');
const selectedIp = computed({
get() {
return store.state.servers.ip || null;
},
set(value) {
store.dispatch('servers/setIp', value);
},
});
const selectedIp = computed(() => store.state.servers.ip);
const dsId = computed(() => store.state.dedicatedServers.dsId);
const busyPorts = computed(() => store.state.dedicatedServers.busyPorts);
const gameCode = computed(() => store.state.games.gameCode);
function initPorts() {
if (!props.initialServerPort) {
setPorts();
}
}
function setPorts() {
if (props.initialServerIp === selectedIp.value) {
serverPort.value = parseInt(props.initialServerPort) || 27015;
queryPort.value = parseInt(props.initialQueryPort) || 27015;
rconPort.value = parseInt(props.initialRconPort) || 27015;
return
}
const gameCode = getExistsPortGameCode();
Expand Down Expand Up @@ -136,6 +124,10 @@ function isBusy(serverIp, serverPort) {
}
function checkPorts() {
if (selectedIp.value === props.initialServerIp && serverPort.value === props.initialServerPort) {
serverPortWarning.value = '';
}
if (isBusy(selectedIp.value, serverPort.value)) {
serverPortWarning.value = trans('validation.unique', { attribute: trans('labels.server_port') });
} else {
Expand All @@ -144,15 +136,11 @@ function checkPorts() {
}
onMounted(() => {
store.dispatch('dedicatedServers/fetchBusyPorts', initPorts);
store.dispatch('dedicatedServers/fetchBusyPorts', checkPorts);
});
watch(dsId, () => {
store.dispatch('dedicatedServers/fetchBusyPorts', setPorts);
});
watch(gameCode, () => {
setPorts();
store.dispatch('dedicatedServers/fetchBusyPorts', checkPorts);
});
watch(serverPort, (newVal, oldVal) => {
Expand All @@ -170,4 +158,16 @@ watch(queryPort, (newVal) => {
emit('update:queryPort', queryPort.value);
});
watch(selectedIp, (newIp, oldIp) => {
if (oldIp) {
setPorts();
}
checkPorts();
});
watch(gameCode, () => {
setPorts();
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ const createServer = () => {
game_mod_id: serverForm.value.gameMod,
install: serverForm.value.install,
rcon: serverForm.value.rcon,
user: serverForm.value.user,
su_user: serverForm.value.user,
ds_id: serverForm.value.nodeId,
server_ip: serverForm.value.ip,
server_port: serverForm.value.serverPort,
Expand Down
1 change: 0 additions & 1 deletion resources/assets/js/views/adminviews/AdminServersEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ const saveServer = () => {
blocked: serverForm.value.blocked,
installed: serverForm.value.status,
rcon: serverForm.value.rcon,
user: serverForm.value.user,
ds_id: server.value.ds_id,
server_ip: serverForm.value.ip,
server_port: serverForm.value.serverPort,
Expand Down

0 comments on commit 7fa607a

Please sign in to comment.