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 @@ -10,6 +10,7 @@ import { FeatureSourceService } from '../../catalog/services/feature-source.serv
import { SearchIndexService } from '../services/search-index.service';
import { ConfirmDialogService } from '@tailormap-viewer/shared';
import { ExtendedFeatureTypeModel } from '../../catalog/models/extended-feature-type.model';
import { loadTasks } from '../../tasks/state/tasks.actions';

@Component({
selector: 'tm-admin-search-index-edit',
Expand Down Expand Up @@ -47,6 +48,8 @@ export class SearchIndexEditComponent implements OnInit {
public indexing$ = this.indexingSubject.asObservable();

public ngOnInit() {
this.store$.dispatch(loadTasks());

this.route.paramMap.pipe(
takeUntilDestroyed(this.destroyRef),
map(params => params.get('searchIndexId')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ <h2 class="schedule-title" i18n="@@admin-core.search-index.schedule">Schedule</h
@if (taskSchedule?.uuid; as uuid) {
<div class="label">Uuid</div>
<div class="uuid">{{ uuid }}</div>
<div class="delete-schedule-message" i18n="@@admin-core.search-index.delete-schedule-message">
Deleting the schedule of a search index can be done by deleting the task on the tasks page
</div>
} @else {
<span class="no-schedule" i18n="@@admin-core.search-index.no-schedule">There is no schedule for this search index yet.</span>
}
Expand All @@ -19,8 +16,7 @@ <h2 class="schedule-title" i18n="@@admin-core.search-index.schedule">Schedule</h
<mat-select formControlName="cronExpression">
@for (option of scheduleOptions; track $index) {
<mat-option
[value]="option.cronExpression"
[disabled]="option.cronExpression === '' && taskSchedule?.uuid">
[value]="option.cronExpression">
{{ option.viewValue }}
</mat-option>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export class SearchIndexSchedulingComponent implements OnInit {
)
.subscribe(value => {
let schedule: TaskSchedule | undefined = undefined;
if (value.cronExpression) {
if (value.cronExpression || this.taskSchedule) {
schedule = {
...this.taskSchedule,
cronExpression: value.cronExpression,
cronExpression: value.cronExpression || '',
description: value.description,
priority: value.priority,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { AdminSnackbarService } from '../../shared/services/admin-snackbar.servi
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { DebounceHelper } from '@tailormap-viewer/shared';
import { addSearchIndex, deleteSearchIndex, updateSearchIndex } from '../state/search-index.actions';
import { catchError, concatMap, map, of } from 'rxjs';
import { catchError, concatMap, map, Observable, of, switchMap, take } from 'rxjs';
import { selectDraftSearchIndex } from '../state/search-index.selectors';
import { selectTask } from '../../tasks/state/tasks.selectors';
import { TaskMonitoringService } from '../../tasks/services/task-monitoring.service';

@Injectable({
providedIn: 'root',
Expand All @@ -18,6 +20,7 @@ export class SearchIndexService {
private adminSnackbarService = inject(AdminSnackbarService);
private sseService = inject(AdminSseService);
private destroyRef = inject(DestroyRef);
private taskMonitoringService = inject(TaskMonitoringService);


public listenForSearchIndexChanges() {
Expand All @@ -42,7 +45,7 @@ export class SearchIndexService {
takeUntilDestroyed(this.destroyRef),
concatMap(searchIndex => {
if (searchIndex) {
return this.updateSearchIndex$(searchIndex.id, searchIndex);
return this.updateSearchIndexAndTask$(searchIndex.id, searchIndex);
}
return of(null);
}),
Expand All @@ -67,7 +70,31 @@ export class SearchIndexService {
);
}

public updateSearchIndex$(id: number, searchIndex: Partial<SearchIndexModel>) {
public updateSearchIndexAndTask$(id: number, searchIndex: Partial<SearchIndexModel>): Observable<SearchIndexModel | null> {
// If the schedule is being removed, delete the associated task.
// The search index should only be updated after the task is successfully deleted.
if (!searchIndex.schedule || searchIndex.schedule.cronExpression || !searchIndex.schedule.uuid) {
return this.updateSearchIndex$(id, searchIndex);
}
return this.store$.select(selectTask(searchIndex.schedule.uuid)).pipe(
take(1),
switchMap(task => {
if (!task) {
return of(null);
}
return this.taskMonitoringService.deleteTask$(task.uuid, task.type);
}),
switchMap((response) => {
if (response) {
const searchIndexEmptySchedule: Partial<SearchIndexModel> = { ...searchIndex, schedule: undefined };
return this.updateSearchIndex$(id, searchIndexEmptySchedule);
}
return of(null);
}),
);
}

private updateSearchIndex$(id: number, searchIndex: Partial<SearchIndexModel>): Observable<SearchIndexModel | null> {
return this.adminApiService.updateSearchIndex$({ id, searchIndex })
.pipe(
catchError(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { TailormapAdminApiV1Service } from '@tailormap-admin/admin-api';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { AdminSnackbarService } from '../../shared/services/admin-snackbar.service';

@Injectable()
@Injectable({
providedIn: 'root',
})
export class TaskMonitoringService {
private store$ = inject(Store);
private adminApiService = inject(TailormapAdminApiV1Service);
Expand Down Expand Up @@ -64,7 +66,7 @@ export class TaskMonitoringService {
this.adminApiService.stopTask$(this.uuid$.value, this.type$.value).subscribe();
}

public deleteTask(uuid: string, type: string ) {
public deleteTask$(uuid: string, type: string ) {
return this.adminApiService.deleteTask$(uuid, type)
.pipe(
catchError(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { reloadSearchIndexes } from '../../search-index/state/search-index.actio
selector: 'tm-admin-task-details',
templateUrl: './task-details.component.html',
styleUrls: ['./task-details.component.css'],
providers: [TaskMonitoringService],
changeDetection: ChangeDetectionStrategy.OnPush,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class TaskDetailsComponent implements OnInit, OnDestroy {
Expand Down Expand Up @@ -69,7 +68,7 @@ export class TaskDetailsComponent implements OnInit, OnDestroy {
.pipe(
take(1),
filter(answer => answer),
switchMap(() => this.taskMonitoringService.deleteTask(task.uuid, task.type)),
switchMap(() => this.taskMonitoringService.deleteTask$(task.uuid, task.type)),
)
.subscribe((response) => {
if (response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export class SliderComponent implements ControlValueAccessor {

@Input()
public set betweenValues(betweenValues: {lower: number | null; upper: number | null}) {
console.debug("Setting between values", betweenValues);
this.lowerValue = betweenValues.lower ?? this.min;
this.upperValue = betweenValues.upper ?? this.max;
}
Expand Down
Loading