[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:
parent
b3c18cb020
commit
9f9e35b805
|
@ -33,11 +33,11 @@
|
||||||
No criteria are specified
|
No criteria are specified
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="criteria.controls.length > 0" [formGroup]="selcrit">
|
<div *ngIf="criteria.controls.length > 0" [formGroup]="selectioncriteria">
|
||||||
<div formArrayName="criteria">
|
<div formArrayName="criteria">
|
||||||
<div class="uk-margin-top" *ngFor="let criterion of criteria.controls; let i=index" [formGroupName]="i">
|
<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>
|
<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-flex uk-flex-middle uk-grid-small uk-margin-small-bottom" uk-grid>
|
||||||
<div class="uk-width-1-5">
|
<div class="uk-width-1-5">
|
||||||
<label class="uk-text-uppercase uk-text-muted">Constraint Field</label>
|
<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>
|
<label class="uk-text-uppercase uk-text-muted">Term</label>
|
||||||
</div>
|
</div>
|
||||||
</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">
|
[formGroupName]="j" class="uk-margin-bottom">
|
||||||
<div class="uk-flex uk-flex-middle uk-grid-small" uk-grid>
|
<div class="uk-flex uk-flex-middle uk-grid-small" uk-grid>
|
||||||
<div class="uk-width-1-5">
|
<div class="uk-width-1-5">
|
||||||
<select formControlName="field" class="form-control uk-select"
|
<select formControlName="field" class="form-control uk-select"
|
||||||
[class.uk-text-muted]="constraint.get('field').value === ''"
|
[class.uk-text-muted]="sc.get('field').value === ''"
|
||||||
[class.uk-form-danger]="constraint.get('field').status === 'INVALID'">
|
[class.uk-form-danger]="sc.get('field').status === 'INVALID'">
|
||||||
<option [value]="''" disabled selected hidden>Select a field...</option>
|
<option [value]="''" disabled selected hidden>Select a field...</option>
|
||||||
<option [value]="'title'">title</option>
|
<option [value]="'title'">title</option>
|
||||||
<option [value]="'author'">author's name</option>
|
<option [value]="'author'">author's name</option>
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-width-1-5">
|
<div class="uk-width-1-5">
|
||||||
<select formControlName="verb" class="form-control uk-select"
|
<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]="'contains'">contains</option>
|
||||||
<option [value]="'equals'">equals</option>
|
<option [value]="'equals'">equals</option>
|
||||||
<option [value]="'not_contains'">not contains</option>
|
<option [value]="'not_contains'">not contains</option>
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-width-2-5">
|
<div class="uk-width-2-5">
|
||||||
<input type="text" class="uk-input" formControlName="value" placeholder="Type term..."
|
<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>
|
||||||
<div class="uk-width-1-6">
|
<div class="uk-width-1-6">
|
||||||
<span *ngIf="getConstraint(i).length > j + 1">AND</span>
|
<span *ngIf="getConstraint(i).length > j + 1">AND</span>
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {HelperFunctions} from '../../../../openaireLibrary/utils/HelperFunctions.class';
|
import {HelperFunctions} from '../../../../openaireLibrary/utils/HelperFunctions.class';
|
||||||
import {SearchCommunityDataprovidersService} from '../../../../openaireLibrary/connect/contentProviders/searchDataproviders.service';
|
import {SearchCommunityDataprovidersService} from '../../../../openaireLibrary/connect/contentProviders/searchDataproviders.service';
|
||||||
import {EnvProperties} from '../../../../openaireLibrary/utils/properties/env-properties';
|
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 {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||||
import {ManageCommunityContentProvidersService} from '../../../../services/manageContentProviders.service';
|
import {ManageCommunityContentProvidersService} from '../../../../services/manageContentProviders.service';
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ export class CriteriaComponent implements OnInit {
|
||||||
public community: string = '';
|
public community: string = '';
|
||||||
public openaireId: string = '';
|
public openaireId: string = '';
|
||||||
public dataProvider: ContentProvider = null;
|
public dataProvider: ContentProvider = null;
|
||||||
public selcrit: FormGroup;
|
public selectioncriteria: FormGroup;
|
||||||
private properties: EnvProperties;
|
private properties: EnvProperties;
|
||||||
showLoading = true;
|
showLoading = true;
|
||||||
public errorMessage: string;
|
public errorMessage: string;
|
||||||
|
@ -59,13 +59,14 @@ export class CriteriaComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
buildForm() {
|
buildForm() {
|
||||||
this.selcrit = this.fb.group({
|
this.selectioncriteria = this.fb.group({
|
||||||
criteria: this.fb.array([])
|
criteria: this.fb.array([])
|
||||||
});
|
});
|
||||||
if (this.dataProvider.selcrit) {
|
let selectionCriteria = CriteriaComponent.CDataToJSON(this.dataProvider.selectioncriteria);
|
||||||
this.dataProvider.selcrit.criteria.forEach(criteria => {
|
if (selectionCriteria) {
|
||||||
|
selectionCriteria.criteria.forEach(criterion => {
|
||||||
let constraintArray: FormArray = this.fb.array([]);
|
let constraintArray: FormArray = this.fb.array([]);
|
||||||
criteria.constraint.forEach(constraint => {
|
criterion.sc.forEach(constraint => {
|
||||||
constraintArray.push(this.fb.group({
|
constraintArray.push(this.fb.group({
|
||||||
field: this.fb.control(constraint.field, Validators.required),
|
field: this.fb.control(constraint.field, Validators.required),
|
||||||
verb: this.fb.control(constraint.verb, 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({
|
this.criteria.push(this.fb.group({
|
||||||
constraint: constraintArray
|
sc: constraintArray
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get criteria(): FormArray {
|
public get criteria(): FormArray {
|
||||||
return this.selcrit.get('criteria') as FormArray;
|
return this.selectioncriteria.get('criteria') as FormArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getConstraint(i: number): 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() {
|
public addCriteria() {
|
||||||
|
@ -96,12 +97,12 @@ export class CriteriaComponent implements OnInit {
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
this.criteria.push(this.fb.group({
|
this.criteria.push(this.fb.group({
|
||||||
constraint: constraintArray
|
sc: constraintArray
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public addConstraint(i: number) {
|
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({
|
constraintArray.push(this.fb.group({
|
||||||
field: this.fb.control('', Validators.required),
|
field: this.fb.control('', Validators.required),
|
||||||
verb: this.fb.control('contains', Validators.required),
|
verb: this.fb.control('contains', Validators.required),
|
||||||
|
@ -110,18 +111,34 @@ export class CriteriaComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeConstraint(i: number, j: number) {
|
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);
|
constraintArray.removeAt(j);
|
||||||
if (constraintArray.length === 0) {
|
if (constraintArray.length === 0) {
|
||||||
this.criteria.removeAt(i);
|
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() {
|
save() {
|
||||||
this.errorMessage = null;
|
this.errorMessage = null;
|
||||||
if (this.selcrit.status === 'VALID') {
|
if (this.selectioncriteria.status === 'VALID') {
|
||||||
this.dataProvider.selcrit = this.selcrit.value;
|
this.dataProvider.selectioncriteria = CriteriaComponent.JSONToCData(this.selectioncriteria.value);
|
||||||
console.log(this.dataProvider);
|
|
||||||
this.manageCommunityContentProvidersService.
|
this.manageCommunityContentProvidersService.
|
||||||
saveContentProvider(this.properties, this.dataProvider).subscribe( () => {
|
saveContentProvider(this.properties, this.dataProvider).subscribe( () => {
|
||||||
this._router.navigate(['manage-content-providers'], {
|
this._router.navigate(['manage-content-providers'], {
|
||||||
|
|
|
@ -68,12 +68,8 @@
|
||||||
<input title="Edit" src="assets/imgs/icn_edit.png"
|
<input title="Edit" src="assets/imgs/icn_edit.png"
|
||||||
(click)="goToCriteria(result.openaireId)"
|
(click)="goToCriteria(result.openaireId)"
|
||||||
class="edit uk-margin-small-right" type="image">
|
class="edit uk-margin-small-right" type="image">
|
||||||
<span *ngIf="result.selcrit && result.selcrit.criteria.length > 0"
|
<span (click)="goToCriteria(result.openaireId)"
|
||||||
(click)="goToCriteria(result.openaireId)"
|
class="clickable">{{getCriteriaLabel(result.selectioncriteria)}}</span>
|
||||||
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>
|
|
||||||
</td>
|
</td>
|
||||||
<td class="uk-text-center uk-width-1-4">
|
<td class="uk-text-center uk-width-1-4">
|
||||||
<!-- red_background_color red_color-->
|
<!-- red_background_color red_color-->
|
||||||
|
|
|
@ -13,6 +13,8 @@ import {DOI, StringUtils} from '../../../openaireLibrary/utils/string-utils.clas
|
||||||
|
|
||||||
import {Session} from '../../../openaireLibrary/login/utils/helper.class';
|
import {Session} from '../../../openaireLibrary/login/utils/helper.class';
|
||||||
import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class';
|
import {LoginErrorCodes} from '../../../openaireLibrary/login/utils/guardHelper.class';
|
||||||
|
import {SelectionCriteria} from '../../../openaireLibrary/utils/entities/contentProvider';
|
||||||
|
import {CriteriaComponent} from './criteria/criteria.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'remove-content-providers',
|
selector: 'remove-content-providers',
|
||||||
|
@ -131,6 +133,15 @@ export class RemoveContentProvidersComponent implements OnInit {
|
||||||
//console.info("ngAfterViewInit");
|
//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) {
|
filterData(row: any, query: string) {
|
||||||
let returnValue: boolean = false;
|
let returnValue: boolean = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue