Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Wellheor1 committed Jul 3, 2024
1 parent 9a7cbea commit bfa9336
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
42 changes: 18 additions & 24 deletions l2-frontend/src/components/types-and-forms-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,28 @@ export default function typesAndForms() {
'api.laboratory.forms100.form_01': { id: 'api.laboratory.forms100.form_01', label: 'Загрузка PDF результата из QMS' },
},
});
// todo - UploadResult + forms - получать только выбранные isResult функции (протестировать)
const getForms = (type: string, forms: string[] = null, onlyResult = false, allowedForms: string[] = null): formsFile[] => {
/* onlyResult - Выдаст только формы находящиеся в isResultForm, allowedForms - выдаст только те функции которые разрешены */
const func = (type: string, forms = null, allowedForms: string[] = null) => {
const result: formsFile[] = [];
for (const form of forms) {
if (allowedForms.includes(form) && fileForms.value[type][form]) {
result.push(fileForms.value[type][form]);
}
}
return result;
};

const getForms = (type: string, forms: string[] = null, onlyResult = false, allowedForms: string[] = null): formsFile[] => {
let result: formsFile[] = [];
if (!allowedForms) {
return result;
return [];
}
if (forms && forms.length > 0) { // Если переданы формы
for (const form of forms) {
if (!onlyResult && fileForms.value[type][form] && allowedForms.includes(form)) {
result.push(fileForms.value[type][form]);
} else if (onlyResult && isResultForm.value.includes(form) && allowedForms.includes(form)) {
result.push(fileForms.value[type][form]);
}
}
} else if (!forms && onlyResult) { // если нет форм, но, есть "только результат"
for (const form of isResultForm.value) {
if (fileForms.value[type][form] && allowedForms.includes(form)) {
result.push(fileForms.value[type][form]);
}
}
} else { // Если нет форм и "только результат" - выдать всё разрешенное
if (forms) {
result = func(type, forms, allowedForms);
} else if (onlyResult) {
result = func(type, isResultForm.value, allowedForms);
} else {
const tmpResult = Object.values(fileForms.value[type]);
for (const form of tmpResult) {
if (allowedForms.includes(String(form))) {
result.push(fileForms.value[type][form]);
}
}
result = func(type, tmpResult, allowedForms);
}
return result;
};
Expand Down
2 changes: 1 addition & 1 deletion l2-frontend/src/pages/LaboratoryResults/ResultsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
<UploadFileModal
v-if="research.enabled_add_files"
title="Прикрепить результат"
:upload-result="true"
:types-file="['PDF']"
:forms-file="['api.laboratory.forms100.form_01']"
:entity-id="pk"
/>
<strong>
Expand Down

0 comments on commit bfa9336

Please sign in to comment.