-module(spectator@internal@views@process_table). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([render/10]). -file("/Users/jonas/Projects/spectator/src/spectator/internal/views/process_table.gleam", 13). -spec render_name(spectator@internal@api:process_item()) -> lustre@internals@vdom:element(any()). render_name(Process) -> case erlang:element(4, erlang:element(3, Process)) of none -> spectator@internal@views@display:pid(erlang:element(2, Process)); {some, Name} -> lustre@element@html:text(erlang:atom_to_binary(Name)) end. -file("/Users/jonas/Projects/spectator/src/spectator/internal/views/process_table.gleam", 20). -spec render_tag(spectator@internal@api:process_item()) -> lustre@internals@vdom:element(any()). render_tag(Process) -> case erlang:element(8, erlang:element(3, Process)) of none -> spectator@internal@views@display:function( erlang:element(3, erlang:element(3, Process)) ); {some, <<"__spectator_internal "/utf8, Rest/binary>>} -> lustre@element@html:text(<<"🔍 "/utf8, Rest/binary>>); {some, Tag} -> lustre@element@html:text(<<"🔖 "/utf8, Tag/binary>>) end. -file("/Users/jonas/Projects/spectator/src/spectator/internal/views/process_table.gleam", 28). -spec render_primitive_list(list(spectator@internal@api:system_primitive())) -> list(lustre@internals@vdom:element(any())). render_primitive_list(Primitives) -> _pipe = gleam@list:map( Primitives, fun spectator@internal@views@display:system_primitive/1 ), gleam@list:intersperse(_pipe, lustre@element@html:text(<<", "/utf8>>)). -file("/Users/jonas/Projects/spectator/src/spectator/internal/views/process_table.gleam", 33). -spec render_details( gleam@option:option(spectator@internal@api:process_item()), gleam@option:option(spectator@internal@api:process_details()), gleam@option:option(spectator@internal@api:status()), gleam@option:option(gleam@dynamic:dynamic_()), fun((spectator@internal@api:process_item(), spectator@internal@api:sys_state()) -> APMV) ) -> lustre@internals@vdom:element(APMV). render_details(P, D, Status, State, Handle_otp_state_click) -> case {P, D} of {{some, Proc}, {some, Details}} -> lustre@element@html:'div'( [lustre@attribute:class(<<"details"/utf8>>)], [lustre@element@html:'div'( [lustre@attribute:class(<<"general"/utf8>>)], [lustre@element@html:'div'( [lustre@attribute:class( <<"panel-heading"/utf8>> )], [case erlang:element(8, erlang:element(3, Proc)) of {some, <<"__spectator_internal "/utf8, Rest/binary>>} -> lustre@element@html:text( <<"🔍 Spectator "/utf8, Rest/binary>> ); {some, Tag} -> lustre@element@html:text( <<<<"🔖 "/utf8, Tag/binary>>/binary, " details"/utf8>> ); none -> lustre@element@html:text( <<"🎛️ Process Details"/utf8>> ) end] ), lustre@element@html:'div'( [lustre@attribute:class( <<"panel-content"/utf8>> )], [lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Process Id"/utf8>> )] ), lustre@element@html:dd( [], [spectator@internal@views@display:pid( erlang:element(2, Proc) )] )] ), case erlang:element( 8, erlang:element(3, Proc) ) of none -> lustre@element@html:text( <<""/utf8>> ); {some, Tag@1} -> lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Tag"/utf8>> )] ), lustre@element@html:dd( [], [lustre@element@html:text( Tag@1 )] )] ) end, case erlang:element( 4, erlang:element(3, Proc) ) of none -> lustre@element@html:text( <<""/utf8>> ); {some, Name} -> lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Registered Name"/utf8>> )] ), lustre@element@html:dd( [], [lustre@element@html:text( erlang:atom_to_binary( Name ) )] )] ) end, lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Status"/utf8>> )] ), lustre@element@html:dd( [], [lustre@element@html:text( erlang:atom_to_binary( erlang:element( 9, erlang:element( 3, Proc ) ) ) )] )] ), lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Links"/utf8>> )] ), lustre@element@html:dd( [], render_primitive_list( erlang:element(3, Details) ) )] ), lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Monitored By"/utf8>> )] ), lustre@element@html:dd( [], render_primitive_list( erlang:element(4, Details) ) )] ), lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Monitors"/utf8>> )] ), lustre@element@html:dd( [], render_primitive_list( erlang:element(5, Details) ) )] ), lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Parent"/utf8>> )] ), lustre@element@html:dd( [], [case erlang:element(7, Details) of none -> lustre@element@html:text( <<"None"/utf8>> ); {some, Pid} -> spectator@internal@views@display:pid( Pid ) end] )] ), lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Trap Exit"/utf8>> )] ), lustre@element@html:dd( [], [spectator@internal@views@display:bool( erlang:element( 6, Details ) )] )] ), lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Initial Call"/utf8>> )] ), lustre@element@html:dd( [], [spectator@internal@views@display:function( erlang:element( 3, erlang:element( 3, Proc ) ) )] )] ), lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Current Function"/utf8>> )] ), lustre@element@html:dd( [], [spectator@internal@views@display:function( erlang:element( 2, erlang:element( 3, Proc ) ) )] )] ), lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Reductions"/utf8>> )] ), lustre@element@html:dd( [], [spectator@internal@views@display:number( erlang:element( 7, erlang:element( 3, Proc ) ) )] )] ), lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Memory"/utf8>> )] ), lustre@element@html:dd( [], [spectator@internal@views@display:number( erlang:element( 5, erlang:element( 3, Proc ) ) )] )] ), lustre@element@html:dl( [], [lustre@element@html:dt( [], [lustre@element@html:text( <<"Message Queue Length"/utf8>> )] ), lustre@element@html:dd( [], [spectator@internal@views@display:number( erlang:element( 6, erlang:element( 3, Proc ) ) )] )] )] )] ), lustre@element@html:'div'( [lustre@attribute:class(<<"otp"/utf8>>)], case {Status, State} of {{some, Status@1}, {some, State@1}} -> [lustre@element@html:'div'( [lustre@attribute:class( <<"panel-heading"/utf8>> )], [lustre@element@html:strong( [], [lustre@element@html:text( <<"☎️ OTP Process: "/utf8>> )] ), spectator@internal@views@display:atom( erlang:element(3, Status@1) ), case erlang:element(5, Status@1) of suspended -> lustre@element@html:button( [lustre@event:on_click( Handle_otp_state_click( Proc, erlang:element( 5, Status@1 ) ) ), lustre@attribute:class( <<"otp-toggle resume"/utf8>> )], [lustre@element@html:text( <<"🏃‍♀️‍➡️ Resume"/utf8>> )] ); running -> lustre@element@html:button( [lustre@event:on_click( Handle_otp_state_click( Proc, erlang:element( 5, Status@1 ) ) ), lustre@attribute:class( <<"otp-toggle suspend"/utf8>> )], [lustre@element@html:text( <<"✋ Suspend"/utf8>> )] ) end] ), lustre@element@html:'div'( [lustre@attribute:class( <<"panel-content"/utf8>> )], [lustre@element@html:pre( [], [lustre@element@html:text( pprint:format(State@1) )] )] )]; {_, _} -> [lustre@element@html:'div'( [lustre@attribute:class( <<"panel-content"/utf8>> )], [lustre@element@html:text( <<"This process does not appear to be OTP-compliant"/utf8>> )] )] end )] ); {_, _} -> lustre@element@html:'div'( [lustre@attribute:class(<<"otp-placeholder"/utf8>>)], [lustre@element@html:text( <<"Click a process to see details"/utf8>> )] ) end. -file("/Users/jonas/Projects/spectator/src/spectator/internal/views/process_table.gleam", 176). -spec classify_selected( spectator@internal@api:process_item(), gleam@option:option(spectator@internal@api:process_item()) ) -> lustre@internals@vdom:attribute(any()). classify_selected(Process, Active) -> Selection_status = case Active of {some, Active@1} when erlang:element(2, Active@1) =:= erlang:element( 2, Process ) -> <<"selected"/utf8>>; _ -> <<""/utf8>> end, case erlang:element(8, erlang:element(3, Process)) of none -> lustre@attribute:class(Selection_status); {some, <<"__spectator_internal "/utf8, _/binary>>} -> lustre@attribute:class( <> ); {some, _} -> lustre@attribute:class(<>) end. -file("/Users/jonas/Projects/spectator/src/spectator/internal/views/process_table.gleam", 189). -spec heading( binary(), binary(), spectator@internal@api:info_sort_criteria(), spectator@internal@api:info_sort_criteria(), spectator@internal@api:sort_direction(), fun((spectator@internal@api:info_sort_criteria()) -> APMZ) ) -> lustre@internals@vdom:element(APMZ). heading( Name, Title, Sort_criteria, Current_sort_criteria, Current_sort_direction, Handle_heading_click ) -> lustre@element@html:th( [lustre@attribute:title(Title), lustre@event:on_click(Handle_heading_click(Sort_criteria))], [lustre@element@html:'div'( [], [case Current_sort_criteria =:= Sort_criteria of true -> case Current_sort_direction of ascending -> spectator@internal@views@icon:sort_ascending( ); descending -> spectator@internal@views@icon:sort_descending( ) end; false -> lustre@element@html:text(<<""/utf8>>) end, lustre@element@html:text(Name)] )] ). -file("/Users/jonas/Projects/spectator/src/spectator/internal/views/process_table.gleam", 219). -spec render( list(spectator@internal@api:process_item()), fun((spectator@internal@api:process_item()) -> APNC), gleam@option:option(spectator@internal@api:process_item()), gleam@option:option(spectator@internal@api:process_details()), gleam@option:option(spectator@internal@api:status()), gleam@option:option(gleam@dynamic:dynamic_()), spectator@internal@api:info_sort_criteria(), spectator@internal@api:sort_direction(), fun((spectator@internal@api:info_sort_criteria()) -> APNC), fun((spectator@internal@api:process_item(), spectator@internal@api:sys_state()) -> APNC) ) -> lustre@internals@vdom:element(APNC). render( Processes, Handle_process_click, Active, Details, Status, State, Sort_criteria, Sort_direction, Handle_heading_click, Handle_otp_state_click ) -> lustre@element@html:table( [], [lustre@element@html:thead( [], [lustre@element@html:tr( [], [heading( <<"Name"/utf8>>, <<"Process PID or registered name"/utf8>>, name, Sort_criteria, Sort_direction, Handle_heading_click ), heading( <<"Tag"/utf8>>, <<"Spectator tag or initial call"/utf8>>, tag, Sort_criteria, Sort_direction, Handle_heading_click ), heading( <<"Current"/utf8>>, <<"Current function"/utf8>>, current_function, Sort_criteria, Sort_direction, Handle_heading_click ), heading( <<"Reductions"/utf8>>, <<"Number of reductions"/utf8>>, reductions, Sort_criteria, Sort_direction, Handle_heading_click ), heading( <<"Memory"/utf8>>, <<"Memory usage"/utf8>>, memory, Sort_criteria, Sort_direction, Handle_heading_click ), heading( <<"Messages"/utf8>>, <<"Message queue size"/utf8>>, message_queue, Sort_criteria, Sort_direction, Handle_heading_click ), heading( <<"Status"/utf8>>, <<"Process Status"/utf8>>, process_status, Sort_criteria, Sort_direction, Handle_heading_click )] )] ), lustre@element@html:tbody( [], gleam@list:map( Processes, fun(Process) -> lustre@element@html:tr( [lustre@attribute:role(<<"button"/utf8>>), classify_selected(Process, Active), lustre@event:on_click( Handle_process_click(Process) )], [lustre@element@html:td([], [render_name(Process)]), lustre@element@html:td( [], [render_tag(Process)] ), lustre@element@html:td( [], [spectator@internal@views@display:function( erlang:element( 2, erlang:element(3, Process) ) )] ), lustre@element@html:td( [], [spectator@internal@views@display:number( erlang:element( 7, erlang:element(3, Process) ) )] ), lustre@element@html:td( [], [spectator@internal@views@display:number( erlang:element( 5, erlang:element(3, Process) ) )] ), lustre@element@html:td( [], [spectator@internal@views@display:number( erlang:element( 6, erlang:element(3, Process) ) )] ), lustre@element@html:td( [], [spectator@internal@views@display:atom( erlang:element( 9, erlang:element(3, Process) ) )] )] ) end ) ), lustre@element@html:tfoot( [], [lustre@element@html:tr( [], [lustre@element@html:td( [lustre@attribute:attribute( <<"colspan"/utf8>>, <<"7"/utf8>> )], [render_details( Active, Details, Status, State, Handle_otp_state_click )] )] )] )] ).