diff --git a/src/app/app.component.ts b/src/app/app.component.ts index c947c0e..4681a77 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -64,37 +64,36 @@ export class AppComponent { this.menuItems=[]; this._communityService.getCommunity(this.properties.communityAPI+((data['communityId'])?data['communityId']:data['community'])).subscribe ( community => { - this.community = community; - // this.params = {community: encodeURIComponent('"'+community.queryId+'"')}; - this.community = {id: data['communityId'], name: (this.community.title)?this.community.title:this.community.shortTitle, logoUrl:this.community.logoUrl}; + // this.community = community; + this.community = {id: community.communityId, name: (community.shortTitle)?community.shortTitle:community.title, logoUrl:community.logoUrl}; this.userMenuItems = [ new MenuItem("","My profile","","",false,[],[],{}), new MenuItem("","My claims","","/myclaims",false,[],["/myclaims"],{}), new MenuItem("","Manage all claims","","/claims",true,[],["/claims"],{}),] this.menuItems= [{ - rootItem: new MenuItem("dashboard","Dashboard","","/community",false,[],[],{communityId:this.community.id}), + rootItem: new MenuItem("dashboard","Dashboard","","/community",false,[],[],{communityId:community.communityId}), items: [] }, {rootItem: new MenuItem("search","Search","","",false,[],[],{}), - items: [new MenuItem("","Publications","","/search/find/publications",false,["publication"],["/search/find/publications"],{community: encodeURIComponent('"'+community.queryId+'"')}), - new MenuItem("","Research Data","","/search/find/datasets",false,["dataset"],["/search/find/datasets"],{community: encodeURIComponent('"'+community.queryId+'"')}), - new MenuItem("","Software","","/search/find/software",false,["software"],["/search/find/software"],{community: encodeURIComponent('"'+community.queryId+'"')}), - new MenuItem("","Projects","","/search/find/projects/",false,["project"],["/search/find/projects"],{communityId: this.community.id}), + items: [new MenuItem("","Publications","","/search/find/publications",false,["publication"],["/search/find/publications"],{community: encodeURIComponent('"'+community.queryId+'"'), communityId: community.communityId}), + new MenuItem("","Research Data","","/search/find/datasets",false,["dataset"],["/search/find/datasets"],{community: encodeURIComponent('"'+community.queryId+'"'), communityId: community.communityId}), + new MenuItem("","Software","","/search/find/software",false,["software"],["/search/find/software"],{community: encodeURIComponent('"'+community.queryId+'"'), communityId: community.communityId}), + new MenuItem("","Projects","","/search/find/projects/",false,["project"],["/search/find/projects"],{communityId: community.communityId}), // new MenuItem("","Content Providers","","/search/find/dataproviders",false,["datasource"],["/search/find/dataproviders"],{community: "%22egi%7C%7CEGI%20Federation%22"}), // new MenuItem("","Organizations","","/search/find/organizations/",false,["organization"],["/search/find/organizations"],{community: "%22egi%7C%7CEGI%20Federation%22"}), ]}, { - rootItem: new MenuItem("monitor","Monitor","","/statistics",false,[],["/statistics"],{communityId:this.community.id}), + rootItem: new MenuItem("monitor","Monitor","","/statistics",false,[],["/statistics"],{communityId:community.communityId}), items: [] }, { - rootItem: new MenuItem("share","Share","","",false,[],["/participate/deposit-publications","/participate/deposit-datasets"],{communityId:this.community.id}), - items: [new MenuItem("","Publications","","/participate/deposit-publications",false,["publication"],["/participate/deposit-publications"],{communityId:this.community.id}), - new MenuItem("","Research Data","","/participate/deposit-datasets",false,["dataset"],["/participate/deposit-datasets"],{communityId:this.community.id})] + rootItem: new MenuItem("share","Share","","",false,[],["/participate/deposit-publications","/participate/deposit-datasets"],{communityId:community.communityId}), + items: [new MenuItem("","Publications","","/participate/deposit-publications",false,["publication"],["/participate/deposit-publications"],{communityId:community.communityId}), + new MenuItem("","Research Data","","/participate/deposit-datasets",false,["dataset"],["/participate/deposit-datasets"],{communityId:community.communityId})] }, { - rootItem: new MenuItem("link","Link","","/participate/claim",false,[],["/participate/claim"],{community:"egi||EGI Federation"}), + rootItem: new MenuItem("link","Link","","/participate/claim",false,[],["/participate/claim"],{communityId:community.communityId}), items: [] } ]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 894284c..55aab58 100755 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,7 +23,6 @@ import { AppRoutingModule } from './app-routing.module'; import { CommunityService } from './community/community.service'; import { CommunitiesService } from './communities/communities.service'; - //import { LibSearchProjectsModule } from './searchPages/simple/searchProjects.module'; @NgModule({ diff --git a/src/app/communities/communities.component.html b/src/app/communities/communities.component.html index eef3d99..1e488ac 100644 --- a/src/app/communities/communities.component.html +++ b/src/app/communities/communities.component.html @@ -40,7 +40,7 @@ {{item.shortTitle}}

{{item.description}}

- Subscribe + diff --git a/src/app/communities/communities.module.ts b/src/app/communities/communities.module.ts index 980613b..aca5dfd 100644 --- a/src/app/communities/communities.module.ts +++ b/src/app/communities/communities.module.ts @@ -14,10 +14,12 @@ import {CommunitiesService} from './communities.service'; import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; import {Meta} from '../openaireLibrary/sharedComponents/metaService'; import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service'; +import {SubscribeModule} from '../utils/subscribe/subscribe.module'; + @NgModule({ imports: [ CommonModule, FormsModule, RouterModule, - CommunitiesRoutingModule + CommunitiesRoutingModule, SubscribeModule ], declarations: [ CommunitiesComponent diff --git a/src/app/community/community.component.html b/src/app/community/community.component.html index 5e04f8e..7c64b93 100644 --- a/src/app/community/community.component.html +++ b/src/app/community/community.component.html @@ -3,7 +3,8 @@
- Subscribe + +
diff --git a/src/app/community/community.module.ts b/src/app/community/community.module.ts index e44ac38..2bc425d 100644 --- a/src/app/community/community.module.ts +++ b/src/app/community/community.module.ts @@ -17,11 +17,12 @@ import {ConfigurationService} from '../openaireLibrary/utils/configuration/confi import {FreeGuard} from '../openaireLibrary/login/freeGuard.guard'; import {PreviousRouteRecorder} from '../openaireLibrary/utils/piwik/previousRouteRecorder.guard'; +import {SubscribeModule} from '../utils/subscribe/subscribe.module'; @NgModule({ imports: [ CommonModule, FormsModule, RouterModule, - CommunityRoutingModule + CommunityRoutingModule, SubscribeModule ], declarations: [ CommunityComponent, ResultsComponent diff --git a/src/app/utils/subscribe/subscribe.component.ts b/src/app/utils/subscribe/subscribe.component.ts new file mode 100644 index 0000000..1975d07 --- /dev/null +++ b/src/app/utils/subscribe/subscribe.component.ts @@ -0,0 +1,82 @@ +import { Component, Input } from '@angular/core'; +import { Location } from '@angular/common'; +import {ActivatedRoute} from '@angular/router'; +import { EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; + +import {SubscribeService} from './subscribe.service'; +import {Session} from '../../openaireLibrary/login/utils/helper.class'; +@Component({ + selector: 'subscribe', + template: ` + + + ` +}) + +export class SubscribeComponent { + // @Input() showSubscribe:boolean = true; + @Input() showNumbers:boolean; + @Input() communityId:string; + + + subscribed:boolean = null; + properties:EnvProperties; + constructor (private route: ActivatedRoute, + private _subscribeService: SubscribeService + ) { + } + + public ngOnInit() { + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + console.log("subscribe "+ this.communityId); + var email = Session.getUserEmail(); + if(email == null){ + this.subscribed = false; + }else{ + //this.properties.adminToolsAPIURL + this._subscribeService.isSubscribedToCommunity(this.communityId, email,this.properties.adminToolsAPIURL).subscribe ( + res => { + this.subscribed = res; + }); + } + }); + + } + + subscribe(){ + var email = Session.getUserEmail(); + if(email == null){ + this.subscribed = false; + }else{ + //this.properties.adminToolsAPIURL + this._subscribeService.subscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe ( + res => { + console.log(res); + if(!this.subscribed){ + this.subscribed = true; + } + }); + } + } + + unsubscribe(){ + var email = Session.getUserEmail(); + if(email == null){ + this.subscribed = false; + }else{ + //this.properties.adminToolsAPIURL + this._subscribeService.unSubscribeToCommunity(this.communityId, email,"http://scoobydoo.di.uoa.gr:8080/uoa-admin-tools/").subscribe ( + res => { + console.log(res); + if(this.subscribed){ + this.subscribed = false; + } + }); + } + } +} diff --git a/src/app/utils/subscribe/subscribe.module.ts b/src/app/utils/subscribe/subscribe.module.ts new file mode 100644 index 0000000..bf5bed0 --- /dev/null +++ b/src/app/utils/subscribe/subscribe.module.ts @@ -0,0 +1,22 @@ +import { NgModule} from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { RouterModule } from '@angular/router'; + +import { SubscribeService } from './subscribe.service'; +import {SubscribeComponent} from './subscribe.component'; + +@NgModule({ + imports: [ + CommonModule, RouterModule + ], + declarations: [ + SubscribeComponent + ], + providers:[ + SubscribeService + ], + exports: [ + SubscribeComponent + ] +}) +export class SubscribeModule { } diff --git a/src/app/utils/subscribe/subscribe.service.ts b/src/app/utils/subscribe/subscribe.service.ts new file mode 100644 index 0000000..75c7ee3 --- /dev/null +++ b/src/app/utils/subscribe/subscribe.service.ts @@ -0,0 +1,55 @@ +import { Injectable } from '@angular/core'; +import { Http, Response, Headers, RequestOptions } from '@angular/http'; +import { Observable } from 'rxjs/Rx'; +import {COOKIE} from "../../openaireLibrary/login/utils/helper.class" + + +@Injectable() +export class SubscribeService { + + constructor(private http:Http) { + } + getCommunitySubscribers(pid:string, url:string){ + return this.http.get(url+"/community/"+pid+"/subscribers") + .map(res => res.json()).do(res => {console.log(res)}).do(res => {console.log(res)}); + } + + isSubscribedToCommunity(pid:string, email:string, url:string){ + return this.http.get(url+"/community/"+pid+"/subscribers") + .map(res => ((res =="")?{}: res.json())) + + .map(res => { + if(res.subscribers && res.subscribers != null){ + + for(var i =0; i< res.subscribers.length; i++ ){ + if(res.subscribers[i]!=null && res.subscribers[i].email == email){ + return true; + } + } + } + return false; + + }).do(res => {console.log("Response is "+res)}); + } + subscribeToCommunity(pid:string, email:string, url:string){ + var subscriber = {"email":email}; + return this.http.post(url+"/community/"+pid+"/subscribers", JSON.stringify(subscriber), this.getAuthOptionsWithBody()) + .map(res => res.json()) + .do(res => {console.log("Response is "+res)}); + } + unSubscribeToCommunity(pid:string, email:string, url:string){ + + return this.http.post(url+"/community/"+pid+"/subscribers/delete", JSON.stringify([email]), this.getAuthOptionsWithBody()) + .map(res => res.json()) + .do(res => {console.log("Response is "+res)}); + } + + public getAuthOptionsWithBody():RequestOptions{ + let headers = new Headers(); + headers.append('Content-Type', 'application/json'); + headers.append('X-XSRF-TOKEN', COOKIE.getCookie(COOKIE.cookieName_id)); + let options = new RequestOptions({ headers: headers, withCredentials:true }); + return options; + } + +}