From feb3c8530bc609d79774c08c12760ed8ac3a67a8 Mon Sep 17 00:00:00 2001 From: Luka van der Plas Date: Tue, 28 May 2024 11:52:07 +0200 Subject: [PATCH] clean up corpus model remove obsolete properties change properties to camel case --- .../corpus-header/corpus-header.component.ts | 2 +- .../document-view.component.spec.ts | 2 +- .../document-view/document-view.component.ts | 2 +- .../app/image-view/image-view.component.ts | 4 ++-- frontend/src/app/models/corpus.ts | 19 +++++---------- frontend/src/app/models/query.spec.ts | 7 +++--- .../src/app/services/corpus.service.spec.ts | 2 +- frontend/src/app/services/corpus.service.ts | 3 --- frontend/src/app/utils/es-query.ts | 2 +- frontend/src/mock-data/corpus.ts | 24 +++++++------------ 10 files changed, 25 insertions(+), 42 deletions(-) diff --git a/frontend/src/app/corpus-header/corpus-header.component.ts b/frontend/src/app/corpus-header/corpus-header.component.ts index 95baaaac7..9abffd5fc 100644 --- a/frontend/src/app/corpus-header/corpus-header.component.ts +++ b/frontend/src/app/corpus-header/corpus-header.component.ts @@ -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; } } } diff --git a/frontend/src/app/document-view/document-view.component.spec.ts b/frontend/src/app/document-view/document-view.component.spec.ts index 6fa470a3a..f59858f51 100644 --- a/frontend/src/app/document-view/document-view.component.spec.ts +++ b/frontend/src/app/document-view/document-view.component.spec.ts @@ -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!' }); diff --git a/frontend/src/app/document-view/document-view.component.ts b/frontend/src/app/document-view/document-view.component.ts index ee8c453e8..81a35aa27 100644 --- a/frontend/src/app/document-view/document-view.component.ts +++ b/frontend/src/app/document-view/document-view.component.ts @@ -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 { diff --git a/frontend/src/app/image-view/image-view.component.ts b/frontend/src/app/image-view/image-view.component.ts index bf93934d2..cc3dd32c1 100644 --- a/frontend/src/app/image-view/image-view.component.ts +++ b/frontend/src/app/image-view/image-view.component.ts @@ -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 && diff --git a/frontend/src/app/models/corpus.ts b/frontend/src/app/models/corpus.ts index 04d71cae1..4906e2966 100644 --- a/frontend/src/app/models/corpus.ts +++ b/frontend/src/app/models/corpus.ts @@ -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. */ @@ -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, ) { } @@ -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[]; diff --git a/frontend/src/app/models/query.spec.ts b/frontend/src/app/models/query.spec.ts index 14b95ae60..9fb6ebd61 100644 --- a/frontend/src/app/models/query.spec.ts +++ b/frontend/src/app/models/query.spec.ts @@ -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, diff --git a/frontend/src/app/services/corpus.service.spec.ts b/frontend/src/app/services/corpus.service.spec.ts index 6a2946cf4..bf07f0d26 100644 --- a/frontend/src/app/services/corpus.service.spec.ts +++ b/frontend/src/app/services/corpus.service.spec.ts @@ -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 = [ { diff --git a/frontend/src/app/services/corpus.service.ts b/frontend/src/app/services/corpus.service.ts index 47f7f4cf4..7092bd591 100644 --- a/frontend/src/app/services/corpus.service.ts +++ b/frontend/src/app/services/corpus.service.ts @@ -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, @@ -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), diff --git a/frontend/src/app/utils/es-query.ts b/frontend/src/app/utils/es-query.ts index e72208bc8..5368470bb 100644 --- a/frontend/src/app/utils/es-query.ts +++ b/frontend/src/app/utils/es-query.ts @@ -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', diff --git a/frontend/src/mock-data/corpus.ts b/frontend/src/mock-data/corpus.ts index 0aaa53230..f1472315d 100644 --- a/frontend/src/mock-data/corpus.ts +++ b/frontend/src/mock-data/corpus.ts @@ -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'], @@ -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'], @@ -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'],