Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h1 class="title">Fields</h1>
[class.is-disabled]="corpus.active">
<label class="label" id="language-label">Language (optional)</label>
<ia-dropdown formControlName="language" labelledBy="language-label">
<span iaDropdownLabel>{{languageLabel(field)}}</span>
<span iaDropdownLabel>{{languageLabel(field.get('language').value)}}</span>
<div iaDropdownMenu>
<a iaDropdownItem *ngFor="let lang of languageOptions"
[value]="lang.code">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,8 @@ export class FieldFormComponent implements OnChanges {
this.dialogService.showManualPage('types-of-fields');
}

languageLabel(field: FormGroup): string {
const value = field.controls.language.value;
return this.languageOptions.find(o => o.code == value).displayName;
languageLabel(code: string): string {
return this.languageOptions.find(o => o.code == code)?.displayName || 'Unknown';
}

addField(name: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ <h1 class="title">Index data</h1>
<div class="field is-grouped">
<div class="control">
<button class="button" (click)="toggleCorpusActive()"
[class.is-primary]="!corpus.active">
[class.is-primary]="!corpus.active"
[class.is-loading]="loading$ | async">
{{corpus.active ? 'Deactivate' : 'Activate'}} corpus
</button>
</div>
<div class="control">
<a class="button is-primary" *ngIf="corpus.active"
[routerLink]="['/search', corpus.definition.name]">
[routerLink]="['/search', corpus.definition.name]"
[class.is-loading]="loading$ | async">
<span class="icon"><fa-icon [icon]="actionIcons.search"/></span>
<span>Search corpus</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { APIIndexHealth, isComplete, JobStatus } from '@models/indexing';
import { ApiService, CorpusService } from '@services';
import { actionIcons } from '@shared/icons';
import * as _ from 'lodash';
import { map, Subject, switchMap, merge, filter } from 'rxjs';
import { map, Subject, switchMap, merge, filter, BehaviorSubject } from 'rxjs';

/** Possible states for the interface of this component */
type DisplayState = {
Expand Down Expand Up @@ -85,9 +85,11 @@ export class IndexFormComponent implements OnChanges, OnDestroy {

state$ = new Subject<DisplayState>;
destroy$ = new Subject<void>();
loading$ = new BehaviorSubject<boolean>(false);

actionIcons = actionIcons;


private jobID: number;
private stopping$ = new Subject<boolean>();

Expand Down Expand Up @@ -138,7 +140,8 @@ export class IndexFormComponent implements OnChanges, OnDestroy {

toggleCorpusActive() {
this.corpus.active = !this.corpus.active;
this.corpus.save();
this.loading$.next(true);
this.corpus.save().subscribe(() => this.loading$.next(false));
}

stateClass(state: DisplayState) {
Expand Down
25 changes: 15 additions & 10 deletions frontend/src/app/models/corpus-definition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as _ from 'lodash';
import { ApiService, CorpusService } from '@services';
import { BehaviorSubject, Observable } from 'rxjs';
import { filter, share, switchMap, tap } from 'rxjs/operators';
import { BehaviorSubject, from, Observable } from 'rxjs';
import { delayWhen, filter, shareReplay, tap } from 'rxjs/operators';
import { findByName } from '@app/utils/utils';

export type Delimiter = ',' | ';' | '\t';
Expand Down Expand Up @@ -153,15 +153,13 @@ export class CorpusDefinition {
const request$ = this.id
? this.apiService.updateCorpus(this.id, data)
: this.apiService.createCorpus(data);
const result$ = request$.pipe(share());

result$.subscribe((result) => this.setFromAPIData(result));
// refresh corpus data if applicable
result$.pipe(
switchMap(() => this.requireCorpusRefresh()),
filter(_.identity)
).subscribe(() => this.corpusService.get(true));
const result$ = request$.pipe(
tap(result => this.setFromAPIData(result)),
delayWhen(() => this.refreshCorpora()),
shareReplay(1),
);

result$.subscribe(); // subscribe to execute request(s)
return result$;
}

Expand Down Expand Up @@ -200,6 +198,13 @@ export class CorpusDefinition {
}
return Promise.resolve(false);
}

/** refresh searchable corpora if needed */
private refreshCorpora(): Observable<any> {
return from(this.requireCorpusRefresh().then(
refresh => refresh ? this.corpusService.get(refresh) : Promise.resolve(undefined)
));
}
};

export const FIELD_TYPE_OPTIONS: {
Expand Down