Skip to content

Commit 5f4eb4d

Browse files
committed
Merge branch 'feature/add-some-examples' into develop
2 parents 68416e0 + 6703e8b commit 5f4eb4d

File tree

15 files changed

+403
-81
lines changed

15 files changed

+403
-81
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Typedoc is generated with command ```npm run build:docs``` into directoy ```docs
201201
- [X] Add typedocs
202202
- [ ] Add greenkeeper
203203
- [ ] Add electron
204-
- [ ] Add pipline example
205-
- [ ] Add utility converters https://www.npmjs.com/package/aurelia-utility-converters
206-
- [ ] Add validation example
207-
- [ ] Add configure http client example
204+
- [X] Add pipline example
205+
- [X] Add utility converters https://www.npmjs.com/package/aurelia-utility-converters
206+
- [X] Add validation example
207+
- [X] Add configure http client example

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"aurelia-templating-binding": "^1.2.0",
9090
"aurelia-templating-resources": "^1.2.0",
9191
"aurelia-templating-router": "^1.0.0",
92+
"aurelia-validation": "^1.0.0-beta.1.0.1",
9293
"bootstrap-sass": "^3.3.7",
9394
"font-awesome": "^4.7.0",
9495
"i18next-browser-languagedetector": "^1.0.1",

src/app/app.vm.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { Lazy, inject } from 'aurelia-framework';
22
import { Router, RouterConfiguration } from 'aurelia-router';
33
import { I18N } from 'aurelia-i18n';
4+
import { HttpClient } from 'aurelia-fetch-client';
45

6+
import { LogManager, Logger} from './services/logger.service';
57
import { AppConfigService } from './services/app-config.service';
68
import { CordovaService } from './services/cordova.service';
79
import { EventBusService, EventBusEvents } from './services/event-bus.service';
810
import { LanguageService } from './services/language.service';
11+
import { ExampleStep } from './piplines/example.step';
912

10-
@inject(I18N, AppConfigService, Lazy.of(CordovaService), EventBusService, LanguageService)
13+
@inject(I18N, AppConfigService, Lazy.of(CordovaService), EventBusService, LanguageService, HttpClient)
1114
export class AppViewModel {
15+
16+
private logger: Logger;
17+
1218
public router: Router;
1319

1420
constructor(
@@ -17,7 +23,15 @@ export class AppViewModel {
1723
private cordovaServiceFn: () => CordovaService,
1824
private eventBusService: EventBusService,
1925
private languageService: LanguageService,
20-
) { }
26+
private httpClient: HttpClient
27+
) {
28+
this.logger = LogManager.getLogger('AppViewModel');
29+
this.configureHttpClient();
30+
}
31+
32+
public attached(): void {
33+
this.configureMoment();
34+
}
2135

2236
public configureRouter(config: RouterConfiguration, router: Router): void {
2337
config.title = this.i18n.tr('TITLE');
@@ -52,6 +66,8 @@ export class AppViewModel {
5266
]);
5367
config.mapUnknownRoutes({ route: '', redirect: '' });
5468

69+
config.addAuthorizeStep(ExampleStep);
70+
5571
this.router = router;
5672
}
5773

@@ -60,4 +76,17 @@ export class AppViewModel {
6076
moment.locale(locale);
6177
this.eventBusService.addSubscription(EventBusEvents.IDS.i18n.locale.changed, (a) => moment.locale(a.newValue));
6278
}
79+
80+
private configureHttpClient(): void {
81+
this.httpClient.configure(config => {
82+
config
83+
.useStandardConfiguration()
84+
.withInterceptor({
85+
request: (request: Request) => {
86+
this.logger.debug('Request interceptor hit: ', request.url);
87+
return request;
88+
}
89+
});
90+
});
91+
}
6392
}

src/app/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ export async function configure(aurelia: Aurelia): Promise<void> {
7070
}
7171
});
7272
})
73+
/**
74+
* Aurelia Validation plugin
75+
* See: https://github.com/aurelia/validation
76+
*
77+
* Configure i18n for aurelia-validation error messages.
78+
* See: http://aurelia.io/hub.html#/doc/article/aurelia/validation/latest/validation-basics
79+
*/
80+
.plugin('aurelia-validation')
7381
// Uncomment the line below to enable animation.
7482
// .plugin('aurelia-animator-css');
7583
// if the css animator is enabled, add swap-order="after" to all router-view elements

src/app/modules/welcome/welcome.vm.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,13 @@ <h3>Switch Language</h3>
3131
<br/><br/>
3232
<p>Everything is: <span t="TR_ATTR"></span></p>
3333
<p>Signalr example: ${ 'TR_SIGNALER' | t & signal:'locale:changed' }</p>
34+
35+
<h3>Converter utility</h3>
36+
<p>${ jsonProperty | json }</p>
37+
<p>Available converters are: filter, json, limit, md5 and sort</p>
38+
39+
<h3>Validation</h3>
40+
<p>Validation is: ${validationValid}</p>
41+
<button class="btn btn-primary" click.delegate="validateFirstName()">validate</button>
3442
</section>
3543
</template>

src/app/modules/welcome/welcome.vm.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { autoinject } from 'aurelia-framework';
2+
import { ValidationControllerFactory, ValidationController, validateTrigger, ValidationRules } from 'aurelia-validation';
23

34
import { LogManager, Logger} from './../../services/logger.service';
45
import { AppConfigService } from './../../services/app-config.service';
@@ -7,25 +8,48 @@ import { LanguageService } from './../../services/language.service';
78
@autoinject
89
export class Welcome {
910
private logger: Logger;
11+
private vController: ValidationController;
1012

1113
public heading: string = 'Welcome to the Aurelia Navigation App';
1214
public firstName: string = 'John';
1315
public lastName: string = 'Doe';
1416
public previousValue: string = this.fullName;
1517
public currentDate: Date = new Date();
18+
public jsonProperty: Object = { key1: 'value1', key2: 'value2' };
19+
public validationValid: boolean = false;
1620

1721
constructor(
1822
private appConfigService: AppConfigService,
19-
private languageService: LanguageService
23+
private languageService: LanguageService,
24+
validationControllerFactory: ValidationControllerFactory
2025
) {
2126
this.logger = LogManager.getLogger('Welcome VM');
2227
this.logger.info('appConfig => name:', appConfigService.getName());
2328
this.logger.info('appConfig => version:', appConfigService.getVersion());
2429
this.logger.info('appConfig => env:', appConfigService.getEnv());
2530
this.logger.info('appConfig => platform:', appConfigService.getPlatform());
2631
this.logger.info('appConfig => config:', appConfigService.getConfig());
32+
33+
this.vController = validationControllerFactory.createForCurrentScope();
34+
this.vController.validateTrigger = validateTrigger.manual;
35+
}
36+
37+
public canDeactivate(): boolean {
38+
if (this.fullName !== this.previousValue) {
39+
return confirm('Are you sure you want to leave?');
40+
}
41+
return true;
2742
}
2843

44+
public validateFirstName(): void {
45+
this.vController
46+
.validate({
47+
object: this,
48+
rules: ValidationRules.ensure('firstName').required().rules
49+
})
50+
.then(r => this.validationValid = r.valid);
51+
}
52+
2953
//Getters can't be directly observed, so they must be dirty checked.
3054
//However, if you tell Aurelia the dependencies, it no longer needs to dirty check the property.
3155
//To optimize by declaring the properties that this getter is computed from, uncomment the line below
@@ -40,13 +64,6 @@ export class Welcome {
4064
alert(`Welcome, ${this.fullName}!`);
4165
}
4266

43-
public canDeactivate(): boolean {
44-
if (this.fullName !== this.previousValue) {
45-
return confirm('Are you sure you want to leave?');
46-
}
47-
return true;
48-
}
49-
5067
public switchLanguage(): void {
5168
const lang = this.languageService.getCurrentLang();
5269
if (lang === this.languageService.getSupportedLanguages()[0]) {

src/app/piplines/example.step.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { autoinject } from 'aurelia-framework';
2+
import { NavigationInstruction, Next } from 'aurelia-router';
3+
import { LogManager, Logger } from './../services/logger.service';
4+
5+
@autoinject
6+
export class ExampleStep {
7+
8+
private logger: Logger;
9+
10+
constructor() {
11+
this.logger = LogManager.getLogger('ExampleStep');
12+
this.logger.debug('initialized');
13+
}
14+
15+
public run(navigationInstruction: NavigationInstruction, next: Next): any {
16+
this.logger.debug('Middleware hit on:', navigationInstruction.fragment);
17+
return next();
18+
}
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class FilterValueConverter {
2+
public toView(array, property, value): any[] {
3+
if (!array || !property || !value) {
4+
return array;
5+
}
6+
return array.filter((item) => item[property].toLowerCase().indexOf(value.toLowerCase()) > -1);
7+
}
8+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
export function configure(aurelia): void {
22
aurelia
33
.globalResources([
4-
'./date-format.converter'
4+
'./date-format.converter',
5+
'./filter.converter',
6+
'./json.converter',
7+
'./limit.converter',
8+
'./md5.converter',
9+
'./sort.converter',
510
]);
611
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class JsonValueConverter {
2+
public toView(value): string | void {
3+
if (value) {
4+
return JSON.stringify(value, undefined, '\t');
5+
}
6+
return;
7+
}
8+
}

0 commit comments

Comments
 (0)