Skip to content

Commit f3bc6ab

Browse files
author
Chris Hunt
committed
Add tags to application list, and fix home dashboard tag
1 parent 09e4bb8 commit f3bc6ab

4 files changed

Lines changed: 42 additions & 14 deletions

File tree

app/Http/Controllers/ItemController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public function dash(): View
4747
} elseif ($treat_tags_as == 'tags') {
4848
$data['apps'] = Item::with('parents')->where('type', 0)->pinned()->orderBy('order', 'asc')->get();
4949
$data['all_apps'] = Item::where('type', 0)->orderBy('order', 'asc')->get();
50-
$data['taglist'] = Item::where('type', 1)->pinned()->orderBy('order', 'asc')->get();
50+
$data['taglist'] = Item::where('id', 0)->orWhere(function($query) {
51+
$query->where('type', 1)->pinned();
52+
})->orderBy('order', 'asc')->get();
5153
} else {
5254

5355
$data['apps'] = Item::whereHas('parents', function ($query) {
@@ -56,7 +58,9 @@ public function dash(): View
5658

5759
$data['all_apps'] = Item::whereHas('parents', function ($query) {
5860
$query->where('id', 0);
59-
})->orWhere('type', 1)->orderBy('order', 'asc')->get();
61+
})->orWhere(function ($query) {
62+
$query->where('type', 1)->whereNot('id', 0);
63+
})->orderBy('order', 'asc')->get();
6064
}
6165

6266
//$data['all_apps'] = Item::doesntHave('parents')->get();

app/Item.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1010
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
1111
use Illuminate\Database\Eloquent\SoftDeletes;
12+
use Illuminate\Database\Eloquent\Casts\Attribute;
1213
use stdClass;
1314
use Symfony\Component\ClassLoader\ClassMapGenerator;
1415

@@ -133,26 +134,33 @@ public function tags()
133134
$id = $this->id;
134135
$tags = ItemTag::select('tag_id')->where('item_id', $id)->pluck('tag_id')->toArray();
135136
$tagdetails = self::select('id', 'title', 'url', 'pinned')->whereIn('id', $tags)->get();
136-
//print_r($tags);
137-
if (in_array(0, $tags)) {
138-
$details = new self([
139-
'id' => 0,
140-
'title' => __('app.dashboard'),
141-
'url' => '',
142-
'pinned' => 0,
143-
]);
144-
$tagdetails->prepend($details);
145-
}
146137

147138
return $tagdetails;
148139
}
149140

141+
protected function title(): Attribute
142+
{
143+
return Attribute::make(
144+
get: fn (string $value) => ($value === 'app.dashboard' ? __('app.dashboard') : $value),
145+
);
146+
}
147+
148+
protected function tagUrl(): Attribute
149+
{
150+
return Attribute::make(
151+
get: fn (mixed $value, array $attributes) => ($attributes['id'] === 0 ? '0-dash' : $attributes['url']),
152+
);
153+
}
154+
150155
public function getTagClass(): string
151156
{
152157
$tags = $this->tags();
153158
$slugs = [];
154159

155160
foreach ($tags as $tag) {
161+
if ($tag->id === 0) {
162+
$tag->url = '0-dash';
163+
}
156164
if ($tag->url) {
157165
$slugs[] = 'tag-'.$tag->url;
158166
}
@@ -161,6 +169,20 @@ public function getTagClass(): string
161169
return implode(' ', $slugs);
162170
}
163171

172+
public function getTagList(): string
173+
{
174+
$tags = $this->tags();
175+
$titles = [];
176+
// print_r($tags);
177+
foreach ($tags as $tag) {
178+
if ($tag->title) {
179+
$titles[] = $tag->title;
180+
}
181+
}
182+
183+
return implode(', ', $titles);
184+
}
185+
164186
public function parents(): BelongsToMany
165187
{
166188
return $this->belongsToMany(Item::class, 'item_tag', 'item_id', 'tag_id');

resources/views/items/list.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<tr>
2323
<th>{{ __('app.title') }}</th>
2424
<th>{{ __('app.url') }}</th>
25+
<th>{{ __('app.apps.tags') }}</th>
2526
<th class="text-center" width="100">{{ __('app.settings.edit') }}</th>
2627
<th class="text-center" width="100">{{ __('app.delete') }}</th>
2728
</tr>
@@ -32,6 +33,7 @@
3233
<tr>
3334
<td>{{ $app->title }}</td>
3435
<td><a href="{{ $app->url }}">{{ $app->link }}</a></td>
36+
<td>{{ $app->getTagList() }}</td>
3537
<td class="text-center"><a{{ $app->target }} href="{!! route('items.edit', [$app->id]) !!}" title="{{ __('app.settings.edit') }} {{ $app->title }}"><i class="fas fa-edit"></i></a></td>
3638
<td class="text-center">
3739
{!! Form::open(['method' => 'DELETE','route' => ['items.destroy', $app->id],'style'=>'display:inline']) !!}
@@ -42,7 +44,7 @@
4244
@endforeach
4345
@else
4446
<tr>
45-
<td colspan="4" class="form-error text-center">
47+
<td colspan="5" class="form-error text-center">
4648
<strong>{{ __('app.settings.no_items') }}</strong>
4749
</td>
4850
</tr>

resources/views/partials/taglist.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div id="taglist" class="taglist">
77
<div class="tag white current" data-tag="all">All</div>
88
@foreach($taglist as $tag)
9-
<div class="tag link{{ title_color($tag->colour) }}" style="background-color: {{ $tag->colour }}" data-tag="tag-{{ $tag->url }}">{{ $tag->title }}</div>
9+
<div class="tag link{{ title_color($tag->colour) }}" style="background-color: {{ $tag->colour }}" data-tag="tag-{{ $tag->tag_url }}">{{ $tag->title }}</div>
1010
@endforeach
1111
</div>
1212
@endif

0 commit comments

Comments
 (0)