mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Added a simple autocomplete mechanism for the footprint URL.
This commit is contained in:
parent
4675793c24
commit
3277d98ee2
10 changed files with 180 additions and 6 deletions
|
@ -694,3 +694,47 @@ table.dataTable {
|
||||||
.dataTables_length {
|
.dataTables_length {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************
|
||||||
|
* Typeahead menu
|
||||||
|
*******************************************/
|
||||||
|
|
||||||
|
.tt-query {
|
||||||
|
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
|
||||||
|
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
|
||||||
|
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tt-hint {
|
||||||
|
color: #999
|
||||||
|
}
|
||||||
|
|
||||||
|
.tt-menu { /* used to be tt-dropdown-menu in older versions */
|
||||||
|
width: 422px;
|
||||||
|
margin-top: 4px;
|
||||||
|
padding: 4px 0;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||||
|
-webkit-border-radius: 4px;
|
||||||
|
-moz-border-radius: 4px;
|
||||||
|
border-radius: 4px;
|
||||||
|
-webkit-box-shadow: 0 5px 10px rgba(0,0,0,.2);
|
||||||
|
-moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
|
||||||
|
box-shadow: 0 5px 10px rgba(0,0,0,.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tt-suggestion {
|
||||||
|
padding: 3px 20px;
|
||||||
|
line-height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tt-suggestion.tt-cursor,.tt-suggestion:hover {
|
||||||
|
color: #fff;
|
||||||
|
background-color: #0097cf;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.tt-suggestion p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
|
@ -40,6 +40,8 @@ require( 'datatables.net-select-bs4' );
|
||||||
require('datatables.net-colreorder-bs4');
|
require('datatables.net-colreorder-bs4');
|
||||||
require('bootstrap-select');
|
require('bootstrap-select');
|
||||||
require('jquery-form');
|
require('jquery-form');
|
||||||
|
require('corejs-typeahead/dist/typeahead.bundle.min');
|
||||||
|
window.Bloodhound = require('corejs-typeahead/dist/bloodhound.js');
|
||||||
|
|
||||||
//Define jquery globally
|
//Define jquery globally
|
||||||
window.$ = window.jQuery = require("jquery");
|
window.$ = window.jQuery = require("jquery");
|
||||||
|
|
|
@ -347,6 +347,31 @@ $(document).on("ajaxUI:start", function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Register typeaheads
|
||||||
|
$(document).on("ajaxUI:reload ajaxUI:start", function () {
|
||||||
|
$('input[data-autocomplete]').each(function() {
|
||||||
|
//@ts-ignore
|
||||||
|
var engine = new Bloodhound({
|
||||||
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(''),
|
||||||
|
queryTokenizer: Bloodhound.tokenizers.obj.whitespace(''),
|
||||||
|
remote: {
|
||||||
|
url: $(this).data('autocomplete'),
|
||||||
|
wildcard: 'QUERY'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(this).typeahead({
|
||||||
|
hint: true,
|
||||||
|
highlight: true,
|
||||||
|
minLength: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'states',
|
||||||
|
source: engine
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
//Need for proper body padding, with every navbar height
|
//Need for proper body padding, with every navbar height
|
||||||
$(window).resize(function () {
|
$(window).resize(function () {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"typeRoots": ["../node_modules"],
|
"typeRoots": ["../node_modules"],
|
||||||
"types": ["jquery", "bootstrap", "jquery.form", "bootstrap-treeview", "bootbox"]
|
"types": ["jquery", "bootstrap", "jquery.form", "bootstrap-treeview", "bootbox", "typeahead"]
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"node_modules"
|
||||||
|
|
|
@ -43,7 +43,8 @@
|
||||||
"twig/extra-bundle": "3.x-dev",
|
"twig/extra-bundle": "3.x-dev",
|
||||||
"twig/intl-extra": "3.x-dev",
|
"twig/intl-extra": "3.x-dev",
|
||||||
"webmozart/assert": "^1.4",
|
"webmozart/assert": "^1.4",
|
||||||
"ext-bcmath": "*"
|
"ext-bcmath": "*",
|
||||||
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"roave/security-advisories": "dev-master",
|
"roave/security-advisories": "dev-master",
|
||||||
|
|
|
@ -22,9 +22,11 @@
|
||||||
"@types/bootstrap-treeview": "^1.20.0",
|
"@types/bootstrap-treeview": "^1.20.0",
|
||||||
"@types/jquery": "^3.3.29",
|
"@types/jquery": "^3.3.29",
|
||||||
"@types/jquery.form": "^3.26.30",
|
"@types/jquery.form": "^3.26.30",
|
||||||
|
"@types/typeahead": "^0.11.32",
|
||||||
"bootbox": "^5.1.0",
|
"bootbox": "^5.1.0",
|
||||||
"bootstrap-fileinput": "^5.0.1",
|
"bootstrap-fileinput": "^5.0.1",
|
||||||
"bootstrap-select": "^1.13.8",
|
"bootstrap-select": "^1.13.8",
|
||||||
|
"corejs-typeahead": "^1.2.1",
|
||||||
"datatables.net-bs4": "^1.10.19",
|
"datatables.net-bs4": "^1.10.19",
|
||||||
"datatables.net-buttons-bs4": "^1.5.4",
|
"datatables.net-buttons-bs4": "^1.5.4",
|
||||||
"datatables.net-colreorder-bs4": "^1.5.1",
|
"datatables.net-colreorder-bs4": "^1.5.1",
|
||||||
|
|
69
src/Controller/TypeaheadController.php
Normal file
69
src/Controller/TypeaheadController.php
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* part-db version 0.1
|
||||||
|
* Copyright (C) 2005 Christoph Lechner
|
||||||
|
* http://www.cl-projects.de/
|
||||||
|
*
|
||||||
|
* part-db version 0.2+
|
||||||
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
||||||
|
* http://code.google.com/p/part-db/
|
||||||
|
*
|
||||||
|
* Part-DB Version 0.4+
|
||||||
|
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||||
|
* https://github.com/jbtronics
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Services\BuiltinAttachmentsFinder;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||||
|
use Symfony\Component\Serializer\Serializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In this controller the endpoints for the typeaheads are collected
|
||||||
|
* @Route("/typeahead")
|
||||||
|
* @package App\Controller
|
||||||
|
*/
|
||||||
|
class TypeaheadController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Route("/builtInRessources/search/{query}", name="typeahead_builtInRessources", requirements={"query"= ".+"})
|
||||||
|
*/
|
||||||
|
public function builtInRessources(Request $request, string $query, BuiltinAttachmentsFinder $finder)
|
||||||
|
{
|
||||||
|
$array = $finder->find($query);
|
||||||
|
|
||||||
|
|
||||||
|
$normalizers = [
|
||||||
|
new ObjectNormalizer()
|
||||||
|
];
|
||||||
|
$encoders = [
|
||||||
|
new JsonEncoder()
|
||||||
|
];
|
||||||
|
$serializer = new Serializer($normalizers, $encoders);
|
||||||
|
$data = $serializer->serialize($array, 'json');
|
||||||
|
return new JsonResponse($data, 200, [], true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,6 +45,8 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\UrlType;
|
use Symfony\Component\Form\Extension\Core\Type\UrlType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
use Symfony\Component\Routing\RouterInterface;
|
||||||
use Symfony\Component\Validator\Constraints\File;
|
use Symfony\Component\Validator\Constraints\File;
|
||||||
use Symfony\Component\Validator\Constraints\Url;
|
use Symfony\Component\Validator\Constraints\Url;
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
@ -53,11 +55,13 @@ class AttachmentFormType extends AbstractType
|
||||||
{
|
{
|
||||||
protected $attachment_helper;
|
protected $attachment_helper;
|
||||||
protected $trans;
|
protected $trans;
|
||||||
|
protected $urlGenerator;
|
||||||
|
|
||||||
public function __construct(AttachmentHelper $attachmentHelper, TranslatorInterface $trans)
|
public function __construct(AttachmentHelper $attachmentHelper, TranslatorInterface $trans, UrlGeneratorInterface $urlGenerator)
|
||||||
{
|
{
|
||||||
$this->attachment_helper = $attachmentHelper;
|
$this->attachment_helper = $attachmentHelper;
|
||||||
$this->trans = $trans;
|
$this->trans = $trans;
|
||||||
|
$this->urlGenerator = $urlGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
|
@ -79,6 +83,8 @@ class AttachmentFormType extends AbstractType
|
||||||
$builder->add('url', TextType::class, [
|
$builder->add('url', TextType::class, [
|
||||||
'label' => $this->trans->trans('attachment.edit.url'),
|
'label' => $this->trans->trans('attachment.edit.url'),
|
||||||
'required' => false,
|
'required' => false,
|
||||||
|
'attr' => ['data-autocomplete' => $this->urlGenerator->generate('typeahead_builtInRessources', ['query' => 'QUERY'])
|
||||||
|
],
|
||||||
'constraints' => [
|
'constraints' => [
|
||||||
$options['allow_builtins'] ? new UrlOrBuiltin() : new Url()
|
$options['allow_builtins'] ? new UrlOrBuiltin() : new Url()
|
||||||
]
|
]
|
||||||
|
|
|
@ -59,7 +59,7 @@ class BuiltinAttachmentsFinder
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find(string $keyword, array $options) : array
|
public function find(string $keyword, array $options = []) : array
|
||||||
{
|
{
|
||||||
$finder = new Finder();
|
$finder = new Finder();
|
||||||
|
|
||||||
|
@ -67,9 +67,20 @@ class BuiltinAttachmentsFinder
|
||||||
$this->configureOptions($resolver);
|
$this->configureOptions($resolver);
|
||||||
$options = $resolver->resolve($options);
|
$options = $resolver->resolve($options);
|
||||||
|
|
||||||
|
if (empty($options['placeholders'])) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
//We search only files
|
//We search only files
|
||||||
$finder->files();
|
$finder->files();
|
||||||
$finder->in($this->pathResolver->getFootprintsPath());
|
//Add the folder for each placeholder
|
||||||
|
foreach ($options['placeholders'] as $placeholder) {
|
||||||
|
$tmp = $this->pathResolver->placeholderToRealPath($placeholder);
|
||||||
|
//Ignore invalid/deactivated placeholders:
|
||||||
|
if ($tmp !== null) {
|
||||||
|
$finder->in($tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Apply filter if needed
|
//Apply filter if needed
|
||||||
if (!empty($options['filename_filter'])) {
|
if (!empty($options['filename_filter'])) {
|
||||||
|
|
16
yarn.lock
16
yarn.lock
|
@ -769,6 +769,13 @@
|
||||||
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
|
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
|
||||||
integrity sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==
|
integrity sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==
|
||||||
|
|
||||||
|
"@types/typeahead@^0.11.32":
|
||||||
|
version "0.11.32"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/typeahead/-/typeahead-0.11.32.tgz#117693a253a8ad46b3824b47539982c093cc9296"
|
||||||
|
integrity sha512-5NkqKPwkBh2dGxFEJjc4Vt9/XsaGmx+tfXMfcJxWjPvCvvCFEKRCz+bz7ZfRAiO0e0Hh1foBol3anLzMY1Ea8A==
|
||||||
|
dependencies:
|
||||||
|
"@types/jquery" "*"
|
||||||
|
|
||||||
"@types/uglify-js@*":
|
"@types/uglify-js@*":
|
||||||
version "3.0.4"
|
version "3.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-3.0.4.tgz#96beae23df6f561862a830b4288a49e86baac082"
|
resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-3.0.4.tgz#96beae23df6f561862a830b4288a49e86baac082"
|
||||||
|
@ -1942,6 +1949,13 @@ core-util-is@~1.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
|
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
|
||||||
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
|
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
|
||||||
|
|
||||||
|
corejs-typeahead@^1.2.1:
|
||||||
|
version "1.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/corejs-typeahead/-/corejs-typeahead-1.2.1.tgz#345a8afe664cc494075b59b64777807f0b3f132b"
|
||||||
|
integrity sha1-NFqK/mZMxJQHW1m2R3eAfws/Eys=
|
||||||
|
dependencies:
|
||||||
|
jquery ">=1.11"
|
||||||
|
|
||||||
cosmiconfig@^5.0.0:
|
cosmiconfig@^5.0.0:
|
||||||
version "5.2.1"
|
version "5.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.2.1.tgz#040f726809c591e77a17c0a3626ca45b4f168b1a"
|
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.2.1.tgz#040f726809c591e77a17c0a3626ca45b4f168b1a"
|
||||||
|
@ -3995,7 +4009,7 @@ jquery-form@^4.2.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
jquery ">=1.7.2"
|
jquery ">=1.7.2"
|
||||||
|
|
||||||
"jquery@>= 1.9.0", jquery@>=1.12.0, jquery@>=1.7, jquery@>=1.7.2, jquery@^3.3.1, jquery@^3.4.1:
|
"jquery@>= 1.9.0", jquery@>=1.11, jquery@>=1.12.0, jquery@>=1.7, jquery@>=1.7.2, jquery@^3.3.1, jquery@^3.4.1:
|
||||||
version "3.4.1"
|
version "3.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.4.1.tgz#714f1f8d9dde4bdfa55764ba37ef214630d80ef2"
|
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.4.1.tgz#714f1f8d9dde4bdfa55764ba37ef214630d80ef2"
|
||||||
integrity sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==
|
integrity sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue