base_url = $base_url ?: HubPage::url( array( 'tab' => 'automations', 'section' => 'executed' ) ); parent::__construct( array( 'singular' => 'execution', 'plural' => 'executions', 'ajax' => false, ) ); } /** * @return array */ public function get_columns() { return array( 'remote_workflow_uuid' => _x( 'Workflow', 'column name', 'afroit-messaging-workflows' ), 'remote_execution_uuid'=> _x( 'Execution', 'column name', 'afroit-messaging-workflows' ), 'status' => _x( 'Status', 'column name', 'afroit-messaging-workflows' ), 'run_at' => _x( 'Run at', 'column name', 'afroit-messaging-workflows' ), 'created_at' => _x( 'Created', 'column name', 'afroit-messaging-workflows' ), 'actions' => _x( 'Actions', 'column name', 'afroit-messaging-workflows' ), ); } protected function get_primary_column_name() { return 'remote_execution_uuid'; } protected function get_column_info() { if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) && 4 === count( $this->_column_headers ) ) { return $this->_column_headers; } $columns = $this->get_columns(); $hidden = $this->screen ? get_hidden_columns( $this->screen ) : array(); $sortable = array(); $primary = $this->get_primary_column_name(); $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); return $this->_column_headers; } /** * @param array> $items * @param int|null $total_items * @param int $per_page * @return void */ public function prepare_items_with_data( array $items, ?int $total_items = null, int $per_page = 20 ): void { $this->items = $items; $total = null !== $total_items ? (int) $total_items : count( $this->items ); $per_page = (int) $per_page; $total_pages = $per_page > 0 ? (int) ceil( $total / $per_page ) : 1; $this->set_pagination_args( array( 'total_items' => $total, 'per_page' => $per_page, 'total_pages' => $total_pages, ) ); } public function prepare_items() { $this->items = array(); } public function no_items() { echo esc_html__( 'No executions found.', 'afroit-messaging-workflows' ); } protected function column_remote_workflow_uuid( $item ) { return esc_html( (string) ( $item['remote_workflow_uuid'] ?? '' ) ); } protected function column_remote_execution_uuid( $item ) { return esc_html( (string) ( $item['remote_execution_uuid'] ?? '' ) ); } protected function column_run_at( $item ) { return esc_html( (string) ( $item['run_at'] ?? '' ) ); } protected function column_created_at( $item ) { return esc_html( (string) ( $item['created_at'] ?? '' ) ); } protected function column_status( $item ) { $status = strtolower( (string) ( $item['status'] ?? '' ) ); $is_terminal = in_array( $status, $this->terminal_statuses, true ); $spinner = $is_terminal ? '' : ' '; return '' . esc_html( $status ?: '-' ) . '' . $spinner; } protected function column_actions( $item ) { $id = isset( $item['id'] ) ? (int) $item['id'] : 0; if ( $id <= 0 ) { return ''; } $execution_json = (string) ( $item['execution_json'] ?? '' ); $execution_b64 = base64_encode( $execution_json ); $view_label = __( 'Execution JSON', 'afroit-messaging-workflows' ); $delete_url = add_query_arg( array( 'action' => 'afromewo_delete_execution_queue_item', 'queue_id' => $id, '_wpnonce' => wp_create_nonce( 'afromewo_delete_execution_queue_item_' . $id ), 'redirect' => rawurlencode( $this->base_url ), ), admin_url( 'admin-post.php' ) ); $out = ' '; $out .= '' . esc_html__( 'Delete', 'afroit-messaging-workflows' ) . ''; return $out; } protected function column_default( $item, $column_name ) { return ''; } protected function get_bulk_actions() { return array(); } protected function bulk_actions( $which = '' ) { // No bulk actions. } }