Skip to content

Commit a576ed2

Browse files
committed
Make it work
1 parent 8a3d51b commit a576ed2

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

resources/js/components/CacheTrackerModal.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import axios from 'axios';
33
import { ref } from 'vue';
44
55
const props = defineProps({
6-
values: { type: Object, required: true },
6+
action: { type: Object, required: true },
77
});
88
99
const getColor = (tag) => {
@@ -34,20 +34,21 @@ const setShowWhat = (what) => {
3434
show.value = what;
3535
}
3636
37-
const item = props.values?.length ? (props.values[0] ?? '') : '';
37+
const item = props.action?.item_title ?? '';
38+
const url = props.action?.item_url ?? '';
3839
const show = ref('tags');
3940
const tags = ref([]);
4041
const urls = ref([]);
4142
4243
axios
43-
.post(cp_url(`/cache-tracker/tags`), { item: item })
44+
.post(cp_url(`/cache-tracker/tags`), { url: url })
4445
.then(response => {
4546
tags.value = response.data;
4647
})
4748
.catch((e) => { });
4849
4950
axios
50-
.post(cp_url(`/cache-tracker/urls`), { item: item })
51+
.post(cp_url(`/cache-tracker/urls`), { url: url })
5152
.then(response => {
5253
urls.value = response.data;
5354
})

src/Actions/ClearCache.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Statamic\Actions\Action;
66
use Statamic\Contracts\Entries\Entry;
7+
use Statamic\Contracts\Taxonomies\Term;
78
use Statamic\Facades\Blink;
89
use Thoughtco\StatamicCacheTracker\Facades\Tracker;
910

@@ -33,7 +34,7 @@ public function visibleTo($item)
3334
return false;
3435
}
3536

36-
if (! $item instanceof Entry) {
37+
if (! ($item instanceof Entry || $item instanceof Term)) {
3738
return false;
3839
}
3940

src/Actions/ViewCacheTags.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,13 @@ public function buttonText()
5353
/** @translation */
5454
return __('Clear cache');
5555
}
56+
57+
public function toArray()
58+
{
59+
return [
60+
...parent::toArray(),
61+
'item_title' => $this->items->first()?->title,
62+
'item_url' => $this->items->first()?->absoluteUrl(),
63+
];
64+
}
5665
}

src/Http/Controllers/GetTagsController.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
namespace Thoughtco\StatamicCacheTracker\Http\Controllers;
44

55
use Statamic\Http\Controllers\Controller;
6+
use Statamic\Support\Str;
67
use Thoughtco\StatamicCacheTracker\Facades\Tracker;
78

89
class GetTagsController extends Controller
910
{
1011
public function __invoke(): array
1112
{
12-
if (! $url = request()->input('item')) {
13+
if (! $url = request()->input('url')) {
1314
return [];
1415
}
1516

16-
return Tracker::get($url) ?? []; //
17+
if (Str::endsWith($url, '/')) {
18+
$url = Str::beforeLast($url, '/');
19+
}
20+
21+
if ($data = Tracker::get($url)) {
22+
return $data['tags'];
23+
}
24+
25+
return [];
1726
}
1827
}

src/Http/Controllers/GetUrlsController.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@
22

33
namespace Thoughtco\StatamicCacheTracker\Http\Controllers;
44

5+
use Statamic\Contracts\Entries\Entry;
6+
use Statamic\Contracts\Taxonomies\Term;
7+
use Statamic\Facades\Data;
58
use Statamic\Http\Controllers\Controller;
9+
use Statamic\Taxonomies\LocalizedTerm;
610
use Thoughtco\StatamicCacheTracker\Facades\Tracker;
711

812
class GetUrlsController extends Controller
913
{
1014
public function __invoke(): array
1115
{
12-
$item = request()->input('item');
16+
if (! $url = request()->input('url')) {
17+
return [];
18+
}
19+
20+
if (! $item = Data::find($url)) {
21+
return [];
22+
}
23+
24+
if ($item instanceof Entry) {
25+
$item = $item->collectionHandle().':'.$item->id();
26+
}
27+
28+
if ($item instanceof Term) {
29+
$item = $item->taxonomyHandle().':'.$item->id();
30+
}
1331

1432
return collect(Tracker::all())
1533
->filter(fn ($tracked) => in_array($item, $tracked['tags']))

0 commit comments

Comments
 (0)