Skip to content

Commit

Permalink
Bugs fixed and code refactored, again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Levdbas committed Oct 6, 2017
1 parent 2a9ac01 commit bbc197a
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 139 deletions.
23 changes: 19 additions & 4 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: levdbas
Tags: time, hours, tracking, client, pre-paid
Requires at least: 3.0.1
Tested up to: 4.8
Stable tag: 1.4
Stable tag: 1.4.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -44,24 +44,39 @@ Yes! Feel free to sent me any suggestions or feedback. I think this plugin can b


== Changelog ==
= 1.4.1 =
Thank you [Jos Klever](https://wordpress.org/support/users/josklever/) for reviewing the plugin.

bugs fixed:

* link to setup page on plugin overview is fixed.
* better check on the $workFields array if it is really empty.

enhancements:

* code refactoring, reusing code from widget page on overview page
* and thus using the same feedback flow from the widget on the overview page.
* add extra feedback when there are no work activities filled in. Providing a button to the settings page as well.


= 1.4 =

## New:
new:

* new menu setup
* main page with dashicon
* overview page with all entries
* settings page with that originally was located under settings
* better access control to widget and buttons

## Enhancements:
Enhancements:

* made the hour wheel more responsive
* code refactoring by splitting code over multiple partials.
* new translations
* UI is more consistant with WordPress in general.

## Bugs fixed:
Bugs fixed:

* fixed a bug where entering more then 24h on bought/used gave an error
* fixed a bug where when deactivating the plugin, all data was lost
Expand Down
3 changes: 2 additions & 1 deletion admin/class-support-hours-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function add_action_links( $links ) {
* Documentation : https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
*/
$settings_link = array(
'<a href="' . admin_url( $this->plugin_name ) . '.php">' . __('Settings', $this->plugin_name) . '</a>',
'<a href="' . admin_url('admin.php?page=support-hours-settings') . '">' . __('Settings', $this->plugin_name) . '</a>',
);
return array_merge( $settings_link, $links );

Expand All @@ -159,6 +159,7 @@ public function add_action_links( $links ) {
*/

public function display_plugin_page() {
include_once( 'partials/support-hours-functions.php' );
include_once( 'support-hours-admin-overview.php' );
}
public function display_plugin_setup_page() {
Expand Down
2 changes: 1 addition & 1 deletion admin/css/support-hours-admin.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions admin/css/support-hours-admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ $breakpoint-alpha: 480px;
padding: 8px 12px 4px;
font-size: 1rem;
background:#fafafa;
margin-bottom: 12px;
}
.currentDate{
display: none;
Expand Down
9 changes: 1 addition & 8 deletions admin/partials/support-hours-admin-settings-workTable.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@

<?php
$i = 0;
?>
<fieldset>
<span class="currentDate"><?php echo date_i18n("d-m-Y"); ?></span>
<table id="repeatable-fieldset-one" class="rwd-table">
Expand All @@ -15,10 +11,7 @@
</tr>
</thead>
<tbody>
<?php
// loop the $workFields. Show all.
if ( $workFields ) : foreach ( $workFields as $field ) {
?>
<?php if ( $workFields ) : foreach ( $workFields as $field ) { ?>


<tr class="repeating">
Expand Down
15 changes: 15 additions & 0 deletions admin/partials/support-hours-admin-widget-bottomMessage.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<?php if(!empty($users) && in_array($user_ID, $users) && !empty($workFields[0]['date'])): ?>

<a class="button button-primary" href="<?php echo admin_url( 'admin.php?page=support-hours-settings' ); ?>"><?php _e('Add new activity', $this->plugin_name); ?></a>

<?php if($i >= 5 && current_user_can('publish_pages')): ?>
<a class="button button-secondary" href="<?php echo admin_url( 'admin.php?page=support-hours' ); ?>"><?php _e('View all acitivities', $this->plugin_name); ?></a>
<?php endif; ?>

<?php elseif(!empty($users) && in_array($user_ID, $users)): ?>

<a class="button button-secondary" href="<?php echo admin_url( 'admin.php?page=support-hours-settings' ); ?>"><?php _e('Add first acitivity', $this->plugin_name); ?></a>

<?php endif; ?>
<?php if ($pagenow == 'index.php'): ?>
<p>
<?php if($percentage == 100) {?>
<?php _e( 'Support hours used.', $this->plugin_name); ?><br />
Expand All @@ -13,3 +27,4 @@
<?php echo $email;?>
</a>
</p>
<?php endif; ?>
33 changes: 33 additions & 0 deletions admin/partials/support-hours-admin-widget-workTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php if ($pagenow == 'admin.php?page=support-hours'): ?>
<h3><?php _e('Activities', $this->plugin_name); ?></h3>
<?php endif; ?>
<table class="worktable" width="100%">
<thead>
<tr>
<th width="20%"><?php _e('Date', $this->plugin_name); ?></th>
<th width="50%"><?php _e('Description', $this->plugin_name); ?></th>
<th width="30%"><?php _e('Time used', $this->plugin_name); ?></th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ( array_reverse($workFields) as $field ) { ?>
<tr>
<td><?php if(!empty($field['used'])) echo $field['date'] ?></td>
<td><?php if(!empty($field['used'])) echo $field['description'] ?></td>
<td><?php if(!empty($field['used'])) echo $field['used'] ?></td>
</tr>
<?php
$i++;
if ($i >= 5){
break;
}
}
?>
</tbody>
</table>
<div class="total">
<span class="bold"><?php _e('Total', $this->plugin_name); ?></span>
<span>: <?php echo AddTime($workFields); ?></span>
</div>
4 changes: 2 additions & 2 deletions admin/partials/support-hours-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function AddTime($workFields) {
}
}

// set of vars used in different files and functions.
// set of vars used in different files and functions.
$options = get_option($this->plugin_name);
$users = $options['users'];
$email = $options['email'];
Expand All @@ -61,9 +61,9 @@ function AddTime($workFields) {
$bought_hours = $options['bought_hours'];
$bought_hours = minuszeros($bought_hours);
$current_color = get_user_option( 'admin_color' );
$size = 'big';

// TODO:set code to functions.

if (strpos($used_hours, ':') !== false){
$size = 'small';
} else{
Expand Down
56 changes: 17 additions & 39 deletions admin/support-hours-admin-overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,29 @@
* Provide a page that can be seen from editor to admin. Shows all the time entries.
*
* @link http://basedonline.nl
* @since 1.0.0
* @since 1.4.0
*
* @package Support_Hours
* @subpackage Support_Hours/admin
*/
?>
<?php
// load options and functions.
$options = get_option($this->plugin_name);
$bought_hours = $options['bought_hours'];
$workFields = $options['workFields'];
include_once( 'partials/support-hours-functions.php' );
global $pagenow;
?>
<div class="wrap">
<h2><?php echo esc_html(get_admin_page_title()); ?></h2>
</div>


<?php if ( $workFields ) : ?>
<table class="worktable" width="100%">
<thead>
<tr>
<th width="20%"><?php _e('Date', $this->plugin_name); ?></th>
<th width="50%"><?php _e('Description', $this->plugin_name); ?></th>
<th width="30%"><?php _e('Time used', $this->plugin_name); ?></th>
</tr>
</thead>
<tbody>
<?php
// loop the $workFields. Show all.
foreach ( array_reverse($workFields) as $field ) {
?>
<tr>
<td><?php if(!empty($field['used'])) echo $field['date'] ?></td>
<td><?php if(!empty($field['used'])) echo $field['description'] ?></td>
<td><?php if(!empty($field['used'])) echo $field['used'] ?></td>
</tr>
<?php
}
<?php
if(!empty($users) && (!empty($bought_hours) || $bought_hours == '00:00' ) && !empty($email)):
$user_ID = get_current_user_id();
$i = 0;
if ( !empty($workFields[0]['date']) ) :
include_once( 'partials/support-hours-admin-widget-workTable.php' );
endif;
include_once( 'partials/support-hours-admin-widget-bottomMessage.php' );
elseif(empty($users) || empty($email)):
?>
</tbody>
</table>
<div class="">
<span class="bold"><?php _e('Total', $this->plugin_name); ?></span>:
<?php echo AddTime($workFields); ?> <?php _e('hours used of', $this->plugin_name); ?>
<?php echo $bought_hours; ?> <?php _e('hours', $this->plugin_name); ?>
<p>
<a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo admin_url( 'admin.php?page=support-hours-settings' ); ?>">
<?php _e( 'Configure plugin!', $this->plugin_name); ?>
</a>
</p>
<?php endif; ?>
</div>
<?php endif;?>
7 changes: 3 additions & 4 deletions admin/support-hours-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
/**
* Settings page of Support Hours
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link http://basedonline.nl
* @since 1.4.0
*
* @package Support_Hours
* @subpackage Support_Hours/admin
*/

?>
<?php
$options = get_option($this->plugin_name);
$bought_hours = $options['bought_hours'];
$users = $options['users'];
$email = $options['email'];
$workFields = $options['workFields'];
$user_ID = get_current_user_id();
$i = 0;
?>
<div class="wrap">
<?php if (empty($users) || (!empty($users) && in_array($user_ID, $users))) { ?>
<h2><?php echo esc_html(get_admin_page_title()); ?></h2>
<form method="post" name="cleanup_options" action="options.php">
<?php
// load fields and include sub-parts of this form.
settings_fields($this->plugin_name);
do_settings_sections($this->plugin_name);
include_once( 'partials/support-hours-admin-settings-textFields.php' );
Expand Down
60 changes: 31 additions & 29 deletions admin/support-hours-admin-widget.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
<?php

/**
* Provide a admin area view for the plugin
* Provide a admin widget for the plugin
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link http://basedonline.nl
* @since 1.0.0
*
* @package Support_Hours
* @subpackage Support_Hours/admin/partials
* @subpackage Support_Hours/admin
*/
// check if user is set or is empty.
if(!empty($users) && !empty($bought_hours)):
$user_ID = get_current_user_id();

// several includes to modulize the code.
$user_ID = get_current_user_id();
$i = 0;
global $pagenow;

if(!empty($users) && (!empty($bought_hours) || $bought_hours == '00:00' ) && !empty($email)):

include_once( 'partials/support-hours-admin-widget-clock.php' );
include_once( 'partials/support-hours-admin-widget-hourTable.php' );

if ( !empty($workFields[0]['date']) ) :
include_once( 'partials/support-hours-admin-widget-workTable.php' );
endif;

include_once( 'partials/support-hours-admin-widget-bottomMessage.php' );
elseif(empty($users)):
// if $users is empty or users do not match.
?>

<p>
<a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo admin_url( 'admin.php?page=support-hours-settings' ); ?>">
<?php _e( 'Configure plugin!', $this->plugin_name); ?>
</a>
</p>
elseif(empty($users) || empty($email)):
?>

<?php
else:
// user is set but $bought_hours is empty.
?>

<h4>
<?php _e( 'No support Hours bought', $this->plugin_name); ?>.
</h4>
<p>
<?php _e( 'Contact me via', $this->plugin_name); ?> <a href="mailto:<?php echo $email;?>"><?php echo $email;?></a>
</p>

<?php endif; ?>
<p>
<a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo admin_url( 'admin.php?page=support-hours-settings' ); ?>">
<?php _e( 'Configure plugin!', $this->plugin_name); ?>
</a>
</p>

<?php else: ?>

<h4>
<?php _e( 'No support Hours bought', $this->plugin_name); ?>.
</h4>
<p>
<?php _e( 'Contact me via', $this->plugin_name); ?> <a href="mailto:<?php echo $email;?>"><?php echo $email;?></a>
</p>

<?php endif; ?>
Binary file modified languages/support-hours-nl_NL.mo
Binary file not shown.
Loading

0 comments on commit bbc197a

Please sign in to comment.