Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change from elastic to meilisearch and aurora api #173

Merged
merged 23 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
44151e4
Add Javascript packages for marked and meilisearch
zimbcode Sep 22, 2023
83b7d46
Remove deprecated PHP packages
zimbcode Sep 22, 2023
5263a93
Improve HTML markup
zimbcode Sep 22, 2023
8aa6c9a
Change public eventSources to JSON feed
zimbcode Sep 22, 2023
dcfb0e6
Use marked for markdown parsing, remove event deduplication in public…
zimbcode Sep 22, 2023
95deb9c
Everything is almost done with meilisearch
zimbcode Sep 26, 2023
33aa0e2
Style hits list
zimbcode Sep 26, 2023
ba615c6
Style searchbox
zimbcode Sep 26, 2023
7f79a9b
Add indices District + Ressort
zimbcode Sep 29, 2023
473d4ce
Remove unnecessary type attribute for script tags
zimbcode Nov 6, 2023
3b3d31f
Always use "slug" naming convention
zimbcode Nov 11, 2023
f0dee5a
better syntax support
zimbcode Nov 11, 2023
fd2c894
Use marked js for markdown support
zimbcode Nov 11, 2023
08c4db5
increase maxWidth of tippy tooltips to support long event descriptions
zimbcode Nov 11, 2023
0d39afa
Fix error that feeds option might not be of type array
zimbcode Nov 11, 2023
9c55b1f
Do not show calendar switch button if no calendars were available
zimbcode Nov 11, 2023
8e94e3c
Update packages
zimbcode Nov 11, 2023
13f083a
add mdio translation
zimbcode Nov 11, 2023
d906511
Merge branch 'main' into feature/aurora-api
zimbcode Nov 11, 2023
884428a
fix linter stuff
zimbcode Nov 11, 2023
47bbdea
fix wrong owner type for mdios
zimbcode Nov 11, 2023
78bf34a
Update ReadMe and Changelog for v3.0.0
zimbcode Nov 11, 2023
7d84b34
Fix jshint errors
zimbcode Nov 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
{
"bitwise": true,
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"esversion": 11,
"expr": true,
"immed": true,
"noarg": true,
"nonbsp": true,
"onevar": true,
"quotmark": "single",
"trailing": true,
"undef": true,
"unused": true,

"browser": true,

"globals": {
"_": false,
"Backbone": false,
"jQuery": false,
"JSON": false,
"wp": false,
"export": false,
"module": false,
"require": false,
"WorkerGlobalScope": false,
"self": false,
"OffscreenCanvas": false,
"Promise": false
},
"bitwise": true,
"forin": false,
"freeze": true,
"futurehostile": true,
"latedef": "nofunc",
"leanswitch": true,
"noarg": true,
"nocomma": true,
"nonbsp": true,
"nonew": true,
"noreturnawait": true,
"predef": [
"tippy",
"lc_select",
"FullCalendar"
],
"shadow": false,
"singleGroups": false,
"trailingcomma": false,
"undef": true,
"unused": true,
"varstmt": true,

"boss": true,
"eqnull": true,

"browser": true
"varstmt": true
}
16 changes: 14 additions & 2 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ All notable changes to this project will be documented in this file.

The format is based on https://keepachangelog.com/en/1.0.0/[Keep a Changelog], and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Versioning].

== {compare}/v1.4.1\...main[Unreleased]
== {compare}/v3.0.0\...main[Unreleased]

== {compare}/v1.4.0\...main[Unreleased]
== {compare}/v2.1.2\...v3.0.0[3.0.0]

=== Changed

* Use meilisearch and aurora API instead of elastic cloud
* Get event owners from meilisearch on admin page
* Get events by aurora events.json api
* Move all requests to client
* JavaScript package updates

== {compare}/v1.4.1\...v2.1.2[2.1.2]

== {compare}/v1.4.0\...v1.4.1[1.4.1]

=== Changed

Expand Down
8 changes: 4 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ https://wordpress.org/[WordPress] plugin for displaying appointments from Elasti

== ⭐ Features

* Display events from Elastic that are allowed to be visible
* Display events from aurora that are allowed to be visible
* Multiple event owners / event sources
* Multiple views: list view, month view
* Customizable colors per event owner / event source
Expand Down Expand Up @@ -88,9 +88,9 @@ IMPORTANT: The plugin's latest version is already installed at https://hosting.r
/**
* Rotaract Params
*/
define( 'ROTARACT_APPOINTMENTS_CLOUD_ID', '<your-elastic-cloud-id>' );
define( 'ROTARACT_APPOINTMENTS_API_ID', '<your-elastic-api-id>' );
define( 'ROTARACT_APPOINTMENTS_API_KEY', '<your-elastic-api-key>' );
define( 'ROTARACT_APPOINTMENTS_SEARCH_URL', '<your-meilisearch-host-url>' );
define( 'ROTARACT_APPOINTMENTS_SEARCH_KEY', '<your-meilisearch-api-key>' );
define( 'ROTARACT_APPOINTMENTS_AURORA_URL', '<your-aurora-host-url>' );
----
. Navigate to setting page 'Rotaract' within the https://wordpress.org/support/article/administration-screens/[Administration Screen]
. Add at least one owner, select a color and save changes
Expand Down
89 changes: 40 additions & 49 deletions admin/class-rotaract-appointments-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,72 +41,58 @@ class Rotaract_Appointments_Admin {
private string $version;

/**
* The version of the JavaScript dependency LC-select.
* The version of the JavaScript dependency Instantsearch.
*
* @since 1.0.0
* @since 3.0.0
* @access private
* @var string $lc_select_version The current version of lc_select.
* @var string $instantsearch_version The current version of Meilisearch.
*/
private string $lc_select_version = '1.1.7';
private string $instantsearch_version = '4.60.0';

/**
* The Elasticsearch caller.
* The version of the JavaScript dependency Meilisearch.
*
* @since 1.0.0
* @since 3.0.0
* @access private
* @var Rotaract_Elastic_Caller $elastic_caller The object that handles search calls to the Elasticsearch instance.
* @var string $instant_meilisearch_version The current version of Meilisearch.
*/
private Rotaract_Elastic_Caller $elastic_caller;
private string $instant_meilisearch_version = '0.13.6';

/**
* Initialize the class and set its properties.
*
* @param string $rotaract_appointments The name of this plugin.
* @param string $version The version of this plugin.
* @param Rotaract_Elastic_Caller $elastic_caller Elasticsearch call handler.
* @param string $rotaract_appointments The name of this plugin.
* @param string $version The version of this plugin.
* @since 1.0.0
*/
public function __construct( string $rotaract_appointments, string $version, Rotaract_Elastic_Caller $elastic_caller ) {
public function __construct( string $rotaract_appointments, string $version ) {

$this->rotaract_appointments = $rotaract_appointments;
$this->version = $version;
$this->elastic_caller = $elastic_caller;
}

/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles() {
public function enqueue_styles(): void {

wp_enqueue_style( '$this->rotaract_appointments', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->version, 'all' );
wp_enqueue_style( 'lc-select-light', plugins_url( 'node_modules/lc-select/themes/light.css', __DIR__ ), array(), $this->lc_select_version, 'all' );
}

/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
public function enqueue_scripts(): void {

// Including the lc_select script in footer results in broken owner selection in appointments submenu page.
wp_enqueue_script( 'lc-select', plugins_url( 'node_modules/lc-select/lc_select.min.js', __DIR__ ), array(), $this->lc_select_version, true );
// Including the Meilisearch script in footer results in broken owner selection in appointments submenu page.
wp_enqueue_script( 'instantsearch', plugins_url( 'node_modules/instantsearch.js/dist/instantsearch.production.min.js', __DIR__ ), array(), $this->instantsearch_version, true );
wp_enqueue_script( 'instant-meilisearch', plugins_url( 'node_modules/@meilisearch/instant-meilisearch/dist/instant-meilisearch.umd.min.js', __DIR__ ), array( 'instantsearch' ), $this->instant_meilisearch_version, true );

wp_enqueue_script( $this->rotaract_appointments, plugins_url( 'js/settings.js', __FILE__ ), array( 'lc-select' ), $this->version, true );
wp_localize_script(
$this->rotaract_appointments,
'lcData',
array(
'labels' => array(
esc_attr__( 'Search', 'rotaract-appointments' ),
esc_attr__( 'Add', 'rotaract-appointments' ),
esc_attr__( 'Select', 'rotaract-appointments' ),
esc_attr__( 'Nothing found.', 'rotaract-appointments' ),
),
)
);
wp_enqueue_script( $this->rotaract_appointments, plugins_url( 'js/settings.js', __FILE__ ), array( 'instantsearch', 'instant-meilisearch' ), $this->version, true );
}

/**
Expand All @@ -122,17 +108,17 @@ private function get_partial( string $filename ): string {
}

/**
* HTML notice that elasticsearch configuration is missing.
* HTML notice that meilisearch configuration is missing.
*/
public function elastic_missing_notice() {
public function meilisearch_missing_notice(): void {

include $this->get_partial( 'notice-elastic-missing.php' );
include $this->get_partial( 'notice-meilisearch-missing.php' );
}

/**
* Adds setting fields for this plugin.
*/
public function admin_init() {
public function admin_init(): void {

// Register our settings.
register_setting(
Expand Down Expand Up @@ -198,7 +184,7 @@ public function admin_init() {
/**
* Adds setting menu and submenu page for this plugin.
*/
public function admin_menu() {
public function admin_menu(): void {
if ( empty( $GLOBALS['admin_page_hooks']['rotaract'] ) ) {

add_menu_page(
Expand All @@ -216,7 +202,7 @@ public function admin_menu() {
/**
* Builds the HTML for the appointments submenu page.
*/
public function rotaract_settings_html() {
public function rotaract_settings_html(): void {
// Check user capabilities.
if ( ! current_user_can( 'manage_options' ) ) {
return;
Expand All @@ -242,7 +228,7 @@ public function rotaract_settings_html() {
*
* @return array
*/
private function get_palette() {
private function get_palette(): array {
return array(
'#d41367' => __( 'Cranberry', 'rotaract-appointments' ),
'#0050a2' => __( 'Azure', 'rotaract-appointments' ),
Expand All @@ -260,7 +246,7 @@ private function get_palette() {
*
* @param array $args The settings array, defining title, id, callback.
*/
public function rotaract_appointment_section( array $args ) { // phpcs:ignore
public function rotaract_appointment_section( array $args ): void { // phpcs:ignore

include $this->get_partial( 'section-rotaract-appointments.php' );
}
Expand All @@ -270,7 +256,7 @@ public function rotaract_appointment_section( array $args ) { // phpcs:ignore
*
* @param array $args The settings array, defining ...
*/
public function appointment_owners_field( array $args ) { // phpcs:ignore
public function appointment_owners_field( array $args ): void { // phpcs:ignore
// Get the value of the setting we've registered with register_setting().
$selected_owners = get_option( 'rotaract_appointment_owners' );

Expand All @@ -281,13 +267,14 @@ public function appointment_owners_field( array $args ) { // phpcs:ignore
/**
* Builds select tag containing grouped appointment options.
*
* @param bool $is_new True if this intends to be a new owner.
* @param bool $is_prototype Flag for identifying create/update.
* @param int $index Index of the parameter.
* @param string|null $owner_name The owner's name.
* @param string|null $owner_slug The owner's slug.
* @param string|null $owner_type The owner's type.
* @param string|null $owner_color Selected color.
*/
private function print_appointment_owners_line( bool $is_new, int $index, string $owner_name = null, string $owner_color = null ) { // phpcs:ignore
$owners = $this->elastic_caller->get_all_owners();
private function print_appointment_owners_line( bool $is_prototype, int $index = -1, string $owner_name = null, string $owner_slug = null, string $owner_type = null, string $owner_color = null ): void { // phpcs:ignore
$color_palette = $this->get_palette();

include $this->get_partial( 'field-appointment-owner.php' );
Expand All @@ -298,7 +285,7 @@ private function print_appointment_owners_line( bool $is_new, int $index, string
*
* @param array $args The settings array, defining ...
*/
public function appointment_ics_field( array $args ) { // phpcs:ignore
public function appointment_ics_field( array $args ): void { // phpcs:ignore
// Get the value of the setting we've registered with register_setting().
$ics_feeds = get_option( 'rotaract_appointment_ics' );

Expand All @@ -310,11 +297,11 @@ public function appointment_ics_field( array $args ) { // phpcs:ignore
*
* @param bool $is_new True if this intends to be a new owner.
* @param int $index Index of the parameter.
* @param string|null $feed_name The feed's name.
* @param string|null $feed_url The feed's url.
* @param string|null $feed_name The owner's name.
* @param string|null $feed_url The ICS URL.
* @param string|null $feed_color Selected color.
*/
private function print_ics_line( bool $is_new, int $index, string $feed_name = null, string $feed_url = null, string $feed_color = null ) { // phpcs:ignore
private function print_ics_line( bool $is_new, int $index, string $feed_name = null, string $feed_url = null, string $feed_color = null ): void { // phpcs:ignore
$color_palette = $this->get_palette();

include $this->get_partial( 'field-ics-line.php' );
Expand All @@ -332,12 +319,16 @@ public function sanitize_rotaract_appointment_owners( ?array $input ): array {
// Re-indexing the array.
foreach ( $input as $owner ) {
$name = sanitize_text_field( $owner['name'] );
$type = sanitize_text_field( $owner['type'] );
$slug = sanitize_text_field( $owner['slug'] );
$color = sanitize_hex_color( $owner['color'] );
if ( empty( $name ) || empty( $color ) ) {
if ( empty( $name ) || empty( $type ) || empty( $slug ) || empty( $color ) ) {
continue;
}
$new_input[] = array(
'name' => $name,
'type' => $type,
'slug' => $slug,
'color' => $color,
);
}
Expand Down Expand Up @@ -375,7 +366,7 @@ public function sanitize_rotaract_appointment_ics( ?array $input ): array {
*
* @param array $args The settings array, defining ...
*/
public function appointment_owners_shortcode_manual( array $args ) { // phpcs:ignore
public function appointment_owners_shortcode_manual( array $args ): void { // phpcs:ignore

include $this->get_partial( 'field-shortcode-manual.php' );
}
Expand Down
Loading