diff --git a/README.md b/README.md index 124fdd4..db6af64 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ The Embed Type determines the remaining fields to fill out. * Group ID: Enter the unique identifier for the group. You can find the identifier by viewing a dashboard or report in the Power BI Service. The identifier is in the URL. * Dataset ID: Enter the unique identifier for the dataset. You can find the identifier by viewing a dashboard in the Power BI Service. The identifier is in the URL. This is only needed for Create Mode. * Page Name: Enter the unique identifier for the Page. You can find the identifier by viewing a dashboard in the Power BI Service. The identifier is in the URL. This is is an optional parameter. If left blank, the report's default page will be shown. + * Filter: An optional pre-set filter, given as a JavaScript object. ### Report Visual diff --git a/includes/class-power-bi-post-types.php b/includes/class-power-bi-post-types.php index 7dae739..fb85639 100644 --- a/includes/class-power-bi-post-types.php +++ b/includes/class-power-bi-post-types.php @@ -240,6 +240,18 @@ public function power_bi_metaboxs() { ), ) ); + $metabox_details->add_field( array( + 'name' => 'Filter', + 'desc' => 'Enter a filter object. Refer to the Power BI JavaScript Wiki for more information about filters.', + 'id' => $prefix . 'filter', + 'type' => 'textarea', + 'default' => '', + 'attributes' => array( + 'data-conditional-id' => $prefix . 'embed_type', + 'data-conditional-value' => wp_json_encode( array( 'report' ) ), + ), + ) ); + $metabox_details->add_field( array( 'name' => 'Visual Name', 'desc' => 'The Visual Name can be retrieved using the GetVisuals method on the Page object.', diff --git a/includes/class-power-bi-shortcodes.php b/includes/class-power-bi-shortcodes.php index dbd37e6..c44e26a 100644 --- a/includes/class-power-bi-shortcodes.php +++ b/includes/class-power-bi-shortcodes.php @@ -43,6 +43,7 @@ public function power_bi_html( $atts ) { 'id' => '', 'width' => '', 'height' => '', + 'filter' => '', ), $atts ) ); if ( empty( $id ) ) { @@ -52,7 +53,7 @@ public function power_bi_html( $atts ) { $container_width = empty( $width ) ? get_post_meta( $id, '_power_bi_width', true ) : $width; $container_height = empty( $height ) ? get_post_meta( $id, '_power_bi_height', true ) : $height; - $powerbi_js = $this->powerbi_js( $id ); + $powerbi_js = $this->powerbi_js( $id, $filter ); ob_start(); echo '
'; @@ -60,7 +61,7 @@ public function power_bi_html( $atts ) { return ob_get_clean(); } - public function powerbi_js( $id ) { + public function powerbi_js( $id, $filter ) { $power_bi_credentials = get_option('power_bi_credentials'); if( isset( $power_bi_credentials['access_token'] ) ) { @@ -90,6 +91,7 @@ public function powerbi_js( $id ) { if( 'report' === $embed_type ) { $report_mode = get_post_meta( $id, '_power_bi_report_mode', true ); $page_name = get_post_meta( $id, '_power_bi_page_name', true ); + $filter = empty( $filter ) ? get_post_meta( $id, '_power_bi_filter', true ) : $filter; if ( 'create' === $report_mode ) { $embed_url = $api_url . "reportEmbed?groupId=" . $group_id; @@ -152,6 +154,9 @@ public function powerbi_js( $id ) { id: '', pageName: '', + + filters: [], +