Mixin performance #875
|
@ -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,30 +1,52 @@
|
||||||
import { getCurrentInstance } from 'vue';
|
function focusFirstInput(input) {
|
||||||
|
input.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
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)) {
|
const form = document.querySelector('.q-form#formModel');
|
||||||
// TODO: AUTOFOCUS IS NOT FOCUSING
|
if (!form) return;
|
||||||
const that = this;
|
try {
|
||||||
this.$el.addEventListener('keyup', function (evt) {
|
const inputsFormCard = form.querySelectorAll(
|
||||||
if (evt.key === 'Enter') {
|
`input:not([disabled]):not([type="checkbox"])`
|
||||||
const input = evt.target;
|
);
|
||||||
if (input.type == 'textarea' && evt.shiftKey) {
|
if (inputsFormCard.length) {
|
||||||
evt.preventDefault();
|
focusFirstInput(inputsFormCard[0]);
|
||||||
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') {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,11 +3,16 @@ import qFormMixin from './qformMixin';
|
||||||
import keyShortcut from './keyShortcut';
|
import keyShortcut from './keyShortcut';
|
||||||
import useNotify from 'src/composables/useNotify.js';
|
import useNotify from 'src/composables/useNotify.js';
|
||||||
import { CanceledError } from 'axios';
|
import { CanceledError } from 'axios';
|
||||||
|
import { QForm } from 'quasar';
|
||||||
|
import { QLayout } from 'quasar';
|
||||||
|
import mainShortcutMixin from './mainShortcutMixin';
|
||||||
|
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
|
|
||||||
export default boot(({ app }) => {
|
export default boot(({ app }) => {
|
||||||
app.mixin(qFormMixin);
|
QForm.mixins = [qFormMixin];
|
||||||
|
QLayout.mixins = [mainShortcutMixin];
|
||||||
|
|
||||||
app.directive('shortcut', keyShortcut);
|
app.directive('shortcut', keyShortcut);
|
||||||
app.config.errorHandler = (error) => {
|
app.config.errorHandler = (error) => {
|
||||||
let message;
|
let message;
|
||||||
|
|
|
@ -177,6 +177,7 @@ function normalize(text) {
|
||||||
class="full-width"
|
class="full-width"
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
|
autofocus
|
||||||
/>
|
/>
|
||||||
</QItem>
|
</QItem>
|
||||||
<QSeparator />
|
<QSeparator />
|
||||||
|
|
|
@ -136,6 +136,7 @@ function reloadData() {
|
||||||
option-value="id"
|
option-value="id"
|
||||||
id="deviceProductionFk"
|
id="deviceProductionFk"
|
||||||
hide-selected
|
hide-selected
|
||||||
|
data-cy="pda-dialog-select"
|
||||||
>
|
>
|
||||||
<template #option="scope">
|
<template #option="scope">
|
||||||
<QItem v-bind="scope.itemProps">
|
<QItem v-bind="scope.itemProps">
|
||||||
|
|
|
@ -32,7 +32,12 @@ const agencyOptions = ref([]);
|
||||||
<FormModel :url="`Zones/${route.params.id}`" auto-load model="zone">
|
<FormModel :url="`Zones/${route.params.id}`" auto-load model="zone">
|
||||||
<template #form="{ data, validate }">
|
<template #form="{ data, validate }">
|
||||||
<VnRow>
|
<VnRow>
|
||||||
<VnInput :label="t('Name')" clearable v-model="data.name" />
|
<VnInput
|
||||||
|
data-cy="zone-basic-data-name"
|
||||||
|
:label="t('Name')"
|
||||||
|
clearable
|
||||||
|
v-model="data.name"
|
||||||
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
|
|
||||||
<VnRow>
|
<VnRow>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
describe('WorkerPda', () => {
|
describe('WorkerPda', () => {
|
||||||
const deviceProductionField =
|
const select = '[data-cy="pda-dialog-select"]';
|
||||||
'.vn-row > .q-field > .q-field__inner > .q-field__control > .q-field__control-container';
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.viewport(1920, 1080);
|
cy.viewport(1920, 1080);
|
||||||
cy.login('developer');
|
cy.login('developer');
|
||||||
|
@ -9,7 +8,8 @@ describe('WorkerPda', () => {
|
||||||
|
|
||||||
it('assign pda', () => {
|
it('assign pda', () => {
|
||||||
cy.get('.q-page-sticky > div > .q-btn > .q-btn__content > .q-icon').click();
|
cy.get('.q-page-sticky > div > .q-btn > .q-btn__content > .q-icon').click();
|
||||||
cy.get(deviceProductionField).type('{downArrow}{enter}');
|
cy.get(select).click();
|
||||||
|
cy.get(select).type('{downArrow}{enter}');
|
||||||
cy.get('.q-notification__message').should('have.text', 'Data created');
|
cy.get('.q-notification__message').should('have.text', 'Data created');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe('ZoneBasicData', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if the name is empty', () => {
|
it('should throw an error if the name is empty', () => {
|
||||||
cy.get('.q-card > :nth-child(1)').clear();
|
cy.get('[data-cy="zone-basic-data-name"] input').type('{selectall}{backspace}');
|
||||||
cy.get('.q-btn-group > .q-btn--standard').click();
|
cy.get('.q-btn-group > .q-btn--standard').click();
|
||||||
cy.get(notification).should('contains.text', "can't be blank");
|
cy.get(notification).should('contains.text', "can't be blank");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue