Commit 5070f4b1 authored by Simonas's avatar Simonas

Merge branch 'search-form' into dev

parents 3d3a6daa 71c0c12d
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
<footer class="l-footer">
<div class="l-inner">
......@@ -149,7 +148,7 @@
<?php
endif;
?>
<script src="/wp-content/themes/biuro/js/main.min.js" async></script>
<script src="/wp-content/themes/biuro/js/main-1e4dd15b.min.js" async></script>
<?php
// global $time_start;
......
......@@ -443,84 +443,6 @@ function df_disable_comments_admin_bar() {
add_action('init', 'df_disable_comments_admin_bar');
// $l = get_nav_menu_locations();
// $m = $l ? wp_get_nav_menu_object( $l[ 'main-menu' ] ) : null;
// $items = $m ? wp_get_nav_menu_items( $m->term_id, array( 'order' => 'DESC' ) ) : array();
// $searchPageURL = $items[0] ? $items[0]->url : '/';
// global $searchPageURL;
// $searchPage = new WP_Query( array(
// 'numberposts' => 1,
// 'post_type' => 'page',
// 'meta_key' => 'search-page',
// 'meta_value' => 'true'
// ) );
// if ( $searchPage->have_posts() ) :
// while( $searchPage->have_posts() ) :
// $searchPage->the_post();
// $searchPageURL = get_the_permalink();
// endwhile;
// else:
// $searchPageURL = '/';
// endif;
// delog( $searchPageURL );
// require_once 'includes/disable_discussion';
// function getContacts ( $request ) {
// $res = array();
// array_push($res, array(
// 'id' => 1,
// 'date' => '2019-03-15 19:05:44',
// 'name' => 'Vardenis',
// 'surname' => 'Pavardenis',
// 'phone' => '+37060000000',
// 'email' => 'email@example.com',
// 'city' => '',
// 'comment' => '',
// 'cv' => ''
// ) );
// array_push($res, array(
// 'id' => 2,
// 'date' => '2019-04-01 08:08:17',
// 'name' => 'Jonas',
// 'surname' => 'Jonaitis Kazlauskaitis',
// 'phone' => '',
// 'email' => 'jonas@example.com',
// 'city' => 'Vilnius',
// 'comment' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est ducimus iusto modi a, iure. Provident.',
// 'cv' => '/path/to/000000000000000.pdf'
// ) );
// array_push($res, array(
// 'id' => 3,
// 'date' => '2019-04-10 07:43:02',
// 'name' => 'Eglė',
// 'surname' => 'Pavardenytė',
// 'phone' => '',
// 'email' => 'egle@example.com',
// 'city' => 'Kaunas',
// 'comment' => '',
// 'cv' => ''
// ) );
// return new WP_REST_Response( $res, 200 );
// }
add_action('init', 'start_session', 1);
function start_session() {
......@@ -537,6 +459,27 @@ function start_session() {
}
}
function getAvailableOptions ( $request ) {
$res = array();
$params = $request->get_params();
if ( !$params ) {
exit;
}
$str = (string) $params['str'];
$type = (string) $params['type'];
$langID = (int) $params['langID'];
if ($type == 'city'):
$res = array_merge(getOptions('field', $str, '', $langID), getOptions('type', $str, '', $langID));
elseif ($type == 'query'):
$res = getOptions('city', '', $str, $langID);
endif;
return new WP_REST_Response( $res, 200 );
}
function getBiuroDivisions ( $request ) {
$res = array();
$params = $request->get_params();
......@@ -597,6 +540,29 @@ add_action( 'rest_api_init', function () {
]
]
));
register_rest_route( 'api/v1', '/options', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'getAvailableOptions',
'args' => [
'langID' => [
'validate_callback' => function($param, $request, $key) {
return is_string( $param );
}
],
'str' => [
'validate_callback' => function($param, $request, $key) {
return is_string( $param );
}
],
'type' => [
'validate_callback' => function($param, $request, $key) {
return is_string( $param );
}
],
]
));
});
......@@ -791,7 +757,7 @@ wp_reset_query();
define('positionsPage', $positionsPage);
function getOptions($taxonomy, $location = '', $str = '') {
function getOptions($taxonomy, $location = '', $str = '', $langID = '') {
global $query_string;
$term = '';
......@@ -803,45 +769,57 @@ function getOptions($taxonomy, $location = '', $str = '') {
if ($pageTerms):
if ($pageTerms->taxonomy === 'city' && ($taxonomy == 'type' || $taxonomy == 'field') || $taxonomy == 'city' && ($pageTerms->taxonomy == 'type' || $pageTerms->taxonomy == 'field')):
return getResults($taxonomy, $pageTerms->taxonomy, $pageTerms->term_id);
return getResults($taxonomy, $pageTerms->taxonomy, $pageTerms->term_id, $langID);
endif;
endif;
$location = $location || isset($searchQuery['city']) ? preg_replace('/[\+]/', ' ', $searchQuery['city']) : '';
$search = $str || isset($searchQuery['s']) ? preg_replace('/[\+]/', ' ', $searchQuery['s']) : '';
if ($location == ''):
$location = isset($searchQuery['city']) ? preg_replace('/[\+]/', ' ', $searchQuery['city']) : '';
endif;
if ($str == ''):
$search = isset($searchQuery['s']) ? preg_replace('/[\+]/', ' ', $searchQuery['s']) : '';
else:
$search = $str;
endif;
if ( $location !== '' && $taxonomy !== 'city') :
$city = get_term_by( 'name', $location, 'city' );
if ($city):
return getResults($taxonomy, $city->taxonomy, $city->term_id);
return getResults($taxonomy, $city->taxonomy, $city->term_id, $langID);
endif;
elseif ( $search !== '' && $taxonomy !== 'field' && $taxonomy !== 'type') :
$field = get_term_by( 'name', $search, 'field' );
if ($field):
return getResults($taxonomy, $field->taxonomy, $field->term_id);
return getResults($taxonomy, $field->taxonomy, $field->term_id, $langID);
endif;
$type = get_term_by( 'name', $search, 'type' );
if ($type):
return getResults($taxonomy, $type->taxonomy, $type->term_id);
return getResults($taxonomy, $type->taxonomy, $type->term_id, $langID);
endif;
endif;
return getResults($taxonomy, $term, $termID);
return getResults($taxonomy, $term, $termID, $langID);
}
function getResults($taxonomy, $term, $termID) {
function getResults($taxonomy, $term = '', $termID = '', $langID = '') {
global $wpdb;
$langs = pll_the_languages(array('raw'=>1));
$langID = $langs[pll_current_language('slug')]['id'];
if ($langID == ''):
$langs = pll_the_languages(array('raw'=>1));
$langID = $langs[pll_current_language('slug')]['id'];
endif;
$prefix = $wpdb->prefix;
$today = date('Y-m-d');
$order = ($taxonomy == 'city') ? 'no DESC' : 'total DESC';
$langID = 2;
$condition = ($term && $termID) ? " AND `" . $term . "`.`term_id` = " . $termID : '';
$structure = ($term && $termID) ? " LEFT JOIN `{$prefix}term_relationships` AS `rel_term2` ON `rel_term2`.`object_id` = `t`.`ID`
INNER JOIN `{$prefix}term_taxonomy` AS `rel_tt_term2` ON `rel_tt_term2`.`taxonomy` = '" . $term . "' AND `rel_tt_term2`.`term_taxonomy_id` = `rel_term2`.`term_taxonomy_id`
......@@ -909,8 +887,8 @@ function getCities() {
delog($wpdb->last_query);
delog('$terms');
debug($terms);
delog('$cities');
debug($cities);
return [];
......
......@@ -31,16 +31,16 @@
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-500.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-regular.woff2" crossorigin="anonymous" >
<style><?php include 'css/core.min.css'; ?></style>
<style><?php include 'css/core-bacf93be7c.min.css'; ?></style>
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-300.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-700.woff2" crossorigin="anonymous" >
<link rel="preload" href="/wp-content/themes/biuro/css/main.min.css" as="style" onload="this.rel='stylesheet'">
<link rel="preload" href="/wp-content/themes/biuro/css/main-1a30808647.min.css" as="style" onload="this.rel='stylesheet'">
<noscript>
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main.min.css">
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main-1a30808647.min.css">
</noscript>
<?php wp_head(); ?>
......
......@@ -31,15 +31,15 @@
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-500.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-regular.woff2" crossorigin="anonymous" >
<style><?php include 'css/core.min.css'; ?></style>
<style><?php include 'css/core-bacf93be7c.min.css'; ?></style>
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-300.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-700.woff2" crossorigin="anonymous" >
<link rel="preload" href="/wp-content/themes/biuro/css/main.min.css" as="style" onload="this.rel='stylesheet'">
<link rel="preload" href="/wp-content/themes/biuro/css/main-1a30808647.min.css" as="style" onload="this.rel='stylesheet'">
<noscript>
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main.min.css">
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main-1a30808647.min.css">
</noscript>
<?php wp_head(); ?>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -66,6 +66,49 @@ const autocomplete = (str) => {
let isOpen = false;
const update = (langID, target, str, hidden) => {
const type = (target.id === 'search-city') ? 'query' : 'city';
fetch('/wp-json/api/v1/options?langID=' + langID + '&str=' + str + '&type=' + type)
.then((t) => t.json())
.then((data) => {
if (!data || !data.length) {
return;
}
const list = data.map((option) => {
return { label: option.name + ' (' + option.total + ')', value: option.name };
});
target.box.list = list;
if (hidden) {
target.box.evaluate();
target.box.close();
} else {
target.focus();
target.box.evaluate();
}
});
};
const updateOptions = (node) => {
const target = (node.id === 'search-city') ? document.getElementById('search-query') : document.getElementById('search-city');
if (!target || (target.value && node.value)) {
return;
}
if (!target.value && node.value) {
update(node.dataset.id, target, node.value, true);
} else if (!node.value) {
update(node.dataset.id, node, target.value);
if (!target.value) {
update(node.dataset.id, target, target.value, true);
}
}
};
const toggle = (status, delay = 0) => {
setTimeout(() => {
isOpen = status;
......@@ -122,6 +165,9 @@ const autocomplete = (str) => {
node.addEventListener('awesomplete-selectcomplete', () => {
node.blur();
updateOptions(node);
if (clear) {
clear.classList.remove('u-hidden');
}
......@@ -147,7 +193,9 @@ const autocomplete = (str) => {
if (clear) {
clear.addEventListener('click', () => {
node.value = '';
node.focus();
updateOptions(node);
if (clear) {
clear.classList.add('u-hidden');
}
......@@ -156,6 +204,8 @@ const autocomplete = (str) => {
}
});
}
node.box = box;
};
autocomplete('search-city');
......
This diff is collapsed.
......@@ -25,6 +25,9 @@ if ( get_post_type() == 'page' ):
endif;
$langs = pll_the_languages(array('raw'=>1));
$langID = $langs[pll_current_language('slug')]['id'];
?>
<form id="search" class="c-search" action="<?php echo home_url(); ?>" method="get">
......@@ -41,7 +44,7 @@ endif;
endforeach;
?>
</datalist>
<input list="search-cities" id="search-city" aria-label="<?php _e('Locations', 'biuro'); ?>" name="city" value="<?php echo (isset($searchQuery['city'])) ? trim(urldecode($searchQuery['city'])) : ''; ?>" placeholder="<?php _e('Locations', 'biuro'); ?>" class="c-search--input c-search--location" />
<input list="search-cities" id="search-city" data-id="<?php echo $langID; ?>" aria-label="<?php _e('Locations', 'biuro'); ?>" name="city" value="<?php echo (isset($searchQuery['city'])) ? trim(urldecode($searchQuery['city'])) : ''; ?>" placeholder="<?php _e('Locations', 'biuro'); ?>" class="c-search--input c-search--location" />
<span class="js-clear--search-city c-search--ico-clear <?php if (!isset($searchQuery['city'])): ?>u-hidden<?php endif; ?>">
<svg width="10px" height="10px" viewBox="0 0 13 13">
<path fill="none" stroke="#B8BCC1" stroke-width="2" stroke-linecap="square" d="M6.5,6.5L0.843,0.843L6.5,6.5 l-5.657,5.657L6.5,6.5z M6.5,6.5l5.657,5.657L6.5,6.5l5.657-5.657L6.5,6.5z"/>
......@@ -71,7 +74,7 @@ endif;
endforeach;
?>
</datalist>
<input list="search-queries" id="search-query" aria-label="<?php _e('Keyword', 'biuro'); ?>" name="s" value="<?php echo (isset($searchQuery['s'])) ? trim(urldecode($searchQuery['s'])) : ''; ?>" placeholder="<?php _e('Keyword', 'biuro'); ?>" class="c-search--input c-search--keyword" />
<input list="search-queries" id="search-query" data-id="<?php echo $langID; ?>" aria-label="<?php _e('Keyword', 'biuro'); ?>" name="s" value="<?php echo (isset($searchQuery['s'])) ? trim(urldecode($searchQuery['s'])) : ''; ?>" placeholder="<?php _e('Keyword', 'biuro'); ?>" class="c-search--input c-search--keyword" />
<span class="js-clear--search-query c-search--ico-clear <?php if (!isset($searchQuery['s'])): ?>u-hidden<?php endif; ?>">
<svg width="10px" height="10px" viewBox="0 0 13 13">
<path fill="none" stroke="#B8BCC1" stroke-width="2" stroke-linecap="square" d="M6.5,6.5L0.843,0.843L6.5,6.5 l-5.657,5.657L6.5,6.5z M6.5,6.5l5.657,5.657L6.5,6.5l5.657-5.657L6.5,6.5z"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment