Merge branch 'dev' of https: refs #6822//gitea.verdnatura.es/verdnatura/salix-front into 6822-createEntryTransferOption
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
This commit is contained in:
commit
70b872b912
|
@ -0,0 +1,33 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
function getCurrentBranchName(p = process.cwd()) {
|
||||||
|
if (!fs.existsSync(p)) return false;
|
||||||
|
|
||||||
|
const gitHeadPath = path.join(p, '.git', 'HEAD');
|
||||||
|
|
||||||
|
if (!fs.existsSync(gitHeadPath))
|
||||||
|
return getCurrentBranchName(path.resolve(p, '..'));
|
||||||
|
|
||||||
|
const headContent = fs.readFileSync(gitHeadPath, 'utf-8');
|
||||||
|
return headContent.trim().split('/')[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
const branchName = getCurrentBranchName();
|
||||||
|
|
||||||
|
if (branchName) {
|
||||||
|
const msgPath = `.git/COMMIT_EDITMSG`;
|
||||||
|
const msg = fs.readFileSync(msgPath, 'utf-8');
|
||||||
|
const reference = branchName.match(/^\d+/);
|
||||||
|
|
||||||
|
const referenceTag = `refs #${reference}`;
|
||||||
|
if (!msg.includes(referenceTag) && reference) {
|
||||||
|
const splitedMsg = msg.split(':');
|
||||||
|
|
||||||
|
if (splitedMsg.length > 1) {
|
||||||
|
const finalMsg = splitedMsg[0] + ': ' + referenceTag + splitedMsg.slice(1).join(':');
|
||||||
|
fs.writeFileSync(msgPath, finalMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
echo "Running husky commit-msg hook"
|
||||||
|
npx --no-install commitlint --edit
|
||||||
|
echo "Adding reference tag to commit message"
|
||||||
|
node .husky/addReferenceTag.js
|
||||||
|
|
1100
CHANGELOG.md
1100
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,8 @@ def PROTECTED_BRANCH
|
||||||
|
|
||||||
def BRANCH_ENV = [
|
def BRANCH_ENV = [
|
||||||
test: 'test',
|
test: 'test',
|
||||||
master: 'production'
|
master: 'production',
|
||||||
|
beta: 'production'
|
||||||
]
|
]
|
||||||
|
|
||||||
node {
|
node {
|
||||||
|
@ -15,7 +16,8 @@ node {
|
||||||
PROTECTED_BRANCH = [
|
PROTECTED_BRANCH = [
|
||||||
'dev',
|
'dev',
|
||||||
'test',
|
'test',
|
||||||
'master'
|
'master',
|
||||||
|
'beta'
|
||||||
].contains(env.BRANCH_NAME)
|
].contains(env.BRANCH_NAME)
|
||||||
|
|
||||||
// https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
|
// https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
module.exports = { extends: ['@commitlint/config-conventional'] };
|
|
@ -1,4 +1,7 @@
|
||||||
const { defineConfig } = require('cypress');
|
const { defineConfig } = require('cypress');
|
||||||
|
// https://docs.cypress.io/app/tooling/reporters
|
||||||
|
// https://docs.cypress.io/app/references/configuration
|
||||||
|
// https://www.npmjs.com/package/cypress-mochawesome-reporter
|
||||||
|
|
||||||
module.exports = defineConfig({
|
module.exports = defineConfig({
|
||||||
e2e: {
|
e2e: {
|
||||||
|
@ -8,15 +11,27 @@ module.exports = defineConfig({
|
||||||
screenshotsFolder: 'test/cypress/screenshots',
|
screenshotsFolder: 'test/cypress/screenshots',
|
||||||
supportFile: 'test/cypress/support/index.js',
|
supportFile: 'test/cypress/support/index.js',
|
||||||
videosFolder: 'test/cypress/videos',
|
videosFolder: 'test/cypress/videos',
|
||||||
|
downloadsFolder: 'test/cypress/downloads',
|
||||||
video: false,
|
video: false,
|
||||||
specPattern: 'test/cypress/integration/**/*.spec.js',
|
specPattern: 'test/cypress/integration/**/*.spec.js',
|
||||||
experimentalRunAllSpecs: true,
|
experimentalRunAllSpecs: true,
|
||||||
|
watchForFileChanges: true,
|
||||||
|
reporter: 'cypress-mochawesome-reporter',
|
||||||
|
reporterOptions: {
|
||||||
|
charts: true,
|
||||||
|
reportPageTitle: 'Cypress Inline Reporter',
|
||||||
|
reportFilename: '[status]_[datetime]-report',
|
||||||
|
embeddedScreenshots: true,
|
||||||
|
reportDir: 'test/cypress/reports',
|
||||||
|
inlineAssets: true,
|
||||||
|
},
|
||||||
component: {
|
component: {
|
||||||
componentFolder: 'src',
|
componentFolder: 'src',
|
||||||
testFiles: '**/*.spec.js',
|
testFiles: '**/*.spec.js',
|
||||||
supportFile: 'test/cypress/support/unit.js',
|
supportFile: 'test/cypress/support/unit.js',
|
||||||
},
|
},
|
||||||
setupNodeEvents(on, config) {
|
setupNodeEvents(on, config) {
|
||||||
|
require('cypress-mochawesome-reporter/plugin')(on);
|
||||||
// implement node event listeners here
|
// implement node event listeners here
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
15
package.json
15
package.json
|
@ -1,19 +1,23 @@
|
||||||
{
|
{
|
||||||
"name": "salix-front",
|
"name": "salix-front",
|
||||||
"version": "24.32.0",
|
"version": "25.04.0",
|
||||||
"description": "Salix frontend",
|
"description": "Salix frontend",
|
||||||
"productName": "Salix",
|
"productName": "Salix",
|
||||||
"author": "Verdnatura",
|
"author": "Verdnatura",
|
||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "pnpm@8.15.1",
|
"packageManager": "pnpm@8.15.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"resetDatabase": "cd ../salix && gulp docker",
|
||||||
"lint": "eslint --ext .js,.vue ./",
|
"lint": "eslint --ext .js,.vue ./",
|
||||||
"format": "prettier --write \"**/*.{js,vue,scss,html,md,json}\" --ignore-path .gitignore",
|
"format": "prettier --write \"**/*.{js,vue,scss,html,md,json}\" --ignore-path .gitignore",
|
||||||
"test:e2e": "cypress open",
|
"test:e2e": "cypress open",
|
||||||
"test:e2e:ci": "cd ../salix && gulp docker && cd ../salix-front && cypress run",
|
"test:e2e:ci": "npm run resetDatabase && cd ../salix-front && cypress run",
|
||||||
"test": "echo \"See package.json => scripts for available tests.\" && exit 0",
|
"test": "echo \"See package.json => scripts for available tests.\" && exit 0",
|
||||||
"test:unit": "vitest",
|
"test:unit": "vitest",
|
||||||
"test:unit:ci": "vitest run"
|
"test:unit:ci": "vitest run",
|
||||||
|
"commitlint": "commitlint --edit",
|
||||||
|
"prepare": "npx husky install",
|
||||||
|
"addReferenceTag": "node .husky/addReferenceTag.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@quasar/cli": "^2.3.0",
|
"@quasar/cli": "^2.3.0",
|
||||||
|
@ -21,6 +25,7 @@
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
"chromium": "^3.0.3",
|
"chromium": "^3.0.3",
|
||||||
"croppie": "^2.6.5",
|
"croppie": "^2.6.5",
|
||||||
|
"moment": "^2.30.1",
|
||||||
"pinia": "^2.1.3",
|
"pinia": "^2.1.3",
|
||||||
"quasar": "^2.14.5",
|
"quasar": "^2.14.5",
|
||||||
"validator": "^13.9.0",
|
"validator": "^13.9.0",
|
||||||
|
@ -29,6 +34,8 @@
|
||||||
"vue-router": "^4.2.1"
|
"vue-router": "^4.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@commitlint/cli": "^19.2.1",
|
||||||
|
"@commitlint/config-conventional": "^19.1.0",
|
||||||
"@intlify/unplugin-vue-i18n": "^0.8.1",
|
"@intlify/unplugin-vue-i18n": "^0.8.1",
|
||||||
"@pinia/testing": "^0.1.2",
|
"@pinia/testing": "^0.1.2",
|
||||||
"@quasar/app-vite": "^1.7.3",
|
"@quasar/app-vite": "^1.7.3",
|
||||||
|
@ -37,10 +44,12 @@
|
||||||
"@vue/test-utils": "^2.4.4",
|
"@vue/test-utils": "^2.4.4",
|
||||||
"autoprefixer": "^10.4.14",
|
"autoprefixer": "^10.4.14",
|
||||||
"cypress": "^13.6.6",
|
"cypress": "^13.6.6",
|
||||||
|
"cypress-mochawesome-reporter": "^3.8.2",
|
||||||
"eslint": "^8.41.0",
|
"eslint": "^8.41.0",
|
||||||
"eslint-config-prettier": "^8.8.0",
|
"eslint-config-prettier": "^8.8.0",
|
||||||
"eslint-plugin-cypress": "^2.13.3",
|
"eslint-plugin-cypress": "^2.13.3",
|
||||||
"eslint-plugin-vue": "^9.14.1",
|
"eslint-plugin-vue": "^9.14.1",
|
||||||
|
"husky": "^8.0.0",
|
||||||
"postcss": "^8.4.23",
|
"postcss": "^8.4.23",
|
||||||
"prettier": "^2.8.8",
|
"prettier": "^2.8.8",
|
||||||
"vitest": "^0.31.1"
|
"vitest": "^0.31.1"
|
||||||
|
|
15480
pnpm-lock.yaml
15480
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,3 @@
|
||||||
import { Notify } from 'quasar';
|
|
||||||
import { onRequest, onResponseError } from 'src/boot/axios';
|
import { onRequest, onResponseError } from 'src/boot/axios';
|
||||||
import { describe, expect, it, vi } from 'vitest';
|
import { describe, expect, it, vi } from 'vitest';
|
||||||
|
|
||||||
|
@ -7,75 +6,60 @@ vi.mock('src/composables/useSession', () => ({
|
||||||
getToken: () => 'DEFAULT_TOKEN',
|
getToken: () => 'DEFAULT_TOKEN',
|
||||||
isLoggedIn: () => vi.fn(),
|
isLoggedIn: () => vi.fn(),
|
||||||
destroy: () => vi.fn(),
|
destroy: () => vi.fn(),
|
||||||
})
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock('src/stores/useStateQueryStore', () => ({
|
||||||
|
useStateQueryStore: () => ({
|
||||||
|
add: () => vi.fn(),
|
||||||
|
remove: () => vi.fn(),
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('Axios boot', () => {
|
describe('Axios boot', () => {
|
||||||
|
|
||||||
describe('onRequest()', async () => {
|
describe('onRequest()', async () => {
|
||||||
it('should set the "Authorization" property on the headers', async () => {
|
it('should set the "Authorization" property on the headers', async () => {
|
||||||
const config = { headers: {} };
|
const config = { headers: {} };
|
||||||
|
|
||||||
const resultConfig = onRequest(config);
|
const resultConfig = onRequest(config);
|
||||||
|
|
||||||
expect(resultConfig).toEqual(expect.objectContaining({
|
expect(resultConfig).toEqual(
|
||||||
headers: {
|
|
||||||
Authorization: 'DEFAULT_TOKEN'
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('onResponseError()', async () => {
|
|
||||||
it('should call to the Notify plugin with a message error for an status code "500"', async () => {
|
|
||||||
Notify.create = vi.fn()
|
|
||||||
|
|
||||||
const error = {
|
|
||||||
response: {
|
|
||||||
status: 500
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = onResponseError(error);
|
|
||||||
|
|
||||||
|
|
||||||
expect(result).rejects.toEqual(
|
|
||||||
expect.objectContaining(error)
|
|
||||||
);
|
|
||||||
expect(Notify.create).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
message: 'An internal server error has ocurred',
|
headers: {
|
||||||
type: 'negative',
|
'Accept-Language': 'en-US',
|
||||||
|
Authorization: 'DEFAULT_TOKEN',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onResponseError()', async () => {
|
||||||
|
it('should call to the Notify plugin with a message error for an status code "500"', async () => {
|
||||||
|
const error = {
|
||||||
|
response: {
|
||||||
|
status: 500,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = onResponseError(error);
|
||||||
|
expect(result).rejects.toEqual(expect.objectContaining(error));
|
||||||
|
});
|
||||||
|
|
||||||
it('should call to the Notify plugin with a message from the response property', async () => {
|
it('should call to the Notify plugin with a message from the response property', async () => {
|
||||||
Notify.create = vi.fn()
|
|
||||||
|
|
||||||
const error = {
|
const error = {
|
||||||
response: {
|
response: {
|
||||||
status: 401,
|
status: 401,
|
||||||
data: {
|
data: {
|
||||||
error: {
|
error: {
|
||||||
message: 'Invalid user or password'
|
message: 'Invalid user or password',
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = onResponseError(error);
|
const result = onResponseError(error);
|
||||||
|
expect(result).rejects.toEqual(expect.objectContaining(error));
|
||||||
|
|
||||||
expect(result).rejects.toEqual(
|
|
||||||
expect.objectContaining(error)
|
|
||||||
);
|
|
||||||
expect(Notify.create).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
message: 'Invalid user or password',
|
|
||||||
type: 'negative',
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
});
|
});
|
|
@ -2,18 +2,23 @@ import axios from 'axios';
|
||||||
import { useSession } from 'src/composables/useSession';
|
import { useSession } from 'src/composables/useSession';
|
||||||
import { Router } from 'src/router';
|
import { Router } from 'src/router';
|
||||||
import useNotify from 'src/composables/useNotify.js';
|
import useNotify from 'src/composables/useNotify.js';
|
||||||
|
import { useStateQueryStore } from 'src/stores/useStateQueryStore';
|
||||||
|
import { i18n } from 'src/boot/i18n';
|
||||||
|
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
|
const stateQuery = useStateQueryStore();
|
||||||
axios.defaults.baseURL = '/api/';
|
const baseUrl = '/api/';
|
||||||
|
axios.defaults.baseURL = baseUrl;
|
||||||
|
const axiosNoError = axios.create({ baseURL: baseUrl });
|
||||||
|
|
||||||
const onRequest = (config) => {
|
const onRequest = (config) => {
|
||||||
const token = session.getToken();
|
const token = session.getToken();
|
||||||
if (token.length && !config.headers.Authorization) {
|
if (token.length && !config.headers.Authorization) {
|
||||||
config.headers.Authorization = token;
|
config.headers.Authorization = token;
|
||||||
|
config.headers['Accept-Language'] = i18n.global.locale.value;
|
||||||
}
|
}
|
||||||
|
stateQuery.add(config);
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,10 +27,10 @@ const onRequestError = (error) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onResponse = (response) => {
|
const onResponse = (response) => {
|
||||||
const { method } = response.config;
|
const config = response.config;
|
||||||
|
stateQuery.remove(config);
|
||||||
|
|
||||||
const isSaveRequest = method === 'patch';
|
if (config.method === 'patch') {
|
||||||
if (isSaveRequest) {
|
|
||||||
notify('globals.dataSaved', 'positive');
|
notify('globals.dataSaved', 'positive');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,28 +38,9 @@ const onResponse = (response) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onResponseError = (error) => {
|
const onResponseError = (error) => {
|
||||||
let message = '';
|
stateQuery.remove(error.config);
|
||||||
|
|
||||||
const response = error.response;
|
if (session.isLoggedIn() && error.response?.status === 401) {
|
||||||
const responseData = response && response.data;
|
|
||||||
const responseError = responseData && response.data.error;
|
|
||||||
if (responseError) {
|
|
||||||
message = responseError.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (response?.status) {
|
|
||||||
case 500:
|
|
||||||
message = 'errors.statusInternalServerError';
|
|
||||||
break;
|
|
||||||
case 502:
|
|
||||||
message = 'errors.statusBadGateway';
|
|
||||||
break;
|
|
||||||
case 504:
|
|
||||||
message = 'errors.statusGatewayTimeout';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (session.isLoggedIn() && response?.status === 401) {
|
|
||||||
session.destroy(false);
|
session.destroy(false);
|
||||||
const hash = window.location.hash;
|
const hash = window.location.hash;
|
||||||
const url = hash.slice(1);
|
const url = hash.slice(1);
|
||||||
|
@ -63,12 +49,12 @@ const onResponseError = (error) => {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
notify(message, 'negative');
|
|
||||||
|
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
axios.interceptors.request.use(onRequest, onRequestError);
|
axios.interceptors.request.use(onRequest, onRequestError);
|
||||||
axios.interceptors.response.use(onResponse, onResponseError);
|
axios.interceptors.response.use(onResponse, onResponseError);
|
||||||
|
axiosNoError.interceptors.request.use(onRequest);
|
||||||
|
axiosNoError.interceptors.response.use(onResponse);
|
||||||
|
|
||||||
export { onRequest, onResponseError };
|
export { onRequest, onResponseError, axiosNoError };
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
import { QInput } from 'quasar';
|
||||||
|
import setDefault from './setDefault';
|
||||||
|
|
||||||
|
setDefault(QInput, 'dense', true);
|
|
@ -0,0 +1,4 @@
|
||||||
|
import { QSelect } from 'quasar';
|
||||||
|
import setDefault from './setDefault';
|
||||||
|
|
||||||
|
setDefault(QSelect, 'dense', true);
|
|
@ -1,9 +1,11 @@
|
||||||
import { boot } from 'quasar/wrappers';
|
import { boot } from 'quasar/wrappers';
|
||||||
import { createI18n } from 'vue-i18n';
|
import { createI18n } from 'vue-i18n';
|
||||||
import messages from 'src/i18n';
|
import messages from 'src/i18n';
|
||||||
|
import { useState } from 'src/composables/useState';
|
||||||
|
const user = useState().getUser();
|
||||||
|
|
||||||
const i18n = createI18n({
|
const i18n = createI18n({
|
||||||
locale: navigator.language || navigator.userLanguage,
|
locale: user.value.lang || navigator.language || navigator.userLanguage,
|
||||||
fallbackLocale: 'en',
|
fallbackLocale: 'en',
|
||||||
globalInjection: true,
|
globalInjection: true,
|
||||||
messages,
|
messages,
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
export default {
|
||||||
|
mounted: function (el, binding) {
|
||||||
|
const shortcut = binding.value ?? '+';
|
||||||
|
|
||||||
|
const { key, ctrl, alt, callback } =
|
||||||
|
typeof shortcut === 'string'
|
||||||
|
? {
|
||||||
|
key: shortcut,
|
||||||
|
ctrl: true,
|
||||||
|
alt: true,
|
||||||
|
callback: () =>
|
||||||
|
document
|
||||||
|
.querySelector(`button[shortcut="${shortcut}"]`)
|
||||||
|
?.click(),
|
||||||
|
}
|
||||||
|
: binding.value;
|
||||||
|
|
||||||
|
const handleKeydown = (event) => {
|
||||||
|
if (event.key === key && (!ctrl || event.ctrlKey) && (!alt || event.altKey)) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Attach the event listener to the window
|
||||||
|
window.addEventListener('keydown', handleKeydown);
|
||||||
|
|
||||||
|
el._handleKeydown = handleKeydown;
|
||||||
|
},
|
||||||
|
unmounted: function (el) {
|
||||||
|
if (el._handleKeydown) {
|
||||||
|
window.removeEventListener('keydown', el._handleKeydown);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -0,0 +1,36 @@
|
||||||
|
import routes from 'src/router/modules';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
let isNotified = false;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
created: function () {
|
||||||
|
const router = useRouter();
|
||||||
|
const keyBindingMap = routes
|
||||||
|
.filter((route) => route.meta.keyBinding)
|
||||||
|
.reduce((map, route) => {
|
||||||
|
map['Key' + route.meta.keyBinding.toUpperCase()] = route.path;
|
||||||
|
return map;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const handleKeyDown = (event) => {
|
||||||
|
const { ctrlKey, altKey, code } = event;
|
||||||
|
|
||||||
|
if (ctrlKey && altKey && keyBindingMap[code] && !isNotified) {
|
||||||
|
event.preventDefault();
|
||||||
|
router.push(keyBindingMap[code]);
|
||||||
|
isNotified = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyUp = (event) => {
|
||||||
|
const { ctrlKey, altKey } = event;
|
||||||
|
if (!ctrlKey || !altKey) {
|
||||||
|
isNotified = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('keydown', handleKeyDown);
|
||||||
|
window.addEventListener('keyup', handleKeyUp);
|
||||||
|
},
|
||||||
|
};
|
|
@ -1,47 +1,51 @@
|
||||||
import { getCurrentInstance } from 'vue';
|
function focusFirstInput(input) {
|
||||||
|
input.focus();
|
||||||
const filterAvailableInput = (element) => {
|
}
|
||||||
return element.classList.contains('q-field__native') && !element.disabled;
|
|
||||||
};
|
|
||||||
const filterAvailableText = (element) => {
|
|
||||||
return (
|
|
||||||
element.__vueParentComponent.type.name === 'QInput' &&
|
|
||||||
element.__vueParentComponent?.attrs?.class !== 'vn-input-date'
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
const vm = getCurrentInstance();
|
const that = this;
|
||||||
if (vm.type.name === 'QForm') {
|
|
||||||
if (!['searchbarForm', 'filterPanelForm'].includes(this.$el?.id)) {
|
|
||||||
// AUTOFOCUS
|
|
||||||
const elementsArray = Array.from(this.$el.elements);
|
|
||||||
const availableInputs = elementsArray.filter(filterAvailableInput);
|
|
||||||
const firstInputElement = availableInputs.find(filterAvailableText);
|
|
||||||
|
|
||||||
if (firstInputElement) {
|
const form = document.querySelector('.q-form#formModel');
|
||||||
firstInputElement.focus();
|
if (!form) return;
|
||||||
}
|
try {
|
||||||
const that = this;
|
const inputsFormCard = form.querySelectorAll(
|
||||||
this.$el.addEventListener('keyup', function (evt) {
|
`input:not([disabled]):not([type="checkbox"])`
|
||||||
if (evt.key === 'Enter') {
|
);
|
||||||
const input = evt.target;
|
if (inputsFormCard.length) {
|
||||||
if (input.type == 'textarea' && evt.shiftKey) {
|
focusFirstInput(inputsFormCard[0]);
|
||||||
evt.preventDefault();
|
|
||||||
let { selectionStart, selectionEnd } = input;
|
|
||||||
input.value =
|
|
||||||
input.value.substring(0, selectionStart) +
|
|
||||||
'\n' +
|
|
||||||
input.value.substring(selectionEnd);
|
|
||||||
selectionStart = selectionEnd = selectionStart + 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
evt.preventDefault();
|
|
||||||
that.onSubmit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
const textareas = document.querySelectorAll(
|
||||||
|
'textarea:not([disabled]), [contenteditable]:not([disabled])'
|
||||||
|
);
|
||||||
|
if (textareas.length) {
|
||||||
|
focusFirstInput(textareas[textareas.length - 1]);
|
||||||
|
}
|
||||||
|
const inputs = document.querySelectorAll(
|
||||||
|
'form#formModel input:not([disabled]):not([type="checkbox"])'
|
||||||
|
);
|
||||||
|
const input = inputs[0];
|
||||||
|
if (!input) return;
|
||||||
|
|
||||||
|
focusFirstInput(input);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
form.addEventListener('keyup', function (evt) {
|
||||||
|
if (evt.key === 'Enter' && !that.$attrs['prevent-submit']) {
|
||||||
|
const input = evt.target;
|
||||||
|
if (input.type == 'textarea' && evt.shiftKey) {
|
||||||
|
evt.preventDefault();
|
||||||
|
let { selectionStart, selectionEnd } = input;
|
||||||
|
input.value =
|
||||||
|
input.value.substring(0, selectionStart) +
|
||||||
|
'\n' +
|
||||||
|
input.value.substring(selectionEnd);
|
||||||
|
selectionStart = selectionEnd = selectionStart + 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
evt.preventDefault();
|
||||||
|
that.onSubmit();
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
export * from './defaults/qTable';
|
export * from './defaults/qTable';
|
||||||
|
export * from './defaults/qInput';
|
||||||
|
export * from './defaults/qSelect';
|
||||||
|
|
|
@ -1,6 +1,54 @@
|
||||||
|
import axios from 'axios';
|
||||||
import { boot } from 'quasar/wrappers';
|
import { boot } from 'quasar/wrappers';
|
||||||
import qFormMixin from './qformMixin';
|
import qFormMixin from './qformMixin';
|
||||||
|
import keyShortcut from './keyShortcut';
|
||||||
|
import { QForm } from 'quasar';
|
||||||
|
import { QLayout } from 'quasar';
|
||||||
|
import mainShortcutMixin from './mainShortcutMixin';
|
||||||
|
import { useCau } from 'src/composables/useCau';
|
||||||
|
|
||||||
export default boot(({ app }) => {
|
export default boot(({ app }) => {
|
||||||
app.mixin(qFormMixin);
|
QForm.mixins = [qFormMixin];
|
||||||
|
QLayout.mixins = [mainShortcutMixin];
|
||||||
|
|
||||||
|
app.directive('shortcut', keyShortcut);
|
||||||
|
app.config.errorHandler = async (error) => {
|
||||||
|
let message;
|
||||||
|
const response = error.response;
|
||||||
|
const responseData = response?.data;
|
||||||
|
const responseError = responseData && response.data.error;
|
||||||
|
if (responseError) {
|
||||||
|
message = responseError.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (response?.status) {
|
||||||
|
case 422:
|
||||||
|
if (error.name == 'ValidationError')
|
||||||
|
message +=
|
||||||
|
' "' +
|
||||||
|
responseError.details.context +
|
||||||
|
'.' +
|
||||||
|
Object.keys(responseError.details.codes).join(',') +
|
||||||
|
'"';
|
||||||
|
break;
|
||||||
|
case 500:
|
||||||
|
message = 'errors.statusInternalServerError';
|
||||||
|
break;
|
||||||
|
case 502:
|
||||||
|
message = 'errors.statusBadGateway';
|
||||||
|
break;
|
||||||
|
case 504:
|
||||||
|
message = 'errors.statusGatewayTimeout';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error(error);
|
||||||
|
if (error instanceof axios.CanceledError) {
|
||||||
|
const env = process.env.NODE_ENV;
|
||||||
|
if (env && env !== 'development') return;
|
||||||
|
message = 'Duplicate request';
|
||||||
|
}
|
||||||
|
|
||||||
|
await useCau(response, message);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, ref, onMounted, nextTick } from 'vue';
|
import { reactive, ref, onMounted, nextTick, computed } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
|
||||||
|
@ -7,27 +7,29 @@ import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
import FormModelPopup from './FormModelPopup.vue';
|
import FormModelPopup from './FormModelPopup.vue';
|
||||||
|
import { useState } from 'src/composables/useState';
|
||||||
defineProps({ showEntityField: { type: Boolean, default: true } });
|
|
||||||
|
|
||||||
const emit = defineEmits(['onDataSaved']);
|
const emit = defineEmits(['onDataSaved']);
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const bicInputRef = ref(null);
|
const bicInputRef = ref(null);
|
||||||
const bankEntityFormData = reactive({
|
const state = useState();
|
||||||
name: null,
|
|
||||||
bic: null,
|
const customer = computed(() => state.get('customer'));
|
||||||
countryFk: null,
|
|
||||||
id: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const countriesFilter = {
|
const countriesFilter = {
|
||||||
fields: ['id', 'name', 'code'],
|
fields: ['id', 'name', 'code'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const bankEntityFormData = reactive({
|
||||||
|
name: null,
|
||||||
|
bic: null,
|
||||||
|
countryFk: customer.value?.countryFk,
|
||||||
|
});
|
||||||
|
|
||||||
const countriesOptions = ref([]);
|
const countriesOptions = ref([]);
|
||||||
|
|
||||||
const onDataSaved = (formData, requestResponse) => {
|
const onDataSaved = (...args) => {
|
||||||
emit('onDataSaved', formData, requestResponse);
|
emit('onDataSaved', ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
@ -39,7 +41,6 @@ onMounted(async () => {
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
<FetchData
|
||||||
url="Countries"
|
url="Countries"
|
||||||
:filter="countriesFilter"
|
|
||||||
auto-load
|
auto-load
|
||||||
@on-fetch="(data) => (countriesOptions = data)"
|
@on-fetch="(data) => (countriesOptions = data)"
|
||||||
/>
|
/>
|
||||||
|
@ -49,10 +50,11 @@ onMounted(async () => {
|
||||||
:title="t('title')"
|
:title="t('title')"
|
||||||
:subtitle="t('subtitle')"
|
:subtitle="t('subtitle')"
|
||||||
:form-initial-data="bankEntityFormData"
|
:form-initial-data="bankEntityFormData"
|
||||||
|
:filter="countriesFilter"
|
||||||
@on-data-saved="onDataSaved"
|
@on-data-saved="onDataSaved"
|
||||||
>
|
>
|
||||||
<template #form-inputs="{ data, validate }">
|
<template #form-inputs="{ data, validate }">
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnInput
|
<VnInput
|
||||||
:label="t('name')"
|
:label="t('name')"
|
||||||
v-model="data.name"
|
v-model="data.name"
|
||||||
|
@ -67,7 +69,7 @@ onMounted(async () => {
|
||||||
:rules="validate('bankEntity.bic')"
|
:rules="validate('bankEntity.bic')"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('country')"
|
:label="t('country')"
|
||||||
|
@ -80,7 +82,13 @@ onMounted(async () => {
|
||||||
:rules="validate('bankEntity.countryFk')"
|
:rules="validate('bankEntity.countryFk')"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="showEntityField" class="col">
|
<div
|
||||||
|
v-if="
|
||||||
|
countriesOptions.find((c) => c.id === data.countryFk)?.code ==
|
||||||
|
'ES'
|
||||||
|
"
|
||||||
|
class="col"
|
||||||
|
>
|
||||||
<VnInput
|
<VnInput
|
||||||
:label="t('id')"
|
:label="t('id')"
|
||||||
v-model="data.id"
|
v-model="data.id"
|
||||||
|
|
|
@ -1,155 +0,0 @@
|
||||||
<script setup>
|
|
||||||
import { reactive, ref, computed } from 'vue';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
|
||||||
import FormModelPopup from './FormModelPopup.vue';
|
|
||||||
import VnInputDate from './common/VnInputDate.vue';
|
|
||||||
|
|
||||||
const emit = defineEmits(['onDataSaved']);
|
|
||||||
|
|
||||||
const { t } = useI18n();
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const manualInvoiceFormData = reactive({
|
|
||||||
maxShipped: Date.vnNew(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const formModelPopupRef = ref();
|
|
||||||
const invoiceOutSerialsOptions = ref([]);
|
|
||||||
const taxAreasOptions = ref([]);
|
|
||||||
const ticketsOptions = ref([]);
|
|
||||||
const clientsOptions = ref([]);
|
|
||||||
const isLoading = computed(() => formModelPopupRef.value?.isLoading);
|
|
||||||
|
|
||||||
const onDataSaved = async (formData, requestResponse) => {
|
|
||||||
emit('onDataSaved', formData, requestResponse);
|
|
||||||
if (requestResponse && requestResponse.id)
|
|
||||||
router.push({ name: 'InvoiceOutSummary', params: { id: requestResponse.id } });
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<FetchData
|
|
||||||
url="InvoiceOutSerials"
|
|
||||||
:filter="{ where: { code: { neq: 'R' } }, order: ['code'] }"
|
|
||||||
@on-fetch="(data) => (invoiceOutSerialsOptions = data)"
|
|
||||||
auto-load
|
|
||||||
/>
|
|
||||||
<FetchData
|
|
||||||
url="TaxAreas"
|
|
||||||
:filter="{ order: ['code'] }"
|
|
||||||
@on-fetch="(data) => (taxAreasOptions = data)"
|
|
||||||
auto-load
|
|
||||||
/>
|
|
||||||
<FormModelPopup
|
|
||||||
ref="formModelPopupRef"
|
|
||||||
:title="t('Create manual invoice')"
|
|
||||||
url-create="InvoiceOuts/createManualInvoice"
|
|
||||||
model="invoiceOut"
|
|
||||||
:form-initial-data="manualInvoiceFormData"
|
|
||||||
@on-data-saved="onDataSaved"
|
|
||||||
>
|
|
||||||
<template #form-inputs="{ data }">
|
|
||||||
<span v-if="isLoading" class="text-primary invoicing-text">
|
|
||||||
<QIcon name="warning" class="fill-icon q-mr-sm" size="md" />
|
|
||||||
{{ t('Invoicing in progress...') }}
|
|
||||||
</span>
|
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
|
||||||
<VnSelect
|
|
||||||
:label="t('Ticket')"
|
|
||||||
:options="ticketsOptions"
|
|
||||||
hide-selected
|
|
||||||
option-label="id"
|
|
||||||
option-value="id"
|
|
||||||
v-model="data.ticketFk"
|
|
||||||
@update:model-value="data.clientFk = null"
|
|
||||||
url="Tickets"
|
|
||||||
:where="{ refFk: null }"
|
|
||||||
:fields="['id', 'nickname']"
|
|
||||||
:filter-options="{ order: 'shipped DESC' }"
|
|
||||||
>
|
|
||||||
<template #option="scope">
|
|
||||||
<QItem v-bind="scope.itemProps">
|
|
||||||
<QItemSection>
|
|
||||||
<QItemLabel> #{{ scope.opt?.id }} </QItemLabel>
|
|
||||||
<QItemLabel caption>{{ scope.opt?.nickname }}</QItemLabel>
|
|
||||||
</QItemSection>
|
|
||||||
</QItem>
|
|
||||||
</template>
|
|
||||||
</VnSelect>
|
|
||||||
<span class="row items-center" style="max-width: max-content">{{
|
|
||||||
t('Or')
|
|
||||||
}}</span>
|
|
||||||
<VnSelect
|
|
||||||
:label="t('Client')"
|
|
||||||
:options="clientsOptions"
|
|
||||||
hide-selected
|
|
||||||
option-label="name"
|
|
||||||
option-value="id"
|
|
||||||
v-model="data.clientFk"
|
|
||||||
@update:model-value="data.ticketFk = null"
|
|
||||||
url="Clients"
|
|
||||||
:fields="['id', 'name']"
|
|
||||||
:filter-options="{ order: 'name ASC' }"
|
|
||||||
/>
|
|
||||||
<VnInputDate :label="t('Max date')" v-model="data.maxShipped" />
|
|
||||||
</VnRow>
|
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
|
||||||
<VnSelect
|
|
||||||
:label="t('Serial')"
|
|
||||||
:options="invoiceOutSerialsOptions"
|
|
||||||
hide-selected
|
|
||||||
option-label="description"
|
|
||||||
option-value="code"
|
|
||||||
v-model="data.serial"
|
|
||||||
/>
|
|
||||||
<VnSelect
|
|
||||||
:label="t('Area')"
|
|
||||||
:options="taxAreasOptions"
|
|
||||||
hide-selected
|
|
||||||
option-label="code"
|
|
||||||
option-value="code"
|
|
||||||
v-model="data.taxArea"
|
|
||||||
/>
|
|
||||||
</VnRow>
|
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
|
||||||
<VnInput
|
|
||||||
:label="t('Reference')"
|
|
||||||
type="textarea"
|
|
||||||
v-model="data.reference"
|
|
||||||
fill-input
|
|
||||||
autogrow
|
|
||||||
/>
|
|
||||||
</VnRow>
|
|
||||||
</template>
|
|
||||||
</FormModelPopup>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.invoicing-text {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
color: $primary;
|
|
||||||
font-size: 24px;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<i18n>
|
|
||||||
es:
|
|
||||||
Create manual invoice: Crear factura manual
|
|
||||||
Ticket: Ticket
|
|
||||||
Client: Cliente
|
|
||||||
Max date: Fecha límite
|
|
||||||
Serial: Serie
|
|
||||||
Area: Area
|
|
||||||
Reference: Referencia
|
|
||||||
Or: O
|
|
||||||
Invoicing in progress...: Facturación en progreso...
|
|
||||||
</i18n>
|
|
|
@ -1,58 +1,62 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelectProvince from 'components/VnSelectProvince.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'components/common/VnInput.vue';
|
||||||
import FormModelPopup from './FormModelPopup.vue';
|
import FormModelPopup from './FormModelPopup.vue';
|
||||||
|
|
||||||
const emit = defineEmits(['onDataSaved']);
|
const emit = defineEmits(['onDataSaved']);
|
||||||
|
const $props = defineProps({
|
||||||
|
countryFk: {
|
||||||
|
type: Number,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
provinceSelected: {
|
||||||
|
type: Number,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const cityFormData = reactive({
|
const cityFormData = ref({
|
||||||
name: null,
|
name: null,
|
||||||
provinceFk: null,
|
provinceFk: null,
|
||||||
});
|
});
|
||||||
|
onMounted(() => {
|
||||||
const provincesOptions = ref([]);
|
cityFormData.value.provinceFk = $props.provinceSelected;
|
||||||
|
});
|
||||||
const onDataSaved = (dataSaved) => {
|
const onDataSaved = (...args) => {
|
||||||
emit('onDataSaved', dataSaved);
|
emit('onDataSaved', ...args);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
|
||||||
@on-fetch="(data) => (provincesOptions = data)"
|
|
||||||
auto-load
|
|
||||||
url="Provinces"
|
|
||||||
/>
|
|
||||||
<FormModelPopup
|
<FormModelPopup
|
||||||
:title="t('New city')"
|
:title="t('New city')"
|
||||||
:subtitle="t('Please, ensure you put the correct data!')"
|
:subtitle="t('Please, ensure you put the correct data!')"
|
||||||
:form-initial-data="cityFormData"
|
:form-initial-data="cityFormData"
|
||||||
url-create="towns"
|
url-create="towns"
|
||||||
model="city"
|
model="city"
|
||||||
@on-data-saved="onDataSaved($event)"
|
@on-data-saved="onDataSaved"
|
||||||
|
data-cy="newCityForm"
|
||||||
>
|
>
|
||||||
<template #form-inputs="{ data, validate }">
|
<template #form-inputs="{ data, validate }">
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnInput
|
<VnInput
|
||||||
:label="t('Name')"
|
:label="t('Name')"
|
||||||
v-model="data.name"
|
v-model="data.name"
|
||||||
:rules="validate('city.name')"
|
:rules="validate('city.name')"
|
||||||
|
required
|
||||||
|
data-cy="cityName"
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelectProvince
|
||||||
:label="t('Province')"
|
:province-selected="$props.provinceSelected"
|
||||||
:options="provincesOptions"
|
:country-fk="$props.countryFk"
|
||||||
hide-selected
|
|
||||||
option-label="name"
|
|
||||||
option-value="id"
|
|
||||||
v-model="data.provinceFk"
|
v-model="data.provinceFk"
|
||||||
:rules="validate('city.provinceFk')"
|
required
|
||||||
|
data-cy="provinceCity"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
<script setup>
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
import FormModelPopup from './FormModelPopup.vue';
|
||||||
|
|
||||||
|
const emit = defineEmits(['onDataSaved']);
|
||||||
|
const { t } = useI18n();
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<FormModelPopup
|
||||||
|
url-create="Expenses"
|
||||||
|
model="Expense"
|
||||||
|
:title="t('New expense')"
|
||||||
|
:form-initial-data="{ id: null, isWithheld: false, name: null }"
|
||||||
|
@on-data-saved="emit('onDataSaved', $event)"
|
||||||
|
>
|
||||||
|
<template #form-inputs="{ data, validate }">
|
||||||
|
<VnRow>
|
||||||
|
<VnInput
|
||||||
|
:label="`${t('globals.code')}`"
|
||||||
|
v-model="data.id"
|
||||||
|
:required="true"
|
||||||
|
:rules="validate('expense.code')"
|
||||||
|
/>
|
||||||
|
<QCheckbox
|
||||||
|
dense
|
||||||
|
size="sm"
|
||||||
|
:label="`${t('It\'s a withholding')}`"
|
||||||
|
v-model="data.isWithheld"
|
||||||
|
:rules="validate('expense.isWithheld')"
|
||||||
|
/>
|
||||||
|
</VnRow>
|
||||||
|
<VnRow>
|
||||||
|
<VnInput
|
||||||
|
:label="`${t('globals.description')}`"
|
||||||
|
v-model="data.name"
|
||||||
|
:required="true"
|
||||||
|
:rules="validate('expense.description')"
|
||||||
|
/>
|
||||||
|
</VnRow>
|
||||||
|
</template>
|
||||||
|
</FormModelPopup>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<i18n>
|
||||||
|
es:
|
||||||
|
New expense: Nuevo gasto
|
||||||
|
It's a withholding: Es una retención
|
||||||
|
</i18n>
|
|
@ -5,9 +5,9 @@ import { useI18n } from 'vue-i18n';
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
|
import VnSelectProvince from 'src/components/VnSelectProvince.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
import CreateNewCityForm from './CreateNewCityForm.vue';
|
import CreateNewCityForm from './CreateNewCityForm.vue';
|
||||||
import CreateNewProvinceForm from './CreateNewProvinceForm.vue';
|
|
||||||
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
||||||
import FormModelPopup from './FormModelPopup.vue';
|
import FormModelPopup from './FormModelPopup.vue';
|
||||||
|
|
||||||
|
@ -21,123 +21,196 @@ const postcodeFormData = reactive({
|
||||||
provinceFk: null,
|
provinceFk: null,
|
||||||
townFk: null,
|
townFk: null,
|
||||||
});
|
});
|
||||||
|
const townsFetchDataRef = ref(false);
|
||||||
|
const townFilter = ref({});
|
||||||
|
|
||||||
const townsFetchDataRef = ref(null);
|
const countriesRef = ref(false);
|
||||||
const provincesFetchDataRef = ref(null);
|
|
||||||
const countriesOptions = ref([]);
|
|
||||||
const provincesOptions = ref([]);
|
const provincesOptions = ref([]);
|
||||||
const townsLocationOptions = ref([]);
|
const townsOptions = ref([]);
|
||||||
|
const town = ref({});
|
||||||
|
const countryFilter = ref({});
|
||||||
|
|
||||||
const onDataSaved = (formData) => {
|
function onDataSaved(formData) {
|
||||||
const newPostcode = {
|
const newPostcode = {
|
||||||
...formData,
|
...formData,
|
||||||
};
|
};
|
||||||
const townObject = townsLocationOptions.value.find(
|
newPostcode.town = town.value.name;
|
||||||
({ id }) => id === formData.townFk
|
newPostcode.townFk = town.value.id;
|
||||||
);
|
|
||||||
newPostcode.town = townObject?.name;
|
|
||||||
const provinceObject = provincesOptions.value.find(
|
const provinceObject = provincesOptions.value.find(
|
||||||
({ id }) => id === formData.provinceFk
|
({ id }) => id === formData.provinceFk
|
||||||
);
|
);
|
||||||
newPostcode.province = provinceObject?.name;
|
newPostcode.province = provinceObject?.name;
|
||||||
const countryObject = countriesOptions.value.find(
|
const countryObject = countriesRef.value.opts.find(
|
||||||
({ id }) => id === formData.countryFk
|
({ id }) => id === formData.countryFk
|
||||||
);
|
);
|
||||||
newPostcode.country = countryObject?.country;
|
newPostcode.country = countryObject?.name;
|
||||||
emit('onDataSaved', newPostcode);
|
emit('onDataSaved', newPostcode);
|
||||||
};
|
}
|
||||||
|
|
||||||
const onCityCreated = async ({ name, provinceFk }, formData) => {
|
async function setCountry(countryFk, data) {
|
||||||
await townsFetchDataRef.value.fetch();
|
data.townFk = null;
|
||||||
formData.townFk = townsLocationOptions.value.find((town) => town.name === name).id;
|
data.provinceFk = null;
|
||||||
formData.provinceFk = provinceFk;
|
data.countryFk = countryFk;
|
||||||
formData.countryFk = provincesOptions.value.find(
|
await fetchTowns();
|
||||||
(province) => province.id === provinceFk
|
}
|
||||||
).countryFk;
|
|
||||||
};
|
|
||||||
|
|
||||||
const onProvinceCreated = async ({ name }, formData) => {
|
// Province
|
||||||
await provincesFetchDataRef.value.fetch();
|
async function setProvince(id, data) {
|
||||||
formData.provinceFk = provincesOptions.value.find(
|
if (data.provinceFk === id) return;
|
||||||
(province) => province.name === name
|
const newProvince = provincesOptions.value.find((province) => province.id == id);
|
||||||
).id;
|
if (newProvince) data.countryFk = newProvince.countryFk;
|
||||||
};
|
postcodeFormData.provinceFk = id;
|
||||||
|
await fetchTowns();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onProvinceCreated(data) {
|
||||||
|
postcodeFormData.provinceFk = data.id;
|
||||||
|
}
|
||||||
|
function provinceByCountry(countryFk = postcodeFormData.countryFk) {
|
||||||
|
return provincesOptions.value
|
||||||
|
.filter((province) => province.countryFk === countryFk)
|
||||||
|
.map(({ id }) => id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Town
|
||||||
|
async function handleTowns(data) {
|
||||||
|
townsOptions.value = data;
|
||||||
|
}
|
||||||
|
function setTown(newTown, data) {
|
||||||
|
town.value = newTown;
|
||||||
|
data.provinceFk = newTown?.provinceFk ?? newTown;
|
||||||
|
data.countryFk = newTown?.province?.countryFk ?? newTown;
|
||||||
|
}
|
||||||
|
async function onCityCreated(newTown, formData) {
|
||||||
|
newTown.province = provincesOptions.value.find(
|
||||||
|
(province) => province.id === newTown.provinceFk
|
||||||
|
);
|
||||||
|
formData.townFk = newTown;
|
||||||
|
setTown(newTown, formData);
|
||||||
|
}
|
||||||
|
async function fetchTowns(countryFk = postcodeFormData.countryFk) {
|
||||||
|
if (!countryFk) return;
|
||||||
|
const provinces = postcodeFormData.provinceFk
|
||||||
|
? [postcodeFormData.provinceFk]
|
||||||
|
: provinceByCountry();
|
||||||
|
townFilter.value.where = {
|
||||||
|
provinceFk: {
|
||||||
|
inq: provinces,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
await townsFetchDataRef.value?.fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function filterTowns(name) {
|
||||||
|
if (name !== '') {
|
||||||
|
townFilter.value.where = {
|
||||||
|
name: {
|
||||||
|
like: `%${name}%`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
await townsFetchDataRef.value?.fetch();
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
<FetchData
|
||||||
ref="townsFetchDataRef"
|
ref="townsFetchDataRef"
|
||||||
@on-fetch="(data) => (townsLocationOptions = data)"
|
:sort-by="['name ASC']"
|
||||||
|
:limit="30"
|
||||||
|
:filter="townFilter"
|
||||||
|
@on-fetch="handleTowns"
|
||||||
auto-load
|
auto-load
|
||||||
url="Towns/location"
|
url="Towns/location"
|
||||||
/>
|
/>
|
||||||
<FetchData
|
|
||||||
ref="provincesFetchDataRef"
|
|
||||||
@on-fetch="(data) => (provincesOptions = data)"
|
|
||||||
auto-load
|
|
||||||
url="Provinces"
|
|
||||||
/>
|
|
||||||
<FetchData
|
|
||||||
@on-fetch="(data) => (countriesOptions = data)"
|
|
||||||
auto-load
|
|
||||||
url="Countries"
|
|
||||||
/>
|
|
||||||
<FormModelPopup
|
<FormModelPopup
|
||||||
url-create="postcodes"
|
url-create="postcodes"
|
||||||
model="postcode"
|
model="postcode"
|
||||||
:title="t('New postcode')"
|
:title="t('New postcode')"
|
||||||
:subtitle="t('Please, ensure you put the correct data!')"
|
:subtitle="t('Please, ensure you put the correct data!')"
|
||||||
:form-initial-data="postcodeFormData"
|
:form-initial-data="postcodeFormData"
|
||||||
|
:mapper="(data) => (data.townFk = data.townFk.id) && data"
|
||||||
@on-data-saved="onDataSaved"
|
@on-data-saved="onDataSaved"
|
||||||
>
|
>
|
||||||
<template #form-inputs="{ data, validate }">
|
<template #form-inputs="{ data, validate }">
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnInput
|
<VnInput
|
||||||
:label="t('Postcode')"
|
:label="t('Postcode')"
|
||||||
v-model="data.code"
|
v-model="data.code"
|
||||||
:rules="validate('postcode.code')"
|
:rules="validate('postcode.code')"
|
||||||
|
clearable
|
||||||
|
required
|
||||||
|
data-cy="locationPostcode"
|
||||||
/>
|
/>
|
||||||
<VnSelectDialog
|
<VnSelectDialog
|
||||||
:label="t('City')"
|
:label="t('City')"
|
||||||
:options="townsLocationOptions"
|
@update:model-value="(value) => setTown(value, data)"
|
||||||
|
@filter="filterTowns"
|
||||||
|
:tooltip="t('Create city')"
|
||||||
v-model="data.townFk"
|
v-model="data.townFk"
|
||||||
hide-selected
|
:options="townsOptions"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
:rules="validate('postcode.city')"
|
:rules="validate('postcode.city')"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
:acls="[{ model: 'Town', props: '*', accessType: 'WRITE' }]"
|
||||||
|
:emit-value="false"
|
||||||
|
required
|
||||||
|
data-cy="locationTown"
|
||||||
>
|
>
|
||||||
|
<template #option="{ itemProps, opt }">
|
||||||
|
<QItem v-bind="itemProps">
|
||||||
|
<QItemSection>
|
||||||
|
<QItemLabel>{{ opt.name }}</QItemLabel>
|
||||||
|
<QItemLabel caption>
|
||||||
|
{{ opt.province.name }},
|
||||||
|
{{ opt.province.country.name }}
|
||||||
|
</QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
|
</template>
|
||||||
<template #form>
|
<template #form>
|
||||||
<CreateNewCityForm @on-data-saved="onCityCreated($event, data)" />
|
<CreateNewCityForm
|
||||||
|
:country-fk="data.countryFk"
|
||||||
|
:province-selected="data.provinceFk"
|
||||||
|
@on-data-saved="
|
||||||
|
(_, requestResponse) =>
|
||||||
|
onCityCreated(requestResponse, data)
|
||||||
|
"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</VnSelectDialog>
|
</VnSelectDialog>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow class="row q-gutter-md q-mb-xl">
|
<VnRow>
|
||||||
<VnSelectDialog
|
<VnSelectProvince
|
||||||
:label="t('Province')"
|
:country-fk="data.countryFk"
|
||||||
:options="provincesOptions"
|
:province-selected="data.provinceFk"
|
||||||
hide-selected
|
@update:model-value="(value) => setProvince(value, data)"
|
||||||
option-label="name"
|
@update:options="
|
||||||
option-value="id"
|
(data) => {
|
||||||
|
provincesOptions = data;
|
||||||
|
}
|
||||||
|
"
|
||||||
v-model="data.provinceFk"
|
v-model="data.provinceFk"
|
||||||
:rules="validate('postcode.provinceFk')"
|
@on-province-created="onProvinceCreated"
|
||||||
:roles-allowed-to-create="['deliveryAssistant']"
|
required
|
||||||
>
|
/>
|
||||||
<template #form>
|
<VnSelect
|
||||||
<CreateNewProvinceForm
|
ref="countriesRef"
|
||||||
@on-data-saved="onProvinceCreated($event, data)"
|
:limit="30"
|
||||||
/>
|
:filter="countryFilter"
|
||||||
</template> </VnSelectDialog
|
:sort-by="['name ASC']"
|
||||||
></VnRow>
|
auto-load
|
||||||
<VnRow class="row q-gutter-md q-mb-xl"
|
url="Countries"
|
||||||
><VnSelect
|
required
|
||||||
:label="t('Country')"
|
:label="t('Country')"
|
||||||
:options="countriesOptions"
|
|
||||||
hide-selected
|
hide-selected
|
||||||
option-label="name"
|
option-label="name"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
v-model="data.countryFk"
|
v-model="data.countryFk"
|
||||||
:rules="validate('postcode.countryFk')"
|
:rules="validate('postcode.countryFk')"
|
||||||
|
@update:model-value="(value) => setCountry(value, data)"
|
||||||
|
data-cy="locationCountry"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
</template>
|
</template>
|
||||||
|
@ -147,6 +220,7 @@ const onProvinceCreated = async ({ name }, formData) => {
|
||||||
<i18n>
|
<i18n>
|
||||||
es:
|
es:
|
||||||
New postcode: Nuevo código postal
|
New postcode: Nuevo código postal
|
||||||
|
Create city: Crear población
|
||||||
Please, ensure you put the correct data!: ¡Por favor, asegúrese de poner los datos correctos!
|
Please, ensure you put the correct data!: ¡Por favor, asegúrese de poner los datos correctos!
|
||||||
City: Población
|
City: Población
|
||||||
Province: Provincia
|
Province: Provincia
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, ref } from 'vue';
|
import { computed, reactive, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
@ -16,44 +15,71 @@ const provinceFormData = reactive({
|
||||||
name: null,
|
name: null,
|
||||||
autonomyFk: null,
|
autonomyFk: null,
|
||||||
});
|
});
|
||||||
|
const $props = defineProps({
|
||||||
|
countryFk: {
|
||||||
|
type: Number,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const autonomiesRef = ref([]);
|
||||||
|
|
||||||
const autonomiesOptions = ref([]);
|
const onDataSaved = (dataSaved, requestResponse) => {
|
||||||
|
requestResponse.autonomy = autonomiesRef.value.opts.find(
|
||||||
const onDataSaved = (dataSaved) => {
|
(autonomy) => autonomy.id == requestResponse.autonomyFk
|
||||||
emit('onDataSaved', dataSaved);
|
);
|
||||||
|
emit('onDataSaved', dataSaved, requestResponse);
|
||||||
};
|
};
|
||||||
|
const where = computed(() => {
|
||||||
|
if (!$props.countryFk) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return { countryFk: $props.countryFk };
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
|
||||||
@on-fetch="(data) => (autonomiesOptions = data)"
|
|
||||||
auto-load
|
|
||||||
url="Autonomies"
|
|
||||||
/>
|
|
||||||
<FormModelPopup
|
<FormModelPopup
|
||||||
:title="t('New province')"
|
:title="t('New province')"
|
||||||
:subtitle="t('Please, ensure you put the correct data!')"
|
:subtitle="t('Please, ensure you put the correct data!')"
|
||||||
url-create="provinces"
|
url-create="provinces"
|
||||||
model="province"
|
model="province"
|
||||||
:form-initial-data="provinceFormData"
|
:form-initial-data="provinceFormData"
|
||||||
@on-data-saved="onDataSaved($event)"
|
@on-data-saved="onDataSaved"
|
||||||
>
|
>
|
||||||
<template #form-inputs="{ data, validate }">
|
<template #form-inputs="{ data, validate }">
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnInput
|
<VnInput
|
||||||
:label="t('Name')"
|
:label="t('Name')"
|
||||||
v-model="data.name"
|
v-model="data.name"
|
||||||
:rules="validate('province.name')"
|
:rules="validate('province.name')"
|
||||||
|
required
|
||||||
|
data-cy="provinceName"
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
|
data-cy="autonomyProvince"
|
||||||
|
required
|
||||||
|
ref="autonomiesRef"
|
||||||
|
auto-load
|
||||||
|
:where="where"
|
||||||
|
url="Autonomies/location"
|
||||||
|
:sort-by="['name ASC']"
|
||||||
|
:limit="30"
|
||||||
:label="t('Autonomy')"
|
:label="t('Autonomy')"
|
||||||
:options="autonomiesOptions"
|
|
||||||
hide-selected
|
hide-selected
|
||||||
option-label="name"
|
option-label="name"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
v-model="data.autonomyFk"
|
v-model="data.autonomyFk"
|
||||||
:rules="validate('province.autonomyFk')"
|
:rules="validate('province.autonomyFk')"
|
||||||
/>
|
>
|
||||||
|
<template #option="{ itemProps, opt }">
|
||||||
|
<QItem v-bind="itemProps">
|
||||||
|
<QItemSection>
|
||||||
|
<QItemLabel>{{ opt.name }}</QItemLabel>
|
||||||
|
<QItemLabel caption> {{ opt.country.name }} </QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
|
</template>
|
||||||
|
</VnSelect>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
</template>
|
</template>
|
||||||
</FormModelPopup>
|
</FormModelPopup>
|
||||||
|
|
|
@ -38,7 +38,7 @@ const onDataSaved = (dataSaved) => {
|
||||||
@on-fetch="(data) => (warehousesOptions = data)"
|
@on-fetch="(data) => (warehousesOptions = data)"
|
||||||
auto-load
|
auto-load
|
||||||
url="Warehouses"
|
url="Warehouses"
|
||||||
:filter="{ fields: ['id', 'name'], order: 'name ASC', limit: 30 }"
|
:filter="{ fields: ['id', 'name'], order: 'name ASC' }"
|
||||||
/>
|
/>
|
||||||
<FetchData
|
<FetchData
|
||||||
@on-fetch="(data) => (temperaturesOptions = data)"
|
@on-fetch="(data) => (temperaturesOptions = data)"
|
||||||
|
@ -50,10 +50,10 @@ const onDataSaved = (dataSaved) => {
|
||||||
model="thermograph"
|
model="thermograph"
|
||||||
:title="t('New thermograph')"
|
:title="t('New thermograph')"
|
||||||
:form-initial-data="thermographFormData"
|
:form-initial-data="thermographFormData"
|
||||||
@on-data-saved="onDataSaved($event)"
|
@on-data-saved="(_, response) => onDataSaved(response)"
|
||||||
>
|
>
|
||||||
<template #form-inputs="{ data, validate }">
|
<template #form-inputs="{ data, validate }">
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnInput
|
<VnInput
|
||||||
:label="t('Identifier')"
|
:label="t('Identifier')"
|
||||||
v-model="data.thermographId"
|
v-model="data.thermographId"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter, onBeforeRouteLeave } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
import { useValidator } from 'src/composables/useValidator';
|
import { useValidator } from 'src/composables/useValidator';
|
||||||
|
@ -10,6 +10,7 @@ import VnPaginate from 'components/ui/VnPaginate.vue';
|
||||||
import VnConfirm from 'components/ui/VnConfirm.vue';
|
import VnConfirm from 'components/ui/VnConfirm.vue';
|
||||||
import SkeletonTable from 'components/ui/SkeletonTable.vue';
|
import SkeletonTable from 'components/ui/SkeletonTable.vue';
|
||||||
import { tMobile } from 'src/composables/tMobile';
|
import { tMobile } from 'src/composables/tMobile';
|
||||||
|
import getDifferences from 'src/filters/getDifferences';
|
||||||
|
|
||||||
const { push } = useRouter();
|
const { push } = useRouter();
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
|
@ -77,7 +78,7 @@ const isLoading = ref(false);
|
||||||
const hasChanges = ref(false);
|
const hasChanges = ref(false);
|
||||||
const originalData = ref();
|
const originalData = ref();
|
||||||
const vnPaginateRef = ref();
|
const vnPaginateRef = ref();
|
||||||
const formData = ref();
|
const formData = ref([]);
|
||||||
const saveButtonRef = ref(null);
|
const saveButtonRef = ref(null);
|
||||||
const watchChanges = ref();
|
const watchChanges = ref();
|
||||||
const formUrl = computed(() => $props.url);
|
const formUrl = computed(() => $props.url);
|
||||||
|
@ -94,9 +95,23 @@ defineExpose({
|
||||||
saveChanges,
|
saveChanges,
|
||||||
getChanges,
|
getChanges,
|
||||||
formData,
|
formData,
|
||||||
|
originalData,
|
||||||
vnPaginateRef,
|
vnPaginateRef,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onBeforeRouteLeave((to, from, next) => {
|
||||||
|
if (hasChanges.value)
|
||||||
|
quasar.dialog({
|
||||||
|
component: VnConfirm,
|
||||||
|
componentProps: {
|
||||||
|
title: t('globals.unsavedPopup.title'),
|
||||||
|
message: t('globals.unsavedPopup.subtitle'),
|
||||||
|
promise: () => next(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
else next();
|
||||||
|
});
|
||||||
|
|
||||||
async function fetch(data) {
|
async function fetch(data) {
|
||||||
resetData(data);
|
resetData(data);
|
||||||
emit('onFetch', data);
|
emit('onFetch', data);
|
||||||
|
@ -112,7 +127,7 @@ function resetData(data) {
|
||||||
originalData.value = JSON.parse(JSON.stringify(data));
|
originalData.value = JSON.parse(JSON.stringify(data));
|
||||||
formData.value = JSON.parse(JSON.stringify(data));
|
formData.value = JSON.parse(JSON.stringify(data));
|
||||||
|
|
||||||
if (watchChanges.value) watchChanges.value(); //destoy watcher
|
if (watchChanges.value) watchChanges.value(); //destroy watcher
|
||||||
watchChanges.value = watch(formData, () => (hasChanges.value = true), { deep: true });
|
watchChanges.value = watch(formData, () => (hasChanges.value = true), { deep: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,14 +176,13 @@ async function saveChanges(data) {
|
||||||
const changes = data || getChanges();
|
const changes = data || getChanges();
|
||||||
try {
|
try {
|
||||||
await axios.post($props.saveUrl || $props.url + '/crud', changes);
|
await axios.post($props.saveUrl || $props.url + '/crud', changes);
|
||||||
} catch (e) {
|
} finally {
|
||||||
return (isLoading.value = false);
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
originalData.value = JSON.parse(JSON.stringify(formData.value));
|
originalData.value = JSON.parse(JSON.stringify(formData.value));
|
||||||
if (changes.creates?.length) await vnPaginateRef.value.fetch();
|
if (changes.creates?.length) await vnPaginateRef.value.fetch();
|
||||||
|
|
||||||
hasChanges.value = false;
|
hasChanges.value = false;
|
||||||
isLoading.value = false;
|
|
||||||
emit('saveChanges', data);
|
emit('saveChanges', data);
|
||||||
quasar.notify({
|
quasar.notify({
|
||||||
type: 'positive',
|
type: 'positive',
|
||||||
|
@ -176,11 +190,11 @@ async function saveChanges(data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function insert() {
|
async function insert(pushData = $props.dataRequired) {
|
||||||
const $index = formData.value.length
|
const $index = formData.value.length
|
||||||
? formData.value[formData.value.length - 1].$index + 1
|
? formData.value[formData.value.length - 1].$index + 1
|
||||||
: 0;
|
: 0;
|
||||||
formData.value.push(Object.assign({ $index }, $props.dataRequired));
|
formData.value.push(Object.assign({ $index }, pushData));
|
||||||
hasChanges.value = true;
|
hasChanges.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,6 +235,8 @@ async function remove(data) {
|
||||||
newData = newData.filter((form) => !ids.some((id) => id == form[pk]));
|
newData = newData.filter((form) => !ids.some((id) => id == form[pk]));
|
||||||
fetch(newData);
|
fetch(newData);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
reset();
|
||||||
}
|
}
|
||||||
emit('update:selected', []);
|
emit('update:selected', []);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +249,7 @@ function getChanges() {
|
||||||
for (const [i, row] of formData.value.entries()) {
|
for (const [i, row] of formData.value.entries()) {
|
||||||
if (!row[pk]) {
|
if (!row[pk]) {
|
||||||
creates.push(row);
|
creates.push(row);
|
||||||
} else if (originalData.value) {
|
} else if (originalData.value[i]) {
|
||||||
const data = getDifferences(originalData.value[i], row);
|
const data = getDifferences(originalData.value[i], row);
|
||||||
if (!isEmpty(data)) {
|
if (!isEmpty(data)) {
|
||||||
updates.push({
|
updates.push({
|
||||||
|
@ -252,34 +268,10 @@ function getChanges() {
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDifferences(obj1, obj2) {
|
|
||||||
let diff = {};
|
|
||||||
delete obj1.$index;
|
|
||||||
delete obj2.$index;
|
|
||||||
|
|
||||||
for (let key in obj1) {
|
|
||||||
if (obj2[key] && JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key])) {
|
|
||||||
diff[key] = obj2[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let key in obj2) {
|
|
||||||
if (
|
|
||||||
obj1[key] === undefined ||
|
|
||||||
JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key])
|
|
||||||
) {
|
|
||||||
diff[key] = obj2[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isEmpty(obj) {
|
function isEmpty(obj) {
|
||||||
if (obj == null) return true;
|
if (obj == null) return true;
|
||||||
if (obj === undefined) return true;
|
if (Array.isArray(obj)) return !obj.length;
|
||||||
if (Object.keys(obj).length === 0) return true;
|
return !Object.keys(obj).length;
|
||||||
|
|
||||||
if (obj.length > 0) return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function reload(params) {
|
async function reload(params) {
|
||||||
|
@ -379,6 +371,7 @@ watch(formUrl, async () => {
|
||||||
@click="onSubmit"
|
@click="onSubmit"
|
||||||
:disable="!hasChanges"
|
:disable="!hasChanges"
|
||||||
:title="t('globals.save')"
|
:title="t('globals.save')"
|
||||||
|
data-cy="crudModelDefaultSaveBtn"
|
||||||
/>
|
/>
|
||||||
<slot name="moreAfterActions" />
|
<slot name="moreAfterActions" />
|
||||||
</QBtnGroup>
|
</QBtnGroup>
|
||||||
|
|
|
@ -156,26 +156,22 @@ const rotateRight = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
try {
|
if (!newPhoto.files && !newPhoto.url) {
|
||||||
if (!newPhoto.files && !newPhoto.url) {
|
notify(t('Select an image'), 'negative');
|
||||||
notify(t('Select an image'), 'negative');
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
type: 'blob',
|
|
||||||
};
|
|
||||||
|
|
||||||
editor.value
|
|
||||||
.result(options)
|
|
||||||
.then((result) => {
|
|
||||||
const file = new File([result], newPhoto.files?.name || '');
|
|
||||||
newPhoto.blob = file;
|
|
||||||
})
|
|
||||||
.then(() => makeRequest());
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error uploading image');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
type: 'blob',
|
||||||
|
};
|
||||||
|
|
||||||
|
editor.value
|
||||||
|
.result(options)
|
||||||
|
.then((result) => {
|
||||||
|
const file = new File([result], newPhoto.files?.name || '');
|
||||||
|
newPhoto.blob = file;
|
||||||
|
})
|
||||||
|
.then(() => makeRequest());
|
||||||
};
|
};
|
||||||
|
|
||||||
const makeRequest = async () => {
|
const makeRequest = async () => {
|
||||||
|
@ -245,14 +241,14 @@ const makeRequest = async () => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<QOptionGroup
|
<QOptionGroup
|
||||||
:options="uploadMethodsOptions"
|
:options="uploadMethodsOptions"
|
||||||
type="radio"
|
type="radio"
|
||||||
v-model="uploadMethodSelected"
|
v-model="uploadMethodSelected"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<QFile
|
<QFile
|
||||||
v-if="uploadMethodSelected === 'computer'"
|
v-if="uploadMethodSelected === 'computer'"
|
||||||
ref="inputFileRef"
|
ref="inputFileRef"
|
||||||
|
@ -287,7 +283,7 @@ const makeRequest = async () => {
|
||||||
placeholder="https://"
|
placeholder="https://"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('Orientation')"
|
:label="t('Orientation')"
|
||||||
:options="viewportTypes"
|
:options="viewportTypes"
|
||||||
|
|
|
@ -51,21 +51,17 @@ const onDataSaved = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
try {
|
isLoading.value = true;
|
||||||
isLoading.value = true;
|
const rowsToEdit = $props.rows.map((row) => ({ id: row.id, itemFk: row.itemFk }));
|
||||||
const rowsToEdit = $props.rows.map((row) => ({ id: row.id, itemFk: row.itemFk }));
|
const payload = {
|
||||||
const payload = {
|
field: selectedField.value.field,
|
||||||
field: selectedField.value.field,
|
newValue: newValue.value,
|
||||||
newValue: newValue.value,
|
lines: rowsToEdit,
|
||||||
lines: rowsToEdit,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
await axios.post($props.editUrl, payload);
|
await axios.post($props.editUrl, payload);
|
||||||
onDataSaved();
|
onDataSaved();
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
} catch (err) {
|
|
||||||
console.error('Error submitting table cell edit');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeForm = () => {
|
const closeForm = () => {
|
||||||
|
@ -82,19 +78,21 @@ const closeForm = () => {
|
||||||
<span class="title">{{ t('Edit') }}</span>
|
<span class="title">{{ t('Edit') }}</span>
|
||||||
<span class="countLines">{{ ` ${rows.length} ` }}</span>
|
<span class="countLines">{{ ` ${rows.length} ` }}</span>
|
||||||
<span class="title">{{ t('buy(s)') }}</span>
|
<span class="title">{{ t('buy(s)') }}</span>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('Field to edit')"
|
:label="t('Field to edit')"
|
||||||
:options="fieldsOptions"
|
:options="fieldsOptions"
|
||||||
hide-selected
|
hide-selected
|
||||||
option-label="label"
|
option-label="label"
|
||||||
v-model="selectedField"
|
v-model="selectedField"
|
||||||
|
data-cy="field-to-edit"
|
||||||
/>
|
/>
|
||||||
<component
|
<component
|
||||||
:is="inputs[selectedField?.component || 'input']"
|
:is="inputs[selectedField?.component || 'input']"
|
||||||
v-bind="selectedField?.attrs || {}"
|
v-bind="selectedField?.attrs || {}"
|
||||||
v-model="newValue"
|
v-model="newValue"
|
||||||
:label="t('Value')"
|
:label="t('Value')"
|
||||||
|
data-cy="value-to-edit"
|
||||||
style="width: 200px"
|
style="width: 200px"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
|
|
|
@ -44,7 +44,7 @@ onMounted(async () => {
|
||||||
|
|
||||||
async function fetch(fetchFilter = {}) {
|
async function fetch(fetchFilter = {}) {
|
||||||
try {
|
try {
|
||||||
const filter = Object.assign(fetchFilter, $props.filter); // eslint-disable-line vue/no-dupe-keys
|
const filter = { ...fetchFilter, ...$props.filter }; // eslint-disable-line vue/no-dupe-keys
|
||||||
if ($props.where && !fetchFilter.where) filter.where = $props.where;
|
if ($props.where && !fetchFilter.where) filter.where = $props.where;
|
||||||
if ($props.sortBy) filter.order = $props.sortBy;
|
if ($props.sortBy) filter.order = $props.sortBy;
|
||||||
if ($props.limit) filter.limit = $props.limit;
|
if ($props.limit) filter.limit = $props.limit;
|
||||||
|
|
|
@ -50,25 +50,25 @@ const loading = ref(false);
|
||||||
|
|
||||||
const tableColumns = computed(() => [
|
const tableColumns = computed(() => [
|
||||||
{
|
{
|
||||||
label: t('entry.buys.id'),
|
label: t('globals.id'),
|
||||||
name: 'id',
|
name: 'id',
|
||||||
field: 'id',
|
field: 'id',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('entry.buys.name'),
|
label: t('globals.name'),
|
||||||
name: 'name',
|
name: 'name',
|
||||||
field: 'name',
|
field: 'name',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('entry.buys.size'),
|
label: t('globals.size'),
|
||||||
name: 'size',
|
name: 'size',
|
||||||
field: 'size',
|
field: 'size',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('entry.buys.producer'),
|
label: t('globals.producer'),
|
||||||
name: 'producerName',
|
name: 'producerName',
|
||||||
field: 'producer',
|
field: 'producer',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
@ -84,34 +84,30 @@ const tableColumns = computed(() => [
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
try {
|
let filter = itemFilter;
|
||||||
let filter = itemFilter;
|
const params = itemFilterParams;
|
||||||
const params = itemFilterParams;
|
const where = {};
|
||||||
const where = {};
|
for (let key in params) {
|
||||||
for (let key in params) {
|
const value = params[key];
|
||||||
const value = params[key];
|
if (!value) continue;
|
||||||
if (!value) continue;
|
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'name':
|
case 'name':
|
||||||
where[key] = { like: `%${value}%` };
|
where[key] = { like: `%${value}%` };
|
||||||
break;
|
break;
|
||||||
case 'producerFk':
|
case 'producerFk':
|
||||||
case 'typeFk':
|
case 'typeFk':
|
||||||
case 'size':
|
case 'size':
|
||||||
case 'inkFk':
|
case 'inkFk':
|
||||||
where[key] = value;
|
where[key] = value;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
filter.where = where;
|
|
||||||
|
|
||||||
const { data } = await axios.get(props.url, {
|
|
||||||
params: { filter: JSON.stringify(filter) },
|
|
||||||
});
|
|
||||||
tableRows.value = data;
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching entries items');
|
|
||||||
}
|
}
|
||||||
|
filter.where = where;
|
||||||
|
|
||||||
|
const { data } = await axios.get(props.url, {
|
||||||
|
params: { filter: JSON.stringify(filter) },
|
||||||
|
});
|
||||||
|
tableRows.value = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeForm = () => {
|
const closeForm = () => {
|
||||||
|
@ -151,11 +147,11 @@ const selectItem = ({ id }) => {
|
||||||
<QIcon name="close" size="sm" />
|
<QIcon name="close" size="sm" />
|
||||||
</span>
|
</span>
|
||||||
<h1 class="title">{{ t('Filter item') }}</h1>
|
<h1 class="title">{{ t('Filter item') }}</h1>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnInput :label="t('entry.buys.name')" v-model="itemFilterParams.name" />
|
<VnInput :label="t('globals.name')" v-model="itemFilterParams.name" />
|
||||||
<VnInput :label="t('entry.buys.size')" v-model="itemFilterParams.size" />
|
<VnInput :label="t('entry.buys.size')" v-model="itemFilterParams.size" />
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('entry.buys.producer')"
|
:label="t('globals.producer')"
|
||||||
:options="producersOptions"
|
:options="producersOptions"
|
||||||
hide-selected
|
hide-selected
|
||||||
option-label="name"
|
option-label="name"
|
||||||
|
@ -163,7 +159,7 @@ const selectItem = ({ id }) => {
|
||||||
v-model="itemFilterParams.producerFk"
|
v-model="itemFilterParams.producerFk"
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('entry.buys.type')"
|
:label="t('globals.type')"
|
||||||
:options="ItemTypesOptions"
|
:options="ItemTypesOptions"
|
||||||
hide-selected
|
hide-selected
|
||||||
option-label="name"
|
option-label="name"
|
||||||
|
|
|
@ -48,13 +48,13 @@ const loading = ref(false);
|
||||||
|
|
||||||
const tableColumns = computed(() => [
|
const tableColumns = computed(() => [
|
||||||
{
|
{
|
||||||
label: t('entry.basicData.id'),
|
label: t('globals.id'),
|
||||||
name: 'id',
|
name: 'id',
|
||||||
field: 'id',
|
field: 'id',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('entry.basicData.warehouseOut'),
|
label: t('globals.warehouseOut'),
|
||||||
name: 'warehouseOutFk',
|
name: 'warehouseOutFk',
|
||||||
field: 'warehouseOutFk',
|
field: 'warehouseOutFk',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
@ -62,7 +62,7 @@ const tableColumns = computed(() => [
|
||||||
warehousesOptions.value.find((warehouse) => warehouse.id === val).name,
|
warehousesOptions.value.find((warehouse) => warehouse.id === val).name,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('entry.basicData.warehouseIn'),
|
label: t('globals.warehouseIn'),
|
||||||
name: 'warehouseInFk',
|
name: 'warehouseInFk',
|
||||||
field: 'warehouseInFk',
|
field: 'warehouseInFk',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
@ -70,14 +70,14 @@ const tableColumns = computed(() => [
|
||||||
warehousesOptions.value.find((warehouse) => warehouse.id === val).name,
|
warehousesOptions.value.find((warehouse) => warehouse.id === val).name,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('entry.basicData.shipped'),
|
label: t('globals.shipped'),
|
||||||
name: 'shipped',
|
name: 'shipped',
|
||||||
field: 'shipped',
|
field: 'shipped',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
format: (val) => toDate(val),
|
format: (val) => toDate(val),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('entry.basicData.landed'),
|
label: t('globals.landed'),
|
||||||
name: 'landed',
|
name: 'landed',
|
||||||
field: 'landed',
|
field: 'landed',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
@ -86,32 +86,28 @@ const tableColumns = computed(() => [
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
try {
|
let filter = travelFilter;
|
||||||
let filter = travelFilter;
|
const params = travelFilterParams;
|
||||||
const params = travelFilterParams;
|
const where = {};
|
||||||
const where = {};
|
for (let key in params) {
|
||||||
for (let key in params) {
|
const value = params[key];
|
||||||
const value = params[key];
|
if (!value) continue;
|
||||||
if (!value) continue;
|
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'agencyModeFk':
|
case 'agencyModeFk':
|
||||||
case 'warehouseInFk':
|
case 'warehouseInFk':
|
||||||
case 'warehouseOutFk':
|
case 'warehouseOutFk':
|
||||||
case 'shipped':
|
case 'shipped':
|
||||||
case 'landed':
|
case 'landed':
|
||||||
where[key] = value;
|
where[key] = value;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filter.where = where;
|
|
||||||
const { data } = await axios.get('Travels', {
|
|
||||||
params: { filter: JSON.stringify(filter) },
|
|
||||||
});
|
|
||||||
tableRows.value = data;
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching travels');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filter.where = where;
|
||||||
|
const { data } = await axios.get('Travels', {
|
||||||
|
params: { filter: JSON.stringify(filter) },
|
||||||
|
});
|
||||||
|
tableRows.value = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeForm = () => {
|
const closeForm = () => {
|
||||||
|
@ -144,9 +140,9 @@ const selectTravel = ({ id }) => {
|
||||||
<QIcon name="close" size="sm" />
|
<QIcon name="close" size="sm" />
|
||||||
</span>
|
</span>
|
||||||
<h1 class="title">{{ t('Filter travels') }}</h1>
|
<h1 class="title">{{ t('Filter travels') }}</h1>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('entry.basicData.agency')"
|
:label="t('globals.agency')"
|
||||||
:options="agenciesOptions"
|
:options="agenciesOptions"
|
||||||
hide-selected
|
hide-selected
|
||||||
option-label="name"
|
option-label="name"
|
||||||
|
@ -154,7 +150,7 @@ const selectTravel = ({ id }) => {
|
||||||
v-model="travelFilterParams.agencyModeFk"
|
v-model="travelFilterParams.agencyModeFk"
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('entry.basicData.warehouseOut')"
|
:label="t('globals.warehouseOut')"
|
||||||
:options="warehousesOptions"
|
:options="warehousesOptions"
|
||||||
hide-selected
|
hide-selected
|
||||||
option-label="name"
|
option-label="name"
|
||||||
|
@ -162,7 +158,7 @@ const selectTravel = ({ id }) => {
|
||||||
v-model="travelFilterParams.warehouseOutFk"
|
v-model="travelFilterParams.warehouseOutFk"
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('entry.basicData.warehouseIn')"
|
:label="t('globals.warehouseIn')"
|
||||||
:options="warehousesOptions"
|
:options="warehousesOptions"
|
||||||
hide-selected
|
hide-selected
|
||||||
option-label="name"
|
option-label="name"
|
||||||
|
@ -170,11 +166,11 @@ const selectTravel = ({ id }) => {
|
||||||
v-model="travelFilterParams.warehouseInFk"
|
v-model="travelFilterParams.warehouseInFk"
|
||||||
/>
|
/>
|
||||||
<VnInputDate
|
<VnInputDate
|
||||||
:label="t('entry.basicData.shipped')"
|
:label="t('globals.shipped')"
|
||||||
v-model="travelFilterParams.shipped"
|
v-model="travelFilterParams.shipped"
|
||||||
/>
|
/>
|
||||||
<VnInputDate
|
<VnInputDate
|
||||||
:label="t('entry.basicData.landed')"
|
:label="t('globals.landed')"
|
||||||
v-model="travelFilterParams.landed"
|
v-model="travelFilterParams.landed"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { onMounted, onUnmounted, computed, ref, watch, nextTick } from 'vue';
|
import { onMounted, onUnmounted, computed, ref, watch, nextTick } from 'vue';
|
||||||
import { onBeforeRouteLeave, useRouter } from 'vue-router';
|
import { onBeforeRouteLeave, useRouter, useRoute } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
import { useState } from 'src/composables/useState';
|
import { useState } from 'src/composables/useState';
|
||||||
|
@ -12,7 +12,6 @@ import SkeletonForm from 'components/ui/SkeletonForm.vue';
|
||||||
import VnConfirm from './ui/VnConfirm.vue';
|
import VnConfirm from './ui/VnConfirm.vue';
|
||||||
import { tMobile } from 'src/composables/tMobile';
|
import { tMobile } from 'src/composables/tMobile';
|
||||||
import { useArrayData } from 'src/composables/useArrayData';
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
import { useRoute } from 'vue-router';
|
|
||||||
|
|
||||||
const { push } = useRouter();
|
const { push } = useRouter();
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
|
@ -22,7 +21,7 @@ const { t } = useI18n();
|
||||||
const { validate } = useValidator();
|
const { validate } = useValidator();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const myForm = ref(null);
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
url: {
|
url: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -87,6 +86,14 @@ const $props = defineProps({
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
defaultTrim: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
maxWidth: {
|
||||||
|
type: [String, Boolean],
|
||||||
|
default: '800px',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const emit = defineEmits(['onFetch', 'onDataSaved']);
|
const emit = defineEmits(['onFetch', 'onDataSaved']);
|
||||||
const modelValue = computed(
|
const modelValue = computed(
|
||||||
|
@ -100,17 +107,21 @@ const isResetting = ref(false);
|
||||||
const hasChanges = ref(!$props.observeFormChanges);
|
const hasChanges = ref(!$props.observeFormChanges);
|
||||||
const originalData = ref({});
|
const originalData = ref({});
|
||||||
const formData = computed(() => state.get(modelValue));
|
const formData = computed(() => state.get(modelValue));
|
||||||
const formUrl = computed(() => $props.url);
|
|
||||||
const defaultButtons = computed(() => ({
|
const defaultButtons = computed(() => ({
|
||||||
save: {
|
save: {
|
||||||
|
dataCy: 'saveDefaultBtn',
|
||||||
color: 'primary',
|
color: 'primary',
|
||||||
icon: 'save',
|
icon: 'save',
|
||||||
label: 'globals.save',
|
label: 'globals.save',
|
||||||
|
click: () => myForm.value.submit(),
|
||||||
|
type: 'submit',
|
||||||
},
|
},
|
||||||
reset: {
|
reset: {
|
||||||
|
dataCy: 'resetDefaultBtn',
|
||||||
color: 'primary',
|
color: 'primary',
|
||||||
icon: 'restart_alt',
|
icon: 'restart_alt',
|
||||||
label: 'globals.reset',
|
label: 'globals.reset',
|
||||||
|
click: () => reset(),
|
||||||
},
|
},
|
||||||
...$props.defaultButtons,
|
...$props.defaultButtons,
|
||||||
}));
|
}));
|
||||||
|
@ -148,19 +159,22 @@ if (!$props.url)
|
||||||
(val) => updateAndEmit('onFetch', val)
|
(val) => updateAndEmit('onFetch', val)
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(formUrl, async () => {
|
watch(
|
||||||
originalData.value = null;
|
() => [$props.url, $props.filter],
|
||||||
reset();
|
async () => {
|
||||||
await fetch();
|
originalData.value = null;
|
||||||
});
|
reset();
|
||||||
|
await fetch();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
onBeforeRouteLeave((to, from, next) => {
|
onBeforeRouteLeave((to, from, next) => {
|
||||||
if (hasChanges.value && $props.observeFormChanges)
|
if (hasChanges.value && $props.observeFormChanges)
|
||||||
quasar.dialog({
|
quasar.dialog({
|
||||||
component: VnConfirm,
|
component: VnConfirm,
|
||||||
componentProps: {
|
componentProps: {
|
||||||
title: t('Unsaved changes will be lost'),
|
title: t('globals.unsavedPopup.title'),
|
||||||
message: t('Are you sure exit without saving?'),
|
message: t('globals.unsavedPopup.subtitle'),
|
||||||
promise: () => next(),
|
promise: () => next(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -184,6 +198,7 @@ async function fetch() {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
state.set(modelValue, {});
|
state.set(modelValue, {});
|
||||||
originalData.value = {};
|
originalData.value = {};
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +208,10 @@ async function save() {
|
||||||
|
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
try {
|
try {
|
||||||
const body = $props.mapper ? $props.mapper(formData.value) : formData.value;
|
formData.value = trimData(formData.value);
|
||||||
|
const body = $props.mapper
|
||||||
|
? $props.mapper(formData.value, originalData.value)
|
||||||
|
: formData.value;
|
||||||
const method = $props.urlCreate ? 'post' : 'patch';
|
const method = $props.urlCreate ? 'post' : 'patch';
|
||||||
const url =
|
const url =
|
||||||
$props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url;
|
$props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url;
|
||||||
|
@ -207,9 +225,6 @@ async function save() {
|
||||||
updateAndEmit('onDataSaved', formData.value, response?.data);
|
updateAndEmit('onDataSaved', formData.value, response?.data);
|
||||||
if ($props.reload) await arrayData.fetch({});
|
if ($props.reload) await arrayData.fetch({});
|
||||||
hasChanges.value = false;
|
hasChanges.value = false;
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
notify('errors.writeRequest', 'negative');
|
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
|
@ -251,17 +266,35 @@ function updateAndEmit(evt, val, res) {
|
||||||
emit(evt, state.get(modelValue), res);
|
emit(evt, state.get(modelValue), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trimData(data) {
|
||||||
|
if (!$props.defaultTrim) return data;
|
||||||
|
for (const key in data) {
|
||||||
|
if (typeof data[key] == 'string') data[key] = data[key].trim();
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
save,
|
save,
|
||||||
isLoading,
|
isLoading,
|
||||||
hasChanges,
|
hasChanges,
|
||||||
reset,
|
reset,
|
||||||
fetch,
|
fetch,
|
||||||
|
formData,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="column items-center full-width">
|
<div class="column items-center full-width">
|
||||||
<QForm @submit="save" @reset="reset" class="q-pa-md" id="formModel">
|
<QForm
|
||||||
|
ref="myForm"
|
||||||
|
v-if="formData"
|
||||||
|
@submit="save"
|
||||||
|
@reset="reset"
|
||||||
|
class="q-pa-md"
|
||||||
|
:style="maxWidth ? 'max-width: ' + maxWidth : ''"
|
||||||
|
id="formModel"
|
||||||
|
:prevent-submit="$attrs['prevent-submit']"
|
||||||
|
>
|
||||||
<QCard>
|
<QCard>
|
||||||
<slot
|
<slot
|
||||||
v-if="formData"
|
v-if="formData"
|
||||||
|
@ -289,11 +322,12 @@ defineExpose({
|
||||||
:color="defaultButtons.reset.color"
|
:color="defaultButtons.reset.color"
|
||||||
:icon="defaultButtons.reset.icon"
|
:icon="defaultButtons.reset.icon"
|
||||||
flat
|
flat
|
||||||
@click="reset"
|
@click="defaultButtons.reset.click"
|
||||||
:disable="!hasChanges"
|
:disable="!hasChanges"
|
||||||
:title="t(defaultButtons.reset.label)"
|
:title="t(defaultButtons.reset.label)"
|
||||||
/>
|
/>
|
||||||
<QBtnDropdown
|
<QBtnDropdown
|
||||||
|
data-cy="saveAndContinueDefaultBtn"
|
||||||
v-if="$props.goTo"
|
v-if="$props.goTo"
|
||||||
@click="saveAndGo"
|
@click="saveAndGo"
|
||||||
:label="tMobile('globals.saveAndContinue')"
|
:label="tMobile('globals.saveAndContinue')"
|
||||||
|
@ -329,7 +363,7 @@ defineExpose({
|
||||||
:label="tMobile('globals.save')"
|
:label="tMobile('globals.save')"
|
||||||
color="primary"
|
color="primary"
|
||||||
icon="save"
|
icon="save"
|
||||||
@click="save"
|
@click="defaultButtons.save.click"
|
||||||
:disable="!hasChanges"
|
:disable="!hasChanges"
|
||||||
:title="t(defaultButtons.save.label)"
|
:title="t(defaultButtons.save.label)"
|
||||||
/>
|
/>
|
||||||
|
@ -348,7 +382,6 @@ defineExpose({
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
#formModel {
|
#formModel {
|
||||||
max-width: 800px;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,8 +389,3 @@ defineExpose({
|
||||||
padding: 32px;
|
padding: 32px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<i18n>
|
|
||||||
es:
|
|
||||||
Unsaved changes will be lost: Los cambios que no haya guardado se perderán
|
|
||||||
Are you sure exit without saving?: ¿Seguro que quiere salir sin guardar?
|
|
||||||
</i18n>
|
|
||||||
|
|
|
@ -61,6 +61,8 @@ defineExpose({
|
||||||
:loading="isLoading"
|
:loading="isLoading"
|
||||||
@click="emit('onDataCanceled')"
|
@click="emit('onDataCanceled')"
|
||||||
v-close-popup
|
v-close-popup
|
||||||
|
data-cy="FormModelPopup_cancel"
|
||||||
|
z-max
|
||||||
/>
|
/>
|
||||||
<QBtn
|
<QBtn
|
||||||
:label="t('globals.save')"
|
:label="t('globals.save')"
|
||||||
|
@ -70,6 +72,8 @@ defineExpose({
|
||||||
class="q-ml-sm"
|
class="q-ml-sm"
|
||||||
:disabled="isLoading"
|
:disabled="isLoading"
|
||||||
:loading="isLoading"
|
:loading="isLoading"
|
||||||
|
data-cy="FormModelPopup_save"
|
||||||
|
z-max
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
const emit = defineEmits(['onSubmit']);
|
const emit = defineEmits(['onSubmit']);
|
||||||
|
|
||||||
defineProps({
|
const $props = defineProps({
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -25,16 +25,21 @@ defineProps({
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
submitOnEnter: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const closeButton = ref(null);
|
const closeButton = ref(null);
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
|
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
emit('onSubmit');
|
if ($props.submitOnEnter) {
|
||||||
closeForm();
|
emit('onSubmit');
|
||||||
|
closeForm();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeForm = () => {
|
const closeForm = () => {
|
||||||
|
|
|
@ -9,6 +9,8 @@ import VnSelect from 'components/common/VnSelect.vue';
|
||||||
import VnFilterPanelChip from 'components/ui/VnFilterPanelChip.vue';
|
import VnFilterPanelChip from 'components/ui/VnFilterPanelChip.vue';
|
||||||
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { getParamWhere } from 'src/filters';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
@ -26,28 +28,21 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const itemCategories = ref([]);
|
const route = useRoute();
|
||||||
const selectedCategoryFk = ref(null);
|
|
||||||
const selectedTypeFk = ref(null);
|
|
||||||
const itemTypesOptions = ref([]);
|
const itemTypesOptions = ref([]);
|
||||||
const suppliersOptions = ref([]);
|
const suppliersOptions = ref([]);
|
||||||
const tagOptions = ref([]);
|
const tagOptions = ref([]);
|
||||||
const tagValues = ref([]);
|
const tagValues = ref([]);
|
||||||
|
const categoryList = ref(null);
|
||||||
|
const selectedCategoryFk = ref(getParamWhere(route.query.table, 'categoryFk', false));
|
||||||
|
const selectedTypeFk = ref(getParamWhere(route.query.table, 'typeFk', false));
|
||||||
|
|
||||||
const categoryList = computed(() => {
|
const selectedCategory = computed(() => {
|
||||||
return (itemCategories.value || [])
|
return (categoryList.value || []).find(
|
||||||
.filter((category) => category.display)
|
|
||||||
.map((category) => ({
|
|
||||||
...category,
|
|
||||||
icon: `vn:${(category.icon || '').split('-')[1]}`,
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
const selectedCategory = computed(() =>
|
|
||||||
(itemCategories.value || []).find(
|
|
||||||
(category) => category?.id === selectedCategoryFk.value
|
(category) => category?.id === selectedCategoryFk.value
|
||||||
)
|
);
|
||||||
);
|
});
|
||||||
|
|
||||||
const selectedType = computed(() => {
|
const selectedType = computed(() => {
|
||||||
return (itemTypesOptions.value || []).find(
|
return (itemTypesOptions.value || []).find(
|
||||||
|
@ -87,21 +82,17 @@ const applyTags = (params, search) => {
|
||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchItemTypes = async (id) => {
|
const fetchItemTypes = async (id = selectedCategoryFk.value) => {
|
||||||
try {
|
const filter = {
|
||||||
const filter = {
|
fields: ['id', 'name', 'categoryFk'],
|
||||||
fields: ['id', 'name', 'categoryFk'],
|
where: { categoryFk: id },
|
||||||
where: { categoryFk: id },
|
include: 'category',
|
||||||
include: 'category',
|
order: 'name ASC',
|
||||||
order: 'name ASC',
|
};
|
||||||
};
|
const { data } = await axios.get('ItemTypes', {
|
||||||
const { data } = await axios.get('ItemTypes', {
|
params: { filter: JSON.stringify(filter) },
|
||||||
params: { filter: JSON.stringify(filter) },
|
});
|
||||||
});
|
itemTypesOptions.value = data;
|
||||||
itemTypesOptions.value = data;
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching item types', err);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCategoryClass = (category, params) => {
|
const getCategoryClass = (category, params) => {
|
||||||
|
@ -111,37 +102,38 @@ const getCategoryClass = (category, params) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSelectedTagValues = async (tag) => {
|
const getSelectedTagValues = async (tag) => {
|
||||||
try {
|
if (!tag?.selectedTag?.id) return;
|
||||||
tag.value = null;
|
tag.value = null;
|
||||||
const filter = {
|
const filter = {
|
||||||
fields: ['value'],
|
fields: ['value'],
|
||||||
order: 'value ASC',
|
order: 'value ASC',
|
||||||
limit: 30,
|
limit: 30,
|
||||||
};
|
};
|
||||||
|
|
||||||
const params = { filter: JSON.stringify(filter) };
|
const params = { filter: JSON.stringify(filter) };
|
||||||
const { data } = await axios.get(`Tags/${tag.selectedTag.id}/filterValue`, {
|
const { data } = await axios.get(`Tags/${tag.selectedTag.id}/filterValue`, {
|
||||||
params,
|
params,
|
||||||
});
|
});
|
||||||
tag.valueOptions = data;
|
tag.valueOptions = data;
|
||||||
} catch (err) {
|
|
||||||
console.error('Error getting selected tag values');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeTag = (index, params, search) => {
|
const removeTag = (index, params, search) => {
|
||||||
(tagValues.value || []).splice(index, 1);
|
(tagValues.value || []).splice(index, 1);
|
||||||
applyTags(params, search);
|
applyTags(params, search);
|
||||||
};
|
};
|
||||||
|
const setCategoryList = (data) => {
|
||||||
|
categoryList.value = (data || [])
|
||||||
|
.filter((category) => category.display)
|
||||||
|
.map((category) => ({
|
||||||
|
...category,
|
||||||
|
icon: `vn:${(category.icon || '').split('-')[1]}`,
|
||||||
|
}));
|
||||||
|
fetchItemTypes();
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
<FetchData url="ItemCategories" limit="30" auto-load @on-fetch="setCategoryList" />
|
||||||
url="ItemCategories"
|
|
||||||
limit="30"
|
|
||||||
auto-load
|
|
||||||
@on-fetch="(data) => (itemCategories = data)"
|
|
||||||
/>
|
|
||||||
<FetchData
|
<FetchData
|
||||||
url="Suppliers"
|
url="Suppliers"
|
||||||
limit="30"
|
limit="30"
|
||||||
|
@ -158,8 +150,8 @@ const removeTag = (index, params, search) => {
|
||||||
/>
|
/>
|
||||||
<VnFilterPanel
|
<VnFilterPanel
|
||||||
:data-key="props.dataKey"
|
:data-key="props.dataKey"
|
||||||
:expr-builder="exprBuilder"
|
:expr-builder="props.exprBuilder"
|
||||||
:custom-tags="customTags"
|
:custom-tags="props.customTags"
|
||||||
>
|
>
|
||||||
<template #tags="{ tag, formatFn }">
|
<template #tags="{ tag, formatFn }">
|
||||||
<strong v-if="tag.label === 'categoryFk'">
|
<strong v-if="tag.label === 'categoryFk'">
|
||||||
|
@ -247,7 +239,7 @@ const removeTag = (index, params, search) => {
|
||||||
>
|
>
|
||||||
<QItemSection class="col">
|
<QItemSection class="col">
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('components.itemsFilterPanel.tag')"
|
:label="t('globals.tag')"
|
||||||
v-model="value.selectedTag"
|
v-model="value.selectedTag"
|
||||||
:options="tagOptions"
|
:options="tagOptions"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
|
@ -296,11 +288,12 @@ const removeTag = (index, params, search) => {
|
||||||
/>
|
/>
|
||||||
</QItem>
|
</QItem>
|
||||||
<QItem class="q-mt-lg">
|
<QItem class="q-mt-lg">
|
||||||
<QIcon
|
<QBtn
|
||||||
name="add_circle"
|
icon="add_circle"
|
||||||
|
shortcut="+"
|
||||||
|
flat
|
||||||
class="fill-icon-on-hover q-px-xs"
|
class="fill-icon-on-hover q-px-xs"
|
||||||
color="primary"
|
color="primary"
|
||||||
size="sm"
|
|
||||||
@click="tagValues.push({})"
|
@click="tagValues.push({})"
|
||||||
/>
|
/>
|
||||||
</QItem>
|
</QItem>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { onMounted, ref, reactive } from 'vue';
|
import { onMounted, watch, ref, reactive, computed } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { QSeparator, useQuasar } from 'quasar';
|
import { QSeparator, useQuasar } from 'quasar';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
@ -9,6 +9,7 @@ import { toLowerCamel } from 'src/filters';
|
||||||
import routes from 'src/router/modules';
|
import routes from 'src/router/modules';
|
||||||
import LeftMenuItem from './LeftMenuItem.vue';
|
import LeftMenuItem from './LeftMenuItem.vue';
|
||||||
import LeftMenuItemGroup from './LeftMenuItemGroup.vue';
|
import LeftMenuItemGroup from './LeftMenuItemGroup.vue';
|
||||||
|
import VnInput from './common/VnInput.vue';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
@ -21,14 +22,58 @@ const props = defineProps({
|
||||||
default: 'main',
|
default: 'main',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const initialized = ref(false);
|
||||||
|
const items = ref([]);
|
||||||
const expansionItemElements = reactive({});
|
const expansionItemElements = reactive({});
|
||||||
|
const pinnedModules = computed(() => {
|
||||||
|
const map = new Map();
|
||||||
|
items.value.forEach((item) => item.isPinned && map.set(item.name, item));
|
||||||
|
return map;
|
||||||
|
});
|
||||||
|
const search = ref(null);
|
||||||
|
|
||||||
|
const filteredItems = computed(() => {
|
||||||
|
if (!search.value) return items.value;
|
||||||
|
const normalizedSearch = normalize(search.value);
|
||||||
|
return items.value.filter((item) => {
|
||||||
|
const locale = normalize(t(item.title));
|
||||||
|
return locale.includes(normalizedSearch);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const filteredPinnedModules = computed(() => {
|
||||||
|
if (!search.value) return pinnedModules.value;
|
||||||
|
const normalizedSearch = search.value
|
||||||
|
.normalize('NFD')
|
||||||
|
.replace(/[\u0300-\u036f]/g, '')
|
||||||
|
.toLowerCase();
|
||||||
|
const map = new Map();
|
||||||
|
for (const [key, pinnedModule] of pinnedModules.value) {
|
||||||
|
const locale = t(pinnedModule.title)
|
||||||
|
.normalize('NFD')
|
||||||
|
.replace(/[\u0300-\u036f]/g, '')
|
||||||
|
.toLowerCase();
|
||||||
|
if (locale.includes(normalizedSearch)) map.set(key, pinnedModule);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await navigation.fetchPinned();
|
await navigation.fetchPinned();
|
||||||
getRoutes();
|
getRoutes();
|
||||||
|
initialized.value = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => route.matched,
|
||||||
|
() => {
|
||||||
|
if (!initialized.value) return;
|
||||||
|
items.value = [];
|
||||||
|
getRoutes();
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
);
|
||||||
|
|
||||||
function findMatches(search, item) {
|
function findMatches(search, item) {
|
||||||
const matches = [];
|
const matches = [];
|
||||||
function findRoute(search, item) {
|
function findRoute(search, item) {
|
||||||
|
@ -47,18 +92,16 @@ function findMatches(search, item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addChildren(module, route, parent) {
|
function addChildren(module, route, parent) {
|
||||||
if (route.menus) {
|
const menus = route?.meta?.menu ?? route?.menus?.[props.source]; //backwards compatible
|
||||||
const mainMenus = route.menus[props.source];
|
if (!menus) return;
|
||||||
const matches = findMatches(mainMenus, route);
|
|
||||||
|
|
||||||
for (const child of matches) {
|
const matches = findMatches(menus, route);
|
||||||
navigation.addMenuItem(module, child, parent);
|
|
||||||
}
|
for (const child of matches) {
|
||||||
|
navigation.addMenuItem(module, child, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = ref([]);
|
|
||||||
|
|
||||||
function getRoutes() {
|
function getRoutes() {
|
||||||
if (props.source === 'main') {
|
if (props.source === 'main') {
|
||||||
const modules = Object.assign([], navigation.getModules().value);
|
const modules = Object.assign([], navigation.getModules().value);
|
||||||
|
@ -79,16 +122,26 @@ function getRoutes() {
|
||||||
if (props.source === 'card') {
|
if (props.source === 'card') {
|
||||||
const currentRoute = route.matched[1];
|
const currentRoute = route.matched[1];
|
||||||
const currentModule = toLowerCamel(currentRoute.name);
|
const currentModule = toLowerCamel(currentRoute.name);
|
||||||
const moduleDef = routes.find(
|
let moduleDef = routes.find(
|
||||||
(route) => toLowerCamel(route.name) === currentModule
|
(route) => toLowerCamel(route.name) === currentModule
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!moduleDef) return;
|
if (!moduleDef) return;
|
||||||
|
if (!moduleDef?.menus) moduleDef = betaGetRoutes();
|
||||||
addChildren(currentModule, moduleDef, items.value);
|
addChildren(currentModule, moduleDef, items.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function betaGetRoutes() {
|
||||||
|
let menuRoute;
|
||||||
|
let index = route.matched.length - 1;
|
||||||
|
while (!menuRoute && index > 0) {
|
||||||
|
if (route.matched[index]?.meta?.menu) menuRoute = route.matched[index];
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
return menuRoute;
|
||||||
|
}
|
||||||
|
|
||||||
async function togglePinned(item, event) {
|
async function togglePinned(item, event) {
|
||||||
if (event.defaultPrevented) return;
|
if (event.defaultPrevented) return;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -114,21 +167,58 @@ async function togglePinned(item, event) {
|
||||||
const handleItemExpansion = (itemName) => {
|
const handleItemExpansion = (itemName) => {
|
||||||
expansionItemElements[itemName].scrollToLastElement();
|
expansionItemElements[itemName].scrollToLastElement();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function normalize(text) {
|
||||||
|
return text
|
||||||
|
.normalize('NFD')
|
||||||
|
.replace(/[\u0300-\u036f]/g, '')
|
||||||
|
.toLowerCase();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<QList padding class="column-max-width">
|
<QList padding class="column-max-width">
|
||||||
<template v-if="$props.source === 'main'">
|
<template v-if="$props.source === 'main'">
|
||||||
<template v-if="$route?.matched[1]?.name === 'Dashboard'">
|
<template v-if="$route?.matched[1]?.name === 'Dashboard'">
|
||||||
<QItem class="header">
|
<QItem class="q-pb-md">
|
||||||
<QItemSection avatar>
|
<VnInput
|
||||||
<QIcon name="view_module" />
|
v-model="search"
|
||||||
</QItemSection>
|
:label="t('Search modules')"
|
||||||
<QItemSection> {{ t('globals.modules') }}</QItemSection>
|
class="full-width"
|
||||||
|
filled
|
||||||
|
dense
|
||||||
|
autofocus
|
||||||
|
/>
|
||||||
</QItem>
|
</QItem>
|
||||||
<QSeparator />
|
<QSeparator />
|
||||||
<template v-for="item in items" :key="item.name">
|
<template v-if="filteredPinnedModules.size">
|
||||||
<template v-if="item.children">
|
<LeftMenuItem
|
||||||
|
v-for="[key, pinnedModule] of filteredPinnedModules"
|
||||||
|
:key="key"
|
||||||
|
:item="pinnedModule"
|
||||||
|
group="modules"
|
||||||
|
>
|
||||||
|
<template #side>
|
||||||
|
<QBtn
|
||||||
|
v-if="pinnedModule.isPinned === true"
|
||||||
|
@click="togglePinned(pinnedModule, $event)"
|
||||||
|
icon="remove_circle"
|
||||||
|
size="xs"
|
||||||
|
flat
|
||||||
|
round
|
||||||
|
>
|
||||||
|
<QTooltip>
|
||||||
|
{{ t('components.leftMenu.removeFromPinned') }}
|
||||||
|
</QTooltip>
|
||||||
|
</QBtn>
|
||||||
|
</template>
|
||||||
|
</LeftMenuItem>
|
||||||
|
<QSeparator />
|
||||||
|
</template>
|
||||||
|
<template v-for="item in filteredItems" :key="item.name">
|
||||||
|
<template
|
||||||
|
v-if="item.children && !filteredPinnedModules.has(item.name)"
|
||||||
|
>
|
||||||
<LeftMenuItem :item="item" group="modules">
|
<LeftMenuItem :item="item" group="modules">
|
||||||
<template #side>
|
<template #side>
|
||||||
<QBtn
|
<QBtn
|
||||||
|
@ -247,3 +337,7 @@ const handleItemExpansion = (itemName) => {
|
||||||
color: var(--vn-label-color);
|
color: var(--vn-label-color);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<i18n>
|
||||||
|
es:
|
||||||
|
Search modules: Buscar módulos
|
||||||
|
</i18n>
|
||||||
|
|
|
@ -33,13 +33,17 @@ const itemComputed = computed(() => {
|
||||||
<QItemSection avatar v-if="!itemComputed.icon">
|
<QItemSection avatar v-if="!itemComputed.icon">
|
||||||
<QIcon name="disabled_by_default" />
|
<QIcon name="disabled_by_default" />
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
<QItemSection>{{ t(itemComputed.title) }}</QItemSection>
|
<QItemSection>
|
||||||
|
{{ t(itemComputed.title) }}
|
||||||
|
<QTooltip v-if="item.keyBinding">
|
||||||
|
{{ 'Ctrl + Alt + ' + item?.keyBinding?.toUpperCase() }}
|
||||||
|
</QTooltip>
|
||||||
|
</QItemSection>
|
||||||
<QItemSection side>
|
<QItemSection side>
|
||||||
<slot name="side" :item="itemComputed" />
|
<slot name="side" :item="itemComputed" />
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.q-item {
|
.q-item {
|
||||||
min-height: 5vh;
|
min-height: 5vh;
|
||||||
|
|
|
@ -3,28 +3,34 @@ import { onMounted, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useState } from 'src/composables/useState';
|
import { useState } from 'src/composables/useState';
|
||||||
import { useStateStore } from 'stores/useStateStore';
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
|
import { useStateQueryStore } from 'src/stores/useStateQueryStore';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
import PinnedModules from './PinnedModules.vue';
|
import PinnedModules from './PinnedModules.vue';
|
||||||
import UserPanel from 'components/UserPanel.vue';
|
import UserPanel from 'components/UserPanel.vue';
|
||||||
import VnBreadcrumbs from './common/VnBreadcrumbs.vue';
|
import VnBreadcrumbs from './common/VnBreadcrumbs.vue';
|
||||||
import VnImg from 'src/components/ui/VnImg.vue';
|
import VnAvatar from './ui/VnAvatar.vue';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
|
const stateQuery = useStateQueryStore();
|
||||||
const state = useState();
|
const state = useState();
|
||||||
const user = state.getUser();
|
const user = state.getUser();
|
||||||
const appName = 'Lilium';
|
const appName = 'Lilium';
|
||||||
|
const pinnedModulesRef = ref();
|
||||||
|
|
||||||
onMounted(() => stateStore.setMounted());
|
onMounted(() => stateStore.setMounted());
|
||||||
|
|
||||||
const pinnedModulesRef = ref();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<QHeader color="white" elevated>
|
<QHeader color="white" elevated>
|
||||||
<QToolbar class="q-py-sm q-px-md">
|
<QToolbar class="q-py-sm q-px-md">
|
||||||
<QBtn @click="stateStore.toggleLeftDrawer()" icon="menu" round dense flat>
|
<QBtn
|
||||||
|
@click="stateStore.toggleLeftDrawer()"
|
||||||
|
icon="dock_to_right"
|
||||||
|
round
|
||||||
|
dense
|
||||||
|
flat
|
||||||
|
>
|
||||||
<QTooltip bottom anchor="bottom right">
|
<QTooltip bottom anchor="bottom right">
|
||||||
{{ t('globals.collapseMenu') }}
|
{{ t('globals.collapseMenu') }}
|
||||||
</QTooltip>
|
</QTooltip>
|
||||||
|
@ -44,21 +50,20 @@ const pinnedModulesRef = ref();
|
||||||
</QBtn>
|
</QBtn>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
<VnBreadcrumbs v-if="$q.screen.gt.sm" />
|
<VnBreadcrumbs v-if="$q.screen.gt.sm" />
|
||||||
|
<QSpinner
|
||||||
|
color="primary"
|
||||||
|
class="q-ml-md"
|
||||||
|
:class="{
|
||||||
|
'no-visible': !stateQuery.isLoading().value,
|
||||||
|
}"
|
||||||
|
size="xs"
|
||||||
|
data-cy="loading-spinner"
|
||||||
|
/>
|
||||||
<QSpace />
|
<QSpace />
|
||||||
<div id="searchbar" class="searchbar"></div>
|
<div id="searchbar" class="searchbar"></div>
|
||||||
<QSpace />
|
<QSpace />
|
||||||
<div class="q-pl-sm q-gutter-sm row items-center no-wrap">
|
<div class="q-pl-sm q-gutter-sm row items-center no-wrap">
|
||||||
<div id="actions-prepend"></div>
|
<div id="actions-prepend"></div>
|
||||||
<QBtn
|
|
||||||
flat
|
|
||||||
v-if="!quasar.platform.is.mobile"
|
|
||||||
@click="pinnedModulesRef.redirect($route.params.id)"
|
|
||||||
icon="more_up"
|
|
||||||
>
|
|
||||||
<QTooltip>
|
|
||||||
{{ t('Go to Salix') }}
|
|
||||||
</QTooltip>
|
|
||||||
</QBtn>
|
|
||||||
<QBtn
|
<QBtn
|
||||||
:class="{ 'q-pa-none': quasar.platform.is.mobile }"
|
:class="{ 'q-pa-none': quasar.platform.is.mobile }"
|
||||||
id="pinnedModules"
|
id="pinnedModules"
|
||||||
|
@ -72,22 +77,13 @@ const pinnedModulesRef = ref();
|
||||||
</QTooltip>
|
</QTooltip>
|
||||||
<PinnedModules ref="pinnedModulesRef" />
|
<PinnedModules ref="pinnedModulesRef" />
|
||||||
</QBtn>
|
</QBtn>
|
||||||
<QBtn
|
<QBtn class="q-pa-none" rounded dense flat no-wrap id="user">
|
||||||
:class="{ 'q-pa-none': quasar.platform.is.mobile }"
|
<VnAvatar
|
||||||
rounded
|
:worker-id="user.id"
|
||||||
dense
|
:title="user.name"
|
||||||
flat
|
size="lg"
|
||||||
no-wrap
|
color="transparent"
|
||||||
id="user"
|
/>
|
||||||
>
|
|
||||||
<QAvatar size="lg">
|
|
||||||
<VnImg
|
|
||||||
:id="user.id"
|
|
||||||
collection="user"
|
|
||||||
size="160x160"
|
|
||||||
:zoom-size="null"
|
|
||||||
/>
|
|
||||||
</QAvatar>
|
|
||||||
<QTooltip bottom>
|
<QTooltip bottom>
|
||||||
{{ t('globals.userPanel') }}
|
{{ t('globals.userPanel') }}
|
||||||
</QTooltip>
|
</QTooltip>
|
||||||
|
@ -99,7 +95,6 @@ const pinnedModulesRef = ref();
|
||||||
<VnBreadcrumbs v-if="$q.screen.lt.md" class="q-ml-md" />
|
<VnBreadcrumbs v-if="$q.screen.lt.md" class="q-ml-md" />
|
||||||
</QHeader>
|
</QHeader>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.searchbar {
|
.searchbar {
|
||||||
width: max-content;
|
width: max-content;
|
||||||
|
@ -108,9 +103,3 @@ const pinnedModulesRef = ref();
|
||||||
background-color: var(--vn-section-color);
|
background-color: var(--vn-section-color);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<i18n>
|
|
||||||
en:
|
|
||||||
Go to Salix: Go to Salix
|
|
||||||
es:
|
|
||||||
Go to Salix: Ir a Salix
|
|
||||||
</i18n>
|
|
||||||
|
|
|
@ -0,0 +1,170 @@
|
||||||
|
<script setup>
|
||||||
|
import { ref, reactive } from 'vue';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
import { useDialogPluginComponent } from 'quasar';
|
||||||
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
|
import FetchData from 'components/FetchData.vue';
|
||||||
|
import VnSelect from 'components/common/VnSelect.vue';
|
||||||
|
import FormPopup from './FormPopup.vue';
|
||||||
|
import axios from 'axios';
|
||||||
|
import useNotify from 'src/composables/useNotify.js';
|
||||||
|
|
||||||
|
const $props = defineProps({
|
||||||
|
invoiceOutData: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { dialogRef } = useDialogPluginComponent();
|
||||||
|
const { t } = useI18n();
|
||||||
|
const router = useRouter();
|
||||||
|
const { notify } = useNotify();
|
||||||
|
|
||||||
|
const rectificativeTypeOptions = ref([]);
|
||||||
|
const siiTypeInvoiceOutsOptions = ref([]);
|
||||||
|
const invoiceParams = reactive({
|
||||||
|
id: $props.invoiceOutData?.id,
|
||||||
|
inheritWarehouse: true,
|
||||||
|
});
|
||||||
|
const invoiceCorrectionTypesOptions = ref([]);
|
||||||
|
|
||||||
|
const refund = async () => {
|
||||||
|
const params = {
|
||||||
|
id: invoiceParams.id,
|
||||||
|
withWarehouse: invoiceParams.inheritWarehouse,
|
||||||
|
cplusRectificationTypeFk: invoiceParams.cplusRectificationTypeFk,
|
||||||
|
siiTypeInvoiceOutFk: invoiceParams.siiTypeInvoiceOutFk,
|
||||||
|
invoiceCorrectionTypeFk: invoiceParams.invoiceCorrectionTypeFk,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = await axios.post('InvoiceOuts/refundAndInvoice', params);
|
||||||
|
notify(t('Refunded invoice'), 'positive');
|
||||||
|
const [id] = data?.refundId || [];
|
||||||
|
if (id) router.push({ name: 'InvoiceOutSummary', params: { id } });
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<FetchData
|
||||||
|
url="CplusRectificationTypes"
|
||||||
|
:filter="{ order: 'description' }"
|
||||||
|
@on-fetch="
|
||||||
|
(data) => (
|
||||||
|
(rectificativeTypeOptions = data),
|
||||||
|
(invoiceParams.cplusRectificationTypeFk = data.filter(
|
||||||
|
(type) => type.description == 'I – Por diferencias'
|
||||||
|
)[0].id)
|
||||||
|
)
|
||||||
|
"
|
||||||
|
auto-load
|
||||||
|
/>
|
||||||
|
<FetchData
|
||||||
|
url="SiiTypeInvoiceOuts"
|
||||||
|
:filter="{ where: { code: { like: 'R%' } } }"
|
||||||
|
@on-fetch="
|
||||||
|
(data) => (
|
||||||
|
(siiTypeInvoiceOutsOptions = data),
|
||||||
|
(invoiceParams.siiTypeInvoiceOutFk = data.filter(
|
||||||
|
(type) => type.code == 'R4'
|
||||||
|
)[0].id)
|
||||||
|
)
|
||||||
|
"
|
||||||
|
auto-load
|
||||||
|
/>
|
||||||
|
<FetchData
|
||||||
|
url="InvoiceCorrectionTypes"
|
||||||
|
@on-fetch="(data) => (invoiceCorrectionTypesOptions = data)"
|
||||||
|
auto-load
|
||||||
|
/>
|
||||||
|
|
||||||
|
<QDialog ref="dialogRef">
|
||||||
|
<FormPopup
|
||||||
|
@on-submit="refund()"
|
||||||
|
:custom-submit-button-label="t('Accept')"
|
||||||
|
:default-cancel-button="false"
|
||||||
|
>
|
||||||
|
<template #form-inputs>
|
||||||
|
<VnRow>
|
||||||
|
<VnSelect
|
||||||
|
:label="t('Rectificative type')"
|
||||||
|
:options="rectificativeTypeOptions"
|
||||||
|
hide-selected
|
||||||
|
option-label="description"
|
||||||
|
option-value="id"
|
||||||
|
v-model="invoiceParams.cplusRectificationTypeFk"
|
||||||
|
:required="true"
|
||||||
|
/>
|
||||||
|
</VnRow>
|
||||||
|
<VnRow>
|
||||||
|
<VnSelect
|
||||||
|
:label="t('Class')"
|
||||||
|
:options="siiTypeInvoiceOutsOptions"
|
||||||
|
hide-selected
|
||||||
|
option-label="description"
|
||||||
|
option-value="id"
|
||||||
|
v-model="invoiceParams.siiTypeInvoiceOutFk"
|
||||||
|
:required="true"
|
||||||
|
>
|
||||||
|
<template #option="scope">
|
||||||
|
<QItem v-bind="scope.itemProps">
|
||||||
|
<QItemSection>
|
||||||
|
<QItemLabel>
|
||||||
|
{{ scope.opt?.code }} -
|
||||||
|
{{ scope.opt?.description }}
|
||||||
|
</QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
|
</template>
|
||||||
|
</VnSelect>
|
||||||
|
</VnRow>
|
||||||
|
|
||||||
|
<VnRow>
|
||||||
|
<VnSelect
|
||||||
|
:label="t('Type')"
|
||||||
|
:options="invoiceCorrectionTypesOptions"
|
||||||
|
hide-selected
|
||||||
|
option-label="description"
|
||||||
|
option-value="id"
|
||||||
|
v-model="invoiceParams.invoiceCorrectionTypeFk"
|
||||||
|
:required="true"
|
||||||
|
/> </VnRow
|
||||||
|
><VnRow>
|
||||||
|
<div>
|
||||||
|
<QCheckbox
|
||||||
|
:label="t('Inherit warehouse')"
|
||||||
|
v-model="invoiceParams.inheritWarehouse"
|
||||||
|
/>
|
||||||
|
<QIcon name="info" class="cursor-info q-ml-sm" size="sm">
|
||||||
|
<QTooltip>{{ t('Inherit warehouse tooltip') }}</QTooltip>
|
||||||
|
</QIcon>
|
||||||
|
</div>
|
||||||
|
</VnRow>
|
||||||
|
</template>
|
||||||
|
</FormPopup>
|
||||||
|
</QDialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<i18n>
|
||||||
|
en:
|
||||||
|
Refund invoice: Refund invoice
|
||||||
|
Rectificative type: Rectificative type
|
||||||
|
Class: Class
|
||||||
|
Type: Type
|
||||||
|
Refunded invoice: Refunded invoice
|
||||||
|
Inherit warehouse: Inherit the warehouse
|
||||||
|
Inherit warehouse tooltip: Select this option to inherit the warehouse when refunding the invoice
|
||||||
|
Accept: Accept
|
||||||
|
Error refunding invoice: Error refunding invoice
|
||||||
|
es:
|
||||||
|
Refund invoice: Abonar factura
|
||||||
|
Rectificative type: Tipo rectificativa
|
||||||
|
Class: Clase
|
||||||
|
Type: Tipo
|
||||||
|
Refunded invoice: Factura abonada
|
||||||
|
Inherit warehouse: Heredar el almacén
|
||||||
|
Inherit warehouse tooltip: Seleccione esta opción para heredar el almacén al abonar la factura.
|
||||||
|
Accept: Aceptar
|
||||||
|
Error refunding invoice: Error abonando factura
|
||||||
|
</i18n>
|
|
@ -15,7 +15,7 @@ const props = defineProps({
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
warehouseFk: {
|
warehouseFk: {
|
||||||
type: Boolean,
|
type: Number,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@ const props = defineProps({
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const regularizeFormData = reactive({
|
const regularizeFormData = reactive({
|
||||||
itemFk: props.itemFk,
|
itemFk: Number(props.itemFk),
|
||||||
warehouseFk: props.warehouseFk,
|
warehouseFk: props.warehouseFk,
|
||||||
quantity: null,
|
quantity: null,
|
||||||
});
|
});
|
||||||
|
@ -44,23 +44,25 @@ const onDataSaved = (data) => {
|
||||||
<FormModelPopup
|
<FormModelPopup
|
||||||
url-create="Items/regularize"
|
url-create="Items/regularize"
|
||||||
model="Items"
|
model="Items"
|
||||||
:title="t('Regularize stock')"
|
:title="t('item.regularizeStock')"
|
||||||
:form-initial-data="regularizeFormData"
|
:form-initial-data="regularizeFormData"
|
||||||
@on-data-saved="onDataSaved($event)"
|
@on-data-saved="onDataSaved($event)"
|
||||||
>
|
>
|
||||||
<template #form-inputs="{ data }">
|
<template #form-inputs="{ data }">
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<QInput
|
<QInput
|
||||||
:label="t('Type the visible quantity')"
|
:label="t('Type the visible quantity')"
|
||||||
v-model.number="data.quantity"
|
v-model.number="data.quantity"
|
||||||
|
type="number"
|
||||||
autofocus
|
autofocus
|
||||||
|
data-cy="regularizeStockInput"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('Warehouse')"
|
:label="t('Warehouse')"
|
||||||
v-model="data.warehouseFk"
|
v-model.number="data.warehouseFk"
|
||||||
:options="warehousesOptions"
|
:options="warehousesOptions"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<script setup>
|
||||||
|
defineProps({ row: { type: Object, required: true } });
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<span>
|
||||||
|
<QIcon
|
||||||
|
v-if="row.isTaxDataChecked === 0"
|
||||||
|
name="vn:no036"
|
||||||
|
color="primary"
|
||||||
|
size="xs"
|
||||||
|
>
|
||||||
|
<QTooltip>{{ $t('salesTicketsTable.noVerifiedData') }}</QTooltip>
|
||||||
|
</QIcon>
|
||||||
|
<QIcon v-if="row.hasTicketRequest" name="vn:buyrequest" color="primary" size="xs">
|
||||||
|
<QTooltip>{{ $t('salesTicketsTable.purchaseRequest') }}</QTooltip>
|
||||||
|
</QIcon>
|
||||||
|
<QIcon v-if="row.itemShortage" name="vn:unavailable" color="primary" size="xs">
|
||||||
|
<QTooltip>{{ $t('salesTicketsTable.notVisible') }}</QTooltip>
|
||||||
|
</QIcon>
|
||||||
|
<QIcon v-if="row.isFreezed" name="vn:frozen" color="primary" size="xs">
|
||||||
|
<QTooltip>{{ $t('salesTicketsTable.clientFrozen') }}</QTooltip>
|
||||||
|
</QIcon>
|
||||||
|
<QIcon
|
||||||
|
v-if="row.risk"
|
||||||
|
name="vn:risk"
|
||||||
|
:color="row.hasHighRisk ? 'negative' : 'primary'"
|
||||||
|
size="xs"
|
||||||
|
>
|
||||||
|
<QTooltip>
|
||||||
|
{{ $t('salesTicketsTable.risk') }}: {{ row.risk - row.credit }}
|
||||||
|
</QTooltip>
|
||||||
|
</QIcon>
|
||||||
|
<QIcon v-if="row.hasComponentLack" name="vn:components" color="primary" size="xs">
|
||||||
|
<QTooltip>{{ $t('salesTicketsTable.componentLack') }}</QTooltip>
|
||||||
|
</QIcon>
|
||||||
|
<QIcon v-if="row.isTooLittle" name="vn:isTooLittle" color="primary" size="xs">
|
||||||
|
<QTooltip>{{ $t('salesTicketsTable.tooLittle') }}</QTooltip>
|
||||||
|
</QIcon>
|
||||||
|
</span>
|
||||||
|
</template>
|
|
@ -2,13 +2,12 @@
|
||||||
import { ref, reactive } from 'vue';
|
import { ref, reactive } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar, useDialogPluginComponent } from 'quasar';
|
||||||
import VnConfirm from 'components/ui/VnConfirm.vue';
|
import VnConfirm from 'components/ui/VnConfirm.vue';
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import VnSelect from 'components/common/VnSelect.vue';
|
import VnSelect from 'components/common/VnSelect.vue';
|
||||||
import FormPopup from './FormPopup.vue';
|
import FormPopup from './FormPopup.vue';
|
||||||
import { useDialogPluginComponent } from 'quasar';
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import useNotify from 'src/composables/useNotify.js';
|
import useNotify from 'src/composables/useNotify.js';
|
||||||
|
|
||||||
|
@ -18,19 +17,19 @@ const $props = defineProps({
|
||||||
default: () => {},
|
default: () => {},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { dialogRef } = useDialogPluginComponent();
|
const { dialogRef } = useDialogPluginComponent();
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
const checked = ref(true);
|
|
||||||
const transferInvoiceParams = reactive({
|
|
||||||
id: $props.invoiceOutData?.id,
|
|
||||||
refFk: $props.invoiceOutData?.ref,
|
|
||||||
});
|
|
||||||
|
|
||||||
const rectificativeTypeOptions = ref([]);
|
const rectificativeTypeOptions = ref([]);
|
||||||
const siiTypeInvoiceOutsOptions = ref([]);
|
const siiTypeInvoiceOutsOptions = ref([]);
|
||||||
|
const checked = ref(true);
|
||||||
|
const transferInvoiceParams = reactive({
|
||||||
|
id: $props.invoiceOutData?.id,
|
||||||
|
});
|
||||||
const invoiceCorrectionTypesOptions = ref([]);
|
const invoiceCorrectionTypesOptions = ref([]);
|
||||||
|
|
||||||
const selectedClient = (client) => {
|
const selectedClient = (client) => {
|
||||||
|
@ -44,43 +43,38 @@ const makeInvoice = async () => {
|
||||||
const params = {
|
const params = {
|
||||||
id: transferInvoiceParams.id,
|
id: transferInvoiceParams.id,
|
||||||
cplusRectificationTypeFk: transferInvoiceParams.cplusRectificationTypeFk,
|
cplusRectificationTypeFk: transferInvoiceParams.cplusRectificationTypeFk,
|
||||||
|
siiTypeInvoiceOutFk: transferInvoiceParams.siiTypeInvoiceOutFk,
|
||||||
invoiceCorrectionTypeFk: transferInvoiceParams.invoiceCorrectionTypeFk,
|
invoiceCorrectionTypeFk: transferInvoiceParams.invoiceCorrectionTypeFk,
|
||||||
newClientFk: transferInvoiceParams.newClientFk,
|
newClientFk: transferInvoiceParams.newClientFk,
|
||||||
refFk: transferInvoiceParams.refFk,
|
|
||||||
siiTypeInvoiceOutFk: transferInvoiceParams.siiTypeInvoiceOutFk,
|
|
||||||
makeInvoice: checked.value,
|
makeInvoice: checked.value,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
if (checked.value && hasToInvoiceByAddress) {
|
||||||
if (checked.value && hasToInvoiceByAddress) {
|
const response = await new Promise((resolve) => {
|
||||||
const response = await new Promise((resolve) => {
|
quasar
|
||||||
quasar
|
.dialog({
|
||||||
.dialog({
|
component: VnConfirm,
|
||||||
component: VnConfirm,
|
componentProps: {
|
||||||
componentProps: {
|
title: t('Bill destination client'),
|
||||||
title: t('Bill destination client'),
|
message: t('transferInvoiceInfo'),
|
||||||
message: t('transferInvoiceInfo'),
|
},
|
||||||
},
|
})
|
||||||
})
|
.onOk(() => {
|
||||||
.onOk(() => {
|
resolve(true);
|
||||||
resolve(true);
|
})
|
||||||
})
|
.onCancel(() => {
|
||||||
.onCancel(() => {
|
resolve(false);
|
||||||
resolve(false);
|
});
|
||||||
});
|
});
|
||||||
});
|
if (!response) {
|
||||||
if (!response) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = await axios.post('InvoiceOuts/transferInvoice', params);
|
|
||||||
notify(t('Transferred invoice'), 'positive');
|
|
||||||
const id = data?.[0];
|
|
||||||
if (id) router.push({ name: 'InvoiceOutSummary', params: { id } });
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error transfering invoice', err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { data } = await axios.post('InvoiceOuts/transfer', params);
|
||||||
|
notify(t('Transferred invoice'), 'positive');
|
||||||
|
const id = data?.[0];
|
||||||
|
if (id) router.push({ name: 'InvoiceOutSummary', params: { id } });
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -118,13 +112,13 @@ const makeInvoice = async () => {
|
||||||
/>
|
/>
|
||||||
<QDialog ref="dialogRef">
|
<QDialog ref="dialogRef">
|
||||||
<FormPopup
|
<FormPopup
|
||||||
@on-submit="makeInvoice()"
|
@on-submit="makeInvoice()"
|
||||||
:title="t('Transfer invoice')"
|
:title="t('Transfer invoice')"
|
||||||
:custom-submit-button-label="t('Transfer client')"
|
:custom-submit-button-label="t('Transfer client')"
|
||||||
:default-cancel-button="false"
|
:default-cancel-button="false"
|
||||||
>
|
>
|
||||||
<template #form-inputs>
|
<template #form-inputs>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('Client')"
|
:label="t('Client')"
|
||||||
:options="clientsOptions"
|
:options="clientsOptions"
|
||||||
|
@ -160,7 +154,7 @@ const makeInvoice = async () => {
|
||||||
:required="true"
|
:required="true"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('Class')"
|
:label="t('Class')"
|
||||||
:options="siiTypeInvoiceOutsOptions"
|
:options="siiTypeInvoiceOutsOptions"
|
||||||
|
@ -191,9 +185,12 @@ const makeInvoice = async () => {
|
||||||
:required="true"
|
:required="true"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow>
|
||||||
<div>
|
<div>
|
||||||
<QCheckbox :label="t('Bill destination client')" v-model="checked" />
|
<QCheckbox
|
||||||
|
:label="t('Bill destination client')"
|
||||||
|
v-model="checked"
|
||||||
|
/>
|
||||||
<QIcon name="info" class="cursor-info q-ml-sm" size="sm">
|
<QIcon name="info" class="cursor-info q-ml-sm" size="sm">
|
||||||
<QTooltip>{{ t('transferInvoiceInfo') }}</QTooltip>
|
<QTooltip>{{ t('transferInvoiceInfo') }}</QTooltip>
|
||||||
</QIcon>
|
</QIcon>
|
||||||
|
|
|
@ -11,14 +11,16 @@ import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import { useClipboard } from 'src/composables/useClipboard';
|
import { useClipboard } from 'src/composables/useClipboard';
|
||||||
import VnImg from 'src/components/ui/VnImg.vue';
|
|
||||||
import { useRole } from 'src/composables/useRole';
|
import { useRole } from 'src/composables/useRole';
|
||||||
|
import VnAvatar from './ui/VnAvatar.vue';
|
||||||
|
import useNotify from 'src/composables/useNotify';
|
||||||
|
|
||||||
const state = useState();
|
const state = useState();
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t, locale } = useI18n();
|
const { t, locale } = useI18n();
|
||||||
const { copyText } = useClipboard();
|
const { copyText } = useClipboard();
|
||||||
|
const { notify } = useNotify();
|
||||||
|
|
||||||
const userLocale = computed({
|
const userLocale = computed({
|
||||||
get() {
|
get() {
|
||||||
|
@ -53,6 +55,7 @@ const user = state.getUser();
|
||||||
const warehousesData = ref();
|
const warehousesData = ref();
|
||||||
const companiesData = ref();
|
const companiesData = ref();
|
||||||
const accountBankData = ref();
|
const accountBankData = ref();
|
||||||
|
const isEmployee = computed(() => useRole().isEmployee());
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
updatePreferences();
|
updatePreferences();
|
||||||
|
@ -70,18 +73,28 @@ function updatePreferences() {
|
||||||
|
|
||||||
async function saveDarkMode(value) {
|
async function saveDarkMode(value) {
|
||||||
const query = `/UserConfigs/${user.value.id}`;
|
const query = `/UserConfigs/${user.value.id}`;
|
||||||
await axios.patch(query, {
|
try {
|
||||||
darkMode: value,
|
await axios.patch(query, {
|
||||||
});
|
darkMode: value,
|
||||||
user.value.darkMode = value;
|
});
|
||||||
|
user.value.darkMode = value;
|
||||||
|
onDataSaved();
|
||||||
|
} catch (error) {
|
||||||
|
onDataError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveLanguage(value) {
|
async function saveLanguage(value) {
|
||||||
const query = `/VnUsers/${user.value.id}`;
|
const query = `/VnUsers/${user.value.id}`;
|
||||||
await axios.patch(query, {
|
try {
|
||||||
lang: value,
|
await axios.patch(query, { lang: value });
|
||||||
});
|
|
||||||
user.value.lang = value;
|
user.value.lang = value;
|
||||||
|
useState().setUser(user.value);
|
||||||
|
onDataSaved();
|
||||||
|
} catch (error) {
|
||||||
|
onDataError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
|
@ -97,11 +110,23 @@ function localUserData() {
|
||||||
state.setUser(user.value);
|
state.setUser(user.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveUserData(param, value) {
|
async function saveUserData(param, value) {
|
||||||
axios.post('UserConfigs/setUserConfig', { [param]: value });
|
try {
|
||||||
localUserData();
|
await axios.post('UserConfigs/setUserConfig', { [param]: value });
|
||||||
|
localUserData();
|
||||||
|
onDataSaved();
|
||||||
|
} catch (error) {
|
||||||
|
onDataError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const isEmployee = computed(() => useRole().isEmployee());
|
|
||||||
|
const onDataSaved = () => {
|
||||||
|
notify('globals.dataSaved', 'positive');
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDataError = () => {
|
||||||
|
notify('errors.updateUserConfig', 'negative');
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -136,7 +161,7 @@ const isEmployee = computed(() => useRole().isEmployee());
|
||||||
@update:model-value="saveLanguage"
|
@update:model-value="saveLanguage"
|
||||||
:label="t(`globals.lang['${userLocale}']`)"
|
:label="t(`globals.lang['${userLocale}']`)"
|
||||||
icon="public"
|
icon="public"
|
||||||
color="orange"
|
color="primary"
|
||||||
false-value="es"
|
false-value="es"
|
||||||
true-value="en"
|
true-value="en"
|
||||||
/>
|
/>
|
||||||
|
@ -145,7 +170,7 @@ const isEmployee = computed(() => useRole().isEmployee());
|
||||||
@update:model-value="saveDarkMode"
|
@update:model-value="saveDarkMode"
|
||||||
:label="t(`globals.darkMode`)"
|
:label="t(`globals.darkMode`)"
|
||||||
checked-icon="dark_mode"
|
checked-icon="dark_mode"
|
||||||
color="orange"
|
color="primary"
|
||||||
unchecked-icon="light_mode"
|
unchecked-icon="light_mode"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -153,10 +178,20 @@ const isEmployee = computed(() => useRole().isEmployee());
|
||||||
<QSeparator vertical inset class="q-mx-lg" />
|
<QSeparator vertical inset class="q-mx-lg" />
|
||||||
|
|
||||||
<div class="col column items-center q-mb-sm">
|
<div class="col column items-center q-mb-sm">
|
||||||
<QAvatar size="80px">
|
<VnAvatar
|
||||||
<VnImg :id="user.id" collection="user" size="160x160" />
|
:worker-id="user.id"
|
||||||
</QAvatar>
|
:title="user.name"
|
||||||
|
size="xxl"
|
||||||
|
color="transparent"
|
||||||
|
/>
|
||||||
|
<QBtn
|
||||||
|
v-if="isEmployee"
|
||||||
|
class="q-mt-sm q-px-md"
|
||||||
|
:to="`/worker/${user.id}`"
|
||||||
|
color="primary"
|
||||||
|
:label="t('globals.myAccount')"
|
||||||
|
dense
|
||||||
|
/>
|
||||||
<div class="text-subtitle1 q-mt-md">
|
<div class="text-subtitle1 q-mt-md">
|
||||||
<strong>{{ user.nickname }}</strong>
|
<strong>{{ user.nickname }}</strong>
|
||||||
</div>
|
</div>
|
||||||
|
@ -168,7 +203,7 @@ const isEmployee = computed(() => useRole().isEmployee());
|
||||||
</div>
|
</div>
|
||||||
<QBtn
|
<QBtn
|
||||||
id="logout"
|
id="logout"
|
||||||
color="orange"
|
color="primary"
|
||||||
flat
|
flat
|
||||||
:label="t('globals.logOut')"
|
:label="t('globals.logOut')"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
<script setup>
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
|
import { useValidator } from 'src/composables/useValidator';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
|
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
||||||
|
import FetchData from 'components/FetchData.vue';
|
||||||
|
import CreateNewProvinceForm from './CreateNewProvinceForm.vue';
|
||||||
|
|
||||||
|
const emit = defineEmits(['onProvinceCreated', 'onProvinceFetched', 'update:options']);
|
||||||
|
const $props = defineProps({
|
||||||
|
countryFk: {
|
||||||
|
type: Number,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
provinceSelected: {
|
||||||
|
type: Number,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const provinceFk = defineModel({ type: Number, default: null });
|
||||||
|
|
||||||
|
const { validate } = useValidator();
|
||||||
|
const { t } = useI18n();
|
||||||
|
const filter = ref({
|
||||||
|
include: { relation: 'country' },
|
||||||
|
where: {
|
||||||
|
countryFk: $props.countryFk,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const provincesOptions = ref($props.provinces);
|
||||||
|
const provincesFetchDataRef = ref();
|
||||||
|
provinceFk.value = $props.provinceSelected;
|
||||||
|
if (!$props.countryFk) {
|
||||||
|
filter.value.where = {};
|
||||||
|
}
|
||||||
|
async function onProvinceCreated(_, data) {
|
||||||
|
await provincesFetchDataRef.value.fetch({ where: { countryFk: $props.countryFk } });
|
||||||
|
provinceFk.value = data.id;
|
||||||
|
emit('onProvinceCreated', data);
|
||||||
|
}
|
||||||
|
async function handleProvinces(data) {
|
||||||
|
provincesOptions.value = data;
|
||||||
|
emit('update:options', data);
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => $props.countryFk,
|
||||||
|
async () => {
|
||||||
|
if ($props.countryFk) {
|
||||||
|
filter.value.where.countryFk = $props.countryFk;
|
||||||
|
} else filter.value.where = {};
|
||||||
|
await provincesFetchDataRef.value.fetch({});
|
||||||
|
emit('onProvinceFetched', provincesOptions.value);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<FetchData
|
||||||
|
ref="provincesFetchDataRef"
|
||||||
|
:filter="filter"
|
||||||
|
@on-fetch="handleProvinces"
|
||||||
|
url="Provinces"
|
||||||
|
auto-load
|
||||||
|
/>
|
||||||
|
<VnSelectDialog
|
||||||
|
data-cy="locationProvince"
|
||||||
|
:label="t('Province')"
|
||||||
|
:options="provincesOptions"
|
||||||
|
:tooltip="t('Create province')"
|
||||||
|
hide-selected
|
||||||
|
v-model="provinceFk"
|
||||||
|
:rules="validate && validate('postcode.provinceFk')"
|
||||||
|
:acls="[{ model: 'Province', props: '*', accessType: 'WRITE' }]"
|
||||||
|
>
|
||||||
|
<template #option="{ itemProps, opt }">
|
||||||
|
<QItem v-bind="itemProps">
|
||||||
|
<QItemSection>
|
||||||
|
<QItemLabel>{{ opt.name }}</QItemLabel>
|
||||||
|
<QItemLabel caption> {{ opt.country.name }} </QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
|
</template>
|
||||||
|
<template #form>
|
||||||
|
<CreateNewProvinceForm
|
||||||
|
:country-fk="$props.countryFk"
|
||||||
|
@on-data-saved="onProvinceCreated"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</VnSelectDialog>
|
||||||
|
</template>
|
||||||
|
<i18n>
|
||||||
|
es:
|
||||||
|
Province: Provincia
|
||||||
|
Create province: Crear provincia
|
||||||
|
</i18n>
|
|
@ -35,7 +35,9 @@ function stopEventPropagation(event) {
|
||||||
dense
|
dense
|
||||||
square
|
square
|
||||||
>
|
>
|
||||||
<span v-if="!col.chip.icon">{{ row[col.name] }}</span>
|
<span v-if="!col.chip.icon">
|
||||||
|
{{ col.format ? col.format(row) : row[col.name] }}
|
||||||
|
</span>
|
||||||
<QIcon v-else :name="col.chip.icon" color="primary-light" />
|
<QIcon v-else :name="col.chip.icon" color="primary-light" />
|
||||||
</QChip>
|
</QChip>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { markRaw, computed, defineModel } from 'vue';
|
import { markRaw, computed } from 'vue';
|
||||||
import { QIcon, QCheckbox } from 'quasar';
|
import { QIcon, QCheckbox } from 'quasar';
|
||||||
import { dashIfEmpty } from 'src/filters';
|
import { dashIfEmpty } from 'src/filters';
|
||||||
|
|
||||||
|
@ -7,9 +7,11 @@ import { dashIfEmpty } from 'src/filters';
|
||||||
import VnSelect from 'components/common/VnSelect.vue';
|
import VnSelect from 'components/common/VnSelect.vue';
|
||||||
import VnSelectCache from 'components/common/VnSelectCache.vue';
|
import VnSelectCache from 'components/common/VnSelectCache.vue';
|
||||||
import VnInput from 'components/common/VnInput.vue';
|
import VnInput from 'components/common/VnInput.vue';
|
||||||
|
import VnInputNumber from 'components/common/VnInputNumber.vue';
|
||||||
import VnInputDate from 'components/common/VnInputDate.vue';
|
import VnInputDate from 'components/common/VnInputDate.vue';
|
||||||
import VnInputTime from 'components/common/VnInputTime.vue';
|
import VnInputTime from 'components/common/VnInputTime.vue';
|
||||||
import VnComponent from 'components/common/VnComponent.vue';
|
import VnComponent from 'components/common/VnComponent.vue';
|
||||||
|
import VnUserLink from 'components/ui/VnUserLink.vue';
|
||||||
|
|
||||||
const model = defineModel(undefined, { required: true });
|
const model = defineModel(undefined, { required: true });
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
|
@ -66,7 +68,7 @@ const defaultComponents = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
number: {
|
number: {
|
||||||
component: markRaw(VnInput),
|
component: markRaw(VnInputNumber),
|
||||||
attrs: {
|
attrs: {
|
||||||
disable: !$props.isEditable,
|
disable: !$props.isEditable,
|
||||||
class: 'fit',
|
class: 'fit',
|
||||||
|
@ -98,14 +100,14 @@ const defaultComponents = {
|
||||||
},
|
},
|
||||||
checkbox: {
|
checkbox: {
|
||||||
component: markRaw(QCheckbox),
|
component: markRaw(QCheckbox),
|
||||||
attrs: (prop) => {
|
attrs: ({ model }) => {
|
||||||
const defaultAttrs = {
|
const defaultAttrs = {
|
||||||
disable: !$props.isEditable,
|
disable: !$props.isEditable,
|
||||||
'model-value': Boolean(prop),
|
'model-value': Boolean(model),
|
||||||
class: 'no-padding fit',
|
class: 'no-padding fit',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof prop == 'number') {
|
if (typeof model == 'number') {
|
||||||
defaultAttrs['true-value'] = 1;
|
defaultAttrs['true-value'] = 1;
|
||||||
defaultAttrs['false-value'] = 0;
|
defaultAttrs['false-value'] = 0;
|
||||||
}
|
}
|
||||||
|
@ -126,6 +128,9 @@ const defaultComponents = {
|
||||||
icon: {
|
icon: {
|
||||||
component: markRaw(QIcon),
|
component: markRaw(QIcon),
|
||||||
},
|
},
|
||||||
|
userLink: {
|
||||||
|
component: markRaw(VnUserLink),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const value = computed(() => {
|
const value = computed(() => {
|
||||||
|
@ -146,8 +151,8 @@ const col = computed(() => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
(newColumn.name.startsWith('is') || newColumn.name.startsWith('has')) &&
|
(/^is[A-Z]/.test(newColumn.name) || /^has[A-Z]/.test(newColumn.name)) &&
|
||||||
!newColumn.component
|
newColumn.component == null
|
||||||
)
|
)
|
||||||
newColumn.component = 'checkbox';
|
newColumn.component = 'checkbox';
|
||||||
if ($props.default && !newColumn.component) newColumn.component = $props.default;
|
if ($props.default && !newColumn.component) newColumn.component = $props.default;
|
||||||
|
@ -163,14 +168,14 @@ const components = computed(() => $props.components ?? defaultComponents);
|
||||||
v-if="col.before"
|
v-if="col.before"
|
||||||
:prop="col.before"
|
:prop="col.before"
|
||||||
:components="components"
|
:components="components"
|
||||||
:value="model"
|
:value="{ row, model }"
|
||||||
v-model="model"
|
v-model="model"
|
||||||
/>
|
/>
|
||||||
<VnComponent
|
<VnComponent
|
||||||
v-if="col.component"
|
v-if="col.component"
|
||||||
:prop="col"
|
:prop="col"
|
||||||
:components="components"
|
:components="components"
|
||||||
:value="model"
|
:value="{ row, model }"
|
||||||
v-model="model"
|
v-model="model"
|
||||||
/>
|
/>
|
||||||
<span :title="value" v-else>{{ value }}</span>
|
<span :title="value" v-else>{{ value }}</span>
|
||||||
|
@ -178,7 +183,7 @@ const components = computed(() => $props.components ?? defaultComponents);
|
||||||
v-if="col.after"
|
v-if="col.after"
|
||||||
:prop="col.after"
|
:prop="col.after"
|
||||||
:components="components"
|
:components="components"
|
||||||
:value="model"
|
:value="{ row, model }"
|
||||||
v-model="model"
|
v-model="model"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { markRaw, computed, defineModel } from 'vue';
|
import { markRaw, computed } from 'vue';
|
||||||
import { QCheckbox } from 'quasar';
|
import { QCheckbox } from 'quasar';
|
||||||
import { useArrayData } from 'composables/useArrayData';
|
import { useArrayData } from 'composables/useArrayData';
|
||||||
|
|
||||||
|
@ -25,11 +25,17 @@ const $props = defineProps({
|
||||||
},
|
},
|
||||||
searchUrl: {
|
searchUrl: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'params',
|
default: 'table',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
defineExpose({ addFilter, props: $props });
|
||||||
|
|
||||||
const model = defineModel(undefined, { required: true });
|
const model = defineModel(undefined, { required: true });
|
||||||
const arrayData = useArrayData($props.dataKey, { searchUrl: $props.searchUrl });
|
const arrayData = useArrayData(
|
||||||
|
$props.dataKey,
|
||||||
|
$props.searchUrl ? { searchUrl: $props.searchUrl } : null
|
||||||
|
);
|
||||||
const columnFilter = computed(() => $props.column?.columnFilter);
|
const columnFilter = computed(() => $props.column?.columnFilter);
|
||||||
|
|
||||||
const updateEvent = { 'update:modelValue': addFilter };
|
const updateEvent = { 'update:modelValue': addFilter };
|
||||||
|
@ -45,7 +51,18 @@ const defaultAttrs = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const forceAttrs = {
|
const forceAttrs = {
|
||||||
label: $props.showTitle ? '' : $props.column.label,
|
label: $props.showTitle ? '' : columnFilter.value?.label ?? $props.column.label,
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectComponent = {
|
||||||
|
component: markRaw(VnSelect),
|
||||||
|
event: updateEvent,
|
||||||
|
attrs: {
|
||||||
|
class: 'q-px-sm q-pb-xs q-pt-none fit',
|
||||||
|
dense: true,
|
||||||
|
filled: !$props.showTitle,
|
||||||
|
},
|
||||||
|
forceAttrs,
|
||||||
};
|
};
|
||||||
|
|
||||||
const components = {
|
const components = {
|
||||||
|
@ -64,6 +81,7 @@ const components = {
|
||||||
attrs: {
|
attrs: {
|
||||||
...defaultAttrs,
|
...defaultAttrs,
|
||||||
clearable: true,
|
clearable: true,
|
||||||
|
type: 'number',
|
||||||
},
|
},
|
||||||
forceAttrs,
|
forceAttrs,
|
||||||
},
|
},
|
||||||
|
@ -97,23 +115,15 @@ const components = {
|
||||||
},
|
},
|
||||||
forceAttrs,
|
forceAttrs,
|
||||||
},
|
},
|
||||||
select: {
|
select: selectComponent,
|
||||||
component: markRaw(VnSelect),
|
rawSelect: selectComponent,
|
||||||
event: updateEvent,
|
|
||||||
attrs: {
|
|
||||||
class: 'q-px-sm q-pb-xs q-pt-none fit',
|
|
||||||
dense: true,
|
|
||||||
filled: !$props.showTitle,
|
|
||||||
},
|
|
||||||
forceAttrs,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function addFilter(value) {
|
async function addFilter(value, name) {
|
||||||
value ??= undefined;
|
value ??= undefined;
|
||||||
if (value && typeof value === 'object') value = model.value;
|
if (value && typeof value === 'object') value = model.value;
|
||||||
value = value === '' ? undefined : value;
|
value = value === '' ? undefined : value;
|
||||||
let field = columnFilter.value?.name ?? $props.column.name;
|
let field = columnFilter.value?.name ?? $props.column.name ?? name;
|
||||||
|
|
||||||
if (columnFilter.value?.inWhere) {
|
if (columnFilter.value?.inWhere) {
|
||||||
if (columnFilter.value.alias) field = columnFilter.value.alias + '.' + field;
|
if (columnFilter.value.alias) field = columnFilter.value.alias + '.' + field;
|
||||||
|
@ -136,6 +146,10 @@ function alignRow() {
|
||||||
const showFilter = computed(
|
const showFilter = computed(
|
||||||
() => $props.column?.columnFilter !== false && $props.column.name != 'tableActions'
|
() => $props.column?.columnFilter !== false && $props.column.name != 'tableActions'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onTabPressed = async () => {
|
||||||
|
if (model.value) enterEvent['keyup.enter']();
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
|
@ -150,6 +164,7 @@ const showFilter = computed(
|
||||||
v-model="model"
|
v-model="model"
|
||||||
:components="components"
|
:components="components"
|
||||||
component-prop="columnFilter"
|
component-prop="columnFilter"
|
||||||
|
@keydown.tab="onTabPressed"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useArrayData } from 'composables/useArrayData';
|
import { useArrayData } from 'composables/useArrayData';
|
||||||
const model = defineModel({ type: Object, required: true });
|
const model = defineModel({ type: Object });
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: [String, Boolean],
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
|
@ -17,7 +17,7 @@ const $props = defineProps({
|
||||||
},
|
},
|
||||||
searchUrl: {
|
searchUrl: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'params',
|
default: 'table',
|
||||||
},
|
},
|
||||||
vertical: {
|
vertical: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
@ -56,7 +56,7 @@ defineExpose({ orderBy });
|
||||||
<span :title="label">{{ label }}</span>
|
<span :title="label">{{ label }}</span>
|
||||||
<QChip
|
<QChip
|
||||||
v-if="name"
|
v-if="name"
|
||||||
:label="!vertical && model?.index"
|
:label="!vertical ? model?.index : ''"
|
||||||
:icon="
|
:icon="
|
||||||
(model?.index || hover) && !vertical
|
(model?.index || hover) && !vertical
|
||||||
? model?.direction == 'DESC'
|
? model?.direction == 'DESC'
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,66 @@
|
||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import VnFilterPanel from 'components/ui/VnFilterPanel.vue';
|
||||||
|
import VnFilter from 'components/VnTable/VnFilter.vue';
|
||||||
|
import VnTableOrder from 'src/components/VnTable/VnOrder.vue';
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
columns: {
|
||||||
|
type: Array,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
searchUrl: {
|
||||||
|
type: [String, Boolean],
|
||||||
|
default: 'table',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const tableFilterRef = ref([]);
|
||||||
|
|
||||||
|
function columnName(col) {
|
||||||
|
const column = { ...col, ...col.columnFilter };
|
||||||
|
let name = column.name;
|
||||||
|
if (column.alias) name = column.alias + '.' + name;
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<VnFilterPanel v-bind="$attrs" :search-button="true" :disable-submit-event="true">
|
||||||
|
<template #body="{ params, orders }">
|
||||||
|
<div
|
||||||
|
class="row no-wrap flex-center"
|
||||||
|
v-for="col of columns.filter((c) => c.columnFilter ?? true)"
|
||||||
|
:key="col.id"
|
||||||
|
>
|
||||||
|
<VnFilter
|
||||||
|
ref="tableFilterRef"
|
||||||
|
:column="col"
|
||||||
|
:data-key="$attrs['data-key']"
|
||||||
|
v-model="params[columnName(col)]"
|
||||||
|
:search-url="searchUrl"
|
||||||
|
/>
|
||||||
|
<VnTableOrder
|
||||||
|
v-if="col?.columnFilter !== false && col?.name !== 'tableActions'"
|
||||||
|
v-model="orders[col.orderBy ?? col.name]"
|
||||||
|
:name="col.orderBy ?? col.name"
|
||||||
|
:data-key="$attrs['data-key']"
|
||||||
|
:search-url="searchUrl"
|
||||||
|
:vertical="true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<slot
|
||||||
|
name="moreFilterPanel"
|
||||||
|
:params="params"
|
||||||
|
:orders="orders"
|
||||||
|
:columns="columns"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #tags="{ tag, formatFn, getLocale }">
|
||||||
|
<div class="q-gutter-x-xs">
|
||||||
|
<strong>{{ getLocale(`${tag.label}`) }}: </strong>
|
||||||
|
<span>{{ formatFn(tag.value) }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</VnFilterPanel>
|
||||||
|
</template>
|
|
@ -65,7 +65,7 @@ async function fetchViewConfigData() {
|
||||||
const userConfig = await getConfig('UserConfigViews', {
|
const userConfig = await getConfig('UserConfigViews', {
|
||||||
where: {
|
where: {
|
||||||
...defaultFilter.where,
|
...defaultFilter.where,
|
||||||
...{ userFk: user.id },
|
...{ userFk: user.value.id },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ async function fetchViewConfigData() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.err('Error fetching config view data', err);
|
console.error('Error fetching config view data', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ onMounted(async () => {
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<QBtn icon="vn:visible_columns" class="bg-vn-section-color q-mr-md q-px-sm" dense>
|
<QBtn icon="vn:visible_columns" class="bg-vn-section-color q-mr-sm q-px-sm" dense>
|
||||||
<QPopupProxy ref="popupProxyRef">
|
<QPopupProxy ref="popupProxyRef">
|
||||||
<QCard class="column q-pa-md">
|
<QCard class="column q-pa-md">
|
||||||
<QIcon name="info" size="sm" class="info-icon">
|
<QIcon name="info" size="sm" class="info-icon">
|
||||||
|
@ -152,7 +152,7 @@ onMounted(async () => {
|
||||||
<QCheckbox
|
<QCheckbox
|
||||||
v-for="col in localColumns"
|
v-for="col in localColumns"
|
||||||
:key="col.name"
|
:key="col.name"
|
||||||
:label="col.label"
|
:label="col.label ?? col.name"
|
||||||
v-model="col.visible"
|
v-model="col.visible"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
import { describe, expect, it, beforeAll, beforeEach, vi } from 'vitest';
|
||||||
|
import { createWrapper } from 'app/test/vitest/helper';
|
||||||
|
import VnTable from 'src/components/VnTable/VnTable.vue';
|
||||||
|
|
||||||
|
describe('VnTable', () => {
|
||||||
|
let wrapper;
|
||||||
|
let vm;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
wrapper = createWrapper(VnTable, {
|
||||||
|
propsData: {
|
||||||
|
columns: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
vm = wrapper.vm;
|
||||||
|
|
||||||
|
vi.mock('src/composables/useFilterParams', () => {
|
||||||
|
return {
|
||||||
|
useFilterParams: vi.fn(() => ({
|
||||||
|
params: {},
|
||||||
|
orders: {},
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => (vm.selected = []));
|
||||||
|
|
||||||
|
describe('handleSelection()', () => {
|
||||||
|
const rows = [{ $index: 0 }, { $index: 1 }, { $index: 2 }];
|
||||||
|
const selectedRows = [{ $index: 1 }];
|
||||||
|
it('should add rows to selected when shift key is pressed and rows are added except last one', () => {
|
||||||
|
vm.handleSelection(
|
||||||
|
{ evt: { shiftKey: true }, added: true, rows: selectedRows },
|
||||||
|
rows
|
||||||
|
);
|
||||||
|
expect(vm.selected).toEqual([{ $index: 0 }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not add rows to selected when shift key is not pressed', () => {
|
||||||
|
vm.handleSelection(
|
||||||
|
{ evt: { shiftKey: false }, added: true, rows: selectedRows },
|
||||||
|
rows
|
||||||
|
);
|
||||||
|
expect(vm.selected).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not add rows to selected when rows are not added', () => {
|
||||||
|
vm.handleSelection(
|
||||||
|
{ evt: { shiftKey: true }, added: false, rows: selectedRows },
|
||||||
|
rows
|
||||||
|
);
|
||||||
|
expect(vm.selected).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,248 @@
|
||||||
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
|
import CrudModel from 'components/CrudModel.vue';
|
||||||
|
import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
describe('CrudModel', () => {
|
||||||
|
let wrapper;
|
||||||
|
let vm;
|
||||||
|
let data;
|
||||||
|
beforeAll(() => {
|
||||||
|
wrapper = createWrapper(CrudModel, {
|
||||||
|
global: {
|
||||||
|
stubs: [
|
||||||
|
'vnPaginate',
|
||||||
|
'useState',
|
||||||
|
'arrayData',
|
||||||
|
'useStateStore',
|
||||||
|
'vue-i18n',
|
||||||
|
],
|
||||||
|
mocks: {
|
||||||
|
validate: vi.fn(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
propsData: {
|
||||||
|
dataRequired: {
|
||||||
|
fk: 1,
|
||||||
|
},
|
||||||
|
dataKey: 'crudModelKey',
|
||||||
|
model: 'crudModel',
|
||||||
|
url: 'crudModelUrl',
|
||||||
|
saveFn: '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
wrapper=wrapper.wrapper;
|
||||||
|
vm=wrapper.vm;
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
vm.fetch([]);
|
||||||
|
vm.watchChanges = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('insert()', () => {
|
||||||
|
it('should new element in list with index 0 if formData not has data', () => {
|
||||||
|
vm.insert();
|
||||||
|
|
||||||
|
expect(vm.formData.length).toEqual(1);
|
||||||
|
expect(vm.formData[0].fk).toEqual(1);
|
||||||
|
expect(vm.formData[0].$index).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getChanges()', () => {
|
||||||
|
it('should return correct updates and creates', async () => {
|
||||||
|
vm.fetch([
|
||||||
|
{ id: 1, name: 'New name one' },
|
||||||
|
{ id: 2, name: 'New name two' },
|
||||||
|
{ id: 3, name: 'Bruce Wayne' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
vm.originalData = [
|
||||||
|
{ id: 1, name: 'Tony Starks' },
|
||||||
|
{ id: 2, name: 'Jessica Jones' },
|
||||||
|
{ id: 3, name: 'Bruce Wayne' },
|
||||||
|
];
|
||||||
|
|
||||||
|
vm.insert();
|
||||||
|
const result = vm.getChanges();
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
creates: [
|
||||||
|
{
|
||||||
|
$index: 3,
|
||||||
|
fk: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
updates: [
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
name: 'New name one',
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
name: 'New name two',
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
id: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getDifferences()', () => {
|
||||||
|
it('should return the differences between two objects', async () => {
|
||||||
|
const obj1 = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
c: 3,
|
||||||
|
};
|
||||||
|
const obj2 = {
|
||||||
|
a: null,
|
||||||
|
b: 4,
|
||||||
|
d: 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = vm.getDifferences(obj1, obj2);
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
a: null,
|
||||||
|
b: 4,
|
||||||
|
d: 5,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isEmpty()', () => {
|
||||||
|
let dummyObj;
|
||||||
|
let dummyArray;
|
||||||
|
let result;
|
||||||
|
it('should return true if object si null', async () => {
|
||||||
|
dummyObj = null;
|
||||||
|
result = vm.isEmpty(dummyObj);
|
||||||
|
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if object si undefined', async () => {
|
||||||
|
dummyObj = undefined;
|
||||||
|
result = vm.isEmpty(dummyObj);
|
||||||
|
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if object is empty', async () => {
|
||||||
|
dummyObj ={};
|
||||||
|
result = vm.isEmpty(dummyObj);
|
||||||
|
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if object is not empty', async () => {
|
||||||
|
dummyObj = {a:1, b:2, c:3};
|
||||||
|
result = vm.isEmpty(dummyObj);
|
||||||
|
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if array is empty', async () => {
|
||||||
|
dummyArray = [];
|
||||||
|
result = vm.isEmpty(dummyArray);
|
||||||
|
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if array is not empty', async () => {
|
||||||
|
dummyArray = [1,2,3];
|
||||||
|
result = vm.isEmpty(dummyArray);
|
||||||
|
|
||||||
|
expect(result).toBe(false);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('resetData()', () => {
|
||||||
|
it('should add $index to elements in data[] and sets originalData and formData with data', async () => {
|
||||||
|
data = [{
|
||||||
|
name: 'Tony',
|
||||||
|
lastName: 'Stark',
|
||||||
|
age: 42,
|
||||||
|
}];
|
||||||
|
|
||||||
|
vm.resetData(data);
|
||||||
|
|
||||||
|
expect(vm.originalData).toEqual(data);
|
||||||
|
expect(vm.originalData[0].$index).toEqual(0);
|
||||||
|
expect(vm.formData).toEqual(data);
|
||||||
|
expect(vm.formData[0].$index).toEqual(0);
|
||||||
|
expect(vm.watchChanges).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should dont do nothing if data is null', async () => {
|
||||||
|
vm.resetData(null);
|
||||||
|
|
||||||
|
expect(vm.watchChanges).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set originalData and formatData with data and generate watchChanges', async () => {
|
||||||
|
data = {
|
||||||
|
name: 'Tony',
|
||||||
|
lastName: 'Stark',
|
||||||
|
age: 42,
|
||||||
|
};
|
||||||
|
|
||||||
|
vm.resetData(data);
|
||||||
|
|
||||||
|
expect(vm.originalData).toEqual(data);
|
||||||
|
expect(vm.formData).toEqual(data);
|
||||||
|
expect(vm.watchChanges).not.toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('saveChanges()', () => {
|
||||||
|
data = [{
|
||||||
|
name: 'Tony',
|
||||||
|
lastName: 'Stark',
|
||||||
|
age: 42,
|
||||||
|
}];
|
||||||
|
|
||||||
|
it('should call saveFn if exists', async () => {
|
||||||
|
await wrapper.setProps({ saveFn: vi.fn() });
|
||||||
|
|
||||||
|
vm.saveChanges(data);
|
||||||
|
|
||||||
|
expect(vm.saveFn).toHaveBeenCalledOnce();
|
||||||
|
expect(vm.isLoading).toBe(false);
|
||||||
|
expect(vm.hasChanges).toBe(false);
|
||||||
|
|
||||||
|
await wrapper.setProps({ saveFn: '' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should use default url if there's not saveFn", async () => {
|
||||||
|
const postMock =vi.spyOn(axios, 'post');
|
||||||
|
|
||||||
|
vm.formData = [{
|
||||||
|
name: 'Bruce',
|
||||||
|
lastName: 'Wayne',
|
||||||
|
age: 45,
|
||||||
|
}]
|
||||||
|
|
||||||
|
await vm.saveChanges(data);
|
||||||
|
|
||||||
|
expect(postMock).toHaveBeenCalledWith(vm.url + '/crud', data);
|
||||||
|
expect(vm.isLoading).toBe(false);
|
||||||
|
expect(vm.hasChanges).toBe(false);
|
||||||
|
expect(vm.originalData).toEqual(JSON.parse(JSON.stringify(vm.formData)));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,56 @@
|
||||||
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
|
import EditForm from 'components/EditTableCellValueForm.vue';
|
||||||
|
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
const fieldA = 'fieldA';
|
||||||
|
const fieldB = 'fieldB';
|
||||||
|
|
||||||
|
describe('EditForm', () => {
|
||||||
|
let vm;
|
||||||
|
const mockRows = [
|
||||||
|
{ id: 1, itemFk: 101 },
|
||||||
|
{ id: 2, itemFk: 102 },
|
||||||
|
];
|
||||||
|
const mockFieldsOptions = [
|
||||||
|
{ label: 'Field A', field: fieldA, component: 'input', attrs: {} },
|
||||||
|
{ label: 'Field B', field: fieldB, component: 'date', attrs: {} },
|
||||||
|
];
|
||||||
|
const editUrl = '/api/edit';
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
vi.spyOn(axios, 'post').mockResolvedValue({ status: 200 });
|
||||||
|
vm = createWrapper(EditForm, {
|
||||||
|
props: {
|
||||||
|
rows: mockRows,
|
||||||
|
fieldsOptions: mockFieldsOptions,
|
||||||
|
editUrl,
|
||||||
|
},
|
||||||
|
}).vm;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onSubmit()', () => {
|
||||||
|
it('should call axios.post with the correct parameters in the payload', async () => {
|
||||||
|
const selectedField = { field: fieldA, component: 'input', attrs: {} };
|
||||||
|
const newValue = 'Test Value';
|
||||||
|
|
||||||
|
vm.selectedField = selectedField;
|
||||||
|
vm.newValue = newValue;
|
||||||
|
|
||||||
|
await vm.onSubmit();
|
||||||
|
|
||||||
|
const payload = axios.post.mock.calls[0][1];
|
||||||
|
|
||||||
|
expect(axios.post).toHaveBeenCalledWith(editUrl, expect.any(Object));
|
||||||
|
expect(payload.field).toEqual(fieldA);
|
||||||
|
expect(payload.newValue).toEqual(newValue);
|
||||||
|
|
||||||
|
expect(payload.lines).toEqual(expect.arrayContaining(mockRows));
|
||||||
|
|
||||||
|
expect(vm.isLoading).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,82 @@
|
||||||
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
|
import FilterItemForm from 'src/components/FilterItemForm.vue';
|
||||||
|
import { vi, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
describe('FilterItemForm', () => {
|
||||||
|
let vm;
|
||||||
|
let wrapper;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
wrapper = createWrapper(FilterItemForm, {
|
||||||
|
props: {
|
||||||
|
url: 'Items/withName',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
vm = wrapper.vm;
|
||||||
|
wrapper = wrapper.wrapper;
|
||||||
|
|
||||||
|
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: 999996,
|
||||||
|
name: 'bolas de madera',
|
||||||
|
size: 2,
|
||||||
|
inkFk: null,
|
||||||
|
producerFk: null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should filter data and populate tableRows for table display', async () => {
|
||||||
|
vm.itemFilterParams.name = 'bolas de madera';
|
||||||
|
|
||||||
|
await vm.onSubmit();
|
||||||
|
|
||||||
|
const expectedFilter = {
|
||||||
|
include: [
|
||||||
|
{ relation: 'producer', scope: { fields: ['name'] } },
|
||||||
|
{ relation: 'ink', scope: { fields: ['name'] } },
|
||||||
|
],
|
||||||
|
where: {"name":{"like":"%bolas de madera%"}},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(axios.get).toHaveBeenCalledWith('Items/withName', {
|
||||||
|
params: { filter: JSON.stringify(expectedFilter) },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(vm.tableRows).toEqual([
|
||||||
|
{
|
||||||
|
id: 999996,
|
||||||
|
name: 'bolas de madera',
|
||||||
|
size: 2,
|
||||||
|
inkFk: null,
|
||||||
|
producerFk: null,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle an empty itemFilterParams correctly', async () => {
|
||||||
|
vm.itemFilterParams.name = null;
|
||||||
|
vm.itemFilterParams = {};
|
||||||
|
|
||||||
|
await vm.onSubmit();
|
||||||
|
|
||||||
|
const expectedFilter = {
|
||||||
|
include: [
|
||||||
|
{ relation: 'producer', scope: { fields: ['name'] } },
|
||||||
|
{ relation: 'ink', scope: { fields: ['name'] } },
|
||||||
|
],
|
||||||
|
where: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(axios.get).toHaveBeenCalledWith('Items/withName', {
|
||||||
|
params: { filter: JSON.stringify(expectedFilter) },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit "itemSelected" with the correct id and close the form', () => {
|
||||||
|
vm.selectItem({ id: 12345 });
|
||||||
|
expect(wrapper.emitted('itemSelected')[0]).toEqual([12345]);
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,149 @@
|
||||||
|
import { describe, expect, it, beforeAll, vi, afterAll } from 'vitest';
|
||||||
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
|
import FormModel from 'src/components/FormModel.vue';
|
||||||
|
|
||||||
|
describe('FormModel', () => {
|
||||||
|
const model = 'mockModel';
|
||||||
|
const url = 'mockUrl';
|
||||||
|
const formInitialData = { mockKey: 'mockVal' };
|
||||||
|
|
||||||
|
describe('modelValue', () => {
|
||||||
|
it('should use the provided model', () => {
|
||||||
|
const { vm } = mount({ propsData: { model } });
|
||||||
|
expect(vm.modelValue).toBe(model);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use the route meta title when model is not provided', () => {
|
||||||
|
const { vm } = mount({});
|
||||||
|
expect(vm.modelValue).toBe('formModel_mockTitle');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onMounted()', () => {
|
||||||
|
let mockGet;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
mockGet = vi.spyOn(axios, 'get').mockResolvedValue({ data: {} });
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
mockGet.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not fetch when has formInitialData', () => {
|
||||||
|
mount({ propsData: { url, model, autoLoad: true, formInitialData } });
|
||||||
|
expect(mockGet).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fetch when there is url and auto-load', () => {
|
||||||
|
mount({ propsData: { url, model, autoLoad: true } });
|
||||||
|
expect(mockGet).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not observe changes', () => {
|
||||||
|
const { vm } = mount({
|
||||||
|
propsData: { url, model, observeFormChanges: false, formInitialData },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(vm.hasChanges).toBe(true);
|
||||||
|
vm.reset();
|
||||||
|
expect(vm.hasChanges).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should observe changes', async () => {
|
||||||
|
const { vm } = mount({
|
||||||
|
propsData: { url, model, formInitialData },
|
||||||
|
});
|
||||||
|
vm.state.set(model, formInitialData);
|
||||||
|
expect(vm.hasChanges).toBe(false);
|
||||||
|
|
||||||
|
vm.formData.mockKey = 'newVal';
|
||||||
|
await vm.$nextTick();
|
||||||
|
expect(vm.hasChanges).toBe(true);
|
||||||
|
vm.formData.mockKey = 'mockVal';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('trimData()', () => {
|
||||||
|
let vm;
|
||||||
|
beforeAll(() => {
|
||||||
|
vm = mount({}).vm;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should trim whitespace from string values', () => {
|
||||||
|
const data = { key1: ' value1 ', key2: ' value2 ' };
|
||||||
|
const trimmedData = vm.trimData(data);
|
||||||
|
expect(trimmedData).toEqual({ key1: 'value1', key2: 'value2' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not modify non-string values', () => {
|
||||||
|
const data = { key1: 123, key2: true, key3: null, key4: undefined };
|
||||||
|
const trimmedData = vm.trimData(data);
|
||||||
|
expect(trimmedData).toEqual(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('save()', async () => {
|
||||||
|
it('should not call if there are not changes', async () => {
|
||||||
|
const { vm } = mount({ propsData: { url, model } });
|
||||||
|
|
||||||
|
await vm.save();
|
||||||
|
expect(vm.hasChanges).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call axios.patch with the right data', async () => {
|
||||||
|
const spy = vi.spyOn(axios, 'patch').mockResolvedValue({ data: {} });
|
||||||
|
const { vm } = mount({ propsData: { url, model, formInitialData } });
|
||||||
|
vm.formData.mockKey = 'newVal';
|
||||||
|
await vm.$nextTick();
|
||||||
|
await vm.save();
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
vm.formData.mockKey = 'mockVal';
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call axios.post with the right data', async () => {
|
||||||
|
const spy = vi.spyOn(axios, 'post').mockResolvedValue({ data: {} });
|
||||||
|
const { vm } = mount({
|
||||||
|
propsData: { url, model, formInitialData, urlCreate: 'mockUrlCreate' },
|
||||||
|
});
|
||||||
|
vm.formData.mockKey = 'newVal';
|
||||||
|
await vm.$nextTick();
|
||||||
|
await vm.save();
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
vm.formData.mockKey = 'mockVal';
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use the saveFn', async () => {
|
||||||
|
const { vm } = mount({
|
||||||
|
propsData: { url, model, formInitialData, saveFn: () => {} },
|
||||||
|
});
|
||||||
|
const spyPatch = vi.spyOn(axios, 'patch').mockResolvedValue({ data: {} });
|
||||||
|
const spySaveFn = vi.spyOn(vm.$props, 'saveFn');
|
||||||
|
|
||||||
|
vm.formData.mockKey = 'newVal';
|
||||||
|
await vm.$nextTick();
|
||||||
|
await vm.save();
|
||||||
|
expect(spyPatch).not.toHaveBeenCalled();
|
||||||
|
expect(spySaveFn).toHaveBeenCalled();
|
||||||
|
vm.formData.mockKey = 'mockVal';
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload the data after save', async () => {
|
||||||
|
const { vm } = mount({
|
||||||
|
propsData: { url, model, formInitialData, reload: true },
|
||||||
|
});
|
||||||
|
vi.spyOn(axios, 'patch').mockResolvedValue({ data: {} });
|
||||||
|
|
||||||
|
vm.formData.mockKey = 'newVal';
|
||||||
|
await vm.$nextTick();
|
||||||
|
await vm.save();
|
||||||
|
vm.formData.mockKey = 'mockVal';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function mount({ propsData = {} }) {
|
||||||
|
return createWrapper(FormModel, {
|
||||||
|
propsData,
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,32 +1,20 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, useSlots } from 'vue';
|
import { onMounted, useSlots } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useStateStore } from 'stores/useStateStore';
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
|
import { useQuasar } from 'quasar';
|
||||||
const slots = useSlots();
|
import { useHasContent } from 'src/composables/useHasContent';
|
||||||
const hasContent = ref(false);
|
|
||||||
const rightPanel = ref(null);
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
rightPanel.value = document.querySelector('#right-panel');
|
|
||||||
if (!rightPanel.value) return;
|
|
||||||
|
|
||||||
// Check if there's content to display
|
|
||||||
const observer = new MutationObserver(() => {
|
|
||||||
hasContent.value = rightPanel.value.childNodes.length;
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(rightPanel.value, {
|
|
||||||
subtree: true,
|
|
||||||
childList: true,
|
|
||||||
attributes: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!slots['right-panel'] && !hasContent.value) stateStore.rightDrawer = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const quasar = useQuasar();
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
|
const slots = useSlots();
|
||||||
|
const hasContent = useHasContent('#right-panel');
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if ((!slots['right-panel'] && !hasContent.value) || quasar.platform.is.mobile)
|
||||||
|
stateStore.rightDrawer = false;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<Teleport to="#actions-append" v-if="stateStore.isHeaderMounted()">
|
<Teleport to="#actions-append" v-if="stateStore.isHeaderMounted()">
|
||||||
|
@ -37,7 +25,7 @@ const stateStore = useStateStore();
|
||||||
@click="stateStore.toggleRightDrawer()"
|
@click="stateStore.toggleRightDrawer()"
|
||||||
round
|
round
|
||||||
dense
|
dense
|
||||||
icon="menu"
|
icon="dock_to_left"
|
||||||
>
|
>
|
||||||
<QTooltip bottom anchor="bottom right">
|
<QTooltip bottom anchor="bottom right">
|
||||||
{{ t('globals.collapseMenu') }}
|
{{ t('globals.collapseMenu') }}
|
||||||
|
@ -45,8 +33,8 @@ const stateStore = useStateStore();
|
||||||
</QBtn>
|
</QBtn>
|
||||||
</div>
|
</div>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above>
|
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256">
|
||||||
<QScrollArea class="fit text-grey-8">
|
<QScrollArea class="fit">
|
||||||
<div id="right-panel"></div>
|
<div id="right-panel"></div>
|
||||||
<slot v-if="!hasContent" name="right-panel" />
|
<slot v-if="!hasContent" name="right-panel" />
|
||||||
</QScrollArea>
|
</QScrollArea>
|
||||||
|
|
|
@ -58,79 +58,71 @@ const getConfig = async (url, filter) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchViewConfigData = async () => {
|
const fetchViewConfigData = async () => {
|
||||||
try {
|
const userConfigFilter = {
|
||||||
const userConfigFilter = {
|
where: { tableCode: $props.tableCode, userFk: user.value.id },
|
||||||
where: { tableCode: $props.tableCode, userFk: user.value.id },
|
};
|
||||||
};
|
const userConfig = await getConfig('UserConfigViews', userConfigFilter);
|
||||||
const userConfig = await getConfig('UserConfigViews', userConfigFilter);
|
|
||||||
|
|
||||||
if (userConfig) {
|
if (userConfig) {
|
||||||
initialUserConfigViewData.value = userConfig;
|
initialUserConfigViewData.value = userConfig;
|
||||||
setUserConfigViewData(userConfig.configuration);
|
setUserConfigViewData(userConfig.configuration);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultConfigFilter = { where: { tableCode: $props.tableCode } };
|
const defaultConfigFilter = { where: { tableCode: $props.tableCode } };
|
||||||
const defaultConfig = await getConfig('DefaultViewConfigs', defaultConfigFilter);
|
const defaultConfig = await getConfig('DefaultViewConfigs', defaultConfigFilter);
|
||||||
|
|
||||||
if (defaultConfig) {
|
if (defaultConfig) {
|
||||||
// Si el backend devuelve una configuración por defecto la usamos
|
// Si el backend devuelve una configuración por defecto la usamos
|
||||||
setUserConfigViewData(defaultConfig.columns);
|
setUserConfigViewData(defaultConfig.columns);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// Si no hay configuración por defecto mostramos todas las columnas
|
// Si no hay configuración por defecto mostramos todas las columnas
|
||||||
const defaultColumns = {};
|
const defaultColumns = {};
|
||||||
$props.allColumns.forEach((col) => (defaultColumns[col] = true));
|
$props.allColumns.forEach((col) => (defaultColumns[col] = true));
|
||||||
setUserConfigViewData(defaultColumns);
|
setUserConfigViewData(defaultColumns);
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.err('Error fetching config view data', err);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveConfig = async () => {
|
const saveConfig = async () => {
|
||||||
try {
|
const params = {};
|
||||||
const params = {};
|
const configuration = {};
|
||||||
const configuration = {};
|
|
||||||
|
|
||||||
formattedCols.value.forEach((col) => {
|
formattedCols.value.forEach((col) => {
|
||||||
const { name, active } = col;
|
const { name, active } = col;
|
||||||
configuration[name] = active;
|
configuration[name] = active;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Si existe una view config del usuario hacemos un update si no la creamos
|
// Si existe una view config del usuario hacemos un update si no la creamos
|
||||||
if (initialUserConfigViewData.value) {
|
if (initialUserConfigViewData.value) {
|
||||||
params.updates = [
|
params.updates = [
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
configuration: configuration,
|
|
||||||
},
|
|
||||||
where: {
|
|
||||||
id: initialUserConfigViewData.value.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
params.creates = [
|
|
||||||
{
|
|
||||||
userFk: user.value.id,
|
|
||||||
tableCode: $props.tableCode,
|
|
||||||
tableConfig: $props.tableCode,
|
|
||||||
configuration: configuration,
|
configuration: configuration,
|
||||||
},
|
},
|
||||||
];
|
where: {
|
||||||
}
|
id: initialUserConfigViewData.value.id,
|
||||||
|
},
|
||||||
const response = await axios.post('UserConfigViews/crud', params);
|
},
|
||||||
if (response.data && response.data[0]) {
|
];
|
||||||
initialUserConfigViewData.value = response.data[0];
|
} else {
|
||||||
}
|
params.creates = [
|
||||||
emitSavedConfig();
|
{
|
||||||
notify('globals.dataSaved', 'positive');
|
userFk: user.value.id,
|
||||||
popupProxyRef.value.hide();
|
tableCode: $props.tableCode,
|
||||||
} catch (err) {
|
tableConfig: $props.tableCode,
|
||||||
console.error('Error saving user view config', err);
|
configuration: configuration,
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const response = await axios.post('UserConfigViews/crud', params);
|
||||||
|
if (response.data && response.data[0]) {
|
||||||
|
initialUserConfigViewData.value = response.data[0];
|
||||||
|
}
|
||||||
|
emitSavedConfig();
|
||||||
|
notify('globals.dataSaved', 'positive');
|
||||||
|
popupProxyRef.value.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
const emitSavedConfig = () => {
|
const emitSavedConfig = () => {
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch } from 'vue';
|
import { nextTick, ref, watch } from 'vue';
|
||||||
import { QInput } from 'quasar';
|
import { QInput } from 'quasar';
|
||||||
|
|
||||||
const props = defineProps({
|
const $props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
insertable: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue', 'accountShortToStandard']);
|
const emit = defineEmits(['update:modelValue', 'accountShortToStandard']);
|
||||||
|
|
||||||
let internalValue = ref(props.modelValue);
|
let internalValue = ref($props.modelValue);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.modelValue,
|
() => $props.modelValue,
|
||||||
(newVal) => {
|
(newVal) => {
|
||||||
internalValue.value = newVal;
|
internalValue.value = newVal;
|
||||||
}
|
}
|
||||||
|
@ -28,8 +32,46 @@ watch(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleKeydown = (e) => {
|
||||||
|
if (e.key === 'Backspace') return;
|
||||||
|
if (e.key === '.') {
|
||||||
|
accountShortToStandard();
|
||||||
|
// TODO: Fix this setTimeout, with nextTick doesn't work
|
||||||
|
setTimeout(() => {
|
||||||
|
setCursorPosition(0, e.target);
|
||||||
|
}, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($props.insertable && e.key.match(/[0-9]/)) {
|
||||||
|
handleInsertMode(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
function setCursorPosition(pos, el = vnInputRef.value) {
|
||||||
|
el.focus();
|
||||||
|
el.setSelectionRange(pos, pos);
|
||||||
|
}
|
||||||
|
const vnInputRef = ref(false);
|
||||||
|
const handleInsertMode = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const input = e.target;
|
||||||
|
const cursorPos = input.selectionStart;
|
||||||
|
const { maxlength } = vnInputRef.value;
|
||||||
|
let currentValue = internalValue.value;
|
||||||
|
if (!currentValue) currentValue = e.key;
|
||||||
|
const newValue = e.key;
|
||||||
|
if (newValue && !isNaN(newValue) && cursorPos < maxlength) {
|
||||||
|
internalValue.value =
|
||||||
|
currentValue.substring(0, cursorPos) +
|
||||||
|
newValue +
|
||||||
|
currentValue.substring(cursorPos + 1);
|
||||||
|
}
|
||||||
|
nextTick(() => {
|
||||||
|
input.setSelectionRange(cursorPos + 1, cursorPos + 1);
|
||||||
|
});
|
||||||
|
};
|
||||||
function accountShortToStandard() {
|
function accountShortToStandard() {
|
||||||
internalValue.value = internalValue.value.replace(
|
internalValue.value = internalValue.value?.replace(
|
||||||
'.',
|
'.',
|
||||||
'0'.repeat(11 - internalValue.value.length)
|
'0'.repeat(11 - internalValue.value.length)
|
||||||
);
|
);
|
||||||
|
@ -37,5 +79,5 @@ function accountShortToStandard() {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<q-input v-model="internalValue" />
|
<QInput @keydown="handleKeydown" ref="vnInputRef" v-model="internalValue" />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -15,7 +15,7 @@ let root = ref(null);
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
matched.value = currentRoute.value.matched.filter(
|
matched.value = currentRoute.value.matched.filter(
|
||||||
(matched) => Object.keys(matched.meta).length
|
(matched) => !!matched?.meta?.title || !!matched?.meta?.icon
|
||||||
);
|
);
|
||||||
breadcrumbs.value.length = 0;
|
breadcrumbs.value.length = 0;
|
||||||
if (!matched.value[0]) return;
|
if (!matched.value[0]) return;
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
<script setup>
|
||||||
|
import VnSelect from './VnSelect.vue';
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
selectProps: { type: Object, required: true },
|
||||||
|
promise: { type: Function, default: () => {} },
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<QBtnDropdown v-bind="$attrs" color="primary">
|
||||||
|
<VnSelect
|
||||||
|
v-bind="selectProps"
|
||||||
|
hide-selected
|
||||||
|
hide-dropdown-icon
|
||||||
|
focus-on-mount
|
||||||
|
@update:model-value="promise"
|
||||||
|
data-cy="vnBtnSelect_select"
|
||||||
|
/>
|
||||||
|
</QBtnDropdown>
|
||||||
|
</template>
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onBeforeMount, computed } from 'vue';
|
import { onBeforeMount, computed } from 'vue';
|
||||||
import { useRoute, onBeforeRouteUpdate } from 'vue-router';
|
import { useRoute, useRouter, onBeforeRouteUpdate } from 'vue-router';
|
||||||
import { useArrayData } from 'src/composables/useArrayData';
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
import { useStateStore } from 'stores/useStateStore';
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
import useCardSize from 'src/composables/useCardSize';
|
import useCardSize from 'src/composables/useCardSize';
|
||||||
|
@ -8,7 +8,6 @@ import VnSubToolbar from '../ui/VnSubToolbar.vue';
|
||||||
import VnSearchbar from 'components/ui/VnSearchbar.vue';
|
import VnSearchbar from 'components/ui/VnSearchbar.vue';
|
||||||
import LeftMenu from 'components/LeftMenu.vue';
|
import LeftMenu from 'components/LeftMenu.vue';
|
||||||
import RightMenu from 'components/common/RightMenu.vue';
|
import RightMenu from 'components/common/RightMenu.vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
dataKey: { type: String, required: true },
|
dataKey: { type: String, required: true },
|
||||||
baseUrl: { type: String, default: undefined },
|
baseUrl: { type: String, default: undefined },
|
||||||
|
@ -17,29 +16,37 @@ const props = defineProps({
|
||||||
descriptor: { type: Object, required: true },
|
descriptor: { type: Object, required: true },
|
||||||
filterPanel: { type: Object, default: undefined },
|
filterPanel: { type: Object, default: undefined },
|
||||||
searchDataKey: { type: String, default: undefined },
|
searchDataKey: { type: String, default: undefined },
|
||||||
searchUrl: { type: String, default: undefined },
|
searchbarProps: { type: Object, default: undefined },
|
||||||
searchbarLabel: { type: String, default: '' },
|
redirectOnError: { type: Boolean, default: false },
|
||||||
searchbarInfo: { type: String, default: '' },
|
|
||||||
searchCustomRouteRedirect: { type: String, default: undefined },
|
|
||||||
searchRedirect: { type: Boolean, default: true },
|
|
||||||
searchMakeFetch: { type: Boolean, default: true },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const router = useRouter();
|
||||||
const url = computed(() => {
|
const url = computed(() => {
|
||||||
if (props.baseUrl) return `${props.baseUrl}/${route.params.id}`;
|
if (props.baseUrl) {
|
||||||
|
return `${props.baseUrl}/${route.params.id}`;
|
||||||
|
}
|
||||||
return props.customUrl;
|
return props.customUrl;
|
||||||
});
|
});
|
||||||
|
const searchRightDataKey = computed(() => {
|
||||||
|
if (!props.searchDataKey) return route.name;
|
||||||
|
return props.searchDataKey;
|
||||||
|
});
|
||||||
const arrayData = useArrayData(props.dataKey, {
|
const arrayData = useArrayData(props.dataKey, {
|
||||||
url: url.value,
|
url: url.value,
|
||||||
filter: props.filter,
|
filter: props.filter,
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
onBeforeMount(async () => {
|
||||||
if (!props.baseUrl) arrayData.store.filter.where = { id: route.params.id };
|
try {
|
||||||
await arrayData.fetch({ append: false, updateRouter: false });
|
if (!props.baseUrl) arrayData.store.filter.where = { id: route.params.id };
|
||||||
|
await arrayData.fetch({ append: false, updateRouter: false });
|
||||||
|
} catch {
|
||||||
|
const { matched: matches } = router.currentRoute.value;
|
||||||
|
const { path } = matches.at(-1);
|
||||||
|
router.push({ path: path.replace(/:id.*/, '') });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (props.baseUrl) {
|
if (props.baseUrl) {
|
||||||
|
@ -65,26 +72,18 @@ if (props.baseUrl) {
|
||||||
</QScrollArea>
|
</QScrollArea>
|
||||||
</QDrawer>
|
</QDrawer>
|
||||||
<slot name="searchbar" v-if="props.searchDataKey">
|
<slot name="searchbar" v-if="props.searchDataKey">
|
||||||
<VnSearchbar
|
<VnSearchbar :data-key="props.searchDataKey" v-bind="props.searchbarProps" />
|
||||||
:data-key="props.searchDataKey"
|
|
||||||
:url="props.searchUrl"
|
|
||||||
:label="props.searchbarLabel"
|
|
||||||
:info="props.searchbarInfo"
|
|
||||||
:custom-route-redirect-name="searchCustomRouteRedirect"
|
|
||||||
:redirect="searchRedirect"
|
|
||||||
/>
|
|
||||||
</slot>
|
</slot>
|
||||||
<slot v-else name="searchbar" />
|
|
||||||
<RightMenu>
|
<RightMenu>
|
||||||
<template #right-panel v-if="props.filterPanel">
|
<template #right-panel v-if="props.filterPanel">
|
||||||
<component :is="props.filterPanel" :data-key="props.searchDataKey" />
|
<component :is="props.filterPanel" :data-key="searchRightDataKey" />
|
||||||
</template>
|
</template>
|
||||||
</RightMenu>
|
</RightMenu>
|
||||||
<QPageContainer>
|
<QPageContainer>
|
||||||
<QPage>
|
<QPage>
|
||||||
<VnSubToolbar />
|
<VnSubToolbar />
|
||||||
<div :class="[useCardSize(), $attrs.class]">
|
<div :class="[useCardSize(), $attrs.class]">
|
||||||
<RouterView />
|
<RouterView :key="route.path" />
|
||||||
</div>
|
</div>
|
||||||
</QPage>
|
</QPage>
|
||||||
</QPageContainer>
|
</QPageContainer>
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
<script setup>
|
||||||
|
import { onBeforeMount, computed } from 'vue';
|
||||||
|
import { useRoute, useRouter, onBeforeRouteUpdate } from 'vue-router';
|
||||||
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
|
import useCardSize from 'src/composables/useCardSize';
|
||||||
|
import LeftMenu from 'components/LeftMenu.vue';
|
||||||
|
import VnSubToolbar from '../ui/VnSubToolbar.vue';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
dataKey: { type: String, required: true },
|
||||||
|
baseUrl: { type: String, default: undefined },
|
||||||
|
customUrl: { type: String, default: undefined },
|
||||||
|
filter: { type: Object, default: () => {} },
|
||||||
|
descriptor: { type: Object, required: true },
|
||||||
|
filterPanel: { type: Object, default: undefined },
|
||||||
|
searchDataKey: { type: String, default: undefined },
|
||||||
|
searchbarProps: { type: Object, default: undefined },
|
||||||
|
redirectOnError: { type: Boolean, default: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
const stateStore = useStateStore();
|
||||||
|
const route = useRoute();
|
||||||
|
const router = useRouter();
|
||||||
|
const url = computed(() => {
|
||||||
|
if (props.baseUrl) {
|
||||||
|
return `${props.baseUrl}/${route.params.id}`;
|
||||||
|
}
|
||||||
|
return props.customUrl;
|
||||||
|
});
|
||||||
|
|
||||||
|
const arrayData = useArrayData(props.dataKey, {
|
||||||
|
url: url.value,
|
||||||
|
filter: props.filter,
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeMount(async () => {
|
||||||
|
try {
|
||||||
|
if (!props.baseUrl) arrayData.store.filter.where = { id: route.params.id };
|
||||||
|
await arrayData.fetch({ append: false, updateRouter: false });
|
||||||
|
} catch {
|
||||||
|
const { matched: matches } = router.currentRoute.value;
|
||||||
|
const { path } = matches.at(-1);
|
||||||
|
router.push({ path: path.replace(/:id.*/, '') });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (props.baseUrl) {
|
||||||
|
onBeforeRouteUpdate(async (to, from) => {
|
||||||
|
if (to.params.id !== from.params.id) {
|
||||||
|
arrayData.store.url = `${props.baseUrl}/${to.params.id}`;
|
||||||
|
await arrayData.fetch({ append: false, updateRouter: false });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<Teleport to="#left-panel" v-if="stateStore.isHeaderMounted()">
|
||||||
|
<component :is="descriptor" />
|
||||||
|
<QSeparator />
|
||||||
|
<LeftMenu source="card" />
|
||||||
|
</Teleport>
|
||||||
|
<VnSubToolbar />
|
||||||
|
<div :class="[useCardSize(), $attrs.class]">
|
||||||
|
<RouterView :key="route.path" />
|
||||||
|
</div>
|
||||||
|
</template>
|
|
@ -0,0 +1,136 @@
|
||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import VnRow from '../ui/VnRow.vue';
|
||||||
|
import FetchData from '../FetchData.vue';
|
||||||
|
import useNotify from 'src/composables/useNotify';
|
||||||
|
import VnInputPassword from 'src/components/common/VnInputPassword.vue';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
submitFn: { type: Function, default: () => {} },
|
||||||
|
askOldPass: { type: Boolean, default: false },
|
||||||
|
});
|
||||||
|
const emit = defineEmits(['onSubmit']);
|
||||||
|
const { t } = useI18n();
|
||||||
|
const { notify } = useNotify();
|
||||||
|
|
||||||
|
const form = ref();
|
||||||
|
const changePassDialog = ref();
|
||||||
|
const passwords = ref({ newPassword: null, repeatPassword: null });
|
||||||
|
const requirements = ref([]);
|
||||||
|
const isLoading = ref(false);
|
||||||
|
|
||||||
|
const validate = async () => {
|
||||||
|
const { newPassword, repeatPassword, oldPassword } = passwords.value;
|
||||||
|
|
||||||
|
if (!newPassword) {
|
||||||
|
notify(t('You must enter a new password'), 'negative');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (newPassword !== repeatPassword) {
|
||||||
|
notify(t("Passwords don't match"), 'negative');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLoading.value = true;
|
||||||
|
await props.submitFn(newPassword, oldPassword);
|
||||||
|
emit('onSubmit');
|
||||||
|
} catch (e) {
|
||||||
|
notify('errors.writeRequest', 'negative');
|
||||||
|
} finally {
|
||||||
|
changePassDialog.value.hide();
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
defineExpose({ show: () => changePassDialog.value.show() });
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<FetchData
|
||||||
|
url="UserPasswords/findOne"
|
||||||
|
auto-load
|
||||||
|
@on-fetch="(data) => (requirements = data)"
|
||||||
|
/>
|
||||||
|
<QDialog ref="changePassDialog">
|
||||||
|
<QCard style="width: 350px">
|
||||||
|
<QCardSection>
|
||||||
|
<slot name="header">
|
||||||
|
<VnRow class="items-center" style="flex-direction: row">
|
||||||
|
<span class="text-h6" v-text="t('globals.changePass')" />
|
||||||
|
<QIcon
|
||||||
|
class="cursor-pointer"
|
||||||
|
name="close"
|
||||||
|
size="xs"
|
||||||
|
style="flex: 0"
|
||||||
|
v-close-popup
|
||||||
|
/>
|
||||||
|
</VnRow>
|
||||||
|
</slot>
|
||||||
|
</QCardSection>
|
||||||
|
<QForm ref="form">
|
||||||
|
<QCardSection>
|
||||||
|
<VnInputPassword
|
||||||
|
v-if="props.askOldPass"
|
||||||
|
:label="t('Old password')"
|
||||||
|
v-model="passwords.oldPassword"
|
||||||
|
:required="true"
|
||||||
|
:toggle-visibility="true"
|
||||||
|
autofocus
|
||||||
|
/>
|
||||||
|
<VnInputPassword
|
||||||
|
:label="t('New password')"
|
||||||
|
v-model="passwords.newPassword"
|
||||||
|
:required="true"
|
||||||
|
:toggle-visibility="true"
|
||||||
|
:info="
|
||||||
|
t('passwordRequirements', {
|
||||||
|
length: requirements.length,
|
||||||
|
nAlpha: requirements.nAlpha,
|
||||||
|
nUpper: requirements.nUpper,
|
||||||
|
nDigits: requirements.nDigits,
|
||||||
|
nPunct: requirements.nPunct,
|
||||||
|
})
|
||||||
|
"
|
||||||
|
autofocus
|
||||||
|
/>
|
||||||
|
|
||||||
|
<VnInputPassword
|
||||||
|
:label="t('Repeat password')"
|
||||||
|
v-model="passwords.repeatPassword"
|
||||||
|
:toggle-visibility="true"
|
||||||
|
/>
|
||||||
|
</QCardSection>
|
||||||
|
</QForm>
|
||||||
|
<QCardActions>
|
||||||
|
<slot name="actions">
|
||||||
|
<QBtn
|
||||||
|
:disabled="isLoading"
|
||||||
|
:loading="isLoading"
|
||||||
|
:label="t('globals.cancel')"
|
||||||
|
class="q-ml-sm"
|
||||||
|
color="primary"
|
||||||
|
flat
|
||||||
|
type="reset"
|
||||||
|
v-close-popup
|
||||||
|
/>
|
||||||
|
<QBtn
|
||||||
|
:disabled="isLoading"
|
||||||
|
:loading="isLoading"
|
||||||
|
:label="t('globals.confirm')"
|
||||||
|
color="primary"
|
||||||
|
@click="validate"
|
||||||
|
/>
|
||||||
|
</slot>
|
||||||
|
</QCardActions>
|
||||||
|
</QCard>
|
||||||
|
</QDialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<i18n>
|
||||||
|
es:
|
||||||
|
New password: Nueva contraseña
|
||||||
|
Repeat password: Repetir contraseña
|
||||||
|
You must enter a new password: Debes introducir la nueva contraseña
|
||||||
|
Passwords don't match: Las contraseñas no coinciden
|
||||||
|
</i18n>
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, defineModel } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
|
||||||
const model = defineModel(undefined, { required: true });
|
const model = defineModel(undefined, { required: true });
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
|
@ -33,7 +33,7 @@ function mix(toComponent) {
|
||||||
...toComponent,
|
...toComponent,
|
||||||
...toValueAttrs(customComponent?.forceAttrs),
|
...toValueAttrs(customComponent?.forceAttrs),
|
||||||
},
|
},
|
||||||
event: event ?? customComponent?.event,
|
event: { ...customComponent?.event, ...event },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
<script setup>
|
|
||||||
import { computed } from 'vue';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
|
||||||
import { useCapitalize } from 'src/composables/useCapitalize';
|
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
modelValue: { type: [String, Number], default: '' },
|
|
||||||
});
|
|
||||||
|
|
||||||
const { t } = useI18n();
|
|
||||||
const emit = defineEmits(['update:modelValue']);
|
|
||||||
|
|
||||||
const amount = computed({
|
|
||||||
get() {
|
|
||||||
return props.modelValue;
|
|
||||||
},
|
|
||||||
set(val) {
|
|
||||||
emit('update:modelValue', val);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<template>
|
|
||||||
<VnInput
|
|
||||||
v-model="amount"
|
|
||||||
type="number"
|
|
||||||
step="any"
|
|
||||||
:label="useCapitalize(t('amount'))"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
<i18n>
|
|
||||||
es:
|
|
||||||
amount: importe
|
|
||||||
</i18n>
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<script setup>
|
||||||
|
const model = defineModel({ type: [String, Number], required: true });
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<QDate v-model="model" :today-btn="true" :options="$attrs.options" />
|
||||||
|
</template>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.q-date {
|
||||||
|
width: 245px;
|
||||||
|
min-width: unset;
|
||||||
|
|
||||||
|
:deep(.q-date__calendar) {
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
:deep(.q-date__view) {
|
||||||
|
min-height: 245px;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
:deep(.q-date__calendar-days-container) {
|
||||||
|
min-height: 160px;
|
||||||
|
height: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.q-date__header) {
|
||||||
|
padding: 2px 2px 5px 12px;
|
||||||
|
height: 60px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -0,0 +1,39 @@
|
||||||
|
<script setup>
|
||||||
|
import { toDateFormat } from 'src/filters/date.js';
|
||||||
|
|
||||||
|
defineProps({ date: { type: [Date, String], required: true } });
|
||||||
|
|
||||||
|
function getBadgeAttrs(date) {
|
||||||
|
let today = Date.vnNew();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
let timeTicket = new Date(date);
|
||||||
|
timeTicket.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
let timeDiff = today - timeTicket;
|
||||||
|
|
||||||
|
if (timeDiff == 0) return { color: 'warning', class: 'black-text-color' };
|
||||||
|
if (timeDiff < 0) return { color: 'success', class: 'black-text-color' };
|
||||||
|
return { color: 'transparent', class: 'normal-text-color' };
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatShippedDate(date) {
|
||||||
|
if (!date) return '-';
|
||||||
|
const dateSplit = date.split('T');
|
||||||
|
const [year, month, day] = dateSplit[0].split('-');
|
||||||
|
const newDate = new Date(year, month - 1, day);
|
||||||
|
return toDateFormat(newDate);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<QBadge v-bind="getBadgeAttrs(date)" class="q-pa-sm" style="font-size: 14px">
|
||||||
|
{{ formatShippedDate(date) }}
|
||||||
|
</QBadge>
|
||||||
|
</template>
|
||||||
|
<style lang="scss">
|
||||||
|
.black-text-color {
|
||||||
|
color: var(--vn-black-text-color);
|
||||||
|
}
|
||||||
|
.normal-text-color {
|
||||||
|
color: var(--vn-text-color);
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -31,6 +31,10 @@ const $props = defineProps({
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
|
description: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const warehouses = ref();
|
const warehouses = ref();
|
||||||
|
@ -43,7 +47,8 @@ const dms = ref({});
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
defaultData();
|
defaultData();
|
||||||
if (!$props.formInitialData)
|
if (!$props.formInitialData)
|
||||||
dms.value.description = t($props.model + 'Description', dms.value);
|
dms.value.description =
|
||||||
|
$props.description ?? t($props.model + 'Description', dms.value);
|
||||||
});
|
});
|
||||||
function onFileChange(files) {
|
function onFileChange(files) {
|
||||||
dms.value.hasFileAttached = !!files;
|
dms.value.hasFileAttached = !!files;
|
||||||
|
@ -54,7 +59,6 @@ function mapperDms(data) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
const { files } = data;
|
const { files } = data;
|
||||||
if (files) formData.append(files?.name, files);
|
if (files) formData.append(files?.name, files);
|
||||||
delete data.files;
|
|
||||||
|
|
||||||
const dms = {
|
const dms = {
|
||||||
hasFile: !!data.hasFile,
|
hasFile: !!data.hasFile,
|
||||||
|
@ -78,6 +82,7 @@ async function save() {
|
||||||
const body = mapperDms(dms.value);
|
const body = mapperDms(dms.value);
|
||||||
const response = await axios.post(getUrl(), body[0], body[1]);
|
const response = await axios.post(getUrl(), body[0], body[1]);
|
||||||
emit('onDataSaved', body[1].params, response);
|
emit('onDataSaved', body[1].params, response);
|
||||||
|
delete dms.value.files;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,13 +163,14 @@ function addDefaultData(data) {
|
||||||
/>
|
/>
|
||||||
<QFile
|
<QFile
|
||||||
ref="inputFileRef"
|
ref="inputFileRef"
|
||||||
:label="t('entry.buys.file')"
|
:label="t('globals.file')"
|
||||||
v-model="dms.files"
|
v-model="dms.files"
|
||||||
:multiple="false"
|
:multiple="false"
|
||||||
:accept="allowedContentTypes"
|
:accept="allowedContentTypes"
|
||||||
@update:model-value="onFileChange(dms.files)"
|
@update:model-value="onFileChange(dms.files)"
|
||||||
class="required"
|
class="required"
|
||||||
:display-value="dms.file"
|
:display-value="dms.file"
|
||||||
|
data-cy="VnDms_inputFile"
|
||||||
>
|
>
|
||||||
<template #append>
|
<template #append>
|
||||||
<QIcon
|
<QIcon
|
||||||
|
|
|
@ -5,12 +5,14 @@ import { useRoute } from 'vue-router';
|
||||||
import { useQuasar, QCheckbox, QBtn, QInput } from 'quasar';
|
import { useQuasar, QCheckbox, QBtn, QInput } from 'quasar';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import VnUserLink from '../ui/VnUserLink.vue';
|
||||||
|
import { downloadFile } from 'src/composables/downloadFile';
|
||||||
|
import VnImg from 'components/ui/VnImg.vue';
|
||||||
import VnPaginate from 'components/ui/VnPaginate.vue';
|
import VnPaginate from 'components/ui/VnPaginate.vue';
|
||||||
import VnDms from 'src/components/common/VnDms.vue';
|
import VnDms from 'src/components/common/VnDms.vue';
|
||||||
import VnConfirm from 'components/ui/VnConfirm.vue';
|
import VnConfirm from 'components/ui/VnConfirm.vue';
|
||||||
import VnInputDate from 'components/common/VnInputDate.vue';
|
import VnInputDate from 'components/common/VnInputDate.vue';
|
||||||
import VnUserLink from '../ui/VnUserLink.vue';
|
import { useSession } from 'src/composables/useSession';
|
||||||
import { downloadFile } from 'src/composables/downloadFile';
|
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
|
@ -18,6 +20,7 @@ const { t } = useI18n();
|
||||||
const rows = ref();
|
const rows = ref();
|
||||||
const dmsRef = ref();
|
const dmsRef = ref();
|
||||||
const formDialog = ref({});
|
const formDialog = ref({});
|
||||||
|
const token = useSession().getTokenMultimedia();
|
||||||
|
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
model: {
|
model: {
|
||||||
|
@ -89,6 +92,23 @@ const dmsFilter = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const columns = computed(() => [
|
const columns = computed(() => [
|
||||||
|
{
|
||||||
|
label: '',
|
||||||
|
name: 'file',
|
||||||
|
align: 'left',
|
||||||
|
component: VnImg,
|
||||||
|
props: (prop) => {
|
||||||
|
return {
|
||||||
|
storage: 'dms',
|
||||||
|
collection: null,
|
||||||
|
resolution: null,
|
||||||
|
id: prop.row.file.split('.')[0],
|
||||||
|
token: token,
|
||||||
|
class: 'rounded',
|
||||||
|
ratio: 1,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
align: 'left',
|
align: 'left',
|
||||||
field: 'id',
|
field: 'id',
|
||||||
|
@ -135,19 +155,13 @@ const columns = computed(() => [
|
||||||
field: 'hasFile',
|
field: 'hasFile',
|
||||||
label: t('globals.original'),
|
label: t('globals.original'),
|
||||||
name: 'hasFile',
|
name: 'hasFile',
|
||||||
|
toolTip: t('The documentation is available in paper form'),
|
||||||
component: QCheckbox,
|
component: QCheckbox,
|
||||||
props: (prop) => ({
|
props: (prop) => ({
|
||||||
disable: true,
|
disable: true,
|
||||||
'model-value': Boolean(prop.value),
|
'model-value': Boolean(prop.value),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
align: 'left',
|
|
||||||
field: 'file',
|
|
||||||
label: t('globals.file'),
|
|
||||||
name: 'file',
|
|
||||||
component: 'span',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
align: 'left',
|
align: 'left',
|
||||||
field: 'worker',
|
field: 'worker',
|
||||||
|
@ -283,7 +297,7 @@ defineExpose({
|
||||||
ref="dmsRef"
|
ref="dmsRef"
|
||||||
:data-key="$props.model"
|
:data-key="$props.model"
|
||||||
:url="$props.model"
|
:url="$props.model"
|
||||||
:filter="dmsFilter"
|
:user-filter="dmsFilter"
|
||||||
:order="['dmsFk DESC']"
|
:order="['dmsFk DESC']"
|
||||||
:auto-load="true"
|
:auto-load="true"
|
||||||
@on-fetch="setData"
|
@on-fetch="setData"
|
||||||
|
@ -297,6 +311,14 @@ defineExpose({
|
||||||
row-key="clientFk"
|
row-key="clientFk"
|
||||||
:grid="$q.screen.lt.sm"
|
:grid="$q.screen.lt.sm"
|
||||||
>
|
>
|
||||||
|
<template #header="props">
|
||||||
|
<QTr :props="props" class="bg">
|
||||||
|
<QTh v-for="col in props.cols" :key="col.name" :props="props">
|
||||||
|
<QTooltip v-if="col.toolTip">{{ col.toolTip }}</QTooltip
|
||||||
|
>{{ col.label }}
|
||||||
|
</QTh>
|
||||||
|
</QTr>
|
||||||
|
</template>
|
||||||
<template #body-cell="props">
|
<template #body-cell="props">
|
||||||
<QTd :props="props">
|
<QTd :props="props">
|
||||||
<QTr :props="props">
|
<QTr :props="props">
|
||||||
|
@ -378,7 +400,14 @@ defineExpose({
|
||||||
/>
|
/>
|
||||||
</QDialog>
|
</QDialog>
|
||||||
<QPageSticky position="bottom-right" :offset="[25, 25]">
|
<QPageSticky position="bottom-right" :offset="[25, 25]">
|
||||||
<QBtn fab color="primary" icon="add" @click="showFormDialog()" class="fill-icon">
|
<QBtn
|
||||||
|
fab
|
||||||
|
color="primary"
|
||||||
|
icon="add"
|
||||||
|
shortcut="+"
|
||||||
|
@click="showFormDialog()"
|
||||||
|
class="fill-icon"
|
||||||
|
>
|
||||||
<QTooltip>
|
<QTooltip>
|
||||||
{{ t('Upload file') }}
|
{{ t('Upload file') }}
|
||||||
</QTooltip>
|
</QTooltip>
|
||||||
|
@ -386,10 +415,6 @@ defineExpose({
|
||||||
</QPageSticky>
|
</QPageSticky>
|
||||||
</template>
|
</template>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.q-gutter-y-ms {
|
|
||||||
display: grid;
|
|
||||||
row-gap: 20px;
|
|
||||||
}
|
|
||||||
.labelColor {
|
.labelColor {
|
||||||
color: var(--vn-label-color);
|
color: var(--vn-label-color);
|
||||||
}
|
}
|
||||||
|
@ -397,8 +422,10 @@ defineExpose({
|
||||||
<i18n>
|
<i18n>
|
||||||
en:
|
en:
|
||||||
contentTypesInfo: Allowed file types {allowedContentTypes}
|
contentTypesInfo: Allowed file types {allowedContentTypes}
|
||||||
|
The documentation is available in paper form: The documentation is available in paper form
|
||||||
es:
|
es:
|
||||||
contentTypesInfo: Tipos de archivo permitidos {allowedContentTypes}
|
contentTypesInfo: Tipos de archivo permitidos {allowedContentTypes}
|
||||||
Generate identifier for original file: Generar identificador para archivo original
|
Generate identifier for original file: Generar identificador para archivo original
|
||||||
Upload file: Subir fichero
|
Upload file: Subir fichero
|
||||||
|
the documentation is available in paper form: Se tiene la documentación en papel
|
||||||
</i18n>
|
</i18n>
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref, useAttrs, nextTick } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { useRequired } from 'src/composables/useRequired';
|
||||||
|
|
||||||
|
const $attrs = useAttrs();
|
||||||
|
const { isRequired, requiredFieldRule } = useRequired($attrs);
|
||||||
|
const { t } = useI18n();
|
||||||
const emit = defineEmits([
|
const emit = defineEmits([
|
||||||
'update:modelValue',
|
'update:modelValue',
|
||||||
'update:options',
|
'update:options',
|
||||||
|
@ -26,16 +30,28 @@ const $props = defineProps({
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
emptyToNull: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
insertable: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
maxlength: {
|
||||||
|
type: Number,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
|
||||||
const requiredFieldRule = (val) => !!val || t('globals.fieldRequired');
|
|
||||||
const vnInputRef = ref(null);
|
const vnInputRef = ref(null);
|
||||||
|
const showPassword = ref(false);
|
||||||
const value = computed({
|
const value = computed({
|
||||||
get() {
|
get() {
|
||||||
return $props.modelValue;
|
return $props.modelValue;
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
|
if ($props.emptyToNull && value === '') value = null;
|
||||||
emit('update:modelValue', value);
|
emit('update:modelValue', value);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -58,48 +74,93 @@ defineExpose({
|
||||||
focus,
|
focus,
|
||||||
});
|
});
|
||||||
|
|
||||||
const inputRules = [
|
const mixinRules = [
|
||||||
|
requiredFieldRule,
|
||||||
|
...($attrs.rules ?? []),
|
||||||
(val) => {
|
(val) => {
|
||||||
const { min } = vnInputRef.value.$attrs;
|
const { maxlength } = vnInputRef.value;
|
||||||
|
if (maxlength && +val.length > maxlength)
|
||||||
|
return t(`maxLength`, { value: maxlength });
|
||||||
|
const { min, max } = vnInputRef.value.$attrs;
|
||||||
|
if (!min) return null;
|
||||||
if (min >= 0) if (Math.floor(val) < min) return t('inputMin', { value: min });
|
if (min >= 0) if (Math.floor(val) < min) return t('inputMin', { value: min });
|
||||||
|
if (!max) return null;
|
||||||
|
if (max > 0) {
|
||||||
|
if (Math.floor(val) > max) return t('inputMax', { value: max });
|
||||||
|
}
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const handleKeydown = (e) => {
|
||||||
|
if (e.key === 'Backspace') return;
|
||||||
|
|
||||||
|
if ($props.insertable && e.key.match(/[0-9]/)) {
|
||||||
|
handleInsertMode(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInsertMode = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const input = e.target;
|
||||||
|
const cursorPos = input.selectionStart;
|
||||||
|
const { maxlength } = vnInputRef.value;
|
||||||
|
let currentValue = value.value;
|
||||||
|
if (!currentValue) currentValue = e.key;
|
||||||
|
const newValue = e.key;
|
||||||
|
if (newValue && !isNaN(newValue) && cursorPos < maxlength) {
|
||||||
|
value.value =
|
||||||
|
currentValue.substring(0, cursorPos) +
|
||||||
|
newValue +
|
||||||
|
currentValue.substring(cursorPos + 1);
|
||||||
|
}
|
||||||
|
nextTick(() => {
|
||||||
|
input.setSelectionRange(cursorPos + 1, cursorPos + 1);
|
||||||
|
});
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div @mouseover="hover = true" @mouseleave="hover = false">
|
||||||
@mouseover="hover = true"
|
|
||||||
@mouseleave="hover = false"
|
|
||||||
:rules="$attrs.required ? [requiredFieldRule] : null"
|
|
||||||
>
|
|
||||||
<QInput
|
<QInput
|
||||||
ref="vnInputRef"
|
ref="vnInputRef"
|
||||||
v-model="value"
|
v-model="value"
|
||||||
v-bind="{ ...$attrs, ...styleAttrs }"
|
v-bind="{ ...$attrs, ...styleAttrs }"
|
||||||
:type="$attrs.type"
|
:type="$attrs.type"
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: isRequired }"
|
||||||
@keyup.enter="emit('keyup.enter')"
|
@keyup.enter="emit('keyup.enter')"
|
||||||
|
@keydown="handleKeydown"
|
||||||
:clearable="false"
|
:clearable="false"
|
||||||
:rules="inputRules"
|
:rules="mixinRules"
|
||||||
:lazy-rules="true"
|
:lazy-rules="true"
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
|
:data-cy="$attrs.dataCy ?? $attrs.label + '_input'"
|
||||||
>
|
>
|
||||||
<template v-if="$slots.prepend" #prepend>
|
<template #prepend>
|
||||||
<slot name="prepend" />
|
<slot name="prepend" />
|
||||||
</template>
|
</template>
|
||||||
<template #append>
|
<template #append>
|
||||||
<slot name="append" v-if="$slots.append && !$attrs.disabled" />
|
|
||||||
<QIcon
|
<QIcon
|
||||||
name="close"
|
name="close"
|
||||||
size="xs"
|
size="xs"
|
||||||
v-if="hover && value && !$attrs.disabled && $props.clearable"
|
:style="{
|
||||||
|
visibility:
|
||||||
|
hover &&
|
||||||
|
value &&
|
||||||
|
!$attrs.disabled &&
|
||||||
|
!$attrs.readonly &&
|
||||||
|
$props.clearable
|
||||||
|
? 'visible'
|
||||||
|
: 'hidden',
|
||||||
|
}"
|
||||||
@click="
|
@click="
|
||||||
() => {
|
() => {
|
||||||
value = null;
|
value = null;
|
||||||
|
vnInputRef.focus();
|
||||||
emit('remove');
|
emit('remove');
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
></QIcon>
|
/>
|
||||||
|
<slot name="append" v-if="$slots.append && !$attrs.disabled" />
|
||||||
<QIcon v-if="info" name="info">
|
<QIcon v-if="info" name="info">
|
||||||
<QTooltip max-width="350px">
|
<QTooltip max-width="350px">
|
||||||
{{ info }}
|
{{ info }}
|
||||||
|
@ -109,9 +170,3 @@ const inputRules = [
|
||||||
</QInput>
|
</QInput>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<i18n>
|
|
||||||
en:
|
|
||||||
inputMin: Must be more than {value}
|
|
||||||
es:
|
|
||||||
inputMin: Debe ser mayor a {value}
|
|
||||||
</i18n>
|
|
||||||
|
|
|
@ -1,38 +1,32 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, watch, computed, ref } from 'vue';
|
import { onMounted, watch, computed, ref, useAttrs } from 'vue';
|
||||||
import { date } from 'quasar';
|
import { date } from 'quasar';
|
||||||
import { useI18n } from 'vue-i18n';
|
import VnDate from './VnDate.vue';
|
||||||
|
import { useRequired } from 'src/composables/useRequired';
|
||||||
|
|
||||||
|
const $attrs = useAttrs();
|
||||||
|
const { isRequired, requiredFieldRule } = useRequired($attrs);
|
||||||
|
const model = defineModel({ type: [String, Date] });
|
||||||
|
|
||||||
const model = defineModel({ type: String });
|
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
isOutlined: {
|
isOutlined: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
showEvent: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const vnInputDateRef = ref(null);
|
||||||
const requiredFieldRule = (val) => !!val || t('globals.fieldRequired');
|
|
||||||
|
|
||||||
const dateFormat = 'DD/MM/YYYY';
|
const dateFormat = 'DD/MM/YYYY';
|
||||||
const isPopupOpen = ref();
|
const isPopupOpen = ref();
|
||||||
const hover = ref();
|
const hover = ref();
|
||||||
const mask = ref();
|
const mask = ref();
|
||||||
|
|
||||||
onMounted(() => {
|
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
|
||||||
// fix quasar bug
|
|
||||||
mask.value = '##/##/####';
|
|
||||||
});
|
|
||||||
|
|
||||||
const styleAttrs = computed(() => {
|
|
||||||
return $props.isOutlined
|
|
||||||
? {
|
|
||||||
dense: true,
|
|
||||||
outlined: true,
|
|
||||||
rounded: true,
|
|
||||||
}
|
|
||||||
: {};
|
|
||||||
});
|
|
||||||
|
|
||||||
const formattedDate = computed({
|
const formattedDate = computed({
|
||||||
get() {
|
get() {
|
||||||
|
@ -44,15 +38,12 @@ const formattedDate = computed({
|
||||||
let newDate;
|
let newDate;
|
||||||
if (value) {
|
if (value) {
|
||||||
// parse input
|
// parse input
|
||||||
if (value.includes('/')) {
|
if (value.includes('/') && value.length >= 10) {
|
||||||
if (value.length == 6) value = value + new Date().getFullYear();
|
if (value.at(2) == '/') value = value.split('/').reverse().join('/');
|
||||||
if (value.length >= 10) {
|
value = date.formatDate(
|
||||||
if (value.at(2) == '/') value = value.split('/').reverse().join('/');
|
new Date(value).toISOString(),
|
||||||
value = date.formatDate(
|
'YYYY-MM-DDTHH:mm:ss.SSSZ'
|
||||||
new Date(value).toISOString(),
|
);
|
||||||
'YYYY-MM-DDTHH:mm:ss.SSSZ'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const [year, month, day] = value.split('-').map((e) => parseInt(e));
|
const [year, month, day] = value.split('-').map((e) => parseInt(e));
|
||||||
newDate = new Date(year, month - 1, day);
|
newDate = new Date(year, month - 1, day);
|
||||||
|
@ -75,25 +66,46 @@ const formattedDate = computed({
|
||||||
const popupDate = computed(() =>
|
const popupDate = computed(() =>
|
||||||
model.value ? date.formatDate(new Date(model.value), 'YYYY/MM/DD') : model.value
|
model.value ? date.formatDate(new Date(model.value), 'YYYY/MM/DD') : model.value
|
||||||
);
|
);
|
||||||
|
onMounted(() => {
|
||||||
|
// fix quasar bug
|
||||||
|
mask.value = '##/##/####';
|
||||||
|
});
|
||||||
watch(
|
watch(
|
||||||
() => model.value,
|
() => model.value,
|
||||||
(val) => (formattedDate.value = val),
|
(val) => (formattedDate.value = val),
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const styleAttrs = computed(() => {
|
||||||
|
return $props.isOutlined
|
||||||
|
? {
|
||||||
|
dense: true,
|
||||||
|
outlined: true,
|
||||||
|
rounded: true,
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
});
|
||||||
|
|
||||||
|
const manageDate = (date) => {
|
||||||
|
formattedDate.value = date;
|
||||||
|
isPopupOpen.value = false;
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div @mouseover="hover = true" @mouseleave="hover = false">
|
<div @mouseover="hover = true" @mouseleave="hover = false">
|
||||||
<QInput
|
<QInput
|
||||||
|
ref="vnInputDateRef"
|
||||||
v-model="formattedDate"
|
v-model="formattedDate"
|
||||||
class="vn-input-date"
|
class="vn-input-date"
|
||||||
:mask="mask"
|
:mask="mask"
|
||||||
placeholder="dd/mm/aaaa"
|
placeholder="dd/mm/aaaa"
|
||||||
v-bind="{ ...$attrs, ...styleAttrs }"
|
v-bind="{ ...$attrs, ...styleAttrs }"
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: isRequired }"
|
||||||
:rules="$attrs.required ? [requiredFieldRule] : null"
|
:rules="mixinRules"
|
||||||
:clearable="false"
|
:clearable="false"
|
||||||
|
@click="isPopupOpen = !isPopupOpen"
|
||||||
|
hide-bottom-space
|
||||||
>
|
>
|
||||||
<template #append>
|
<template #append>
|
||||||
<QIcon
|
<QIcon
|
||||||
|
@ -106,18 +118,14 @@ watch(
|
||||||
!$attrs.disable
|
!$attrs.disable
|
||||||
"
|
"
|
||||||
@click="
|
@click="
|
||||||
|
vnInputDateRef.focus();
|
||||||
model = null;
|
model = null;
|
||||||
isPopupOpen = false;
|
isPopupOpen = false;
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
<QIcon
|
|
||||||
name="event"
|
|
||||||
class="cursor-pointer"
|
|
||||||
@click="isPopupOpen = !isPopupOpen"
|
|
||||||
:title="t('Open date')"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
<QMenu
|
<QMenu
|
||||||
|
v-if="$q.screen.gt.xs"
|
||||||
transition-show="scale"
|
transition-show="scale"
|
||||||
transition-hide="scale"
|
transition-hide="scale"
|
||||||
v-model="isPopupOpen"
|
v-model="isPopupOpen"
|
||||||
|
@ -126,30 +134,14 @@ watch(
|
||||||
:no-focus="true"
|
:no-focus="true"
|
||||||
:no-parent-event="true"
|
:no-parent-event="true"
|
||||||
>
|
>
|
||||||
<QDate
|
<VnDate v-model="popupDate" @update:model-value="manageDate" />
|
||||||
v-model="popupDate"
|
|
||||||
:landscape="true"
|
|
||||||
:today-btn="true"
|
|
||||||
@update:model-value="
|
|
||||||
(date) => {
|
|
||||||
formattedDate = date;
|
|
||||||
isPopupOpen = false;
|
|
||||||
}
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</QMenu>
|
</QMenu>
|
||||||
|
<QDialog v-else v-model="isPopupOpen">
|
||||||
|
<VnDate v-model="popupDate" @update:model-value="manageDate" />
|
||||||
|
</QDialog>
|
||||||
</QInput>
|
</QInput>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style lang="scss">
|
|
||||||
.vn-input-date.q-field--standard.q-field--readonly .q-field__control:before {
|
|
||||||
border-bottom-style: solid;
|
|
||||||
}
|
|
||||||
|
|
||||||
.vn-input-date.q-field--outlined.q-field--readonly .q-field__control:before {
|
|
||||||
border-style: solid;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<i18n>
|
<i18n>
|
||||||
es:
|
es:
|
||||||
Open date: Abrir fecha
|
Open date: Abrir fecha
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
<script setup>
|
||||||
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
step: { type: Number, default: 0.01 },
|
||||||
|
decimalPlaces: { type: Number, default: 2 },
|
||||||
|
positive: { type: Boolean, default: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
const model = defineModel({ type: [Number, String] });
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<VnInput
|
||||||
|
v-bind="$attrs"
|
||||||
|
v-model.number="model"
|
||||||
|
type="number"
|
||||||
|
:step="step"
|
||||||
|
@input="
|
||||||
|
(evt) => {
|
||||||
|
const val = evt.target.value;
|
||||||
|
if (positive && val < 0) return (model = 0);
|
||||||
|
const [, decimal] = val.split('.');
|
||||||
|
if (val && decimal?.length > decimalPlaces)
|
||||||
|
model = parseFloat(val).toFixed(decimalPlaces);
|
||||||
|
}
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</template>
|
|
@ -0,0 +1,31 @@
|
||||||
|
<script setup>
|
||||||
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
const model = defineModel({ type: [Number, String] });
|
||||||
|
const $props = defineProps({
|
||||||
|
toggleVisibility: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const showPassword = ref(false);
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<VnInput
|
||||||
|
v-bind="{ ...$attrs }"
|
||||||
|
v-model="model"
|
||||||
|
:type="
|
||||||
|
$props.toggleVisibility ? (showPassword ? 'text' : 'password') : $attrs.type
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<template #append v-if="toggleVisibility">
|
||||||
|
<QIcon
|
||||||
|
:name="showPassword ? 'visibility_off' : 'visibility'"
|
||||||
|
class="cursor-pointer"
|
||||||
|
@click="showPassword = !showPassword"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</VnInput>
|
||||||
|
</template>
|
|
@ -1,8 +1,11 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { watch, computed, ref, nextTick } from 'vue';
|
import { computed, ref, useAttrs } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
|
||||||
import { date } from 'quasar';
|
import { date } from 'quasar';
|
||||||
|
import VnTime from './VnTime.vue';
|
||||||
|
import { useRequired } from 'src/composables/useRequired';
|
||||||
|
|
||||||
|
const $attrs = useAttrs();
|
||||||
|
const { isRequired, requiredFieldRule } = useRequired($attrs);
|
||||||
const model = defineModel({ type: String });
|
const model = defineModel({ type: String });
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
timeOnly: {
|
timeOnly: {
|
||||||
|
@ -14,13 +17,12 @@ const props = defineProps({
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { t } = useI18n();
|
const vnInputTimeRef = ref(null);
|
||||||
const requiredFieldRule = (val) => !!val || t('globals.fieldRequired');
|
const initialDate = ref(model.value ?? Date.vnNew());
|
||||||
|
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
|
||||||
const dateFormat = 'HH:mm';
|
const dateFormat = 'HH:mm';
|
||||||
const isPopupOpen = ref();
|
const isPopupOpen = ref();
|
||||||
const hover = ref();
|
const hover = ref();
|
||||||
const inputRef = ref();
|
|
||||||
|
|
||||||
const styleAttrs = computed(() => {
|
const styleAttrs = computed(() => {
|
||||||
return props.isOutlined
|
return props.isOutlined
|
||||||
|
@ -50,7 +52,8 @@ const formattedTime = computed({
|
||||||
}
|
}
|
||||||
if (!props.timeOnly) {
|
if (!props.timeOnly) {
|
||||||
const [hh, mm] = time.split(':');
|
const [hh, mm] = time.split(':');
|
||||||
const date = new Date(model.value ? model.value : null);
|
|
||||||
|
const date = new Date(model.value ? model.value : initialDate.value);
|
||||||
date.setHours(hh, mm, 0);
|
date.setHours(hh, mm, 0);
|
||||||
time = date?.toISOString();
|
time = date?.toISOString();
|
||||||
}
|
}
|
||||||
|
@ -62,47 +65,22 @@ const formattedTime = computed({
|
||||||
function dateToTime(newDate) {
|
function dateToTime(newDate) {
|
||||||
return date.formatDate(new Date(newDate), dateFormat);
|
return date.formatDate(new Date(newDate), dateFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
|
||||||
() => model.value,
|
|
||||||
(val) => (formattedTime.value = val),
|
|
||||||
{ immediate: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => formattedTime.value,
|
|
||||||
async (val) => {
|
|
||||||
let position = 3;
|
|
||||||
const input = inputRef.value?.getNativeElement();
|
|
||||||
if (!val || !input) return;
|
|
||||||
|
|
||||||
let [hh, mm] = val.split(':');
|
|
||||||
hh = parseInt(hh);
|
|
||||||
if (hh >= 10 || mm != '00') return;
|
|
||||||
|
|
||||||
await nextTick();
|
|
||||||
await nextTick();
|
|
||||||
if (!hh) position = 0;
|
|
||||||
input.setSelectionRange(position, position);
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div @mouseover="hover = true" @mouseleave="hover = false">
|
<div @mouseover="hover = true" @mouseleave="hover = false">
|
||||||
<QInput
|
<QInput
|
||||||
ref="inputRef"
|
ref="vnInputTimeRef"
|
||||||
class="vn-input-time"
|
class="vn-input-time"
|
||||||
mask="##:##"
|
mask="##:##"
|
||||||
placeholder="--:--"
|
placeholder="--:--"
|
||||||
v-model="formattedTime"
|
v-model="formattedTime"
|
||||||
v-bind="{ ...$attrs, ...styleAttrs }"
|
v-bind="{ ...$attrs, ...styleAttrs }"
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: isRequired }"
|
||||||
style="min-width: 100px"
|
style="min-width: 100px"
|
||||||
:rules="$attrs.required ? [requiredFieldRule] : null"
|
:rules="mixinRules"
|
||||||
@click="isPopupOpen = false"
|
@click="isPopupOpen = !isPopupOpen"
|
||||||
@focus="inputRef.getNativeElement().setSelectionRange(0, 0)"
|
type="time"
|
||||||
|
hide-bottom-space
|
||||||
>
|
>
|
||||||
<template #append>
|
<template #append>
|
||||||
<QIcon
|
<QIcon
|
||||||
|
@ -115,18 +93,14 @@ watch(
|
||||||
!$attrs.disable
|
!$attrs.disable
|
||||||
"
|
"
|
||||||
@click="
|
@click="
|
||||||
|
vnInputTimeRef.focus();
|
||||||
model = null;
|
model = null;
|
||||||
isPopupOpen = false;
|
isPopupOpen = false;
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
<QIcon
|
|
||||||
name="Schedule"
|
|
||||||
class="cursor-pointer"
|
|
||||||
@click="isPopupOpen = !isPopupOpen"
|
|
||||||
:title="t('Open time')"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
<QMenu
|
<QMenu
|
||||||
|
v-if="$q.screen.gt.xs"
|
||||||
transition-show="scale"
|
transition-show="scale"
|
||||||
transition-hide="scale"
|
transition-hide="scale"
|
||||||
v-model="isPopupOpen"
|
v-model="isPopupOpen"
|
||||||
|
@ -135,8 +109,11 @@ watch(
|
||||||
:no-focus="true"
|
:no-focus="true"
|
||||||
:no-parent-event="true"
|
:no-parent-event="true"
|
||||||
>
|
>
|
||||||
<QTime v-model="formattedTime" mask="HH:mm" landscape now-btn />
|
<VnTime v-model="formattedTime" />
|
||||||
</QMenu>
|
</QMenu>
|
||||||
|
<QDialog v-else v-model="isPopupOpen">
|
||||||
|
<VnTime v-model="formattedTime" />
|
||||||
|
</QDialog>
|
||||||
</QInput>
|
</QInput>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -149,8 +126,12 @@ watch(
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
:deep(input[type='time']::-webkit-calendar-picker-indicator) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<i18n>
|
<i18n>
|
||||||
es:
|
es:
|
||||||
Open time: Abrir tiempo
|
Open time: Abrir tiempo
|
||||||
</i18n>
|
</i18n>
|
||||||
, nextTick
|
|
||||||
|
|
|
@ -1,122 +1,99 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, toRefs, computed, watch, onMounted } from 'vue';
|
|
||||||
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
|
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
|
||||||
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
||||||
import FetchData from 'components/FetchData.vue';
|
|
||||||
const emit = defineEmits(['update:modelValue', 'update:options']);
|
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
|
import { useAttrs } from 'vue';
|
||||||
|
import { useRequired } from 'src/composables/useRequired';
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const postcodesOptions = ref([]);
|
const emit = defineEmits(['update:model-value', 'update:options']);
|
||||||
const postcodesRef = ref(null);
|
const $attrs = useAttrs();
|
||||||
|
const { isRequired, requiredFieldRule } = useRequired($attrs);
|
||||||
const $props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {
|
location: {
|
||||||
type: [String, Number, Object],
|
type: Object,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
options: {
|
|
||||||
type: Array,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
optionLabel: {
|
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
optionValue: {
|
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
filterOptions: {
|
|
||||||
type: Array,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
isClearable: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
defaultFilter: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const { options } = toRefs($props);
|
watch(
|
||||||
const myOptions = ref([]);
|
() => props.location,
|
||||||
const myOptionsOriginal = ref([]);
|
(newValue) => {
|
||||||
|
if (!modelValue.value) return;
|
||||||
|
modelValue.value = formatLocation(newValue) ?? null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const value = computed({
|
const mixinRules = [requiredFieldRule];
|
||||||
get() {
|
const locationProperties = [
|
||||||
return $props.modelValue;
|
'postcode',
|
||||||
},
|
(obj) =>
|
||||||
set(value) {
|
obj.city
|
||||||
emit(
|
? `${obj.city}${obj.province?.name ? `(${obj.province.name})` : ''}`
|
||||||
'update:modelValue',
|
: null,
|
||||||
postcodesOptions.value.find((p) => p.code === value)
|
(obj) => obj.country?.name,
|
||||||
);
|
];
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
onMounted(() => {
|
const formatLocation = (obj, properties = locationProperties) => {
|
||||||
locationFilter($props.modelValue);
|
const parts = properties.map((prop) => {
|
||||||
});
|
if (typeof prop === 'string') {
|
||||||
|
return obj[prop];
|
||||||
|
} else if (typeof prop === 'function') {
|
||||||
|
return prop(obj);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
function setOptions(data) {
|
const filteredParts = parts.filter(
|
||||||
myOptions.value = JSON.parse(JSON.stringify(data));
|
(part) => part !== null && part !== undefined && part !== ''
|
||||||
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
);
|
||||||
}
|
|
||||||
setOptions(options.value);
|
|
||||||
|
|
||||||
watch(options, (newValue) => {
|
return filteredParts.join(', ');
|
||||||
setOptions(newValue);
|
};
|
||||||
});
|
|
||||||
|
const modelValue = ref(props.location ? formatLocation(props.location) : null);
|
||||||
|
|
||||||
function showLabel(data) {
|
function showLabel(data) {
|
||||||
return `${data.code} - ${data.town}(${data.province}), ${data.country}`;
|
const dataProperties = [
|
||||||
|
'code',
|
||||||
|
(obj) => (obj.town ? `${obj.town}(${obj.province})` : null),
|
||||||
|
'country',
|
||||||
|
];
|
||||||
|
return formatLocation(data, dataProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
function locationFilter(search = '') {
|
const handleModelValue = (data) => {
|
||||||
if (
|
emit('update:model-value', data);
|
||||||
search &&
|
};
|
||||||
(search.includes('undefined') || search.startsWith(`${$props.modelValue} - `))
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
let where = { search };
|
|
||||||
postcodesRef.value.fetch({ filter: { where }, limit: 30 });
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleFetch(data) {
|
|
||||||
postcodesOptions.value = data;
|
|
||||||
}
|
|
||||||
function onDataSaved(newPostcode) {
|
|
||||||
postcodesOptions.value.push(newPostcode);
|
|
||||||
value.value = newPostcode.code;
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
|
||||||
ref="postcodesRef"
|
|
||||||
url="Postcodes/filter"
|
|
||||||
@on-fetch="(data) => handleFetch(data)"
|
|
||||||
/>
|
|
||||||
<VnSelectDialog
|
<VnSelectDialog
|
||||||
v-if="postcodesRef"
|
v-model="modelValue"
|
||||||
:option-label="(opt) => showLabel(opt) ?? 'code'"
|
option-filter-value="search"
|
||||||
:option-value="(opt) => opt.code"
|
:option-label="
|
||||||
v-model="value"
|
(opt) => (typeof modelValue === 'string' ? modelValue : showLabel(opt))
|
||||||
:options="postcodesOptions"
|
"
|
||||||
|
url="Postcodes/filter"
|
||||||
|
@update:model-value="handleModelValue"
|
||||||
|
:use-like="false"
|
||||||
:label="t('Location')"
|
:label="t('Location')"
|
||||||
:placeholder="t('search_by_postalcode')"
|
:placeholder="t('search_by_postalcode')"
|
||||||
@input-value="locationFilter"
|
|
||||||
:default-filter="false"
|
|
||||||
:input-debounce="300"
|
:input-debounce="300"
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: isRequired }"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
clearable
|
:emit-value="false"
|
||||||
|
:tooltip="t('Create new location')"
|
||||||
|
:rules="mixinRules"
|
||||||
|
:lazy-rules="true"
|
||||||
>
|
>
|
||||||
<template #form>
|
<template #form>
|
||||||
<CreateNewPostcode
|
<CreateNewPostcode
|
||||||
@on-data-saved="onDataSaved"
|
@on-data-saved="
|
||||||
|
(newValue) => {
|
||||||
|
modelValue = newValue;
|
||||||
|
emit('update:model-value', newValue);
|
||||||
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #option="{ itemProps, opt }">
|
<template #option="{ itemProps, opt }">
|
||||||
|
@ -140,7 +117,9 @@ function onDataSaved(newPostcode) {
|
||||||
<i18n>
|
<i18n>
|
||||||
en:
|
en:
|
||||||
search_by_postalcode: Search by postalcode, town, province or country
|
search_by_postalcode: Search by postalcode, town, province or country
|
||||||
|
Create new location: Create new location
|
||||||
es:
|
es:
|
||||||
Location: Ubicación
|
Location: Ubicación
|
||||||
|
Create new location: Crear nueva ubicación
|
||||||
search_by_postalcode: Buscar por código postal, ciudad o país
|
search_by_postalcode: Buscar por código postal, ciudad o país
|
||||||
</i18n>
|
</i18n>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onUnmounted } from 'vue';
|
import { ref, onUnmounted, watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { date } from 'quasar';
|
import { date } from 'quasar';
|
||||||
import { useStateStore } from 'stores/useStateStore';
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
|
@ -14,11 +14,13 @@ import VnJsonValue from '../common/VnJsonValue.vue';
|
||||||
import FetchData from '../FetchData.vue';
|
import FetchData from '../FetchData.vue';
|
||||||
import VnSelect from './VnSelect.vue';
|
import VnSelect from './VnSelect.vue';
|
||||||
import VnUserLink from '../ui/VnUserLink.vue';
|
import VnUserLink from '../ui/VnUserLink.vue';
|
||||||
|
import VnPaginate from '../ui/VnPaginate.vue';
|
||||||
|
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
const validationsStore = useValidator();
|
const validationsStore = useValidator();
|
||||||
const { models } = validationsStore;
|
const { models } = validationsStore;
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const router = useRouter();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
model: {
|
model: {
|
||||||
|
@ -65,9 +67,10 @@ const filter = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
where: { and: [{ originFk: route.params.id }] },
|
||||||
};
|
};
|
||||||
|
|
||||||
const workers = ref();
|
const paginate = ref();
|
||||||
const actions = ref();
|
const actions = ref();
|
||||||
const changeInput = ref();
|
const changeInput = ref();
|
||||||
const searchInput = ref();
|
const searchInput = ref();
|
||||||
|
@ -213,7 +216,7 @@ function getLogTree(data) {
|
||||||
}
|
}
|
||||||
nLogs++;
|
nLogs++;
|
||||||
modelLog.logs.push(log);
|
modelLog.logs.push(log);
|
||||||
|
modelLog.summaryId = modelLog.logs[0].summaryId;
|
||||||
// Changes
|
// Changes
|
||||||
const notDelete = log.action != 'delete';
|
const notDelete = log.action != 'delete';
|
||||||
const olds = (notDelete ? log.oldInstance : null) || {};
|
const olds = (notDelete ? log.oldInstance : null) || {};
|
||||||
|
@ -234,9 +237,8 @@ async function openPointRecord(id, modelLog) {
|
||||||
const locale = validations[modelLog.model]?.locale || {};
|
const locale = validations[modelLog.model]?.locale || {};
|
||||||
pointRecord.value = parseProps(propNames, locale, data);
|
pointRecord.value = parseProps(propNames, locale, data);
|
||||||
}
|
}
|
||||||
async function setLogTree() {
|
async function setLogTree(data) {
|
||||||
filter.where = { and: [{ originFk: route.params.id }] };
|
if (!data) return;
|
||||||
const { data } = await getLogs(filter);
|
|
||||||
logTree.value = getLogTree(data);
|
logTree.value = getLogTree(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,15 +267,7 @@ async function applyFilter() {
|
||||||
filter.where.and.push(selectedFilters.value);
|
filter.where.and.push(selectedFilters.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = await getLogs(filter);
|
paginate.value.fetch(filter);
|
||||||
|
|
||||||
logTree.value = getLogTree(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getLogs(filter) {
|
|
||||||
return axios.get(props.url ?? `${props.model}Logs`, {
|
|
||||||
params: { filter: JSON.stringify(filter) },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDate(type) {
|
function setDate(type) {
|
||||||
|
@ -376,257 +370,313 @@ async function clearFilter() {
|
||||||
await applyFilter();
|
await applyFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
setLogTree();
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
stateStore.rightDrawer = false;
|
stateStore.rightDrawer = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => router.currentRoute.value.params.id,
|
||||||
|
() => {
|
||||||
|
applyFilter();
|
||||||
|
}
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
|
||||||
:url="`${props.model}Logs/${route.params.id}/editors`"
|
|
||||||
:filter="{
|
|
||||||
fields: ['id', 'nickname', 'name', 'image'],
|
|
||||||
order: 'nickname',
|
|
||||||
limit: 30,
|
|
||||||
}"
|
|
||||||
@on-fetch="(data) => (workers = data)"
|
|
||||||
auto-load
|
|
||||||
/>
|
|
||||||
<FetchData
|
<FetchData
|
||||||
:url="`${props.model}Logs/${route.params.id}/models`"
|
:url="`${props.model}Logs/${route.params.id}/models`"
|
||||||
:filter="{ order: ['changedModel'] }"
|
:filter="{ order: ['changedModel'] }"
|
||||||
@on-fetch="
|
@on-fetch="
|
||||||
(data) =>
|
(data) =>
|
||||||
(actions = data.map((item) => {
|
(actions = data.map((item) => {
|
||||||
|
const changedModel = item.changedModel;
|
||||||
return {
|
return {
|
||||||
locale: useCapitalize(validations[item.changedModel].locale.name),
|
locale: useCapitalize(
|
||||||
value: item.changedModel,
|
validations[changedModel]?.locale?.name ?? changedModel
|
||||||
|
),
|
||||||
|
value: changedModel,
|
||||||
};
|
};
|
||||||
}))
|
}))
|
||||||
"
|
"
|
||||||
auto-load
|
auto-load
|
||||||
/>
|
/>
|
||||||
<div
|
<VnPaginate
|
||||||
class="column items-center logs origin-log q-mt-md"
|
ref="paginate"
|
||||||
v-for="(originLog, originLogIndex) in logTree"
|
:data-key="`${model}Log`"
|
||||||
:key="originLogIndex"
|
:url="`${model}Logs`"
|
||||||
|
:filter="filter"
|
||||||
|
:skeleton="false"
|
||||||
|
auto-load
|
||||||
|
@on-fetch="setLogTree"
|
||||||
|
search-url="logs"
|
||||||
>
|
>
|
||||||
<QItem class="origin-info items-center q-my-md" v-if="logTree.length > 1">
|
<template #body>
|
||||||
<h6 class="origin-id text-grey">
|
<div
|
||||||
{{ useCapitalize(validations[props.model].locale.name) }}
|
class="column items-center logs origin-log q-mt-md"
|
||||||
#{{ originLog.originFk }}
|
v-for="(originLog, originLogIndex) in logTree"
|
||||||
</h6>
|
:key="originLogIndex"
|
||||||
<div class="line bg-grey"></div>
|
>
|
||||||
</QItem>
|
<QItem class="origin-info items-center q-my-md" v-if="logTree.length > 1">
|
||||||
<div
|
<h6 class="origin-id text-grey">
|
||||||
class="user-log q-mb-sm"
|
{{ useCapitalize(validations[props.model].locale.name) }}
|
||||||
v-for="(userLog, userIndex) in originLog.logs"
|
#{{ originLog.originFk }}
|
||||||
:key="userIndex"
|
</h6>
|
||||||
>
|
<div class="line bg-grey"></div>
|
||||||
<div class="timeline">
|
</QItem>
|
||||||
<div class="user-avatar">
|
<div
|
||||||
<VnUserLink :worker-id="userLog?.user?.id">
|
class="user-log q-mb-sm"
|
||||||
<template #link>
|
v-for="(userLog, userIndex) in originLog.logs"
|
||||||
<VnAvatar
|
:key="userIndex"
|
||||||
:class="{ 'cursor-pointer': userLog?.user?.id }"
|
|
||||||
:worker-id="userLog?.user?.id"
|
|
||||||
:title="userLog?.user?.nickname"
|
|
||||||
:show-letter="!userLog?.user"
|
|
||||||
size="lg"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</VnUserLink>
|
|
||||||
</div>
|
|
||||||
<div class="arrow bg-panel" v-if="byRecord"></div>
|
|
||||||
<div class="line"></div>
|
|
||||||
</div>
|
|
||||||
<QList class="user-changes" v-if="userLog">
|
|
||||||
<QItem
|
|
||||||
class="model-log column q-px-none q-py-xs"
|
|
||||||
v-for="(modelLog, modelLogIndex) in userLog.logs"
|
|
||||||
:key="modelLogIndex"
|
|
||||||
>
|
>
|
||||||
<QItemSection>
|
<div class="timeline">
|
||||||
<QItemLabel class="model-info q-mb-xs" v-if="!byRecord">
|
<div class="user-avatar">
|
||||||
<QChip
|
<VnUserLink :worker-id="userLog?.user?.id">
|
||||||
dense
|
<template #link>
|
||||||
size="md"
|
<VnAvatar
|
||||||
class="model-name q-mr-xs text-white"
|
:class="{ 'cursor-pointer': userLog?.user?.id }"
|
||||||
v-if="
|
:worker-id="userLog?.user?.id"
|
||||||
!(modelLog.changedModel && modelLog.changedModelId) &&
|
:title="userLog?.user?.nickname"
|
||||||
modelLog.model
|
:show-letter="!userLog?.user"
|
||||||
"
|
size="lg"
|
||||||
:style="{
|
/>
|
||||||
backgroundColor: useColor(modelLog.model),
|
</template>
|
||||||
}"
|
</VnUserLink>
|
||||||
:title="`${modelLog.model} #${modelLog.id}`"
|
</div>
|
||||||
>
|
<div class="arrow bg-panel" v-if="byRecord"></div>
|
||||||
{{ t(modelLog.modelI18n) }}
|
<div class="line"></div>
|
||||||
</QChip>
|
</div>
|
||||||
<span class="model-id" v-if="modelLog.summaryId"
|
<QList class="user-changes" v-if="userLog">
|
||||||
>#{{ modelLog.summaryId }}</span
|
<QItem
|
||||||
>
|
class="model-log column q-px-none q-py-xs"
|
||||||
<span class="model-value" :title="modelLog.showValue">
|
v-for="(modelLog, modelLogIndex) in userLog.logs"
|
||||||
{{ modelLog.showValue }}
|
:key="modelLogIndex"
|
||||||
</span>
|
|
||||||
<QBtn
|
|
||||||
flat
|
|
||||||
round
|
|
||||||
color="grey"
|
|
||||||
class="q-mr-xs q-ml-auto"
|
|
||||||
size="sm"
|
|
||||||
icon="filter_alt"
|
|
||||||
:title="t('recordChanges')"
|
|
||||||
@click.stop="filterByRecord(modelLog)"
|
|
||||||
/>
|
|
||||||
</QItemLabel>
|
|
||||||
</QItemSection>
|
|
||||||
<QItemSection>
|
|
||||||
<QCard
|
|
||||||
class="changes-log q-py-none q-mb-xs"
|
|
||||||
v-for="(log, logIndex) in modelLog.logs"
|
|
||||||
:key="logIndex"
|
|
||||||
>
|
>
|
||||||
<QCardSection class="change-info q-pa-none">
|
<QItemSection>
|
||||||
<QItem
|
<QItemLabel class="model-info q-mb-xs" v-if="!byRecord">
|
||||||
class="q-px-sm q-py-xs justify-between items-center"
|
<QChip
|
||||||
>
|
dense
|
||||||
<div
|
size="md"
|
||||||
class="date text-grey text-caption q-mr-sm"
|
class="model-name q-mr-xs text-white"
|
||||||
:title="
|
v-if="
|
||||||
date.formatDate(
|
!(
|
||||||
log.creationDate,
|
modelLog.changedModel &&
|
||||||
'DD/MM/YYYY hh:mm:ss'
|
modelLog.changedModelId
|
||||||
) ?? `date:'dd/MM/yyyy HH:mm:ss'`
|
) && modelLog.model
|
||||||
"
|
"
|
||||||
|
:style="{
|
||||||
|
backgroundColor: useColor(modelLog.model),
|
||||||
|
}"
|
||||||
|
:title="`${modelLog.model} #${modelLog.id}`"
|
||||||
>
|
>
|
||||||
{{ toRelativeDate(log.creationDate) }}
|
{{ t(modelLog.modelI18n) }}
|
||||||
</div>
|
</QChip>
|
||||||
<div>
|
|
||||||
<QBtn
|
|
||||||
color="grey"
|
|
||||||
class="pit"
|
|
||||||
icon="preview"
|
|
||||||
flat
|
|
||||||
round
|
|
||||||
:title="t('pointRecord')"
|
|
||||||
padding="none"
|
|
||||||
v-if="log.action != 'insert'"
|
|
||||||
@click.stop="
|
|
||||||
openPointRecord(log.id, modelLog)
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<QPopupProxy>
|
|
||||||
<QCard v-if="pointRecord">
|
|
||||||
<div
|
|
||||||
class="header q-px-sm q-py-xs q-ma-none text-white text-bold bg-primary"
|
|
||||||
>
|
|
||||||
{{ modelLog.modelI18n }}
|
|
||||||
<span v-if="modelLog.id"
|
|
||||||
>#{{ modelLog.id }}</span
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<QCardSection
|
|
||||||
class="change-detail q-pa-sm"
|
|
||||||
>
|
|
||||||
<QItem
|
|
||||||
v-for="(
|
|
||||||
value, index
|
|
||||||
) in pointRecord"
|
|
||||||
:key="index"
|
|
||||||
class="q-pa-none"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="json-field q-mr-xs text-grey"
|
|
||||||
:title="value.name"
|
|
||||||
>
|
|
||||||
{{ value.nameI18n }}:
|
|
||||||
</span>
|
|
||||||
<VnJsonValue
|
|
||||||
:value="value.val.val"
|
|
||||||
/>
|
|
||||||
</QItem>
|
|
||||||
</QCardSection>
|
|
||||||
</QCard>
|
|
||||||
</QPopupProxy>
|
|
||||||
</QBtn>
|
|
||||||
<QIcon
|
|
||||||
class="action q-ml-xs"
|
|
||||||
:class="actionsClass[log.action]"
|
|
||||||
:name="actionsIcon[log.action]"
|
|
||||||
:title="
|
|
||||||
t(`actions.${actionsText[log.action]}`)
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</QItem>
|
|
||||||
</QCardSection>
|
|
||||||
<QCardSection
|
|
||||||
class="change-detail q-px-sm q-py-xs"
|
|
||||||
:class="{ expanded: log.expand }"
|
|
||||||
v-if="log.props.length || log.description"
|
|
||||||
>
|
|
||||||
<QIcon
|
|
||||||
class="cursor-pointer q-mr-md"
|
|
||||||
color="grey"
|
|
||||||
name="expand_more"
|
|
||||||
:title="t('globals.details')"
|
|
||||||
size="sm"
|
|
||||||
@click="log.expand = !log.expand"
|
|
||||||
/>
|
|
||||||
<span v-if="log.props.length" class="attributes">
|
|
||||||
<span v-if="!log.expand" class="q-pa-none text-grey">
|
|
||||||
<span
|
|
||||||
v-for="(prop, propIndex) in log.props"
|
|
||||||
:key="propIndex"
|
|
||||||
class="basic-json"
|
|
||||||
>
|
|
||||||
<span class="json-field" :title="prop.name">
|
|
||||||
{{ prop.nameI18n }}:
|
|
||||||
</span>
|
|
||||||
<VnJsonValue :value="prop.val.val" />
|
|
||||||
<span v-if="propIndex < log.props.length - 1"
|
|
||||||
>,
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
<span
|
<span
|
||||||
v-if="log.expand"
|
class="model-id q-mr-xs"
|
||||||
class="expanded-json column q-pa-none"
|
v-if="modelLog.summaryId"
|
||||||
>
|
v-text="`#${modelLog.summaryId}`"
|
||||||
<div
|
/>
|
||||||
v-for="(prop, prop2Index) in log.props"
|
<span
|
||||||
:key="prop2Index"
|
class="model-value"
|
||||||
class="q-pa-none text-grey"
|
:title="modelLog.showValue"
|
||||||
|
v-text="modelLog.showValue"
|
||||||
|
/>
|
||||||
|
<QBtn
|
||||||
|
flat
|
||||||
|
round
|
||||||
|
color="grey"
|
||||||
|
class="q-mr-xs q-ml-auto"
|
||||||
|
size="sm"
|
||||||
|
icon="filter_alt"
|
||||||
|
:title="t('recordChanges')"
|
||||||
|
@click.stop="filterByRecord(modelLog)"
|
||||||
|
/>
|
||||||
|
</QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
<QItemSection>
|
||||||
|
<QCard
|
||||||
|
class="changes-log q-py-none q-mb-xs"
|
||||||
|
v-for="(log, logIndex) in modelLog.logs"
|
||||||
|
:key="logIndex"
|
||||||
|
>
|
||||||
|
<QCardSection class="change-info q-pa-none">
|
||||||
|
<QItem
|
||||||
|
class="q-px-sm q-py-xs justify-between items-center"
|
||||||
>
|
>
|
||||||
<span class="json-field" :title="prop.name">
|
<div
|
||||||
{{ prop.nameI18n }}:
|
class="date text-grey text-caption q-mr-sm"
|
||||||
</span>
|
:title="
|
||||||
<VnJsonValue :value="prop.val.val" />
|
date.formatDate(
|
||||||
<span v-if="prop.val.id" class="id-value">
|
log.creationDate,
|
||||||
#{{ prop.val.id }}
|
'DD/MM/YYYY hh:mm:ss'
|
||||||
</span>
|
) ?? `date:'dd/MM/yyyy HH:mm:ss'`
|
||||||
<span v-if="log.action == 'update'">
|
"
|
||||||
←
|
>
|
||||||
<VnJsonValue :value="prop.old.val" />
|
{{ toRelativeDate(log.creationDate) }}
|
||||||
<span v-if="prop.old.id" class="id-value">
|
</div>
|
||||||
#{{ prop.old.id }}
|
<div>
|
||||||
|
<QBtn
|
||||||
|
color="grey"
|
||||||
|
class="pit"
|
||||||
|
icon="preview"
|
||||||
|
flat
|
||||||
|
round
|
||||||
|
:title="t('pointRecord')"
|
||||||
|
padding="none"
|
||||||
|
v-if="log.action != 'insert'"
|
||||||
|
@click.stop="
|
||||||
|
openPointRecord(log.id, modelLog)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<QPopupProxy>
|
||||||
|
<QCard v-if="pointRecord">
|
||||||
|
<div
|
||||||
|
class="header q-px-sm q-py-xs q-ma-none text-white text-bold bg-primary"
|
||||||
|
>
|
||||||
|
{{ modelLog.modelI18n }}
|
||||||
|
<span v-if="modelLog.id"
|
||||||
|
>#{{
|
||||||
|
modelLog.id
|
||||||
|
}}</span
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<QCardSection
|
||||||
|
class="change-detail q-pa-sm"
|
||||||
|
>
|
||||||
|
<QItem
|
||||||
|
v-for="(
|
||||||
|
value, index
|
||||||
|
) in pointRecord"
|
||||||
|
:key="index"
|
||||||
|
class="q-pa-none"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="json-field q-mr-xs text-grey"
|
||||||
|
:title="
|
||||||
|
value.name
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
value.nameI18n
|
||||||
|
}}:
|
||||||
|
</span>
|
||||||
|
<VnJsonValue
|
||||||
|
:value="
|
||||||
|
value.val.val
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</QItem>
|
||||||
|
</QCardSection>
|
||||||
|
</QCard>
|
||||||
|
</QPopupProxy>
|
||||||
|
</QBtn>
|
||||||
|
<QIcon
|
||||||
|
class="action q-ml-xs"
|
||||||
|
:class="actionsClass[log.action]"
|
||||||
|
:name="actionsIcon[log.action]"
|
||||||
|
:title="
|
||||||
|
t(
|
||||||
|
`actions.${
|
||||||
|
actionsText[log.action]
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</QItem>
|
||||||
|
</QCardSection>
|
||||||
|
<QCardSection
|
||||||
|
class="change-detail q-px-sm q-py-xs"
|
||||||
|
:class="{ expanded: log.expand }"
|
||||||
|
v-if="log.props.length || log.description"
|
||||||
|
>
|
||||||
|
<QIcon
|
||||||
|
class="cursor-pointer q-mr-md"
|
||||||
|
color="grey"
|
||||||
|
name="expand_more"
|
||||||
|
:title="t('globals.details')"
|
||||||
|
size="sm"
|
||||||
|
@click="log.expand = !log.expand"
|
||||||
|
/>
|
||||||
|
<span v-if="log.props.length" class="attributes">
|
||||||
|
<span
|
||||||
|
v-if="!log.expand"
|
||||||
|
class="q-pa-none text-grey"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
v-for="(prop, propIndex) in log.props"
|
||||||
|
:key="propIndex"
|
||||||
|
class="basic-json"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="json-field"
|
||||||
|
:title="prop.name"
|
||||||
|
>
|
||||||
|
{{ prop.nameI18n }}:
|
||||||
|
</span>
|
||||||
|
<VnJsonValue :value="prop.val.val" />
|
||||||
|
<span
|
||||||
|
v-if="
|
||||||
|
propIndex <
|
||||||
|
log.props.length - 1
|
||||||
|
"
|
||||||
|
>,
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
<span
|
||||||
</span>
|
v-if="log.expand"
|
||||||
</span>
|
class="expanded-json column q-pa-none"
|
||||||
<span v-if="!log.props.length" class="description">
|
>
|
||||||
{{ log.description }}
|
<div
|
||||||
</span>
|
v-for="(
|
||||||
</QCardSection>
|
prop, prop2Index
|
||||||
</QCard>
|
) in log.props"
|
||||||
</QItemSection>
|
:key="prop2Index"
|
||||||
</QItem>
|
class="q-pa-none text-grey"
|
||||||
</QList>
|
>
|
||||||
</div>
|
<span
|
||||||
</div>
|
class="json-field"
|
||||||
|
:title="prop.name"
|
||||||
|
>
|
||||||
|
{{ prop.nameI18n }}:
|
||||||
|
</span>
|
||||||
|
<VnJsonValue :value="prop.val.val" />
|
||||||
|
<span
|
||||||
|
v-if="prop.val.id"
|
||||||
|
class="id-value"
|
||||||
|
>
|
||||||
|
#{{ prop.val.id }}
|
||||||
|
</span>
|
||||||
|
<span v-if="log.action == 'update'">
|
||||||
|
←
|
||||||
|
<VnJsonValue
|
||||||
|
:value="prop.old.val"
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
v-if="prop.old.id"
|
||||||
|
class="id-value"
|
||||||
|
>
|
||||||
|
#{{ prop.old.id }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="!log.props.length"
|
||||||
|
class="description"
|
||||||
|
>
|
||||||
|
{{ log.description }}
|
||||||
|
</span>
|
||||||
|
</QCardSection>
|
||||||
|
</QCard>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
|
</QList>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</VnPaginate>
|
||||||
<Teleport to="#right-panel" v-if="stateStore.isHeaderMounted()">
|
<Teleport to="#right-panel" v-if="stateStore.isHeaderMounted()">
|
||||||
<QList dense>
|
<QList dense>
|
||||||
<QSeparator />
|
<QSeparator />
|
||||||
|
@ -675,17 +725,16 @@ onUnmounted(() => {
|
||||||
</QOptionGroup>
|
</QOptionGroup>
|
||||||
</QItem>
|
</QItem>
|
||||||
<QItem class="q-mt-sm">
|
<QItem class="q-mt-sm">
|
||||||
<QItemSection v-if="!workers">
|
<QItemSection v-if="userRadio !== null">
|
||||||
<QSkeleton type="QInput" class="full-width" />
|
|
||||||
</QItemSection>
|
|
||||||
<QItemSection v-if="workers && userRadio !== null">
|
|
||||||
<VnSelect
|
<VnSelect
|
||||||
class="full-width"
|
class="full-width"
|
||||||
:label="t('globals.user')"
|
:label="t('globals.user')"
|
||||||
v-model="userSelect"
|
v-model="userSelect"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
:options="workers"
|
:url="`${model}Logs/${$route.params.id}/editors`"
|
||||||
|
:fields="['id', 'nickname', 'name', 'image']"
|
||||||
|
sort-by="nickname"
|
||||||
@update:model-value="selectFilter('userSelect')"
|
@update:model-value="selectFilter('userSelect')"
|
||||||
hide-selected
|
hide-selected
|
||||||
>
|
>
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<script setup>
|
||||||
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
|
import { onMounted, ref } from 'vue';
|
||||||
|
import { useQuasar } from 'quasar';
|
||||||
|
import LeftMenu from '../LeftMenu.vue';
|
||||||
|
|
||||||
|
const stateStore = useStateStore();
|
||||||
|
const $props = defineProps({
|
||||||
|
leftDrawer: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
onMounted(
|
||||||
|
() => (stateStore.leftDrawer = useQuasar().screen.gt.xs ? $props.leftDrawer : false)
|
||||||
|
);
|
||||||
|
|
||||||
|
const teleportRef = ref({});
|
||||||
|
const hasContent = ref();
|
||||||
|
let observer;
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (!teleportRef.value) return;
|
||||||
|
const checkContent = () => {
|
||||||
|
hasContent.value = teleportRef.value?.innerHTML?.trim() !== '';
|
||||||
|
};
|
||||||
|
|
||||||
|
observer = new MutationObserver(checkContent);
|
||||||
|
observer.observe(teleportRef.value, { childList: true, subtree: true });
|
||||||
|
|
||||||
|
checkContent();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<QDrawer v-model="stateStore.leftDrawer" show-if-above :width="256">
|
||||||
|
<QScrollArea class="fit text-grey-8">
|
||||||
|
<div id="left-panel" ref="teleportRef"></div>
|
||||||
|
<LeftMenu v-if="!hasContent" />
|
||||||
|
</QScrollArea>
|
||||||
|
</QDrawer>
|
||||||
|
<QPageContainer>
|
||||||
|
<QPage>
|
||||||
|
<RouterView />
|
||||||
|
</QPage>
|
||||||
|
</QPageContainer>
|
||||||
|
</template>
|
|
@ -9,10 +9,6 @@ const $props = defineProps({
|
||||||
type: Number, //Progress value (1.0 > x > 0.0)
|
type: Number, //Progress value (1.0 > x > 0.0)
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
showDialog: {
|
|
||||||
type: Boolean,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
cancelled: {
|
cancelled: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: false,
|
required: false,
|
||||||
|
@ -24,30 +20,22 @@ const emit = defineEmits(['cancel', 'close']);
|
||||||
|
|
||||||
const dialogRef = ref(null);
|
const dialogRef = ref(null);
|
||||||
|
|
||||||
const _showDialog = computed({
|
const showDialog = defineModel('showDialog', {
|
||||||
get: () => $props.showDialog,
|
type: Boolean,
|
||||||
set: (value) => {
|
default: false,
|
||||||
if (value) dialogRef.value.show();
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const _progress = computed(() => $props.progress);
|
const _progress = computed(() => $props.progress);
|
||||||
|
|
||||||
const progressLabel = computed(() => `${Math.round($props.progress * 100)}%`);
|
const progressLabel = computed(() => `${Math.round($props.progress * 100)}%`);
|
||||||
|
|
||||||
const cancel = () => {
|
|
||||||
dialogRef.value.hide();
|
|
||||||
emit('cancel');
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<QDialog ref="dialogRef" v-model="_showDialog" @hide="onDialogHide">
|
<QDialog ref="dialogRef" v-model="showDialog" @hide="emit('close')">
|
||||||
<QCard class="full-width dialog">
|
<QCard class="full-width dialog">
|
||||||
<QCardSection class="row">
|
<QCardSection class="row">
|
||||||
<span class="text-h6">{{ t('Progress') }}</span>
|
<span class="text-h6">{{ t('Progress') }}</span>
|
||||||
<QSpace />
|
<QSpace />
|
||||||
<QBtn icon="close" flat round dense @click="emit('close')" />
|
<QBtn icon="close" flat round dense v-close-popup />
|
||||||
</QCardSection>
|
</QCardSection>
|
||||||
<QCardSection>
|
<QCardSection>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
|
@ -80,7 +68,7 @@ const cancel = () => {
|
||||||
type="button"
|
type="button"
|
||||||
flat
|
flat
|
||||||
class="text-primary"
|
class="text-primary"
|
||||||
@click="cancel()"
|
v-close-popup
|
||||||
>
|
>
|
||||||
{{ t('globals.cancel') }}
|
{{ t('globals.cancel') }}
|
||||||
</QBtn>
|
</QBtn>
|
||||||
|
|
|
@ -2,5 +2,12 @@
|
||||||
const model = defineModel({ type: Boolean, required: true });
|
const model = defineModel({ type: Boolean, required: true });
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<QRadio v-model="model" v-bind="$attrs" dense :dark="true" class="q-mr-sm" />
|
<QRadio
|
||||||
|
v-model="model"
|
||||||
|
v-bind="$attrs"
|
||||||
|
dense
|
||||||
|
:dark="true"
|
||||||
|
class="q-mr-sm"
|
||||||
|
size="xs"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
<script setup>
|
||||||
|
import RightMenu from './RightMenu.vue';
|
||||||
|
import VnSearchbar from 'components/ui/VnSearchbar.vue';
|
||||||
|
import VnTableFilter from '../VnTable/VnTableFilter.vue';
|
||||||
|
import { onBeforeMount, computed, ref } from 'vue';
|
||||||
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
|
import { useHasContent } from 'src/composables/useHasContent';
|
||||||
|
|
||||||
|
const $props = defineProps({
|
||||||
|
section: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
dataKey: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
searchBar: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
prefix: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
rightFilter: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
columns: {
|
||||||
|
type: Array,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
arrayDataProps: {
|
||||||
|
type: Object,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
redirect: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
keepData: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
let arrayData;
|
||||||
|
const sectionValue = computed(() => $props.section ?? $props.dataKey);
|
||||||
|
const isMainSection = computed(() => {
|
||||||
|
const isSame = sectionValue.value == route.name;
|
||||||
|
if (!isSame && arrayData) {
|
||||||
|
arrayData.reset(['userParams', 'userFilter']);
|
||||||
|
}
|
||||||
|
return isSame;
|
||||||
|
});
|
||||||
|
const searchbarId = 'section-searchbar';
|
||||||
|
const hasContent = useHasContent(`#${searchbarId}`);
|
||||||
|
|
||||||
|
onBeforeMount(() => {
|
||||||
|
if ($props.dataKey)
|
||||||
|
arrayData = useArrayData($props.dataKey, {
|
||||||
|
searchUrl: 'table',
|
||||||
|
keepData: $props.keepData,
|
||||||
|
...$props.arrayDataProps,
|
||||||
|
navigate: $props.redirect,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<slot name="searchbar">
|
||||||
|
<VnSearchbar
|
||||||
|
v-if="searchBar && !hasContent"
|
||||||
|
v-bind="arrayDataProps"
|
||||||
|
:data-key="dataKey"
|
||||||
|
:label="$t(`${prefix}.search`)"
|
||||||
|
:info="$t(`${prefix}.searchInfo`)"
|
||||||
|
/>
|
||||||
|
<div :id="searchbarId"></div>
|
||||||
|
</slot>
|
||||||
|
<RightMenu>
|
||||||
|
<template #right-panel v-if="$slots['rightMenu'] || rightFilter">
|
||||||
|
<slot name="rightMenu">
|
||||||
|
<VnTableFilter
|
||||||
|
v-if="rightFilter && columns"
|
||||||
|
:data-key="dataKey"
|
||||||
|
:array-data="arrayData"
|
||||||
|
:columns="columns"
|
||||||
|
/>
|
||||||
|
</slot>
|
||||||
|
</template>
|
||||||
|
</RightMenu>
|
||||||
|
<slot name="body" v-if="isMainSection" />
|
||||||
|
<RouterView v-else />
|
||||||
|
</template>
|
|
@ -1,8 +1,21 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, toRefs, computed, watch, onMounted } from 'vue';
|
import { ref, toRefs, computed, watch, onMounted, useAttrs } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import FetchData from 'src/components/FetchData.vue';
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
const emit = defineEmits(['update:modelValue', 'update:options']);
|
import { useRequired } from 'src/composables/useRequired';
|
||||||
|
import dataByOrder from 'src/utils/dataByOrder';
|
||||||
|
import { QItemLabel } from 'quasar';
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:modelValue', 'update:options', 'remove']);
|
||||||
|
const $attrs = useAttrs();
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
const isRequired = computed(() => {
|
||||||
|
return useRequired($attrs).isRequired;
|
||||||
|
});
|
||||||
|
const requiredFieldRule = computed(() => {
|
||||||
|
return useRequired($attrs).requiredFieldRule;
|
||||||
|
});
|
||||||
|
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
|
@ -21,18 +34,30 @@ const $props = defineProps({
|
||||||
type: String,
|
type: String,
|
||||||
default: 'id',
|
default: 'id',
|
||||||
},
|
},
|
||||||
|
optionCaption: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
optionFilter: {
|
optionFilter: {
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
|
optionFilterValue: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
url: {
|
url: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: null,
|
||||||
},
|
},
|
||||||
filterOptions: {
|
filterOptions: {
|
||||||
type: [Array],
|
type: [Array],
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
|
exprBuilder: {
|
||||||
|
type: Function,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
isClearable: {
|
isClearable: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
|
@ -45,6 +70,10 @@ const $props = defineProps({
|
||||||
type: Array,
|
type: Array,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
|
include: {
|
||||||
|
type: [Object, Array],
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
where: {
|
where: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: null,
|
default: null,
|
||||||
|
@ -65,23 +94,60 @@ const $props = defineProps({
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
params: {
|
||||||
|
type: Object,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
noOne: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
dataKey: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
isOutlined: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
|
||||||
const requiredFieldRule = (val) => val ?? t('globals.fieldRequired');
|
const {
|
||||||
|
optionLabel,
|
||||||
const { optionLabel, optionValue, optionFilter, options, modelValue } = toRefs($props);
|
optionValue,
|
||||||
|
optionCaption,
|
||||||
|
optionFilter,
|
||||||
|
optionFilterValue,
|
||||||
|
options,
|
||||||
|
modelValue,
|
||||||
|
} = toRefs($props);
|
||||||
const myOptions = ref([]);
|
const myOptions = ref([]);
|
||||||
const myOptionsOriginal = ref([]);
|
const myOptionsOriginal = ref([]);
|
||||||
const vnSelectRef = ref();
|
const vnSelectRef = ref();
|
||||||
const dataRef = ref();
|
|
||||||
const lastVal = ref();
|
const lastVal = ref();
|
||||||
|
const noOneText = t('globals.noOne');
|
||||||
|
const noOneOpt = ref({
|
||||||
|
[optionValue.value]: false,
|
||||||
|
[optionLabel.value]: noOneText,
|
||||||
|
});
|
||||||
|
const styleAttrs = computed(() => {
|
||||||
|
return $props.isOutlined
|
||||||
|
? {
|
||||||
|
dense: true,
|
||||||
|
outlined: true,
|
||||||
|
rounded: true,
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
});
|
||||||
|
const isLoading = ref(false);
|
||||||
|
const useURL = computed(() => $props.url);
|
||||||
const value = computed({
|
const value = computed({
|
||||||
get() {
|
get() {
|
||||||
return $props.modelValue;
|
return $props.modelValue;
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
|
setOptions(myOptionsOriginal.value);
|
||||||
emit('update:modelValue', value);
|
emit('update:modelValue', value);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -90,30 +156,43 @@ watch(options, (newValue) => {
|
||||||
setOptions(newValue);
|
setOptions(newValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(modelValue, (newValue) => {
|
watch(modelValue, async (newValue) => {
|
||||||
if (!myOptions.value.some((option) => option[optionValue.value] == newValue))
|
if (!myOptions?.value?.some((option) => option[optionValue.value] == newValue))
|
||||||
fetchFilter(newValue);
|
await fetchFilter(newValue);
|
||||||
|
|
||||||
|
if ($props.noOne) myOptions.value.unshift(noOneOpt.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
setOptions(options.value);
|
setOptions(options.value);
|
||||||
if ($props.url && $props.modelValue && !findKeyInOptions())
|
if (useURL.value && $props.modelValue && !findKeyInOptions())
|
||||||
fetchFilter($props.modelValue);
|
fetchFilter($props.modelValue);
|
||||||
if ($props.focusOnMount) setTimeout(() => vnSelectRef.value.showPopup(), 300);
|
if ($props.focusOnMount) setTimeout(() => vnSelectRef.value.showPopup(), 300);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const arrayDataKey =
|
||||||
|
$props.dataKey ?? ($props.url?.length > 0 ? $props.url : $attrs.name ?? $attrs.label);
|
||||||
|
|
||||||
|
const arrayData = useArrayData(arrayDataKey, {
|
||||||
|
url: $props.url,
|
||||||
|
searchUrl: false,
|
||||||
|
mapKey: $attrs['map-key'],
|
||||||
|
});
|
||||||
|
|
||||||
function findKeyInOptions() {
|
function findKeyInOptions() {
|
||||||
if (!$props.options) return;
|
if (!$props.options) return;
|
||||||
return filter($props.modelValue, $props.options)?.length;
|
return filter($props.modelValue, $props.options)?.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setOptions(data) {
|
function setOptions(data) {
|
||||||
|
data = dataByOrder(data, $props.sortBy);
|
||||||
myOptions.value = JSON.parse(JSON.stringify(data));
|
myOptions.value = JSON.parse(JSON.stringify(data));
|
||||||
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
||||||
|
emit('update:options', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function filter(val, options) {
|
function filter(val, options) {
|
||||||
const search = val.toString().toLowerCase();
|
const search = val?.toString()?.toLowerCase();
|
||||||
|
|
||||||
if (!search) return options;
|
if (!search) return options;
|
||||||
|
|
||||||
|
@ -125,28 +204,42 @@ function filter(val, options) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = row.id;
|
if (!row) return;
|
||||||
|
const id = String(row[$props.optionValue]);
|
||||||
const optionLabel = String(row[$props.optionLabel]).toLowerCase();
|
const optionLabel = String(row[$props.optionLabel]).toLowerCase();
|
||||||
|
|
||||||
return id == search || optionLabel.includes(search);
|
return id.includes(search) || optionLabel.includes(search);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchFilter(val) {
|
async function fetchFilter(val) {
|
||||||
if (!$props.url || !dataRef.value) return;
|
if (!$props.url) return;
|
||||||
|
|
||||||
const { fields, sortBy, limit } = $props;
|
const { fields, include, sortBy, limit } = $props;
|
||||||
let key = optionFilter.value ?? optionLabel.value;
|
const key =
|
||||||
|
optionFilterValue.value ??
|
||||||
|
(new RegExp(/\d/g).test(val)
|
||||||
|
? optionValue.value
|
||||||
|
: optionFilter.value ?? optionLabel.value);
|
||||||
|
|
||||||
if (new RegExp(/\d/g).test(val)) key = optionValue.value;
|
let defaultWhere = {};
|
||||||
|
if ($props.filterOptions.length) {
|
||||||
const defaultWhere = $props.useLike
|
defaultWhere = $props.filterOptions.reduce((obj, prop) => {
|
||||||
? { [key]: { like: `%${val}%` } }
|
if (!obj.or) obj.or = [];
|
||||||
: { [key]: val };
|
obj.or.push({ [prop]: getVal(val) });
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
} else defaultWhere = { [key]: getVal(val) };
|
||||||
const where = { ...(val ? defaultWhere : {}), ...$props.where };
|
const where = { ...(val ? defaultWhere : {}), ...$props.where };
|
||||||
const fetchOptions = { where, order: sortBy, limit };
|
$props.exprBuilder && Object.assign(where, $props.exprBuilder(key, val));
|
||||||
|
const fetchOptions = { where, include, limit };
|
||||||
if (fields) fetchOptions.fields = fields;
|
if (fields) fetchOptions.fields = fields;
|
||||||
return dataRef.value.fetch(fetchOptions);
|
if (sortBy) fetchOptions.order = sortBy;
|
||||||
|
arrayData.resetPagination();
|
||||||
|
|
||||||
|
const { data } = await arrayData.applyFilter({ filter: fetchOptions });
|
||||||
|
setOptions(data);
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function filterHandler(val, update) {
|
async function filterHandler(val, update) {
|
||||||
|
@ -158,11 +251,17 @@ async function filterHandler(val, update) {
|
||||||
let newOptions;
|
let newOptions;
|
||||||
|
|
||||||
if (!$props.defaultFilter) return update();
|
if (!$props.defaultFilter) return update();
|
||||||
if ($props.url) {
|
if (
|
||||||
|
$props.url &&
|
||||||
|
($props.limit || (!$props.limit && Object.keys(myOptions.value).length === 0))
|
||||||
|
) {
|
||||||
newOptions = await fetchFilter(val);
|
newOptions = await fetchFilter(val);
|
||||||
} else newOptions = filter(val, myOptionsOriginal.value);
|
} else newOptions = filter(val, myOptionsOriginal.value);
|
||||||
update(
|
update(
|
||||||
() => {
|
() => {
|
||||||
|
if ($props.noOne && noOneText.toLowerCase().includes(val.toLowerCase()))
|
||||||
|
newOptions.unshift(noOneOpt.value);
|
||||||
|
|
||||||
myOptions.value = newOptions;
|
myOptions.value = newOptions;
|
||||||
},
|
},
|
||||||
(ref) => {
|
(ref) => {
|
||||||
|
@ -173,47 +272,142 @@ async function filterHandler(val, update) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nullishToTrue(value) {
|
||||||
|
return value ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);
|
||||||
|
|
||||||
|
async function onScroll({ to, direction, from, index }) {
|
||||||
|
const lastIndex = myOptions.value.length - 1;
|
||||||
|
|
||||||
|
if (from === 0 && index === 0) return;
|
||||||
|
if (!useURL.value && !$props.fetchRef) return;
|
||||||
|
if (direction === 'decrease') return;
|
||||||
|
if (to === lastIndex && arrayData.store.hasMoreData && !isLoading.value) {
|
||||||
|
isLoading.value = true;
|
||||||
|
await arrayData.loadMore();
|
||||||
|
setOptions(arrayData.store.data);
|
||||||
|
vnSelectRef.value.scrollTo(lastIndex);
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ opts: myOptions });
|
||||||
|
|
||||||
|
function handleKeyDown(event) {
|
||||||
|
if (event.key === 'Tab' && !event.shiftKey) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const inputValue = vnSelectRef.value?.inputValue;
|
||||||
|
|
||||||
|
if (inputValue) {
|
||||||
|
const matchingOption = myOptions.value.find(
|
||||||
|
(option) =>
|
||||||
|
option[optionLabel.value].toLowerCase() === inputValue.toLowerCase()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (matchingOption) {
|
||||||
|
emit('update:modelValue', matchingOption[optionValue.value]);
|
||||||
|
} else {
|
||||||
|
emit('update:modelValue', inputValue);
|
||||||
|
}
|
||||||
|
vnSelectRef.value?.hidePopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
const focusableElements = document.querySelectorAll(
|
||||||
|
'a:not([disabled]), button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), details:not([disabled]), [tabindex]:not([tabindex="-1"]):not([disabled])'
|
||||||
|
);
|
||||||
|
const currentIndex = Array.prototype.indexOf.call(
|
||||||
|
focusableElements,
|
||||||
|
event.target
|
||||||
|
);
|
||||||
|
if (currentIndex >= 0 && currentIndex < focusableElements.length - 1) {
|
||||||
|
focusableElements[currentIndex + 1].focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCaption(opt) {
|
||||||
|
if (optionCaption.value === false) return;
|
||||||
|
return opt[optionCaption.value] || opt[optionValue.value];
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
|
||||||
ref="dataRef"
|
|
||||||
:url="$props.url"
|
|
||||||
@on-fetch="(data) => setOptions(data)"
|
|
||||||
:where="where || { [optionValue]: value }"
|
|
||||||
:limit="limit"
|
|
||||||
:sort-by="sortBy"
|
|
||||||
:fields="fields"
|
|
||||||
/>
|
|
||||||
<QSelect
|
<QSelect
|
||||||
v-model="value"
|
v-model="value"
|
||||||
:options="myOptions"
|
:options="myOptions"
|
||||||
:option-label="optionLabel"
|
:option-label="optionLabel"
|
||||||
:option-value="optionValue"
|
:option-value="optionValue"
|
||||||
v-bind="$attrs"
|
v-bind="{ ...$attrs, ...styleAttrs }"
|
||||||
emit-value
|
|
||||||
map-options
|
|
||||||
use-input
|
|
||||||
@filter="filterHandler"
|
@filter="filterHandler"
|
||||||
hide-selected
|
:emit-value="nullishToTrue($attrs['emit-value'])"
|
||||||
fill-input
|
:map-options="nullishToTrue($attrs['map-options'])"
|
||||||
|
:use-input="nullishToTrue($attrs['use-input'])"
|
||||||
|
:hide-selected="nullishToTrue($attrs['hide-selected'])"
|
||||||
|
:fill-input="nullishToTrue($attrs['fill-input'])"
|
||||||
ref="vnSelectRef"
|
ref="vnSelectRef"
|
||||||
lazy-rules
|
lazy-rules
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: isRequired }"
|
||||||
:rules="$attrs.required ? [requiredFieldRule] : null"
|
:rules="mixinRules"
|
||||||
virtual-scroll-slice-size="options.length"
|
virtual-scroll-slice-size="options.length"
|
||||||
|
hide-bottom-space
|
||||||
|
:input-debounce="useURL ? '300' : '0'"
|
||||||
|
:loading="isLoading"
|
||||||
|
@virtual-scroll="onScroll"
|
||||||
|
@keydown="handleKeyDown"
|
||||||
|
:data-cy="$attrs.dataCy ?? $attrs.label + '_select'"
|
||||||
|
:data-url="url"
|
||||||
>
|
>
|
||||||
<template v-if="isClearable" #append>
|
<template #append>
|
||||||
<QIcon
|
<QIcon
|
||||||
v-show="value"
|
v-show="isClearable && value"
|
||||||
name="close"
|
name="close"
|
||||||
@click.stop="value = null"
|
@click="
|
||||||
|
() => {
|
||||||
|
value = null;
|
||||||
|
emit('remove');
|
||||||
|
}
|
||||||
|
"
|
||||||
class="cursor-pointer"
|
class="cursor-pointer"
|
||||||
size="xs"
|
size="xs"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template v-for="(_, slotName) in $slots" #[slotName]="slotData" :key="slotName">
|
<template v-for="(_, slotName) in $slots" #[slotName]="slotData" :key="slotName">
|
||||||
<slot :name="slotName" v-bind="slotData ?? {}" :key="slotName" />
|
<div v-if="slotName == 'append'">
|
||||||
|
<QIcon
|
||||||
|
v-show="isClearable && value"
|
||||||
|
name="close"
|
||||||
|
@click.stop="
|
||||||
|
() => {
|
||||||
|
value = null;
|
||||||
|
emit('remove');
|
||||||
|
}
|
||||||
|
"
|
||||||
|
class="cursor-pointer"
|
||||||
|
size="xs"
|
||||||
|
/>
|
||||||
|
<slot name="append" v-if="$slots.append" v-bind="slotData ?? {}" />
|
||||||
|
</div>
|
||||||
|
<slot v-else :name="slotName" v-bind="slotData ?? {}" :key="slotName" />
|
||||||
|
</template>
|
||||||
|
<template #option="{ opt, itemProps }">
|
||||||
|
<QItem v-bind="itemProps">
|
||||||
|
<QItemSection v-if="typeof opt !== 'object'"> {{ opt }}</QItemSection>
|
||||||
|
<QItemSection v-else-if="opt[optionValue] == opt[optionLabel]">
|
||||||
|
<QItemLabel>{{ opt[optionLabel] }}</QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
<QItemSection v-else>
|
||||||
|
<QItemLabel>
|
||||||
|
{{ opt[optionLabel] }}
|
||||||
|
</QItemLabel>
|
||||||
|
<QItemLabel caption v-if="getCaption(opt)">
|
||||||
|
{{ `#${getCaption(opt)}` }}
|
||||||
|
</QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
</template>
|
</template>
|
||||||
</QSelect>
|
</QSelect>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -8,18 +8,32 @@ const $props = defineProps({
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
find: {
|
find: {
|
||||||
type: String,
|
type: [String, Object],
|
||||||
default: null,
|
default: null,
|
||||||
|
description: 'search in row to add default options',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const options = ref([]);
|
const options = ref([]);
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
onBeforeMount(async () => {
|
||||||
const { url } = useAttrs();
|
const { url, optionValue, optionLabel } = useAttrs();
|
||||||
const findBy = $props.find ?? url?.charAt(0)?.toLocaleLowerCase() + url?.slice(1, -1);
|
const findBy = $props.find ?? url?.charAt(0)?.toLocaleLowerCase() + url?.slice(1, -1);
|
||||||
if (findBy) options.value = [$props.row[findBy]];
|
if (!findBy || !$props.row) return;
|
||||||
|
// is object
|
||||||
|
if (typeof findBy == 'object') {
|
||||||
|
const { value, label } = findBy;
|
||||||
|
if (!$props.row[value] || !$props.row[label]) return;
|
||||||
|
return (options.value = [
|
||||||
|
{
|
||||||
|
[optionValue ?? 'id']: $props.row[value],
|
||||||
|
[optionLabel ?? 'name']: $props.row[label],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
// is string
|
||||||
|
if ($props.row[findBy]) options.value = [$props.row[findBy]];
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VnSelect v-bind="$attrs" :options="$attrs.options ?? options" />
|
<VnSelect v-bind="$attrs" :options="$attrs.options ?? options" />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,25 +1,21 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
import { useRole } from 'src/composables/useRole';
|
||||||
|
import { useAcl } from 'src/composables/useAcl';
|
||||||
|
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
|
|
||||||
import { useRole } from 'src/composables/useRole';
|
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue']);
|
const emit = defineEmits(['update:modelValue']);
|
||||||
|
|
||||||
|
const value = defineModel({ type: [String, Number, Object] });
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
modelValue: {
|
|
||||||
type: [String, Number, Object],
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
type: Array,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
rolesAllowedToCreate: {
|
rolesAllowedToCreate: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => ['developer'],
|
default: () => ['developer'],
|
||||||
},
|
},
|
||||||
|
acls: {
|
||||||
|
type: Array,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
actionIcon: {
|
actionIcon: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'add',
|
default: 'add',
|
||||||
|
@ -31,31 +27,24 @@ const $props = defineProps({
|
||||||
});
|
});
|
||||||
|
|
||||||
const role = useRole();
|
const role = useRole();
|
||||||
const showForm = ref(false);
|
const acl = useAcl();
|
||||||
|
|
||||||
const value = computed({
|
|
||||||
get() {
|
|
||||||
return $props.modelValue;
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
emit('update:modelValue', value);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const isAllowedToCreate = computed(() => {
|
const isAllowedToCreate = computed(() => {
|
||||||
|
if ($props.acls.length) return acl.hasAny($props.acls);
|
||||||
return role.hasAny($props.rolesAllowedToCreate);
|
return role.hasAny($props.rolesAllowedToCreate);
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggleForm = () => {
|
|
||||||
showForm.value = !showForm.value;
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VnSelect v-model="value" :options="options" v-bind="$attrs">
|
<VnSelect
|
||||||
|
v-model="value"
|
||||||
|
v-bind="$attrs"
|
||||||
|
@update:model-value="(...args) => emit('update:modelValue', ...args)"
|
||||||
|
>
|
||||||
<template v-if="isAllowedToCreate" #append>
|
<template v-if="isAllowedToCreate" #append>
|
||||||
<QIcon
|
<QIcon
|
||||||
@click.stop.prevent="toggleForm()"
|
:data-cy="$attrs.dataCy ?? $attrs.label + '_icon'"
|
||||||
|
@click.stop.prevent="$refs.dialog.show()"
|
||||||
:name="actionIcon"
|
:name="actionIcon"
|
||||||
:size="actionIcon === 'add' ? 'xs' : 'sm'"
|
:size="actionIcon === 'add' ? 'xs' : 'sm'"
|
||||||
:class="['default-icon', { '--add-icon': actionIcon === 'add' }]"
|
:class="['default-icon', { '--add-icon': actionIcon === 'add' }]"
|
||||||
|
@ -65,7 +54,7 @@ const toggleForm = () => {
|
||||||
>
|
>
|
||||||
<QTooltip v-if="tooltip">{{ tooltip }}</QTooltip>
|
<QTooltip v-if="tooltip">{{ tooltip }}</QTooltip>
|
||||||
</QIcon>
|
</QIcon>
|
||||||
<QDialog v-model="showForm" transition-show="scale" transition-hide="scale">
|
<QDialog ref="dialog" transition-show="scale" transition-hide="scale">
|
||||||
<slot name="form" />
|
<slot name="form" />
|
||||||
</QDialog>
|
</QDialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
<script setup>
|
||||||
|
import { onBeforeMount, ref, useAttrs } from 'vue';
|
||||||
|
import axios from 'axios';
|
||||||
|
import VnSelect from 'components/common/VnSelect.vue';
|
||||||
|
|
||||||
|
const { schema, table, column, translation, defaultOptions } = defineProps({
|
||||||
|
schema: {
|
||||||
|
type: String,
|
||||||
|
default: 'vn',
|
||||||
|
},
|
||||||
|
table: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
translation: {
|
||||||
|
type: Function,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
defaultOptions: {
|
||||||
|
type: Array,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const $attrs = useAttrs();
|
||||||
|
const options = ref([]);
|
||||||
|
onBeforeMount(async () => {
|
||||||
|
options.value = [].concat(defaultOptions);
|
||||||
|
const { data } = await axios.get(`Applications/get-enum-values`, {
|
||||||
|
params: { schema, table, column },
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const value of data)
|
||||||
|
options.value.push({
|
||||||
|
[$attrs['option-value'] ?? 'id']: value,
|
||||||
|
[$attrs['option-label'] ?? 'name']: translation ? translation(value) : value,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VnSelect
|
||||||
|
v-bind="$attrs"
|
||||||
|
:options="options"
|
||||||
|
:key="options.length"
|
||||||
|
:input-debounce="0"
|
||||||
|
/>
|
||||||
|
</template>
|
|
@ -0,0 +1,86 @@
|
||||||
|
<script setup>
|
||||||
|
import { computed, useAttrs } from 'vue';
|
||||||
|
import VnSelect from 'components/common/VnSelect.vue';
|
||||||
|
import VnAvatar from 'src/components/ui/VnAvatar.vue';
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:modelValue']);
|
||||||
|
const $props = defineProps({
|
||||||
|
hasAvatar: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
hasInfo: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
type: [String, Number, Object],
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const $attrs = useAttrs();
|
||||||
|
|
||||||
|
const value = computed({
|
||||||
|
get() {
|
||||||
|
return $props.modelValue;
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
emit('update:modelValue', val);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const url = computed(() => {
|
||||||
|
let url = 'Workers/search';
|
||||||
|
const { departmentCodes } = $attrs.params ?? {};
|
||||||
|
if (!departmentCodes) return url;
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
departmentCodes: JSON.stringify(departmentCodes),
|
||||||
|
});
|
||||||
|
|
||||||
|
return url.concat(`?${params.toString()}`);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VnSelect
|
||||||
|
:label="$t('globals.worker')"
|
||||||
|
v-bind="$attrs"
|
||||||
|
v-model="value"
|
||||||
|
:url="url"
|
||||||
|
option-value="id"
|
||||||
|
option-label="nickname"
|
||||||
|
:fields="['id', 'name', 'nickname', 'code']"
|
||||||
|
:filter-options="['id', 'name', 'nickname', 'code']"
|
||||||
|
sort-by="nickname ASC"
|
||||||
|
>
|
||||||
|
<template #prepend v-if="$props.hasAvatar">
|
||||||
|
<VnAvatar :worker-id="value" color="primary" :title="title" />
|
||||||
|
</template>
|
||||||
|
<template #append v-if="$props.hasInfo">
|
||||||
|
<QIcon name="info" class="cursor-pointer">
|
||||||
|
<QTooltip>{{ $t($props.hasInfo) }}</QTooltip>
|
||||||
|
</QIcon>
|
||||||
|
</template>
|
||||||
|
<template #option="scope">
|
||||||
|
<QItem v-bind="scope.itemProps">
|
||||||
|
<QItemSection>
|
||||||
|
<QItemLabel>
|
||||||
|
{{ scope.opt.name }}
|
||||||
|
</QItemLabel>
|
||||||
|
<QItemLabel v-if="!scope.opt.id">
|
||||||
|
{{ scope.opt.nickname }}
|
||||||
|
</QItemLabel>
|
||||||
|
<QItemLabel caption v-else>
|
||||||
|
#{{ scope.opt.id }}, {{ scope.opt.nickname }}, {{ scope.opt.code }}
|
||||||
|
</QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
|
</template>
|
||||||
|
</VnSelect>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<i18n>
|
||||||
|
es:
|
||||||
|
Responsible for approving invoices: Responsable de aprobar las facturas
|
||||||
|
</i18n>
|
|
@ -86,7 +86,7 @@ async function send() {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<QDialog ref="dialogRef">
|
<QDialog ref="dialogRef" data-cy="vnSmsDialog">
|
||||||
<QCard class="q-pa-sm">
|
<QCard class="q-pa-sm">
|
||||||
<QCardSection class="row items-center q-pb-none">
|
<QCardSection class="row items-center q-pb-none">
|
||||||
<span class="text-h6 text-grey">
|
<span class="text-h6 text-grey">
|
||||||
|
@ -161,6 +161,7 @@ async function send() {
|
||||||
:loading="isLoading"
|
:loading="isLoading"
|
||||||
color="primary"
|
color="primary"
|
||||||
unelevated
|
unelevated
|
||||||
|
data-cy="sendSmsBtn"
|
||||||
/>
|
/>
|
||||||
</QCardActions>
|
</QCardActions>
|
||||||
</QCard>
|
</QCard>
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<script setup>
|
||||||
|
const model = defineModel({ type: [String, Number], required: true });
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<QTime v-model="model" now-btn mask="HH:mm" />
|
||||||
|
</template>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.q-time {
|
||||||
|
width: 230px;
|
||||||
|
min-width: unset;
|
||||||
|
:deep(.q-time__header) {
|
||||||
|
min-height: unset;
|
||||||
|
height: 50px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -7,8 +7,8 @@ defineProps({
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div :class="$q.screen.gt.md ? 'q-pb-lg' : 'q-pb-md'">
|
<div :class="$q.screen.gt.md ? 'q-pb-lg' : 'q-pb-md'">
|
||||||
<div class="header-link">
|
<div class="header-link" :style="{ cursor: url ? 'pointer' : 'default' }">
|
||||||
<a :href="url" :class="url ? 'link' : 'color-vn-text'">
|
<a :href="url" :class="url ? 'link' : 'color-vn-text'" v-bind="$attrs">
|
||||||
{{ text }}
|
{{ text }}
|
||||||
<QIcon v-if="url" :name="icon" />
|
<QIcon v-if="url" :name="icon" />
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
|
import VnChangePassword from 'src/components/common/VnChangePassword.vue';
|
||||||
|
import { vi, beforeEach, afterEach, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
import { Notify } from 'quasar';
|
||||||
|
|
||||||
|
describe('VnSmsDialog', () => {
|
||||||
|
let vm;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||||
|
data: [],
|
||||||
|
});
|
||||||
|
vm = createWrapper(VnChangePassword, {
|
||||||
|
propsData: {
|
||||||
|
submitFn: vi.fn(),
|
||||||
|
},
|
||||||
|
}).vm;
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
Notify.create = vi.fn();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should notify when new password is empty', async () => {
|
||||||
|
vm.passwords.newPassword = '';
|
||||||
|
vm.passwords.repeatPassword = 'password';
|
||||||
|
|
||||||
|
await vm.validate();
|
||||||
|
expect(Notify.create).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
message: 'You must enter a new password',
|
||||||
|
type: 'negative',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should notify when passwords don't match", async () => {
|
||||||
|
vm.passwords.newPassword = 'password1';
|
||||||
|
vm.passwords.repeatPassword = 'password2';
|
||||||
|
await vm.validate();
|
||||||
|
expect(Notify.create).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
message: `Passwords don't match`,
|
||||||
|
type: 'negative',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('if passwords match', () => {
|
||||||
|
it('should call submitFn and emit password', async () => {
|
||||||
|
vm.passwords.newPassword = 'password';
|
||||||
|
vm.passwords.repeatPassword = 'password';
|
||||||
|
await vm.validate();
|
||||||
|
expect(vm.props.submitFn).toHaveBeenCalledWith('password', undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call submitFn and emit password and old password', async () => {
|
||||||
|
vm.passwords.newPassword = 'password';
|
||||||
|
vm.passwords.repeatPassword = 'password';
|
||||||
|
vm.passwords.oldPassword = 'oldPassword';
|
||||||
|
|
||||||
|
await vm.validate();
|
||||||
|
expect(vm.props.submitFn).toHaveBeenCalledWith('password', 'oldPassword');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
|
||||||
|
import { createWrapper } from 'app/test/vitest/helper';
|
||||||
|
import VnDiscount from 'components/common/vnDiscount.vue';
|
||||||
|
|
||||||
|
describe('VnDiscount', () => {
|
||||||
|
let vm;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
vm = createWrapper(VnDiscount, {
|
||||||
|
props: {
|
||||||
|
data: {},
|
||||||
|
price: 100,
|
||||||
|
quantity: 2,
|
||||||
|
discount: 10,
|
||||||
|
}
|
||||||
|
}).vm;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('total', () => {
|
||||||
|
it('should calculate total correctly', () => {
|
||||||
|
expect(vm.total).toBe(180);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,87 @@
|
||||||
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
|
import VnDmsList from 'src/components/common/VnDmsList.vue';
|
||||||
|
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
describe('VnDmsList', () => {
|
||||||
|
let vm;
|
||||||
|
const dms = {
|
||||||
|
userFk: 1,
|
||||||
|
name: 'DMS 1'
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
vi.spyOn(axios, 'get').mockResolvedValue({ data: [] });
|
||||||
|
vm = createWrapper(VnDmsList, {
|
||||||
|
props: {
|
||||||
|
model: 'WorkerDms/1110/filter',
|
||||||
|
defaultDmsCode: 'hhrrData',
|
||||||
|
filter: 'wd.workerFk',
|
||||||
|
updateModel: 'Workers',
|
||||||
|
deleteModel: 'WorkerDms',
|
||||||
|
downloadModel: 'WorkerDms'
|
||||||
|
}
|
||||||
|
}).vm;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setData()', () => {
|
||||||
|
const data = [
|
||||||
|
{
|
||||||
|
userFk: 1,
|
||||||
|
name: 'Jessica',
|
||||||
|
lastName: 'Jones',
|
||||||
|
file: '4.jpg',
|
||||||
|
created: '2021-07-28 21:00:00'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userFk: 2,
|
||||||
|
name: 'Bruce',
|
||||||
|
lastName: 'Banner',
|
||||||
|
created: '2022-07-28 21:00:00',
|
||||||
|
dms: {
|
||||||
|
userFk: 2,
|
||||||
|
name: 'Bruce',
|
||||||
|
lastName: 'BannerDMS',
|
||||||
|
created: '2022-07-28 21:00:00',
|
||||||
|
file: '4.jpg',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userFk: 3,
|
||||||
|
name: 'Natasha',
|
||||||
|
lastName: 'Romanoff',
|
||||||
|
file: '4.jpg',
|
||||||
|
created: '2021-10-28 21:00:00'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
it('Should replace objects that contain the "dms" property with the value of the same and sort by creation date', () => {
|
||||||
|
vm.setData(data);
|
||||||
|
expect([vm.rows][0][0].lastName).toEqual('BannerDMS');
|
||||||
|
expect([vm.rows][0][1].lastName).toEqual('Romanoff');
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parseDms()', () => {
|
||||||
|
const resultDms = { ...dms, userId:1};
|
||||||
|
|
||||||
|
it('Should add properties that end with "Fk" by changing the suffix to "Id"', () => {
|
||||||
|
const parsedDms = vm.parseDms(dms);
|
||||||
|
expect(parsedDms).toEqual(resultDms);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('showFormDialog()', () => {
|
||||||
|
const resultDms = { ...dms, userId:1};
|
||||||
|
|
||||||
|
it('should call fn parseDms() and set show true if dms is defined', () => {
|
||||||
|
vm.showFormDialog(dms);
|
||||||
|
expect(vm.formDialog.show).toEqual(true);
|
||||||
|
expect(vm.formDialog.dms).toEqual(resultDms);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,72 @@
|
||||||
|
import { createWrapper } from 'app/test/vitest/helper.js';
|
||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import VnInputDate from 'components/common/VnInputDate.vue';
|
||||||
|
|
||||||
|
let vm;
|
||||||
|
let wrapper;
|
||||||
|
|
||||||
|
function generateWrapper(date, outlined, required) {
|
||||||
|
wrapper = createWrapper(VnInputDate, {
|
||||||
|
props: {
|
||||||
|
modelValue: date,
|
||||||
|
},
|
||||||
|
attrs: {
|
||||||
|
isOutlined: outlined,
|
||||||
|
required: required
|
||||||
|
},
|
||||||
|
});
|
||||||
|
wrapper = wrapper.wrapper;
|
||||||
|
vm = wrapper.vm;
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('VnInputDate', () => {
|
||||||
|
|
||||||
|
describe('formattedDate', () => {
|
||||||
|
it('formats a valid date correctly', async () => {
|
||||||
|
generateWrapper('2023-12-25', false, false);
|
||||||
|
await vm.$nextTick();
|
||||||
|
expect(vm.formattedDate).toBe('25/12/2023');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('updates the model value when a new date is set', async () => {
|
||||||
|
const input = wrapper.find('input');
|
||||||
|
await input.setValue('31/12/2023');
|
||||||
|
expect(wrapper.emitted()['update:modelValue']).toBeTruthy();
|
||||||
|
expect(wrapper.emitted()['update:modelValue'][0][0]).toBe('2023-12-31T00:00:00.000Z');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not update the model value when an invalid date is set', async () => {
|
||||||
|
const input = wrapper.find('input');
|
||||||
|
await input.setValue('invalid-date');
|
||||||
|
expect(wrapper.emitted()['update:modelValue'][0][0]).toBe('2023-12-31T00:00:00.000Z');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('styleAttrs', () => {
|
||||||
|
it('should return empty styleAttrs when isOutlined is false', async () => {
|
||||||
|
generateWrapper('2023-12-25', false, false);
|
||||||
|
await vm.$nextTick();
|
||||||
|
expect(vm.styleAttrs).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set styleAttrs when isOutlined is true', async () => {
|
||||||
|
generateWrapper('2023-12-25', true, false);
|
||||||
|
await vm.$nextTick();
|
||||||
|
expect(vm.styleAttrs.outlined).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('required', () => {
|
||||||
|
it('should not applies required class when isRequired is false', async () => {
|
||||||
|
generateWrapper('2023-12-25', false, false);
|
||||||
|
await vm.$nextTick();
|
||||||
|
expect(wrapper.find('.vn-input-date').classes()).not.toContain('required');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should applies required class when isRequired is true', async () => {
|
||||||
|
generateWrapper('2023-12-25', false, true);
|
||||||
|
await vm.$nextTick();
|
||||||
|
expect(wrapper.find('.vn-input-date').classes()).toContain('required');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,63 @@
|
||||||
|
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
|
||||||
|
import { createWrapper } from 'app/test/vitest/helper';
|
||||||
|
import VnInputTime from 'components/common/VnInputTime.vue';
|
||||||
|
|
||||||
|
describe('VnInputTime', () => {
|
||||||
|
let wrapper;
|
||||||
|
let vm;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
wrapper = createWrapper(VnInputTime, {
|
||||||
|
props: {
|
||||||
|
isOutlined: true,
|
||||||
|
timeOnly: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
vm = wrapper.vm;
|
||||||
|
wrapper = wrapper.wrapper;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the correct data if isOutlined is true', () => {
|
||||||
|
expect(vm.isOutlined).toBe(true);
|
||||||
|
expect(vm.styleAttrs).toEqual({ dense: true, outlined: true, rounded: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the formatted data', () => {
|
||||||
|
expect(vm.dateToTime('2022-01-01T03:23:43')).toBe('03:23');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('formattedTime', () => {
|
||||||
|
it('should return the formatted time for a valid ISO date', () => {
|
||||||
|
vm.model = '2025-01-02T15:45:00';
|
||||||
|
expect(vm.formattedTime).toBe('15:45');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle null model value gracefully', () => {
|
||||||
|
vm.model = null;
|
||||||
|
expect(vm.formattedTime).toBe(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle time-only input correctly', async () => {
|
||||||
|
await wrapper.setProps({ timeOnly: true });
|
||||||
|
vm.formattedTime = '14:30';
|
||||||
|
expect(vm.model).toBe('14:30');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pad short time values correctly', async () => {
|
||||||
|
await wrapper.setProps({ timeOnly: true });
|
||||||
|
vm.formattedTime = '9';
|
||||||
|
expect(vm.model).toBe('09:00');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not update the model if the value is unchanged', () => {
|
||||||
|
vm.model = '14:30';
|
||||||
|
const previousModel = vm.model;
|
||||||
|
vm.formattedTime = '14:30';
|
||||||
|
expect(vm.model).toBe(previousModel);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,95 @@
|
||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import VnJsonValue from 'src/components/common/VnJsonValue.vue';
|
||||||
|
import { createWrapper } from 'app/test/vitest/helper';
|
||||||
|
|
||||||
|
const buildComponent = (props) => {
|
||||||
|
return createWrapper(VnJsonValue, {
|
||||||
|
props,
|
||||||
|
}).wrapper;
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('VnJsonValue', () => {
|
||||||
|
it('renders null value correctly', async () => {
|
||||||
|
const wrapper = buildComponent({ value: null });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toBe('∅');
|
||||||
|
expect(span.classes()).toContain('json-null');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders boolean true correctly', async () => {
|
||||||
|
const wrapper = buildComponent({ value: true });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toBe('✓');
|
||||||
|
expect(span.classes()).toContain('json-true');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders boolean false correctly', async () => {
|
||||||
|
const wrapper = buildComponent({ value: false });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toBe('✗');
|
||||||
|
expect(span.classes()).toContain('json-false');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders a short string correctly', async () => {
|
||||||
|
const wrapper = buildComponent({ value: 'Hello' });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toBe('Hello');
|
||||||
|
expect(span.classes()).toContain('json-string');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders a long string correctly with ellipsis', async () => {
|
||||||
|
const longString = 'a'.repeat(600);
|
||||||
|
const wrapper = buildComponent({ value: longString });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toContain('...');
|
||||||
|
expect(span.text().length).toBeLessThanOrEqual(515);
|
||||||
|
expect(span.attributes('title')).toBe(longString);
|
||||||
|
expect(span.classes()).toContain('json-string');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders a number correctly', async () => {
|
||||||
|
const wrapper = buildComponent({ value: 123.4567 });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toBe('123.457');
|
||||||
|
expect(span.classes()).toContain('json-number');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders an integer correctly', async () => {
|
||||||
|
const wrapper = buildComponent({ value: 42 });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toBe('42');
|
||||||
|
expect(span.classes()).toContain('json-number');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders a date correctly', async () => {
|
||||||
|
const date = new Date('2023-01-01');
|
||||||
|
const wrapper = buildComponent({ value: date });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toBe('2023-01-01');
|
||||||
|
expect(span.classes()).toContain('json-object');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders an object correctly', async () => {
|
||||||
|
const obj = { key: 'value' };
|
||||||
|
const wrapper = buildComponent({ value: obj });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toBe(obj.toString());
|
||||||
|
expect(span.classes()).toContain('json-object');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders an array correctly', async () => {
|
||||||
|
const arr = [1, 2, 3];
|
||||||
|
const wrapper = buildComponent({ value: arr });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toBe(arr.toString());
|
||||||
|
expect(span.classes()).toContain('json-object');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('updates value when prop changes', async () => {
|
||||||
|
const wrapper = buildComponent({ value: true });
|
||||||
|
await wrapper.setProps({ value: 123 });
|
||||||
|
const span = wrapper.find('span');
|
||||||
|
expect(span.text()).toBe('123');
|
||||||
|
expect(span.classes()).toContain('json-number');
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,91 @@
|
||||||
|
import { createWrapper } from 'app/test/vitest/helper';
|
||||||
|
import VnLocation from 'components/common/VnLocation.vue';
|
||||||
|
import { vi, afterEach, expect, it, beforeEach, describe } from 'vitest';
|
||||||
|
|
||||||
|
function buildComponent(data) {
|
||||||
|
return createWrapper(VnLocation, {
|
||||||
|
global: {
|
||||||
|
props: {
|
||||||
|
location: data
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}).vm;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('formatLocation', () => {
|
||||||
|
let locationBase;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
locationBase = {
|
||||||
|
postcode: '46680',
|
||||||
|
city: 'Algemesi',
|
||||||
|
province: { name: 'Valencia' },
|
||||||
|
country: { name: 'Spain' }
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the postcode, city, province and country', () => {
|
||||||
|
const location = { ...locationBase };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
expect(vm.formatLocation(location)).toEqual('46680, Algemesi(Valencia), Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the postcode and country', () => {
|
||||||
|
const location = { ...locationBase, city: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
expect(vm.formatLocation(location)).toEqual('46680, Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the city, province and country', () => {
|
||||||
|
const location = { ...locationBase, postcode: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
expect(vm.formatLocation(location)).toEqual('Algemesi(Valencia), Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the country', () => {
|
||||||
|
const location = { ...locationBase, postcode: undefined, city: undefined, province: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
expect(vm.formatLocation(location)).toEqual('Spain');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('showLabel', () => {
|
||||||
|
let locationBase;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
locationBase = {
|
||||||
|
code: '46680',
|
||||||
|
town: 'Algemesi',
|
||||||
|
province: 'Valencia',
|
||||||
|
country: 'Spain'
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the label with postcode, city, province and country', () => {
|
||||||
|
const location = { ...locationBase };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
expect(vm.showLabel(location)).toEqual('46680, Algemesi(Valencia), Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the label with postcode and country', () => {
|
||||||
|
const location = { ...locationBase, town: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
expect(vm.showLabel(location)).toEqual('46680, Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the label with city, province and country', () => {
|
||||||
|
const location = { ...locationBase, code: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
expect(vm.showLabel(location)).toEqual('Algemesi(Valencia), Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the label with country', () => {
|
||||||
|
const location = { ...locationBase, code: undefined, town: undefined, province: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
expect(vm.showLabel(location)).toEqual('Spain');
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,107 @@
|
||||||
|
import { describe, it, expect, vi, beforeAll, afterEach, beforeEach } from 'vitest';
|
||||||
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
|
import VnNotes from 'src/components/ui/VnNotes.vue';
|
||||||
|
|
||||||
|
describe('VnNotes', () => {
|
||||||
|
let vm;
|
||||||
|
let wrapper;
|
||||||
|
let spyFetch;
|
||||||
|
let postMock;
|
||||||
|
let expectedBody;
|
||||||
|
const mockData= {name: 'Tony', lastName: 'Stark', text: 'Test Note', observationTypeFk: 1};
|
||||||
|
|
||||||
|
function generateExpectedBody() {
|
||||||
|
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setTestParams(text, observationType, type){
|
||||||
|
vm.newNote.text = text;
|
||||||
|
vm.newNote.observationTypeFk = observationType;
|
||||||
|
wrapper.setProps({ selectType: type });
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
vi.spyOn(axios, 'get').mockReturnValue({ data: [] });
|
||||||
|
|
||||||
|
wrapper = createWrapper(VnNotes, {
|
||||||
|
propsData: {
|
||||||
|
url: '/test',
|
||||||
|
body: { name: 'Tony', lastName: 'Stark' },
|
||||||
|
}
|
||||||
|
});
|
||||||
|
wrapper = wrapper.wrapper;
|
||||||
|
vm = wrapper.vm;
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
postMock = vi.spyOn(axios, 'post').mockResolvedValue(mockData);
|
||||||
|
spyFetch = vi.spyOn(vm.vnPaginateRef, 'fetch').mockImplementation(() => vi.fn());
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
expectedBody = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('insert', () => {
|
||||||
|
it('should not call axios.post and vnPaginateRef.fetch if newNote.text is null', async () => {
|
||||||
|
await setTestParams( null, null, true );
|
||||||
|
|
||||||
|
await vm.insert();
|
||||||
|
|
||||||
|
expect(postMock).not.toHaveBeenCalled();
|
||||||
|
expect(spyFetch).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not call axios.post and vnPaginateRef.fetch if newNote.text is empty', async () => {
|
||||||
|
await setTestParams( "", null, false );
|
||||||
|
|
||||||
|
await vm.insert();
|
||||||
|
|
||||||
|
expect(postMock).not.toHaveBeenCalled();
|
||||||
|
expect(spyFetch).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is true', async () => {
|
||||||
|
await setTestParams( "Test Note", null, true );
|
||||||
|
|
||||||
|
await vm.insert();
|
||||||
|
|
||||||
|
expect(postMock).not.toHaveBeenCalled();
|
||||||
|
expect(spyFetch).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is false', async () => {
|
||||||
|
await setTestParams( "Test Note", null, false );
|
||||||
|
|
||||||
|
generateExpectedBody();
|
||||||
|
|
||||||
|
await vm.insert();
|
||||||
|
|
||||||
|
expect(postMock).toHaveBeenCalledWith(vm.$props.url, expectedBody);
|
||||||
|
expect(spyFetch).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is setted and selectType is false', async () => {
|
||||||
|
await setTestParams( "Test Note", 1, false );
|
||||||
|
|
||||||
|
generateExpectedBody();
|
||||||
|
|
||||||
|
await vm.insert();
|
||||||
|
|
||||||
|
expect(postMock).toHaveBeenCalledWith(vm.$props.url, expectedBody);
|
||||||
|
expect(spyFetch).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call axios.post and vnPaginateRef.fetch when newNote is valid', async () => {
|
||||||
|
await setTestParams( "Test Note", 1, true );
|
||||||
|
|
||||||
|
generateExpectedBody();
|
||||||
|
|
||||||
|
await vm.insert();
|
||||||
|
|
||||||
|
expect(postMock).toHaveBeenCalledWith(vm.$props.url, expectedBody);
|
||||||
|
expect(spyFetch).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue