Skip to content

Commit

Permalink
Merge branch 'develop' into filip/remote-images-fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ilicfilip committed Jan 6, 2025
2 parents bea207a + 13dd774 commit 7674248
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 89 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
Fixed:

* Duplicate weekly suggested tasks.
* Fixed the REST API endpoint for getting stats.
* The REST API endpoint for getting stats.
* Scrollable monthly badges widget height on page load.
* 2026 monthly badges showing up

Enhancements:

* Refocus the "add new task" input after ToDo item is added.

= 1.0.1 =

Expand Down
7 changes: 4 additions & 3 deletions assets/css/dashboard-widgets/score.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#progress_planner_dashboard_widget_score {

.prpl-dashboard-widget {
padding-top: 5px; /* Total 16px top spacing */
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
grid-gap: calc(var(--prpl-gap) / 2);
Expand Down Expand Up @@ -36,12 +37,12 @@
}

.prpl-dashboard-widget-footer {
margin-top: 1em;
padding-top: 1em;
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid #c3c4c7; /* same color as the one WP-Core uses */
font-size: var(--prpl-font-size-base);
display: flex;
gap: 1em;
gap: 0.5rem;
align-items: center;
}
}
1 change: 1 addition & 0 deletions assets/images/logo_progress_planner_pro.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions assets/js/web-components/prpl-gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ customElements.define(
start: '270deg',
cutout: '57%',
contentFontSize: 'var(--prpl-font-size-6xl)',
contentPadding:
'var(--prpl-padding) var(--prpl-padding) calc(var(--prpl-padding) * 2) var(--prpl-padding)',
marginBottom: 'var(--prpl-padding)',
},
content = ''
) {
Expand All @@ -41,11 +44,18 @@ customElements.define(
props.cutout = this.getAttribute( 'cutout' ) || props.cutout;
props.contentFontSize =
this.getAttribute( 'contentFontSize' ) || props.contentFontSize;
props.contentPadding =
this.getAttribute( 'contentPadding' ) || props.contentPadding;
props.marginBottom =
this.getAttribute( 'marginBottom' ) || props.marginBottom;

this.innerHTML = `
<div style="padding: var(--prpl-padding) var(--prpl-padding) calc(var(--prpl-padding) * 2) var(--prpl-padding); background: ${
<div style="padding: ${ props.contentPadding };
background: ${
props.background
}; border-radius:var(--prpl-border-radius-big); aspect-ratio: 2 / 1; overflow: hidden; position: relative;margin-bottom: var(--prpl-padding);">
}; border-radius:var(--prpl-border-radius-big); aspect-ratio: 2 / 1; overflow: hidden; position: relative; margin-bottom: ${
props.marginBottom
};">
<div style="width: 100%; aspect-ratio: 1 / 1; border-radius: 100%; position: relative; background: radial-gradient(${
props.background
} 0 ${ props.cutout }, transparent ${
Expand Down
21 changes: 16 additions & 5 deletions assets/js/widgets/suggested-tasks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global customElements, progressPlannerSuggestedTasks, confetti, prplDocumentReady, progressPlannerSuggestedTask */
const PRPL_SUGGESTED_TASKS_MAX_ITEMS = 5;

/**
* Count the number of items in the list.
Expand Down Expand Up @@ -262,7 +261,8 @@ document.addEventListener( 'DOMContentLoaded', () => {

// Inject items, until we reach the maximum number of items.
while (
progressPlannerCountItems() <= PRPL_SUGGESTED_TASKS_MAX_ITEMS &&
progressPlannerCountItems() <
parseInt( progressPlannerSuggestedTasks.maxItems ) &&
progressPlannerGetNextItem()
) {
progressPlannerInjectNextItem();
Expand Down Expand Up @@ -299,8 +299,18 @@ class BadgeScroller {
init() {
this.addEventListeners();

// On page load.
this.setWrapperHeight();
// On page load, when all images are loaded.
const images = [ ...this.element.querySelectorAll( 'img' ) ];
if ( images.length ) {
Promise.all(
images.map(
( im ) =>
new Promise( ( resolve ) => ( im.onload = resolve ) )
)
).then( () => {
this.setWrapperHeight();
} );
}

// When popover is opened.
document
Expand Down Expand Up @@ -416,7 +426,8 @@ document.addEventListener(
'prplMaybeInjectSuggestedTaskEvent',
() => {
while (
progressPlannerCountItems() <= PRPL_SUGGESTED_TASKS_MAX_ITEMS &&
progressPlannerCountItems() <
parseInt( progressPlannerSuggestedTasks.maxItems ) &&
progressPlannerGetNextItem()
) {
progressPlannerInjectNextItem();
Expand Down
8 changes: 3 additions & 5 deletions assets/js/widgets/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ const progressPlannerInjectTodoItem = ( content, done, addToStart, save ) => {
document.getElementById( 'todo-list' ).appendChild( todoItemElement );
}

// Focus the new task's content element after it is added to the DOM
setTimeout( () => {
todoItemElement.querySelector( 'input[type="checkbox"]' ).focus();
}, 0 );

if ( save ) {
progressPlannerSaveTodoList();
}
Expand Down Expand Up @@ -91,5 +86,8 @@ prplDocumentReady( () => {
);

document.getElementById( 'new-todo-content' ).value = '';

// Focus the new task input element.
document.getElementById( 'new-todo-content' ).focus();
} );
} );
114 changes: 53 additions & 61 deletions classes/actions/class-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ public function __construct() {
* @return void
*/
public function register_hooks() {
// Add activity when a post is updated.
\add_action( 'post_updated', [ $this, 'post_updated' ], 10, 2 );

// Add activity when a post is added.
\add_action( 'wp_insert_post', [ $this, 'insert_post' ], 10, 2 );
// Add activity when a post is added or updated.
\add_action( 'wp_insert_post', [ $this, 'insert_post' ], 10, 3 );
\add_action( 'transition_post_status', [ $this, 'transition_post_status' ], 10, 3 );

// Add activity when a post is trashed or deleted.
Expand All @@ -40,84 +38,41 @@ public function register_hooks() {
}

/**
* Post updated.
* Insert a post.
*
* Runs on post_updated hook.
* Runs on wp_insert_post hook.
*
* @param int $post_id The post ID.
* @param \WP_Post $post The post object.
*
* @param bool $update Whether this is an update.
* @return void
*/
public function post_updated( $post_id, $post ) {
public function insert_post( $post_id, $post, $update ) {
// Bail if we should skip saving.
if ( $this->should_skip_saving( $post ) ) {
return;
}

// Reset the words count.
\progress_planner()->get_settings()->set( [ 'word_count', $post_id ], false );

if ( 'publish' !== $post->post_status ) {
return;
}

// Check if there is an update activity for this post, on this date.
$existing = \progress_planner()->get_query()->query_activities(
[
'category' => 'content',
'type' => 'update',
'data_id' => (string) $post_id,
'start_date' => \progress_planner()->get_date()->get_datetime_from_mysql_date( $post->post_modified )->modify( '-12 hours' ),
'end_date' => \progress_planner()->get_date()->get_datetime_from_mysql_date( $post->post_modified )->modify( '+12 hours' ),
],
'RAW'
);
// Set the type of activity.
$type = $update ? 'update' : 'publish';

// If there is an update activity for this post, on this date, bail.
if ( ! empty( $existing ) ) {
return;
}

$this->add_post_activity( $post, 'update' );
}

/**
* Insert a post.
*
* Runs on wp_insert_post hook.
*
* @param int $post_id The post ID.
* @param \WP_Post $post The post object.
* @return void
*/
public function insert_post( $post_id, $post ) {
// Bail if we should skip saving.
if ( $this->should_skip_saving( $post ) ) {
return;
// Reset the words count if it's an update.
if ( 'update' === $type ) {
\progress_planner()->get_settings()->set( [ 'word_count', $post_id ], false );
}

// Bail if the post is not published.
if ( 'publish' !== $post->post_status ) {
return;
}

// Check if there is a publish activity for this post.
$existing = \progress_planner()->get_query()->query_activities(
[
'category' => 'content',
'type' => 'publish',
'data_id' => (string) $post_id,
],
'RAW'
);

// If there is a publish activity for this post, bail.
if ( ! empty( $existing ) ) {
// Bail if there is a recent activity for this post.
if ( $this->is_there_recent_activity( $post, $type ) ) {
return;
}

// Add a publish activity.
$this->add_post_activity( $post, 'publish' );
// Finally add an activity.
$this->add_post_activity( $post, $type );
}

/**
Expand All @@ -138,6 +93,11 @@ public function transition_post_status( $new_status, $old_status, $post ) {
return;
}

// Bail if there is a recent activity for this post.
if ( $this->is_there_recent_activity( $post, $new_status ) ) {
return;
}

// Add activity.
$this->add_post_activity( $post, $new_status === 'publish' ? 'publish' : 'update' );
}
Expand Down Expand Up @@ -236,6 +196,38 @@ private function should_skip_saving( $post ) {
return false;
}

/**
* Check if there is a recent activity for this post.
*
* @param \WP_Post $post The post object.
* @param string $type The type of activity (ie publish, update, trash, delete etc).
*
* @return bool
*/
private function is_there_recent_activity( $post, $type ) {
// Query arguments.
$query_args = [
'category' => 'content',
'type' => $type,
'data_id' => (string) $post->ID,
];

// If it's an update add the start and end date. We don't want to add multiple update activities for the same post on the same day.
if ( 'update' === $type ) {
$query_args['start_date'] = \progress_planner()->get_date()->get_datetime_from_mysql_date( $post->post_modified )->modify( '-12 hours' );
$query_args['end_date'] = \progress_planner()->get_date()->get_datetime_from_mysql_date( $post->post_modified )->modify( '+12 hours' );
}

// Check if there is an activity for this post.
$existing = \progress_planner()->get_query()->query_activities(
$query_args,
'RAW'
);

// If there is an activity for this post, bail.
return ! empty( $existing ) ? true : false;
}

/**
* Add an update activity.
*
Expand Down
2 changes: 1 addition & 1 deletion classes/badges/class-monthly.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function init_badges() {
$start_date = $activation_date->modify( 'first day of this month' );

// Year when plugin was released.
$end_date = ( 2024 === (int) $start_date->format( 'Y' ) )
$end_date = ( 2024 === (int) $start_date->format( 'Y' ) && 2024 === (int) \gmdate( 'Y' ) )
? new \DateTime( 'last day of December next year' )
: new \DateTime( 'last day of December this year' );

Expand Down
9 changes: 6 additions & 3 deletions classes/widgets/class-suggested-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function register_scripts() {
public function enqueue_scripts() {
$handle = 'progress-planner-' . $this->id;

$current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;

// Enqueue the script.
\wp_enqueue_script( $handle );

Expand Down Expand Up @@ -123,9 +125,10 @@ public function enqueue_scripts() {
$handle,
'progressPlannerSuggestedTasks',
[
'ajaxUrl' => \admin_url( 'admin-ajax.php' ),
'nonce' => \wp_create_nonce( 'progress_planner' ),
'tasks' => $tasks,
'ajaxUrl' => \admin_url( 'admin-ajax.php' ),
'nonce' => \wp_create_nonce( 'progress_planner' ),
'tasks' => $tasks,
'maxItems' => $current_screen && 'dashboard' === $current_screen->id ? 3 : 5,
]
);
}
Expand Down
8 changes: 7 additions & 1 deletion views/admin-page-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
?>
<div class="prpl-header">
<div class="prpl-header-logo">
<?php \progress_planner()->the_asset( 'images/logo_progress_planner.svg' ); ?>
<?php
if ( \progress_planner()->is_pro_site() ) {
\progress_planner()->the_asset( 'images/logo_progress_planner_pro.svg' );
} else {
\progress_planner()->the_asset( 'images/logo_progress_planner.svg' );
}
?>
</div>

<div class="prpl-header-right">
Expand Down
8 changes: 7 additions & 1 deletion views/admin-page-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
<div class="wrap prpl-wrap prpl-settings-wrap">
<div class="prpl-header">
<div class="prpl-header-logo">
<?php \progress_planner()->the_asset( 'images/logo_progress_planner.svg' ); ?>
<?php
if ( \progress_planner()->is_pro_site() ) {
\progress_planner()->the_asset( 'images/logo_progress_planner_pro.svg' );
} else {
\progress_planner()->the_asset( 'images/logo_progress_planner.svg' );
}
?>
</div>
</div>
<h1>
Expand Down
Loading

0 comments on commit 7674248

Please sign in to comment.