add subscribe functionality and component | fix the community id in app component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@51050 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
0e29902938
commit
a7df9c7826
|
@ -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: []
|
||||
}
|
||||
];
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
{{item.shortTitle}}</a></h3>
|
||||
</div>
|
||||
<p *ngIf="item.description != null" >{{item.description}}</p>
|
||||
<a class="uk-button uk-button-primary"> Subscribe</a>
|
||||
<subscribe [communityId]="item.communityId"></subscribe>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
<div class="uk-container uk-margin-bottom">
|
||||
|
||||
<article class="uk-article ">
|
||||
<a class="uk-button uk-button-primary uk-align-right"> Subscribe</a>
|
||||
|
||||
<subscribe *ngIf="communityId != null" [communityId]="communityId" class=" uk-align-right"></subscribe>
|
||||
<div *ngIf="communityId != null && community != null">
|
||||
<blockquote>
|
||||
<div *ngIf="community.title != null">
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: `
|
||||
|
||||
<div *ngIf="subscribed != null">
|
||||
<a *ngIf="!subscribed" class="uk-button uk-button-primary" (click)="subscribe()"> Subscribe</a>
|
||||
<a *ngIf="subscribed" class="uk-button uk-button-primary" (click)="unsubscribe()"> Unsubscribe</a>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 { }
|
|
@ -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 => <any> 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 => ((<any>res =="")?{}:<any> 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 => <any> 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 => <any> 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue