Merge remote-tracking branch 'origin/new-search-extend-criteria' into develop
This commit is contained in:
commit
caee719f66
|
|
@ -49,7 +49,8 @@ import {OpenaireEntities} from "../../openaireLibrary/utils/properties/searchFie
|
|||
<loading></loading>
|
||||
</div>
|
||||
<ng-container *ngIf="!loading">
|
||||
<ng-container *ngIf="!this.communityService.selectedSubCommunity && previewSubCommunitiesCriteria.length > 0">
|
||||
<ng-container
|
||||
*ngIf="!this.communityService.selectedSubCommunity && previewSubCommunitiesCriteria.length > 0">
|
||||
<ul class="uk-subnav uk-subnav-pill uk-margin-top" uk-margin uk-switcher>
|
||||
<li class="uk-active"><a href="#">Set for community <span
|
||||
*ngIf="selectionCriteria?.criteria?.length > 0"
|
||||
|
|
@ -119,44 +120,42 @@ export class AdvancedCriteriaComponent implements OnInit, OnDestroy {
|
|||
public criteriaUtils: CriteriaUtils = new CriteriaUtils();
|
||||
private subscriptions: any[] = [];
|
||||
@ViewChild('criteria') criteria: CriteriaComponent;
|
||||
@ViewChild('filtersModal', { static: true }) filtersModal: FullScreenModalComponent;
|
||||
|
||||
@ViewChild('filtersModal', {static: true}) filtersModal: FullScreenModalComponent;
|
||||
|
||||
constructor(protected communityService: CommunityService,
|
||||
private cdr: ChangeDetectorRef,
|
||||
private advancedCriteriaService: AdvancedCriteriaService, private title: Title,
|
||||
private route: ActivatedRoute, private _router: Router) {}
|
||||
|
||||
private route: ActivatedRoute, private _router: Router) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.loading = true;
|
||||
this.subscriptions.push(this.communityService.getCommunityAsObservable().subscribe(community => {
|
||||
this.community = community;
|
||||
this.title.setTitle(this.community.shortTitle.toUpperCase() + (this.communityService.selectedSubCommunity?':'+this.communityService.selectedSubCommunity?.label:"") +' | Advance Criteria');
|
||||
this.title.setTitle(this.community.shortTitle.toUpperCase() + (this.communityService.selectedSubCommunity ? ':' + this.communityService.selectedSubCommunity?.label : "") + ' | Advance Criteria');
|
||||
this.getCriteria();
|
||||
}));
|
||||
}
|
||||
getCriteria(){
|
||||
this.loading = true;
|
||||
if(this.communityService.selectedSubCommunityId()){
|
||||
this.subscriptions.push(this.advancedCriteriaService.getAdvancedCriteriaForSubcommunities(this.community.communityId,this.communityService.selectedSubCommunityId()).subscribe(
|
||||
res => {
|
||||
console.log(res)
|
||||
this.selectionCriteria = res.selectionCriteria;
|
||||
console.log(this.selectionCriteria);
|
||||
this.loading = false;
|
||||
|
||||
}
|
||||
) );
|
||||
}else{
|
||||
this.subscriptions.push(this.advancedCriteriaService.getAdvancedCriteriaForSubcommunities(this.community.communityId,this.communityService.selectedSubCommunityId).subscribe( res =>{
|
||||
getCriteria() {
|
||||
this.loading = true;
|
||||
if (this.communityService.selectedSubCommunityId()) {
|
||||
this.subscriptions.push(this.advancedCriteriaService.getAdvancedCriteriaForSubcommunities(this.community.communityId, this.communityService.selectedSubCommunityId()).subscribe(
|
||||
res => {
|
||||
this.selectionCriteria = res.selectionCriteria;
|
||||
this.loading = false;
|
||||
}
|
||||
));
|
||||
} else {
|
||||
this.subscriptions.push(this.advancedCriteriaService.getAdvancedCriteriaForSubcommunities(this.community.communityId, this.communityService.selectedSubCommunityId).subscribe(res => {
|
||||
this.selectionCriteria = this.community.selectionCriteria;
|
||||
this.previewSubCommunitiesCriteria = res;
|
||||
console.log(this.selectionCriteria, res);
|
||||
this.loading = false;
|
||||
|
||||
}) );
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
saveCriteria() {
|
||||
let callback = (selectionCriteria): void => {
|
||||
this.advancedCriteriaService.saveAdvancedCriteria(this.community.communityId, selectionCriteria, this.communityService.selectedSubCommunityId()).subscribe(() => {
|
||||
|
|
@ -172,7 +171,7 @@ export class AdvancedCriteriaComponent implements OnInit, OnDestroy {
|
|||
this.loading = true;
|
||||
this.criteria.save(callback);
|
||||
}
|
||||
|
||||
|
||||
public openCriteria() {
|
||||
this.criteria.reset();
|
||||
this.filtersModal.title = 'Criteria';
|
||||
|
|
@ -182,19 +181,20 @@ export class AdvancedCriteriaComponent implements OnInit, OnDestroy {
|
|||
this.filtersModal.open();
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach(subscription => {
|
||||
if(subscription instanceof Subscription) {
|
||||
if (subscription instanceof Subscription) {
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
})
|
||||
}
|
||||
subCommunityChanged(){
|
||||
|
||||
subCommunityChanged() {
|
||||
this.getCriteria();
|
||||
}
|
||||
|
||||
navigateToSub(communityId){
|
||||
navigateToSub(communityId) {
|
||||
this.communityService.setSelectedSubCommunity(communityId);
|
||||
this._router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
|
|
|
|||
|
|
@ -95,3 +95,4 @@
|
|||
</ng-container>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ export class AddContentProvidersComponent implements OnInit {
|
|||
sub.unsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
console.log('destroy')
|
||||
if (this.subResults) {
|
||||
this.subResults.unsubscribe();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,24 @@ import {Option} from "../../openaireLibrary/sharedComponents/input/input.compone
|
|||
import {Criteria} from "../../openaireLibrary/utils/entities/contentProvider";
|
||||
|
||||
export class CriteriaUtils {
|
||||
public readonly fields: Option[] = [
|
||||
{value: 'author', label: 'Author\'s name'},
|
||||
{value: 'title', label: 'Title'},
|
||||
{value: 'orcid', label: 'Author\'s ORCID'},
|
||||
{value: 'contributor', label: 'Contributor'},
|
||||
{value: 'description', label: 'Abstract'},
|
||||
{value: 'subject', label: 'Subject'},
|
||||
{value: 'fos', label: 'Field of Science'},
|
||||
{value: 'sdg', label: 'SDG'},
|
||||
{value: 'publisher', label: 'Publisher'},
|
||||
{value: 'publicationyear', label: 'Publication Year'}
|
||||
]
|
||||
public readonly numericFields: string[] = ['publicationyear'];
|
||||
public readonly criteriaFields = {
|
||||
["description"]: {value: 'description', label: 'Abstract', type: 'keyword',operator :"string"},
|
||||
["access"]: {value: 'access', label: 'Access right', type: 'vocabulary',operator :"string", vocabularyId: 'access'},
|
||||
["author"]: {value: 'author', label: 'Author\'s name', type: 'keyword',operator :"string"},
|
||||
["orcid"]: {value: 'orcid', label: 'Author\'s ORCID', type: 'keyword',operator :"string"},
|
||||
["contributor"]: {value: 'contributor', label: 'Contributor', type: 'keyword',operator :"string"},
|
||||
["fos"]: {value: 'fos', label: 'Field of Science', type: 'static',operator :"string"},
|
||||
["language"]: {value: 'language', label: 'Language', type: 'vocabulary',operator :"exact", vocabularyId:"lang"},
|
||||
["publisher"]: {value: 'publisher', label: 'Publisher', type: 'keyword',operator :"string"},
|
||||
["publicationyear"]: {value: 'publicationyear', label: 'Publication Year', type: 'number',operator :"numeric"},
|
||||
["sdg"]: {value: 'sdg', label: 'SDG', type: 'static',operator :"exact"},
|
||||
["documentType"]: {value: 'documentType', label: 'Specific type', type: 'vocabulary',operator :"string" , vocabularyId:"type"},
|
||||
["subject"]: {value: 'subject', label: 'Subject', type: 'keyword',operator :"string"},
|
||||
["title"]: {value: 'title', label: 'Title', type: 'keyword',operator :"string"},
|
||||
["type"]: {value: 'type', label: 'Type', type: 'static',operator :"exact"},
|
||||
|
||||
}
|
||||
|
||||
public readonly verbs: Option[] = [
|
||||
{value: 'contains', label: 'contains'},
|
||||
{value: 'equals', label: 'equals'},
|
||||
|
|
@ -27,10 +32,14 @@ export class CriteriaUtils {
|
|||
{value: 'lesser_than', label: 'lesser than'},
|
||||
{value: 'greater_than', label: 'greater than'}
|
||||
]
|
||||
public readonly verbsForExact: Option[] = [
|
||||
{value: 'equals', label: 'equals'},
|
||||
{value: 'not_equals', label: 'not equals'}
|
||||
]
|
||||
|
||||
public getFiltersAsText(criteria: Criteria[], shortVersion=true): string {
|
||||
let text = criteria.slice(0, shortVersion?3:criteria.length).map((criterion, index) => (index + 1) + ". " + criterion.constraint.map(constraint => {
|
||||
let field = this.fields.find(field => field.value === constraint.field)?.label;
|
||||
let field = this.criteriaFields[constraint.field]?.label;
|
||||
let matchCase = false;
|
||||
if (!constraint.verb.includes('_caseinsensitive')) {
|
||||
matchCase = true;
|
||||
|
|
|
|||
|
|
@ -17,83 +17,66 @@
|
|||
</h3>
|
||||
<div class="uk-width-expand uk-padding-small uk-border uk-border-rounded" formArrayName="constraint">
|
||||
<div class="uk-flex-middle uk-grid uk-margin-small-bottom uk-visible@l" uk-grid>
|
||||
<div class="uk-width-1-4">
|
||||
<div class="uk-width-1-4@l uk-width-1-1@m">
|
||||
<label class="uk-text-uppercase uk-text-bold">Field</label>
|
||||
</div>
|
||||
<div class="uk-width-1-4">
|
||||
<div class="uk-width-1-4@l uk-width-1-1@m">
|
||||
<label class="uk-text-uppercase uk-text-bold">Operator</label>
|
||||
</div>
|
||||
<div class="uk-width-1-4">
|
||||
<div class="uk-width-1-4@l uk-width-1-1@m">
|
||||
<label class="uk-text-uppercase uk-text-bold">Term</label>
|
||||
</div>
|
||||
<div class="uk-width-expand uk-text-truncate">
|
||||
<label class="uk-text-bold uk-text-uppercase">Match Case</label>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngFor="let constraint of getConstraint(i).controls; let j=index" [formGroupName]="j.toString()"
|
||||
class="uk-margin-bottom uk-hidden@l">
|
||||
<div class="uk-flex-middle uk-grid-small uk-margin-medium-bottom" uk-grid>
|
||||
<div class="uk-flex uk-flex-right uk-width-1-1">
|
||||
<button class="uk-close uk-icon" (click)="removeConstraint(i, j)">
|
||||
<icon name="close" ratio="1.5" [flex]="true"
|
||||
[attr.uk-tooltip]="(getConstraint(i).length === 1?'By removing this constraint, the ' + entityType + ' will be removed too':null)"></icon>
|
||||
</button>
|
||||
</div>
|
||||
<div class="uk-width-1-1" input type="select" inputClass="border-bottom" [placeholder]="{static: true, label: 'Choose a field'}"
|
||||
[options]="criteriaUtils.fields" [formInput]="constraint.get('field')" (valueChange)="resetFieldWhenValueChange(constraint)">
|
||||
<label class="uk-text-uppercase uk-text-bold uk-width-1-3 uk-text-truncate">Field:</label>
|
||||
</div>
|
||||
<div *ngIf="criteriaUtils.numericFields.indexOf(constraint.get('field').value) == -1" class="uk-width-1-1" input type="select" inputClass="border-bottom"
|
||||
[options]="criteriaUtils.verbs" [formInput]="constraint.get('verb')">
|
||||
<label class="uk-text-uppercase uk-text-bold uk-width-1-3 uk-text-truncate">Operator:</label>
|
||||
</div>
|
||||
<div *ngIf="criteriaUtils.numericFields.indexOf(constraint.get('field').value) != -1" class="uk-width-1-1" input type="select" inputClass="border-bottom"
|
||||
[options]="criteriaUtils.verbsForNumbers" [formInput]="constraint.get('verb')">
|
||||
<label class="uk-text-uppercase uk-text-bold uk-width-1-3 uk-text-truncate">Operator:</label>
|
||||
</div>
|
||||
<div class="uk-width-1-1" input [placeholder]="{static: true, label: 'Type a keyword'}"
|
||||
[formInput]="constraint.get('value')">
|
||||
<label class="uk-text-uppercase uk-text-bold uk-width-1-3 uk-text-truncate">Term:</label>
|
||||
</div>
|
||||
<div class="uk-width-1-1">
|
||||
<div class="uk-grid" uk-grid>
|
||||
<label class="uk-text-uppercase uk-text-bold uk-width-1-3 uk-text-truncate">Match Case</label>
|
||||
<div class="uk-width-expand">
|
||||
<mat-slide-toggle [checked]="constraint.get('verb_suffix').value === ''"
|
||||
[attr.uk-tooltip]="(constraint.get('verb_suffix').value === ''?('Only \'\'' + constraint.get('value').value + '\'\' matches'):
|
||||
('Both \'\'' + constraint.get('value').value.toUpperCase() + '\'\' and \'\'' + constraint.get('value').value.toLowerCase() + '\'\' match'))"
|
||||
(change)="caseSensitive($event, constraint)"></mat-slide-toggle>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngFor="let constraint of getConstraint(i).controls; let j=index"
|
||||
[formGroupName]="j.toString()" class="uk-margin-bottom uk-visible@l">
|
||||
[formGroupName]="j.toString()" class="uk-margin-bottom ">
|
||||
<div class="uk-flex uk-flex-middle uk-grid" uk-grid>
|
||||
<div class="uk-width-1-4" input type="select" inputClass="border-bottom" [placeholder]="{static: true, label: 'Choose a field'}"
|
||||
[options]="criteriaUtils.fields" [formInput]="constraint.get('field')"></div>
|
||||
<div *ngIf="criteriaUtils.numericFields.indexOf(constraint.get('field').value) == -1" class="uk-width-1-4" input type="select" inputClass="border-bottom"
|
||||
<div class="uk-width-1-4@l uk-width-1-1@m" input type="select" inputClass="border-bottom" [placeholder]="{static: true, label: 'Choose a field'}"
|
||||
[options]="fieldOptions" [formInput]="constraint.get('field')" (valueChange)="resetFieldWhenValueChange(constraint)"></div>
|
||||
<div *ngIf="criteriaUtils.criteriaFields[constraint.get('field').value].operator == 'string'" class="uk-width-1-4@l uk-width-1-1@m" input type="select" inputClass="border-bottom"
|
||||
[options]="criteriaUtils.verbs" [formInput]="constraint.get('verb')"></div>
|
||||
<div *ngIf="criteriaUtils.numericFields.indexOf(constraint.get('field').value) != -1" class="uk-width-1-4" input type="select" inputClass="border-bottom"
|
||||
<div *ngIf="criteriaUtils.criteriaFields[constraint.get('field').value].operator == 'numeric'" class="uk-width-1-4@l uk-width-1-1@m" input type="select" inputClass="border-bottom"
|
||||
[options]="criteriaUtils.verbsForNumbers" [formInput]="constraint.get('verb')"></div>
|
||||
<div *ngIf="constraint.get('field').value !== 'fos' && constraint.get('field').value !== 'sdg'" class="uk-width-1-4" inputClass="flat small" input [placeholder]="{static: true, label: 'Type a keyword'}"
|
||||
<div *ngIf="criteriaUtils.criteriaFields[constraint.get('field').value].operator == 'exact'" class="uk-width-1-4@l uk-width-1-1@m" input type="select" inputClass="border-bottom"
|
||||
[options]="criteriaUtils.verbsForExact" [formInput]="constraint.get('verb')"></div>
|
||||
<ng-container *ngIf="criteriaUtils.criteriaFields[constraint.get('field').value].type == 'vocabulary'">
|
||||
<static-autocomplete [properties]=properties [vocabularyId]="criteriaUtils.criteriaFields[constraint.get('field').value].vocabularyId" class="uk-width-1-4@l uk-width-1-1@m"
|
||||
[fieldId]="criteriaUtils.criteriaFields[constraint.get('field').value].vocabularyId"
|
||||
[selectedValue]="constraint.get('value').value" entityName="result" inputClass="flat"
|
||||
[placeHolderMessage]="'Search for '+criteriaUtils.criteriaFields[constraint.get('field').value].label" [title]="criteriaUtils.criteriaFields[constraint.get('field').value].label"
|
||||
(selectedValueChanged)="autoCompleteValueChanged(constraint.get('value'), $event)"
|
||||
[type]="criteriaUtils.criteriaFields[constraint.get('field').value].operator === 'string'?'autocomplete_soft':'autocomplete'"
|
||||
[list]="vocabularyLists[criteriaUtils.criteriaFields[constraint.get('field').value].vocabularyId] "
|
||||
(listUpdated)="vocabularyLists[criteriaUtils.criteriaFields[constraint.get('field').value].vocabularyId] = $event.value"
|
||||
></static-autocomplete>
|
||||
</ng-container>
|
||||
<div *ngIf="criteriaUtils.criteriaFields[constraint.get('field').value].type == 'keyword'" class="uk-width-1-4@l uk-width-1-1@m" inputClass="flat small" input [placeholder]="{static: true, label: 'Type a keyword'}"
|
||||
[formInput]="constraint.get('value')"></div>
|
||||
<div *ngIf="constraint.get('field').value === 'fos'" class="uk-width-1-4" inputClass="flat small" input [placeholder]="{static: true, label: 'Choose a FoS'}"
|
||||
[formInput]="constraint.get('value')" type="select" [options]="fos"></div>
|
||||
<div *ngIf="constraint.get('field').value === 'sdg'" class="uk-width-1-4" inputClass="flat small" input [placeholder]="{static: true, label: 'Choose a FoS'}"
|
||||
[formInput]="constraint.get('value')" type="select" [options]="sdg"></div>
|
||||
<div class="uk-width-expand">
|
||||
<mat-slide-toggle [checked]="constraint.get('verb_suffix').value === ''" class="uk-margin-left"
|
||||
[attr.uk-tooltip]="(constraint.get('verb_suffix').value === ''?('Only \'\'' + constraint.get('value').value + '\'\' matches'):
|
||||
<div *ngIf="criteriaUtils.criteriaFields[constraint.get('field').value].type == 'number'" class="uk-width-1-4@l uk-width-1-1@m" inputClass="flat small" input [placeholder]="{static: true, label: 'Give a ' + criteriaUtils.criteriaFields[constraint.get('field').value].label}"
|
||||
[formInput]="constraint.get('value')"></div>
|
||||
<ng-container *ngIf="criteriaUtils.criteriaFields[constraint.get('field').value].type == 'static'">
|
||||
<div class="uk-width-1-4@l uk-width-1-1@m" inputClass="flat small" input [placeholder]="{static: true, label: 'Choose a ' + criteriaUtils.criteriaFields[constraint.get('field').value].label}"
|
||||
[formInput]="constraint.get('value')" [type]="criteriaUtils.criteriaFields[constraint.get('field').value].operator === 'string'?'autocomplete_soft':'select'" [options]="staticLists[constraint.get('field').value]"></div>
|
||||
</ng-container>
|
||||
<div class="uk-width-1-1@m uk-width-expand@l uk-grid">
|
||||
|
||||
<label class="uk-text-uppercase uk-text-bold uk-width-1-3@m uk-hidden@l uk-text-truncate">Match Case</label>
|
||||
<div class="uk-width-expand">
|
||||
|
||||
<mat-slide-toggle [checked]="constraint.get('verb_suffix').value === ''"
|
||||
class="uk-margin-left"
|
||||
[attr.uk-tooltip]="(constraint.get('verb_suffix').value === ''?('Only \'\'' + constraint.get('value').value + '\'\' matches'):
|
||||
('Both \'\'' + constraint.get('value').value.toUpperCase() + '\'\' and \'\'' + constraint.get('value').value.toLowerCase() + '\'\' match'))"
|
||||
(change)="caseSensitive($event, constraint)"></mat-slide-toggle>
|
||||
</div>
|
||||
<div class="uk-flex uk-flex-center">
|
||||
<button class="uk-close uk-icon" (click)="removeConstraint(i, j)">
|
||||
<icon name="close" ratio="1.5" [flex]="true"
|
||||
[attr.uk-tooltip]="(getConstraint(i).length === 1?'By removing this constraint, the ' + entityType + ' will be removed too':null)"></icon>
|
||||
</button>
|
||||
(change)="caseSensitive($event, constraint)"></mat-slide-toggle>
|
||||
</div>
|
||||
<div class="uk-width-auto">
|
||||
<button class="uk-close uk-icon" (click)="removeConstraint(i, j)">
|
||||
<icon name="close" ratio="1.5" [flex]="true"
|
||||
[attr.uk-tooltip]="(getConstraint(i).length === 1?'By removing this constraint, the ' + entityType + ' will be removed too':null)"></icon>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import {NotificationHandler} from "../../../openaireLibrary/utils/notification-h
|
|||
import {OpenaireEntities} from "../../../openaireLibrary/utils/properties/searchFields";
|
||||
import {ISVocabulariesService} from "../../../openaireLibrary/utils/staticAutoComplete/ISVocabularies.service";
|
||||
import {Subscription} from "rxjs";
|
||||
import {Option} from "../../../openaireLibrary/sharedComponents/input/input.component";
|
||||
|
||||
@Component({
|
||||
selector: 'criteria',
|
||||
|
|
@ -38,37 +39,47 @@ export class CriteriaComponent implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||
public selectionCriteriaForm: UntypedFormGroup;
|
||||
public properties: EnvProperties = properties;
|
||||
public criteriaUtils: CriteriaUtils = new CriteriaUtils();
|
||||
public fos: string[] = [];
|
||||
public sdg: string[] = [];
|
||||
public loading = true;
|
||||
public openaireEntities = OpenaireEntities;
|
||||
private subscriptions: any[] = [];
|
||||
|
||||
fieldOptions = [];
|
||||
vocabularyLists: { [id: string]: any[] } = {};
|
||||
staticLists: { [id: string]: any[] } = {};
|
||||
constructor(private cdr: ChangeDetectorRef, private vocabulariesService: ISVocabulariesService,
|
||||
private fb: UntypedFormBuilder) {
|
||||
for (const key of Object.keys(this.criteriaUtils.criteriaFields)) {
|
||||
const field = this.criteriaUtils.criteriaFields[key];
|
||||
this.fieldOptions.push({value: this.criteriaUtils.criteriaFields[key].value, label: this.criteriaUtils.criteriaFields[key].label});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ngOnInit() {
|
||||
this.loading = false;
|
||||
this.subscriptions.push(this.vocabulariesService.getVocabularyByType('fos', null, properties).subscribe((fos: any[]) => {
|
||||
this.fos = fos.map(element => element.id);
|
||||
this.staticLists['fos'] = fos.map(element => element.id);
|
||||
}));
|
||||
this.subscriptions.push(this.vocabulariesService.getVocabularyByType('sdg', null, properties).subscribe((sdg: any[]) => {
|
||||
this.sdg = sdg.map(element => element.id);
|
||||
this.staticLists['sdg'] = sdg.map(element => element.id);
|
||||
}));
|
||||
|
||||
this.staticLists['type']= [{ label: OpenaireEntities.PUBLICATIONS, value: "Publication" },
|
||||
{ label: OpenaireEntities.DATASETS, value: "Dataset" },
|
||||
{ label: OpenaireEntities.SOFTWARE, value: "Software" },
|
||||
{ label: OpenaireEntities.OTHER, value: "ORP" }]
|
||||
|
||||
}
|
||||
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if(changes.selectionCriteria){
|
||||
this.reset();
|
||||
}
|
||||
this.calculateMaxHeight();
|
||||
}
|
||||
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.calculateMaxHeight();
|
||||
}
|
||||
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach(subscription => {
|
||||
if (subscription instanceof Subscription) {
|
||||
|
|
@ -76,7 +87,7 @@ export class CriteriaComponent implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
calculateMaxHeight() {
|
||||
if(this.height) {
|
||||
if(this.height > 0) {
|
||||
|
|
@ -86,13 +97,12 @@ export class CriteriaComponent implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
reset() {
|
||||
this.selectionCriteriaForm = this.fb.group({
|
||||
criteria: this.fb.array([])
|
||||
});
|
||||
if (this.selectionCriteria?.criteria) {
|
||||
|
||||
this.selectionCriteria.criteria.forEach(criterion => {
|
||||
let constraintArray: UntypedFormArray = this.fb.array([]);
|
||||
criterion.constraint.forEach(constraint => {
|
||||
|
|
@ -109,23 +119,23 @@ export class CriteriaComponent implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
get disabled() {
|
||||
return this.loading || !this.dirty || this.selectionCriteriaForm.invalid;
|
||||
}
|
||||
|
||||
|
||||
public get criteria(): UntypedFormArray {
|
||||
return this.selectionCriteriaForm.get('criteria') as UntypedFormArray;
|
||||
}
|
||||
|
||||
|
||||
public getConstraint(i: number): UntypedFormArray {
|
||||
return this.criteria.at(i).get('constraint') as UntypedFormArray;
|
||||
}
|
||||
|
||||
|
||||
public addCriteria() {
|
||||
let constraintArray: UntypedFormArray = this.fb.array([
|
||||
this.fb.group({
|
||||
field: this.fb.control('', Validators.required),
|
||||
field: this.fb.control(this.fieldOptions[0].value, Validators.required),
|
||||
verb: this.fb.control('contains', Validators.required),
|
||||
value: this.fb.control('', Validators.required),
|
||||
verb_suffix: this.fb.control('_caseinsensitive')
|
||||
|
|
@ -135,18 +145,18 @@ export class CriteriaComponent implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||
this.cdr.detectChanges();
|
||||
document.getElementById('criterion-' + (this.criteria.length - 1).toString()).scrollIntoView({behavior: 'smooth'});
|
||||
}
|
||||
|
||||
|
||||
public addConstraint(i: number) {
|
||||
let constraintArray: UntypedFormArray = this.criteria.at(i).get('constraint') as UntypedFormArray;
|
||||
constraintArray.push(this.fb.group({
|
||||
field: this.fb.control('', Validators.required),
|
||||
verb: this.fb.control('contains', Validators.required),
|
||||
field: this.fb.control(this.fieldOptions[0].value, Validators.required),
|
||||
verb: this.fb.control('equals', Validators.required), // equals is available in all operator types
|
||||
value: this.fb.control('', Validators.required),
|
||||
verb_suffix: this.fb.control('_caseinsensitive')
|
||||
}));
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
|
||||
|
||||
public removeConstraint(i: number, j: number) {
|
||||
let constraintArray: UntypedFormArray = this.criteria.at(i).get('constraint') as UntypedFormArray;
|
||||
constraintArray.removeAt(j);
|
||||
|
|
@ -155,11 +165,11 @@ export class CriteriaComponent implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||
}
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
|
||||
|
||||
get criteriaArray(): Criteria[] {
|
||||
return (this.selectionCriteria?.criteria) ? this.selectionCriteria?.criteria : [];
|
||||
}
|
||||
|
||||
|
||||
get dirty() {
|
||||
if (!this.selectionCriteria && !this.criteria) {
|
||||
return false;
|
||||
|
|
@ -178,19 +188,19 @@ export class CriteriaComponent implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||
}).length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
save(callback: (selectionCriteria) => void = null) {
|
||||
if (this.selectionCriteriaForm.valid) {
|
||||
this.loading = true;
|
||||
callback(this.parseForm(this.selectionCriteriaForm.value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
handeError(message, error = null) {
|
||||
console.error(error);
|
||||
NotificationHandler.rise(message, 'danger');
|
||||
}
|
||||
|
||||
|
||||
caseSensitive(event: MatSlideToggleChange, constraint: AbstractControl) {
|
||||
if (event.checked) {
|
||||
constraint.get('verb_suffix').setValue('');
|
||||
|
|
@ -198,11 +208,11 @@ export class CriteriaComponent implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||
constraint.get('verb_suffix').setValue('_caseinsensitive');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
removeSuffix(verb: string) {
|
||||
return verb.replace('_caseinsensitive', '');
|
||||
}
|
||||
|
||||
|
||||
getSuffix(verb: string) {
|
||||
if (verb.includes('_caseinsensitive')) {
|
||||
return '_caseinsensitive';
|
||||
|
|
@ -210,7 +220,7 @@ export class CriteriaComponent implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
parseForm(formValue): SelectionCriteria {
|
||||
let value = HelperFunctions.copy(formValue);
|
||||
let selectionCriteria: SelectionCriteria = new SelectionCriteria();
|
||||
|
|
@ -226,13 +236,25 @@ export class CriteriaComponent implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||
return selectionCriteria;
|
||||
}
|
||||
|
||||
resetFieldWhenValueChange(constraint){
|
||||
resetFieldWhenValueChange(constraint) {
|
||||
// if field not numeric, but verb is numeric clear the verb
|
||||
if(this.criteriaUtils.numericFields.indexOf(constraint.get('field').value) == -1 && this.criteriaUtils.verbs.indexOf(constraint.get('verb').value)){
|
||||
constraint.get('verb').setValue(this.criteriaUtils.verbs[0].value);
|
||||
constraint.get("value").setValue("");
|
||||
constraint.get("value").setValue("");
|
||||
let operatorOptions = this.criteriaUtils.verbs;
|
||||
if (this.criteriaUtils.criteriaFields[constraint.get('field').value].operator == 'numeric') {
|
||||
operatorOptions = this.criteriaUtils.verbsForNumbers;
|
||||
} else if (this.criteriaUtils.criteriaFields[constraint.get('field').value].operator == 'exact') {
|
||||
operatorOptions = this.criteriaUtils.verbsForExact;
|
||||
}
|
||||
if(this.criteriaUtils.numericFields.indexOf(constraint.get('field').value) != -1 && this.criteriaUtils.numericFields.indexOf(constraint.get('verb').value)){
|
||||
constraint.get('verb').setValue(this.criteriaUtils.verbsForNumbers[0].value);
|
||||
constraint.get('verb').setValue(operatorOptions[0].value);
|
||||
constraint.get('verb_suffix').setValue(this.getSuffix(constraint.get('verb').value));
|
||||
}
|
||||
|
||||
public autoCompleteValueChanged(control: AbstractControl, value: Option | string) {
|
||||
if(typeof value === 'string') {
|
||||
control.setValue(value);
|
||||
} else {
|
||||
control.setValue(value.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import {MatSlideToggleModule} from "@angular/material/slide-toggle";
|
|||
import {ScrollingModule} from "@angular/cdk/scrolling";
|
||||
import {NoLoadPaging} from "../../../openaireLibrary/searchPages/searchUtils/no-load-paging.module";
|
||||
import {PagingModule} from "../../../openaireLibrary/utils/paging.module";
|
||||
import {StaticAutocompleteModule} from "../../../openaireLibrary/utils/staticAutoComplete/staticAutoComplete.module";
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
|
|
@ -30,6 +31,7 @@ import {PagingModule} from "../../../openaireLibrary/utils/paging.module";
|
|||
ScrollingModule,
|
||||
NoLoadPaging,
|
||||
PagingModule,
|
||||
StaticAutocompleteModule,
|
||||
],
|
||||
declarations: [
|
||||
CriteriaComponent
|
||||
|
|
|
|||
|
|
@ -24,11 +24,10 @@ import {UntypedFormBuilder} from "@angular/forms";
|
|||
[communityContentProviders]="communityContentProviders"
|
||||
[loading]="showLoadingInRemove" [community]="community"
|
||||
(editCriteria)="openCriteria($event)"
|
||||
|
||||
(communityContentProvidersChanged)="communityContentProvidersChanged($event)">
|
||||
</remove-content-providers>
|
||||
<fs-modal #addContentProvidersModal>
|
||||
<add-content-providers #addContentProviders [communityContentProviders]="communityContentProviders"
|
||||
<fs-modal #addContentProvidersModal (cancelEmitter)="addView = false">
|
||||
<add-content-providers [communityContentProviders]="communityContentProviders"
|
||||
[community]="community"
|
||||
(communityContentProvidersChanged)="communityContentProvidersChanged($event)"></add-content-providers>
|
||||
</fs-modal>
|
||||
|
|
@ -46,17 +45,17 @@ import {UntypedFormBuilder} from "@angular/forms";
|
|||
<label class="uk-margin-medium-top uk-margin-small-left ">Suggest for deposit</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-hr" [class.uk-hidden]="!enabled">
|
||||
<div class="uk-text-center uk-text-bold uk-text-large uk-margin-top ">Content filters</div>
|
||||
<criteria #criteria *ngIf="dataProvider" [height]="'-1'"
|
||||
[selectionCriteria]="dataProvider.selectioncriteria">
|
||||
<div no-criteria>
|
||||
<h5 class="uk-margin-small-bottom">No Filters for {{dataProvider.officialname}} yet</h5>
|
||||
<i class="uk-display-block">If no Filters are specified, all {{openaireEntities.RESULTS | lowercase}} of this {{openaireEntities.DATASOURCE | lowercase}} will be included in your
|
||||
{{openaireEntities.COMMUNITY | lowercase}}.
|
||||
</i>
|
||||
</div>
|
||||
</criteria>
|
||||
<div *ngIf="enabled" class="uk-hr">
|
||||
<div class="uk-text-center uk-text-bold uk-text-large uk-margin-top ">Content filters</div>
|
||||
<criteria #criteria *ngIf="dataProvider" [height]="-1"
|
||||
[selectionCriteria]="dataProvider.selectioncriteria">
|
||||
<div no-criteria>
|
||||
<h5 class="uk-margin-small-bottom">No Filters for {{dataProvider.officialname}} yet</h5>
|
||||
<i class="uk-display-block">If no Filters are specified, all {{openaireEntities.RESULTS | lowercase}} of this {{openaireEntities.DATASOURCE | lowercase}} will be included in your
|
||||
{{openaireEntities.COMMUNITY | lowercase}}.
|
||||
</i>
|
||||
</div>
|
||||
</criteria>
|
||||
</div>
|
||||
<div *ngIf="deposit" class="uk-hr">
|
||||
|
||||
|
|
@ -84,9 +83,8 @@ export class ManageContentProvidersComponent implements OnInit {
|
|||
communityContentProviders: ContentProvider[] = [];
|
||||
@ViewChild(RemoveContentProvidersComponent) removeContentProvidersComponent: RemoveContentProvidersComponent;
|
||||
@ViewChild('criteria') criteria: CriteriaComponent;
|
||||
@ViewChild('addContentProvidersModal', { static: true }) addContentProvidersModal: FullScreenModalComponent;
|
||||
@ViewChild('addContentProvidersModal') addContentProvidersModal: FullScreenModalComponent;
|
||||
@ViewChild('filtersModal', { static: true }) filtersModal: FullScreenModalComponent;
|
||||
@ViewChild('depositModal', { static: true }) depositModal: FullScreenModalComponent;
|
||||
private subscriptions: any[] = [];
|
||||
public showLoadingInRemove: boolean = true;
|
||||
public body: string = "Send from page";
|
||||
|
|
@ -94,6 +92,7 @@ export class ManageContentProvidersComponent implements OnInit {
|
|||
public openaireEntities = OpenaireEntities;
|
||||
public community: CommunityInfo;
|
||||
public dataProvider: ContentProvider;
|
||||
public addView: boolean = false;
|
||||
message = "";
|
||||
deposit= false;
|
||||
enabled = false;
|
||||
|
|
@ -130,6 +129,8 @@ export class ManageContentProvidersComponent implements OnInit {
|
|||
this.addContentProvidersModal.okButtonText = "Done";
|
||||
this.addContentProvidersModal.back = true;
|
||||
this.addContentProvidersModal.okButton = true;
|
||||
this.addView = true;
|
||||
this.cdr.detectChanges();
|
||||
this.addContentProvidersModal.open();
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +155,6 @@ export class ManageContentProvidersComponent implements OnInit {
|
|||
this.dataProvider.deposit = this.deposit;
|
||||
this.dataProvider.message = this.message;
|
||||
this.dataProvider.enabled = this.enabled;
|
||||
console.log(this.dataProvider)
|
||||
this.manageCommunityContentProvidersService.saveContentProvider(this.properties, this.dataProvider, this.communityService.selectedSubCommunityId()).subscribe(() => {
|
||||
this.criteria.reset();
|
||||
this.removeContentProvidersComponent.getCommunityContentProviders();
|
||||
|
|
@ -166,7 +166,6 @@ export class ManageContentProvidersComponent implements OnInit {
|
|||
});
|
||||
}
|
||||
this.removeContentProvidersComponent.loading = true;
|
||||
console.log()
|
||||
this.criteria.save(callback);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue