Skip to content

Commit 9bfed0e

Browse files
authored
Merge pull request #119 from imbus/some-more-renaming-stuff
Some more renaming stuff
2 parents dabd04e + b0b9f5d commit 9bfed0e

File tree

69 files changed

+1646
-1629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1646
-1629
lines changed

app/Exceptions/Handler.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,19 @@ public function render($request, Throwable $e)
150150
// Sigh.
151151
if ($route == 'assets.index') {
152152
$route = 'hardware.index';
153-
} elseif ($route == 'reporttemplates.index') {
153+
} else if ($route == 'reporttemplates.index') {
154154
$route = 'reports/custom';
155-
} elseif ($route == 'assetmodels.index') {
155+
} else if ($route == 'assetmodels.index') {
156156
$route = 'models.index';
157-
} elseif ($route == 'predefinedkits.index') {
157+
} else if ($route == 'predefinedkits.index') {
158158
$route = 'kits.index';
159-
} elseif ($route == 'assetmaintenances.index') {
159+
} else if ($route == 'assetmaintenances.index') {
160160
$route = 'maintenances.index';
161-
} elseif ($route === 'licenseseats.index') {
161+
} else if ($route === 'licenseseats.index') {
162162
$route = 'licenses.index';
163-
} elseif (($route === 'customfieldsets.index') || ($route === 'customfields.index')) {
163+
} else if (($route === 'customfieldsets.index') || ($route === 'customfields.index')) {
164164
$route = 'fields.index';
165-
} elseif ($route === 'predefinedfilters.index') {
165+
} else if ($route === 'predefinedfilters.index') {
166166
$route = 'predefined-filters.index';
167167
}
168168

app/Http/Controllers/Api/AssetsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function index(FilterRequest $request, $action = null, $upcoming_status =
148148
$filter = json_decode($request->input('filter'), true);
149149
}
150150

151-
if (!isset($filter[0]['field'])){
151+
if (!isset($filter[0]['field'])) {
152152
$filter = array_filter($filter, function ($key) use ($allowed_columns){
153153
return in_array($key, $allowed_columns);
154154
}, ARRAY_FILTER_USE_KEY);

app/Http/Transformers/PredefinedFiltersTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function transformPredefinedFilter($filter)
4545
'rows' => []
4646
];
4747

48-
foreach ($permissionGroups as $group){
48+
foreach ($permissionGroups as $group) {
4949
$groups['rows'][] = [
5050
'id' => $group->id,
5151
'name' => $group->name

app/Livewire/Notifications.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,21 @@ protected function pushAlert(array $data): void
157157
if (empty($data['message'])) {
158158
return;
159159
}
160+
161+
$alert = $this->buildAlert($data);
162+
163+
if ($alert['tag'] !== null && $this->replaceTaggedAlert($alert)) {
164+
return;
165+
}
166+
167+
$this->addAlert($alert);
168+
}
160169

170+
protected function buildAlert(array $data): array
171+
{
161172
$type = $this->normalizeType($data['type'] ?? 'info');
162-
163-
// Build final alert array
164-
$alert = [
173+
174+
return [
165175
'id' => uniqid('al_', true),
166176
'type' => $type,
167177
'tag' => $data['tag'] ?? null,
@@ -170,22 +180,28 @@ protected function pushAlert(array $data): void
170180
'description' => $data['description'] ?? null,
171181
'icon' => $data['icon'] ?? $this->defaultIcon($type),
172182
'html' => $data['html'] ?? false,
173-
'created_at' => time(),
183+
'created_at' => time(),
174184
];
185+
}
175186

176-
// Tag replacement logic if tag provided
177-
if ($alert['tag'] !== null) {
178-
foreach ($this->liveAlerts as $index => $liveAlert) {
179-
if ($liveAlert['tag'] === $alert['tag']) {
180-
$this->liveAlerts[$index] = $alert;
181-
return;
182-
}
187+
protected function replaceTaggedAlert(array $alert): bool
188+
{
189+
foreach ($this->liveAlerts as $index => $liveAlert) {
190+
if ($liveAlert['tag'] === $alert['tag']) {
191+
$this->liveAlerts[$index] = $alert;
192+
return true;
183193
}
184194
}
195+
196+
return false;
197+
}
185198

199+
protected function addAlert(array $alert): void
200+
{
186201
$this->liveAlerts[] = $alert;
187202
}
188203

204+
189205
/**
190206
* Dismiss by alert unique ID.
191207
*/

app/Livewire/Partials/AdvancedSearch/Modal.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Modal extends Component
4343
protected $listeners = ["groupSelect"];
4444

4545
public ?int $filterId;
46+
4647
public $filterData;
4748

4849
#[On("openPredefinedFiltersModal")]
@@ -81,7 +82,7 @@ public function openPredefinedFiltersModal(
8182
$predefinedFilterId
8283
);
8384

84-
if ($predefinedFilter === null){
85+
if ($predefinedFilter === null) {
8586
$this->showModal = false;
8687
$this->dispatchNotFoundNotification();
8788
return;
@@ -107,6 +108,7 @@ public function openPredefinedFiltersModal(
107108
$this->groupSelect
108109
);
109110
}
111+
// end if
110112

111113
$this->dispatch("openPredefinedFiltersModalEvent");
112114
}
@@ -129,7 +131,7 @@ public function savePredefinedFiltersModal(
129131
) {
130132
$this->validate();
131133

132-
if($this->validateMaxLenghtForFiltername()) {
134+
if ($this->validateMaxLenghtForFiltername()) {
133135
$this->dispatch('showNotificationInFrontend', [
134136
'type' => 'error',
135137
'title' => trans('general.notification_error'),

app/Models/PredefinedFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function userHasPermission(User $user, string $action): bool
8787
default:
8888
return false;
8989
}
90+
// end switch
9091
}
9192

9293
private function checkPermissions(User $user, $action): bool

app/Services/FilterService/FilterService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ protected function handleAssignedTo($value, $inner, $operator){
245245
}
246246

247247
// === 3b. Handle assignedTo asset ===
248-
elseif ($value['type'] === Asset::class) {
248+
else if ($value['type'] === Asset::class) {
249249
$assignedValue = $value['value'];
250250

251251
$this->applyAssignedToAsset($inner, $assignedValue, $operator);
252252
}
253253
// === 3c. Handle assignedTo user ===
254-
elseif ($value['type'] === User::class) {
254+
else if ($value['type'] === User::class) {
255255
$assignedValue = trim((string) ($value['value'] ?? ''));
256256

257257
$this->applyAssignedToUser($inner, $assignedValue, $operator);

app/Services/PredefinedFilterService.php

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function getAllViewableFilters(): Collection
5454
})->values();
5555
}
5656

57-
public function getFilterWithOptionalPermissionsById(int $id, bool $includePredefinedFilterGroups = true)
57+
public function getFilterWithOptionalPermissionsById(int $id, bool $includePredefinedFilterGroups=true)
5858
{
5959
$predefinedFilter = PredefinedFilter::find($id);
6060
if ($includePredefinedFilterGroups && $predefinedFilter) {
@@ -69,7 +69,7 @@ public function getFilterWithIdAndNameValues(int $id)
6969
{
7070
$predefinedFilter = $this->getFilterWithOptionalPermissionsById($id);
7171

72-
if (!$predefinedFilter){
72+
if (!$predefinedFilter) {
7373
return null;
7474
}
7575

@@ -90,15 +90,15 @@ public function getFilterWithIdAndNameValues(int $id)
9090

9191
$model = null;
9292

93-
if (isset($filter['field']) && !in_array($filter['field'], $fieldsToLookup)){
93+
if (isset($filter['field']) && !in_array($filter['field'], $fieldsToLookup)) {
9494
continue;
9595
}
9696

9797
if (!empty($filter['value']) && is_array($filter['value']) && is_int($filter['value'][0])) {
9898

9999
$values =[];
100100

101-
foreach ($filter['value'] as $valueId){
101+
foreach ($filter['value'] as $valueId) {
102102
switch ($filter['field']) {
103103
case 'company':
104104
$model = Company::find($valueId);
@@ -125,7 +125,9 @@ public function getFilterWithIdAndNameValues(int $id)
125125
default:
126126
break;
127127
}
128-
if ($model){
128+
// end switch
129+
130+
if ($model) {
129131
$values[] = [
130132
'id' => $model->id,
131133
'name' => $model->name
@@ -208,51 +210,52 @@ public function deleteFilter(PredefinedFilter $filter): ?bool
208210
public function selectList(Request $request, bool $visibilityInName = false): LengthAwarePaginator
209211
{
210212
$user = Auth::user();
211-
213+
212214
$filters = PredefinedFilter::with("permissionGroups")
213215
->orderBy('name')
214216
->get(['id', 'name', 'created_by', 'is_public']);
215-
216-
$viewableFilters = $filters->filter(function ($filter) use ($user) {
217-
if ($filter->userHasPermission($user, 'view')) {
218-
return true;
219-
}
220-
221-
return false;
222-
})->pluck('id');
223-
217+
218+
$viewableFilters = $filters->filter(fn($f) => $f->userHasPermission($user, 'view'))
219+
->pluck('id');
220+
224221
$query = PredefinedFilter::select(['id', 'name', 'is_public'])
225222
->whereIn('id', $viewableFilters);
223+
224+
$this->applySearchFilter($query, $request);
226225

227-
if ($request->filled('search')) {
228-
$search = trim($request->get('search', ''));
229-
$upper = strtoupper($search);
230-
231-
$privateTag = strtoupper(trans('general.private')) . ':';
232-
$publicTag = strtoupper(trans('general.public')) . ':';
226+
$paginated = $query->orderBy('name')->paginate(50);
233227

234-
if (str_starts_with($upper, 'PRIVATE:') || str_starts_with($upper, $privateTag)) {
235-
$query->where('is_public', 0);
236-
$search = preg_replace('/^(PRIVATE:|' . preg_quote($privateTag, '/') . ')/i', '', $search);
237-
} elseif (str_starts_with($upper, 'PUBLIC:') || str_starts_with($upper, $publicTag)) {
238-
$query->where('is_public', 1);
239-
$search = preg_replace('/^(PUBLIC:|' . preg_quote($publicTag, '/') . ')/i', '', $search);
240-
}
228+
foreach ($paginated as $item) {
229+
$item->use_text = $visibilityInName
230+
? $item->name . ' (' . $this->getVisibilityAsLocalizedString($item->is_public) . ')'
231+
: $item->name;
232+
}
233+
234+
return $paginated;
235+
}
241236

242-
$query->where('name', 'LIKE', '%' . trim($search) . '%');
237+
protected function applySearchFilter($query, Request $request): void
238+
{
239+
if (!$request->filled('search')) {
240+
return;
243241
}
244242

245-
$paginated = $query->orderBy('name')->paginate(50);
243+
$search = trim($request->get('search', ''));
244+
$upper = strtoupper($search);
245+
246+
$private = strtoupper(trans('general.private')) . ':';
247+
$public = strtoupper(trans('general.public')) . ':';
246248

247-
foreach ($paginated as $item) {
248-
if ($visibilityInName === true) {
249-
$item->use_text = $item->name . ' (' . $this->getVisibilityAsLocalizedString($item->is_public) . ')';
250-
} else {
251-
$item->use_text = $item->name;
252-
}
249+
if (str_starts_with($upper, 'PRIVATE:') || str_starts_with($upper, $private)) {
250+
$query->where('is_public', 0);
251+
$search = preg_replace('/^(PRIVATE:|' . preg_quote($private, '/') . ')/i', '', $search);
252+
253+
} elseif (str_starts_with($upper, 'PUBLIC:') || str_starts_with($upper, $public)) {
254+
$query->where('is_public', 1);
255+
$search = preg_replace('/^(PUBLIC:|' . preg_quote($public, '/') . ')/i', '', $search);
253256
}
254-
255-
return $paginated;
257+
258+
$query->where('name', 'LIKE', '%' . trim($search) . '%');
256259
}
257260

258261
private function syncPermissions($currentPermissions, $newPermissions): array

0 commit comments

Comments
 (0)