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

Commit

Permalink
code climate #1
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-cox committed Mar 8, 2018
1 parent 933e9f0 commit 3d42118
Show file tree
Hide file tree
Showing 22 changed files with 401 additions and 353 deletions.
5 changes: 2 additions & 3 deletions src/frontend/app/core/entity-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { tag } from 'rxjs-spy/operators/tag';
import { interval } from 'rxjs/observable/interval';
import { filter, first, map, share, shareReplay, tap, withLatestFrom, startWith, pairwise, distinctUntilChanged } from 'rxjs/operators';
import { filter, map, pairwise, share, shareReplay, startWith, tap, withLatestFrom } from 'rxjs/operators';
import { Observable } from 'rxjs/Rx';

import { EntityMonitor } from '../shared/monitors/entity-monitor';
import { ValidateEntitiesStart } from '../store/actions/request.actions';
import { AppState } from '../store/app-state';
import { validateEntityRelations } from '../store/helpers/entity-relations.helpers';
import {
ActionState,
RequestInfoState,
Expand All @@ -19,7 +19,6 @@ import { getEntityUpdateSections, getUpdateSectionById } from '../store/selector
import { APIResource, EntityInfo } from '../store/types/api.types';
import { ICFAction, IRequestAction } from '../store/types/request.types';
import { composeFn } from './../store/helpers/reducer.helper';
import { ValidateEntitiesStart } from '../store/actions/request.actions';

type PollUntil = (apiResource: APIResource, updatingState: ActionState) => boolean;

Expand Down
58 changes: 28 additions & 30 deletions src/frontend/app/core/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,36 @@ export class LoggerService {
constructor(private store: Store<AppState>) { }

private log(level: LogLevel, message: string, arg: any) {
if (LogLevelStringToNumber[level] >= LogLevelStringToNumber[environment.logLevel]) {
if (environment.logToConsole) {
const date = new Date();
message = `${date.toUTCString()}- ${message}`;

let func = console.log;
switch (level) {
case LogLevel.ERROR:
func = console.error;
this.store.dispatch(new LoggerErrorAction(message));
break;
case LogLevel.WARN:
func = console.warn;
this.store.dispatch(new LoggerWarnAction(message));
break;
case LogLevel.INFO:
func = console.info;
this.store.dispatch(new LoggerInfoAction(message));
break;
case LogLevel.DEBUG:
func = console.log;
this.store.dispatch(new LoggerDebugAction(message));
break;
}
if (LogLevelStringToNumber[level] < LogLevelStringToNumber[environment.logLevel] || !environment.logToConsole) {
return;
}
const date = new Date();
message = `${date.toUTCString()}- ${message}`;

if (arg) {
func(message, arg);
} else {
func(message);
}
let func = console.log;
switch (level) {
case LogLevel.ERROR:
func = console.error;
this.store.dispatch(new LoggerErrorAction(message));
break;
case LogLevel.WARN:
func = console.warn;
this.store.dispatch(new LoggerWarnAction(message));
break;
case LogLevel.INFO:
func = console.info;
this.store.dispatch(new LoggerInfoAction(message));
break;
case LogLevel.DEBUG:
func = console.log;
this.store.dispatch(new LoggerDebugAction(message));
break;
}

}
if (arg) {
func(message, arg);
} else {
func(message);
}
}

Expand Down
28 changes: 10 additions & 18 deletions src/frontend/app/features/applications/application.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { schema } from 'normalizr';
import { Observable } from 'rxjs/Observable';
import { map, mergeMap, filter } from 'rxjs/operators';
import { filter, map, mergeMap } from 'rxjs/operators';

import { EntityService } from '../../core/entity-service';
import { EntityServiceFactory } from '../../core/entity-service-factory.service';
Expand All @@ -20,15 +19,19 @@ import {
} from '../../store/actions/app-metadata.actions';
import { GetApplication, UpdateApplication, UpdateExistingApplication } from '../../store/actions/application.actions';
import { AppState } from '../../store/app-state';
import { entityFactory, routeSchemaKey, stackSchemaKey, domainSchemaKey } from '../../store/helpers/entity-factory';
import {
appEnvVarsSchemaKey,
applicationSchemaKey,
appStatsSchemaKey,
appSummarySchemaKey,
spaceSchemaKey,
domainSchemaKey,
entityFactory,
organisationSchemaKey,
routeSchemaKey,
spaceSchemaKey,
stackSchemaKey,
} from '../../store/helpers/entity-factory';
import { createEntityRelationKey } from '../../store/helpers/entity-relation.types';
import { ActionState, rootUpdatingKey } from '../../store/reducers/api-request-reducer/types';
import { selectEntity, selectUpdateInfo } from '../../store/selectors/api.selectors';
import { endpointEntitiesSelector } from '../../store/selectors/endpoint.selectors';
Expand All @@ -45,7 +48,6 @@ import {
EnvVarStratosProject,
} from './application/application-tabs-base/tabs/build-tab/application-env-vars.service';
import { getRoute, isTCPRoute } from './routes/routes.helper';
import { createEntityRelationKey } from '../../store/helpers/entity-relations.helpers';

export function createGetApplicationAction(guid: string, endpointGuid: string) {
return new GetApplication(
Expand Down Expand Up @@ -250,15 +252,10 @@ export class ApplicationService {
*/
this.isFetchingApp$ = this.appEntityService.isFetchingEntity$;


this.isUpdatingApp$ =
this.app$.map(a => {
const updatingRoot = a.entityRequestInfo.updating[rootUpdatingKey] || {
busy: false
};
const updatingSection = a.entityRequestInfo.updating[UpdateExistingApplication.updateKey] || {
busy: false
};
const updatingRoot = a.entityRequestInfo.updating[rootUpdatingKey] || { busy: false };
const updatingSection = a.entityRequestInfo.updating[UpdateExistingApplication.updateKey] || { busy: false };
return updatingRoot.busy || updatingSection.busy || false;
});

Expand All @@ -279,12 +276,7 @@ export class ApplicationService {
}
const nonTCPRoutes = app.entity.routes.filter(p => !isTCPRoute(p));
if (nonTCPRoutes.length > 0) {
return getRoute(
nonTCPRoutes[0],
true,
false,
nonTCPRoutes[0].entity.domain
);
return getRoute(nonTCPRoutes[0], true, false, nonTCPRoutes[0].entity.domain);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { ApplicationService, createGetApplicationAction } from '../application.service';
import { ApplicationStateService } from '../../../shared/components/application-state/application-state.service';
import { EntityService } from '../../../core/entity-service';
import { AppState } from '../../../store/app-state';
import { Store } from '@ngrx/store';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { RouterNav } from '../../../store/actions/router.actions';
import { ApplicationEnvVarsService } from './application-tabs-base/tabs/build-tab/application-env-vars.service';
import { Store } from '@ngrx/store';

import { EntityService } from '../../../core/entity-service';
import { EntityServiceFactory } from '../../../core/entity-service-factory.service';
import { ApplicationStateService } from '../../../shared/components/application-state/application-state.service';
import { PaginationMonitorFactory } from '../../../shared/monitors/pagination-monitor.factory';
import { applicationSchemaKey, routeSchemaKey } from '../../../store/helpers/entity-factory';
import { entityFactory } from '../../../store/helpers/entity-factory';
import { schema } from 'normalizr';
import { createEntityRelationKey } from '../../../store/helpers/entity-relations.helpers';
import { AppState } from '../../../store/app-state';
import { applicationSchemaKey, entityFactory } from '../../../store/helpers/entity-factory';
import { ApplicationService, createGetApplicationAction } from '../application.service';
import { ApplicationEnvVarsService } from './application-tabs-base/tabs/build-tab/application-env-vars.service';


const applicationServiceFactory = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import {
organisationSchemaKey,
routeSchemaKey,
} from '../../../../store/helpers/entity-factory';
import { createEntityRelationKey } from '../../../../store/helpers/entity-relations.helpers';
import { RequestInfoState } from '../../../../store/reducers/api-request-reducer/types';
import { selectRequestInfo } from '../../../../store/selectors/api.selectors';
import { APIResource } from '../../../../store/types/api.types';
import { CreateNewApplicationState } from '../../../../store/types/create-application.types';
import { createGetApplicationAction } from '../../application.service';
import { createEntityRelationKey } from '../../../../store/helpers/entity-relation.types';

@Component({
selector: 'app-create-application-step3',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Domain } from '../../../../store/types/domain.types';
import { Route, RouteMode } from '../../../../store/types/route.types';
import { ApplicationService } from '../../application.service';
import { routeSchemaKey, domainSchemaKey, applicationSchemaKey } from '../../../../store/helpers/entity-factory';
import { createEntityRelationKey } from '../../../../store/helpers/entity-relations.helpers';
import { createEntityRelationKey } from '../../../../store/helpers/entity-relation.types';

@Component({
selector: 'app-add-routes',
Expand Down Expand Up @@ -211,19 +211,14 @@ export class AddRoutesComponent implements OnInit, OnDestroy {
take(1),
tap(p => {
if (p.error) {
this.snackBar.open(
'Failed to associate route with the app!',
'Dismiss'
);
this.snackBar.open('Failed to associate route with the app!', 'Dismiss');
} else {
this.store.dispatch(new GetAppRoutes(this.appGuid, this.cfGuid,
createEntityRelationKey(applicationSchemaKey, domainSchemaKey)
));
this.store.dispatch(
new RouterNav({
path: ['applications', this.cfGuid, this.appGuid]
})
);
this.store.dispatch(new RouterNav({
path: ['applications', this.cfGuid, this.appGuid]
}));
}
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { TableCellAppRouteComponent } from './table-cell-app-route/table-cell-ap
import { TableCellRadioComponent } from './table-cell-radio/table-cell-radio.component';
import { TableCellRouteComponent } from './table-cell-route/table-cell-route.component';
import { TableCellTCPRouteComponent } from './table-cell-tcproute/table-cell-tcproute.component';
import { createEntityRelationPaginationKey, createEntityRelationKey } from '../../../../../store/helpers/entity-relations.helpers';
import { spaceSchemaKey, routeSchemaKey, domainSchemaKey, applicationSchemaKey } from '../../../../../store/helpers/entity-factory';
import { createEntityRelationPaginationKey, createEntityRelationKey } from '../../../../../store/helpers/entity-relation.types';

@Injectable()
export class CfAppMapRoutesListConfigService implements IListConfig<APIResource> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DeleteRoute, UnmapRoute } from '../../../../../store/actions/route.acti
import { RouterNav } from '../../../../../store/actions/router.actions';
import { AppState } from '../../../../../store/app-state';
import { applicationSchemaKey } from '../../../../../store/helpers/entity-factory';
import { createEntityRelationPaginationKey } from '../../../../../store/helpers/entity-relations.helpers';
import { createEntityRelationPaginationKey } from '../../../../../store/helpers/entity-relation.types';
import { selectEntity } from '../../../../../store/selectors/api.selectors';
import { APIResource, EntityInfo } from '../../../../../store/types/api.types';
import { ConfirmationDialog, ConfirmationDialogService } from '../../../confirmation-dialog.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { schema } from 'normalizr';
import { GetAllApplications } from '../../../../../store/actions/application.actions';
import { AppState } from '../../../../../store/app-state';
import { applicationSchemaKey, entityFactory, spaceSchemaKey } from '../../../../../store/helpers/entity-factory';
import { createEntityRelationKey } from '../../../../../store/helpers/entity-relations.helpers';
import { APIResource } from '../../../../../store/types/api.types';
import { PaginationEntityState } from '../../../../../store/types/pagination.types';
import { ListDataSource } from '../../data-sources-controllers/list-data-source';
import { IListConfig } from '../../list.component.types';
import { createEntityRelationKey } from '../../../../../store/helpers/entity-relation.types';



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class CfOrgCardComponent extends TableCellCustom<APIResource<CfOrg>>
ngOnInit() {
const userRole$ = this.cfEndpointService.currentUser$.pipe(
switchMap(u => {
// FIX ME: This is null if the endpoint is disconnected. Not sure we should init it if we're headed directly to org level?
// This is null if the endpoint is disconnected. Probably related to https://github.com/cloudfoundry-incubator/stratos/issues/1727
if (!u) {
return Observable.of({
orgManager: false,
Expand All @@ -62,11 +62,7 @@ export class CfOrgCardComponent extends TableCellCustom<APIResource<CfOrg>>
user: false
});
}
return this.cfUserService.getUserRoleInOrg(
u.guid,
this.row.entity.guid,
this.row.entity.cfGuid
);
return this.cfUserService.getUserRoleInOrg(u.guid, this.row.entity.guid, this.row.entity.cfGuid);
}),
map(u => getOrgRolesString(u))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { organisationWithSpaceKey } from '../../../../../store/helpers/entity-fa
import { APIResource } from '../../../../../store/types/api.types';
import { ListDataSource } from '../../data-sources-controllers/list-data-source';
import { IListConfig } from '../../list.component.types';
import { createEntityRelationKey } from '../../../../../store/helpers/entity-relations.helpers';
import { createEntityRelationKey } from '../../../../../store/helpers/entity-relation.types';

const orgWithSpaceSchema = entityFactory(organisationWithSpaceKey);
const spaceSchema = entityFactory(spaceSchemaKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { map } from 'rxjs/operators';
import { DeleteOrganisation, GetAllOrganisations } from '../../store/actions/organisation.actions';
import { AppState } from '../../store/app-state';
import { entityFactory, organisationWithSpaceKey, spaceSchemaKey } from '../../store/helpers/entity-factory';
import { createEntityRelationKey } from '../../store/helpers/entity-relations.helpers';
import { createEntityRelationKey } from '../../store/helpers/entity-relation.types';
import {
getCurrentPageRequestInfo,
getPaginationObservables,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/app/store/actions/application.actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Headers, RequestOptions, URLSearchParams } from '@angular/http';

import { applicationSchemaKey, appStatsSchemaKey, entityFactory, routeSchemaKey } from '../helpers/entity-factory';
import { EntityInlineChildAction, EntityInlineParentAction } from '../helpers/entity-relations.helpers';
import { EntityInlineChildAction, EntityInlineParentAction } from '../helpers/entity-relation.types';
import { pick } from '../helpers/reducer.helper';
import { ActionMergeFunction } from '../types/api.types';
import { CfApplication } from '../types/application.types';
Expand Down
11 changes: 8 additions & 3 deletions src/frontend/app/store/actions/organisation.actions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { RequestOptions, URLSearchParams } from '@angular/http';

import { entityFactory } from '../helpers/entity-factory';
import { EntityInlineChildAction, EntityInlineParentAction } from '../helpers/entity-relations.helpers';
import { organisationSchemaKey, organisationWithSpaceKey, spaceSchemaKey, spacesKey } from '../helpers/entity-factory';
import {
entityFactory,
organisationSchemaKey,
organisationWithSpaceKey,
spaceSchemaKey,
spacesKey,
} from '../helpers/entity-factory';
import { EntityInlineChildAction, EntityInlineParentAction } from '../helpers/entity-relation.types';
import { PaginatedAction } from '../types/pagination.types';
import { CFStartAction, ICFAction } from '../types/request.types';
import { getActions } from './action.helper';
Expand Down
5 changes: 2 additions & 3 deletions src/frontend/app/store/actions/relation.actions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { RequestOptions, URLSearchParams } from '@angular/http';
import { schema } from 'normalizr';

import { EntityInlineChildAction, EntityInlineParentAction, EntityTreeRelation } from '../helpers/entity-relations.helpers';
import { EntityInlineChildAction, EntityInlineParentAction, EntityTreeRelation } from '../helpers/entity-relation.types';
import { PaginatedAction } from '../types/pagination.types';
import { CFStartAction, RequestEntityLocation, IRequestActionEntity } from '../types/request.types';
import { CFStartAction, IRequestActionEntity, RequestEntityLocation } from '../types/request.types';

const relationActionId = 'FetchRelationAction';

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/app/store/actions/request.actions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Action } from '@ngrx/store';

import { ValidationResult } from '../helpers/entity-relations.helpers';
import { NormalizedResponse } from '../types/api.types';
import { PaginatedAction } from '../types/pagination.types';
import { ICFAction } from '../types/request.types';
import { ValidationResult } from '../helpers/entity-relation.types';

export const ApiActionTypes = {
API_REQUEST_START: 'API_REQUEST_START'
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/app/store/actions/space.actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RequestOptions } from '@angular/http';

import { entityFactory, routeSchemaKey, spaceSchemaKey, spaceWithOrgKey } from '../helpers/entity-factory';
import { EntityInlineChildAction, EntityInlineParentAction } from '../helpers/entity-relations.helpers';
import { EntityInlineChildAction, EntityInlineParentAction } from '../helpers/entity-relation.types';
import { PaginatedAction } from '../types/pagination.types';
import { CFStartAction, ICFAction } from '../types/request.types';
import { RouteEvents } from './route.actions';
Expand Down
Loading

0 comments on commit 3d42118

Please sign in to comment.