user endpoint and some search fixes

This commit is contained in:
Timo Bejan 2021-08-04 11:44:42 +03:00
parent e90667014c
commit f7ae692613
4 changed files with 31 additions and 20 deletions

View File

@ -50,7 +50,7 @@
>&nbsp;<s>{{ term }}</s></span
>.&nbsp;{{ 'search-screen.must-contain' | translate }}:
<span
(click)="$event.stopPropagation(); updateNavigation(search$.getValue(), term)"
(click)="$event.stopPropagation(); updateNavigation(search$.getValue().query, term)"
*ngFor="let term of unmatched"
>&nbsp;<u>{{ term }}</u></span
>

View File

@ -30,6 +30,11 @@ interface ListItem {
readonly numberOfPages: number;
}
interface SearchInput {
query: string;
dossierIds?: string[];
}
@Component({
templateUrl: './search-screen.component.html',
styleUrls: ['./search-screen.component.scss'],
@ -40,7 +45,7 @@ export class SearchScreenComponent extends BaseListingComponent<ListItem> implem
readonly searchPositions = searchPositions;
readonly itemSize = 85;
readonly search$ = new BehaviorSubject<string>(null);
readonly search$ = new BehaviorSubject<SearchInput>(null);
readonly searchResults$: Observable<ListItem[]> = this.search$.asObservable().pipe(
switchMap(query => this._search(query)),
map(searchResult => this._toMatchedDocuments(searchResult)),
@ -64,7 +69,6 @@ export class SearchScreenComponent extends BaseListingComponent<ListItem> implem
];
protected readonly _primaryKey = 'fileName';
protected readonly _tableHeaderLabel = _('search-screen.table-header');
private _dossierId: string;
constructor(
protected readonly _injector: Injector,
@ -100,9 +104,10 @@ export class SearchScreenComponent extends BaseListingComponent<ListItem> implem
.valueChanges.pipe(debounceTime(300))
.subscribe(value => this.updateNavigation(value));
this.addSubscription = this.filterService.filterGroups$
.pipe(skip(1))
.subscribe(() => this.updateNavigation(this.search$.getValue()));
this.addSubscription = this.filterService.filterGroups$.pipe(skip(1)).subscribe(filters => {
const dossierIds = filters[0].values.filter(v => v.checked).map(v => v.key);
this.search$.next({ query: this.searchService.searchValue, dossierIds: dossierIds });
});
}
setInitialConfig() {
@ -115,21 +120,22 @@ export class SearchScreenComponent extends BaseListingComponent<ListItem> implem
this._router.navigate([], { queryParams }).then();
}
private _search(query: string): Observable<SearchResult> {
private _search(searchInput: SearchInput): Observable<SearchResult> {
return this._searchControllerService.search({
dossierId: this._dossierId,
queryString: query ?? '',
from: 0,
dossierIds: searchInput.dossierIds,
queryString: searchInput.query ?? '',
page: 1,
returnSections: false,
size: 100
pageSize: 300
});
}
private _updateValues({ query, dossierId }: { readonly query: string; readonly dossierId: string }) {
if (dossierId) this.filterService.toggleFilter('dossiers', dossierId);
this._dossierId = dossierId;
if (dossierId) {
this.filterService.toggleFilter('dossiers', dossierId);
}
this.searchService.searchValue = query;
this.search$.next(query);
this.search$.next({ query, dossierIds: dossierId ? [dossierId] : [] });
}
private _getFileWrapper(dossierId: string, fileId: string): FileStatusWrapper {

View File

@ -123,9 +123,13 @@ export class UserService {
}
async loadAllUsers() {
this._allUsers = (await this._userControllerService.getAllUsers().toPromise()).map(
user => new UserWrapper(user, user.roles, user.userId)
);
let allUsers = [];
if (this._currentUser.isUserAdmin) {
allUsers = await this._userControllerService.getAllUsers().toPromise();
} else {
allUsers = await this._userControllerService.getUsers().toPromise();
}
this._allUsers = allUsers.map(user => new UserWrapper(user, user.roles, user.userId));
this._allRedUsers = this._allUsers.filter(u => UserService._hasAnyRedRole(u));
this.usersReloaded$.next();
return this._allUsers;

View File

@ -11,10 +11,11 @@
*/
export interface SearchRequest {
dossierId?: string;
dossierIds?: string[];
dossierTemplateIds?: string[];
fileId?: string;
from?: number;
page?: number;
pageSize?: number;
queryString?: string;
returnSections?: boolean;
size?: number;
}