Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search across translations #4208

Merged
merged 4 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {DEFAULT_SCHEMA, getVocabularySelectionTypes, getMediaTypeKeys, getMediaTypes} from '../constants';
import {IVocabulary, IVocabularyTag} from 'superdesk-api';
import {IVocabulary, IVocabularyItem, IVocabularyTag} from 'superdesk-api';
import {IDirectiveScope} from 'types/Angular/DirectiveScope';
import {remove, reduce} from 'lodash';
import {gettext, downloadFile} from 'core/utils';
Expand All @@ -11,11 +11,13 @@ function getOther() {
}

export interface IScope extends IDirectiveScope<void> {
filterVocab(vocabulary: IVocabulary): boolean;
vocabularies: Array<IVocabulary>;
vocabulary: any;
tags: IVocabulary['tags'];
loading: boolean;
mediaTypes: object;
localQuery: string;
thecalcc marked this conversation as resolved.
Show resolved Hide resolved
openVocabulary(vocabulary: IVocabulary): void;
downloadVocabulary(vocabulary: IVocabulary): void;
uploadConfig(): void;
Expand Down Expand Up @@ -140,6 +142,22 @@ export function VocabularyConfigController($scope: IScope, $route, $routeParams,
$scope.existsVocabulariesForTag = (currentTag: IVocabularyTag, tab: string) =>
($scope.vocabularies || []).some((vocabulary) => checkTag(vocabulary, currentTag, tab));

/**
* Checks if a vocabulary's display_name matches the search
* query or if it matches a translation of that vocabulary.
*/
$scope.filterVocab = function(vocabulary: IVocabulary): boolean {
const translationMach = Object.values(vocabulary?.translations?.display_name ?? [])
thecalcc marked this conversation as resolved.
Show resolved Hide resolved
.find((tr: string) => tr.toLowerCase().indexOf($scope.localQuery) != -1);
thecalcc marked this conversation as resolved.
Show resolved Hide resolved
const displayNameMatch = vocabulary.display_name.toLowerCase().indexOf($scope.localQuery) != -1;

if (!$scope.localQuery || displayNameMatch || translationMach != null) {
return true;
} else {
return false;
}
};

/**
* Don't show OTHER tag if it is the only tag available for current tab
*/
Expand Down
6 changes: 3 additions & 3 deletions scripts/apps/vocabularies/views/vocabulary-config.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="sd-page__flex-helper">
<div class="sd-page__header">
<sd-search-handler ng-model="query.display_name" data-debounce="200"></sd-search-handler>
<sd-search-handler ng-model="localQuery" data-debounce="200"></sd-search-handler>
<span class="sd-page__element-grow"></span>
<button class="btn btn--primary"
ng-click="createCustomField('text')" ng-if="tab === 'text-fields'">
Expand All @@ -19,7 +19,7 @@
<i class="icon-plus-sign icon--white"></i>
<span translate>Add New</span>
</button>

<button class="btn btn--primary"
ng-click="createVocabulary()" ng-if="tab === 'vocabularies'">
<i class="icon-plus-sign icon--white"></i>
Expand Down Expand Up @@ -56,7 +56,7 @@
<div class="sd-list-item-group sd-list-item-group--space-between-items" style="max-width: 1000px;">
<div
class="sd-list-item sd-shadow--z1"
ng-repeat="vocabulary in getVocabulariesForTag(tag, tab) | orderBy:'display_name|translate' | filter: query track by vocabulary._id"
ng-repeat="vocabulary in getVocabulariesForTag(tag, tab) | orderBy:'display_name|translate' | filter: filterVocab track by vocabulary._id"
data-test-id="vocabulary-item"
>
<div class="sd-list-item__column sd-list-item__column--grow sd-list-item__column--no-border">
Expand Down
5 changes: 5 additions & 0 deletions scripts/core/superdesk-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,11 @@ declare module 'superdesk-api' {
service: {};
priority?: number;
unique_field: string;
translations?: {
display_name: {
[key: string]: string;
};
};
schema: {};
field_type:
| 'text'
Expand Down