Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding wladston's configurable filters and backgrounds #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* Background: Optionally entender a background color for your embed. For instance, entering `models.BackgroundType.Transparent` in this field will make your embed have a transparent background.

### Report Visual
Expand Down
12 changes: 12 additions & 0 deletions includes/class-power-bi-post-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
9 changes: 7 additions & 2 deletions includes/class-power-bi-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function power_bi_html( $atts ) {
'id' => '',
'width' => '',
'height' => '',
'filter' => '',
), $atts ) );

if ( empty( $id ) ) {
Expand All @@ -52,15 +53,15 @@ 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 '<div id="powerbi-embedded-'. $id .'" style="height: ' . $container_height . '; width: ' . $container_width . ';"></div>';
echo $powerbi_js;
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'] ) ) {
Expand Down Expand Up @@ -91,6 +92,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;
Expand Down Expand Up @@ -156,6 +158,9 @@ public function powerbi_js( $id ) {
<?php if ('report' === $embed_type) : ?>
id: '<?php echo $report_id; ?>',
pageName: '<?php echo $page_name; ?>',
<?php if ($filter) : ?>
filters: [<?php echo $filter; ?>],
<?php endif; ?>
<?php endif; ?>

<?php if ('qna' === $embed_type) : ?>
Expand Down