diff --git a/src/app/pages/projects/remove-projects.component.html b/src/app/pages/projects/remove-projects.component.html index fc4a4b8..59af0c5 100644 --- a/src/app/pages/projects/remove-projects.component.html +++ b/src/app/pages/projects/remove-projects.component.html @@ -28,31 +28,32 @@ [totalResults]="communitySearchUtils.totalResults">
- - +
{ this.page = 1; - this._getCommunityProjects(this.page, this.filterForm.get('keyword').value,null ); + this._getCommunityProjects(this.page, this.filterForm.get('keyword').value,(this.filterForm.get("funder").value? this.filterForm.get("funder").value.id:null), + this.filterForm.get("sort").value.sort ); })); -/* - this.subscriptions.push(this.filterForm.get('funder').valueChanges.subscribe(value => { - this.page = 1; - this._getCommunityProjects(1, this.searchText.toString(),this.fundersCtrl.getRawValue() ); - - }));*/ -/* - this.subscriptions.push(this.filterForm.get('sort').valueChanges.subscribe(value => { this.page = 1; - this.sort(); + this._getCommunityProjects(this.page, this.filterForm.get('keyword').value, this.filterForm.get("funder").value? this.filterForm.get("funder").value.id:null, this.filterForm.get("sort").value.sort ); })); -*/ this.subscriptions.push(this.communityService.getCommunityAsObservable().subscribe(community => { if (community) { @@ -115,6 +102,7 @@ export class RemoveProjectsComponent implements OnInit { + this.community.communityId + ".openaire.eu" + this.properties.searchLinkToProject.split("?")[0]; this.keyword = ''; + this._getCommunityFunders(); this._getCommunityProjects(1,this.keyword, null); } })); @@ -139,16 +127,9 @@ export class RemoveProjectsComponent implements OnInit { public confirmedDeleteProject(data: any) { this.subscriptions.push(this._manageCommunityProjectsService.removeProject(this.properties, this.community.communityId, this.selectedCommunityProject.openaireId).subscribe( data => { - // let index = this.communityProjects.indexOf(this.selectedCommunityProject); - // this.communityProjects.splice(index, 1); - // this.applyFilters(); + this._clearCacheService.purgeBrowserCache(this.openaireEntiites.PROJECT+" removed", this.community.communityId); NotificationHandler.rise(OpenaireEntities.PROJECT+' successfully removed!'); - // this.communityProjectsChanged.emit({ - // value: this.communityProjects, - // }); - // this.communitySearchUtils.totalResults--; - // this.communitySearchUtils.page = 1; this._getCommunityProjects(this.communitySearchUtils.page, this.keyword,null); }, @@ -188,11 +169,11 @@ export class RemoveProjectsComponent implements OnInit { public getCommunityProjects() { this._getCommunityProjects(this.communitySearchUtils.page, this.keyword,null ); } - public _getCommunityProjects(page, keyword, funder) { + public _getCommunityProjects(page, keyword, funder, orderBy = "name" ) { this.communitySearchUtils.status = this.errorCodes.LOADING; this.communitySearchUtils.page = page; this.communitySearchUtils.keyword = keyword; - this.subscriptions.push(this._searchCommunityProjectsService.searchProjectsWithPaging(this.properties, this.community.communityId, this.communitySearchUtils.page, this.resultsPerPage, this.communitySearchUtils.keyword, funder).subscribe( + this.subscriptions.push(this._searchCommunityProjectsService.searchProjectsWithPaging(this.properties, this.community.communityId, this.communitySearchUtils.page, this.resultsPerPage, this.communitySearchUtils.keyword, funder, orderBy).subscribe( data => { this.previewCommunityProjects = data.content; this.communitySearchUtils.totalResults = data.totalElements; @@ -213,23 +194,21 @@ export class RemoveProjectsComponent implements OnInit { } else { this.communitySearchUtils.status = this.errorCodes.NOT_AVAILABLE; } - this.loading = false; } )); } - - public createFunderFilter(): void { - let funders: Set = new Set(); - this.allOptions = []; - let i; - /* for (i = 0; i < this.communityProjects.length; i++) { - let funder = this.communityProjects[i].funder; - if (funder && !funders.has(funder)) { - funders.add(funder); - this.allOptions.push({label: funder, value: {id: funder, label: funder}}); + public _getCommunityFunders() { + this.subscriptions.push(this._searchCommunityProjectsService.getProjectFunders(this.properties, this.community.communityId).subscribe( + data => { + for (let funder of data) { + this.allFunderOptions.push({label: funder, value: {id: funder, label: funder}}); + } + this.previewFunderOptions =[...this.allFunderOptions]; + }, + err => { } - }*/ + )); } public updatePage($event) { @@ -242,67 +221,6 @@ export class RemoveProjectsComponent implements OnInit { this.addProjects.emit(); } - public applyFilters() { - /*this.previewCommunityProjects = this.communityProjects.filter(project => { - return (this.filterCommunityProjectByKeyword(project) && this.filterCommunityProjectByFunder(project)); - }); - // check paging here!!! - if (this.previewCommunityProjects.slice((this.page - 1) * this.resultsPerPage, this.page * this.resultsPerPage).length == 0) { - this.page = 1; - } - - this.sort();*/ - this._getCommunityProjects(1, this.searchText.toString(),this.fundersCtrl.getRawValue() ); - } -/* - - public filterCommunityProjectByKeyword(project): boolean { - return this.searchText.toString() === '' - || ((project.name + " " + project.acronym + " " + project.grantId + " " + project.funder)).match(this.searchText) != null; - } - - public filterCommunityProjectByFunder(project): boolean { - if (this.fundersCtrl.getRawValue().length == 0) { - return true; - } - for (let funder of this.fundersCtrl.getRawValue()) { - if (project.funder.toLowerCase().indexOf(funder.label.toLowerCase()) != -1) { - return true; - } - } - return false; - } -*/ - -/* - private sort() { - let sortOption: { sort: string, descending: boolean } = this.filterForm.get('sort').value; - - this.previewCommunityProjects.sort((left, right): number => { - if (sortOption.sort == "title") { - if ((left.name + left.acronym) > (right.name + right.acronym)) { - return sortOption.descending ? -1 : 1; - } else if ((left.name + left.acronym) < (right.name + right.acronym)) { - return sortOption.descending ? 1 : -1; - } - } else if (sortOption.sort == "grant") { - if (left.grantId > right.grantId) { - return sortOption.descending ? -1 : 1; - } else if (left.grantId < right.grantId) { - return sortOption.descending ? 1 : -1; - } - } else if (sortOption.sort == "funder") { - if (left.funder > right.funder) { - return sortOption.descending ? -1 : 1; - } else if (left.funder < right.funder) { - return sortOption.descending ? 1 : -1; - } - } - - return 0; - }); - } -*/ public onSearchClose() { this.communitySearchUtils.keyword = this.filterForm.get('keyword').value; @@ -317,23 +235,23 @@ export class RemoveProjectsComponent implements OnInit { NotificationHandler.rise(message, 'danger'); } - select(value: string, event, dropdownFilter: DropdownFilterComponent) { + select(option, event, dropdownFilter: DropdownFilterComponent) { + console.log(option) if(event.target instanceof HTMLInputElement) { dropdownFilter.closeDropdown(); - if(event.target.checked && !this.selectedFunders.find(entity => value === entity)) { - this.selectedFunders.push(value); - this.fundersCtrl.setControl(this.fundersCtrl.value.length, this._fb.control(value)); + if(event.target.checked) { + this.filterForm.get("funder").setValue(option.value); + this._getCommunityProjects(1, this.filterForm.get('keyword').value, this.filterForm.get('funder').value.id ); + this.previewFunderOptions =[option]; } else if(!event.target.checked) { - let index = this.selectedFunders.indexOf(value); - if(index !== -1) { - this.selectedFunders.splice(index, 1); - this.fundersCtrl.removeAt(index); - } + this.filterForm.get("funder").setValue(null); + this._getCommunityProjects(1, this.filterForm.get('keyword').value,null); + this.previewFunderOptions =[...this.allFunderOptions]; } } } isSelected(value: string) { - return this.filterForm && this.filterForm.get('funder').value.find(funder => funder === value) + return this.filterForm && this.filterForm.get('funder').value && this.filterForm.get('funder').value.id === value; } }