Merge pull request #1293 from KodeStar/2.x

Fixes to tags and show tags on application list
This commit is contained in:
KodeStar
2024-02-19 11:08:18 +00:00
committed by GitHub
9 changed files with 55 additions and 27 deletions

View File

@@ -47,7 +47,9 @@ class ItemController extends Controller
} elseif ($treat_tags_as == 'tags') {
$data['apps'] = Item::with('parents')->where('type', 0)->pinned()->orderBy('order', 'asc')->get();
$data['all_apps'] = Item::where('type', 0)->orderBy('order', 'asc')->get();
$data['taglist'] = Item::where('type', 1)->pinned()->orderBy('order', 'asc')->get();
$data['taglist'] = Item::where('id', 0)->orWhere(function($query) {
$query->where('type', 1)->pinned();
})->orderBy('order', 'asc')->get();
} else {
$data['apps'] = Item::whereHas('parents', function ($query) {
@@ -56,7 +58,9 @@ class ItemController extends Controller
$data['all_apps'] = Item::whereHas('parents', function ($query) {
$query->where('id', 0);
})->orWhere('type', 1)->orderBy('order', 'asc')->get();
})->orWhere(function ($query) {
$query->where('type', 1)->whereNot('id', 0);
})->orderBy('order', 'asc')->get();
}
//$data['all_apps'] = Item::doesntHave('parents')->get();

View File

@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Casts\Attribute;
use stdClass;
use Symfony\Component\ClassLoader\ClassMapGenerator;
@@ -133,26 +134,33 @@ class Item extends Model
$id = $this->id;
$tags = ItemTag::select('tag_id')->where('item_id', $id)->pluck('tag_id')->toArray();
$tagdetails = self::select('id', 'title', 'url', 'pinned')->whereIn('id', $tags)->get();
//print_r($tags);
if (in_array(0, $tags)) {
$details = new self([
'id' => 0,
'title' => __('app.dashboard'),
'url' => '',
'pinned' => 0,
]);
$tagdetails->prepend($details);
}
return $tagdetails;
}
protected function title(): Attribute
{
return Attribute::make(
get: fn (mixed $value) => ($value === 'app.dashboard' ? __('app.dashboard') : $value),
);
}
protected function tagUrl(): Attribute
{
return Attribute::make(
get: fn (mixed $value, array $attributes) => ($attributes['id'] === 0 ? '0-dash' : $attributes['url']),
);
}
public function getTagClass(): string
{
$tags = $this->tags();
$slugs = [];
foreach ($tags as $tag) {
if ($tag->id === 0) {
$tag->url = '0-dash';
}
if ($tag->url) {
$slugs[] = 'tag-'.$tag->url;
}
@@ -161,6 +169,20 @@ class Item extends Model
return implode(' ', $slugs);
}
public function getTagList(): string
{
$tags = $this->tags();
$titles = [];
// print_r($tags);
foreach ($tags as $tag) {
if ($tag->title) {
$titles[] = $tag->title;
}
}
return implode(', ', $titles);
}
public function parents(): BelongsToMany
{
return $this->belongsToMany(Item::class, 'item_tag', 'item_id', 'tag_id');

2
public/js/app.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,4 @@
{
"/css/app.css": "/css/app.css?id=9ac09de3efefe57251cba47c5747c556",
"/js/app.js": "/js/app.js?id=3e28afce465cda43c0b0da9d29ad69a1"
"/js/app.js": "/js/app.js?id=a3df64b8054d7a3f742957b38d687835"
}

View File

@@ -178,7 +178,7 @@ $.when($.ready).then(() => {
$(e.target).addClass("current");
$("#sortable .item-container").show();
if (tag !== "all") {
$("#sortable .item-container:not(." + tag + ")").hide();
$(`#sortable .item-container:not(.${tag})`).hide();
}
})
.on("click", "#add-item, #pin-item", (e) => {

View File

@@ -7,8 +7,8 @@
{!! Form::hidden('pinned', '0') !!}
<label class="switch">
<?php
$checked = false;
if(isset($item->pinned) && (bool)$item->pinned === true) $checked = true;
$checked = true;
if(isset($item->pinned) && (bool)$item->pinned !== true) $checked = false;
$set_checked = ($checked) ? ' checked="checked"' : '';
?>
<input type="checkbox" name="pinned" value="1"<?php echo $set_checked;?> />
@@ -57,17 +57,17 @@
{!! csrf_field() !!}
<div class="input">
<label>{{ __('app.apps.application_name') }} *</label>
{!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'id' => 'appname', 'class' => 'form-control')) !!}
{!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'id' => 'appname', 'class' => 'form-control', 'required')) !!}
</div>
<div class="input">
<label>{{ __('app.apps.colour') }} *</label>
<label>{{ __('app.apps.colour') }}</label>
{!! Form::text('colour', $item->colour ?? '#161b1f', array('placeholder' => __('app.apps.hex'), 'id' => 'appcolour', 'class' => 'form-control color-picker set-bg-elem')) !!}
</div>
<div class="input">
<label>{{ strtoupper(__('app.url')) }}</label>
{!! Form::text('url', $item->url ?? null, array('placeholder' => __('app.url'), 'id' => 'appurl', 'class' => 'form-control')) !!}
<label>{{ strtoupper(__('app.url')) }} *</label>
{!! Form::text('url', $item->url ?? null, array('placeholder' => __('app.url'), 'id' => 'appurl', 'class' => 'form-control', 'required')) !!}
<small class="help">Don't forget http(s)://</small>
</div>

View File

@@ -22,6 +22,7 @@
<tr>
<th>{{ __('app.title') }}</th>
<th>{{ __('app.url') }}</th>
<th>{{ __('app.apps.tags') }}</th>
<th class="text-center" width="100">{{ __('app.settings.edit') }}</th>
<th class="text-center" width="100">{{ __('app.delete') }}</th>
</tr>
@@ -32,6 +33,7 @@
<tr>
<td>{{ $app->title }}</td>
<td><a href="{{ $app->url }}">{{ $app->link }}</a></td>
<td>{{ $app->getTagList() }}</td>
<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>
<td class="text-center">
{!! Form::open(['method' => 'DELETE','route' => ['items.destroy', $app->id],'style'=>'display:inline']) !!}
@@ -42,7 +44,7 @@
@endforeach
@else
<tr>
<td colspan="4" class="form-error text-center">
<td colspan="5" class="form-error text-center">
<strong>{{ __('app.settings.no_items') }}</strong>
</td>
</tr>

View File

@@ -6,7 +6,7 @@ $treat_tags_as = \App\Setting::fetch('treat_tags_as');
<div id="taglist" class="taglist">
<div class="tag white current" data-tag="all">All</div>
@foreach($taglist as $tag)
<div class="tag link{{ title_color($tag->colour) }}" style="background-color: {{ $tag->colour }}" data-tag="tag-{{ $tag->url }}">{{ $tag->title }}</div>
<div class="tag link{{ title_color($tag->colour) }}" style="background-color: {{ $tag->colour }}" data-tag="tag-{{ $tag->tag_url }}">{{ $tag->title }}</div>
@endforeach
</div>
@endif

View File

@@ -11,14 +11,14 @@
<div class="input">
<label>{{ __('app.apps.tag_name') }} *</label>
{!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'class' => 'form-control')) !!}
{!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'class' => 'form-control', 'required')) !!}
<hr />
<label>{{ __('app.apps.pinned') }}</label>
{!! Form::hidden('pinned', '0') !!}
<label class="switch">
<?php
$checked = false;
if(isset($item->pinned) && (bool)$item->pinned === true) $checked = true;
$checked = true;
if(isset($item->pinned) && (bool)$item->pinned !== true) $checked = false;
$set_checked = ($checked) ? ' checked="checked"' : '';
?>
<input type="checkbox" name="pinned" value="1"<?php echo $set_checked;?> />
@@ -26,7 +26,7 @@
</label>
</div>
<div class="input">
<label>{{ __('app.apps.colour') }} *</label>
<label>{{ __('app.apps.colour') }}</label>
{!! Form::text('colour', null, array('placeholder' => __('app.apps.hex'),'class' => 'form-control color-picker')) !!}
<hr />
</div>