|
| 1 | +<script setup> |
| 2 | +import axios from 'axios'; |
| 3 | +import { ref } from 'vue'; |
| 4 | +
|
| 5 | +const props = defineProps({ |
| 6 | + action: { type: Object, required: true }, |
| 7 | +}); |
| 8 | +
|
| 9 | +const getColor = (tag) => { |
| 10 | + if (tag.indexOf('collection:') === 0) { |
| 11 | + return 'yellow'; |
| 12 | + } |
| 13 | +
|
| 14 | + if (tag.indexOf('term:') === 0) { |
| 15 | + return 'rose'; |
| 16 | + } |
| 17 | +
|
| 18 | + if (tag.indexOf('global:') === 0) { |
| 19 | + return 'violet'; |
| 20 | + } |
| 21 | +
|
| 22 | + if (tag.indexOf('partial:') === 0) { |
| 23 | + return 'blue'; |
| 24 | + } |
| 25 | +
|
| 26 | + return 'green'; |
| 27 | +} |
| 28 | +
|
| 29 | +const setShowWhat = (what) => { |
| 30 | + show.value = what; |
| 31 | +} |
| 32 | +
|
| 33 | +const item = props.action?.item_title ?? ''; |
| 34 | +const url = props.action?.item_url ?? ''; |
| 35 | +const show = ref('tags'); |
| 36 | +const tags = ref([]); |
| 37 | +const urls = ref([]); |
| 38 | +
|
| 39 | +axios |
| 40 | + .post(cp_url(`/cache-tracker/tags`), { url: url }) |
| 41 | + .then(response => { |
| 42 | + tags.value = response.data; |
| 43 | + }) |
| 44 | + .catch((e) => { }); |
| 45 | +
|
| 46 | +axios |
| 47 | + .post(cp_url(`/cache-tracker/urls`), { url: url }) |
| 48 | + .then(response => { |
| 49 | + urls.value = response.data; |
| 50 | + }) |
| 51 | + .catch((e) => { }); |
| 52 | +</script> |
| 53 | +
|
| 54 | +<template> |
| 55 | + <div> |
| 56 | + <ui-button-group class="mb-4"> |
| 57 | + <ui-button :variant="show == 'tags' ? 'primary' : 'default'" size="sm" @click="setShowWhat('tags')">Tags on this URL</ui-button> |
| 58 | + <ui-button :variant="show == 'urls' ? 'primary' : 'default'" size="sm" @click="setShowWhat('urls')">URLs with this item</ui-button> |
| 59 | + </ui-button-group> |
| 60 | +
|
| 61 | + <div v-if="show == 'tags'"> |
| 62 | +
|
| 63 | + <ui-description v-text="__('There are no tags tracked on :url.', { url: url })" v-if="tags.length < 1"></ui-description> |
| 64 | +
|
| 65 | + <ui-description v-text="__('The following tags are being tracked on :url:', { url: url })" v-if="tags.length"></ui-description> |
| 66 | +
|
| 67 | + <div class="flex gap-2 mt-4" v-if="tags.length"> |
| 68 | +
|
| 69 | + <template v-for="tag in tags"> |
| 70 | + <ui-badge pill :color="getColor(tag)" v-text="tag"></ui-badge> |
| 71 | + </template> |
| 72 | +
|
| 73 | + </div> |
| 74 | +
|
| 75 | + </div> |
| 76 | +
|
| 77 | + <div v-if="show == 'urls'"> |
| 78 | + <ui-description v-text="__('There are no urls tracked containing :item.', { item: item })" v-if="urls.length < 1"></ui-description> |
| 79 | +
|
| 80 | + <ui-description v-text="__('The following URLs contain :item:', { item: 'ryan' })" v-if="urls.length"></ui-description> |
| 81 | +
|
| 82 | + <div class="flex gap-2 mt-4" v-if="urls.length"> |
| 83 | +
|
| 84 | + <template v-for="url in urls"> |
| 85 | + <a :href="url" v-text="url"></a><br /> |
| 86 | + </template> |
| 87 | +
|
| 88 | + </div> |
| 89 | +
|
| 90 | + </div> |
| 91 | + </div> |
| 92 | +</template> |
0 commit comments