[Admin]: Add save on datasource criteria

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@57355 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-10-13 20:09:41 +00:00
parent b3c18cb020
commit 9f9e35b805
4 changed files with 52 additions and 28 deletions

View File

@ -33,11 +33,11 @@
No criteria are specified
</div>
</div>
<div *ngIf="criteria.controls.length > 0" [formGroup]="selcrit">
<div *ngIf="criteria.controls.length > 0" [formGroup]="selectioncriteria">
<div formArrayName="criteria">
<div class="uk-margin-top" *ngFor="let criterion of criteria.controls; let i=index" [formGroupName]="i">
<span class="uk-text-uppercase uk-text-large uk-margin-small-bottom">Criterion {{i + 1}}</span><br>
<div class="uk-padding" style="border: solid 1px;" formArrayName="constraint">
<div class="uk-padding" style="border: solid 1px;" formArrayName="sc">
<div class="uk-flex uk-flex-middle uk-grid-small uk-margin-small-bottom" uk-grid>
<div class="uk-width-1-5">
<label class="uk-text-uppercase uk-text-muted">Constraint Field</label>
@ -49,13 +49,13 @@
<label class="uk-text-uppercase uk-text-muted">Term</label>
</div>
</div>
<div *ngFor="let constraint of getConstraint(i).controls; let j=index"
<div *ngFor="let sc of getConstraint(i).controls; let j=index"
[formGroupName]="j" class="uk-margin-bottom">
<div class="uk-flex uk-flex-middle uk-grid-small" uk-grid>
<div class="uk-width-1-5">
<select formControlName="field" class="form-control uk-select"
[class.uk-text-muted]="constraint.get('field').value === ''"
[class.uk-form-danger]="constraint.get('field').status === 'INVALID'">
[class.uk-text-muted]="sc.get('field').value === ''"
[class.uk-form-danger]="sc.get('field').status === 'INVALID'">
<option [value]="''" disabled selected hidden>Select a field...</option>
<option [value]="'title'">title</option>
<option [value]="'author'">author's name</option>
@ -66,7 +66,7 @@
</div>
<div class="uk-width-1-5">
<select formControlName="verb" class="form-control uk-select"
[class.uk-form-danger]="constraint.get('verb').status === 'INVALID'">
[class.uk-form-danger]="sc.get('verb').status === 'INVALID'">
<option [value]="'contains'">contains</option>
<option [value]="'equals'">equals</option>
<option [value]="'not_contains'">not contains</option>
@ -75,7 +75,7 @@
</div>
<div class="uk-width-2-5">
<input type="text" class="uk-input" formControlName="value" placeholder="Type term..."
[class.uk-form-danger]="constraint.get('value').status === 'INVALID'">
[class.uk-form-danger]="sc.get('value').status === 'INVALID'">
</div>
<div class="uk-width-1-6">
<span *ngIf="getConstraint(i).length > j + 1">AND</span>

View File

@ -3,7 +3,7 @@ import {ActivatedRoute, Router} from '@angular/router';
import {HelperFunctions} from '../../../../openaireLibrary/utils/HelperFunctions.class';
import {SearchCommunityDataprovidersService} from '../../../../openaireLibrary/connect/contentProviders/searchDataproviders.service';
import {EnvProperties} from '../../../../openaireLibrary/utils/properties/env-properties';
import {ContentProvider} from '../../../../openaireLibrary/utils/entities/contentProvider';
import {ContentProvider, SelectionCriteria} from '../../../../openaireLibrary/utils/entities/contentProvider';
import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms';
import {ManageCommunityContentProvidersService} from '../../../../services/manageContentProviders.service';
@ -16,7 +16,7 @@ export class CriteriaComponent implements OnInit {
public community: string = '';
public openaireId: string = '';
public dataProvider: ContentProvider = null;
public selcrit: FormGroup;
public selectioncriteria: FormGroup;
private properties: EnvProperties;
showLoading = true;
public errorMessage: string;
@ -59,13 +59,14 @@ export class CriteriaComponent implements OnInit {
}
buildForm() {
this.selcrit = this.fb.group({
this.selectioncriteria = this.fb.group({
criteria: this.fb.array([])
});
if (this.dataProvider.selcrit) {
this.dataProvider.selcrit.criteria.forEach(criteria => {
let selectionCriteria = CriteriaComponent.CDataToJSON(this.dataProvider.selectioncriteria);
if (selectionCriteria) {
selectionCriteria.criteria.forEach(criterion => {
let constraintArray: FormArray = this.fb.array([]);
criteria.constraint.forEach(constraint => {
criterion.sc.forEach(constraint => {
constraintArray.push(this.fb.group({
field: this.fb.control(constraint.field, Validators.required),
verb: this.fb.control(constraint.verb, Validators.required),
@ -73,18 +74,18 @@ export class CriteriaComponent implements OnInit {
}));
});
this.criteria.push(this.fb.group({
constraint: constraintArray
sc: constraintArray
}));
});
}
}
public get criteria(): FormArray {
return this.selcrit.get('criteria') as FormArray;
return this.selectioncriteria.get('criteria') as FormArray;
}
public getConstraint(i: number): FormArray {
return this.criteria.at(i).get('constraint') as FormArray;
return this.criteria.at(i).get('sc') as FormArray;
}
public addCriteria() {
@ -96,12 +97,12 @@ export class CriteriaComponent implements OnInit {
})
]);
this.criteria.push(this.fb.group({
constraint: constraintArray
sc: constraintArray
}));
}
public addConstraint(i: number) {
let constraintArray: FormArray = this.criteria.at(i).get('constraint') as FormArray;
let constraintArray: FormArray = this.criteria.at(i).get('sc') as FormArray;
constraintArray.push(this.fb.group({
field: this.fb.control('', Validators.required),
verb: this.fb.control('contains', Validators.required),
@ -110,18 +111,34 @@ export class CriteriaComponent implements OnInit {
}
public removeConstraint(i: number, j: number) {
let constraintArray: FormArray = this.criteria.at(i).get('constraint') as FormArray;
let constraintArray: FormArray = this.criteria.at(i).get('sc') as FormArray;
constraintArray.removeAt(j);
if (constraintArray.length === 0) {
this.criteria.removeAt(i);
}
}
public static CDataToJSON(cdata: string): SelectionCriteria {
if(cdata && cdata.length > 0) {
return JSON.parse(cdata.replace('<![CDATA[', '').
replace(']]>', ''));
} else {
return null;
}
}
public static JSONToCData(selectioncriteria: SelectionCriteria): string {
if(selectioncriteria && selectioncriteria.criteria.length > 0) {
return '<![CDATA[' + JSON.stringify(selectioncriteria) + ']]>';
} else {
return '';
}
}
save() {
this.errorMessage = null;
if (this.selcrit.status === 'VALID') {
this.dataProvider.selcrit = this.selcrit.value;
console.log(this.dataProvider);
if (this.selectioncriteria.status === 'VALID') {
this.dataProvider.selectioncriteria = CriteriaComponent.JSONToCData(this.selectioncriteria.value);
this.manageCommunityContentProvidersService.
saveContentProvider(this.properties, this.dataProvider).subscribe( () => {
this._router.navigate(['manage-content-providers'], {

View File

@ -68,12 +68,8 @@
<input title="Edit" src="assets/imgs/icn_edit.png"
(click)="goToCriteria(result.openaireId)"
class="edit uk-margin-small-right" type="image">
<span *ngIf="result.selcrit && result.selcrit.criteria.length > 0"
(click)="goToCriteria(result.openaireId)"
class="clickable">{{result.selcrit.criteria.length}} criteria</span>
<span *ngIf="!result.selcrit || result.selcrit.criteria.length === 0"
(click)="goToCriteria(result.openaireId)"
class="clickable">no criteria</span>
<span (click)="goToCriteria(result.openaireId)"
class="clickable">{{getCriteriaLabel(result.selectioncriteria)}}</span>
</td>
<td class="uk-text-center uk-width-1-4">
<!-- red_background_color red_color-->

View File

@ -13,6 +13,8 @@ import {DOI, StringUtils} from '../../../openaireLibrary/utils/string-utils.clas
import {Session} from '../../../openaireLibrary/login/utils/helper.class';
import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class';
import {SelectionCriteria} from '../../../openaireLibrary/utils/entities/contentProvider';
import {CriteriaComponent} from './criteria/criteria.component';
@Component({
selector: 'remove-content-providers',
@ -131,6 +133,15 @@ export class RemoveContentProvidersComponent implements OnInit {
//console.info("ngAfterViewInit");
}
public getCriteriaLabel(cdata: string): string {
let selectionCriteria: SelectionCriteria = CriteriaComponent.CDataToJSON(cdata);
if(selectionCriteria && selectionCriteria.criteria.length > 0) {
return (selectionCriteria.criteria.length === 1)?'1 criterion':(selectionCriteria.criteria.length + ' criteria')
} else {
return 'no criteria';
}
}
filterData(row: any, query: string) {
let returnValue: boolean = false;