| 1 | <template> |
| 2 | <div class="pipe-list"> |
| 3 | <n-card content-class="px-0!"> |
| 4 | <n-spin :show="loading" content-class="min-h-7"> |
| 5 | <n-collapse v-if="pipelines.length" v-model:expanded-names="selectedPipeline" accordion> |
| 6 | <n-collapse-item |
| 7 | v-for="pipe of pipelines" |
| 8 | :key="pipe.id" |
| 9 | :title="pipe.title" |
| 10 | :name="pipe.id" |
| 11 | class="px-5" |
| 12 | > |
| 13 | <template #header> |
| 14 | <PipeTitle :pipeline="pipe" /> |
| 15 | </template> |
| 16 | <template #header-extra> |
| 17 | <n-button size="small" @click.stop="openModal(pipe)"> |
| 18 | <template #icon> |
| 19 | <Icon :name="InfoIcon" /> |
| 20 | </template> |
| 21 | </n-button> |
| 22 | </template> |
| 23 | <div class="overflow-hidden"> |
| 24 | <PipeDetails :pipeline="pipe" @click-rule="emit('openRule', $event)" /> |
| 25 | </div> |
| 26 | </n-collapse-item> |
| 27 | </n-collapse> |
| 28 | <template v-else> |
| 29 | <n-empty v-if="!loading" description="No pipelines found" class="h-32 justify-center" /> |
| 30 | </template> |
| 31 | </n-spin> |
| 32 | </n-card> |
| 33 | |
| 34 | <n-modal |
| 35 | v-model:show="showDetails" |
| 36 | preset="card" |
| 37 | content-class="p-0!" |
| 38 | :style="{ maxWidth: 'min(600px, 90vw)', overflow: 'hidden' }" |
| 39 | :title="highlightPipe?.title" |
| 40 | :bordered="false" |
| 41 | segmented |
| 42 | > |
| 43 | <PipeInfo :pipeline="highlightPipe" /> |
| 44 | </n-modal> |
| 45 | </div> |
| 46 | </template> |
| 47 | |
| 48 | <script setup lang="ts"> |
| 49 | // TODO-FE: refactor |
| 50 | import type { PipelineFull } from "@/types/graylog/pipelines.d" |
| 51 | import { NButton, NCard, NCollapse, NCollapseItem, NEmpty, NModal, NSpin, useMessage } from "naive-ui" |
| 52 | import { onBeforeMount, ref, watch } from "vue" |
| 53 | import Api from "@/api" |
| 54 | import Icon from "@/components/common/Icon.vue" |
| 55 | import PipeDetails from "@/components/graylog/Pipelines/PipeDetails.vue" |
| 56 | import PipeInfo from "@/components/graylog/Pipelines/PipeInfo.vue" |
| 57 | import PipeTitle from "@/components/graylog/Pipelines/PipeTitle.vue" |
| 58 | |
| 59 | const emit = defineEmits<{ |
| 60 | (e: "openRule", value: string): void |
| 61 | }>() |
| 62 | |
| 63 | const InfoIcon = "carbon:information" |
| 64 | |
| 65 | const message = useMessage() |
| 66 | const showDetails = ref(false) |
| 67 | const loading = ref(false) |
| 68 | const pipelines = ref<PipelineFull[]>([]) |
| 69 | const selectedPipeline = ref<string | null>(null) |
| 70 | const highlightPipe = ref<PipelineFull | undefined>(undefined) |
| 71 | const highlightRule = ref<string | null>(null) |
| 72 | const showRulesDrawer = ref(false) |
| 73 | |
| 74 | function setHighlightPipe(pipeline: PipelineFull) { |
| 75 | highlightPipe.value = pipeline |
| 76 | } |
| 77 | |
| 78 | function openModal(pipeline: PipelineFull) { |
| 79 | setHighlightPipe(pipeline) |
| 80 | showDetails.value = true |
| 81 | } |
| 82 | |
| 83 | function getPipelines() { |
| 84 | loading.value = true |
| 85 | |
| 86 | Api.graylog |
| 87 | .getPipelinesFull() |
| 88 | .then(res => { |
| 89 | if (res.data.success) { |
| 90 | pipelines.value = res.data.pipelines || [] |
| 91 | if (pipelines.value.length && !selectedPipeline.value) { |
| 92 | selectedPipeline.value = pipelines.value[0]?.id ?? null |
| 93 | } |
| 94 | } else { |
| 95 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 96 | } |
| 97 | }) |
| 98 | .catch(err => { |
| 99 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 100 | }) |
| 101 | .finally(() => { |
| 102 | loading.value = false |
| 103 | }) |
| 104 | } |
| 105 | |
| 106 | watch(showRulesDrawer, val => { |
| 107 | if (!val) { |
| 108 | highlightRule.value = null |
| 109 | } |
| 110 | }) |
| 111 | |
| 112 | onBeforeMount(() => { |
| 113 | getPipelines() |
| 114 | // MOCK |
| 115 | /* |
| 116 | pipelines.value = pipeline_full |
| 117 | */ |
| 118 | }) |
| 119 | </script> |