-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SLB-480): added the coffee module as a POC for how a UI could lo…
…ok like
- Loading branch information
Showing
8 changed files
with
176 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
_core: | ||
default_config_hash: cOqVnz_7pbb_0R31nQwih4Gh8XkmIbyFagFp6uUPaOc | ||
coffee_menus: | ||
admin: admin | ||
max_results: 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ module: | |
block: 0 | ||
block_content: 0 | ||
breakpoint: 0 | ||
coffee: 0 | ||
config: 0 | ||
config_ignore: 0 | ||
config_notify: 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
apps/cms/patches/contrib/coffee/on_the_fly_ajax_search_poc.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
diff --git a/js/coffee.js b/js/coffee.js | ||
index 23c4e09..f4ee07a 100644 | ||
--- a/js/coffee.js | ||
+++ b/js/coffee.js | ||
@@ -13,10 +13,31 @@ | ||
var initSource = proto._initSource; | ||
|
||
function filter(array, term) { | ||
- var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), 'i'); | ||
- return $.grep(array, function (value) { | ||
- return matcher.test(value.command) || matcher.test(value.label) || matcher.test(value.value); | ||
+ var matcher = new RegExp($.ui.autocomplete.escapeRegex(term.startsWith('#') ? term.substring(1) : term), 'i'); | ||
+ // By default, we do an ajax request to get the available options using a | ||
+ // search feature implemented on the server. However, if the command starts | ||
+ // with '#', then juts use the default behavior to search through the array | ||
+ // parameter, which contains all the static entries. | ||
+ if (term.startsWith('#')) { | ||
+ return $.grep(array, function (value) { | ||
+ return matcher.test(value.command) || matcher.test(value.label) || matcher.test(value.value); | ||
+ }) | ||
+ } | ||
+ | ||
+ var results; | ||
+ $.ajax({ | ||
+ url: Drupal.url('global-search?search=' + encodeURIComponent(term)), | ||
+ dataType: 'json', | ||
+ // We have to wait for the request to complete before returning the | ||
+ // results. | ||
+ async: false, | ||
+ success: function (data) { | ||
+ results = $.grep(data, function (value) { | ||
+ return matcher.test(value.command) || matcher.test(value.label) || matcher.test(value.value); | ||
+ }); | ||
+ } | ||
}); | ||
+ return results; | ||
} | ||
|
||
$.extend(proto, { |
6 changes: 6 additions & 0 deletions
6
packages/drupal/search_api_global/search_api_global.routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
search_api_global.global-search: | ||
path: '/global-search' | ||
defaults: | ||
_controller: 'Drupal\search_api_global\Controller\GlobalSearchCoffeeController::search' | ||
requirements: | ||
_permission: 'access coffee' |
44 changes: 44 additions & 0 deletions
44
packages/drupal/search_api_global/src/Controller/GlobalSearchCoffeeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Drupal\search_api_global\Controller; | ||
|
||
use Drupal\Core\Controller\ControllerBase; | ||
use Drupal\Core\Entity\EntityMalformedException; | ||
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException; | ||
use Drupal\views\Views; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class GlobalSearchCoffeeController extends ControllerBase { | ||
|
||
public function search(Request $request) { | ||
$commands = []; | ||
$search = $request->query->get('search'); | ||
// More advanced example to include view results. | ||
if ($view = Views::getView('global_search')) { | ||
$view->setDisplay('search'); | ||
if (!empty($search)) { | ||
$view->setExposedInput(['search_api_fulltext' => $search]); | ||
} | ||
$view->preExecute(); | ||
$view->execute(); | ||
|
||
foreach ($view->result as $row) { | ||
$entity = $row->_entity; | ||
$url = ''; | ||
try { | ||
$url = $entity->toUrl()->toString(); | ||
} catch (UndefinedLinkTemplateException|EntityMalformedException $e) { | ||
// Just do nothing here, in case we could not build a URL we will just | ||
// show an empty value there. | ||
} | ||
$commands[] = [ | ||
'value' => $url, | ||
'label' => $entity->label() . ' (' . $entity->getEntityType()->getLabel() . ')', | ||
'command' => $entity->label(), | ||
]; | ||
} | ||
} | ||
return new JsonResponse($commands); | ||
} | ||
} |