refactor(keyword-highlighting): remove duplication after rebase

This commit is contained in:
2026-08-24 21:49:05 +02:00
parent 2f509fbbfe
commit 56ada07d97
16 changed files with 222 additions and 149 deletions
@@ -39,26 +39,6 @@
}
</div>
<ng-template #expandTmp let-article>
@if (article.snippet) {
@let expanded = isSnippetExpanded(article);
<button
mat-icon-button
class="expand-toggle"
[attr.aria-expanded]="expanded"
[matTooltip]="
expanded ? 'Textstelle ausblenden' : 'Textstelle anzeigen'
"
[attr.aria-label]="
expanded ? 'Textstelle ausblenden' : 'Textstelle anzeigen'
">
<mat-icon class="expand-icon" [class.is-expanded]="expanded">
{{ EXPAND_MORE_ICON }}
</mat-icon>
</button>
}
</ng-template>
<ng-template #titleTmp let-article>
<div class="title-cell">
<a
@@ -205,7 +185,8 @@
<app-data-table
[columns]="columns()"
[data]="elements()"
[detailTemplate]="snippetTmp" />
[detailTemplate]="snippetTmp"
[canExpand]="hasSnippet" />
</div>
<app-query-param-paginator
@@ -80,11 +80,6 @@
overflow: visible;
}
.mat-column-expand {
width: 48px;
padding-right: 0;
}
.detail-row .mat-mdc-cell {
padding: 0;
border-bottom: none;
@@ -121,15 +116,6 @@
}
}
.expand-icon {
color: var(--sg-text-muted);
transition: transform 150ms ease-in-out;
&.is-expanded {
transform: rotate(180deg);
}
}
.date-text {
white-space: nowrap;
}
@@ -35,7 +35,6 @@ import { YearRangeSliderComponent } from '../../../../shared/ui/year-range-slide
import {
CANCEL_ICON,
CHECK_CIRCLE_ICON,
EXPAND_MORE_ICON,
FILTER_OFF_ICON,
HELP_ICON,
OPEN_IN_NEW_ICON,
@@ -79,7 +78,6 @@ export class KeywordsToNewsResultsComponent {
readonly CHECK_CIRCLE_ICON = CHECK_CIRCLE_ICON;
readonly SORT_ICON = SORT_ICON;
readonly FILTER_OFF_ICON = FILTER_OFF_ICON;
readonly EXPAND_MORE_ICON = EXPAND_MORE_ICON;
readonly CANCEL_ICON = CANCEL_ICON;
readonly HELP_ICON = HELP_ICON;
readonly OPEN_IN_NEW_ICON = OPEN_IN_NEW_ICON;
@@ -166,22 +164,13 @@ export class KeywordsToNewsResultsComponent {
return baseTopicIds.length > 0 || this.selectedTopicIds().length > 0;
});
expandTmp = viewChild.required<TemplateRef<any>>('expandTmp');
titleTmp = viewChild.required<TemplateRef<any>>('titleTmp');
dateTmp = viewChild.required<TemplateRef<any>>('dateTmp');
relevanceTmp = viewChild.required<TemplateRef<any>>('relevanceTmp');
topicsTmp = viewChild.required<TemplateRef<any>>('topicsTmp');
actionsTmp = viewChild.required<TemplateRef<any>>('actionsTmp');
private readonly dataTable = viewChild(DataTableComponent);
readonly columns = computed<GenericColumn<NewsResult>[]>(() => [
{
id: 'expand',
header: '',
type: 'display',
cellTemplate: this.expandTmp(),
},
{
id: 'maintitle',
header: 'Titel',
@@ -261,10 +250,6 @@ export class KeywordsToNewsResultsComponent {
return !!topic.id && this.selectedTopicIds().includes(topic.id);
}
isSnippetExpanded(article: NewsResult): boolean {
return this.dataTable()?.expandedElement() === article;
}
readonly snippetHighlights = computed(() => {
const byArticleId = new Map<string, SnippetHighlight>();
@@ -332,6 +317,8 @@ export class KeywordsToNewsResultsComponent {
return result;
}
readonly hasSnippet = (article: NewsResult): boolean => !!article.snippet;
isTopicsExpanded(article: NewsResult): boolean {
return this.expandedTopicsIds().has(article.id);
}
@@ -11,15 +11,7 @@
<span class="snippet-label">
Fundstelle im {{ snippetSourceLabel(work) }}
</span>
<p class="snippet">
@for (segment of segments; track $index) {
@if (segment.isSearchMatch) {
<mark class="snippet-mark">{{ segment.text }}</mark>
} @else {
<span>{{ segment.text }}</span>
}
}
</p>
<app-snippet-text [segments]="segments" />
} @else if (work.matched_via?.length) {
<span class="snippet-label">Kein Treffer im Text</span>
<p class="snippet">
@@ -121,12 +121,6 @@
overflow-wrap: anywhere;
}
.snippet-mark {
background: transparent;
color: var(--sg-blue-highlight);
font-weight: 700;
}
.matched-topic {
color: var(--sg-text);
font-weight: 600;
@@ -18,20 +18,11 @@ import {
Work,
} from '../../../../api';
import { SearchResultsStateService } from '../search-results-state.service';
interface SnippetSegment {
text: string;
isSearchMatch: boolean;
}
function decodeHtml(text: string): string {
return text
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#(?:39|x27);/g, "'")
.replace(/&amp;/g, '&');
}
import {
SnippetSegment,
splitSnippet,
} from '../../../../resolvers/utils/keyword-highlight';
import { SnippetTextComponent } from '../../../../shared/ui/snippet-text/snippet-text.component';
@Component({
selector: 'app-works-results',
@@ -42,6 +33,7 @@ function decodeHtml(text: string): string {
PublicationTableComponent,
PublicationFilterComponent,
QueryParamPaginatorComponent,
SnippetTextComponent,
],
templateUrl: './works-results.component.html',
styleUrl: './works-results.component.scss',
@@ -90,37 +82,12 @@ export class KeywordsToWorksResultsComponent implements OnInit {
if (!work.id || !work.snippet) {
continue;
}
byWorkId.set(work.id, this.buildSegments(work.snippet));
byWorkId.set(work.id, splitSnippet(work.snippet));
}
return byWorkId;
});
private buildSegments(snippet: string): SnippetSegment[] {
const searchMatch = /<em>([\s\S]*?)<\/em>/g;
const segments: SnippetSegment[] = [];
let lastIndex = 0;
let match: RegExpExecArray | null;
const pushPlain = (raw: string) => {
const text = decodeHtml(raw);
if (text) {
segments.push({ text, isSearchMatch: false });
}
};
while ((match = searchMatch.exec(snippet)) !== null) {
pushPlain(snippet.slice(lastIndex, match.index));
segments.push({ text: decodeHtml(match[1]), isSearchMatch: true });
lastIndex = searchMatch.lastIndex;
}
pushPlain(snippet.slice(lastIndex));
return segments;
}
snippetSourceLabel(work: Work): string {
return work.snippet_field === 'title' ? 'Titel' : 'Abstract';
}