Skip to content
This repository was archived by the owner on Feb 18, 2020. It is now read-only.

Commit 1b6c319

Browse files
committed
Merge remote-tracking branch 'origin/feature/init-configurable-project'
2 parents ca40b0d + 9131ba5 commit 1b6c319

File tree

7 files changed

+92
-30
lines changed

7 files changed

+92
-30
lines changed

src/exemples/admin/admin.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import {Component} from '@angular/core';
22
import {bootstrap} from '@angular/platform-browser-dynamic';
33
import {HmAdminComponent} from '../../hm-admin/hm-admin.component';
4-
4+
import configuration from './configuration';
55

66
@Component({
7-
selector: 'app',
8-
directives: [HmAdminComponent],
9-
template: `<hm-admin-app></hm-admin-app>`
7+
selector: 'app',
8+
directives: [HmAdminComponent],
9+
template: `<hm-admin-app [config]='config'></hm-admin-app>`
1010
})
1111
export class App {
12-
}
12+
public config: Configuration;
1313

14-
bootstrap(App);
14+
constructor() {
15+
this.config = configuration;
16+
}
1517

18+
}
19+
20+
export interface Configuration {
21+
api: {
22+
baseUrl: string
23+
}
24+
}
25+
bootstrap(App);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
api: {
3+
baseUrl: 'http://www.markus-lanthaler.com/hydra/event-api/'
4+
}
5+
6+
};
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
import {
2-
beforeEachProviders,
3-
describe,
4-
expect,
5-
it,
6-
inject
7-
} from '@angular/core/testing';
8-
import { HmAdminComponent } from './hm-admin.component.ts';
1+
import {beforeEachProviders, describe, expect, it, inject} from '@angular/core/testing';
2+
import {HmAdminComponent} from './hm-admin.component.ts';
93

104
beforeEachProviders(() => [HmAdminComponent]);
115

126
describe('App: HmAdmin', () => {
7+
138
it('should create the app',
14-
inject([HmAdminComponent], (app: HmAdminComponent) => {
15-
expect(app).toBeTruthy();
16-
}));
9+
inject([HmAdminComponent], (app: HmAdminComponent) => {
10+
expect(app).toBeTruthy();
11+
}));
1712

18-
it('should have as title \'hm-admin works!\'',
19-
inject([HmAdminComponent], (app: HmAdminComponent) => {
20-
expect(app.title).toEqual('hm-admin works!');
21-
}));
2213
});

src/hm-admin/hm-admin.component.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
import { Component } from '@angular/core';
1+
import {Component, Input, OnInit} from '@angular/core';
2+
import {ConfigService} from './services/config/config.service';
23

34
@Component({
45
moduleId: module.id,
56
selector: 'hm-admin-app',
67
templateUrl: 'hm-admin.component.html',
7-
styleUrls: ['hm-admin.component.css']
8+
styleUrls: ['hm-admin.component.css'],
9+
providers: [ConfigService]
810
})
9-
export class HmAdminComponent {
11+
export class HmAdminComponent implements OnInit {
12+
@Input('config')
13+
config: any;
14+
15+
16+
constructor(private configService:ConfigService) {}
17+
18+
ngOnInit() {
19+
this.configService.hookMeIfYouCan(this.config);
20+
}
21+
1022
title = 'hm-admin works!';
1123
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {it, describe, expect, inject, beforeEachProviders} from '@angular/core/testing';
2+
import {ConfigService} from './config.service';
3+
4+
export function main() {
5+
describe('Config service', () => {
6+
7+
beforeEachProviders(() => { return [ConfigService]; });
8+
9+
describe('hookMeIfYouCan', () => {
10+
11+
it('should be hookable with available values', inject([ConfigService], (configService) => {
12+
let defaultConfig = {
13+
api: {
14+
baseUrl: 'http://localhost:8000'
15+
},
16+
nonAvailableHook: 'foo'
17+
};
18+
19+
configService.hookMeIfYouCan(defaultConfig);
20+
expect(configService.api.url).toBe('http://localhost:8000');
21+
expect(configService['nonAvailableHook']).toBeUndefined();
22+
}));
23+
24+
});
25+
});
26+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {Injectable} from '@angular/core';
2+
3+
@Injectable()
4+
export class ConfigService {
5+
api: any = {};
6+
7+
/**
8+
* Complete the default configuration with external one
9+
*
10+
* @param config
11+
* @private
12+
*/
13+
hookMeIfYouCan(config: any): void {
14+
for (let key in config) {
15+
if (config.hasOwnProperty(key) && this.hasOwnProperty(key)) {
16+
this[key] = config[key];
17+
}
18+
}
19+
}
20+
};

src/index.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@
1212
map: {
1313
'@angular': 'vendor/@angular',
1414
'rxjs': 'vendor/rxjs',
15-
'hm-admin':'hm-admin'
15+
'hm-admin':'hm-admin',
16+
'admin':'exemples/admin'
1617
},
1718
packages: {
18-
'dist': { defaultExtension: 'js', format: 'register', main: 'boot.js' },
19+
'../': { defaultExtension: 'js' },
1920
'@angular/common': { defaultExtension: 'js', main: 'index.js' },
2021
'@angular/compiler': { defaultExtension: 'js', main: 'index.js' },
2122
'@angular/core': { defaultExtension: 'js', main: 'index.js' },
22-
'@angular/http': { defaultExtension: 'js', main: 'index.js' },
2323
'@angular/platform-browser': { defaultExtension: 'js', main: 'index.js' },
2424
'@angular/platform-browser-dynamic': { defaultExtension: 'js', main: 'index.js' },
25-
'@angular/router': { defaultExtension: 'js', main: 'index.js' },
26-
'rxjs': { defaultExtension: 'js' },
27-
'hm-admin': { defaultExtension: 'js',main:'hm-admin.component.js' }
2825
}
2926
});
3027
System.import('exemples/admin/admin.js').catch(function (err) {console.error(err);});

0 commit comments

Comments
 (0)