[Connect | Trunk]: Add regisrty property. Add new UM methods on subscribe and curators component.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@59233 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-08-06 20:02:46 +00:00
parent d71892ed9e
commit cafb672ae7
7 changed files with 221 additions and 147 deletions

View File

@ -150,18 +150,16 @@ export class AppComponent {
break;
}
if (this.user && com['status'] != "hidden") {
if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || Session.isManager('community', this.communityId, this.user)) {
this.managerOfCommunities = true;
} else if (com.managers.indexOf(this.user.email) != -1) {
this.managerOfCommunities = true;
}
}
if (communityId && communityId != "" && com.communityId == communityId) {
community = com;
let isCommunityManager: boolean = false;
if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || Session.isManager('community', this.communityId, this.user)) {
isCommunityManager = true;
} else if (this.user && com.managers.indexOf(this.user.email) != -1) {
isCommunityManager = true;

View File

@ -1,5 +1,5 @@
import {Component, Input} from '@angular/core';
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import {CuratorService} from "../openaireLibrary/connect/curators/curator.service";
import {Curator} from "../openaireLibrary/utils/entities/CuratorInfo";
import {ActivatedRoute, Router} from "@angular/router";
@ -15,11 +15,12 @@ import {Breadcrumb} from "../openaireLibrary/utils/breadcrumbs/breadcrumbs.compo
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
import {Subscription} from "rxjs";
import {properties} from "../../environments/environment";
import {UserRegistryService} from "../openaireLibrary/services/user-registry.service";
@Component({
selector: 'curators',
templateUrl: './curators.component.html'
})
export class CuratorsComponent {
@ -28,130 +29,156 @@ export class CuratorsComponent {
@Input() longView = true;
public downloadUrl = null;
public showLoading = true;
public curators: Curator[];
public curatorsLimit: number = 5;
public numberOfCurators: number = 5;
public showMore = [];
public maxCharacters = 500;
public properties: EnvProperties;
public pageContents = null;
public divContents = null;
public url: string = null;
public pageTitle: string = "Curators";
public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'About - curators'}];
subs: Subscription[] = [];
constructor (private route: ActivatedRoute,
private curatorsService: CuratorService,
private communityService: CommunityService,
private _router: Router,
private helper: HelperService,
private _meta: Meta,
private _title: Title,
private seoService: SEOService,
private _piwikService: PiwikService) {}
constructor(private route: ActivatedRoute,
private curatorsService: CuratorService,
private communityService: CommunityService,
private userRegistryService: UserRegistryService,
private _router: Router,
private helper: HelperService,
private _meta: Meta,
private _title: Title,
private seoService: SEOService,
private _piwikService: PiwikService) {
}
ngOnInit() {
this.showLoading = true;
this.properties = properties;
if(this.longView) {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subs.push(this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe());
}
this.url = this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url);
this.updateUrl(this.url);
this.updateTitle(this.pageTitle);
this.updateDescription("OpenAIRE - Connect, Community Gateway, research community");
this.showLoading = true;
this.properties = properties;
if (this.longView) {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.subs.push(this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe());
}
this.downloadUrl = this.properties.utilsService + '/download/';
if(!this.longView) {
this.url = this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url);
this.updateUrl(this.url);
this.updateTitle(this.pageTitle);
this.updateDescription("OpenAIRE - Connect, Community Gateway, research community");
}
this.downloadUrl = this.properties.utilsService + '/download/';
if (properties.environment !== 'development') {
if (!this.longView) {
let emails = this.managers.join();
this.subs.push(this.curatorsService.getCurators(this.properties, emails).subscribe(curators => {
this.curators = curators;
for(let i = 0; i < this.curators.length; i++) {
this.showMore[i]= false;
for (let i = 0; i < this.curators.length; i++) {
this.showMore[i] = false;
}
this.showLoading = false;
HelperFunctions.scroll();
}));
} else {
this.subs.push(this.route.queryParams.subscribe(data => {
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
if(!this.communityId) {
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
if (!this.communityId) {
this.communityId = data['communityId'];
}
//this.getDivContents();
this.getPageContents();
this.subs.push(this.communityService.getCommunityByState(this.properties,
this.properties.communityAPI + this.communityId).subscribe(community => {
this.managers = community.managers;
let emails = this.managers.join();
this.subs.push(this.curatorsService.getCurators(this.properties, emails).subscribe(curators => {
this.curators = curators;
for(let i = 0; i < this.curators.length; i++) {
this.showMore[i]= false;
}
this.showLoading = false;
HelperFunctions.scroll();
}));
this.managers = community.managers;
let emails = this.managers.join();
this.subs.push(this.curatorsService.getCurators(this.properties, emails).subscribe(curators => {
this.curators = curators;
for (let i = 0; i < this.curators.length; i++) {
this.showMore[i] = false;
}
this.showLoading = false;
HelperFunctions.scroll();
}));
}));
}));
}
} else {
this.subs.push(this.route.queryParams.subscribe(data => {
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
if (!this.communityId) {
this.communityId = data['communityId'];
}
if(this.longView) {
//this.getDivContents();
this.getPageContents();
}
this.subs.push(this.userRegistryService.getManagersEmail('community', this.communityId).subscribe(managers => {
let emails = managers.map(manager => manager.email).join();
this.subs.push(this.curatorsService.getCurators(this.properties, emails).subscribe(curators => {
this.curators = curators;
for (let i = 0; i < this.curators.length; i++) {
this.showMore[i] = false;
}
this.showLoading = false;
HelperFunctions.scroll();
}));
}));
}));
}
}
ngOnDestroy() {
for (let sub of this.subs) {
sub.unsubscribe();
}
}
private getPageContents() {
this.subs.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
this.pageContents = contents;
}));
}
private getDivContents() {
this.subs.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
this.divContents = contents;
}));
}
public toggle(index: number) {
this.showMore[index] = !this.showMore[index];
}
_format(name: string){
if(name) {
_format(name: string) {
if (name) {
return (((name).length > this.maxCharacters) ? (name.substring(0, (this.maxCharacters - ('...').length)) + '...') : name);
} else {
return null;
}
}
public urlPrefix(url: string): string {
return StringUtils.urlPrefix(url);
}
private updateDescription(description: string) {
this._meta.updateTag({content: description}, "name='description'");
this._meta.updateTag({content: description}, "property='og:description'");
}
private updateTitle(title: string) {
var _title = ((title.length > 50) ? title.substring(0, 50) : title);
this._title.setTitle(_title);
this._meta.updateTag({content: _title}, "property='og:title'");
}
private updateUrl(url: string) {
this._meta.updateTag({content: url}, "property='og:url'");
}

View File

@ -14,6 +14,7 @@ import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.cla
import {UserManagementService} from "../../openaireLibrary/services/user-management.service";
import {Subscription} from "rxjs";
import {properties} from "../../../environments/environment";
import {UserRegistryService} from "../../openaireLibrary/services/user-registry.service";
declare var UIkit: any;
@ -26,22 +27,26 @@ declare var UIkit: any;
<a class="uk-alert-close" uk-close></a>
<p>Please login first to subscribe</p>
</div>
<button *ngIf="!subscribed" [class]="'uk-button portal-button uk-button-small uk-width-1-1 ' + (loading ? ' uk-disabled' : '')"
<button *ngIf="!subscribed"
[class]="'uk-button portal-button uk-button-small uk-width-1-1 ' + (loading ? ' uk-disabled' : '')"
(click)="subscribe()">
<span class="uk-icon uk-flex uk-flex-middle">
<svg height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"></path>
<path
d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"></path>
</svg>
<span class="space">Subscribe</span>
</span>
</button>
<button *ngIf="subscribed" [class]="'subscribed-button uk-button uk-button-small uk-width-1-1 ' + (loading ? ' uk-disabled' : '')"
<button *ngIf="subscribed"
[class]="'subscribed-button uk-button uk-button-small uk-width-1-1 ' + (loading ? ' uk-disabled' : '')"
(click)="confirmOpen()">
<span class="uk-icon uk-flex uk-flex-middle">
<svg height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"></path>
<path
d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"></path>
</svg>
<span class="space">Subscribed</span>
</span>
@ -62,10 +67,10 @@ export class SubscribeComponent {
@Input() communityId: string;
@Input() showTemplate: boolean = true;
@Output() subscribeEvent = new EventEmitter();
public community = null;
public emailToInformManagers: Email;
loading: boolean = false;
subscribed: boolean = null;
@Input() properties: EnvProperties;
@ -74,30 +79,28 @@ export class SubscribeComponent {
showLoginAlert: Boolean = false;
@ViewChild(AlertModal) alert;
private user: User;
subs: Subscription[] = [];
constructor(private route: ActivatedRoute,
private _subscribeService: SubscribeService,
private _emailService: EmailService,
private _communityService: CommunityService,
private router: Router,
private userManagementService: UserManagementService
) {}
private userManagementService: UserManagementService,
private userRegistryService: UserRegistryService
) {
}
public ngOnInit() {
if(!this.properties) {
if (!this.properties) {
this.properties = properties;
}
if(!this.showNumbers) {
if (!this.showNumbers) {
this.subs.push(this.userManagementService.getUserInfo().subscribe(
user => {
this.user = user;
this.init();
},
error => {},
() => {
this.init();
}
));
} else {
@ -105,26 +108,35 @@ export class SubscribeComponent {
}
//this.init();
}
public ngOnDestroy() {
for (let sub of this.subs) {
sub.unsubscribe();
}
}
private isSubscribed() {
this.subs.push(this._subscribeService.isSubscribed.subscribe(
res => {
this.subscribed = res;
if (this.subscribed) {
this.subscribeEvent.emit({
value: "ok"
});
this.subscribed = Session.isSubscriber('community', this.communityId, this.user);
if (!this.subscribed) {
this.subs.push(this._subscribeService.isSubscribed.subscribe(
res => {
this.subscribed = res;
if (this.subscribed) {
this.subscribeEvent.emit({
value: "ok"
});
}
}
));
} else {
if (this.subscribed) {
this.subscribeEvent.emit({
value: "ok"
});
}
));
}
}
private init() {
if (!this.showNumbers) {
let email = (this.user) ? this.user.email : null;
@ -132,40 +144,39 @@ export class SubscribeComponent {
this.subscribed = false;
} else {
if (this.communityId) {
// this._subscribeService.isSubscribedToCommunity(this.properties, this.communityId).subscribe(
// res => {
// this.subscribed = res;
// if (this.subscribed) {
// this.subscribeEvent.emit({
// value: "ok"
// });
// }
// },
// error => {
// this.handleError("Error getting response if email: " + email + " is subscribed to community with id: " + this.communityId, error);
// });
this._subscribeService.initIsSubscribedToCommunity(this.properties, this.communityId);
this.isSubscribed();
}
}
} else {
if (this.communityId) {
this.subs.push(this._subscribeService.getNumberOfCommunitySubscribers(this.properties, this.communityId).subscribe(
res => {
this.subscribers = (res && res.value) ? res.value : 0;//(res && res.subscribers && res.subscribers.length) ? res.subscribers.length : 0;
this.countSubscribersEvent.emit({
value: this.subscribers
});
},
error => {
this.handleError("Error getting community subscribers for community with id: " + this.communityId, error);
}));
if (properties.environment !== 'development') {
this.subs.push(this._subscribeService.getNumberOfCommunitySubscribers(this.properties, this.communityId).subscribe(
res => {
this.subscribers = (res && res.value) ? res.value : 0;//(res && res.subscribers && res.subscribers.length) ? res.subscribers.length : 0;
this.countSubscribersEvent.emit({
value: this.subscribers
});
},
error => {
this.handleError("Error getting community subscribers for community with id: " + this.communityId, error);
}));
} else {
this.subs.push(this.userRegistryService.getSubscribersCount('community', this.communityId).subscribe(res => {
this.subscribers = (res && res.response) ? res.response : 0;
this.countSubscribersEvent.emit({
value: this.subscribers
});
},
error => {
this.handleError("Error getting community subscribers for community with id: " + this.communityId, error);
}));
}
}
}
if (this.communityId) {
this.emailToInformManagers = {body: "", subject: "", recipients: []};
this.subs.push(this._communityService.getCommunityByState(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => {
this.community = community;
@ -177,7 +188,26 @@ export class SubscribeComponent {
));
}
}
private successfulSubscribe(email) {
if (!this.subscribed) {
this.subscribed = true;
this.subscribeEvent.emit({
value: "ok"
});
this.subs.push(this._emailService.notifyForNewManagers(this.properties, this.communityId, Composer.composeEmailToInformManagers(this.community.title, this.communityId, this.community.managers,
email, this.properties.adminPortalURL)).subscribe(
res => {
//console.log("The email has been sent successfully!")
},
error => {
//console.log(error)
this.handleError("Error notifying managers about new subscribers for community with id: " + this.communityId, error);
}
));
}
}
subscribe() {
var email = (this.user) ? this.user.email : null;
if (email == null) {
@ -192,6 +222,23 @@ export class SubscribeComponent {
} else {
this.loading = true;
this.showLoginAlert = false;
if(properties.environment === 'development') {
this.subs.push(this.userRegistryService.subscribeTo('community', this.communityId).subscribe(res => {
this.userManagementService.updateUserInfo();
this.loading = false;
this.successfulSubscribe(email);
},error => {
this.loading = false;
UIkit.notification({
message: '<strong>An error occurred. Please try again!<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
});
//console.log(error)
this.handleError("Error subscribing email: " + email + " from community with id: " + this.communityId, error);
}));
}
this.subs.push(this._subscribeService.subscribeToCommunity(this.properties, this.communityId).subscribe(
res => {
this.loading = false;
@ -200,28 +247,13 @@ export class SubscribeComponent {
value: "error"
});
UIkit.notification({
message: '<strong>An error occured. Please try again!<strong>',
message: '<strong>An error occurred. Please try again!<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
});
} else {
if (!this.subscribed) {
this.subscribed = true;
this.subscribeEvent.emit({
value: "ok"
});
this.subs.push(this._emailService.notifyForNewManagers(this.properties, this.communityId, Composer.composeEmailToInformManagers(this.community.title, this.communityId, this.community.managers,
email, this.properties.adminPortalURL)).subscribe(
res => {
//console.log("The email has been sent successfully!")
},
error => {
//console.log(error)
this.handleError("Error notifying managers about new subscribers for community with id: " + this.communityId, error);
}
));
}
this.successfulSubscribe(email);
}
},
error => {
@ -230,7 +262,7 @@ export class SubscribeComponent {
value: "error"
});
UIkit.notification({
message: '<strong>An error occured. Please try again!<strong>',
message: '<strong>An error occurred. Please try again!<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
@ -240,20 +272,36 @@ export class SubscribeComponent {
}));
}
}
unsubscribe() {
var email = (this.user) ? this.user.email : null;
if (email == null) {
this.subscribed = false;
} else {
this.loading = true;
//this.properties.adminToolsAPIURL
if(properties.environment === 'development') {
this.subs.push(this.userRegistryService.unsubscribeFrom('community', this.communityId).subscribe(res => {
this.userManagementService.updateUserInfo();
this.loading = false;
this.subscribed = false;
},error => {
this.loading = false;
UIkit.notification({
message: '<strong>An error occurred. Please try again!<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
});
//console.log(error)
this.handleError("Error unsubscribing email: " + email + " from community with id: " + this.communityId, error);
}));
}
this.subs.push(this._subscribeService.unSubscribeToCommunity(this.properties, this.communityId).subscribe(
res => {
this.loading = false;
if (res.status && res.status != 200) {
UIkit.notification({
message: '<strong>An error occured. Please try again!<strong>',
message: '<strong>An error occurred. Please try again!<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
@ -268,7 +316,7 @@ export class SubscribeComponent {
error => {
this.loading = false;
UIkit.notification({
message: '<strong>An error occured. Please try again!<strong>',
message: '<strong>An error occurred. Please try again!<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
@ -278,9 +326,9 @@ export class SubscribeComponent {
}));
}
}
confirmOpen() {
this.alert.cancelButton = true;
this.alert.okButton = true;
//this.alert.alertTitle = "Unsubscribe community ";
@ -290,11 +338,11 @@ export class SubscribeComponent {
this.alert.cancelButtonText = "CANCEL";
this.alert.open();
}
confirmClose(data) {
this.unsubscribe();
}
private handleError(message: string, error) {
console.error("Subscribe (component): " + message, error);
}

View File

@ -51,7 +51,7 @@ export let properties: EnvProperties = {
loginUrl: "https://beta.services.openaire.eu/connect-user-management/openid_connect_login",
userInfoUrl: "https://beta.services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=",
registryUrl: 'https://beta.services.openaire.eu/uoa-user-management/api/registry/',
logoutUrl: "https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",
cookieDomain: ".openaire.eu",

View File

@ -51,7 +51,7 @@ export let properties: EnvProperties = {
loginUrl: "https://services.openaire.eu/connect-user-management/openid_connect_login",
userInfoUrl: " https://services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=",
registryUrl: 'https://services.openaire.eu/uoa-user-management/api/registry/',
logoutUrl: "https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",
cookieDomain: ".openaire.eu",

View File

@ -51,7 +51,7 @@ export let properties: EnvProperties = {
loginUrl: "https://services.openaire.eu/connect-user-management/openid_connect_login",
userInfoUrl: " https://services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=",
registryUrl: 'https://services.openaire.eu/uoa-user-management/api/registry/',
logoutUrl: "https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",
cookieDomain: ".openaire.eu",

View File

@ -51,9 +51,10 @@ export let properties: EnvProperties = {
vocabulariesAPI: 'https://dev-openaire.d4science.org/provision/mvc/vocabularies/',
piwikBaseUrl: 'https://analytics.openaire.eu/piwik.php?idsite=',
piwikSiteId: '80',
loginUrl: 'http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-users-1.0.0-SNAPSHOT/openid_connect_login',
userInfoUrl: 'http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=',
logoutUrl: 'https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=',
loginUrl: 'http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/openid_connect_login',
userInfoUrl: 'http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUser',
registryUrl: 'http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/',
logoutUrl: 'https://openaire-dev.aai-dev.grnet.gr/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=',
cookieDomain: '.di.uoa.gr',
feedbackmail: 'openaire.test@gmail.com',
cacheUrl: 'http://dl170.madgik.di.uoa.gr:3000/get?url=',