Commit 4a1e633a authored by Karl Hasselbring's avatar Karl Hasselbring

Improved: Benutzter Foki wird auf Erbebnisseite automatisch als Suchfokus ausgewählt

Fixed: Fokus Erstellungs- und Bearbeitungs-Modal
parent b4bb8356
<?php
namespace App\Http\Controllers;
use App;
class FokiLoader
{
public static function loadFoki()
{
$sumaFile = "";
if (App::isLocale('en')) {
$sumaFile = config_path() . "/sumas.xml";
} else {
$sumaFile = config_path() . "/sumas.xml";
}
$xml = simplexml_load_file($sumaFile);
$sumas = $xml->xpath("suma");
$foki = [];
foreach ($sumas as $suma) {
if ((!isset($suma['disabled']) || $suma['disabled'] === "") && (!isset($suma['userSelectable']) || $suma['userSelectable']->__toString() === "1")) {
if (isset($suma['type'])) {
$f = explode(",", $suma['type']->__toString());
foreach ($f as $tmp) {
$displayName = $suma['displayName']->__toString();
$url = isset($suma['homepage']) ? $suma['homepage']->__toString() : "https://metager.de";
$foki[$tmp][$suma['name']->__toString()] = ['displayName' => $displayName, 'url' => $url];
}
} else {
$displayName = $suma['displayName']->__toString();
$url = isset($suma['homepage']) ? $suma['homepage']->__toString() : "https://metager.de";
$foki["andere"][$suma['name']->__toString()] = ['displayName' => $displayName, 'url' => $url];
}
}
}
return $foki;
}
}
......@@ -58,7 +58,6 @@ class StartpageController extends Controller
->with('browser', (new Agent())->browser())
->with('navbarFocus', 'suche')
->with('theme', $theme)
->with('foki', $this->loadFoki())
->with('focus', $request->input('focus', 'web'))
->with('time', $request->input('param_time', '1500'))
->with('request', $request->input('request', 'GET'))
......@@ -133,10 +132,7 @@ class StartpageController extends Controller
public function loadSettings(Request $request)
{
$foki = $this->loadFoki();
return view('settings')
->with('foki', $foki)
->with('title', 'Einstellungen')
->with('js', ['settings.js'])
->with('navbarFocus', 'suche');
......@@ -159,37 +155,4 @@ class StartpageController extends Controller
->with('link', $link)
->with('password', $password);
}
private function loadFoki()
{
$sumaFile = "";
if (App::isLocale('en')) {
$sumaFile = config_path() . "/sumas.xml";
} else {
$sumaFile = config_path() . "/sumas.xml";
}
$xml = simplexml_load_file($sumaFile);
$sumas = $xml->xpath("suma");
$foki = [];
foreach ($sumas as $suma) {
if ((!isset($suma['disabled']) || $suma['disabled'] === "") && (!isset($suma['userSelectable']) || $suma['userSelectable']->__toString() === "1")) {
if (isset($suma['type'])) {
$f = explode(",", $suma['type']->__toString());
foreach ($f as $tmp) {
$displayName = $suma['displayName']->__toString();
$url = isset($suma['homepage']) ? $suma['homepage']->__toString() : "https://metager.de";
$foki[$tmp][$suma['name']->__toString()] = ['displayName' => $displayName, 'url' => $url];
}
} else {
$displayName = $suma['displayName']->__toString();
$url = isset($suma['homepage']) ? $suma['homepage']->__toString() : "https://metager.de";
$foki["andere"][$suma['name']->__toString()] = ['displayName' => $displayName, 'url' => $url];
}
}
}
return $foki;
}
}
$(function () {
loadLocalStorage();
setActionListeners();
setSearchbarActionListeners();
loadInitialCustomFocuses();
checkFocusEditable();
loadSelectedFocus();
});
/**
......@@ -17,7 +18,7 @@ function loadLocalStorage () {
/**
* Sets all action listeners for this page
*/
function setActionListeners () {
function setSearchbarActionListeners () {
$('.focusCheckbox').click(toggleDeleteButton);
$('#addFocusBtn').click(() => showFocusCreateDialog(''));
$('#editFocusBtn').click(editCurrentFocus);
......@@ -73,6 +74,7 @@ function loadInitialCustomFocuses () {
}
}
}
/**
* Shows the focus create dialog
* If an id is given it will try to load a focus for the given id
......@@ -165,10 +167,10 @@ function saveFocus () {
alert('No characters other than a-z, A-Z, 0-9, ä, ö, ü, ß, -, _ allowed, at least 1 character');
break;
case 'es':
alert('Por favor, introduzca un nombre válido'); // TODO
alert('Por favor, introduzca un nombre válido');
break;
default:
alert('Bitte gültigen Namen eingeben:\n* Keine Sonderzeichen\n* Mindestens 1 Buchstabe\n'); // TODO
alert('Bitte gültigen Namen eingeben:\n* Keine Sonderzeichen\n* Mindestens 1 Buchstabe\n');
break;
}
return;
......@@ -336,23 +338,11 @@ function disableEditFocusBtn () {
$('#editFocusBtn').addClass('disabled').off('click');
}
function loadSavedResults () {
var results = new Results();
if (results.length > 0) {
var html = $('\
<div class="focus">\
<input id="savedResults" class="focus-radio hide" name="focus" value="container" form="searchForm" type="radio" required="">\
<label id="saved-results-label" class="focus-label" for="savedResults">\
<span class="glyphicon glyphicon-floppy-disk"></span>\
<span class="content">gespeicherte Ergebnisse</span>\
<span class="badge">' + results.length + '</span>\
</label>\
</div>\
');
$('#addFocusBtnDiv').before(html);
$('#foki input#savedResults').change(function () {
if ($(this).prop('checked')) $('#searchForm').submit();
});
function loadSelectedFocus() {
var url = window.location;
var focus = /focus=(focus_\w+)/.exec(url)[1];
if (focus) {
setFocus(focus);
}
}
......
$(document).ready(function () {
activateJSOnlyContent();
createCustomFocuses();
var focus = $('#foki > li.active > a').attr('aria-controls');
var custom = $('#foki > li.active').hasClass('custom-focus-tab-selector');
getDocumentReadyForUse(focus, custom);
......@@ -365,184 +364,7 @@ function productWidget () {
}
$('.lightSliderContainer').removeClass('hidden');
}
/**
* Creates focus tab and tab selector for every stored focus in local storage
*/
function createCustomFocuses () {
for (var key in localStorage) {
if (key.startsWith('focus_')) {
var focus = loadFocusById(key);
var active = false;
if (getActiveFocusId() === getIdFromName(focus.name)) {
active = true;
}
addFocus(focus, active);
addTab(focus, active);
}
}
}
/**
* Adds a focuses tab selector to the tab selector section
*
* @if( $metager->getFokus() === "produktsuche" )
* <li id="produktsucheTabSelector" class="active tab-selector" role="presentation" data-loaded="1">
* <a aria-controls="produktsuche" data-href="#produktsuche" href="#produktsuche">
* <i class="fa fa-shopping-cart" aria-hidden="true"></i>
* <span class="hidden-xs">{{ trans('index.foki.produkte') }}</span>
* </a>
* </li>
* @else
* <li id="produktsucheTabSelector" class="tab-selector" role="presentation" data-loaded="0">
* <a aria-controls="produktsuche" data-href="{!! $metager->generateSearchLink('produktsuche') !!}" href="{!! $metager->generateSearchLink('produktsuche', false) !!}">
* <i class="fa fa-shopping-cart" aria-hidden="true"></i>
* <span class="hidden-xs">{{ trans('index.foki.produkte') }}</span>
* </a>
* </li>
* @endif
*/
function addFocus (focus, active = false) {
var id = getIdFromName(focus.name);
var foki = document.getElementById('foki');
// create <input>
var focusElement = document.createElement('li');
focusElement.id = id + 'TabSelector';
focusElement.classList.add('tab-selector');
focusElement.classList.add('custom-focus-tab-selector');
if (active) {
focusElement.classList.add('active');
focusElement.setAttribute('data-loaded', '1');
} else {
focusElement.setAttribute('data-loaded', '0');
}
focusElement.setAttribute('role', 'presentation');
// create <a>
var focusElementLink = document.createElement('a');
focusElementLink.setAttribute('aria-controls', id);
var searchLink = generateSearchLinkForFocus(focus);
focusElementLink.setAttribute('data-href', searchLink);
focusElementLink.setAttribute('href', searchLink);
// create <a> icon
var focusElementIcon = document.createElement('i');
focusElementIcon.classList.add('fa');
focusElementIcon.classList.add('fa-star');
focusElementIcon.setAttribute('aria-hidden', 'true');
// create <span> focusname
var focusElementName = document.createElement('span');
focusElementName.classList.add('hidden-xs');
focusElementName.innerHTML = focus.name;
// add new elements
var mapsTabSelector = document.getElementById('mapsTabSelector');
foki.insertBefore(focusElement, mapsTabSelector);
focusElement.appendChild(focusElementLink);
focusElementLink.appendChild(focusElementIcon);
focusElementLink.appendChild(focusElementName);
}
/**
* Adds a focuses tab to the tab section
*
* @if( $metager->getFokus() === "produktsuche" )
* <div role="tabpanel" class="tab-pane active" id="produktsuche">
* <div class="row">
* @yield('results')
* </div>
* </div>
* @else
* <div role="tabpanel" class="tab-pane" id="produktsuche">
* <div class="loader">
* <img src="/img/ajax-loader.gif" alt="" />
* </div>
* </div>
* @endif
*/
function addTab (focus, active = false) {
var id = getIdFromName(focus.name);
// create tab div
var tabPane = document.createElement('div');
tabPane.id = id;
tabPane.classList.add('tab-pane');
if (active) {
tabPane.classList.add('active');
}
tabPane.setAttribute('role', 'tabpanel');
// create row div
var row = document.createElement('div');
row.classList.add('loader');
// create loader image
var img = document.createElement('img');
img.setAttribute('src', '/img/ajax-loader.gif');
img.setAttribute('alt', '');
row.appendChild(img);
// add new elements
var tabs = document.getElementById('main-content-tabs');
tabs.appendChild(tabPane);
tabPane.appendChild(row);
}
/**
* Turns a name into an id
* Converts special characters and spaces
*/
function getIdFromName (name) {
return 'focus_' + name.split(' ').join('_').toLowerCase();
}
/**
* Loads the focus object for the given id from local storage
*/
function loadFocusById (id) {
return JSON.parse(localStorage.getItem(id));
}
/**
* Gets the id of the currently active focus
*/
function getActiveFocusId () {
var search = window.location.search;
var from = search.indexOf('focus=') + 'focus='.length;
var to = search.substring(from).indexOf('&') + from;
if (to <= 0) {
to = search.substring(from).length;
}
return search.substring(from, to);
}
/**
* Turns the link of the current page into a search link for the given focus
*/
// TODO catch error if link is http://localhost:8000/meta/meta.ger3?
function generateSearchLinkForFocus (focus) {
var link = document.location.href;
// remove old engine settings
// not yet tested, only for compability problems with old versions of bookmarks and plugins
/*
while (link.indexOf("engine_") !== -1) {
var from = search.indexOf("engine_")
var to = search.substring(from).indexOf("&") + from
if (to === 0) {
to = search.substring(from).length
}
link = link.substring(0, from) + link.substring(to)
}
*/
// add new engine settings
for (var key in focus) {
if (key.startsWith('engine_')) {
var focusName = key.substring('engine_'.length);
link += '&' + focusName + '=' + focus[key];
}
}
link += '&out=results';
link = replaceFocusInUrl(link);
return link;
}
/**
* Replaces the focus in a given url with the "angepasst" focus
*/
function replaceFocusInUrl (url) {
var from = url.indexOf('focus=');
var to = url.substring(from).indexOf('&') + from;
if (to === 0) {
to = url.substring(from).length;
}
url = url.substring(0, from) + url.substring(to);
return url + '&focus=angepasst';
}
/**
* Loads the content for a given fokus
*/
......
$(function () {
loadLocalStorage();
setActionListeners();
setSearchbarActionListeners();
loadInitialCustomFocuses();
checkFocusEditable();
loadSelectedFocus();
});
/**
......@@ -17,7 +18,7 @@ function loadLocalStorage () {
/**
* Sets all action listeners for this page
*/
function setActionListeners () {
function setSearchbarActionListeners () {
$('.focusCheckbox').click(toggleDeleteButton);
$('#addFocusBtn').click(() => showFocusCreateDialog(''));
$('#editFocusBtn').click(editCurrentFocus);
......@@ -73,6 +74,7 @@ function loadInitialCustomFocuses () {
}
}
}
/**
* Shows the focus create dialog
* If an id is given it will try to load a focus for the given id
......@@ -165,10 +167,10 @@ function saveFocus () {
alert('No characters other than a-z, A-Z, 0-9, ä, ö, ü, ß, -, _ allowed, at least 1 character');
break;
case 'es':
alert('Por favor, introduzca un nombre válido'); // TODO
alert('Por favor, introduzca un nombre válido');
break;
default:
alert('Bitte gültigen Namen eingeben:\n* Keine Sonderzeichen\n* Mindestens 1 Buchstabe\n'); // TODO
alert('Bitte gültigen Namen eingeben:\n* Keine Sonderzeichen\n* Mindestens 1 Buchstabe\n');
break;
}
return;
......@@ -336,22 +338,10 @@ function disableEditFocusBtn () {
$('#editFocusBtn').addClass('disabled').off('click');
}
function loadSavedResults () {
var results = new Results();
if (results.length > 0) {
var html = $('\
<div class="focus">\
<input id="savedResults" class="focus-radio hide" name="focus" value="container" form="searchForm" type="radio" required="">\
<label id="saved-results-label" class="focus-label" for="savedResults">\
<span class="glyphicon glyphicon-floppy-disk"></span>\
<span class="content">gespeicherte Ergebnisse</span>\
<span class="badge">' + results.length + '</span>\
</label>\
</div>\
');
$('#addFocusBtnDiv').before(html);
$('#foki input#savedResults').change(function () {
if ($(this).prop('checked')) $('#searchForm').submit();
});
function loadSelectedFocus() {
var url = window.location;
var focus = /focus=(focus_\w+)/.exec(url)[1];
if (focus) {
setFocus(focus);
}
}
......@@ -3,8 +3,8 @@
@section('title', $title )
@section('content')
@include('modals.plugin-modal')
@include('modals.create-focus-modal')
@include('modals.plugin-modal')
<h1 id="mglogo"><a class="hidden-xs" href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/") }}">MetaGer</a></h1>
@include('parts.searchbar', ['class' => 'startpage-searchbar'])
<ul class="list-inline searchform-bonus hidden">
......@@ -16,7 +16,7 @@
@if (LaravelLocalization::getCurrentLocale() == "de")
<li>
<a href="https://suma-ev.de/presse/Werbefreie-Suche-mit-MetaGer.html" target="_blank" class="btn btn-default mutelink">
Werbefreie Suche mit MetaGer
Werbefreie Suche mit MetaGer
</a>
</li>
@endif
......
......@@ -21,6 +21,7 @@
</head>
<body id="resultBody">
@if( !isset($suspendheader) )
@include('modals.create-focus-modal')
@include('layouts.researchandtabs')
@else
<div class="tab-content container-fluid">
......
......@@ -26,36 +26,26 @@
</button>
</div>
</div>
{{--
<h2>{!! trans('settings.suchmaschinen.1') !!}
<small>
<button type="button" class="btn btn-link allUnchecker hide">{!! trans('settings.suchmaschinen.2') !!}</button>
</small>
</h2>
--}} @foreach( $foki as $fokus => $sumas )
<div class="headingGroup {{ $fokus }}">
<h3 class="focus-category">
@lang("settings.foki." . $fokus) {{--
<small>
<button type="button" class="checker btn btn-link hide" data-type="{{ $fokus }}">{!! trans('settings.suchmaschinen.3') !!}</button>
</small>
--}}
</h3>
<div class="row">
@foreach( $sumas as $name => $data )
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="checkbox settings-checkbox">
<label>
<input type="checkbox" name="engine_{{ $name }}" class="focusCheckbox" @if ($fokus=='web' ) checked @endif>{{ $data['displayName'] }}
<a class="settings-icon" target="_blank" rel="noopener" href="{{ $data['url'] }}">
<i class="fa fa-link" aria-hidden="true"></i>
</a>
</label>
@foreach( App\Http\Controllers\FokiLoader::loadFoki() as $fokus => $sumas )
<div class="headingGroup {{ $fokus }}">
<h3 class="focus-category">
@lang("settings.foki." . $fokus)
</h3>
<div class="row">
@foreach( $sumas as $name => $data )
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="checkbox settings-checkbox">
<label>
<input type="checkbox" name="engine_{{ $name }}" class="focusCheckbox" @if ($fokus=='web' ) checked @endif>{{ $data['displayName'] }}
<a class="settings-icon" target="_blank" rel="noopener" href="{{ $data['url'] }}">
<i class="fa fa-link" aria-hidden="true"></i>
</a>
</label>
</div>
</div>
@endforeach
</div>
@endforeach
</div>
</div>
@endforeach
<div class="clearfix">
<div class="settings-modal-buttons pull-right">
......
<!-- Don't forget to @include('modals.create-focus-modal') -->
<!-- Don't forget <script type="text/javascript" src="{{ elixir('js/searchbar.js') }}"></script> -->
<fieldset>
<form id="searchForm" method={{ $request }} action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/meta/meta.ger3") }}" accept-charset="UTF-8">
<form id="searchForm" method={{ $request }} action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/meta/meta.ger3 ") }}" accept-charset="UTF-8">
<div class="searchbar {{$class or ''}}">
<div class="search-focus-selector">
<select id="focus-select" name="focus" style="font-family: FontAwesome, sans-serif;">
......@@ -21,13 +23,13 @@
</button>
</div>
<div class="search-settings">
<a id="settings-btn" class="mutelink btn btn-default" href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "settings") }}">
<a id="settings-btn" class="mutelink btn btn-default" href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "settings ") }}">
<i class="fa fa-cog" aria-hidden="true"></i>
</a>
</div>
<div class="search-input-submit">
<div class="search-input">
<input type="text" name="eingabe" required="" autofocus="" autocomplete="{{$autocomplete or 'off'}}" class="form-control" placeholder="{{ trans('index.placeholder') }}">
<input type="text" name="eingabe" required="" autofocus="" autocomplete="{{$autocomplete or 'off'}}" class="form-control"placeholder="{{ trans('index.placeholder') }}">
</div>
<div class="search-submit" id="submit-inputgroup">
<button type="submit">
......@@ -36,23 +38,11 @@
</div>
</div>
<div class="search-hidden">
<input type="hidden" name="encoding" value="utf8">
@if (isset($option_values))
@foreach($option_values as $option => $value)
<input type="hidden" name={{ $option }} value={{ $value }}>
@endforeach
@endif
@if (isset($option_values))
<input type="hidden" name="time" value={{ $time }}>
@endif
@if (isset($focusPages))
@foreach ($focusPages as $fp)
<input type="hidden" name={{ $fp }} value="on">
@endforeach
@endif
@if (isset($theme))
<input type="hidden" name="theme" value={{ $theme }}>
@endif
<input type="hidden" name="encoding" value="utf8"> @if (isset($option_values)) @foreach($option_values as $option => $value)
<input type="hidden" name={{ $option }} value={{ $value }}> @endforeach @endif @if (isset($option_values))
<input type="hidden" name="time" value={{ $time }}> @endif @if (isset($focusPages)) @foreach ($focusPages as $fp)
<input type="hidden" name={{ $fp }} value="on"> @endforeach @endif @if (isset($theme))
<input type="hidden" name="theme" value={{ $theme }}> @endif
</div>
</div>
</form>
......
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