mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Added possibility to ignore the checks of withdraw amount when building projects
This fixes #349
This commit is contained in:
parent
b62dc1241d
commit
33a0981981
6 changed files with 118 additions and 2 deletions
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {Controller} from "@hotwired/stimulus";
|
||||
|
||||
/**
|
||||
* This controller is used on a checkbox, which toggles the max value of all number input fields
|
||||
*/
|
||||
export default class extends Controller {
|
||||
|
||||
_checkbox;
|
||||
|
||||
getCheckbox() {
|
||||
if (this._checkbox) {
|
||||
return this._checkbox;
|
||||
}
|
||||
|
||||
//Find the checkbox inside the controller element
|
||||
this._checkbox = this.element.querySelector('input[type="checkbox"]');
|
||||
return this._checkbox;
|
||||
}
|
||||
|
||||
connect() {
|
||||
//Add event listener to the checkbox
|
||||
this.getCheckbox().addEventListener('change', this.toggleInputLimits.bind(this));
|
||||
}
|
||||
|
||||
toggleInputLimits() {
|
||||
//Find all input fields with the data-toggle-input-limits-target="max"
|
||||
const inputFields = document.querySelectorAll("input[type='number']");
|
||||
|
||||
inputFields.forEach((inputField) => {
|
||||
//Ensure that the input field has either a max or a data-max attribute
|
||||
if (!inputField.hasAttribute('max') && !inputField.hasAttribute('data-max')) {
|
||||
return;
|
||||
}
|
||||
|
||||
//If the checkbox is checked, rename the max attribute to data-max
|
||||
if (this.getCheckbox().checked) {
|
||||
inputField.setAttribute('data-max', inputField.getAttribute('max'));
|
||||
inputField.removeAttribute('max');
|
||||
} else {
|
||||
//If the checkbox is not checked, rename the data-max attribute back to max
|
||||
inputField.setAttribute('max', inputField.getAttribute('data-max'));
|
||||
inputField.removeAttribute('data-max');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -62,6 +62,15 @@ class ProjectBuildType extends AbstractType implements DataMapperInterface
|
|||
'disabled' => !$this->security->isGranted('@parts_stock.withdraw'),
|
||||
]);
|
||||
|
||||
$builder->add('dontCheckQuantity', CheckboxType::class, [
|
||||
'label' => 'project.build.dont_check_quantity',
|
||||
'help' => 'project.build.dont_check_quantity.help',
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'data-controller' => 'pages--dont-check-quantity-checkbox'
|
||||
]
|
||||
]);
|
||||
|
||||
$builder->add('comment', TextType::class, [
|
||||
'label' => 'part.info.withdraw_modal.comment',
|
||||
'help' => 'part.info.withdraw_modal.comment.hint',
|
||||
|
@ -124,6 +133,7 @@ class ProjectBuildType extends AbstractType implements DataMapperInterface
|
|||
}
|
||||
|
||||
$forms['comment']->setData($data->getComment());
|
||||
$forms['dontCheckQuantity']->setData($data->isDontCheckQuantity());
|
||||
$forms['addBuildsToBuildsPart']->setData($data->getAddBuildsToBuildsPart());
|
||||
if (isset($forms['buildsPartLot'])) {
|
||||
$forms['buildsPartLot']->setData($data->getBuildsPartLot());
|
||||
|
@ -150,6 +160,8 @@ class ProjectBuildType extends AbstractType implements DataMapperInterface
|
|||
}
|
||||
|
||||
$data->setComment($forms['comment']->getData());
|
||||
$data->setDontCheckQuantity($forms['dontCheckQuantity']->getData());
|
||||
|
||||
if (isset($forms['buildsPartLot'])) {
|
||||
$lot = $forms['buildsPartLot']->getData();
|
||||
if (!$lot) { //When the user selected "Create new lot", create a new lot
|
||||
|
|
|
@ -47,6 +47,8 @@ final class ProjectBuildRequest
|
|||
|
||||
private bool $add_build_to_builds_part = false;
|
||||
|
||||
private bool $dont_check_quantity = false;
|
||||
|
||||
/**
|
||||
* @param Project $project The project that should be build
|
||||
* @param int $number_of_builds The number of builds that should be created
|
||||
|
@ -283,4 +285,26 @@ final class ProjectBuildRequest
|
|||
{
|
||||
return $this->number_of_builds;
|
||||
}
|
||||
|
||||
/**
|
||||
* If Set to true, the given withdraw amounts are used without any checks for requirements.
|
||||
* @return bool
|
||||
*/
|
||||
public function isDontCheckQuantity(): bool
|
||||
{
|
||||
return $this->dont_check_quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true, the given withdraw amounts are used without any checks for requirements.
|
||||
* @param bool $dont_check_quantity
|
||||
* @return $this
|
||||
*/
|
||||
public function setDontCheckQuantity(bool $dont_check_quantity): ProjectBuildRequest
|
||||
{
|
||||
$this->dont_check_quantity = $dont_check_quantity;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -69,12 +69,12 @@ class ValidProjectBuildRequestValidator extends ConstraintValidator
|
|||
->addViolation();
|
||||
}
|
||||
|
||||
if ($withdraw_sum > $needed_amount) {
|
||||
if ($withdraw_sum > $needed_amount && $value->isDontCheckQuantity() === false) {
|
||||
$this->buildViolationForLot($lot, 'validator.project_build.lot_bigger_than_needed')
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
if ($withdraw_sum < $needed_amount) {
|
||||
if ($withdraw_sum < $needed_amount && $value->isDontCheckQuantity() === false) {
|
||||
$this->buildViolationForLot($lot, 'validator.project_build.lot_smaller_than_needed')
|
||||
->addViolation();
|
||||
}
|
||||
|
|
|
@ -74,6 +74,9 @@
|
|||
</table>
|
||||
|
||||
{{ form_row(form.comment) }}
|
||||
<div {{ stimulus_controller('pages/dont_check_quantity_checkbox') }}>
|
||||
{{ form_row(form.dontCheckQuantity) }}
|
||||
</div>
|
||||
|
||||
{{ form_row(form.addBuildsToBuildsPart) }}
|
||||
{% if form.buildsPartLot is defined %}
|
||||
|
|
|
@ -11603,5 +11603,17 @@ Please note, that you can not impersonate a disabled user. If you try you will g
|
|||
<target>Show available Part-DB updates</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="VVpmfIj" name="project.build.dont_check_quantity">
|
||||
<segment>
|
||||
<source>project.build.dont_check_quantity</source>
|
||||
<target>Do not check quantities</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="AzYSIiX" name="project.build.dont_check_quantity.help">
|
||||
<segment>
|
||||
<source>project.build.dont_check_quantity.help</source>
|
||||
<target>If this option is selected, the given withdraw quantities are used as given, no matter if more or less parts are actually required to build this project.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue