[Admin]: Fix datasource criteria base on communities API

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@57516 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-11-05 15:18:54 +00:00
parent 9f9e35b805
commit 248b7a4400
4 changed files with 16 additions and 34 deletions

View File

@ -37,7 +37,7 @@
<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="sc"> <div class="uk-padding" style="border: solid 1px;" formArrayName="constraint">
<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 sc of getConstraint(i).controls; let j=index" <div *ngFor="let constraint 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]="sc.get('field').value === ''" [class.uk-text-muted]="constraint.get('field').value === ''"
[class.uk-form-danger]="sc.get('field').status === 'INVALID'"> [class.uk-form-danger]="constraint.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]="sc.get('verb').status === 'INVALID'"> [class.uk-form-danger]="constraint.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]="sc.get('value').status === 'INVALID'"> [class.uk-form-danger]="constraint.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>

View File

@ -62,11 +62,11 @@ export class CriteriaComponent implements OnInit {
this.selectioncriteria = this.fb.group({ this.selectioncriteria = this.fb.group({
criteria: this.fb.array([]) criteria: this.fb.array([])
}); });
let selectionCriteria = CriteriaComponent.CDataToJSON(this.dataProvider.selectioncriteria); let selectionCriteria = this.dataProvider.selectioncriteria;
if (selectionCriteria) { if (selectionCriteria) {
selectionCriteria.criteria.forEach(criterion => { selectionCriteria.criteria.forEach(criterion => {
let constraintArray: FormArray = this.fb.array([]); let constraintArray: FormArray = this.fb.array([]);
criterion.sc.forEach(constraint => { criterion.constraint.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),
@ -74,7 +74,7 @@ export class CriteriaComponent implements OnInit {
})); }));
}); });
this.criteria.push(this.fb.group({ this.criteria.push(this.fb.group({
sc: constraintArray constraint: constraintArray
})); }));
}); });
} }
@ -85,7 +85,7 @@ export class CriteriaComponent implements OnInit {
} }
public getConstraint(i: number): FormArray { public getConstraint(i: number): FormArray {
return this.criteria.at(i).get('sc') as FormArray; return this.criteria.at(i).get('constraint') as FormArray;
} }
public addCriteria() { public addCriteria() {
@ -97,12 +97,12 @@ export class CriteriaComponent implements OnInit {
}) })
]); ]);
this.criteria.push(this.fb.group({ this.criteria.push(this.fb.group({
sc: constraintArray constraint: constraintArray
})); }));
} }
public addConstraint(i: number) { public addConstraint(i: number) {
let constraintArray: FormArray = this.criteria.at(i).get('sc') as FormArray; let constraintArray: FormArray = this.criteria.at(i).get('constraint') 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),
@ -111,34 +111,17 @@ 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('sc') as FormArray; let constraintArray: FormArray = this.criteria.at(i).get('constraint') 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.selectioncriteria.status === 'VALID') { if (this.selectioncriteria.status === 'VALID') {
this.dataProvider.selectioncriteria = CriteriaComponent.JSONToCData(this.selectioncriteria.value); this.dataProvider.selectioncriteria = this.selectioncriteria.value;
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'], {

View File

@ -133,8 +133,7 @@ export class RemoveContentProvidersComponent implements OnInit {
//console.info("ngAfterViewInit"); //console.info("ngAfterViewInit");
} }
public getCriteriaLabel(cdata: string): string { public getCriteriaLabel(selectionCriteria: SelectionCriteria): string {
let selectionCriteria: SelectionCriteria = CriteriaComponent.CDataToJSON(cdata);
if(selectionCriteria && selectionCriteria.criteria.length > 0) { if(selectionCriteria && selectionCriteria.criteria.length > 0) {
return (selectionCriteria.criteria.length === 1)?'1 criterion':(selectionCriteria.criteria.length + ' criteria') return (selectionCriteria.criteria.length === 1)?'1 criterion':(selectionCriteria.criteria.length + ' criteria')
} else { } else {

View File

@ -34,7 +34,7 @@
"piwikBaseUrl" :" https://analytics.openaire.eu/piwik.php?idsite=6", "piwikBaseUrl" :" https://analytics.openaire.eu/piwik.php?idsite=6",
"loginUrl" :"http://rudie.di.uoa.gr:8080/dnet-login/openid_connect_login", "loginUrl" :"http://rudie.di.uoa.gr:8080/dnet-login/openid_connect_login",
"userInfoUrl" : "http://rudie.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=", "userInfoUrl" : "http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=",
"logoutUrl" :"https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=", "logoutUrl" :"https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",