@@ -21,136 +21,59 @@ public function getFormats(): array
2121
2222 public static function getColumns (): array
2323 {
24- return [
25- ExportColumn::make ('id ' )
26- ->label ('ID ' ),
27- ExportColumn::make ('ip_address ' )
28- ->label ('IP address ' )
29- ->state (function (Result $ record ): ?string {
30- return $ record ->ip_address ;
31- })
32- ->enabledByDefault (false ),
33- ExportColumn::make ('isp ' )
34- ->label ('ISP ' )
35- ->state (function (Result $ record ): ?string {
36- return $ record ->isp ;
37- })
38- ->enabledByDefault (false ),
39- ExportColumn::make ('server_location ' )
40- ->label ('Server Location ' )
41- ->state (function (Result $ record ): ?string {
42- return $ record ->server_location ;
43- })
44- ->enabledByDefault (false ),
45- ExportColumn::make ('service ' )
46- ->state (function (Result $ record ) {
47- return $ record ->service ->getLabel ();
48- }),
49- ExportColumn::make ('server_id ' )
50- ->label ('Server ID ' )
51- ->state (function (Result $ record ): ?string {
52- return $ record ->server_id ;
53- })
54- ->enabledByDefault (false ),
55- ExportColumn::make ('server_name ' )
56- ->state (function (Result $ record ): ?string {
57- return $ record ->server_name ;
58- })
59- ->enabledByDefault (false ),
60-
61- ExportColumn::make ('download ' )
62- ->state (function (Result $ record ): ?string {
63- return $ record ->download_bits ;
64- }),
65- ExportColumn::make ('upload ' )
66- ->state (function (Result $ record ): ?string {
67- return $ record ->upload_bits ;
68- }),
69- ExportColumn::make ('ping ' ),
70- ExportColumn::make ('packet_loss ' ),
71- ExportColumn::make ('download_jitter ' )
72- ->state (function (Result $ record ): ?string {
73- return $ record ->download_jitter ;
74- })
75- ->enabledByDefault (false ),
76- ExportColumn::make ('upload_jitter ' )
77- ->state (function (Result $ record ): ?string {
78- return $ record ->upload_jitter ;
79- })
80- ->enabledByDefault (false ),
81- ExportColumn::make ('ping_jitter ' )
82- ->state (function (Result $ record ): ?string {
83- return $ record ->ping_jitter ;
84- })
85- ->enabledByDefault (false ),
86- ExportColumn::make ('ping_low ' )
87- ->state (function (Result $ record ): ?string {
88- return $ record ->ping_low ;
89- })
90- ->enabledByDefault (false ),
91- ExportColumn::make ('ping_high ' )
92- ->state (function (Result $ record ): ?string {
93- return $ record ->ping_high ;
94- })
95- ->enabledByDefault (false ),
96- ExportColumn::make ('upload_latency_high ' )
97- ->state (function (Result $ record ): ?string {
98- return $ record ->upload_latency_high ;
99- })
100- ->enabledByDefault (false ),
101- ExportColumn::make ('upload_latency_low ' )
102- ->state (function (Result $ record ): ?string {
103- return $ record ->upload_latency_low ;
104- })
105- ->enabledByDefault (false ),
106- ExportColumn::make ('upload_latency_avg ' )
107- ->state (function (Result $ record ): ?string {
108- return $ record ->upload_latency_iqm ;
109- })
110- ->enabledByDefault (false ),
111- ExportColumn::make ('download_latency_high ' )
112- ->state (function (Result $ record ): ?string {
113- return $ record ->download_latency_high ;
114- })
115- ->enabledByDefault (false ),
116- ExportColumn::make ('download_latency_low ' )
117- ->state (function (Result $ record ): ?string {
118- return $ record ->download_latency_low ;
119- })
120- ->enabledByDefault (false ),
121- ExportColumn::make ('download_latency_avg ' )
122- ->state (function (Result $ record ): ?string {
123- return $ record ->download_latency_iqm ;
124- })
125- ->enabledByDefault (false ),
126- ExportColumn::make ('result_url ' )
127- ->state (function (Result $ record ) {
128- return $ record ->result_url ;
129- }),
130- ExportColumn::make ('error_message ' )
131- ->state (function (Result $ record ) {
132- return $ record ->error_message ;
133- })
134- ->enabledByDefault (false ),
135- ExportColumn::make ('comments ' )
136- ->enabledByDefault (false ),
137- ExportColumn::make ('status ' )
138- ->state (function (Result $ record ) {
139- return $ record ->status ->getLabel ();
140- }),
141- ExportColumn::make ('scheduled ' )
142- ->state (function (Result $ record ): string {
143- return $ record ->scheduled ? 'Yes ' : 'No ' ;
144- }),
145- ExportColumn::make ('healthy ' )
146- ->state (function (Result $ record ): string {
147- return $ record ->healthy ? 'Yes ' : 'No ' ;
148- })
149- ->enabledByDefault (false ),
24+ $ columns = [
25+ ExportColumn::make ('id ' )->label ('ID ' ),
26+ ExportColumn::make ('service ' )->state (fn (Result $ r ) => $ r ->service ->getLabel ()),
27+ ExportColumn::make ('status ' )->state (fn (Result $ r ) => $ r ->status ->getLabel ()),
28+ ExportColumn::make ('scheduled ' )->state (fn (Result $ r ) => $ r ->scheduled ? 'Yes ' : 'No ' ),
29+ ExportColumn::make ('healthy ' )->state (fn (Result $ r ) => $ r ->healthy ? 'Yes ' : 'No ' ),
15030 ExportColumn::make ('created_at ' ),
151- ExportColumn::make ('updated_at ' )
152- -> enabledByDefault ( false ),
31+ ExportColumn::make ('updated_at ' ),
32+ ExportColumn:: make ( ' comments ' ),
15333 ];
34+
35+ $ columns = array_merge ($ columns , self ::generateDataColumns ());
36+
37+ return $ columns ;
38+ }
39+
40+ protected static function generateDataColumns (): array
41+ {
42+
43+ $ sample = Result::query ()->whereNotNull ('data ' )->first ()?->data ?? [];
44+
45+ $ flattened = self ::flatten ($ sample );
46+
47+ $ columns = [];
48+
49+ foreach ($ flattened as $ key => $ default ) {
50+ $ columns [] = ExportColumn::make ($ key )
51+ ->label (str_replace ('_ ' , ' ' , ucfirst ($ key )))
52+ ->state (function (Result $ r ) use ($ key ) {
53+ $ flattened = self ::flatten ($ r ->data ?? []);
54+
55+ return $ flattened [$ key ] ?? null ;
56+ });
57+ }
58+
59+ return $ columns ;
60+ }
61+
62+ protected static function flatten (array $ array , string $ prefix = '' ): array
63+ {
64+ $ result = [];
65+
66+ foreach ($ array as $ key => $ value ) {
67+ $ newKey = $ prefix ? "{$ prefix }_ {$ key }" : $ key ;
68+
69+ if (is_array ($ value )) {
70+ $ result += self ::flatten ($ value , $ newKey );
71+ } else {
72+ $ result [$ newKey ] = $ value ;
73+ }
74+ }
75+
76+ return $ result ;
15477 }
15578
15679 public static function getCompletedNotificationBody (Export $ export ): string
0 commit comments