Commit 6f7f62ea authored by Kristjan Kruus's avatar Kristjan Kruus

Pull request #85: Bugfix/RIHAKB-961 rakendust ei kuvata esimesel laadimisel

Merge in RIHA/riha-browser from bugfix/RIHAKB-961-rakendust-ei-kuvata-esimesel-laadimisel to develop

* commit '2780908d':
  made getActiveUser() method safe to be invoked.
  WIP - possible fix
parents 08422f58 2780908d
import { Component, OnInit, Input, DoCheck, KeyValueDiffers } from '@angular/core';
import { SystemsService } from '../../../../services/systems.service';
import { ToastrService } from 'ngx-toastr';
import { GridData } from '../../../../models/grid-data';
import { EnvironmentService } from '../../../../services/environment.service';
import { GeneralHelperService } from '../../../../services/general-helper.service';
import { classifiers } from "../../../../services/environment.service";
import { UserMatrix } from '../../../../models/user-matrix';
import {Component, DoCheck, Input, KeyValueDiffers, OnInit} from '@angular/core';
import {SystemsService} from '../../../../services/systems.service';
import {ToastrService} from 'ngx-toastr';
import {GridData} from '../../../../models/grid-data';
import {classifiers, EnvironmentService} from '../../../../services/environment.service';
import {GeneralHelperService} from '../../../../services/general-helper.service';
import {UserMatrix} from '../../../../models/user-matrix';
@Component({
selector: 'app-discussions-list',
......@@ -23,7 +22,7 @@ export class DiscussionsListComponent implements OnInit, DoCheck {
public isNewDiscussion(ad){
if (ad.lastComment){
return ad.lastComment.organizationCode != this.environmentService.getActiveUser().activeOrganization.code;
return this.environmentService.getActiveUser() != null && ad.lastComment.organizationCode != this.environmentService.getActiveUser().activeOrganization.code;
} else {
return true;
}
......
import { Component, OnInit, KeyValueDiffers } from '@angular/core';
import { SystemsService } from '../../../services/systems.service';
import { ToastrService } from 'ngx-toastr';
import { GridData } from '../../../models/grid-data';
import { EnvironmentService, classifiers } from '../../../services/environment.service';
import { GeneralHelperService } from '../../../services/general-helper.service';
import {Component, KeyValueDiffers, OnInit} from '@angular/core';
import {SystemsService} from '../../../services/systems.service';
import {ToastrService} from 'ngx-toastr';
import {GridData} from '../../../models/grid-data';
import {classifiers, EnvironmentService} from '../../../services/environment.service';
import {GeneralHelperService} from '../../../services/general-helper.service';
import * as moment from 'moment';
import { UserMatrix } from '../../../models/user-matrix';
import {UserMatrix} from '../../../models/user-matrix';
@Component({
selector: 'app-systems-for-approval-list',
......@@ -43,7 +43,7 @@ export class SystemsForApprovalListComponent implements OnInit {
const eventsCount = ar.events.length;
for (let i = 0; i < eventsCount; i++){
const event = ar.events[i];
const activeOrganization = this.environmentService.getActiveUser().getActiveOrganization();
const activeOrganization = this.environmentService.getActiveUser() ? this.environmentService.getActiveUser().getActiveOrganization() : null;
if (event.type == this.classifiers.event_type.DECISION.code && activeOrganization && activeOrganization.code == event.organizationCode){
hasDecision = true;
break;
......
......@@ -113,7 +113,7 @@ export class ApproverIssueDetailsComponent implements OnInit, CanDeactivateModal
&& this.feedback.type != classifiers.issue_type.MODIFICATION_REQUEST.code
&& this.feedback.type != classifiers.issue_type.FINALIZATION_REQUEST.code
&& this.feedback.type != classifiers.issue_type.ESTABLISHMENT_REQUEST.code){
ret = bHasApproverRole || this.activeUser.canEdit(this.system.getOwnerCode());
ret = bHasApproverRole || (this.activeUser && this.activeUser.canEdit(this.system.getOwnerCode()));
}
}
return ret;
......
import { Component, OnInit, DoCheck, KeyValueDiffers } from '@angular/core';
import { UserMatrix } from '../../models/user-matrix';
import { EnvironmentService } from '../../services/environment.service';
import { GridData } from '../../models/grid-data';
import { SystemsService } from '../../services/systems.service';
import { GeneralHelperService } from '../../services/general-helper.service';
import {Component, DoCheck, KeyValueDiffers, OnInit} from '@angular/core';
import {UserMatrix} from '../../models/user-matrix';
import {EnvironmentService} from '../../services/environment.service';
import {GridData} from '../../models/grid-data';
import {SystemsService} from '../../services/systems.service';
import {GeneralHelperService} from '../../services/general-helper.service';
@Component({
selector: 'app-producer-dashboard',
......@@ -23,7 +23,7 @@ export class ProducerDashboardComponent implements OnInit, DoCheck {
}
private getOwnOpenIssues(){
if (this.userMatrix.isLoggedIn && this.userMatrix.isOrganizationSelected) {
if (this.userMatrix.isLoggedIn && this.userMatrix.isOrganizationSelected && this.environmentService.getActiveUser()) {
this.systemsService.getActiveIssuesForOrganization(this.environmentService.getActiveUser().activeOrganization.code, this.gridData.sort).subscribe(res =>{
this.gridData.updateData(res);
this.loaded = true;
......
......@@ -65,7 +65,7 @@ export class ProducerDetailsComponent implements OnInit, DoCheck, CanDeactivateM
break;
}
case 'contacts': {
ret = (this.system.hasContacts() && this.environmentService.getActiveUser() != null) || editable;
ret = (this.system.hasContacts() && typeof this.environmentService.getActiveUser() !== 'undefined' && this.environmentService.getActiveUser() != null) || editable;
break;
}
case 'security': {
......@@ -106,7 +106,7 @@ export class ProducerDetailsComponent implements OnInit, DoCheck, CanDeactivateM
this.userMatrix = this.environmentService.getUserMatrix();
if (this.loaded && this.userMatrix.isLoggedIn){
const user = this.environmentService.getActiveUser();
return this.issueId && this.userMatrix.isLoggedIn && !(user.canEdit(this.system.getOwnerCode()) || this.userMatrix.hasApproverRole);
return this.issueId && this.userMatrix.isLoggedIn && user && !(user.canEdit(this.system.getOwnerCode()) || this.userMatrix.hasApproverRole);
} else {
return false;
}
......
import { Component, OnInit, Input } from '@angular/core';
import { System } from '../../../models/system';
import { SystemsService } from '../../../services/systems.service';
import { EnvironmentService, classifiers } from "../../../services/environment.service";
import { WindowRefService } from '../../../services/window-ref.service';
import { Router, ActivatedRoute } from '@angular/router';
import {Component, Input, OnInit} from '@angular/core';
import {System} from '../../../models/system';
import {SystemsService} from '../../../services/systems.service';
import {classifiers, EnvironmentService} from "../../../services/environment.service";
import {WindowRefService} from '../../../services/window-ref.service';
import {ActivatedRoute, Router} from '@angular/router';
@Component({
selector: 'app-producer-edit-general',
......@@ -76,7 +76,7 @@ export class ProducerEditGeneralComponent implements OnInit {
}
isLoggedIn(){
return this.environmentService.getActiveUser() != null;
return typeof this.environmentService.getActiveUser() !== 'undefined' && this.environmentService.getActiveUser() != null;
}
goBackToDetails(f){
......
......@@ -18,7 +18,7 @@ export class RihaNavbarComponent implements OnInit, AfterContentChecked {
public _dc: number = 0;
isUserLoggedIn(): boolean {
return this.environmentService.getActiveUser() != null;
return typeof this.environmentService.getActiveUser() !== 'undefined' && this.environmentService.getActiveUser() != null;
}
getRand() {
......@@ -67,22 +67,22 @@ export class RihaNavbarComponent implements OnInit, AfterContentChecked {
isAllowedToChangeOrganization(): boolean {
const user = this.environmentService.getActiveUser();
return user.getOrganizations().length > 1 || (user.getOrganizations().length == 1 && user.getActiveOrganization() == null);
return user && user.getOrganizations().length > 1 || (user.getOrganizations().length == 1 && user.getActiveOrganization() == null);
}
isNoOrganizationPresent(): boolean {
const user = this.environmentService.getActiveUser();
return user.getOrganizations().length == 0;
return user && user.getOrganizations().length == 0;
}
noOrganizationSelected(): boolean {
const user = this.environmentService.getActiveUser();
return user.getActiveOrganization() == null;
return user && user.getActiveOrganization() == null;
}
getUserText(): string {
const user = this.environmentService.getActiveUser();
return user.getFullNameWithActiveOrganization();
return user && user.getFullNameWithActiveOrganization();
}
searchInfosystems(input) {
......
......@@ -16,7 +16,7 @@ export class EnvironmentService {
private userInfoUrl = environment.api.userInfoUrl;
private classifiersUrl = environment.api.classifiersUrl;
public globalEnvironment: any;
public globalEnvironment = new Environment({});
private lastVisitedLocations = [null, null];
......@@ -106,7 +106,7 @@ export class EnvironmentService {
}
public onAppStart(): Promise<any> {
const promise = this.loadEnvironmentData().toPromise();
const promise = this.loadEnvironmentDataProperly();
promise.then(env => {
this.runTrackingScripts(new Environment(env));
});
......@@ -129,6 +129,11 @@ export class EnvironmentService {
return observable;
}
public async loadEnvironmentDataProperly(): Promise<Environment> {
this.globalEnvironment = new Environment(await this.http.get<Environment>(this.environmentUrl).toPromise());
return this.globalEnvironment;
}
public doLogout(): Observable<any> {
return this.http.post('/logout',null);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment