#7187 - refactorWokerPda #378
|
@ -1,126 +1,145 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { onMounted, ref, computed } from 'vue';
|
import { ref, computed } from 'vue';
|
||||||
import FetchData from 'components/FetchData.vue';
|
|
||||||
import FormModel from 'components/FormModel.vue';
|
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
|
||||||
import useNotify from 'src/composables/useNotify.js';
|
|
||||||
import axios from 'axios';
|
|
||||||
import { useRole } from 'src/composables/useRole';
|
import { useRole } from 'src/composables/useRole';
|
||||||
|
import axios from 'axios';
|
||||||
|
import useNotify from 'src/composables/useNotify.js';
|
||||||
|
|
||||||
|
import FetchData from 'components/FetchData.vue';
|
||||||
|
|
||||||
|
import VnPaginate from 'src/components/ui/VnPaginate.vue';
|
||||||
|
import FormModelPopup from 'src/components/FormModelPopup.vue';
|
||||||
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
|
import VnLv from 'src/components/ui/VnLv.vue';
|
||||||
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
|
||||||
const route = useRoute();
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
const { hasAny } = useRole();
|
|
||||||
|
|
||||||
const fetchCurrentDeviceRef = ref(null);
|
const paginate = ref();
|
||||||
const deviceProductionsFilter = {
|
const dialog = ref();
|
||||||
fields: ['id', 'serialNumber', 'modelFk'],
|
const route = useRoute();
|
||||||
where: { stateFk: 'idle' },
|
const routeId = computed(() => route.params.id);
|
||||||
order: 'id',
|
|
||||||
};
|
|
||||||
const deviceProductionsOptions = ref([]);
|
|
||||||
const newPDA = ref({});
|
|
||||||
const currentPDA = ref(null);
|
|
||||||
|
|
||||||
const isAllowedToEdit = computed(() => hasAny(['hr', 'productionAssi']));
|
const initialData = computed(() => {
|
||||||
|
return {
|
||||||
|
userFk: routeId.value,
|
||||||
|
deviceProductionFk: null,
|
||||||
|
simSerialNumber: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const setCurrentPDA = (data) => {
|
const deallocatePDA = async (deviceProductionFk) => {
|
||||||
currentPDA.value = data;
|
|
||||||
currentPDA.value.description = `ID: ${currentPDA.value.deviceProductionFk} ${t(
|
|
||||||
'worker.pda.model'
|
|
||||||
)}: ${currentPDA.value.deviceProduction.modelFk} ${t('worker.pda.serialNumber')}: ${
|
|
||||||
currentPDA.value.deviceProduction.serialNumber
|
|
||||||
}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const deallocatePDA = async (data) => {
|
|
||||||
try {
|
try {
|
||||||
await axios.post(`Workers/${route.params.id}/deallocatePDA`, {
|
await axios.post(`Workers/${route.params.id}/deallocatePDA`, {
|
||||||
pda: currentPDA.value.deviceProductionFk,
|
pda: deviceProductionFk,
|
||||||
});
|
});
|
||||||
data.pda = null;
|
|
||||||
currentPDA.value = null;
|
|
||||||
await fetchCurrentDeviceRef.value.fetch();
|
|
||||||
notify(t('PDA deallocated'), 'positive');
|
notify(t('PDA deallocated'), 'positive');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error deallocating PDA');
|
console.error('Error deallocating PDA');
|
||||||
}
|
}
|
||||||
|
paginate.value.fetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(async () => await fetchCurrentDeviceRef.value.fetch());
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<QPage class="column items-center q-pa-md centerCard">
|
||||||
<FetchData
|
<FetchData
|
||||||
url="DeviceProductions"
|
url="deviceProductions"
|
||||||
:filter="deviceProductionsFilter"
|
:filter="{ where: { stateFk: 'idle' } }"
|
||||||
|
@on-fetch="(data) => (deviceProductions = data)"
|
||||||
auto-load
|
auto-load
|
||||||
@on-fetch="(data) => (deviceProductionsOptions = data)"
|
|
||||||
/>
|
/>
|
||||||
<FetchData
|
<VnPaginate
|
||||||
ref="fetchCurrentDeviceRef"
|
ref="paginate"
|
||||||
|
data-key="WorkerPda"
|
||||||
url="DeviceProductionUsers"
|
url="DeviceProductionUsers"
|
||||||
:filter="{
|
:filter="{ where: { userFk: routeId } }"
|
||||||
where: { userFk: route.params.id },
|
order="id"
|
||||||
include: { relation: 'deviceProduction' },
|
|
||||||
}"
|
|
||||||
auto-load
|
auto-load
|
||||||
@on-fetch="(data) => setCurrentPDA(data[0])"
|
|
||||||
/>
|
|
||||||
<QPage class="column items-center q-pa-md">
|
|
||||||
<FormModel
|
|
||||||
url="DeviceProductionUsers"
|
|
||||||
:url-create="`Workers/${route.params.id}/allocatePDA`"
|
|
||||||
model="DeviceProductionUser"
|
|
||||||
:form-initial-data="newPDA"
|
|
||||||
auto-load
|
|
||||||
:default-buttons="{ save: { label: 'globals.assign', color: 'primary' } }"
|
|
||||||
@on-data-saved="(_, data) => setCurrentPDA(data)"
|
|
||||||
>
|
>
|
||||||
<template #form="{ data }">
|
<template #body="{ rows }">
|
||||||
|
<QCard
|
||||||
|
flat
|
||||||
|
bordered
|
||||||
|
:key="row.id"
|
||||||
|
v-for="row of rows"
|
||||||
|
class="card q-pt-xs q-mb-sm"
|
||||||
|
>
|
||||||
|
<QItem>
|
||||||
|
<QItemSection side-left>
|
||||||
|
<VnRow>
|
||||||
<QField
|
<QField
|
||||||
v-if="currentPDA && currentPDA.description"
|
|
||||||
:label="t('worker.pda.currentPDA')"
|
:label="t('worker.pda.currentPDA')"
|
||||||
:model-value="currentPDA.description"
|
:model-value="row?.deviceProductionFk"
|
||||||
:editable="false"
|
disable
|
||||||
class="full-width"
|
|
||||||
>
|
>
|
||||||
<template #control>
|
<template #control>
|
||||||
<div tabindex="0">
|
<div tabindex="0">
|
||||||
{{ currentPDA.description }}
|
{{
|
||||||
|
row?.deviceProductionFk +
|
||||||
|
' - ' +
|
||||||
|
row?.deviceProduction?.modelFk
|
||||||
|
}}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="isAllowedToEdit" #append>
|
</QField>
|
||||||
|
<QField
|
||||||
|
:label="t('Current SIM')"
|
||||||
|
:model-value="row?.simSerialNumber"
|
||||||
|
disable
|
||||||
|
>
|
||||||
|
<template #control>
|
||||||
|
<div tabindex="0">{{ row?.simSerialNumber }}</div>
|
||||||
|
</template>
|
||||||
|
</QField>
|
||||||
|
</VnRow>
|
||||||
|
</QItemSection>
|
||||||
|
<QItemSection side>
|
||||||
<QIcon
|
<QIcon
|
||||||
name="delete"
|
name="delete"
|
||||||
size="sm"
|
size="sm"
|
||||||
class="cursor-pointer"
|
class="cursor-pointer"
|
||||||
color="primary"
|
color="primary"
|
||||||
@click="deallocatePDA(data)"
|
@click="deallocatePDA(row.deviceProductionFk)"
|
||||||
>
|
>
|
||||||
<QTooltip>
|
<QTooltip>
|
||||||
{{ t('worker.pda.removePDA') }}
|
{{ t('worker.pda.removePDA') }}
|
||||||
</QTooltip>
|
</QTooltip>
|
||||||
</QIcon>
|
</QIcon>
|
||||||
|
</QItemSection>
|
||||||
pablone marked this conversation as resolved
|
|||||||
|
</QItem>
|
||||||
|
</QCard>
|
||||||
</template>
|
</template>
|
||||||
</QField>
|
</VnPaginate>
|
||||||
|
<QPageSticky :offset="[18, 18]">
|
||||||
|
<QBtn @click.stop="dialog.show()" color="primary" fab icon="add">
|
||||||
|
<QDialog ref="dialog">
|
||||||
|
<FormModelPopup
|
||||||
|
:title="t('Add new device')"
|
||||||
|
url-create="DeviceProductionUsers"
|
||||||
|
model="DeviceProductionUser"
|
||||||
|
:form-initial-data="initialData"
|
||||||
|
@on-data-saved="paginate.fetch()"
|
||||||
|
>
|
||||||
|
<template #form-inputs="{ data }">
|
||||||
|
<VnRow class="row q-gutter-md q-mb-md">
|
||||||
<VnSelect
|
<VnSelect
|
||||||
v-else
|
|
||||||
:label="t('worker.pda.newPDA')"
|
:label="t('worker.pda.newPDA')"
|
||||||
v-model="data.pda"
|
v-model="data.deviceProductionFk"
|
||||||
pablone marked this conversation as resolved
alexm
commented
fetch y data = {} fetch y data = {}
Sino ix lo ultim q tenies
|
|||||||
:options="deviceProductionsOptions"
|
:options="deviceProductions"
|
||||||
option-label="serialNumber"
|
option-label="id"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
hide-selected
|
hide-selected
|
||||||
:disable="!isAllowedToEdit"
|
|
||||||
>
|
>
|
||||||
<template #option="scope">
|
<template #option="scope">
|
||||||
<QItem v-bind="scope.itemProps">
|
<QItem v-bind="scope.itemProps">
|
||||||
<QItemSection>
|
<QItemSection>
|
||||||
<QItemLabel>ID: {{ scope.opt?.id }}</QItemLabel>
|
<QItemLabel
|
||||||
|
>ID: {{ scope.opt?.id }}</QItemLabel
|
||||||
|
>
|
||||||
<QItemLabel caption>
|
<QItemLabel caption>
|
||||||
{{ scope.opt?.modelFk }},
|
{{ scope.opt?.modelFk }},
|
||||||
{{ scope.opt?.serialNumber }}
|
{{ scope.opt?.serialNumber }}
|
||||||
|
@ -129,12 +148,39 @@ onMounted(async () => await fetchCurrentDeviceRef.value.fetch());
|
||||||
</QItem>
|
</QItem>
|
||||||
</template>
|
</template>
|
||||||
</VnSelect>
|
</VnSelect>
|
||||||
|
<VnInput
|
||||||
|
v-model="data.simSerialNumber"
|
||||||
|
:label="t('SIM serial number')"
|
||||||
|
use-input
|
||||||
|
/>
|
||||||
|
</VnRow>
|
||||||
</template>
|
</template>
|
||||||
</FormModel>
|
</FormModelPopup>
|
||||||
|
</QDialog>
|
||||||
|
</QBtn>
|
||||||
|
<QTooltip>
|
||||||
|
{{ t('globals.new') }}
|
||||||
|
</QTooltip>
|
||||||
|
</QPageSticky>
|
||||||
</QPage>
|
</QPage>
|
||||||
</template>
|
</template>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.centerCard {
|
||||||
|
padding: 5%;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 60%;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
.label {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
.q-field {
|
||||||
|
margin-bottom: 0px;
|
||||||
|
padding-bottom: 0px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<i18n>
|
<i18n>
|
||||||
es:
|
es:
|
||||||
PDA deallocated: PDA desasignada
|
PDA deallocated: PDA desasignada
|
||||||
|
Current SIM: SIM actual
|
||||||
</i18n>
|
</i18n>
|
||||||
|
|
Loading…
Reference in New Issue
Gastar VnConfirm