File tree Expand file tree Collapse file tree 5 files changed +46
-8
lines changed
Expand file tree Collapse file tree 5 files changed +46
-8
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import axios from 'axios';
33import { ref } from ' vue' ;
44
55const props = defineProps ({
6- values : { type: Object , required: true },
6+ action : { type: Object , required: true },
77});
88
99const 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 ?? ' ' ;
3839const show = ref (' tags' );
3940const tags = ref ([]);
4041const urls = ref ([]);
4142
4243axios
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
4950axios
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 })
Original file line number Diff line number Diff line change 44
55use Statamic \Actions \Action ;
66use Statamic \Contracts \Entries \Entry ;
7+ use Statamic \Contracts \Taxonomies \Term ;
78use Statamic \Facades \Blink ;
89use 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
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 33namespace Thoughtco \StatamicCacheTracker \Http \Controllers ;
44
55use Statamic \Http \Controllers \Controller ;
6+ use Statamic \Support \Str ;
67use Thoughtco \StatamicCacheTracker \Facades \Tracker ;
78
89class 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}
Original file line number Diff line number Diff line change 22
33namespace Thoughtco \StatamicCacheTracker \Http \Controllers ;
44
5+ use Statamic \Contracts \Entries \Entry ;
6+ use Statamic \Contracts \Taxonomies \Term ;
7+ use Statamic \Facades \Data ;
58use Statamic \Http \Controllers \Controller ;
9+ use Statamic \Taxonomies \LocalizedTerm ;
610use Thoughtco \StatamicCacheTracker \Facades \Tracker ;
711
812class 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 ' ]))
You can’t perform that action at this time.
0 commit comments