Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Improve output of STRATOS_PROJECT in code block by parsing string as …
Browse files Browse the repository at this point in the history
…object
  • Loading branch information
richard-cox committed Jul 24, 2018
1 parent 41b42c8 commit c860f1b
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { LoggerService } from '../../../../../../core/logger.service';
import { ListDataSource } from '../../../../../../shared/components/list/data-sources-controllers/list-data-source';
import {
ListAppEnvVar,
Expand All @@ -14,6 +15,7 @@ import { ListConfig } from '../../../../../../shared/components/list/list.compon
import { AppState } from '../../../../../../store/app-state';
import { ApplicationService } from '../../../../application.service';


export interface VariableTabAllEnvVarType {
name: string;
value: string;
Expand All @@ -34,7 +36,8 @@ export class VariablesTabComponent implements OnInit {
constructor(
private store: Store<AppState>,
private appService: ApplicationService,
private listConfig: ListConfig<ListAppEnvVar>
private listConfig: ListConfig<ListAppEnvVar>,
private loggerService: LoggerService
) {
this.envVarsDataSource = listConfig.getDataSource();
}
Expand All @@ -53,7 +56,7 @@ export class VariablesTabComponent implements OnInit {
values: app.entity.entity.environment_json || {}
})));
this.allEnvVars$ = this.appService.appEnvVars.entities$.pipe(
map(this.mapEnvVars)
map(this.mapEnvVars.bind(this))
);
}

Expand All @@ -80,11 +83,20 @@ export class VariablesTabComponent implements OnInit {
Object.keys(envVars).forEach(key => {
result.push({
name: key,
value: envVars[key]
value: key === 'STRATOS_PROJECT' ? this.parseStratosProject(envVars[key]) : envVars[key]
});
});
});
return result;
}

private parseStratosProject(value: string): Object | string {
try {
return JSON.parse(value);
} catch (err) {
this.loggerService.debug('Failed to parse STRATOS_PROJECT env var', err);
}
return '';
}

}

0 comments on commit c860f1b

Please sign in to comment.