diff --git a/src/types/dashboard.d.ts b/src/types/dashboard.d.ts
index 4bb9aa33..b6b578aa 100644
--- a/src/types/dashboard.d.ts
+++ b/src/types/dashboard.d.ts
@@ -38,7 +38,8 @@ export interface LayoutConfig {
metricConfig?: MetricConfigOpt[];
id?: string;
associate?: { widgetId: string }[];
- filters?: { dataIndex: number; sourceId: string };
+ eventAssociate?: boolean;
+ filters?: { dataIndex: number; sourceId: string; isRange?: boolean };
}
export type MetricConfigOpt = {
diff --git a/src/views/dashboard/configuration/Event.vue b/src/views/dashboard/configuration/Event.vue
index 82433732..cdc9ddab 100644
--- a/src/views/dashboard/configuration/Event.vue
+++ b/src/views/dashboard/configuration/Event.vue
@@ -14,7 +14,7 @@ limitations under the License. -->
{{ t("enableAssociate") }}
import { ref, watch, onMounted } from "vue";
import dayjs from "dayjs";
import { useThrottleFn } from "@vueuse/core";
+import { Event } from "@/types/events";
+import { LayoutConfig } from "@/types/dashboard";
import { useEventStore } from "@/store/modules/event";
import { DataSet, Timeline } from "vis-timeline/standalone";
import "vis-timeline/styles/vis-timeline-graph2d.css";
+import { useDashboardStore } from "@/store/modules/dashboard";
+import getDashboard from "@/hooks/useDashboardsSession";
+import dateFormatStep, { dateFormatTime } from "@/utils/dateFormat";
+import { useAppStoreWithOut } from "@/store/modules/app";
const eventStore = useEventStore();
/*global Nullable */
const timeline = ref>(null);
const visGraph = ref>(null);
const oldVal = ref<{ width: number; height: number }>({ width: 0, height: 0 });
+const dashboardStore = useDashboardStore();
+const appStore = useAppStoreWithOut();
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") =>
new Date(dayjs(date).format(pattern));
const visDate = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") =>
@@ -49,12 +57,12 @@ function visTimeline() {
visGraph.value.destroy();
}
const h = timeline.value.getBoundingClientRect().height;
- const events = eventStore.events.map((d, index) => {
+ const events = eventStore.events.map((d: Event, index: number) => {
return {
id: index + 1,
content: d.name,
- start: dateFormat(d.startTime),
- end: dateFormat(d.endTime),
+ start: dateFormat(Number(d.startTime)),
+ end: dateFormat(Number(d.endTime)),
data: d,
className: d.type,
};
@@ -68,7 +76,7 @@ function visTimeline() {
autoResize: false,
tooltip: {
overflowMethod: "cap",
- template(item) {
+ template(item: Event | any) {
const data = item.data || {};
let tmp = `ID: ${data.uuid || ""}
Name: ${data.name || ""}
@@ -88,6 +96,43 @@ function visTimeline() {
},
};
visGraph.value = new Timeline(timeline.value, items, options);
+ visGraph.value.on("select", (properties: { items: number[] }) => {
+ if (!dashboardStore.selectedGrid.eventAssociate) {
+ return;
+ }
+ const all = getDashboard(dashboardStore.currentDashboard).widgets;
+ const widgets = all.filter(
+ (d: { value: string; label: string } & LayoutConfig) => {
+ const isLinear = ["Bar", "Line", "Area"].includes(
+ (d.graph && d.graph.type) || ""
+ );
+ if (isLinear) {
+ return d;
+ }
+ }
+ );
+ const index = properties.items[0];
+ const i = items[index];
+ for (const widget of widgets) {
+ const startTime: string = dateFormatTime(
+ new Date(i.startTime),
+ appStore.duration.step
+ );
+ const endTime: string = dateFormatTime(
+ new Date(i.endTime),
+ appStore.duration.step
+ );
+ widget.filters = {
+ sourceId: dashboardStore.selectedGrid.id || "",
+ isRange: true,
+ duration: {
+ startTime,
+ endTime,
+ },
+ };
+ dashboardStore.setWidget(widget);
+ }
+ });
}
function resize() {
const observer = new ResizeObserver((entries) => {