Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tagify
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
tagify
Commits
c72793d9
Commit
c72793d9
authored
1 year ago
by
David Galeano
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3401241
by gxleano: Fix Number of result when 'On click' option is...
parent
066bdfea
No related branches found
Branches containing commit
Tags
7.x-4.0-rc1
Tags containing commit
1 merge request
!45
Issue #3401241 by gxleano: Fix Number of result when 'On click' option is...
Pipeline
#48875
passed
1 year ago
Stage: build
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
js/tagify.js
+27
-20
27 additions, 20 deletions
js/tagify.js
src/Controller/TagifyEntityAutocompleteController.php
+5
-2
5 additions, 2 deletions
src/Controller/TagifyEntityAutocompleteController.php
src/TagifyEntityAutocompleteMatcher.php
+2
-7
2 additions, 7 deletions
src/TagifyEntityAutocompleteMatcher.php
with
34 additions
and
29 deletions
js/tagify.js
+
27
−
20
View file @
c72793d9
...
...
@@ -64,53 +64,60 @@
tagify
.
updateValueByDOMTags
()
}
function
handleAutocomplete
(
value
){
function
handleAutocomplete
(
value
,
selectedEntities
){
tagify
.
whitelist
=
null
;
// https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort
controller
&&
controller
.
abort
();
controller
=
new
AbortController
();
// Show loading animation meanwhile the dropdown suggestions are hided.
value
!==
''
?
tagify
.
loading
(
true
)
:
tagify
.
loading
(
false
);
fetch
(
$
(
input
).
attr
(
'
data-autocomplete-url
'
)
+
'
?q=
'
+
encodeURIComponent
(
value
),
{
signal
:
controller
.
signal
})
.
then
(
res
=>
res
.
json
())
.
then
(
function
(
newWhitelist
)
{
fetch
(
$
(
input
).
attr
(
'
data-autocomplete-url
'
)
+
'
?q=
'
+
encodeURIComponent
(
value
)
+
'
&selected=
'
+
selectedEntities
,
{
signal
:
controller
.
signal
})
.
then
(
res
=>
res
.
json
())
.
then
(
function
(
newWhitelist
)
{
let
newWhitelistData
=
[];
newWhitelist
.
forEach
(
function
(
current
)
{
newWhitelistData
.
push
({
value
:
current
.
label
,
entity_id
:
current
.
entity_id
,
...
current
.
attributes
});
newWhitelist
.
forEach
(
function
(
current
)
{
newWhitelistData
.
push
({
value
:
current
.
label
,
entity_id
:
current
.
entity_id
,
...
current
.
attributes
});
});
if
(
newWhitelistData
)
{
// build the whitelist with the values coming from the fetch
tagify
.
whitelist
=
newWhitelistData
;
// update whitelist Array in-place
tagify
.
loading
(
false
).
dropdown
.
show
(
value
)
// render the suggestions dropdown
});
}
}).
catch
(
error
=>
{
console
.
error
(
'
Error fetching data:
'
,
error
);
});
}
// onInput event.
let
onInput
=
Drupal
.
debounce
(
function
(
e
)
{
let
value
=
e
.
detail
.
value
;
handleAutocomplete
(
value
);
handleAutocomplete
(
value
,
tagify
.
value
.
map
(
item
=>
item
.
entity_id
)
);
},
500
);
// onEditInput event.
let
onEditInput
=
Drupal
.
debounce
(
function
(
e
)
{
let
value
=
e
.
detail
.
data
.
newValue
;
handleAutocomplete
(
value
);
},
500
);
// onFocusInput event.
let
onFocusInput
=
Drupal
.
debounce
(
function
()
{
handleAutocomplete
(
''
);
handleAutocomplete
(
value
,
tagify
.
value
.
map
(
item
=>
item
.
entity_id
));
},
500
);
// Edit input event (When user is editing the tag).
tagify
.
on
(
'
edit:input
'
,
onEditInput
)
// Input event (When user is creating the tag).
tagify
.
on
(
'
input
'
,
onInput
)
// Focus input event (When user interacts with the field).
tagify
.
on
(
'
focus
'
,
onFocusInput
)
// If 'On click' dropdown suggestions is enabled.
if
(
!
tagify
.
settings
.
dropdown
.
enabled
)
{
// Getting 'tagify__input' element.
const
tagifyInput
=
document
.
querySelector
(
'
.tagify__input
'
);
tagifyInput
.
addEventListener
(
'
click
'
,
function
()
{
handleAutocomplete
(
''
,
tagify
.
value
.
map
(
item
=>
item
.
entity_id
));
});
}
});
}
};
...
...
This diff is collapsed.
Click to expand it.
src/Controller/TagifyEntityAutocompleteController.php
+
5
−
2
View file @
c72793d9
...
...
@@ -74,13 +74,16 @@ class TagifyEntityAutocompleteController extends ControllerBase {
*/
public
function
handleAutocomplete
(
Request
$request
,
$target_type
,
$selection_handler
,
$selection_settings_key
)
{
$matches
=
[];
// Get already selected entity ids.
$selected
=
$request
->
query
->
get
(
'selected'
)
?
explode
(
','
,
$request
->
query
->
get
(
'selected'
))
:
[];
// Get the typed string from the URL, if it exists.
$input
=
$request
->
query
->
get
(
'q'
);
if
(
$input
!==
NULL
)
{
// Selection settings are passed in as a hashed key of a serialized array
// stored in the key/value store.
$selection_settings
=
$this
->
keyValue
(
'entity_autocomplete'
)
->
get
(
$selection_settings_key
,
FALSE
);
// Validate the autocomplete minimum length.
if
(
$input
===
''
&&
$selection_settings
[
'suggestions_dropdown'
]
!==
0
)
{
return
new
JsonResponse
([]);
...
...
@@ -99,7 +102,7 @@ class TagifyEntityAutocompleteController extends ControllerBase {
// key/value store.
throw
new
AccessDeniedHttpException
();
}
$matches
=
$this
->
matcher
->
getMatches
(
$target_type
,
$selection_handler
,
$selection_settings
,
mb_strtolower
(
$input
),
$
request
->
query
->
all
(
'
selected
'
)
);
$matches
=
$this
->
matcher
->
getMatches
(
$target_type
,
$selection_handler
,
$selection_settings
,
mb_strtolower
(
$input
),
$selected
);
}
return
new
JsonResponse
(
$matches
);
...
...
This diff is collapsed.
Click to expand it.
src/TagifyEntityAutocompleteMatcher.php
+
2
−
7
View file @
c72793d9
...
...
@@ -85,18 +85,14 @@ class TagifyEntityAutocompleteMatcher implements TagifyEntityAutocompleteMatcher
// Get an array of matching entities.
$match_operator
=
!
empty
(
$selection_settings
[
'match_operator'
])
?
$selection_settings
[
'match_operator'
]
:
'CONTAINS'
;
$match_limit
=
isset
(
$selection_settings
[
'match_limit'
])
?
(
int
)
$selection_settings
[
'match_limit'
]
:
10
;
$entity_labels
=
$handler
->
getReferenceableEntities
(
$string
,
$match_operator
,
$match_limit
+
count
(
$selected
));
$entity_labels
=
$handler
->
getReferenceableEntities
(
$string
,
$match_operator
,
(
$match_limit
===
0
)
?
$match_limit
:
$match_limit
+
count
(
$selected
));
// Loop through the entities and convert them into autocomplete output.
foreach
(
$entity_labels
as
$bundle
=>
$values
)
{
foreach
(
$values
as
$entity_id
=>
$label
)
{
// Filter out already selected items.
if
(
in_array
(
$entity_id
,
$selected
))
{
continue
;
}
$matches
[
$entity_id
]
=
$this
->
buildTagifyItem
(
$entity_id
,
$label
,
$bundle
);
}
}
...
...
@@ -108,7 +104,6 @@ class TagifyEntityAutocompleteMatcher implements TagifyEntityAutocompleteMatcher
$this
->
moduleHandler
->
alter
(
'tagify_autocomplete_matches'
,
$matches
,
$options
);
}
return
array_values
(
$matches
);
}
...
...
@@ -131,7 +126,7 @@ class TagifyEntityAutocompleteMatcher implements TagifyEntityAutocompleteMatcher
return
[
'entity_id'
=>
$entity_id
,
'label'
=>
Html
::
decodeEntities
(
$label
),
'type'
=>
$bundle
'type'
=>
$bundle
,
];
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment