Skip to content

Commit 9d0209c

Browse files
authored
Merge pull request #1293 from KodeStar/2.x
Fixes to tags and show tags on application list
2 parents 809a997 + 599035b commit 9d0209c

File tree

9 files changed

+55
-27
lines changed

9 files changed

+55
-27
lines changed

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 (mixed $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');

public/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ $.when($.ready).then(() => {
178178
$(e.target).addClass("current");
179179
$("#sortable .item-container").show();
180180
if (tag !== "all") {
181-
$("#sortable .item-container:not(." + tag + ")").hide();
181+
$(`#sortable .item-container:not(.${tag})`).hide();
182182
}
183183
})
184184
.on("click", "#add-item, #pin-item", (e) => {

resources/views/items/form.blade.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
{!! Form::hidden('pinned', '0') !!}
88
<label class="switch">
99
<?php
10-
$checked = false;
11-
if(isset($item->pinned) && (bool)$item->pinned === true) $checked = true;
10+
$checked = true;
11+
if(isset($item->pinned) && (bool)$item->pinned !== true) $checked = false;
1212
$set_checked = ($checked) ? ' checked="checked"' : '';
1313
?>
1414
<input type="checkbox" name="pinned" value="1"<?php echo $set_checked;?> />
@@ -57,17 +57,17 @@
5757
{!! csrf_field() !!}
5858
<div class="input">
5959
<label>{{ __('app.apps.application_name') }} *</label>
60-
{!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'id' => 'appname', 'class' => 'form-control')) !!}
60+
{!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'id' => 'appname', 'class' => 'form-control', 'required')) !!}
6161
</div>
6262

6363
<div class="input">
64-
<label>{{ __('app.apps.colour') }} *</label>
64+
<label>{{ __('app.apps.colour') }}</label>
6565
{!! Form::text('colour', $item->colour ?? '#161b1f', array('placeholder' => __('app.apps.hex'), 'id' => 'appcolour', 'class' => 'form-control color-picker set-bg-elem')) !!}
6666
</div>
6767

6868
<div class="input">
69-
<label>{{ strtoupper(__('app.url')) }}</label>
70-
{!! Form::text('url', $item->url ?? null, array('placeholder' => __('app.url'), 'id' => 'appurl', 'class' => 'form-control')) !!}
69+
<label>{{ strtoupper(__('app.url')) }} *</label>
70+
{!! Form::text('url', $item->url ?? null, array('placeholder' => __('app.url'), 'id' => 'appurl', 'class' => 'form-control', 'required')) !!}
7171
<small class="help">Don't forget http(s)://</small>
7272
</div>
7373

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

resources/views/tags/form.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111

1212
<div class="input">
1313
<label>{{ __('app.apps.tag_name') }} *</label>
14-
{!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'class' => 'form-control')) !!}
14+
{!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'class' => 'form-control', 'required')) !!}
1515
<hr />
1616
<label>{{ __('app.apps.pinned') }}</label>
1717
{!! Form::hidden('pinned', '0') !!}
1818
<label class="switch">
1919
<?php
20-
$checked = false;
21-
if(isset($item->pinned) && (bool)$item->pinned === true) $checked = true;
20+
$checked = true;
21+
if(isset($item->pinned) && (bool)$item->pinned !== true) $checked = false;
2222
$set_checked = ($checked) ? ' checked="checked"' : '';
2323
?>
2424
<input type="checkbox" name="pinned" value="1"<?php echo $set_checked;?> />
2525
<span class="slider round"></span>
2626
</label>
2727
</div>
2828
<div class="input">
29-
<label>{{ __('app.apps.colour') }} *</label>
29+
<label>{{ __('app.apps.colour') }}</label>
3030
{!! Form::text('colour', null, array('placeholder' => __('app.apps.hex'),'class' => 'form-control color-picker')) !!}
3131
<hr />
3232
</div>

0 commit comments

Comments
 (0)