0
0
Fork 0

Merge pull request '#4988 - agencySection' (!293) from 4988-agencySection into dev

Reviewed-on: verdnatura/salix-front#293
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Pablo Natek 2024-04-26 07:19:07 +00:00
commit 119f625435
20 changed files with 652 additions and 4 deletions

View File

@ -91,9 +91,15 @@ globals:
basicData: Basic data
log: Logs
parkingList: Parkings list
agencyList: Agencies list
agency: Agency
workCenters: Work centers
modes: Modes
created: Created
worker: Worker
now: Now
name: Name
new: New
errors:
statusUnauthorized: Access denied
statusInternalServerError: An internal server error has ocurred

View File

@ -91,9 +91,15 @@ globals:
basicData: Datos básicos
log: Historial
parkingList: Listado de parkings
agencyList: Listado de agencias
agency: Agencia
workCenters: Centros de trabajo
modes: Modos
created: Fecha creación
worker: Trabajador
now: Ahora
name: Nombre
new: Nuevo
errors:
statusUnauthorized: Acceso denegado
statusInternalServerError: Ha ocurrido un error interno del servidor

View File

@ -0,0 +1,79 @@
<script setup>
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import CardList from 'src/components/ui/CardList.vue';
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
import { useStateStore } from 'stores/useStateStore';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const router = useRouter();
const stateStore = useStateStore();
function navigate(id) {
router.push({ path: `/agency/${id}` });
}
function exprBuilder(param, value) {
if (!value) return;
if (param !== 'search') return;
if (!isNaN(value)) return { id: value };
return { name: { like: `%${value}%` } };
}
</script>
<template>
<template v-if="stateStore.isHeaderMounted()">
<Teleport to="#searchbar">
<VnSearchbar
:info="t('You can search by name')"
:label="t('Search agency')"
data-key="AgencyList"
url="Agencies"
/>
</Teleport>
</template>
<QPage class="column items-center q-pa-md">
<div class="vn-card-list">
<VnPaginate
data-key="AgencyList"
url="Agencies"
order="name"
:expr-builder="exprBuilder"
auto-load
>
<template #body="{ rows }">
<CardList
:id="row.id"
:key="row.id"
:title="row.name"
@click="navigate(row.id)"
v-for="row of rows"
>
<template #list-items>
<QCheckbox
:label="t('isOwn')"
v-model="row.isOwn"
:disable="true"
/>
<QCheckbox
:label="t('isAnyVolumeAllowed')"
v-model="row.isAnyVolumeAllowed"
:disable="true"
/>
</template>
</CardList>
</template>
</VnPaginate>
</div>
</QPage>
</template>
<i18n>
es:
isOwn: Tiene propietario
isAnyVolumeAllowed: Permite cualquier volumen
Search agency: Buscar agencia
You can search by name: Puedes buscar por nombre
en:
isOwn: Has owner
isAnyVolumeAllowed: Allows any volume
</i18n>

View File

@ -0,0 +1,52 @@
<script setup>
import { ref } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import FormModel from 'components/FormModel.vue';
import FetchData from 'src/components/FetchData.vue';
import VnRow from 'components/ui/VnRow.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
const { t } = useI18n();
const route = useRoute();
const routeId = route.params?.id || null;
const warehouses = ref([]);
</script>
<template>
<FetchData
url="warehouses"
sort-by="name"
@on-fetch="(data) => (warehouses = data)"
auto-load
/>
<FormModel :url="`Agencies/${routeId}`" model="agency" auto-load>
<template #form="{ data }">
<VnRow>
<VnInput v-model="data.name" :label="t('globals.name')" />
</VnRow>
<VnRow>
<VnSelectFilter
v-model="data.warehouseFk"
option-value="id"
option-label="name"
:label="t('globals.warehouse')"
:options="warehouses"
use-input
input-debounce="0"
:is-clearable="false"
/>
</VnRow>
<VnRow>
<QCheckbox :label="t('agency.isOwn')" v-model="data.isOwn" />
</VnRow>
<VnRow>
<QCheckbox
:label="t('agency.isAnyVolumeAllowed')"
v-model="data.isAnyVolumeAllowed"
/>
</VnRow>
</template>
</FormModel>
</template>

View File

@ -0,0 +1,35 @@
<script setup>
import { onMounted, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useArrayData } from 'src/composables/useArrayData';
import AgencyDescriptor from 'pages/Agency/Card/AgencyDescriptor.vue';
import VnCard from 'components/common/VnCard.vue';
const route = useRoute();
const arrayData = useArrayData('Agency', {
url: `Agencies/${route.params.id}`,
});
const { store } = arrayData;
onMounted(async () => await arrayData.fetch({ append: false }));
watch(
() => route.params.id,
async (newId) => {
if (newId) {
store.url = `Agencies/${newId}`;
await arrayData.fetch({ append: false });
}
}
);
</script>
<template>
<VnCard
data-key="Agency"
base-url="Agencies"
:descriptor="AgencyDescriptor"
searchbar-data-key="AgencyList"
searchbar-url="Agencies"
searchbar-label="agency.searchBar.label"
searchbar-info="agency.searchBar.info"
/>
</template>

View File

@ -0,0 +1,35 @@
<script setup>
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router';
import { useArrayData } from 'src/composables/useArrayData';
import CardDescriptor from 'components/ui/CardDescriptor.vue';
import VnLv from 'components/ui/VnLv.vue';
const props = defineProps({
id: {
type: Number,
required: false,
default: null,
},
});
const { t } = useI18n();
const { params } = useRoute();
const entityId = computed(() => props.id || params.id);
const { store } = useArrayData('Parking');
const card = computed(() => store.data);
</script>
<template>
<CardDescriptor
module="Agency"
data-key="Agency"
:url="`Agencies/${entityId}`"
:title="card?.name"
:subtitle="props.id"
>
<template #body="{ entity: agency }">
<VnLv :label="t('globals.name')" :value="agency.name" />
</template>
</CardDescriptor>
</template>

View File

@ -0,0 +1,6 @@
<script setup>
import VnLog from 'src/components/common/VnLog.vue';
</script>
<template>
<VnLog model="Agency" url="/AgencyLogs" />
</template>

View File

@ -0,0 +1,60 @@
<script setup>
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import CardList from 'src/components/ui/CardList.vue';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import VnLv from 'src/components/ui/VnLv.vue';
const { t } = useI18n();
const route = useRoute();
const routeId = route.params.id;
</script>
<template>
<QPage class="column items-center q-pa-md">
<div class="vn-card-list">
<VnPaginate
data-key="AgencyModes"
:url="`AgencyModes`"
:filter="{ where: { agencyFk: routeId } }"
order="name"
auto-load
>
<template #body="{ rows }">
<CardList
:id="row.id"
:key="row.id"
:title="row.name"
v-for="row of rows"
>
<template #list-items>
<VnLv
:label="t('globals.description')"
:value="row?.description"
/>
<VnLv
:label="t('deliveryMethod')"
:value="row?.deliveryMethodFk"
/>
<VnLv label="m3" :value="row?.m3" />
<VnLv :label="t('inflation')" :value="row?.inflation" />
<VnLv :label="t('globals.code')" :value="row?.code" />
</template>
</CardList>
</template>
</VnPaginate>
</div>
</QPage>
</template>
<i18n>
es:
isOwn: Tiene propietario
isAnyVolumeAllowed: Permite cualquier volumen
Search agency: Buscar agencia
You can search by name: Puedes buscar por nombre
deliveryMethod: Método de entrega
inflation: Inflación
en:
isOwn: Has owner
isAnyVolumeAllowed: Allows any volume
</i18n>

View File

@ -0,0 +1,55 @@
<script setup>
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import FetchData from 'src/components/FetchData.vue';
import CardSummary from 'components/ui/CardSummary.vue';
import VnLv from 'components/ui/VnLv.vue';
import VnTitle from 'src/components/common/VnTitle.vue';
import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
const $props = defineProps({
id: {
type: Number,
default: 0,
},
});
const { params } = useRoute();
const { t } = useI18n();
const entityId = computed(() => $props.id || params.id);
const filter = {
fields: ['id', 'sectorFk', 'code', 'pickingOrder', 'row', 'column'],
include: [{ relation: 'sector', scope: { fields: ['id', 'description'] } }],
};
</script>
<template>
<div class="q-pa-md">
<CardSummary :url="`Agencies/${entityId}`">
<template #header="{ entity: agency }">{{ agency.name }}</template>
<template #body="{ entity: agency }">
<QCard class="vn-one">
<QCardSection class="q-pa-none">
<VnTitle
:url="`#/agency/${entityId}/basic-data`"
:text="t('globals.pageTitles.basicData')"
/>
</QCardSection>
<VnLv :label="t('globals.name')" :value="agency.name" />
<QCheckbox
:label="t('agency.isOwn')"
v-model="agency.isOwn"
:disable="true"
/>
<QCheckbox
:label="t('agency.isAnyVolumeAllowed')"
v-model="agency.isAnyVolumeAllowed"
:disable="true"
/>
</QCard>
</template>
</CardSummary>
</div>
</template>

View File

@ -0,0 +1,136 @@
<script setup>
import axios from 'axios';
import { useQuasar } from 'quasar';
import { ref, computed } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import FetchData from 'src/components/FetchData.vue';
import FormModelPopup from 'src/components/FormModelPopup.vue';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import VnLv from 'src/components/ui/VnLv.vue';
import VnRow from 'components/ui/VnRow.vue';
import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
const { t } = useI18n();
const route = useRoute();
const paginate = ref();
const dialog = ref();
const routeId = computed(() => route.params.id);
const quasar = useQuasar();
const initialData = computed(() => {
return {
agencyFk: routeId.value,
workCenterFk: null,
};
});
async function deleteWorCenter(id) {
try {
await axios.delete(`AgencyWorkCenters/${id}`).then(async () => {
quasar.notify({
message: t('agency.notification.removeItem'),
type: 'positive',
});
});
} catch (error) {
quasar.notify({
message: t('agency.notification.removeItemError'),
type: 'error',
});
}
paginate.value.fetch();
}
</script>
<template>
<div class="centerCard">
<FetchData
url="workCenters"
sort-by="name"
@on-fetch="(data) => (warehouses = data)"
auto-load
/>
<VnPaginate
ref="paginate"
data-key="AgencyWorkCenters"
url="AgencyWorkCenters"
:filter="{ where: { agencyFk: routeId } }"
order="id"
auto-load
>
<template #body="{ rows }">
<QCard
flat
bordered
:key="row.id"
v-for="row of rows"
class="card q-pa-md q-mb-sm"
>
<QItem>
<QItemSection side-left>
<VnLv :value="row?.workCenter?.name" icon="delete" />
</QItemSection>
<QItemSection side>
<QBtn
@click.stop="deleteWorCenter(row.id)"
icon="delete"
color="primary"
round
flat
/>
</QItemSection>
</QItem>
</QCard>
</template>
</VnPaginate>
</div>
<QPageSticky :offset="[18, 18]">
<QBtn @click.stop="dialog.show()" color="primary" fab icon="add">
<QDialog ref="dialog">
<FormModelPopup
:title="t('Add work center')"
url-create="AgencyWorkCenters"
model="AgencyWorkCenter"
:form-initial-data="initialData"
@on-data-saved="paginate.fetch()"
>
<template #form-inputs="{ data }">
<VnRow class="row q-gutter-md q-mb-md">
<VnSelectFilter
v-model="data.workCenterFk"
option-value="id"
option-label="name"
:label="t('workCenter')"
:options="warehouses"
use-input
input-debounce="0"
:is-clearable="false"
/>
</VnRow>
</template>
</FormModelPopup>
</QDialog>
</QBtn>
<QTooltip>
{{ t('globals.new') }}
</QTooltip>
</QPageSticky>
</template>
<style lang="scss" scoped>
.centerCard {
padding: 5%;
width: 100%;
max-width: 50%;
margin: 0 auto;
}
</style>
<i18n>
es:
workCenter removed successfully: Centro de trabajo eliminado correctamente
This workCenter is already assigned to this agency: Este workCenter ya está asignado a esta agencia
Add work center: Añadir centro de trabajo
workCenter: Centro de trabajo
</i18n>

View File

@ -0,0 +1,11 @@
agency:
isOwn: Own
isAnyVolumeAllowed: Any volume allowed
notification:
removeItemError: Error removing agency
removeItem: WorkCenter removed successfully
pageTitles:
agency: Agency
searchBar:
info: You can search by agency code
label: Search agency...

View File

@ -0,0 +1,12 @@
agency:
isOwn: Propio
isAnyVolumeAllowed: Cualquier volumen
removeItem: Agencia eliminada correctamente
notification:
removeItemError: Error al eliminar la agencia
removeItem: Centro de trabajo eliminado correctamente
pageTitles:
agency: Agencia
searchBar:
info: Puedes buscar por nombre o id
label: Buscar agencia...

View File

@ -13,7 +13,6 @@ const router = useRouter();
const initialData = ref({});
const setClient = (data) => {
console.log(data.credit);
initialData.value.credit = data.credit;
};

View File

@ -73,7 +73,6 @@ const fetchAddresses = async (formData) => {
const { defaultAddress } = selectedClient.value;
formData.addressId = defaultAddress.id;
console.log();
} catch (err) {
console.error(`Error fetching addresses`, err);
return err.response;

View File

@ -0,0 +1,88 @@
import { RouterView } from 'vue-router';
export default {
path: '/agency',
name: 'Agency',
meta: {
title: 'agency',
icon: 'garage_home',
moduleName: 'Agency',
},
component: RouterView,
redirect: { name: 'AgencyCard' },
menus: {
main: [],
card: ['AgencyBasicData', 'AgencyModes', 'AgencyWorkCenters', 'AgencyLog'],
},
children: [
{
path: '/agency/:id',
name: 'AgencyCard',
component: () => import('src/pages/Agency/Card/AgencyCard.vue'),
redirect: { name: 'AgencySummary' },
children: [
{
name: 'AgencySummary',
path: 'summary',
meta: {
title: 'summary',
icon: 'view_list',
},
component: () => import('src/pages/Agency/Card/AgencySummary.vue'),
},
{
name: 'AgencyBasicData',
path: 'basic-data',
meta: {
title: 'basicData',
icon: 'vn:settings',
},
component: () => import('pages/Agency/Card/AgencyBasicData.vue'),
},
{
path: 'workCenter',
name: 'AgencyWorkCenterCard',
redirect: { name: 'AgencyWorkCenters' },
children: [
{
path: '',
name: 'AgencyWorkCenters',
meta: {
icon: 'apartment',
title: 'workCenters',
},
component: () =>
import('src/pages/Agency/Card/AgencyWorkcenter.vue'),
},
],
},
{
path: 'modes',
name: 'AgencyModesCard',
redirect: { name: 'AgencyModes' },
children: [
{
path: '',
name: 'AgencyModes',
meta: {
icon: 'format_list_bulleted',
title: 'modes',
},
component: () =>
import('src/pages/Agency/Card/AgencyModes.vue'),
},
],
},
{
name: 'AgencyLog',
path: 'log',
meta: {
title: 'log',
icon: 'history',
},
component: () => import('src/pages/Agency/Card/AgencyLog.vue'),
},
],
},
],
};

View File

@ -15,6 +15,7 @@ import Department from './department';
import Entry from './entry';
import roadmap from './roadmap';
import Parking from './parking';
import Agency from './agency';
export default [
Item,
@ -34,4 +35,5 @@ export default [
Entry,
roadmap,
Parking,
Agency,
];

View File

@ -11,7 +11,7 @@ export default {
component: RouterView,
redirect: { name: 'RouteMain' },
menus: {
main: ['RouteList', 'RouteAutonomous', 'RouteRoadmap', 'CmrList'],
main: ['RouteList', 'RouteAutonomous', 'RouteRoadmap', 'CmrList', 'AgencyList'],
card: ['RouteBasicData', 'RouteTickets', 'RouteLog'],
},
children: [
@ -75,6 +75,21 @@ export default {
},
component: () => import('src/pages/Route/Cmr/CmrList.vue'),
},
{
path: '/agency',
redirect: { name: 'AgencyList' },
children: [
{
path: 'list',
name: 'AgencyList',
meta: {
title: 'agencyList',
icon: 'view_list',
},
component: () => import('src/pages/Agency/AgencyList.vue'),
},
],
},
],
},
{

View File

@ -15,6 +15,7 @@ import order from 'src/router/modules/order';
import entry from 'src/router/modules/entry';
import roadmap from 'src/router/modules/roadmap';
import parking from 'src/router/modules/parking';
import agency from 'src/router/modules/agency';
const routes = [
{
@ -71,6 +72,7 @@ const routes = [
roadmap,
entry,
parking,
agency,
{
path: '/:catchAll(.*)*',
name: 'NotFound',

View File

@ -0,0 +1,50 @@
describe('AgencyWorkCenter', () => {
beforeEach(() => {
cy.viewport(1920, 1080);
cy.login('developer');
cy.visit(`/#/agency`);
});
it('assign workCenter', () => {
cy.visit(`/#/agency`);
cy.get(':nth-child(1) > :nth-child(1) > .card-list-body > .list-items').click();
cy.get('[href="#/agency/11/workCenter"] > .q-item__section--main').click();
cy.get('.q-page-sticky > div > .q-btn > .q-btn__content > .q-icon').click();
cy.get(
'.vn-row > .q-field > .q-field__inner > .q-field__control > .q-field__control-container'
).type('workCenterOne{enter}');
cy.get('.q-btn--standard > .q-btn__content > .block').click();
cy.get('.q-notification__message').should('have.text', 'Data created');
});
it('delete workCenter', () => {
cy.get(':nth-child(1) > :nth-child(1) > .card-list-body > .list-items').click();
cy.get('[href="#/agency/11/workCenter"] > .q-item__section--main').click();
cy.get('.q-item__section--side > .q-btn > .q-btn__content > .q-icon').click();
cy.get('.q-notification__message').should(
'have.text',
'WorkCenter removed successfully'
);
});
it('error on duplicate workCenter', () => {
cy.visit(`/#/agency`);
cy.get(':nth-child(1) > :nth-child(1) > .card-list-body > .list-items').click();
cy.get('[href="#/agency/11/workCenter"] > .q-item__section--main').click();
cy.get('.q-page-sticky > div > .q-btn > .q-btn__content > .q-icon').click();
cy.get(
'.vn-row > .q-field > .q-field__inner > .q-field__control > .q-field__control-container'
).type('workCenterOne{enter}');
cy.get('.q-btn--standard > .q-btn__content > .block').click();
cy.get('.q-notification__message').should('have.text', 'Data created');
cy.get('.q-page-sticky > div > .q-btn > .q-btn__content > .q-icon').click();
cy.get(
'.vn-row > .q-field > .q-field__inner > .q-field__control > .q-field__control-container'
).type('workCenterOne{enter}');
cy.get('.q-btn--standard > .q-btn__content > .block').click();
cy.get(
':nth-child(2) > .q-notification__wrapper > .q-notification__content > .q-notification__message'
).should('have.text', 'This workCenter is already assigned to this agency');
});
});

View File

@ -1 +1 @@
// This file will be run before each test file
// This file will be run before each test file, don't delete or vitest will not work.