Skip to content

Commit

Permalink
Merge pull request #1587 from UUDigitalHumanitieslab/feature/clean-up…
Browse files Browse the repository at this point in the history
…-frontend-corpus-model

clean up frontend corpus model
  • Loading branch information
lukavdplas authored Jun 4, 2024
2 parents 2343999 + 1ef6201 commit d6eb9e2
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 42 deletions.
2 changes: 1 addition & 1 deletion frontend/src/app/corpus-header/corpus-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CorpusHeaderComponent implements OnChanges, OnInit {

ngOnChanges(changes: SimpleChanges): void {
if (this.corpus) {
this.wordModelsPresent = this.corpus.word_models_present;
this.wordModelsPresent = this.corpus.wordModelsPresent;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('DocumentViewComponent', () => {
fixture = TestBed.createComponent(DocumentViewComponent);
component = fixture.componentInstance;
component.corpus = _.merge({
scan_image_type: 'farout_image_type',
scanImageType: 'farout_image_type',
fields: [mockField]
}, mockCorpus);
component.document = makeDocument({ great_field: 'Hello world!' });
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/document-view/document-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class DocumentViewComponent implements OnChanges {
}

get showScanTab() {
return !!this.corpus.scan_image_type;
return !!this.corpus.scanImageType;
}

ngOnChanges(changes: SimpleChanges): void {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/image-view/image-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class ImageViewComponent implements OnChanges {

ngOnChanges(changes: SimpleChanges) {
if (changes.corpus) {
this.allowDownload = this.corpus.allow_image_download;
this.mediaType = this.corpus.scan_image_type;
this.allowDownload = this.corpus.allowImageDownload;
this.mediaType = this.corpus.scanImageType;
}
if (
changes.document &&
Expand Down
19 changes: 6 additions & 13 deletions frontend/src/app/models/corpus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { Store } from '../store/types';
import { SimpleStore } from '../store/simple-store';

// corresponds to the corpus definition on the backend.
export class Corpus implements ElasticSearchIndex {
export class Corpus {
constructor(
public serverName,
/**
* Internal name for referring to this corpus e.g. in URLs.
*/
Expand All @@ -25,15 +24,13 @@ export class Corpus implements ElasticSearchIndex {
public fields: CorpusField[],
public minDate: Date,
public maxDate: Date,
public scan_image_type: string,
public allow_image_download: boolean,
public word_models_present: boolean,
public scanImageType: string,
public allowImageDownload: boolean,
public wordModelsPresent: boolean,
public languages: string[],
public category: string,
public descriptionpage?: string,
public citationPage?: string,
public documentContext?: DocumentContext,
public new_highlight?: boolean,
public newHighlight?: boolean,
public defaultSort?: SortState,
public languageField?: CorpusField,
) { }
Expand All @@ -47,14 +44,10 @@ export class Corpus implements ElasticSearchIndex {
}

get displayLanguages(): string {
return this.languages.join(', '); // may have to truncate long lists?
return this.languages.join(', ');
}
}

export interface ElasticSearchIndex {
index: string;
serverName: string;
}

export interface DocumentContext {
contextFields: CorpusField[];
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/app/models/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import { SimpleStore } from '../store/simple-store';
const corpus: Corpus = {
name: 'mock-corpus',
title: 'Mock Corpus',
serverName: 'default',
description: '',
index: 'mock-corpus',
minDate: new Date('1800-01-01'),
minYear: 1800,
maxDate: new Date('1900-01-01'),
maxYear: 1900,
scan_image_type: null,
allow_image_download: true,
word_models_present: false,
scanImageType: null,
allowImageDownload: true,
wordModelsPresent: false,
fields: [
mockField2,
mockFieldDate,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/services/corpus.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('CorpusService', () => {
expect(items.length).toBe(1);
const corpus = _.first(items);

expect(corpus.scan_image_type).toBe('png');
expect(corpus.scanImageType).toBe('png');

const fieldData = [
{
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/app/services/corpus.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export class CorpusService {
private parseCorpusItem = (data: any): Corpus => {
const allFields: CorpusField[] = data.fields.map(this.parseField);
return new Corpus(
data.server_name,
data.name,
data.title,
data.description,
Expand All @@ -90,8 +89,6 @@ export class CorpusService {
data.word_models_present,
data.languages,
data.category,
data.description_page,
data.citation_page,
this.parseDocumentContext(data.document_context, allFields),
data.new_highlight,
this.parseDefaultSort(data.default_sort, allFields),
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/utils/es-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const makeHighlightSpecification = (corpus: Corpus, queryText?: string, h
field.positionsOffsets &&
// add matched_fields for stemmed highlighting
// ({ [field.name]: {"type": "fvh", "matched_fields": ["speech", "speech.stemmed"] }}):
corpus.new_highlight
corpus.newHighlight
? {
[field.name]: {
type: 'fvh',
Expand Down
24 changes: 9 additions & 15 deletions frontend/src/mock-data/corpus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,14 @@ export const mockFieldDate = new CorpusField({

export const mockCorpus: Corpus = {
name: 'test1',
serverName: 'default',
index: 'test1',
title: 'Test corpus',
description: 'This corpus is for mocking',
minDate: new Date('1800-01-01'),
maxDate: new Date('1900-01-01'),
image: 'test.jpg',
scan_image_type: 'pdf',
allow_image_download: false,
word_models_present: false,
scanImageType: 'pdf',
allowImageDownload: false,
wordModelsPresent: false,
directDownloadLimit: 500,
fields: [mockField, mockField2],
languages: ['English'],
Expand All @@ -157,16 +155,14 @@ export const mockCorpus: Corpus = {

export const mockCorpus2 = {
name: 'test2',
serverName: 'default',
index: 'test2',
title: 'Test corpus 2',
description: 'This corpus is for mocking',
minDate: new Date('1850-01-01'),
maxDate: new Date('2000-01-01'),
image: 'test.jpg',
scan_image_type: 'pdf',
allow_image_download: false,
word_models_present: false,
scanImageType: 'pdf',
allowImageDownload: false,
wordModelsPresent: false,
directDownloadLimit: 1000,
fields: [mockField2],
languages: ['English', 'French'],
Expand All @@ -177,16 +173,14 @@ export const mockCorpus2 = {

export const mockCorpus3: Corpus = {
name: 'test3',
serverName: 'default',
index: 'test3',
title: 'Test corpus 3',
description: 'This corpus is for mocking',
minDate: new Date(),
maxDate: new Date(),
image: 'test.jpg',
scan_image_type: 'pdf',
allow_image_download: false,
word_models_present: false,
scanImageType: 'pdf',
allowImageDownload: false,
wordModelsPresent: false,
directDownloadLimit: 2000,
fields: [mockField, mockField2, mockField3, mockFieldDate, mockFieldMultipleChoice],
languages: ['English'],
Expand Down

0 comments on commit d6eb9e2

Please sign in to comment.