Skip to content

Commit

Permalink
feat(core/application): Add 'autoActivate' toggle for DataSources
Browse files Browse the repository at this point in the history
- Also deprecate DataSourceConfig
  • Loading branch information
christopherthielen committed Sep 22, 2017
1 parent 31fa073 commit 9a318c6
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 209 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { module } from 'angular';
import { UIRouter } from '@uirouter/core';

import { ROBOT_TO_HUMAN_FILTER } from 'core/presentation/robotToHumanFilter/robotToHuman.filter';
import { SCHEDULER_FACTORY, SchedulerFactory } from 'core/scheduler/scheduler.factory';
import { Application } from './application.model';

import { ApplicationDataSource, DataSourceConfig } from './service/applicationDataSource';
import { ApplicationDataSource, IDataSourceConfig } from './service/applicationDataSource';

export class ApplicationModelBuilder {

constructor(private $log: ng.ILogService,
private $q: ng.IQService,
private $filter: any,
private $uiRouter: UIRouter,
private schedulerFactory: SchedulerFactory) {
'ngInject';
}
Expand All @@ -23,7 +25,7 @@ export class ApplicationModelBuilder {
dataSources = dataSources[0];
}
const application = new Application(name, this.schedulerFactory.createScheduler(), this.$q, this.$log);
dataSources.forEach(ds => this.addDataSource(new DataSourceConfig(ds), application));
dataSources.forEach(ds => this.addDataSource(ds, application));
return application;
}

Expand All @@ -35,13 +37,13 @@ export class ApplicationModelBuilder {

public createNotFoundApplication(name: string): Application {
const application = new Application(name, this.schedulerFactory.createScheduler(), this.$q, this.$log);
this.addDataSource(new DataSourceConfig({key: 'serverGroups', lazy: true}), application);
this.addDataSource({key: 'serverGroups', lazy: true}, application);
application.notFound = true;
return application;
}

private addDataSource(config: DataSourceConfig, application: Application): void {
const source = new ApplicationDataSource(config, application, this.$q, this.$log, this.$filter);
private addDataSource(config: IDataSourceConfig, application: Application): void {
const source = new ApplicationDataSource(config, application, this.$q, this.$log, this.$filter, this.$uiRouter);
application.dataSources.push(source);
application[config.key] = source;
}
Expand All @@ -52,6 +54,7 @@ export const APPLICATION_MODEL_BUILDER = 'spinnaker.core.application.model.build

module(APPLICATION_MODEL_BUILDER, [
SCHEDULER_FACTORY,
ROBOT_TO_HUMAN_FILTER
ROBOT_TO_HUMAN_FILTER,
require('@uirouter/angularjs').default,
])
.service('applicationModelBuilder', ApplicationModelBuilder);
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {DataSourceConfig} from '../service/applicationDataSource';
import {APPLICATION_DATA_SOURCE_REGISTRY} from '../service/applicationDataSource.registry';
import {APP_CONFIG_STATES} from './appConfig.states';

Expand All @@ -10,10 +9,10 @@ module.exports = angular
APP_CONFIG_STATES,
])
.run(function($q, applicationDataSourceRegistry) {
applicationDataSourceRegistry.registerDataSource(new DataSourceConfig({
applicationDataSourceRegistry.registerDataSource({
key: 'config',
label: 'Config',
sref: '.config',
active: '**.config.**',
}));
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { IFilterService, ILogService, IPromise, IQService, module } from 'angular';

import { UIRouter } from '@uirouter/core';

import { Api, API_SERVICE } from 'core/api/api.service';
import { SCHEDULER_FACTORY, SchedulerFactory } from 'core/scheduler/scheduler.factory';
import { Application } from '../application.model';
import { ApplicationDataSource, DataSourceConfig } from '../service/applicationDataSource';
import { ApplicationDataSource, IDataSourceConfig } from '../service/applicationDataSource';
import { APPLICATION_DATA_SOURCE_REGISTRY, ApplicationDataSourceRegistry } from './applicationDataSource.registry';
import { ROBOT_TO_HUMAN_FILTER } from 'core/presentation/robotToHumanFilter/robotToHuman.filter';
import { INFERRED_APPLICATION_WARNING_SERVICE, InferredApplicationWarningService } from './inferredApplicationWarning.service';
Expand All @@ -25,8 +27,12 @@ export interface IApplicationSummary {

export class ApplicationReader {

public constructor(private $q: IQService, private $log: ILogService, private $filter: IFilterService,
private API: Api, private schedulerFactory: SchedulerFactory,
public constructor(private $q: IQService,
private $log: ILogService,
private $filter: IFilterService,
private $uiRouter: UIRouter,
private API: Api,
private schedulerFactory: SchedulerFactory,
private inferredApplicationWarningService: InferredApplicationWarningService,
private applicationDataSourceRegistry: ApplicationDataSourceRegistry) {
'ngInject';
Expand Down Expand Up @@ -60,9 +66,9 @@ export class ApplicationReader {
}

private addDataSources(application: Application): void {
const dataSources: DataSourceConfig[] = this.applicationDataSourceRegistry.getDataSources();
dataSources.forEach((ds: DataSourceConfig) => {
const dataSource: ApplicationDataSource = new ApplicationDataSource(new DataSourceConfig(ds), application, this.$q, this.$log, this.$filter);
const dataSources: IDataSourceConfig[] = this.applicationDataSourceRegistry.getDataSources();
dataSources.forEach((ds: IDataSourceConfig) => {
const dataSource: ApplicationDataSource = new ApplicationDataSource(ds, application, this.$q, this.$log, this.$filter, this.$uiRouter);
application.dataSources.push(dataSource);
application[ds.key] = dataSource;
});
Expand Down Expand Up @@ -107,4 +113,5 @@ module(APPLICATION_READ_SERVICE, [
APPLICATION_DATA_SOURCE_REGISTRY,
INFERRED_APPLICATION_WARNING_SERVICE,
ROBOT_TO_HUMAN_FILTER,
require('@uirouter/angularjs').default,
]).service('applicationReader', ApplicationReader);
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as _ from 'lodash';
import { module } from 'angular';

import {module} from 'angular';
import * as _ from 'lodash';

import {DataSourceConfig} from './applicationDataSource';
import { IDataSourceConfig } from './applicationDataSource';

export class ApplicationDataSourceRegistry {

private defaultDataSourceOrder: string[] = ['executions', 'serverGroups', 'loadBalancers', 'securityGroups', 'tasks', 'config'];
private dataSources: DataSourceConfig[] = [];
private dataSources: IDataSourceConfig[] = [];
private dataSourceOrder: string[] = [];

public setDataSourceOrder(keys: string[]): void {
Expand All @@ -28,12 +28,12 @@ export class ApplicationDataSourceRegistry {
this.dataSources.sort((a, b) => order.indexOf(a.key) - order.indexOf(b.key));
}

public registerDataSource(config: any): void {
this.dataSources.push(new DataSourceConfig(config));
public registerDataSource(config: IDataSourceConfig): void {
this.dataSources.push(config);
this.sortDataSources();
}

public getDataSources(): DataSourceConfig[] {
public getDataSources(): IDataSourceConfig[] {
return _.cloneDeep(this.dataSources);
}
}
Expand Down
Loading

0 comments on commit 9a318c6

Please sign in to comment.