Skip to content

Commit

Permalink
Merge pull request #551 from alicolville/report-improvement
Browse files Browse the repository at this point in the history
10.3.5
  • Loading branch information
alicolville authored Apr 17, 2023
2 parents e1e8fc1 + b1da2ef commit d54eeb4
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 37 deletions.
19 changes: 18 additions & 1 deletion assets/js/data.footable.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,18 @@ jQuery( document ).ready(function ( $, undefined ) {

ws_ls_log( 'Users: Fetching Data' );

ws_ls_post_data_to_WP('get_groups_users', { 'table_id': $(this).attr( 'id' ), 'group_id': $(this).data( 'group-id' ), 'todays_entries_only': $(this).data( 'todays-entries-only' ) , 'is-admin': $(this).data( 'is-admin' )}, ws_ls_callback_groups_users );
let data = {
'table_id': $(this).attr( 'id' ),
'group_id': $(this).data( 'group-id' ),
'todays_entries_only': $(this).data( 'todays-entries-only' ),
'is-admin': $(this).data( 'is-admin' ),
'hide_column_gains': $(this).data( 'hide-column-gains' ),
'hide_column_losses': $(this).data( 'hide-column-losses' ),
'hide_column_diff_from_prev': $(this).data( 'hide-column-diff-from-prev' ),
'hide_summary_row': $(this).data( 'hide-summary-row' ),
};

ws_ls_post_data_to_WP('get_groups_users', data, ws_ls_callback_groups_users );
});

/**
Expand All @@ -453,6 +464,12 @@ jQuery( document ).ready(function ( $, undefined ) {
$( '.ws-ls-total-lost-count span' ).html( response.total_difference );
$( '.ws-ls-total-lost-count' ).removeClass( 'ykuk-invisible' );

$( '.ws-ls-total-losses-count span' ).html( response.total_losses );
$( '.ws-ls-total-losses-count' ).removeClass( 'ykuk-invisible' );

$( '.ws-ls-total-gains-count span' ).html( response.total_gains );
$( '.ws-ls-total-gains-count' ).removeClass( 'ykuk-invisible' );

ws_ls_log('Groups: Rendering Table: ' + table_id );

$( table_id ).removeClass( 'ws-ls-loading-table' );
Expand Down
2 changes: 1 addition & 1 deletion assets/js/data.footable.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/shortcodes/wt-group-view-as-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ The shortcode supports the following arguments:
|disable-main-font|If set to true will disable the main font used in the shortcode|True or False (default)|[wt-group-view-as-table disable-main-font=true]
|disable-theme-css|If set to true will disable the additional CSS used in the shortcode|True or False (default)|[wt-group-view-as-table disable-theme-css=true]
|group-id |Specifies the group ID to show user information for. |Number. Defaults to 0| [wt-group-view-as-table group-id=123]
|hide-column-diff-from-prev|If enabled, hide the column "Diff from Prev".|"true" or "false" (default)| [wt-group-view-as-table hide-column-diff-from-prev="true"]
|hide-column-gains|If enabled, hide the column "Gains".|"true" or "false" (default)| [wt-group-view-as-table hide-column-gains="true"]
|hide-column-losses|If enabled, hide the column "Losses".|"true" or "false" (default)| [wt-group-view-as-table hide-column-losses="true"]
|enable-group-select |If enabled, display a dropdown list of all user groups. Selecting an option shall show data for that given group.|"true" (default) or "false"| [wt-group-view-as-table enable-group-select="false"]
|todays-entries-only|If enabled, users will only be shown for the given group if they have added an entry for today|"true" or "false" (default)|[wt-group-view-as-table todays-entries-only="true"]
48 changes: 35 additions & 13 deletions includes/components.php
Original file line number Diff line number Diff line change
Expand Up @@ -1145,14 +1145,18 @@ function ws_ls_component_user_search( $arguments ) {
*/
function ws_ls_component_group_view_entries( $arguments ) {

$arguments = wp_parse_args( $arguments, [ 'default-to-users-group' => false,
'disable-theme-css' => false,
'disable-main-font' => false,
'group-id' => NULL,
'table-allow-delete' => false,
'uikit' => true,
'enable-group-select' => true,
'todays-entries-only' => false
$arguments = wp_parse_args( $arguments, [ 'default-to-users-group' => false,
'disable-theme-css' => false,
'disable-main-font' => false,
'group-id' => NULL,
'table-allow-delete' => false,
'uikit' => true,
'enable-group-select' => true,
'todays-entries-only' => false,
'hide-column-gains' => false,
'hide-column-losses' => false,
'hide-column-diff-from-prev' => false,
'hide-summary-row' => false
]);

if ( true === $arguments[ 'uikit' ] ) {
Expand All @@ -1178,13 +1182,23 @@ function ws_ls_component_group_view_entries( $arguments ) {
$html .= ws_ls_component_group_select( [ 'selected' => $arguments[ 'group-id' ], 'uikit' => $arguments[ 'uikit' ] ] );
}

$message = ( true === ws_ls_to_bool( $arguments[ 'todays-entries-only' ] ) ) ?
$display_text = ( true === ws_ls_to_bool( $arguments[ 'todays-entries-only' ] ) ) ?
__( 'Total weight difference (between previous/latest)', WE_LS_SLUG ) :
__( 'Total weight difference (between start/latest)', WE_LS_SLUG );

$message = ws_ls_component_alert( [ 'message' => __( 'Total losses', WE_LS_SLUG ) . ': <strong><span></span>.</strong>',
'css-classes' => 'ykuk-invisible ws-ls-total-losses-count',
'uikit' => $arguments[ 'uikit']
]);

$message .= ws_ls_component_alert( [ 'message' => __( 'Total gains', WE_LS_SLUG ) . ': <strong><span></span>.</strong>',
'css-classes' => 'ykuk-invisible ws-ls-total-gains-count',
'uikit' => $arguments[ 'uikit']
]);

$message = ws_ls_component_alert( [ 'message' => $message . ': <strong><span></span>.</strong>',
'css-classes' => 'ykuk-invisible ws-ls-total-lost-count', 'uikit'
=> $arguments[ 'uikit']
$message .= ws_ls_component_alert( [ 'message' => $display_text . ': <strong><span></span>.</strong>',
'css-classes' => 'ykuk-invisible ws-ls-total-lost-count',
'uikit' => $arguments[ 'uikit']
]);

$html .= sprintf('<div id="-row" class="ws-ls-form-row ykuk-width-1-1">
Expand All @@ -1201,6 +1215,10 @@ function ws_ls_component_group_view_entries( $arguments ) {
data-cascade="true"
data-toggle="true"
data-is-admin="%5$s"
data-hide-column-gains="%6$s"
data-hide-column-losses="%7$s"
data-hide-column-diff-from-prev="%8$s"
data-hide-summary-row="%9$s"
data-use-parent-width="true">
</table>
<div class="ykuk-divider-icon"></div>
Expand All @@ -1210,7 +1228,11 @@ function ws_ls_component_group_view_entries( $arguments ) {
( true === ws_ls_to_bool( $arguments[ 'table-allow-delete' ] ) ) ? 'true' : 'false',
( true === ws_ls_to_bool( $arguments[ 'todays-entries-only' ] ) ) ? 'true' : 'false',
$message,
( true === is_admin() ) ? 'true' : 'false'
( true === is_admin() ) ? 'true' : 'false',
$arguments[ 'hide-column-gains' ],
$arguments[ 'hide-column-losses' ],
$arguments[ 'hide-column-diff-from-prev' ],
$arguments[ 'hide-summary-row' ]
);

return $html;
Expand Down
75 changes: 58 additions & 17 deletions pro-features/user-groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,13 @@ function ws_ls_ajax_groups_users_get(){

check_ajax_referer( 'ws-ls-user-tables', 'security' );

$table_id = ws_ls_post_value( 'table_id' );
$group_id = ws_ls_post_value( 'group_id' );
$is_admin = ws_ls_post_value( 'is-admin' );
$todays_entries_only = ws_ls_post_value( 'todays_entries_only' );
$table_id = ws_ls_post_value( 'table_id' );
$group_id = ws_ls_post_value( 'group_id' );
$is_admin = ws_ls_post_value( 'is-admin' );
$todays_entries_only = ws_ls_post_value( 'todays_entries_only' );
$hide_col_diff_from_prev = ws_ls_post_value_to_bool( 'hide_column_diff_from_prev' );
$hide_column_gains = ws_ls_post_value_to_bool( 'hide_column_gains' );
$hide_column_losses = ws_ls_post_value_to_bool( 'hide_column_losses' );

$cache_key = sprintf( 'ajax-group-%d-%d', $group_id, $todays_entries_only );

Expand All @@ -713,12 +716,23 @@ function ws_ls_ajax_groups_users_get(){
[ 'name' => 'number-of-entries', 'title' => __('No. entries', WE_LS_SLUG), 'breakpoints'=> 'md', 'type' => 'number' ],
[ 'name' => 'start-weight', 'title' => __('Start', WE_LS_SLUG), 'breakpoints'=> 'md', 'type' => 'text' ],
[ 'name' => 'previous-weight', 'title' => __('Previous', WE_LS_SLUG), 'breakpoints'=> 'md', 'type' => 'text' ],
[ 'name' => 'latest-weight', 'title' => __('Latest', WE_LS_SLUG), 'breakpoints'=> '', 'type' => 'text' ],
[ 'name' => 'diff-weight', 'title' => $diff_label, 'breakpoints'=> 'md', 'type' => 'text' ],
[ 'name' => 'target', 'title' => __('Target', WE_LS_SLUG), 'breakpoints'=> '', 'type' => 'text' ],
[ 'name' => 'awards', 'title' => __('Awards', WE_LS_SLUG), 'breakpoints'=> 'md', 'type' => 'text' ],
];
[ 'name' => 'latest-weight', 'title' => __('Latest', WE_LS_SLUG), 'breakpoints'=> '', 'type' => 'text' ] ];
if ( false === $hide_col_diff_from_prev ) {
$columns[] = [ 'name' => 'diff-weight', 'title' => $diff_label, 'breakpoints'=> 'md', 'type' => 'text' ];
}

if ( false === $hide_column_losses ) {
$columns[] = [ 'name' => 'losses', 'title' => __('Losses', WE_LS_SLUG), 'breakpoints'=> 'md', 'type' => 'text' ];
}

if ( false === $hide_column_gains ) {
$columns[] = [ 'name' => 'gains', 'title' => __('Gains', WE_LS_SLUG), 'breakpoints'=> 'md', 'type' => 'text' ];
}

$columns[] = [ 'name' => 'target', 'title' => __('Target', WE_LS_SLUG), 'breakpoints'=> '', 'type' => 'text' ];
$columns[] = [ 'name' => 'awards', 'title' => __('Awards', WE_LS_SLUG), 'breakpoints'=> 'md', 'type' => 'text' ];

$rows = [];
$total_difference = 0;

Expand All @@ -728,6 +742,9 @@ function ws_ls_ajax_groups_users_get(){
$rows = ws_ls_groups_users_for_given_group( $group_id, $todays_entries_only );
$is_admin = ws_ls_to_bool( $is_admin );

$loss_total = 0;
$gain_total = 0;

foreach ( $rows as &$row ) {

$row[ 'display_name' ] = ( $is_admin ) ? ws_ls_get_link_to_user_profile( $row[ 'user_id' ], $row[ 'display_name' ] ) : $row[ 'display_name' ];
Expand All @@ -746,9 +763,11 @@ function ws_ls_ajax_groups_users_get(){
if ( false === empty( $row[ 'latest-weight' ] ) ) {
$row[ 'start-weight' ] = ws_ls_weight_display( $row[ 'latest-weight' ][ 'first_weight' ], NULL, 'display' );
$row[ 'previous-weight' ] = ws_ls_entry_get_previous( [ 'user-id' => $row[ 'user_id' ], 'meta' => false ] );

if ( (int) $row[ 'number-of-entries' ] > 1 ) {

if ( false === empty( $todays_entries_only ) ) {

$difference = $row[ 'latest-weight' ][ 'kg' ] - $row[ 'previous-weight' ][ 'kg' ];
$row[ 'diff-weight' ] = ws_ls_weight_display( $difference, NULL, 'display', false, true );

Expand All @@ -758,10 +777,26 @@ function ws_ls_ajax_groups_users_get(){
}

$total_difference += $difference;

$row[ 'losses' ] = NULL;
$row[ 'gains' ] = NULL;

if ( $difference > 0 ) {

$gain_total += $difference;

$row[ 'gains' ] = ws_ls_weight_display( $difference, NULL, 'display', false, true );

} else {
$row[ 'losses' ] = ws_ls_weight_display( $difference, NULL, 'display', false, true );

$loss_total += $difference;
}
}

$row[ 'previous-weight' ] = $row[ 'previous-weight' ][ 'display' ];
$row[ 'latest-weight' ] = $row[ 'latest-weight' ][ 'display' ];

}

$row[ 'target' ] = ws_ls_target_get( $row[ 'user_id' ], 'display' );
Expand All @@ -775,7 +810,9 @@ function ws_ls_ajax_groups_users_get(){
'columns' => $columns,
'rows' => $rows,
'table_id' => $table_id,
'total_difference' => ws_ls_weight_display( $total_difference, NULL, 'display', false, true )
'total_difference' => ws_ls_weight_display( $total_difference, NULL, 'display', false, true ),
'total_gains' => ws_ls_weight_display( $gain_total, NULL, 'display', false, true ),
'total_losses' => ws_ls_weight_display( $loss_total, NULL, 'display', false, true ),
];

ws_ls_cache_user_set( 'groups', $cache_key, $data, MINUTE_IN_SECONDS );
Expand Down Expand Up @@ -908,12 +945,16 @@ function ws_ls_groups_view_as_table( $user_defined_arguments ) {
return ws_ls_display_pro_upgrade_notice_for_shortcode();
}

$arguments = shortcode_atts( [ 'default-to-users-group' => false,
'disable-theme-css' => false,
'disable-main-font' => false,
'group-id' => NULL,
'enable-group-select' => true,
'todays-entries-only' => false
$arguments = shortcode_atts( [ 'default-to-users-group' => false,
'disable-theme-css' => false,
'disable-main-font' => false,
'group-id' => NULL,
'enable-group-select' => true,
'todays-entries-only' => false,
'hide-column-gains' => false,
'hide-column-losses' => false,
'hide-column-diff-from-prev' => false,
'hide-summary-row' => false
], $user_defined_arguments );

return ws_ls_component_group_view_entries( $arguments );
Expand Down
9 changes: 7 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: aliakro
Tags: weight,tracker,chart,bmi,bmr,macronutrient,measure,awards,custom fields,history,measurements,data
Requires at least: 5.7
Tested up to: 6.1.1
Stable tag: 10.3.4
Tested up to: 6.2
Stable tag: 10.3.5
Requires PHP: 7.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -152,6 +152,11 @@ Measurements are created using Custom Fields. You can therefore specify the unit

== Changelog ==

= 10.3.5 =

* Improvement: Added two new columns, "gains" and "losses" to the shortcode [wt-group-view-as-table]. Read more: https://docs.yeken.uk/shortcodes/wt-group-view-as-table.html
* Improvement: Added the argument "hide-column-diff-from-prev", "hide-column-gains", "hide-column-losses" to the shortcode [wt-group-view-as-table]. Read more: https://docs.yeken.uk/shortcodes/wt-group-view-as-table.html

= 10.3.4 =

* Maintenance: Removed reference to deprecated WP functionality (WP_User->id).
Expand Down
6 changes: 3 additions & 3 deletions weight-loss-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
/**
* Plugin Name: Weight Tracker
* Description: Allow your users to track their weight, body measurements, photos and other pieces of custom data. Display in charts, tables, shortcodes and widgets. Manage their data, issue awards, email notifications, etc! Provide advanced data on Body Mass Index (BMI), Basal Metabolic Rate (BMR), Calorie intake, Harris Benedict Formula, Macronutrients Calculator and more.
* Version: 10.3.4
* Version: 10.3.5
* Requires at least: 5.7
* Tested up to: 6.1.1
* Tested up to: 6.2
* Requires PHP: 7.2
* Author: Ali Colville
* Author URI: https://www.YeKen.uk
Expand All @@ -18,7 +18,7 @@
*/

define( 'WS_LS_ABSPATH', plugin_dir_path( __FILE__ ) );
define( 'WE_LS_CURRENT_VERSION', '10.3.4' );
define( 'WE_LS_CURRENT_VERSION', '10.3.5' );
define( 'WE_LS_TITLE', 'Weight Tracker' );
define( 'WE_LS_SLUG', 'weight-loss-tracker' );
define( 'WE_LS_LICENSE_TYPES_URL', 'https://docs.yeken.uk/features.html' );
Expand Down

0 comments on commit d54eeb4

Please sign in to comment.