Skip to content
This repository was archived by the owner on Aug 28, 2023. It is now read-only.

Commit 8899288

Browse files
authoredMar 25, 2022
[80375] Enable filtering and sorting for model zoo (#38)
1 parent 8c0bb98 commit 8899288

File tree

48 files changed

+973
-386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+973
-386
lines changed
 

‎client/src/app/core/services/api/rest/huggingface.service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface IModelsResponse {
2121
};
2222
}
2323

24+
// TODO Consider moving to shared models (e.g. huggingface directory)
2425
interface IHFModelsData {
2526
models: IHuggingfaceModel[];
2627
tags: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { AfterViewInit, Component, OnDestroy, ViewChild } from '@angular/core';
2+
import { MatPaginator } from '@angular/material/paginator';
3+
import { FormControl } from '@angular/forms';
4+
5+
import { map, takeUntil } from 'rxjs/operators';
6+
import { Subject } from 'rxjs';
7+
8+
import { BaseModelZooDataSource } from '@shared/models/model-zoo-data-source/base-model-zoo-data-source';
9+
10+
import { ModelZooFilterGroupComponent } from '../model-zoo-filter-group/model-zoo-filter-group.component';
11+
12+
@Component({ template: '' })
13+
export abstract class BaseModelZooImportComponent<T, U = string> implements AfterViewInit, OnDestroy {
14+
@ViewChild(MatPaginator) private _paginator: MatPaginator;
15+
16+
@ViewChild(ModelZooFilterGroupComponent) private _filterGroupComponent: ModelZooFilterGroupComponent;
17+
18+
abstract readonly dataSource: BaseModelZooDataSource<T, U>;
19+
20+
readonly sortControl = new FormControl(null);
21+
readonly filtersControl = new FormControl({});
22+
23+
modelSearch = '';
24+
25+
readonly appliedFiltersCount$ = this.filtersControl.valueChanges.pipe(
26+
map((filters: U) => Object.entries(filters).filter(([, value]) => value.length).length)
27+
);
28+
29+
protected _selectedModel: T = null;
30+
get selectedModel(): T {
31+
return this._selectedModel;
32+
}
33+
set selectedModel(value: T) {
34+
this._selectedModel = value;
35+
}
36+
37+
protected readonly _unsubscribe$ = new Subject<void>();
38+
39+
protected constructor() {
40+
this._subscribeToSortAndFiltersChanges();
41+
}
42+
43+
protected abstract get _dataSourceFilter(): U;
44+
45+
abstract importModel(): void;
46+
47+
searchModels(value: string): void {
48+
this.modelSearch = value;
49+
this._filter();
50+
}
51+
52+
protected _filter(): void {
53+
this.dataSource.filter = this._dataSourceFilter;
54+
}
55+
56+
protected _subscribeToSortAndFiltersChanges(): void {
57+
this.sortControl.valueChanges.pipe(takeUntil(this._unsubscribe$)).subscribe((sort) => {
58+
this.dataSource.sort = sort;
59+
});
60+
61+
this.filtersControl.valueChanges.pipe(takeUntil(this._unsubscribe$)).subscribe(() => {
62+
this._filter();
63+
});
64+
}
65+
66+
resetAllFilters(): void {
67+
this._filterGroupComponent.resetAllFilters();
68+
}
69+
70+
ngAfterViewInit(): void {
71+
this.dataSource.paginator = this._paginator;
72+
}
73+
74+
ngOnDestroy(): void {
75+
this._unsubscribe$.next();
76+
this._unsubscribe$.complete();
77+
}
78+
}

0 commit comments

Comments
 (0)