[develop | DONE | ADDED ] bulk selection of projects
This commit is contained in:
parent
05db374254
commit
4bd736bd25
|
@ -84,12 +84,23 @@
|
|||
<div class="uk-margin-small-top" [innerHTML]="infoMessage"></div>
|
||||
</div>
|
||||
<ng-container *ngIf="openaireSearchUtils.totalResults > 0">
|
||||
<div>
|
||||
<label>
|
||||
<input id="checkAll" type="checkbox" (click)="selectAll()" class="uk-checkbox" title="Select all"
|
||||
[ngModel]="selectedIndexes.length == openaireProjects.length"/>
|
||||
</label>
|
||||
<button *ngIf="selectedIndexes.length > 0" class="uk-button uk-button-link uk-margin-xsmall-left" [class.uk-disabled]="selectedIndexes.length == 0"
|
||||
[disabled]="selectedIndexes.length == 0" (click)="addAll()" >
|
||||
Add ({{selectedIndexes.length}})
|
||||
</button>
|
||||
<hr class="uk-margin-remove-top">
|
||||
</div>
|
||||
<no-load-paging [type]="openaireEntities.PROJECTS"
|
||||
[page]="openaireSearchUtils.page" [pageSize]="resultsPerPage" (pageChange)="goTo($event.value, false)"
|
||||
[totalResults]="openaireSearchUtils.totalResults">
|
||||
</no-load-paging>
|
||||
<div class="uk-grid uk-child-width-1-1 uk-margin-medium-top uk-margin-bottom" uk-grid>
|
||||
<div *ngFor="let result of openaireProjects">
|
||||
<div *ngFor="let result of openaireProjects; let i = index">
|
||||
<div class="uk-card uk-card-default">
|
||||
<div class="uk-card-body">
|
||||
<result-preview [properties]="properties" [showOrganizations]="true"
|
||||
|
@ -99,6 +110,10 @@
|
|||
</div>
|
||||
<div class="uk-card-footer uk-padding-remove-vertical">
|
||||
<div class="uk-grid uk-grid-small uk-flex-nowrap uk-grid-divider uk-flex-right" uk-grid>
|
||||
<div class="uk-flex uk-flex-middle">
|
||||
<input [id]="result.id" class="uk-checkbox" type="checkbox" title="Select"
|
||||
value="{{selectedIndexes.indexOf(i) != -1}}" [ngModel]="selectedIndexes.indexOf(i)!=-1" (click)="toggleSelected(i)">
|
||||
</div>
|
||||
<div *ngIf="!result['isPart']">
|
||||
<div class="uk-padding-small uk-padding-remove-horizontal">
|
||||
<a (click)="addProject(result)" class="uk-button uk-button-link uk-flex uk-flex-middle">
|
||||
|
|
|
@ -41,6 +41,7 @@ export class AddProjectsComponent implements OnInit {
|
|||
@Output() communityProjectsChanged = new EventEmitter();
|
||||
// @Input() communityProjects = [];
|
||||
public openaireProjects = [];
|
||||
public selectedIndexes = [];
|
||||
public queryParameters: string = "";
|
||||
|
||||
// public pagingLimit: number = properties.pagingLimit;
|
||||
|
@ -351,4 +352,48 @@ export class AddProjectsComponent implements OnInit {
|
|||
this.buildQueryParameters();
|
||||
this.goTo(1);
|
||||
}
|
||||
public toggleSelected(index){
|
||||
if (this.selectedIndexes.indexOf(index) != -1){
|
||||
this.selectedIndexes.splice(this.selectedIndexes.indexOf(index), 1);
|
||||
}else{
|
||||
this.selectedIndexes.push(index);
|
||||
}
|
||||
}
|
||||
public addAll(){
|
||||
let projectList = [];
|
||||
for(let index of this.selectedIndexes){
|
||||
projectList.push(this.openaireProjects[index]);
|
||||
}
|
||||
this.subscriptions.push(this._manageCommunityProjectsService.addProjectList(this.properties, this.community.communityId, projectList).subscribe(
|
||||
data => {
|
||||
// this.communityProjects.push(data);
|
||||
this._clearCacheService.purgeBrowserCache(this.openaireEntities.PROJECT+" added", this.community.communityId);
|
||||
UIkit.notification(this.openaireEntities.PROJECT+' successfully added!', {
|
||||
status: 'success',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
for(let index of this.selectedIndexes){
|
||||
this.openaireProjects[index]["isPart"] = true;
|
||||
|
||||
}
|
||||
this.selectedIndexes = [];
|
||||
this.communityProjectsChanged.emit({
|
||||
list: projectList,
|
||||
});
|
||||
},
|
||||
err => {
|
||||
this.handleError('An error has been occurred. Try again later!');
|
||||
console.error(err.status);
|
||||
}
|
||||
));
|
||||
}
|
||||
public selectAll(){
|
||||
if(this.selectedIndexes.length < this.openaireProjects.length) {
|
||||
this.selectedIndexes = Array.from(Array(10).keys());
|
||||
}else{
|
||||
this.selectedIndexes = [];
|
||||
}
|
||||
console.log(this.selectedIndexes)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,28 +18,22 @@ export class ManageCommunityProjectsService {
|
|||
}
|
||||
|
||||
addProject(properties:EnvProperties, pid: string, project: any) {
|
||||
//let headers = new Headers({'Content-Type': 'application/json'});
|
||||
//let options = new RequestOptions({headers: headers});
|
||||
|
||||
let headers = new HttpHeaders({'Content-Type': 'application/json'});
|
||||
|
||||
let url = properties.communityAPI+pid+"/projects";
|
||||
|
||||
let communityProject = this.convertSearchProjectToCommunityProject(project, pid);
|
||||
let testProject: any = {
|
||||
"acronym": "test",
|
||||
"communityId": "egi",
|
||||
"funder": "test",
|
||||
"grantId": "test",
|
||||
"name": "test",
|
||||
"openaireId": "test"
|
||||
};
|
||||
|
||||
return this.http.post<any>(url, JSON.stringify(communityProject), {headers: headers});
|
||||
//return this.http.post(url, JSON.stringify(communityProject), options)
|
||||
//.map(res => <any> res.json())
|
||||
let communityProject = this.convertSearchProjectToCommunityProject(project, pid);
|
||||
return this.http.post<any>(url, JSON.stringify(communityProject), {headers: headers});
|
||||
}
|
||||
|
||||
addProjectList(properties:EnvProperties, pid: string, projects: any[]) {
|
||||
let headers = new HttpHeaders({'Content-Type': 'application/json'});
|
||||
let url = properties.communityAPI+pid+"/projectList";
|
||||
let communityProjects = [];
|
||||
for(let project of projects) {
|
||||
communityProjects.push(this.convertSearchProjectToCommunityProject(project, pid));
|
||||
}
|
||||
return this.http.post<any>(url, JSON.stringify(communityProjects), {headers: headers});
|
||||
}
|
||||
|
||||
convertSearchProjectToCommunityProject(project: any, community: string) : any {
|
||||
let communityProject = {
|
||||
"acronym": "",
|
||||
|
|
Loading…
Reference in New Issue