Skip to content
Merged
Changes from all 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
24 changes: 23 additions & 1 deletion src/app/home-page/home-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import { SearchObjects } from '../shared/search/models/search-objects.model';
import { environment } from '../../environments/environment';
import { UsageReportDataService } from '../core/statistics/usage-report-data.service';
import { isUndefined } from '../shared/empty.util';

const MAX_TRUNCATE_LENGTH = 20;

@Component({
selector: 'ds-home-page',
styleUrls: ['./home-page.component.scss'],
Expand Down Expand Up @@ -232,7 +235,7 @@ export class HomePageComponent implements OnInit {
// remove `/objects` from the updatedSearchUrl
updatedSearchUrl = updatedSearchUrl.replace('/objects', '');
const fastSearchLink: FastSearchLink = Object.assign(new FastSearchLink(), {
name: facetValue.value,
name: this.truncateText(facetValue.value),
occurrences: facetValue.count,
url: updatedSearchUrl
});
Expand Down Expand Up @@ -264,6 +267,25 @@ export class HomePageComponent implements OnInit {
redirectToBrowseByField(field) {
this.router.navigateByUrl('/browse/' + field);
}

/**
* If the text is longer than MAX_TRUNCATE_LENGTH characters, replace the characters after
* the MAX_TRUNCATE_LENGTHth index with '...' This method is used to truncate
* the text in the `authors/subjects/languages` browsing section. We do not want
* to display the full text of the author/subject/language, but only
* the first MAX_TRUNCATE_LENGTH characters because it overflows to the next line.
*
* @param text
* @private
*/
private truncateText(text: string): string {
if (text.length > MAX_TRUNCATE_LENGTH) {
// Replace characters after the MAX_TRUNCATE_LENGTHth index with '...'
return text.substring(0, MAX_TRUNCATE_LENGTH) + '...';
} else {
return text; // Return the original string if it's not longer than MAX_TRUNCATE_LENGTH characters
}
}
}

/**
Expand Down