Adds Dmp search filter on Dataset Listing. (Ticket #63)

This commit is contained in:
gkolokythas 2019-04-09 10:29:43 +03:00
parent 30c84de19a
commit 92b027280d
5 changed files with 61 additions and 23 deletions

View File

@ -6,18 +6,27 @@
</mat-card-title>
</mat-card-header>
<div class="row">
<mat-form-field class="col-md-4">
<input matInput placeholder=" {{'CRITERIA.PROJECTS.LIKE'| translate}}" name="datasetCriteriaName" [(ngModel)]="criteria.like" (ngModelChange)="controlModified()">
<mat-form-field class="col-md-3">
<input matInput placeholder=" {{'CRITERIA.DATA-SETS.LIKE'| translate}}" name="datasetCriteriaName" [(ngModel)]="criteria.like"
(ngModelChange)="controlModified()">
</mat-form-field>
<mat-form-field class="col-md-4">
<mat-select placeholder=" {{'CRITERIA.DATA-SETS.STATUS'| translate}}" name="datasetCriteriastatus" [(ngModel)]="criteria.status" (ngModelChange)="controlModified()">
<mat-form-field class="col-md-3">
<app-multiple-auto-complete placeholder="{{'CRITERIA.DMP.LIKE'| translate}}" name="dmpCriteriaName" [(ngModel)]="criteria.dmpIds"
(ngModelChange)="controlModified()" [configuration]="dmpAutoCompleteConfiguration" [disabled]="!dmpSearchEnabled"></app-multiple-auto-complete>
</mat-form-field>
<mat-form-field class="col-md-3">
<mat-select placeholder=" {{'CRITERIA.DATA-SETS.STATUS'| translate}}" name="datasetCriteriastatus" [(ngModel)]="criteria.status"
(ngModelChange)="controlModified()">
<mat-option [value]="null">{{'CRITERIA.DATA-SETS.NONE'| translate}}</mat-option>
<mat-option [value]="statuses.Draft">{{enumUtils.toDatasetStatusString(statuses.Draft)}}</mat-option>
<mat-option [value]="statuses.Finalized">{{enumUtils.toDatasetStatusString(statuses.Finalized)}}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="col-md-4">
<app-multiple-auto-complete name="datasetCriteriaTags" [(ngModel)]="criteria.tags" (ngModelChange)="controlModified()" placeholder="{{'CRITERIA.DATA-SETS.TAGS' | translate}}" [configuration]="tagsAutoCompleteConfiguration"></app-multiple-auto-complete>
<mat-form-field class="col-md-3">
<app-multiple-auto-complete name="datasetCriteriaTags" [(ngModel)]="criteria.tags" (ngModelChange)="controlModified()" placeholder="{{'CRITERIA.DATA-SETS.TAGS' | translate}}"
[configuration]="tagsAutoCompleteConfiguration"></app-multiple-auto-complete>
</mat-form-field>
</div>
</mat-card>

View File

@ -9,6 +9,12 @@ import { ExternalSourcesService } from '../../../../core/services/external-sourc
import { EnumUtils } from '../../../../core/services/utilities/enum-utils.service';
import { RequestItem } from '../../../../core/query/request-item';
import { BaseCriteriaComponent } from '../../../misc/criteria/base-criteria.component';
import { DmpCriteria } from '../../../../core/query/dmp/dmp-criteria';
import { DmpService } from '../../../../core/services/dmp/dmp.service';
import { DataTableRequest } from '../../../../core/model/data-table/data-table-request';
import { DataTableData } from '../../../../core/model/data-table/data-table-data';
import { DmpListingModel } from '../../../../core/model/dmp/dmp-listing';
import { Input } from '@angular/core';
@Component({
selector: 'app-dataset-criteria-component',
@ -17,10 +23,10 @@ import { BaseCriteriaComponent } from '../../../misc/criteria/base-criteria.comp
})
export class DatasetCriteriaComponent extends BaseCriteriaComponent implements OnInit {
@Input() dmpSearchEnabled;
public criteria: any;
public filteringTagsAsync = false;
public filteredTags: ExternalSourceItemModel[];
statuses = DatasetStatus;
tagsAutoCompleteConfiguration = {
@ -30,9 +36,17 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O
titleFn: (item) => item['name']
};
dmpAutoCompleteConfiguration = {
filterFn: (x, excluded) => this.filterDmps(x).map(x => x.data),
initialItems: (extraData) => this.filterDmps('').map(x => x.data),
displayFn: (item) => item['label'],
titleFn: (item) => item['label']
};
constructor(
private externalSourcesService: ExternalSourcesService,
public enumUtils: EnumUtils
public enumUtils: EnumUtils,
public dmpService: DmpService
) {
super(new ValidationErrorModel());
}
@ -60,7 +74,6 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O
}
filterTags(value: string): Observable<ExternalSourceItemModel[]> {
this.filteredTags = undefined;
this.filteringTagsAsync = true;
@ -69,6 +82,14 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O
criteria.like = value;
requestItem.criteria = criteria;
return this.externalSourcesService.searchDatasetTags(requestItem);
}
filterDmps(value: string): Observable<DataTableData<DmpListingModel>> {
const fields: Array<string> = new Array<string>();
fields.push('asc');
const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(0, null, { fields: fields });
dmpDataTableRequest.criteria = new DmpCriteria();
dmpDataTableRequest.criteria.like = value;
return this.dmpService.getPaged(dmpDataTableRequest, "autocomplete");
}
}

View File

@ -1,7 +1,7 @@
<div>
<h3>{{'DATASET-LISTING.TITLE' | translate}} {{titlePrefix}}</h3>
<app-dataset-criteria-component></app-dataset-criteria-component>
<app-dataset-criteria-component [dmpSearchEnabled]="dmpSearchEnabled"></app-dataset-criteria-component>
<mat-card class="mat-card">
<mat-table [dataSource]="dataSource" matSort (matSortChange)="refresh()">

View File

@ -34,6 +34,7 @@ export class DatasetListingComponent extends BaseComponent implements OnInit, IB
pageEvent: PageEvent;
titlePrefix: String;
dmpId: string;
dmpSearchEnabled = true;
constructor(
private datasetService: DatasetService,
@ -47,23 +48,24 @@ export class DatasetListingComponent extends BaseComponent implements OnInit, IB
super();
}
ngOnInit() {
this.route.params
.pipe(takeUntil(this._destroyed))
.subscribe(async (params: Params) => {
this.dmpId = params['dmpId'];
this.criteria.setCriteria(this.getDefaultCriteria(this.dmpId));
this.refresh();
this.criteria.setRefreshCallback(() => this.refresh());
if (this.dmpId != null) {
this.dmpSearchEnabled = false;
const dmp = await this.dmpService.getSingle(this.dmpId).toPromise();
this.criteria.setCriteria(this.getDefaultCriteria(dmp));
this.refresh();
this.breadCrumbs = Observable.of([{ parentComponentName: 'DmpEditorComponent', label: dmp.label, url: 'plans/edit/' + this.dmpId }]);
if (params['dmpLabel'] !== undefined) {
this.titlePrefix = 'for ' + params['dmpLabel'];
}
} else {
this.criteria.setCriteria(this.getDefaultCriteria());
this.refresh();
this.breadCrumbs = Observable.of([]);
}
});
@ -77,7 +79,7 @@ export class DatasetListingComponent extends BaseComponent implements OnInit, IB
this.router.navigate(['/datasets/edit/' + rowId]);
}
getDefaultCriteria(dmpId: String): DatasetCriteria {
getDefaultCriteria(dmpId: any = null): DatasetCriteria {
const defaultCriteria = new DatasetCriteria();
if (dmpId != null) {
defaultCriteria.dmpIds.push(dmpId);
@ -90,7 +92,6 @@ export class DatasetListingComponent extends BaseComponent implements OnInit, IB
.pipe(takeUntil(this._destroyed))
.subscribe();
}
}
export class DatasetDataSource extends DataSource<DatasetListingModel> {
@ -106,7 +107,6 @@ export class DatasetDataSource extends DataSource<DatasetListingModel> {
private dmpId: String
) {
super();
}
connect(): Observable<DatasetListingModel[]> {
@ -115,7 +115,6 @@ export class DatasetDataSource extends DataSource<DatasetListingModel> {
//this._sort.matSortChange
];
return Observable.merge(...displayDataChanges)
.startWith(null)
.switchMap(() => {
@ -123,7 +122,13 @@ export class DatasetDataSource extends DataSource<DatasetListingModel> {
let fields: Array<string> = new Array();
if (this._sort.active) { fields = this._sort.direction === 'asc' ? ['+' + this._sort.active] : ['-' + this._sort.active]; }
const request = new DataTableRequest<DatasetCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
request.criteria = this._criteria.criteria;
request.criteria = {
like: this._criteria.criteria.like,
status: this._criteria.criteria.status,
dmpIds: this._criteria.criteria.dmpIds ? this._criteria.criteria.dmpIds.map(x => x.id) : null,
tags: this._criteria.criteria.tags,
allVersions: this._criteria.criteria.allVersions
}
if (this.dmpId) { request.criteria.allVersions = true; }
return this._service.getPaged(request);
})

View File

@ -270,7 +270,9 @@
"DMP-SEARCH": {
"PLACEHOLDER": "Search DMP"
},
"ERROR-MESSAGE": "This DMP does not contain this Dataset Profile"
"COPY": "Copy",
"CANCEL": "Cancel",
"ERROR-MESSAGE": "Selected DMP does not contain this Dataset Profile"
}
},
"DATASET-LISTING": {
@ -419,7 +421,7 @@
"CRITERIA": {
"FILTERS": "Filters",
"PROJECTS": {
"LIKE": "Search",
"LIKE": "Search Projects",
"PERIOD-FROM": "Project Start",
"PERIOD-TO": "Project End",
"PROJECT-STATE-TYPE": "Project Status",
@ -437,10 +439,11 @@
"PERIOD-TO": "End",
"STATUS": "Status",
"NONE": "-",
"TAGS": "Tags"
"TAGS": "Tags",
"LIKE": "Search Datasets"
},
"DMP": {
"LIKE": "Search",
"LIKE": "Search DMPs",
"PROJECTS": "Projects"
},
"USERS": {