Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 12 additions & 38 deletions app/Livewire/Planning/QualityAssessment/QuestionRanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public function updateLabel($index)
$idGeneralScore = $this->items[$index]['id_general_score'];
$value = $this->items[$index]['description'];

if ($this->oldItems[$index]['description'] === $value) {
return;
}

GeneralScore::updateOrCreate([
'id_general_score' => $idGeneralScore,
], [
Expand All @@ -198,6 +202,8 @@ public function updateLabel($index)
message: __('project/planning.quality-assessment.ranges.label-updated'),
type: 'success'
);

$this->oldItems[$index]['description'] = $value;
} catch (\Exception $e) {
$this->toast(
message: $e->getMessage(),
Expand Down Expand Up @@ -237,46 +243,14 @@ public function generateIntervals()
}
}

// Excluir registros antigos de GeneralScore
GeneralScore::where('id_project', $this->currentProject->id_project)->delete();

// Gerar novos intervalos
$sum = $this->sum;
$items = [];
$min = 0.01;
$max = round($sum / $this->intervals, 2);

for ($i = 0; $i < $this->intervals; $i++) {
$itemToAdd = [
'start' => $min,
'end' => $max,
'description' => 'Item ' . ($i + 1),
'id_project' => $this->currentProject->id_project,
];

$itemCreated = GeneralScore::create($itemToAdd);
$items[] = array_merge($itemCreated->toArray(), [
'id_project' => $this->currentProject->id_project,
]);

$min = round($max + 0.01, 2);
$max = round($max + $sum / $this->intervals, 2);
public function updated($propertyName)
{
if (preg_match('/items\.(\d+)\.description/', $propertyName, $matches)) {
$index = $matches[1];
$this->updateLabel($index);
}
}

$this->items = $items;
$this->oldItems = $this->items;

// Notificar outros componentes sobre a atualização dos intervalos
$this->dispatch('general-scores-generated');


$this->toast(
message: __('project/planning.quality-assessment.ranges.generated'),
type: 'success'
);
}


public function render()
{
return view('livewire.planning.quality-assessment.question-ranges');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/>
<div class="btn-group">
<x-input
wire:model="items.{{ $loop->index }}.description"
wire:model.lazy="items.{{ $loop->index }}.description"
label="Label"
placeholder="Good"
class="max-input"
Expand Down
Loading