@@ -33,7 +45,7 @@ type Tab = 'all' | 'communities' | 'ris';
Research Communities
-
+
@@ -47,7 +59,7 @@ type Tab = 'all' | 'communities' | 'ris';
Research Initiatives
-
+
@@ -81,19 +93,44 @@ type Tab = 'all' | 'communities' | 'ris';
export class ManageCommunitiesComponent implements OnInit, OnDestroy {
public properties: EnvProperties = properties;
public communities: CommunityInfo[] = [];
+ public filteredCommunities: CommunityInfo[] = [];
public ris: CommunityInfo[] = [];
+ public filteredRis: CommunityInfo[] = [];
public loading: boolean;
public user: User;
public tab: Tab = "all";
private subscriptions: any[] = [];
+ public communitySearchUtils: SearchUtilsClass = new SearchUtilsClass();
+ public errorCodes: ErrorCodes;
+
+ // Search
+ @ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
+ filterForm: FormGroup;
+ // private searchText: RegExp = new RegExp('');
+ private searchText: string = '';
+ public keyword: string = '';
constructor(private route: ActivatedRoute,
+ private _fb: FormBuilder,
private communitiesService: CommunitiesService,
private title: Title,
private userManagementService: UserManagementService) {
+ this.errorCodes = new ErrorCodes();
+ this.communitySearchUtils.status = this.errorCodes.LOADING;
}
ngOnInit() {
+ this.communitySearchUtils.keyword = "";
+
+ this.filterForm = this._fb.group({
+ keyword: [''],
+ });
+
+ this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => {
+ this.searchText = value.toLowerCase();
+ this.applyFilters();
+ }));
+
this.loading = true;
this.title.setTitle('Administrator Dashboard | Manage Communities');
this.subscriptions.push(this.route.fragment.subscribe((fragment: Tab) => {
@@ -109,18 +146,22 @@ export class ManageCommunitiesComponent implements OnInit, OnDestroy {
this.subscriptions.push(this.communitiesService.getCommunities(this.properties, this.properties.communityAPI + 'communities').subscribe(
communities => {
this.communities = [];
+ this.filteredCommunities = [];
this.ris = [];
- console.log(communities);
+ this.filteredRis = [];
communities.forEach(community => {
if (Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || Session.isManager('community', community.communityId, this.user)) {
if (community.type === 'community') {
this.communities.push(community);
+ this.filteredCommunities.push(community);
} else {
this.ris.push(community);
+ this.filteredRis.push(community);
}
}
})
this.loading = false;
+ this.keyword = '';
}));
}
}));
@@ -151,5 +192,19 @@ export class ManageCommunitiesComponent implements OnInit, OnDestroy {
default:
return false;
}
+ }
+
+ public applyFilters() {
+ this.filteredCommunities = this.communities.filter(community => community.shortTitle.toLowerCase().includes(this.searchText) || community.title.toLowerCase().includes(this.searchText));
+ this.filteredRis = this.ris.filter(community => community.shortTitle.toLowerCase().includes(this.searchText) || community.title.toLowerCase().includes(this.searchText));
+ }
+
+ public onSearchClose() {
+ this.communitySearchUtils.keyword = this.filterForm.get('keyword').value;
+ }
+
+ public resetInput() {
+ this.communitySearchUtils.keyword = null;
+ this.searchInputComponent.reset()
}
}
diff --git a/src/app/pages/manage-communities/manage-communities.module.ts b/src/app/pages/manage-communities/manage-communities.module.ts
index db83fdd..bf73f92 100644
--- a/src/app/pages/manage-communities/manage-communities.module.ts
+++ b/src/app/pages/manage-communities/manage-communities.module.ts
@@ -12,10 +12,11 @@ import {IconsModule} from '../../openaireLibrary/utils/icons/icons.module';
import {IconsService} from '../../openaireLibrary/utils/icons/icons.service';
import {earth, group, lock} from '../../openaireLibrary/utils/icons/icons';
import {LogoUrlPipeModule} from "../../openaireLibrary/utils/pipes/logoUrlPipe.module";
+import {SearchInputModule} from '../../openaireLibrary/sharedComponents/search-input/search-input.module';
@NgModule({
imports: [
- CommonModule, ManageCommunitiesRoutingModule, RouterModule, PageContentModule, LoadingModule, UrlPrefixModule, IconsModule, LogoUrlPipeModule
+ CommonModule, ManageCommunitiesRoutingModule, RouterModule, PageContentModule, LoadingModule, UrlPrefixModule, IconsModule, LogoUrlPipeModule, SearchInputModule
],
declarations: [ManageCommunitiesComponent],
providers: [LoginGuard, CommunitiesService],