Skip to content

Commit

Permalink
Merge branch 'DES/enhancement/#705-vl-refactor' into DES/enhancement/…
Browse files Browse the repository at this point in the history
…705-vl-refactor/icon
  • Loading branch information
brenner-company committed Mar 8, 2021
2 parents 2f188d2 + ff4707d commit d68ce44
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { isEmpty } from '@ember/utils';
import { tracked } from '@glimmer/tracking';
import { timeout } from 'ember-concurrency';
import { restartableTask } from 'ember-concurrency-decorators';
import search from 'frontend-kaleidos/utils/mu-search';

export default class PublicationsPublicationCaseSearchComponent extends Component {
@tracked searchText;
@tracked isShowingResults = false;
@tracked searchResults;

searchFields = Object.freeze([
'title',
'publicationFlowNumber',
'publicationFlowRemark',
'shortTitle',
'subcaseTitle',
'subcaseSubTitle',
'publicationFlowNumacNumbers',
'publicationFlowId'
]);
searchModifier = Object.freeze(':phrase_prefix:');

@restartableTask
*debouncedSearch(event) {
this.searchText = event.target.value;
if (!isEmpty(this.searchText)) {
yield timeout(500);
yield this.search.perform();
} else {
this.searchResults = [];
this.hideResults();
}
}

@action
showResults() {
this.isShowingResults = true;
}

@action
hideResults() {
this.isShowingResults = false;
}

@restartableTask
*search() {
if (!isEmpty(this.searchText)) {
this.searchResults = yield this.searchPublications.perform(this.searchText);
this.showResults();
} else {
this.searchResults = [];
this.hideResults();
}
}

@restartableTask
*searchPublications(searchTerm) {
const filter = {
':has:publicationFlowNumber': 'true',
};
filter[`${this.searchModifier}${this.searchFields.join(',')}`] = searchTerm;
const searchResults = yield search('cases', 0, 10, null, filter, (item) => {
const entry = item.attributes;
entry.id = item.id;
return entry;
});
return searchResults;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<WebComponents::AuInput
class="auk-input--block"
@icon="search"
@type="text"
data-test-trigger-search-input
@placeholder={{t "search-placeholder"}}
value={{this.searchText}}
{{on "input" (perform this.debouncedSearch)}}
{{on "focusout" this.hideResults}}
{{on "focusin" (if this.search.lastSuccessful this.showResults this.hideResults)}}
@enter={{perform this.search}}
@autocomplete="off"
/>
{{#if this.isShowingResults}}
<div class="autocomplete-results auk-search-results-list">
{{#each this.searchResults as |result|}}
<WebComponents::AuDropdown::Item @class="auk-search-results-list__item">
<LinkTo
data-test-publication-search-result
@route="publications.publication.documents"
@model={{result.publicationFlowId}}
>
{{#if result.subcaseSubTitle}}
{{result.subcaseSubTitle}}
{{else if result.subcaseTitle}}
{{result.subcaseTitle}}
{{else if result.shortTitle}}
{{result.shortTitle}}
{{else if result.title}}
{{result.title}}
{{/if}}
<br>
<span class="auk-u-muted auk-u-text-small">{{result.publicationFlowNumber}}</span>
</LinkTo>
</WebComponents::AuDropdown::Item>
{{else}}
{{ t "no-results-found" }}
{{/each}}
</div>
{{/if}}
37 changes: 0 additions & 37 deletions app/pods/publications/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import {
action, set
} from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { timeout } from 'ember-concurrency';
import { restartableTask } from 'ember-concurrency-decorators';
import search from 'frontend-kaleidos/utils/mu-search';

export default class PublicationsController extends Controller {
@service publicationService;
Expand All @@ -15,9 +12,6 @@ export default class PublicationsController extends Controller {
@tracked hasError = false;
@tracked numberIsAlreadyUsed = false;
@tracked isCreatingPublication = false;
@tracked searchText;
@tracked showSearchResults = false;
@tracked searchResults;
@tracked showLoader = false;
@tracked isShowPublicationFilterModal = false;

Expand All @@ -40,37 +34,6 @@ export default class PublicationsController extends Controller {
longTitle: null,
};

@restartableTask
*debouncedSearchTask(event) {
this.searchText = event.target.value;
yield timeout(500);
yield this.search(this.searchText);
}

@action
async search() {
const filter = {
':has:publicationFlowNumber': 1,
};
if (this.searchText.length === 0 || this.searchText === '') {
this.showSearchResults = false;
} else {
this.textSearchFields = ['title', 'publicationFlowNumber', 'publicationFlowRemark', 'shortTitle', 'subcaseTitle', 'subcaseSubTitle', 'publicationFlowNumacNumbers', 'publicationFlowId'];
const searchModifier = ':phrase_prefix:';
const textSearchKey = this.textSearchFields.join(',');
filter[`${searchModifier}${textSearchKey}`] = `${this.searchText}*`;
this.showSearchResults = true;
this.searchResults = await search('cases', 0, 10, null, filter, (item) => {
const entry = item.attributes;
entry.id = item.id;
return entry;
});
if (this.searchResults.length === 0) {
this.searchResults = false;
}
}
}

get getError() {
return this.hasError;
}
Expand Down
40 changes: 1 addition & 39 deletions app/pods/publications/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,7 @@
<WebComponents::AuToolbar::Group @position="right">
<WebComponents::AuToolbar::Item>
<WebComponents::AuDropdown>
<WebComponents::AuInput @icon="search"
class="auk-input--block"
type="text"
data-test-trigger-search-input
id="defaultInput"
@placeholder={{t "search-placeholder"}}
@value={{this.searchText}}
{{on "input" (perform this.debouncedSearchTask)}}
@enter={{perform this.debouncedSearchTask}}
@autocomplete="off"
/>
{{#if showSearchResults}}
<div class="autocomplete-results auk-search-results-list">
{{#each this.searchResults as |result|}}
<WebComponents::AuDropdown::Item
@class="auk-search-results-list__item">
<LinkTo
data-test-publication-search-result
@route="publications.publication.documents"
@model={{result.publicationFlowId}}
>
{{#if result.subcaseSubTitle}}
{{result.subcaseSubTitle}}
{{else if result.subcaseTitle}}
{{result.subcaseTitle}}
{{else if result.shortTitle}}
{{result.shortTitle}}
{{else if result.title}}
{{result.title}}
{{/if}}
<br>
<span class="auk-u-muted auk-u-text-small">{{result.publicationFlowNumber}}</span>
</LinkTo>
</WebComponents::AuDropdown::Item>
{{else}}
{{ t "no-results-found" }}
{{/each}}
</div>
{{/if}}
<Publications::PublicationCaseSearch/>
</WebComponents::AuDropdown>
</WebComponents::AuToolbar::Item>
<WebComponents::AuToolbar::Item>
Expand Down
2 changes: 1 addition & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(environment) {
metricsAdapters: [
{
name: 'Matomo',
environments: ['development', 'test', 'cypress-test', 'production'],
environments: ['production'],
config: {
scriptUrl: 'https://dev-kaleidos-matomo.redpencil.io', // Can optionally be CDN-sourced
trackerUrl: 'https://dev-kaleidos-matomo.redpencil.io',
Expand Down

0 comments on commit d68ce44

Please sign in to comment.