diff --git a/assets/admin/admin.css b/assets/admin/admin.css index 357be08..59bfc33 100644 --- a/assets/admin/admin.css +++ b/assets/admin/admin.css @@ -46,7 +46,6 @@ @media (max-width: 782px) { .sg-admin .sg-copy { flex-direction: column; align-items: stretch; } } /* Phones: wide tables scroll inside their own box instead of pushing the page; controls never exceed the card. */ @media (max-width: 782px) { - .sg-admin table.sg-table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; } .sg-admin .sg-table th, .sg-admin .sg-table td { min-width: 3em; padding: 8px 6px; font-size: 13px; } .sg-admin .sg-table code { overflow-wrap: anywhere; word-break: break-all; font-size: 12px; } .sg-admin .sg-table td:last-child .button { margin: 0 4px 4px 0; } @@ -56,3 +55,34 @@ .sg-admin select, .sg-admin input[type="text"], .sg-admin input[type="url"], .sg-admin input[type="number"], .sg-admin textarea { max-width: 100%; box-sizing: border-box; } .sg-admin .sg-card { padding-left: 14px; padding-right: 14px; } } + +/* Table wrapper: scrolls sideways inside itself, never the page. Desktop look is unchanged. */ +.sg-admin .sg-scroll { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; } +.sg-admin .sg-scroll:focus-visible { outline: 2px solid #2271b1; outline-offset: 1px; } +.sg-admin .sg-swipe-hint { display: none; } +.sg-admin .sg-table code { overflow-wrap: anywhere; } +@media (max-width: 782px) { + .sg-admin .sg-table code { word-break: normal; overflow-wrap: anywhere; white-space: normal; } + /* Scroll tables: edge fades (scroll shadows) plus a one-line hint. */ + .sg-admin .sg-swipe-hint { display: block; margin: 4px 0; font-size: 12px; color: #50575e; } + .sg-admin .sg-scroll:not(.sg-scroll-cards) { + background: linear-gradient(to right, #fff 30%, rgba(255,255,255,0)) 0 0 / 40px 100% no-repeat local, + linear-gradient(to left, #fff 30%, rgba(255,255,255,0)) 100% 0 / 40px 100% no-repeat local, + linear-gradient(to right, rgba(0,0,0,.22), rgba(0,0,0,0)) 0 0 / 14px 100% no-repeat scroll, + linear-gradient(to left, rgba(0,0,0,.22), rgba(0,0,0,0)) 100% 0 / 14px 100% no-repeat scroll; + } + .sg-admin .sg-scroll:not(.sg-scroll-cards) .sg-table { min-width: 560px; } + /* Card tables: each row becomes a labelled card. */ + .sg-admin .sg-scroll-cards { overflow-x: visible; } + .sg-admin table.sg-cards, .sg-admin table.sg-cards tbody, .sg-admin table.sg-cards tr, .sg-admin table.sg-cards td { display: block; width: auto; box-sizing: border-box; } + .sg-admin table.sg-cards { border: 0; background: none; box-shadow: none; } + .sg-admin table.sg-cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } + .sg-admin table.sg-cards tr { margin: 0 0 12px; padding: 4px 0; border: 1px solid #c3c4c7; border-radius: 4px; background: #fff; } + .sg-admin table.sg-cards td { display: flex; gap: 10px; justify-content: space-between; align-items: baseline; padding: 6px 12px; font-size: 14px; border: 0; overflow-wrap: anywhere; text-align: right; } + .sg-admin table.sg-cards td::before { content: attr(data-label); flex: 0 0 34%; font-weight: 600; color: #50575e; text-align: left; } + .sg-admin table.sg-cards td:first-child { display: block; font-size: 15px; text-align: left; border-bottom: 1px solid #f0f0f1; padding-bottom: 8px; } + .sg-admin table.sg-cards td:first-child::before, .sg-admin table.sg-cards td[data-label=""]::before, .sg-admin table.sg-cards td.sg-actions::before { display: none; } + .sg-admin table.sg-cards td.sg-actions, .sg-admin table.sg-cards td[data-label=""] { display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 12px 8px; text-align: center; } + .sg-admin table.sg-cards td.sg-actions .button, .sg-admin table.sg-cards td[data-label=""] .button { display: block; width: 100%; min-height: 44px; line-height: 42px; margin: 0; padding: 0 12px; box-sizing: border-box; text-align: center; } + .sg-admin table.sg-cards td.sg-actions form, .sg-admin table.sg-cards td[data-label=""] form { display: block; margin: 0; } +} diff --git a/assets/admin/alerts.css b/assets/admin/alerts.css index 4c75060..348b66c 100644 --- a/assets/admin/alerts.css +++ b/assets/admin/alerts.css @@ -31,3 +31,6 @@ .sga-howto{margin-top:8px} .sga-howto pre{overflow-x:auto;max-width:100%;padding:8px;background:#f0f0f1} .sga-bg-pick{margin-left:12px} + +/* Alerts list: media that was deleted from the Media Library */ +.sga-missing{color:#8a2424;background:#fcf0f0;border:1px solid #d63638;border-radius:3px;padding:0 6px;font-weight:600;display:inline-block} diff --git a/includes/Admin/ActionsPage.php b/includes/Admin/ActionsPage.php index 8a55079..ecc68d6 100644 --- a/includes/Admin/ActionsPage.php +++ b/includes/Admin/ActionsPage.php @@ -55,17 +55,17 @@ final class ActionsPage { if ( ! $queued ) { echo '

Nothing in the queue. When a donation triggers a reward, it shows up here.

'; } else { - echo ''; + echo Admin::tableOpen( array( 'Donor', 'Amount', 'Reward', 'Time', 'Message', '' ), 'Reward queue' ); foreach ( $queued as $e ) { - echo ''; - echo ''; - echo ''; - echo ''; - echo '' . Admin::td( 'Donor' ) . esc_html( Format::donorName( $e ) ) . ''; + echo Admin::td( 'Amount' ) . esc_html( Format::money( (int) ( $e['base_minor'] ?? 0 ), Format::currency( $e['currency'] ?? $cur ) ) ) . ''; + echo Admin::td( 'Reward' ) . '' . esc_html( (string) $e['title'] ) . ' × ' . (int) $e['times'] . ''; + echo Admin::td( 'Time' ) . esc_html( self::when( (string) $e['created_at'] ) ) . ''; + echo Admin::td( 'Message' ) . esc_html( (string) ( $e['message'] ?? '' ) ) . '' . Admin::td( '', 'sg-actions' ); Admin::form( 'sg_event_done', array( 'event_id' => (int) $e['id'] ), 'sg-inline' ); echo ''; } - echo '
DonorAmountRewardTimeMessage
' . esc_html( Format::donorName( $e ) ) . '' . esc_html( Format::money( (int) ( $e['base_minor'] ?? 0 ), Format::currency( $e['currency'] ?? $cur ) ) ) . '' . esc_html( (string) $e['title'] ) . ' × ' . (int) $e['times'] . '' . esc_html( self::when( (string) $e['created_at'] ) ) . '' . esc_html( (string) ( $e['message'] ?? '' ) ) . ''; + echo '
'; + echo Admin::tableClose(); Admin::form( 'sg_event_done_all' ); echo '

'; } @@ -104,17 +104,17 @@ final class ActionsPage { echo '

No rewards yet.

'; return; } - echo ''; + echo Admin::tableOpen( array( 'Reward', 'Amount', 'Triggers', 'Applies to', 'Order', 'Actions' ), 'Reward menu' ); foreach ( $actions as $a ) { $id = (int) $a['id']; - echo ''; - echo ''; - echo ''; - echo '' . Admin::td( 'Amount' ) . esc_html( Format::money( $a['amount_minor'], $cur ) ) . ''; + echo Admin::td( 'Triggers' ) . esc_html( Matcher::EVERY === $a['mode'] ? 'Every time it adds up' : 'Exactly this amount' ) . ''; + echo Admin::td( 'Applies to' ) . esc_html( 0 === $a['goal_id'] ? 'All goals' : ( $goals[ $a['goal_id'] ] ?? 'Goal #' . $a['goal_id'] ) ) . ''; + echo Admin::td( 'Order' ) . (int) $a['sort'] . '' . Admin::td( 'Actions', 'sg-actions' ); echo 'Edit '; Admin::form( 'sg_action_toggle', array( 'action_id' => $id, 'enabled' => $a['enabled'] ? 0 : 1 ), 'sg-inline' ); echo ' '; @@ -122,7 +122,7 @@ final class ActionsPage { echo ''; echo ''; } - echo '
RewardAmountTriggersApplies toOrderActions
' . esc_html( $a['title'] ) . ''; + echo '' . Admin::td( 'Reward' ) . '' . esc_html( $a['title'] ) . ''; if ( '' !== $a['description'] ) { echo '
' . esc_html( $a['description'] ) . ''; } - echo '
' . esc_html( Format::money( $a['amount_minor'], $cur ) ) . '' . esc_html( Matcher::EVERY === $a['mode'] ? 'Every time it adds up' : 'Exactly this amount' ) . '' . esc_html( 0 === $a['goal_id'] ? 'All goals' : ( $goals[ $a['goal_id'] ] ?? 'Goal #' . $a['goal_id'] ) ) . '' . (int) $a['sort'] . ''; + echo '
'; + echo Admin::tableClose() . ''; } private static function renderForm( int $id ): void { diff --git a/includes/Admin/Admin.php b/includes/Admin/Admin.php index d1d84c3..aa0cf8f 100644 --- a/includes/Admin/Admin.php +++ b/includes/Admin/Admin.php @@ -175,6 +175,33 @@ final class Admin { } } + /** + * Open a table inside a keyboard-focusable scroll region. $headers is a list of column labels (an empty + * label is a visually hidden column). $cards=true turns rows into labelled cards on phones (cells need + * td() labels); false keeps sideways scrolling and shows a swipe hint on phones. + * + * @param string[] $headers + */ + public static function tableOpen( array $headers, string $label, bool $cards = true ): string { + $h = static fn( string $s ): string => htmlspecialchars( $s, ENT_QUOTES, 'UTF-8' ); + $out = $cards ? '' : '

Swipe sideways to see more

'; + $out .= '
'; + $out .= ''; + foreach ( $headers as $t ) { + $out .= '' === $t ? '' : ''; + } + return $out . ''; + } + + public static function tableClose(): string { + return '
Actions' . $h( $t ) . '
'; + } + + /** Opening carrying the column label that phone cards print before the value. */ + public static function td( string $label, string $class = '' ): string { + return ''; + } + public static function close(): void { echo ''; } diff --git a/includes/Admin/AlertsPage.php b/includes/Admin/AlertsPage.php index 319951d..afdf591 100644 --- a/includes/Admin/AlertsPage.php +++ b/includes/Admin/AlertsPage.php @@ -48,6 +48,44 @@ final class AlertsPage { ); } + /** + * Media column parts for one alert. $existing maps attachment id => true for ids still in the Media Library. + * + * @param array $d + * @param array $existing + * @return array list of [label, missing] + */ + public static function mediaParts( array $d, array $existing ): array { + $parts = array(); + $vid = (int) ( $d['visual_id'] ?? 0 ); + if ( $vid > 0 ) { + $video = 'video' === ( $d['visual_type'] ?? '' ); + $parts[] = isset( $existing[ $vid ] ) ? array( $video ? 'Video' : 'Picture/GIF', false ) : array( $video ? 'Video missing' : 'Picture missing', true ); + } + $sid = (int) ( $d['sound_id'] ?? 0 ); + if ( $sid > 0 ) { + $parts[] = isset( $existing[ $sid ] ) ? array( 'Sound', false ) : array( 'Sound missing', true ); + } + return $parts; + } + + /** One query: which of the alerts' attachments still exist. @return array */ + private static function existingAttachments( array $defs ): array { + $ids = array(); + foreach ( $defs as $d ) { + foreach ( array( 'visual_id', 'sound_id' ) as $k ) { + if ( (int) ( $d[ $k ] ?? 0 ) > 0 ) { + $ids[ (int) $d[ $k ] ] = true; + } + } + } + if ( ! $ids ) { + return array(); + } + $found = get_posts( array( 'post_type' => 'attachment', 'post_status' => 'any', 'post__in' => array_keys( $ids ), 'posts_per_page' => count( $ids ), 'fields' => 'ids', 'orderby' => 'none', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false ) ); + return array_fill_keys( array_map( 'intval', $found ), true ); + } + /* ---------------------------------------------------------------- render */ public static function render(): void { @@ -89,24 +127,22 @@ final class AlertsPage { echo '

No custom alerts yet.

'; return; } - echo ''; + echo Admin::tableOpen( array( 'Name', 'Plays when', 'Applies to', 'Media', 'Order', 'Actions' ), 'Your alerts' ); + $existing = self::existingAttachments( $defs ); foreach ( $defs as $d ) { $id = (int) $d['id']; $when = 'reward' === $d['trigger_type'] ? 'Reward: ' . ( $rewards[ $d['action_id'] ] ?? 'a reward that was deleted' ) : 'Donation of at least ' . Format::money( (int) $d['min_minor'], $cur ); $media = array(); - if ( $d['visual_id'] ) { - $media[] = 'video' === $d['visual_type'] ? 'Video' : 'Picture/GIF'; + foreach ( self::mediaParts( $d, $existing ) as [ $mLabel, $mMissing ] ) { + $media[] = $mMissing ? '' . esc_html( $mLabel ) . '' : esc_html( $mLabel ); } - if ( $d['sound_id'] ) { - $media[] = 'Sound'; - } - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + echo Admin::td( 'Plays when' ) . esc_html( $when ) . ''; + echo Admin::td( 'Applies to' ) . esc_html( 0 === $d['goal_id'] ? 'All goals' : ( $goals[ $d['goal_id'] ] ?? 'Goal #' . $d['goal_id'] ) ) . ''; + echo Admin::td( 'Media' ) . ( $media ? implode( ', ', $media ) : 'Text only' ) . ''; + echo Admin::td( 'Order' ) . (int) $d['sort'] . '' . Admin::td( 'Actions', 'sg-actions' ); echo 'Edit '; Admin::form( 'sg_alert_toggle', array( 'alert_id' => $id, 'enabled' => $d['enabled'] ? 0 : 1 ), 'sg-inline' ); echo ' '; @@ -114,7 +150,7 @@ final class AlertsPage { echo ''; echo ''; } - echo '
NamePlays whenApplies toMediaOrderActions
' . esc_html( $d['title'] ) . '' . esc_html( $when ) . '' . esc_html( 0 === $d['goal_id'] ? 'All goals' : ( $goals[ $d['goal_id'] ] ?? 'Goal #' . $d['goal_id'] ) ) . '' . esc_html( $media ? implode( ', ', $media ) : 'Text only' ) . '' . (int) $d['sort'] . ''; + echo '' . Admin::td( 'Name' ) . '' . esc_html( $d['title'] ) . '
'; + echo Admin::tableClose() . ''; } private static function mediaField( string $name, string $label, string $kind, int $id, string $help ): void { diff --git a/includes/Admin/DonationsPage.php b/includes/Admin/DonationsPage.php index 3123ece..6ffb350 100644 --- a/includes/Admin/DonationsPage.php +++ b/includes/Admin/DonationsPage.php @@ -44,18 +44,18 @@ final class DonationsPage { foreach ( Store::goals()->all() as $g ) { $goals[ (int) $g['id'] ] = (string) $g['title']; } - echo ''; + echo Admin::tableOpen( array( 'Date', 'Donor', 'Amount', 'Fee', 'Total paid', 'Goal', 'Status', 'Message' ), 'Donations', false ); foreach ( $res['rows'] as $r ) { $cur = Format::currency( $r['currency'] ); $test = Format::isTest( $r ); - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + echo '' . Admin::td( 'Date' ) . esc_html( self::fmtDate( (string) $r['created_at'] ) ) . ''; + echo Admin::td( 'Donor' ) . esc_html( Format::donorName( $r ) ) . ( $test ? ' TEST' : '' ) . ''; + echo Admin::td( 'Amount' ) . esc_html( Format::money( (int) $r['base_minor'], $cur ) ) . '' . Admin::td( 'Fee' ) . esc_html( Format::money( (int) $r['fee_minor'], $cur ) ) . '' . Admin::td( 'Total paid' ) . esc_html( Format::money( (int) $r['total_minor'], $cur ) ) . ''; + echo Admin::td( 'Goal' ) . esc_html( $test ? '(test)' : ( $goals[ (int) $r['goal_id'] ] ?? '#' . (int) $r['goal_id'] ) ) . ''; + echo Admin::td( 'Status' ) . esc_html( ucfirst( (string) $r['status'] ) ) . ( 'approved' === $r['moderation'] ? '' : ' message ' . esc_html( (string) $r['moderation'] ) . '' ) . ''; + echo Admin::td( 'Message' ) . esc_html( (string) $r['message'] ) . ''; } - echo '
DateDonorAmountFeeTotal paidGoalStatusMessage
' . esc_html( self::fmtDate( (string) $r['created_at'] ) ) . '' . esc_html( Format::donorName( $r ) ) . ( $test ? ' TEST' : '' ) . '' . esc_html( Format::money( (int) $r['base_minor'], $cur ) ) . '' . esc_html( Format::money( (int) $r['fee_minor'], $cur ) ) . '' . esc_html( Format::money( (int) $r['total_minor'], $cur ) ) . '' . esc_html( $test ? '(test)' : ( $goals[ (int) $r['goal_id'] ] ?? '#' . (int) $r['goal_id'] ) ) . '' . esc_html( ucfirst( (string) $r['status'] ) ) . ( 'approved' === $r['moderation'] ? '' : ' message ' . esc_html( (string) $r['moderation'] ) . '' ) . '' . esc_html( (string) $r['message'] ) . '
'; + echo Admin::tableClose(); $pages = (int) ceil( $res['total'] / self::PER_PAGE ); if ( $pages > 1 ) { echo '
' . wp_kses_post( (string) paginate_links( array( @@ -83,18 +83,18 @@ final class DonationsPage { Admin::close(); return; } - echo ''; + echo Admin::tableOpen( array( 'Date', 'Donor', 'Amount', 'Message', 'Decision' ), 'Messages waiting for review' ); foreach ( $res['rows'] as $r ) { $cur = Format::currency( $r['currency'] ); - echo ''; - echo '' . Admin::td( 'Date' ) . esc_html( self::fmtDate( (string) $r['created_at'] ) ) . '' . Admin::td( 'Donor' ) . esc_html( Format::donorName( $r ) ) . ''; + echo Admin::td( 'Amount' ) . esc_html( Format::money( (int) $r['base_minor'], $cur ) ) . '' . Admin::td( 'Message' ) . esc_html( (string) $r['message'] ) . '' . Admin::td( 'Decision', 'sg-actions' ); foreach ( array( 'approved' => 'Approve', 'rejected' => 'Reject' ) as $to => $lbl ) { Admin::form( 'sg_moderate', array( 'donation_id' => (int) $r['id'], 'decision' => $to ), 'sg-inline' ); echo ' '; } echo ''; } - echo '
DateDonorAmountMessageDecision
' . esc_html( self::fmtDate( (string) $r['created_at'] ) ) . '' . esc_html( Format::donorName( $r ) ) . '' . esc_html( Format::money( (int) $r['base_minor'], $cur ) ) . '' . esc_html( (string) $r['message'] ) . ''; + echo '
'; + echo Admin::tableClose(); Admin::close(); } diff --git a/includes/Admin/GoalsPage.php b/includes/Admin/GoalsPage.php index 29c1384..4e312f5 100644 --- a/includes/Admin/GoalsPage.php +++ b/includes/Admin/GoalsPage.php @@ -40,17 +40,17 @@ final class GoalsPage { Admin::close(); return; } - echo ''; + echo Admin::tableOpen( array( 'Goal', 'Status', 'Raised', 'Dates', 'Actions' ), 'Goals' ); foreach ( $goals as $g ) { $gid = (int) $g['id']; $cur = Format::currency( $g['currency'] ); $raised = Store::goals()->raised_minor( $gid ); $target = (int) $g['target_minor']; $pct = $target > 0 ? min( 100, intdiv( $raised * 100, $target ) ) : 0; - echo ''; - echo ''; - echo ''; - echo '' . Admin::td( 'Goal' ) . '' . esc_html( (string) $g['title'] ) . '
ID ' . $gid . ' · [streamgoals_donate goal="' . $gid . '"]'; + echo Admin::td( 'Status' ) . '' . esc_html( self::STATUSES[ $g['status'] ] ?? (string) $g['status'] ) . ''; + echo Admin::td( 'Raised' ) . esc_html( Format::money( $raised, $cur ) . ' of ' . Format::money( $target, $cur ) ) . ' (' . (int) $pct . '%)
' . ( ! empty( $g['close_at_target'] ) ? 'Closes at target' : '' ) . ''; + echo Admin::td( 'Dates' ) . esc_html( self::dateLabel( $g['starts_at'] ?? null, 'Starts' ) ) . '
' . esc_html( self::dateLabel( $g['ends_at'] ?? null, 'Ends' ) ) . '' . Admin::td( 'Actions', 'sg-actions' ); echo 'Edit '; echo 'Rules '; $nt = $tierCounts[ $gid ] ?? 0; @@ -69,7 +69,7 @@ final class GoalsPage { echo ''; echo ''; } - echo '
GoalStatusRaisedDatesActions
' . esc_html( (string) $g['title'] ) . '
ID ' . $gid . ' · [streamgoals_donate goal="' . $gid . '"]
' . esc_html( self::STATUSES[ $g['status'] ] ?? (string) $g['status'] ) . '' . esc_html( Format::money( $raised, $cur ) . ' of ' . Format::money( $target, $cur ) ) . ' (' . (int) $pct . '%)
' . ( ! empty( $g['close_at_target'] ) ? 'Closes at target' : '' ) . '
' . esc_html( self::dateLabel( $g['starts_at'] ?? null, 'Starts' ) ) . '
' . esc_html( self::dateLabel( $g['ends_at'] ?? null, 'Ends' ) ) . '
'; + echo '
'; + echo Admin::tableClose(); Admin::close(); } @@ -216,22 +216,22 @@ final class GoalsPage { if ( ! $tiers ) { echo '

No tiers yet. This goal works as a single target until you add one.

'; } else { - echo ''; + echo Admin::tableOpen( array( '#', 'Unlock', 'Target', 'Status', 'Actions' ), 'Tiers' ); foreach ( TierPolicy::sorted( $tiers ) as $i => $t ) { $tid = (int) $t['id']; $status = TierPolicy::status( $tiers, $t ); $label = 'reached' === $status ? 'Reached on ' . get_date_from_gmt( (string) $t['reached_at'], 'Y-m-d H:i' ) : ( 'current' === $status ? 'Current' : 'Upcoming' ); - echo '' . Admin::td( '#' ) . (int) ( $i + 1 ) . '' . Admin::td( 'Unlock' ) . '' . esc_html( $t['title'] ) . ''; if ( '' !== $t['description'] ) { echo '
' . esc_html( $t['description'] ) . ''; } - echo ''; - echo '' . Admin::td( 'Target' ) . esc_html( Format::money( (int) $t['target_minor'], $cur ) ) . ''; + echo Admin::td( 'Status' ) . '' . esc_html( $label ) . '' . Admin::td( 'Actions', 'sg-actions' ); echo 'Edit '; Admin::form( 'sg_tier_delete', array( 'goal_id' => $goalId, 'tier_id' => $tid ), 'sg-inline sg-confirm' ); echo ''; } - echo '
#UnlockTargetStatusActions
' . (int) ( $i + 1 ) . '' . esc_html( $t['title'] ) . ''; + echo '
' . esc_html( Format::money( (int) $t['target_minor'], $cur ) ) . '' . esc_html( $label ) . ''; + echo '
'; + echo Admin::tableClose(); } echo '
'; @@ -331,24 +331,24 @@ final class GoalsPage { if ( ! $rules ) { echo '

No rules yet. The goal bar works without any rules.

'; } else { - echo ''; + echo Admin::tableOpen( array( 'Rule', 'What it does', 'Actions' ), 'Rules' ); foreach ( $rules as $r ) { $rid = (int) $r['id']; - echo ''; + echo '' . Admin::td( 'Rule' ) . esc_html( RuleConfig::TYPES[ $r['type'] ] ?? (string) $r['type'] ) . ( $r['enabled'] ? '' : ' (off)' ) . ''; try { $summary = RuleConfig::summary( (string) $r['type'], $r['config'], $cur ); } catch ( \Throwable $e ) { // One unreadable rule must not take down the whole screen; say what is wrong so it can be fixed or deleted. $summary = 'Could not read this rule (' . $e->getMessage() . '). You can delete it and add it again.'; } - echo '' . Admin::td( 'Actions', 'sg-actions' ); echo 'Edit '; Admin::form( 'sg_rule_toggle', array( 'goal_id' => $goalId, 'rule_id' => $rid, 'enabled' => $r['enabled'] ? 0 : 1 ), 'sg-inline' ); echo ' '; Admin::form( 'sg_rule_delete', array( 'goal_id' => $goalId, 'rule_id' => $rid ), 'sg-inline sg-confirm' ); echo ''; } - echo '
RuleWhat it doesActions
' . esc_html( RuleConfig::TYPES[ $r['type'] ] ?? (string) $r['type'] ) . ( $r['enabled'] ? '' : ' (off)' ) . '
' . esc_html( $summary ) . ''; + echo Admin::td( 'What it does' ) . esc_html( $summary ) . '
'; + echo Admin::tableClose(); } echo '
'; diff --git a/tests/Unit/AdminTableAlertMediaTest.php b/tests/Unit/AdminTableAlertMediaTest.php new file mode 100644 index 0000000..745c73a --- /dev/null +++ b/tests/Unit/AdminTableAlertMediaTest.php @@ -0,0 +1,40 @@ + 5, 'visual_type' => 'image', 'sound_id' => 6 ); + $this->assertSame( array( array( 'Picture/GIF', false ), array( 'Sound', false ) ), AlertsPage::mediaParts( $d, array( 5 => true, 6 => true ) ) ); + $this->assertSame( array( array( 'Picture missing', true ), array( 'Sound', false ) ), AlertsPage::mediaParts( $d, array( 6 => true ) ) ); + $this->assertSame( array( array( 'Picture missing', true ), array( 'Sound missing', true ) ), AlertsPage::mediaParts( $d, array() ) ); + } + + public function test_media_parts_video_and_text_only(): void { + $this->assertSame( array( array( 'Video missing', true ) ), AlertsPage::mediaParts( array( 'visual_id' => 9, 'visual_type' => 'video', 'sound_id' => 0 ), array() ) ); + $this->assertSame( array( array( 'Video', false ) ), AlertsPage::mediaParts( array( 'visual_id' => 9, 'visual_type' => 'video', 'sound_id' => 0 ), array( 9 => true ) ) ); + $this->assertSame( array(), AlertsPage::mediaParts( array( 'visual_id' => 0, 'sound_id' => 0 ), array() ) ); + } + + public function test_table_open_is_focusable_region_with_hint_only_when_scrolling(): void { + $cards = Admin::tableOpen( array( 'Goal', '' ), 'Goals "x"' ); + $this->assertStringContainsString( 'tabindex="0" role="region" aria-label="Goals "x""', $cards ); + $this->assertStringContainsString( 'sg-cards', $cards ); + $this->assertStringNotContainsString( 'Swipe sideways', $cards ); + $this->assertStringContainsString( 'screen-reader-text', $cards ); + $scroll = Admin::tableOpen( array( 'A' ), 'Donations', false ); + $this->assertStringContainsString( 'Swipe sideways to see more', $scroll ); + $this->assertStringNotContainsString( 'sg-cards', $scroll ); + $this->assertSame( '', Admin::tableClose() ); + } + + public function test_td_escapes_label(): void { + $this->assertSame( '', Admin::td( 'A&"', 'sg-actions' ) ); + } +}