Save changes and update database with claims

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@47033 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
konstantina.galouni 2017-05-02 14:05:13 +00:00
parent 6b35091e9c
commit bf6c47a309
5 changed files with 102 additions and 53 deletions

View File

@ -9,6 +9,8 @@ import {ModalLoading} from '../../utils/modal/loading.component';
import {Session} from '../../login/utils/helper.class';
import {RouterHelper} from '../../utils/routerHelper.class';
@Component({
selector: 'claims-project-manager',
template: `
@ -38,69 +40,96 @@ import {Session} from '../../login/utils/helper.class';
</div>
<div *ngIf="accessStatus=='valid'">
<h1> Pending Claims </h1>
<h1> Pending Claims for project:
<a [queryParams]="routerHelper.createQueryParam('projectId',project['openaireId'])"
routerLinkActive="router-link-active"
routerLink="/search/project" >
{{project['name']}} ({{project['funderName']}})
</a>
</h1>
<div *ngIf=" pending_claims && pending_claims.length == 0" >
<div class = "uk-alert uk-alert-info " >No pending claims found.</div>
</div>
<div class="">
<div class="uk-overflow-container">
<table *ngIf="pending_claims && pending_claims.length > 0" class="uk-table uk-table-striped">
<thead>
<tr>
<th>Research Result</th>
<th>Link to</th>
<th>Claimed by</th>
<th>Claimed Date</th>
<th>True</th>
<th>False</th>
<!--th>Link to</th-->
<th class="uk-text-center">Claimed by</th>
<th class="uk-text-center">Claimed Date</th>
<th class="uk-text-center">Approve</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let claim of pending_claims ">
<td><claim-entity [entity]="claim.target" [type]="claim.targetType" > </claim-entity></td>
<td><claim-entity [entity]="claim.source" [type]="claim.sourceType" > </claim-entity></td>
<td>{{claim.userMail}}</td>
<td>{{claim.date}}</td>
<td><input [id]="claim.id" type="checkbox" (click)="selectApprove(claim.id,$event)" [ngModel]="isSelectedRight(claim.id)"/></td>
<td><input [id]="claim.id" type="checkbox" (click)="selectDisapprove(claim.id,$event)" [ngModel]="isSelectedWrong(claim.id)"/></td>
<tr class="uk-table-middle" *ngFor="let claim of pending_claims ">
<td class="uk-width-2-6" *ngIf="claim.targetType != 'project'"><claim-entity [entity]="claim.target" [type]="claim.targetType" > </claim-entity></td>
<td class="uk-width-1-6 uk-text-center" *ngIf="claim.sourceType != 'project'"><claim-entity [entity]="claim.source" [type]="claim.sourceType" > </claim-entity></td>
<td class="uk-width-1-6 uk-text-center">{{claim.userMail}}</td>
<td class="uk-width-1-6 uk-text-center">{{claim.date}}</td>
<!--td>
<label>
Yes <input [id]="claim.id" type="checkbox" (click)="selectApprove(claim.id,$event)" [ngModel]="isSelectedRight(claim.id)"/>
</label>
<label>
No <input [id]="claim.id" type="checkbox" (click)="selectDisapprove(claim.id,$event)" [ngModel]="isSelectedWrong(claim.id)"/>
</label>
</td-->
<td class="uk-width-1-6 uk-text-center">
<label>
Yes <input [id]="claim.id" type="checkbox" (click)="selectApprove(claim.id,$event)" [ngModel]="isSelectedRight(claim.id)"/>
</label>
<label>
No <input [id]="claim.id" type="checkbox" (click)="selectDisapprove(claim.id,$event)" [ngModel]="isSelectedWrong(claim.id)"/>
</label>
</td>
</tr>
</tbody>
</table>
<h1> Already Curated Claims </h1>
<div *ngIf=" curated_claims && curated_claims.length == 0" >
<div class = "uk-alert uk-alert-info " >No curated claims found.</div>
</div>
<div class="">
<div class="uk-overflow-container">
<table *ngIf="curated_claims && curated_claims.length > 0" class="uk-table uk-table-striped">
<thead>
<tr>
<th>Research Result</th>
<th>Link to</th>
<th>Claimed by</th>
<th>Claimed Date</th>
<th>Curated by</th>
<th>Curation Date</th>
<th>True</th>
<th>False</th>
<th></th>
<!--th>Link to</th-->
<th class="uk-text-center">Claimed by</th>
<th class="uk-text-center">Claimed Date</th>
<th class="uk-text-center">Curated by</th>
<th class="uk-text-center">Curation Date</th>
<th class="uk-text-center">Approved</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let claim of curated_claims let i=index">
<td><claim-entity [entity]="claim.target" [type]="claim.targetType" > </claim-entity></td>
<td><claim-entity [entity]="claim.source" [type]="claim.sourceType" > </claim-entity></td>
<td>{{claim.userMail}}</td>
<td>{{claim.date}}</td>
<td>{{claim.curatedBy}}</td>
<td>{{claim.curationDate}}</td>
<td><input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" (click)="selectApprove(claim.id,$event)" [ngModel]="isRight(claim)"/></td>
<td><input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" (click)="selectDisapprove(claim.id,$event)" [ngModel]="isWrong(claim)"/></td>
<td><button class="uk-button" (click)="editable.add(i)">Edit</button></td>
<tr class="uk-table-middle" *ngFor="let claim of curated_claims let i=index">
<td class="uk-width-1-6" *ngIf="claim.targetType != 'project'"><claim-entity [entity]="claim.target" [type]="claim.targetType" > </claim-entity></td>
<td class="uk-width-1-6" *ngIf="claim.sourceType != 'project'"><claim-entity [entity]="claim.source" [type]="claim.sourceType" > </claim-entity></td>
<td class="uk-width-1-6 uk-text-center">{{claim.userMail}}</td>
<td class="uk-width-1-6 uk-text-center">{{claim.date}}</td>
<td class="uk-width-1-6 uk-text-center">{{claim.curatedBy}}</td>
<td class="uk-width-1-6 uk-text-center">{{claim.curationDate}}</td>
<td class="uk-width-1-6 uk-text-center">
<label>
Yes <input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" [ngModel]="isRight(claim)"/>
</label>
<label>
No <input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" [ngModel]="isWrong(claim)"/>
</label>
</td>
<!--td><input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" (click)="selectDisapprove(claim.id,$event)" [ngModel]="isWrong(claim)"/></td-->
<!--td><button class="uk-button" (click)="editable.add(i)">Edit</button></td-->
</tr>
</tbody>
</table>
@ -116,8 +145,10 @@ import {Session} from '../../login/utils/helper.class';
})
export class ClaimsByTokenComponent {
//change true - false to accept: yes - no
public token: string = "";
public sub: any;
public project: any;
private claims:any = [];
public pending_claims: any = [];
public curated_claims: any = [];
@ -132,6 +163,8 @@ export class ClaimsByTokenComponent {
@ViewChild (ModalSelect) selectModal : ModalSelect;
@ViewChild (ModalLoading) loading : ModalLoading ;
public routerHelper:RouterHelper = new RouterHelper();
constructor ( private route: ActivatedRoute, private _router:Router, private claimsByTokenService: ClaimsByTokenService ) {
}
@ -150,15 +183,20 @@ export class ClaimsByTokenComponent {
}
validateJWTandToken() {
var user_token=Session.getUserJwt();
var jwtToken=Session.getUserJwt();
if(this.token) {
this.claimsByTokenService.getClaims(this.token, user_token).subscribe(
this.claimsByTokenService.getClaims(this.token, jwtToken).subscribe(
data => {
this.closeLoading();
this.accessStatus = "valid";
//console.info(data);
this.claims = data.data;
for(let claim of this.claims) {
if(claim.targetType == "project") {
this.project = claim.target;
} else {
this.project = claim.source;
}
if(claim.curatedBy) {
this.curated_claims.push(claim);
} else {
@ -229,8 +267,9 @@ export class ClaimsByTokenComponent {
saveChanges() {
console.info("Changes Saved!");
/*
this.claimsByTokenService.updateClaimsCuration(this.token, this.selectedRight, this.selectedWrong).subscribe(
var jwtToken=Session.getUserJwt();
this.claimsByTokenService.updateClaimsCuration(jwtToken, this.selectedRight, this.selectedWrong).subscribe(
data => {
console.info(data);
},
@ -238,7 +277,7 @@ export class ClaimsByTokenComponent {
console.log(err);
}
);
*/
}
public closeLoading(){

View File

@ -1,4 +1,5 @@
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { SharedModule } from '../../shared/shared.module';
import { ClaimsByTokenComponent } from './claimsByToken.component';
@ -14,6 +15,7 @@ import {LoginGuard} from'../../login/loginGuard.guard';
@NgModule({
imports: [
RouterModule,
SharedModule,
ClaimsByTokenRoutingModule,
ClaimEntityFormatterModule,

View File

@ -10,12 +10,11 @@ export class ClaimsByTokenService {
constructor(private http: Http, public _cache: CacheService) {}
getClaims(token: string, user_token: string):any {
getClaims(token: string, jwtToken: string):any {
console.info("getClaims in service");
let url = OpenaireProperties.getClaimsAPIURL()+"projects/corda__h2020::94c962e736df90a5075a7f660ba3d7f6/claims"
+"?&token="+user_token;
console.info(url);
+"?&token="+jwtToken;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
@ -43,17 +42,24 @@ console.info(url);
}
*/
updateClaimsCuration(token: string, selectedRight: Set<string>, selectedWrong: Set<string>) {
let url = OpenaireProperties.getClaimsAPIURL(); // What else?
let claimsCurationInfo: any = [];
for(let selected in selectedRight) {
let claimCurationInfo: any = {"claim_id": selected, "approved": true, "token": token};
claimsCurationInfo.add(claimCurationInfo);
}
for(let selected in selectedWrong) {
let claimCurationInfo: any = {"claim_id": selected, "approved": false, "token": token};
claimsCurationInfo.add(claimCurationInfo);
}
updateClaimsCuration(jwtToken: string, selectedRight: Set<string>, selectedWrong: Set<string>) {
let url = OpenaireProperties.getClaimsAPIURL() + "curate/bulk?token="+jwtToken;
let claimsCurationInfo: any = []; //e.g.: [{"id":"2","approved":true},{"id":"1","approved":true}]
selectedRight.forEach(function(selected) {
console.info(selected);
let claimCurationInfo: {"id": string, "approved": boolean} = {"id": selected, "approved": true};
claimsCurationInfo.push(claimCurationInfo);
});
selectedWrong.forEach(function(selected) {
let claimCurationInfo: any = {"id": selected, "approved": false};
claimsCurationInfo.push(claimCurationInfo);
});
console.info("\n\n"+claimsCurationInfo);
let body = JSON.stringify( claimsCurationInfo );
console.warn('Json body: : '+body);
let headers = new Headers({ 'Content-Type': 'application/json' });

View File

@ -1,4 +1,5 @@
export class DatasetInfo {
underCurationMessage: boolean;
title: { "name": string, "url": string, "accessMode": string};
authors: { "name": string, "id": string}[];
date: string;

View File

@ -1,4 +1,5 @@
export class PublicationInfo {
underCurationMessage: boolean;
title: { "name": string, "url": string, "accessMode": string};
authors: { "name": string, "id": string}[];
date: string;