Skip to content

Commit

Permalink
Merge branch 'develop' into filip/dashboard-widget-design-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ilicfilip committed Dec 25, 2024
2 parents d0f9711 + 1a7e4dd commit 3575c1f
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 74 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Fixed:

* Duplicate weekly suggested tasks.
* Fixed the REST API endpoint for getting stats.

= 1.0.1 =
Expand Down
3 changes: 1 addition & 2 deletions assets/css/onboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
min-height: 1px;
}

#prpl-onboarding-form .prpl-form-fields label,
#prpl-onboarding-submit-grid-wrapper {
#prpl-onboarding-form .prpl-form-fields label {
display: grid;
grid-template-columns: 1fr 3fr;
margin-bottom: 0.5em;
Expand Down
30 changes: 23 additions & 7 deletions assets/css/welcome.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
.prpl-welcome {

.prpl-wrap.prpl-pp-not-accepted {
padding: 0;
overflow-x: hidden;
max-height: 80vh;
width: 80vw;
margin: 10vh 10vw;
z-index: 9999;
}

.prpl-welcome {

.inner-content {
padding: calc(var(--prpl-gap) * 1.5);
Expand All @@ -15,8 +12,13 @@
grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
gap: calc(var(--prpl-gap) * 2);

.left {
flex-grow: 1;
}

img {
max-width: 100%;
width: 550px;
height: auto;
}
}
Expand Down Expand Up @@ -45,4 +47,18 @@
}
}
}

ul {
list-style: disc;
margin-left: 1rem;
}

.prpl-onboard-form-radio-select {
margin-top: 0.75rem;
}

.prpl-disabled {
opacity: 0.5;
pointer-events: none;
}
}
Binary file modified assets/images/image_onboaring_block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions assets/js/onboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,15 @@ if ( document.getElementById( 'prpl-onboarding-form' ) ) {
.addEventListener( 'change', function () {
const privacyPolicyAccepted = !! this.checked;

document.getElementById(
'prpl-onboarding-submit-wrapper'
).style.display = privacyPolicyAccepted ? 'block' : 'none';
if ( privacyPolicyAccepted ) {
document
.getElementById( 'prpl-onboarding-submit-wrapper' )
.classList.remove( 'prpl-disabled' );
} else {
document
.getElementById( 'prpl-onboarding-submit-wrapper' )
.classList.add( 'prpl-disabled' );
}
} );

document
Expand Down
52 changes: 12 additions & 40 deletions classes/admin/class-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private function register_hooks() {
\add_action( 'admin_menu', [ $this, 'add_page' ] );
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
\add_action( 'wp_ajax_progress_planner_save_cpt_settings', [ $this, 'save_cpt_settings' ] );
\add_filter( 'progress_planner_admin_widgets', [ $this, 'remove_widgets_if_privacy_policy_not_accepted' ] );
}

/**
Expand Down Expand Up @@ -57,36 +56,6 @@ public function get_widgets() {
return \apply_filters( 'progress_planner_admin_widgets', $widgets );
}

/**
* Remove the widgets if the license key is not set (user has not accepted the privacy policy).
*
* @param array<\Progress_Planner\Widget> $widgets The widgets.
*
* @return array<\Progress_Planner\Widget>
*/
public function remove_widgets_if_privacy_policy_not_accepted( $widgets ) {

// When privacy policy is accepted also the license key is set.
$privacy_policy_accepted = \progress_planner()->is_privacy_policy_accepted();

if ( true === $privacy_policy_accepted ) {
return $widgets;
}

$widgets_to_keep = [
'activity-scores',
'todo',
'published-content',
];

return \array_filter(
$widgets,
function ( $widget ) use ( $widgets_to_keep ) {
return \in_array( $widget->get_id(), $widgets_to_keep, true );
}
);
}

/**
* Get a widget object.
*
Expand Down Expand Up @@ -158,15 +127,18 @@ public function enqueue_scripts() {
\progress_planner()->get_admin__scripts()->register_scripts();

if ( 'toplevel_page_progress-planner' === $current_screen->id ) {
\wp_enqueue_script( 'progress-planner-web-components-prpl-gauge' );
\wp_enqueue_script( 'progress-planner-web-components-prpl-chart-bar' );
\wp_enqueue_script( 'progress-planner-web-components-prpl-chart-line' );
\wp_enqueue_script( 'progress-planner-web-components-prpl-big-counter' );
\wp_enqueue_script( 'progress-planner-onboard' );
\wp_enqueue_script( 'progress-planner-header-filters' );
\wp_enqueue_script( 'progress-planner-todo' );
\wp_enqueue_script( 'progress-planner-settings' );
\wp_enqueue_script( 'progress-planner-grid-masonry' );

if ( true === \progress_planner()->is_privacy_policy_accepted() ) {
\wp_enqueue_script( 'progress-planner-web-components-prpl-gauge' );
\wp_enqueue_script( 'progress-planner-web-components-prpl-chart-bar' );
\wp_enqueue_script( 'progress-planner-web-components-prpl-chart-line' );
\wp_enqueue_script( 'progress-planner-web-components-prpl-big-counter' );
\wp_enqueue_script( 'progress-planner-header-filters' );
\wp_enqueue_script( 'progress-planner-settings' );
\wp_enqueue_script( 'progress-planner-grid-masonry' );
} else {
\wp_enqueue_script( 'progress-planner-onboard' );
}
}

if ( 'progress-planner_page_progress-planner-settings' === $current_screen->id ) {
Expand Down
46 changes: 46 additions & 0 deletions classes/suggested-tasks/class-local-tasks-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function __construct() {

\add_filter( 'progress_planner_suggested_tasks_items', [ $this, 'inject_tasks' ] );
\add_action( 'plugins_loaded', [ $this, 'add_plugin_integration' ] );

// Add the cleanup action.
\add_action( 'admin_init', [ $this, 'cleanup_pending_tasks' ] );
}

/**
Expand Down Expand Up @@ -229,4 +232,47 @@ public function remove_pending_task( $task ) {
$tasks = \array_diff( $tasks, [ $task ] );
return \update_option( self::OPTION_NAME, $tasks );
}

/**
* Remove all tasks which have date set to the previous week.
* Tasks for the current week will be added automatically.
*
* @return void
*/
public function cleanup_pending_tasks() {

$cleanup_recently_performed = \progress_planner()->get_cache()->get( 'cleanup_pending_tasks' );

if ( $cleanup_recently_performed ) {
return;
}

$tasks = (array) $this->get_pending_tasks();

if ( empty( $tasks ) ) {
return;
}

$task_count = count( $tasks );

$tasks = \array_filter(
$tasks,
function ( $task ) {
$task_object = ( new Local_Task_Factory( $task ) )->get_task();
$task_data = $task_object->get_data();

if ( isset( $task_data['year_week'] ) ) {
return \gmdate( 'YW' ) === $task_data['year_week'];
}

return true;
}
);

if ( count( $tasks ) !== $task_count ) {
\update_option( self::OPTION_NAME, $tasks );
}

\progress_planner()->get_cache()->set( 'cleanup_pending_tasks', true, DAY_IN_SECONDS );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ public function get_task(): Task_Local {
return new Task_Local( [ 'task_id' => $this->task_id ] );
}

$type = substr( $this->task_id, 0, $last_pos );
$task_suffix = substr( $this->task_id, $last_pos + 1 );

$task_suffix_key = 'remote-task' === $type ? 'remote_task_id' : 'year_week';

return new Task_Local(
[
'type' => substr( $this->task_id, 0, $last_pos ),
'year_week' => substr( $this->task_id, $last_pos + 1 ),
'type' => $type,
$task_suffix_key => $task_suffix,
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers;

use Progress_Planner\Suggested_Tasks\Local_Tasks\Local_Task_Factory;
/**
* Add tasks for Core updates.
*/
Expand Down Expand Up @@ -54,7 +55,10 @@ public function evaluate_task( $task_id ) {
require_once ABSPATH . 'wp-admin/includes/update.php'; // @phpstan-ignore requireOnce.fileNotFound
}

if ( 0 === strpos( $task_id, self::TYPE ) && 0 === \wp_get_update_data()['counts']['total'] ) {
$task_object = ( new Local_Task_Factory( $task_id ) )->get_task();
$task_data = $task_object->get_data();

if ( $task_data['type'] === self::TYPE && \gmdate( 'YW' ) === $task_data['year_week'] && 0 === \wp_get_update_data()['counts']['total'] ) {
return $task_id;
}
return false;
Expand Down Expand Up @@ -136,7 +140,9 @@ public function is_task_type_snoozed() {
}

foreach ( $snoozed as $task ) {
if ( self::TYPE === $task['id'] ) {
$task_object = ( new Local_Task_Factory( $task['id'] ) )->get_task();
$task_data = $task_object->get_data();
if ( $task_data['type'] === self::TYPE ) {
return true;
}
}
Expand Down
36 changes: 35 additions & 1 deletion tests/phpunit/test-class-suggested-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Suggested_Tasks_Test extends \WP_UnitTestCase {
* @return void
*/
public function set_up() {
$this->suggested_tasks = new Suggested_Tasks();
$this->suggested_tasks = \progress_planner()->get_suggested_tasks();
}

/**
Expand Down Expand Up @@ -96,4 +96,38 @@ public function test_mark_task_as_snoozed() {
*/
public function test_maybe_unsnooze_tasks() {
}

/**
* Test the task_cleanup method.
*
* @return void
*/
public function test_task_cleanup() {
// Tasks that should not be removed.
$tasks_to_keep = [
'remote-task-1234',
'post_id/14|type/update-post',
'date/202452|long/0|type/create-post',
'update-core-' . \gmdate( 'YW' ),
'settings-saved-' . \gmdate( 'YW' ),
];

foreach ( $tasks_to_keep as $task_id ) {
$this->suggested_tasks->get_local()->add_pending_task( $task_id );
}

// Tasks that should be removed.
$tasks_to_remove = [
'update-core-202451',
'settings-saved-202451',
];

foreach ( $tasks_to_remove as $task_id ) {
$this->suggested_tasks->get_local()->add_pending_task( $task_id );
}

$this->suggested_tasks->get_local()->cleanup_pending_tasks();

$this->assertEquals( count( $tasks_to_keep ), \count( $this->suggested_tasks->get_local()->get_pending_tasks() ) );
}
}
29 changes: 19 additions & 10 deletions views/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>

<div class="wrap prpl-wrap">
<h1 class="screen-reader-text"><?php \esc_html_e( 'Progress Planner', 'progress-planner' ); ?></h1>
<?php \progress_planner()->the_view( 'admin-page-header.php' ); ?>
<?php \progress_planner()->the_view( 'welcome.php' ); ?>
$prpl_privacy_policy_accepted = \progress_planner()->is_privacy_policy_accepted();
$prpl_wrapper_class = '';

if ( ! $prpl_privacy_policy_accepted ) {
$prpl_wrapper_class = 'prpl-pp-not-accepted';
}
?>

<div class="prpl-widgets-container">
<?php foreach ( \progress_planner()->get_admin__page()->get_widgets() as $prpl_admin_widget ) : ?>
<?php $prpl_admin_widget->render(); ?>
<?php endforeach; ?>
</div>
<div class="wrap prpl-wrap <?php echo esc_attr( $prpl_wrapper_class ); ?>">
<?php if ( true === $prpl_privacy_policy_accepted ) : ?>
<h1 class="screen-reader-text"><?php \esc_html_e( 'Progress Planner', 'progress-planner' ); ?></h1>
<?php \progress_planner()->the_view( 'admin-page-header.php' ); ?>
<div class="prpl-widgets-container">
<?php foreach ( \progress_planner()->get_admin__page()->get_widgets() as $prpl_admin_widget ) : ?>
<?php $prpl_admin_widget->render(); ?>
<?php endforeach; ?>
</div>
<?php else : ?>
<?php \progress_planner()->the_view( 'welcome.php' ); ?>
<?php endif; ?>
</div>
Loading

0 comments on commit 3575c1f

Please sign in to comment.