replace session.isLoggedIn() method

This commit is contained in:
argirok 2023-08-03 13:02:59 +03:00
parent 5c345d8ff7
commit f160aaa000
2 changed files with 27 additions and 38 deletions

View File

@ -2,12 +2,9 @@ import {Component, Input, ViewChild} from '@angular/core';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {ContextsService} from './service/contexts.service'; import {ContextsService} from './service/contexts.service';
import {ClaimEntity, ShowOptions} from './claimHelper.class'; import {ClaimEntity, ShowOptions} from './claimHelper.class';
import {Session} from '../../login/utils/helper.class';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {EnvProperties} from '../../utils/properties/env-properties'; import {EnvProperties} from '../../utils/properties/env-properties';
import {Subscriber} from "rxjs"; import {Subscriber} from "rxjs";
import {OpenaireEntities} from "../../utils/properties/searchFields"; import {OpenaireEntities} from "../../utils/properties/searchFields";
import {CommunityService} from "../../connect/community/community.service";
import {CommunitiesService} from "../../connect/communities/communities.service"; import {CommunitiesService} from "../../connect/communities/communities.service";
declare var UIkit: any; declare var UIkit: any;
@ -167,10 +164,6 @@ export class ClaimContextSearchFormComponent {
} }
getCommunities() { getCommunities() {
if (!Session.isLoggedIn()) {
this.saveStateAndRedirectLogin();
} else {
this.loading = true; this.loading = true;
this.subscriptions.push(this._contextService.getPublicCommunitiesByState().subscribe( this.subscriptions.push(this._contextService.getPublicCommunitiesByState().subscribe(
data => { data => {
@ -203,18 +196,14 @@ export class ClaimContextSearchFormComponent {
this.error = true; this.error = true;
} }
)); ));
}
} }
getCategories() { getCategories() {
this.loading = true; this.loading = true;
// this.categories=[]; // this.categories=[];
if (this.selectedCommunityId != '0') { if (this.selectedCommunityId != '0') {
if (!Session.isLoggedIn()) {
this.saveStateAndRedirectLogin();
} else {
if (this.categories[this.selectedCommunityId]) { if (this.categories[this.selectedCommunityId]) {
this.loading = false; this.loading = false;
if(this.categories[this.selectedCommunityId].length > 0){ if(this.categories[this.selectedCommunityId].length > 0){
@ -242,7 +231,7 @@ export class ClaimContextSearchFormComponent {
} }
)); ));
} }
}
} }
displaySubcategory(id) { displaySubcategory(id) {
@ -255,9 +244,6 @@ export class ClaimContextSearchFormComponent {
} }
browseConcepts(categoryId) { browseConcepts(categoryId) {
if (!Session.isLoggedIn()) {
this.saveStateAndRedirectLogin();
} else {
if (this.conceptsClass[categoryId] != null) { if (this.conceptsClass[categoryId] != null) {
this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId]; this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId];
return; return;
@ -285,8 +271,6 @@ export class ClaimContextSearchFormComponent {
this.conceptsCategoryLoading[categoryId] = false; this.conceptsCategoryLoading[categoryId] = false;
} }
)); ));
}
} }
browseSubConcepts(categoryId, conceptId) { browseSubConcepts(categoryId, conceptId) {
@ -308,24 +292,6 @@ export class ClaimContextSearchFormComponent {
} }
saveStateAndRedirectLogin() {
if (this.results != null) {
localStorage.setItem(this.localStoragePrefix + "results", JSON.stringify(this.results));
}
if (this.sources != null) {
localStorage.setItem(this.localStoragePrefix + "sources", JSON.stringify(this.sources));
}
this.router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this.router.url
}
});
}
private static handleError(message: string, error) { private static handleError(message: string, error) {
console.error("Claim context search form (component): " + message, error); console.error("Claim context search form (component): " + message, error);
} }

View File

@ -16,6 +16,8 @@ import {OpenaireEntities} from "../../utils/properties/searchFields";
import {StringUtils} from "../../utils/string-utils.class"; import {StringUtils} from "../../utils/string-utils.class";
import {RouterHelper} from "../../utils/routerHelper.class"; import {RouterHelper} from "../../utils/routerHelper.class";
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import {LoginErrorCodes} from "../../login/utils/guardHelper.class";
import {UserManagementService} from "../../services/user-management.service";
@Component({ @Component({
selector: 'linking-generic', selector: 'linking-generic',
@ -51,12 +53,17 @@ export class LinkingGenericComponent {
constructor (private _router: Router, private route: ActivatedRoute, private entitySearch:EntitiesSearchService, constructor (private _router: Router, private route: ActivatedRoute, private entitySearch:EntitiesSearchService,
private _meta: Meta, private _title: Title, private _piwikService:PiwikService, private _meta: Meta, private _title: Title, private _piwikService:PiwikService,
private seoService: SEOService, private helper: HelperService, private cdr: ChangeDetectorRef, private seoService: SEOService, private helper: HelperService, private cdr: ChangeDetectorRef,
private location: Location) { private location: Location, private userManagementService: UserManagementService) {
} }
subscriptions = []; subscriptions = [];
ngOnInit() { ngOnInit() {
if(this.breadcrumbs.length === 0) { this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
if (!user) {
this.saveStateAndRedirectLogin();
}
}));
if(this.breadcrumbs.length === 0) {
this.breadcrumbs.push({name: 'home', route: '/'}); this.breadcrumbs.push({name: 'home', route: '/'});
this.breadcrumbs.push({name: "Link", route: null}); this.breadcrumbs.push({name: "Link", route: null});
} }
@ -211,4 +218,20 @@ export class LinkingGenericComponent {
this.location.back(); this.location.back();
} }
} }
saveStateAndRedirectLogin() {
if (this.results != null) {
localStorage.setItem(this.localStoragePrefix + "results", JSON.stringify(this.results));
}
if (this.sources != null) {
localStorage.setItem(this.localStoragePrefix + "sources", JSON.stringify(this.sources));
}
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
}
} }