Skip to content

Commit

Permalink
Optimize meta keys on Content Calendar, Board, and Overview by moving…
Browse files Browse the repository at this point in the history
… search to ajax #1768
  • Loading branch information
olatechpro committed Oct 4, 2024
1 parent 2ad94a7 commit 3fdb8f5
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 39 deletions.
3 changes: 2 additions & 1 deletion modules/calendar/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ public function get_content_calendar_datas() {
$datas = [];

// add all meta keys
$datas['meta_keys'] = $wpdb->get_col("SELECT DISTINCT meta_key FROM $wpdb->postmeta WHERE 1=1 ORDER BY meta_key ASC");
$datas['meta_keys'] = [];

// add editorial fields
if (class_exists('PP_Editorial_Metadata')) {
Expand Down Expand Up @@ -1352,6 +1352,7 @@ class="button-primary">
[
'nonce' => wp_create_nonce('publishpress-calendar-get-data'),
'moduleUrl' => $this->module_url,
'publishpressUrl' => PUBLISHPRESS_URL,
]
);

Expand Down
28 changes: 25 additions & 3 deletions modules/calendar/lib/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ jQuery(document).ready(function ($) {
}
});

$('.co-cc-content .entry-item.form-item .new-fields .field .new-item-metakey').pp_select2({
allowClear: true,
ajax: {
url: ajaxurl,
dataType: 'json',
delay: 0,
data: function (params) {
return {
action: 'publishpress_content_search_meta_keys',
nonce: $(this).attr('data-nonce'),
q: params.term
};
},
processResults: function (data) {
return {
results: data
};
},
cache: false
}
});

$('#pp-content-filters select.filter_taxonomy').pp_select2({
allowClear: true,
ajax: {
Expand Down Expand Up @@ -166,10 +188,10 @@ jQuery(document).ready(function ($) {
new_entry += '<div class="entry-item enable-item active-item customize-item-' + entryMetaKey + ' custom" data-name="' + entryMetaKey + '">';
new_entry += '<input class="customize-item-input" type="hidden" name="content_calendar_' + customizeForm + '[' + entryMetaKey + ']" value="' + entryTitle + '" />';
new_entry += '<input type="hidden" name="content_calendar_custom_' + customizeForm + '[' + entryMetaKey + ']" value="' + entryTitle + '" />';
new_entry += '<div class="items-list-item-check checked"><svg><use xlink:href="' + PPContentCalendar.moduleUrl + 'lib/content-calendar-icon.svg#svg-sprite-cu2-check-2-fill"></use></svg></div>';
new_entry += '<div class="items-list-item-check unchecked"><svg><use xlink:href="' + PPContentCalendar.moduleUrl + 'lib/content-calendar-icon.svg#svg-sprite-x"></use></svg></div>';
new_entry += '<div class="items-list-item-check checked"><svg><use xlink:href="' + PPContentCalendar.publishpressUrl + 'common/icons/content-icon.svg#svg-sprite-cu2-check-2-fill"></use></svg></div>';
new_entry += '<div class="items-list-item-check unchecked"><svg><use xlink:href="' + PPContentCalendar.publishpressUrl + 'common/icons/content-icon.svg#svg-sprite-x"></use></svg></div>';
new_entry += '<div class="items-list-item-name"><div class="items-list-item-name-text">' + entryTitle + ' <span class="customize-item-info">(' + entryMetaKey + ')</span></div></div>';
new_entry += '<div class="delete-content-calendar-item" data-meta="' + entryMetaKey + '"><svg><use xlink:href="' + PPContentCalendar.moduleUrl + 'lib/content-calendar-icon.svg#svg-sprite-cu2-menu-trash"></use></svg></div>';
new_entry += '<div class="delete-content-calendar-item" data-meta="' + entryMetaKey + '"><svg><use xlink:href="' + PPContentCalendar.publishpressUrl + 'common/icons/content-icon.svg#svg-sprite-cu2-menu-trash"></use></svg></div>';
new_entry += '</div>';
$(formClass + ' .co-cc-content .entry-item.form-item').after(new_entry);

Expand Down
7 changes: 2 additions & 5 deletions modules/calendar/library/calendar-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,8 @@ public static function content_calendar_customize_filter_form($args) {
<input class="new-item-title" type="text" placeholder="<?php esc_attr_e('Filter Title', 'publishpress'); ?>" />
</div>
<div class="field">
<select class="new-item-metakey">
<option value=""><?php esc_html_e('Select Metakey', 'publishpress'); ?></option>
<?php foreach ($meta_keys as $meta_key) : ?>
<option value="<?php echo esc_attr($meta_key); ?>"><?php echo esc_html($meta_key); ?></option>
<?php endforeach; ?>
<select class="new-item-metakey" data-nonce="<?php echo esc_attr(wp_create_nonce('publishpress-content-get-data')); ?>">
<option value=""><?php esc_html_e('Search Metakey', 'publishpress'); ?></option>
</select>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion modules/content-board/content-board.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ public function get_content_board_datas() {
$datas = [];

// add all meta keys
$datas['meta_keys'] = $wpdb->get_col("SELECT DISTINCT meta_key FROM $wpdb->postmeta WHERE 1=1 ORDER BY meta_key ASC");
$datas['meta_keys'] = [];

// add editorial fields
if (class_exists('PP_Editorial_Metadata')) {
Expand Down
29 changes: 26 additions & 3 deletions modules/content-board/lib/content-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ jQuery(document).ready(function ($) {
use_today_as_start_date_input.val(1);
});


$('.co-cc-content .entry-item.form-item .new-fields .field .new-item-metakey').pp_select2({
allowClear: true,
ajax: {
url: ajaxurl,
dataType: 'json',
delay: 0,
data: function (params) {
return {
action: 'publishpress_content_search_meta_keys',
nonce: $(this).attr('data-nonce'),
q: params.term
};
},
processResults: function (data) {
return {
results: data
};
},
cache: false
}
});

$('#pp-content-filters select#filter_author').pp_select2({
allowClear: true,
ajax: {
Expand Down Expand Up @@ -326,10 +349,10 @@ jQuery(document).ready(function ($) {
new_entry += '<div class="entry-item enable-item active-item customize-item-' + entryMetaKey + ' custom" data-name="' + entryMetaKey + '">';
new_entry += '<input class="customize-item-input" type="hidden" name="content_board_' + customizeForm + '[' + entryMetaKey + ']" value="' + entryTitle + '" />';
new_entry += '<input type="hidden" name="content_board_custom_' + customizeForm + '[' + entryMetaKey + ']" value="' + entryTitle + '" />';
new_entry += '<div class="items-list-item-check checked"><svg><use xlink:href="' + PPContentBoard.moduleUrl + 'lib/content-board-icon.svg#svg-sprite-cu2-check-2-fill"></use></svg></div>';
new_entry += '<div class="items-list-item-check unchecked"><svg><use xlink:href="' + PPContentBoard.moduleUrl + 'lib/content-board-icon.svg#svg-sprite-x"></use></svg></div>';
new_entry += '<div class="items-list-item-check checked"><svg><use xlink:href="' + PPContentBoard.publishpressUrl + 'common/icons/content-icon.svg#svg-sprite-cu2-check-2-fill"></use></svg></div>';
new_entry += '<div class="items-list-item-check unchecked"><svg><use xlink:href="' + PPContentBoard.publishpressUrl + 'common/icons/content-icon.svg#svg-sprite-x"></use></svg></div>';
new_entry += '<div class="items-list-item-name"><div class="items-list-item-name-text">' + entryTitle + ' <span class="customize-item-info">(' + entryMetaKey + ')</span></div></div>';
new_entry += '<div class="delete-content-board-item" data-meta="' + entryMetaKey + '"><svg><use xlink:href="' + PPContentBoard.moduleUrl + 'lib/content-board-icon.svg#svg-sprite-cu2-menu-trash"></use></svg></div>';
new_entry += '<div class="delete-content-board-item" data-meta="' + entryMetaKey + '"><svg><use xlink:href="' + PPContentBoard.publishpressUrl + 'common/icons/content-icon.svg#svg-sprite-cu2-menu-trash"></use></svg></div>';
new_entry += '</div>';
$(formClass + ' .co-cc-content .entry-item.form-item').after(new_entry);

Expand Down
3 changes: 2 additions & 1 deletion modules/content-board/library/content-board-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ public function enqueue_admin_scripts()
'PPContentBoard',
[
'nonce' => wp_create_nonce('content_board_action_nonce'),
'moduleUrl' => $this->module_url
'moduleUrl' => $this->module_url,
'publishpressUrl' => PUBLISHPRESS_URL,
]
);
}
Expand Down
14 changes: 4 additions & 10 deletions modules/content-board/library/content-board-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static function content_board_customize_column_form($args) {
$column_index = 0;
foreach ($columns as $column_group => $column_datas) :
$column_index++;
$hidden_style = empty($column_datas['columns']) ? 'display: none;' : '';
$hidden_style = empty($column_datas['columns']) && $column_group !== 'custom' ? 'display: none;' : '';
?>
<div class="customize-group-title title-index-<?php echo esc_attr($column_index); ?> <?php echo esc_attr($column_group); ?>" style="<?php echo esc_attr($hidden_style); ?>">
<div class="title-text"><?php echo esc_html($column_datas['title']); ?></div>
Expand All @@ -217,11 +217,8 @@ public static function content_board_customize_column_form($args) {
<input class="new-item-title" type="text" placeholder="<?php esc_attr_e('Title', 'publishpress'); ?>" />
</div>
<div class="field">
<select class="new-item-metakey">
<option value=""><?php esc_html_e('Select Metakey', 'publishpress'); ?></option>
<?php foreach ($meta_keys as $meta_key) : ?>
<option value="<?php echo esc_attr($meta_key); ?>"><?php echo esc_html($meta_key); ?></option>
<?php endforeach; ?>
<select class="new-item-metakey" data-nonce="<?php echo esc_attr(wp_create_nonce('publishpress-content-get-data')); ?>">
<option value=""><?php esc_html_e('Search Metakey', 'publishpress'); ?></option>
</select>
</div>
</div>
Expand Down Expand Up @@ -366,11 +363,8 @@ public static function content_board_customize_filter_form($args) {
<input class="new-item-title" type="text" placeholder="<?php esc_attr_e('Filter Title', 'publishpress'); ?>" />
</div>
<div class="field">
<select class="new-item-metakey">
<select class="new-item-metakey" data-nonce="<?php echo esc_attr(wp_create_nonce('publishpress-content-get-data')); ?>">
<option value=""><?php esc_html_e('Select Metakey', 'publishpress'); ?></option>
<?php foreach ($meta_keys as $meta_key) : ?>
<option value="<?php echo esc_attr($meta_key); ?>"><?php echo esc_html($meta_key); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions modules/content-overview/content-overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ public function enqueue_admin_scripts()
'PPContentOverview',
[
'nonce' => wp_create_nonce('content_overview_filter_nonce'),
'moduleUrl' => $this->module_url
'moduleUrl' => $this->module_url,
'publishpressUrl' => PUBLISHPRESS_URL,
]
);
}
Expand Down Expand Up @@ -961,7 +962,7 @@ public function get_content_overview_datas() {
$datas = [];

// add all meta keys
$datas['meta_keys'] = $wpdb->get_col("SELECT DISTINCT meta_key FROM $wpdb->postmeta WHERE 1=1 ORDER BY meta_key ASC");
$datas['meta_keys'] = [];

// add editorial fields
if (class_exists('PP_Editorial_Metadata')) {
Expand Down
28 changes: 25 additions & 3 deletions modules/content-overview/lib/content-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ jQuery(document).ready(function ($) {
use_today_as_start_date_input.val(1);
});

$('.co-cc-content .entry-item.form-item .new-fields .field .new-item-metakey').pp_select2({
allowClear: true,
ajax: {
url: ajaxurl,
dataType: 'json',
delay: 0,
data: function (params) {
return {
action: 'publishpress_content_search_meta_keys',
nonce: $(this).attr('data-nonce'),
q: params.term
};
},
processResults: function (data) {
return {
results: data
};
},
cache: false
}
});

$('#pp-content-filters select#filter_author').pp_select2({
allowClear: true,
ajax: {
Expand Down Expand Up @@ -273,10 +295,10 @@ jQuery(document).ready(function ($) {
new_entry += '<div class="entry-item enable-item active-item customize-item-' + entryMetaKey + ' custom" data-name="' + entryMetaKey + '">';
new_entry += '<input class="customize-item-input" type="hidden" name="content_overview_' + customizeForm + '[' + entryMetaKey + ']" value="' + entryTitle + '" />';
new_entry += '<input type="hidden" name="content_overview_custom_' + customizeForm + '[' + entryMetaKey + ']" value="' + entryTitle + '" />';
new_entry += '<div class="items-list-item-check checked"><svg><use xlink:href="' + PPContentOverview.moduleUrl + 'lib/content-overview-icon.svg#svg-sprite-cu2-check-2-fill"></use></svg></div>';
new_entry += '<div class="items-list-item-check unchecked"><svg><use xlink:href="' + PPContentOverview.moduleUrl + 'lib/content-overview-icon.svg#svg-sprite-x"></use></svg></div>';
new_entry += '<div class="items-list-item-check checked"><svg><use xlink:href="' + PPContentOverview.publishpressUrl + 'common/icons/content-icon.svg#svg-sprite-cu2-check-2-fill"></use></svg></div>';
new_entry += '<div class="items-list-item-check unchecked"><svg><use xlink:href="' + PPContentOverview.publishpressUrl + 'common/icons/content-icon.svg#svg-sprite-x"></use></svg></div>';
new_entry += '<div class="items-list-item-name"><div class="items-list-item-name-text">' + entryTitle + ' <span class="customize-item-info">(' + entryMetaKey + ')</span></div></div>';
new_entry += '<div class="delete-content-overview-item" data-meta="' + entryMetaKey + '"><svg><use xlink:href="' + PPContentOverview.moduleUrl + 'lib/content-overview-icon.svg#svg-sprite-cu2-menu-trash"></use></svg></div>';
new_entry += '<div class="delete-content-overview-item" data-meta="' + entryMetaKey + '"><svg><use xlink:href="' + PPContentOverview.publishpressUrl + 'common/icons/content-icon.svg#svg-sprite-cu2-menu-trash"></use></svg></div>';
new_entry += '</div>';
$(formClass + ' .co-cc-content .entry-item.form-item').after(new_entry);

Expand Down
14 changes: 4 additions & 10 deletions modules/content-overview/library/content-overview-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static function content_overview_customize_column_form($args) {
$column_index = 0;
foreach ($columns as $column_group => $column_datas) :
$column_index++;
$hidden_style = empty($column_datas['columns']) ? 'display: none;' : '';
$hidden_style = empty($column_datas['columns']) && $column_group !== 'custom' ? 'display: none;' : '';
?>
<div class="customize-group-title title-index-<?php echo esc_attr($column_index); ?> <?php echo esc_attr($column_group); ?>" style="<?php echo esc_attr($hidden_style); ?>">
<div class="title-text"><?php echo esc_html($column_datas['title']); ?></div>
Expand All @@ -216,11 +216,8 @@ public static function content_overview_customize_column_form($args) {
<input class="new-item-title" type="text" placeholder="<?php esc_attr_e('Column Title', 'publishpress'); ?>" />
</div>
<div class="field">
<select class="new-item-metakey">
<option value=""><?php esc_html_e('Select Metakey', 'publishpress'); ?></option>
<?php foreach ($meta_keys as $meta_key) : ?>
<option value="<?php echo esc_attr($meta_key); ?>"><?php echo esc_html($meta_key); ?></option>
<?php endforeach; ?>
<select class="new-item-metakey" data-nonce="<?php echo esc_attr(wp_create_nonce('publishpress-content-get-data')); ?>">
<option value=""><?php esc_html_e('Search Metakey', 'publishpress'); ?></option>
</select>
</div>
</div>
Expand Down Expand Up @@ -365,11 +362,8 @@ public static function content_overview_customize_filter_form($args) {
<input class="new-item-title" type="text" placeholder="<?php esc_attr_e('Filter Title', 'publishpress'); ?>" />
</div>
<div class="field">
<select class="new-item-metakey">
<select class="new-item-metakey" data-nonce="<?php echo esc_attr(wp_create_nonce('publishpress-content-get-data')); ?>">
<option value=""><?php esc_html_e('Select Metakey', 'publishpress'); ?></option>
<?php foreach ($meta_keys as $meta_key) : ?>
<option value="<?php echo esc_attr($meta_key); ?>"><?php echo esc_html($meta_key); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
Expand Down
Loading

0 comments on commit 3fdb8f5

Please sign in to comment.