EntitiesView.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <Section class = "with-header-and-content" v-if="entityDefinitions.length === 0" title="Loading entity definitions...">
  3. <div class = "section-header">
  4. <h2 class="loading-message">
  5. Loading entity definitions...
  6. </h2>
  7. </div>
  8. </Section>
  9. <template v-else>
  10. <Section v-for="def in entityDefinitions" :key="def.title" :title="'Entity: ' + def.title ">
  11. <div class = "section-content">
  12. <p>{{ def.instances.length }} instances.</p>
  13. <ul>
  14. <li v-for="inst in def.instances" :key="inst.uniqueKey">
  15. <router-link :to="{ name: 'EntityDetails', params: { entityType: inst.type, entityKey: inst.uniqueKey } }">
  16. {{ inst.title }}
  17. </router-link>
  18. </li>
  19. </ul>
  20. <h3>Used on Dashboards:</h3>
  21. <ul>
  22. <li v-for="dash in filteredDashboards(def.usedOnDashboards)" :key="dash">
  23. <template v-if="isEntityDirectory(dash)">
  24. {{ getDashboardTitle(dash) }} <span class="entity-directory-label">[Entity Directory]</span>
  25. </template>
  26. <router-link v-else-if="!dash.includes('entity:')" :to="{ name: 'Dashboard', params: { title: getDashboardTitle(dash) } }">
  27. {{ getDashboardTitle(dash) }}
  28. </router-link>
  29. <span v-else>{{ dash }}</span>
  30. </li>
  31. </ul>
  32. </div>
  33. </Section>
  34. </template>
  35. </template>
  36. <script setup>
  37. import { ref, onMounted } from 'vue'
  38. import Section from 'picocrank/vue/components/Section.vue'
  39. const entityDefinitions = ref([])
  40. async function fetchEntities() {
  41. const ret = await window.client.getEntities()
  42. entityDefinitions.value = ret.entityDefinitions
  43. }
  44. function filteredDashboards(dashboards) {
  45. return dashboards.filter(d => d && !d.includes('{{'))
  46. }
  47. function isEntityDirectory(dashboardTitle) {
  48. return dashboardTitle.endsWith(' [Entity Directory]')
  49. }
  50. function getDashboardTitle(dashboardTitle) {
  51. if (isEntityDirectory(dashboardTitle)) {
  52. return dashboardTitle.slice(0, -' [Entity Directory]'.length)
  53. }
  54. return dashboardTitle
  55. }
  56. onMounted(() => {
  57. fetchEntities()
  58. })
  59. </script>