[develop | DONE | ADDED ] bulk removal of projects, update page if all projects of the page are removed,
This commit is contained in:
parent
597d409290
commit
82ade5e137
|
@ -283,6 +283,7 @@ export class AddProjectsComponent implements OnInit {
|
|||
goTo(page: number = 1, refineQuery: boolean = true) {
|
||||
this.openaireSearchUtils.page = page;
|
||||
this.openaireSearchUtils.status = this.errorCodes.LOADING;
|
||||
this.selectedIndexes = [];
|
||||
if(refineQuery) {
|
||||
this.openaireSearchUtils.refineStatus = this.errorCodes.LOADING;
|
||||
this.getFunders();
|
||||
|
@ -390,10 +391,9 @@ export class AddProjectsComponent implements OnInit {
|
|||
}
|
||||
public selectAll(){
|
||||
if(this.selectedIndexes.length < this.openaireProjects.length) {
|
||||
this.selectedIndexes = Array.from(Array(10).keys());
|
||||
this.selectedIndexes = Array.from(Array(this.openaireProjects.length).keys());
|
||||
}else{
|
||||
this.selectedIndexes = [];
|
||||
}
|
||||
console.log(this.selectedIndexes)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,18 @@
|
|||
</div>
|
||||
</div>
|
||||
<div inner>
|
||||
|
||||
<div *ngIf="communitySearchUtils.totalResults > 0">
|
||||
<label>
|
||||
<input id="checkAll" type="checkbox" (click)="selectAll()" class="uk-checkbox" title="Select all"
|
||||
[ngModel]="selectedIndexes.length == previewCommunityProjects.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)="promtToRemoveProjects()" >
|
||||
Remove ({{selectedIndexes.length}})
|
||||
</button>
|
||||
<hr class="uk-margin-remove-top">
|
||||
</div>
|
||||
<div class="uk-margin-top">
|
||||
<results-and-pages [type]="openaireEntiites.PROJECTS | lowercase" [page]="communitySearchUtils.page" [pageSize]="resultsPerPage"
|
||||
[totalResults]="communitySearchUtils.totalResults"></results-and-pages>
|
||||
|
@ -109,6 +121,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]="item.id" class="uk-checkbox" type="checkbox" title="Select"
|
||||
value="{{selectedIndexes.indexOf(i) != -1}}" [ngModel]="selectedIndexes.indexOf(i)!=-1" (click)="toggleSelected(i)">
|
||||
</div>
|
||||
<div>
|
||||
<div class="uk-padding-small uk-padding-remove-horizontal">
|
||||
<button class="uk-button uk-button-link uk-flex uk-flex-middle"
|
||||
|
|
|
@ -21,6 +21,7 @@ import {NotificationHandler} from "../../openaireLibrary/utils/notification-hand
|
|||
import {ClearCacheService} from "../../openaireLibrary/services/clear-cache.service";
|
||||
import {debounceTime, distinctUntilChanged} from "rxjs/operators";
|
||||
import {IndexInfoService} from "../../openaireLibrary/utils/indexInfo.service";
|
||||
declare var UIkit;
|
||||
|
||||
@Component({
|
||||
selector: 'remove-projects',
|
||||
|
@ -65,6 +66,9 @@ export class RemoveProjectsComponent implements OnInit {
|
|||
|
||||
public openaireEntiites = OpenaireEntities;
|
||||
lastDBLoadDate = null;
|
||||
public selectedIndexes = [];
|
||||
openaireEntities = OpenaireEntities;
|
||||
|
||||
constructor(private route: ActivatedRoute, private _router: Router,
|
||||
private _fb: UntypedFormBuilder,
|
||||
private communityService: CommunityService,
|
||||
|
@ -129,11 +133,12 @@ export class RemoveProjectsComponent implements OnInit {
|
|||
}
|
||||
|
||||
public confirmedDeleteProject(data: any) {
|
||||
if(this.selectedCommunityProject) {
|
||||
this.subscriptions.push(this._manageCommunityProjectsService.removeProject(this.properties, this.community.communityId, this.selectedCommunityProject.openaireId).subscribe(
|
||||
data => {
|
||||
this._clearCacheService.purgeBrowserCache(this.openaireEntiites.PROJECT+" removed", this.community.communityId);
|
||||
NotificationHandler.rise(OpenaireEntities.PROJECT+' successfully removed!');
|
||||
this._getCommunityProjects(this.communitySearchUtils.page, this.keyword,null);
|
||||
this._clearCacheService.purgeBrowserCache(this.openaireEntiites.PROJECT + " removed", this.community.communityId);
|
||||
NotificationHandler.rise(OpenaireEntities.PROJECT + ' successfully removed!');
|
||||
this._getCommunityProjects(this.previewCommunityProjects.length == 1 && (this.communitySearchUtils.page - 1) >= 0 ? (this.communitySearchUtils.page -1 ): this.communitySearchUtils.page, this.keyword, null);
|
||||
|
||||
},
|
||||
err => {
|
||||
|
@ -141,8 +146,24 @@ export class RemoveProjectsComponent implements OnInit {
|
|||
console.error(err);
|
||||
}
|
||||
));
|
||||
}else if(this.selectedIndexes.length > 0){
|
||||
this.removeAll();
|
||||
}
|
||||
}
|
||||
public promtToRemoveProjects() {
|
||||
this.selectedCommunityProject = null;
|
||||
this.alertModalDeleteCommunity.cancelButton = true;
|
||||
this.alertModalDeleteCommunity.okButton = true;
|
||||
this.alertModalDeleteCommunity.alertTitle = "Remove "+OpenaireEntities.PROJECTS;
|
||||
this.alertModalDeleteCommunity.message = "";
|
||||
let title = this.selectedIndexes.length + " " + OpenaireEntities.PROJECTS;
|
||||
if (title) {
|
||||
this.alertModalDeleteCommunity.message += " <b>" + title + "</b> ";
|
||||
}
|
||||
this.alertModalDeleteCommunity.message += " will be removed from your "+OpenaireEntities.COMMUNITY.toLowerCase()+". Are you sure?";
|
||||
this.alertModalDeleteCommunity.okButtonText = "Yes";
|
||||
this.alertModalDeleteCommunity.open();
|
||||
}
|
||||
|
||||
public removeProject(communityProject: any) {
|
||||
this.selectedCommunityProject = communityProject;
|
||||
this.alertModalDeleteCommunity.cancelButton = true;
|
||||
|
@ -176,6 +197,7 @@ export class RemoveProjectsComponent implements OnInit {
|
|||
this.communitySearchUtils.status = this.errorCodes.LOADING;
|
||||
this.communitySearchUtils.page = page;
|
||||
this.communitySearchUtils.keyword = keyword;
|
||||
this.communitySearchUtils.totalResults = 0;
|
||||
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;
|
||||
|
@ -218,6 +240,7 @@ export class RemoveProjectsComponent implements OnInit {
|
|||
HelperFunctions.scroll();
|
||||
this.page = $event.value;
|
||||
this._getCommunityProjects(this.page, this.filterForm.get('keyword').value, null);
|
||||
this.selectedIndexes = [];
|
||||
}
|
||||
|
||||
addNew() {
|
||||
|
@ -258,5 +281,41 @@ export class RemoveProjectsComponent implements OnInit {
|
|||
return this.filterForm && this.filterForm.get('funder').value && this.filterForm.get('funder').value.id === value;
|
||||
}
|
||||
|
||||
|
||||
public selectAll(){
|
||||
if(this.selectedIndexes.length < this.communitySearchUtils.totalResults) {
|
||||
this.selectedIndexes = Array.from(Array(this.previewCommunityProjects.length).keys());
|
||||
}else{
|
||||
this.selectedIndexes = [];
|
||||
}
|
||||
}
|
||||
public toggleSelected(index){
|
||||
if (this.selectedIndexes.indexOf(index) != -1){
|
||||
this.selectedIndexes.splice(this.selectedIndexes.indexOf(index), 1);
|
||||
}else{
|
||||
this.selectedIndexes.push(index);
|
||||
}
|
||||
}
|
||||
public removeAll(){
|
||||
let projectList = [];
|
||||
for(let index of this.selectedIndexes){
|
||||
projectList.push(this.previewCommunityProjects[index].openaireId);
|
||||
}
|
||||
this.subscriptions.push(this._manageCommunityProjectsService.removeProjectList(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.selectedIndexes.length + " " + this.openaireEntities.PROJECTS+' successfully removed!', {
|
||||
status: 'success',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
this._getCommunityProjects(projectList.length == this.previewCommunityProjects.length && (this.communitySearchUtils.page - 1) > 0 ? (this.communitySearchUtils.page -1 ): this.communitySearchUtils.page, this.keyword, null);
|
||||
this.selectedIndexes = [];
|
||||
},
|
||||
err => {
|
||||
this.handleError('An error has been occurred. Try again later!');
|
||||
console.error(err.status);
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,12 @@ export class ManageCommunityProjectsService {
|
|||
//return this.http.delete(url, options)
|
||||
return this.http.request('delete', url, { headers: headers})
|
||||
}
|
||||
removeProjectList(properties:EnvProperties, pid: string, projects: any[]) {
|
||||
let headers = new HttpHeaders({'Content-Type': 'application/json'});
|
||||
let url = properties.communityAPI+pid+"/projectList";
|
||||
|
||||
return this.http.delete<any>(url, { headers: headers, body: JSON.stringify(projects)});
|
||||
}
|
||||
addProject(properties:EnvProperties, pid: string, project: any) {
|
||||
let headers = new HttpHeaders({'Content-Type': 'application/json'});
|
||||
let url = properties.communityAPI+pid+"/projects";
|
||||
|
|
Loading…
Reference in New Issue