From 0b0ed2f5c75ece48a6c7daf645bc25aeeef600da Mon Sep 17 00:00:00 2001 From: Olivier van Helden Date: Mon, 13 Jan 2025 19:16:21 -0400 Subject: [PATCH] collapsible sidebar cards --- classes/class-grid.php | 55 ++++++++++++++++++++----------------- templates/bootstrap.css | 20 ++++++++++++++ templates/template-page.php | 5 ++-- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/classes/class-grid.php b/classes/class-grid.php index 72a0db0..84bbedd 100644 --- a/classes/class-grid.php +++ b/classes/class-grid.php @@ -54,31 +54,47 @@ class OpenSim_Grid { if( empty( $info ) ) { return; } + $hide_first = ''; if( ! empty( $args['title'] ) && is_string( $args['title'] ) ) { $title = $args['title']; } else { - $title = array_shift( $info ); + $title = array_values( $info )[0]; + if( is_numeric( array_keys( $info )[0] ) ) { + $hide_first = 'hidden d-none'; + } } + $collapse_head = ''; + $collapse_class = ''; + $collapse_data = ''; $html = sprintf( - '
-
-
    ', + '
    +
    +
    + +
    +
      ', $id, + $title, + $collapse_head, + $collapse_class, + $collapse_data ); - $html .= sprintf( - '
    • -
      %s
      -
    • ', - $title, - ); foreach( $info as $key => $value ) { $html .= sprintf( - '
    • %s %s
    • ', + ' +
    • + %3$s %4$s +
    • ', + $id, + $hide_first, is_numeric( $key ) ? '' : $key . ':', $value ); + $hide_first = ''; $class=""; } $html .= '
    '; @@ -131,25 +147,14 @@ class OpenSim_Grid { public static function grid_status_card( $grid_uri = null, $args = null ) { $info = self::grid_status( $grid_uri, $args ); - error_log( __FUNCTION__ . ' info: ' . print_r($info, true) ); - - - return self::array_to_card( 'grid-status', $info ); - if( ! $info || OpenSim::is_error( $info ) ) { return false; } - $title = false; - if( ! empty( $args['title'])) { - $title = $args['title'] === true ? _( 'Grid Information' ) : $args['title']; - } - - $html = self::array_to_card( 'grid-status', $info, $title ); - return $html; + return self::array_to_card( 'grid-status', $info ); } public static function grid_status( $grid_url = null ) { - // Fake data for debugging purpose + // DEBUG - Fake data for debugging purpose $info = array( _('Status') => _('Grid Online'), _('Members') => 113, @@ -161,7 +166,7 @@ class OpenSim_Grid { _('Total area') => '1.44 km²', ); return $info; - // End debugging + // End DEBUG global $OpenSimDB; // If db is not yet configured, calls to $OpenSimDB would crash otherwise diff --git a/templates/bootstrap.css b/templates/bootstrap.css index 175c63e..5c6f170 100644 --- a/templates/bootstrap.css +++ b/templates/bootstrap.css @@ -19,3 +19,23 @@ a.hop-link { text-decoration: none !important; } + +.cards .accordion-button { + border: 0; +} + +.cards .accordion-button:not(.collapsed) { + color: inherit; + background-color: inherit; + box-shadow: none; +} + +.cards .accordion-button::after { + background-image: url("data:image/svg+xml,") !important; + transform: rotate(180deg); +} + +.accordion-button:not(.collapsed)::after { + color: white; + transform: rotate(0); +} diff --git a/templates/template-page.php b/templates/template-page.php index 65ae99f..4d6d49e 100644 --- a/templates/template-page.php +++ b/templates/template-page.php @@ -14,6 +14,7 @@
    +