| @@ -48,11 +48,14 @@ | ||
| 48 | 48 | |
| 49 | 49 | public function createLabel(Request $request, $board_id) |
| 50 | 50 | { |
| 51 | 51 | $board_id = absint($board_id); |
| 52 | - $labelData = $this->labelSanitizeAndValidate($request->only(['bg_color', 'color', 'label']), [ | |
| 53 | - 'bg_color' => 'required|string', | |
| 54 | - 'color' => 'required|string', | |
| 52 | + $labelData = Helper::sanitizeLabel($request->only(['bg_color', 'color', 'color_preset', 'label'])); | |
| 53 | + $hasPreset = !empty($labelData['color_preset']); | |
| 54 | + $labelData = $this->validate($labelData, [ | |
| 55 | + 'bg_color' => $hasPreset ? 'nullable|string' : 'required|string', | |
| 56 | + 'color' => $hasPreset ? 'nullable|string' : 'required|string', | |
| 57 | + 'color_preset' => 'nullable|string', | |
| 55 | 58 | 'label' => 'nullable|string', |
| 56 | 59 | ]); |
| 57 | 60 | |
| 58 | 61 | try { |
| @@ -80,9 +83,9 @@ | ||
| 80 | 83 | 'task_id' => 'required|integer', |
| 81 | 84 | 'board_term_id' => 'required|integer', |
| 82 | 85 | ]); |
| 83 | 86 | try { |
| 84 | - $label = $this->labelService->createLabelForTask($labelData); | |
| 87 | + $label = $this->labelService->createLabelForTask($labelData, $board_id); | |
| 85 | 88 | |
| 86 | 89 | return $this->sendSuccess([ |
| 87 | 90 | 'message' => __('Label has been added', 'fluent-boards'), |
| 88 | 91 | 'label' => $label, |
| @@ -96,9 +99,9 @@ | ||
| 96 | 99 | { |
| 97 | 100 | $board_id = absint($board_id); |
| 98 | 101 | $task_id = absint($task_id); |
| 99 | 102 | try { |
| 100 | - $labels = $this->labelService->getLabelsByTask($task_id); | |
| 103 | + $labels = $this->labelService->getLabelsByTask($task_id, $board_id); | |
| 101 | 104 | |
| 102 | 105 | return $this->sendSuccess([ |
| 103 | 106 | 'labels' => $labels, |
| 104 | 107 | ], 200); |
| @@ -112,9 +115,9 @@ | ||
| 112 | 115 | $board_id = absint($board_id); |
| 113 | 116 | $task_id = absint($task_id); |
| 114 | 117 | $label_id = absint($label_id); |
| 115 | 118 | try { |
| 116 | - $this->labelService->deleteLabelOfTask($task_id, $label_id); | |
| 119 | + $this->labelService->deleteLabelOfTask($task_id, $label_id, $board_id); | |
| 117 | 120 | |
| 118 | 121 | return $this->sendSuccess([ |
| 119 | 122 | 'message' => __('Label has been deleted', 'fluent-boards'), |
| 120 | 123 | ], 200); |
| @@ -127,9 +130,9 @@ | ||
| 127 | 130 | { |
| 128 | 131 | $board_id = absint($board_id); |
| 129 | 132 | $label_id = absint($label_id); |
| 130 | 133 | try { |
| 131 | - $this->labelService->deleteLabelOfBoard($label_id); | |
| 134 | + $this->labelService->deleteLabelOfBoard($label_id, $board_id); | |
| 132 | 135 | |
| 133 | 136 | return $this->sendSuccess([ |
| 134 | 137 | 'message' => __('Label has been deleted', 'fluent-boards'), |
| 135 | 138 | 'type' => 'success', |
| @@ -142,15 +145,18 @@ | ||
| 142 | 145 | public function editLabelofBoard(Request $request, $board_id, $label_id) |
| 143 | 146 | { |
| 144 | 147 | $board_id = absint($board_id); |
| 145 | 148 | $label_id = absint($label_id); |
| 146 | - $labelData = $this->labelSanitizeAndValidate($request->only(['bg_color', 'color', 'label']), [ | |
| 147 | - 'bg_color' => 'required|string', | |
| 148 | - 'color' => 'nullable|string', | |
| 149 | + $labelData = Helper::sanitizeLabel($request->only(['bg_color', 'color', 'color_preset', 'label'])); | |
| 150 | + $isCustomSelection = array_key_exists('color_preset', $labelData) && $labelData['color_preset'] === ''; | |
| 151 | + $labelData = $this->validate($labelData, [ | |
| 152 | + 'bg_color' => $isCustomSelection ? 'required|string' : 'nullable|string', | |
| 153 | + 'color' => $isCustomSelection ? 'required|string' : 'nullable|string', | |
| 154 | + 'color_preset' => 'nullable|string', | |
| 149 | 155 | 'label' => 'nullable|string', |
| 150 | 156 | ]); |
| 151 | 157 | try { |
| 152 | - $label = $this->labelService->editLabelofBoard($labelData, $label_id); | |
| 158 | + $label = $this->labelService->editLabelofBoard($labelData, $label_id, $board_id); | |
| 153 | 159 | do_action('fluent_boards/board_label_updated', $label); |
| 154 | 160 | |
| 155 | 161 | return $this->sendSuccess([ |
| 156 | 162 | 'message' => __('Label has been updated', 'fluent-boards'), |