Skip to content

Commit 845a190

Browse files
committed
Add parallel requests
1 parent df84abc commit 845a190

File tree

8 files changed

+67
-5
lines changed

8 files changed

+67
-5
lines changed

cloudapp/src/app/app-routing.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { MainComponent } from './main/main.component';
44
import { NewrouteComponent } from './newroute/newroute.component';
55
import { ThemingComponent } from './theming/theming.component';
66
import { SettingsComponent } from './settings/settings.component';
7+
import { ParallelComponent } from './parallel/parallel.component';
78

89
const routes: Routes = [
910
{ path: '', component: MainComponent },
1011
{ path: 'newroute', component: NewrouteComponent },
1112
{ path: 'theming', component: ThemingComponent },
1213
{ path: 'settings', component: SettingsComponent },
14+
{ path: 'parallel', component: ParallelComponent },
1315
];
1416

1517
@NgModule({

cloudapp/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TopmenuComponent } from './topmenu/topmenu.component';
1313
import { NewrouteComponent } from './newroute/newroute.component';
1414
import { ThemingComponent } from './theming/theming.component';
1515
import { SettingsComponent } from './settings/settings.component';
16+
import { ParallelComponent } from './parallel/parallel.component';
1617

1718
export function getToastrModule() {
1819
return ToastrModule.forRoot({
@@ -28,7 +29,8 @@ export function getToastrModule() {
2829
TopmenuComponent,
2930
NewrouteComponent,
3031
ThemingComponent,
31-
SettingsComponent
32+
SettingsComponent,
33+
ParallelComponent
3234
],
3335
imports: [
3436
MaterialModule,

cloudapp/src/app/main/main.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ <h1>
55
<p>This app includes all of the code referenced in the <a href="https://developers.exlibrisgroup.com/cloudapps/tutorials" target="_blank">tutorials section of the CloudApps documentation</a>. The following menu will lead you to the component referenced in the corresponding tutorial:</p>
66
<ul>
77
<li><a [routerLink]="['newroute']">Adding additional routes</a></li>
8-
<li><a [routerLink]="['theming']">Using Material Components & Theming</a></li>
8+
<li><a [routerLink]="['theming']">Using Material components & theming</a></li>
99
<li><a [routerLink]="['settings']">Using the Settings Service</a></li>
10+
<li><a [routerLink]="['parallel']">Making parallel API requests</a></li>
1011
</ul>
1112
</section>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<p>
2+
<button mat-stroked-button type="button" color="primary" (click)="run()">Run</button>
3+
</p>
4+
<ul>
5+
<li *ngFor="let user of users">
6+
<strong>{{ user.name }}</strong>: ${{ user.fees.value }}
7+
</li>
8+
</ul>

cloudapp/src/app/parallel/parallel.component.scss

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { CloudAppRestService } from '@exlibris/exl-cloudapp-angular-lib';
3+
import { mergeMap, map } from 'rxjs/operators';
4+
import { from } from 'rxjs';
5+
import { AppService } from '../app.service';
6+
7+
const CONCURRENT_REQUESTS = 5;
8+
9+
@Component({
10+
selector: 'app-parallel',
11+
templateUrl: './parallel.component.html',
12+
styleUrls: ['./parallel.component.scss']
13+
})
14+
export class ParallelComponent implements OnInit {
15+
users: Array<{name: string, fees: number}>;
16+
17+
constructor(
18+
private restService: CloudAppRestService,
19+
private appService: AppService
20+
) { }
21+
22+
ngOnInit() {
23+
this.appService.setTitle('Parallel Requests');
24+
}
25+
26+
run() {
27+
this.users = [];
28+
this.getUsers().subscribe(users=>this.loadUsers(users.user));
29+
}
30+
31+
loadUsers(users: any[]) {
32+
from(users).pipe(
33+
mergeMap(user => this.restService.call(`/users/${user.primary_id}?expand=fees`), CONCURRENT_REQUESTS),
34+
map(user=>({name: user.full_name, fees: user.fees}))
35+
)
36+
.subscribe(s=>this.users.push(s));
37+
}
38+
39+
getUsers() {
40+
return this.restService.call('/users?limit=50');
41+
}
42+
}

cloudapp/src/app/settings/settings.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export class SettingsComponent implements OnInit {
2727
showValue: this.fb.control(false),
2828
pageSize: this.fb.control(10)
2929
});
30-
//this.settingsService.remove().subscribe(()=>this.load());
3130
this.load();
3231
}
3332

manifest.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
{
2-
"$schema": "./manifest.schema.json",
32
"id": "cloud-app-tutorials",
43
"title": "CloudApp Tutorials",
5-
"description": "Tutorials for CloudApps",
4+
"subtitle": "Accompanying code for the CloudApp tutorials in the Developer Network",
5+
"description": "The Ex Libris Developer Network includes a number of detailed tutorials which demonstrate various capabilities of CloudApps. For more information, see https://developers.exlibrisgroup.com/cloudapps/tutorials/.",
66
"author": "Josh Weisman",
77
"contentSecurity": {
88
"sandbox": {
99
"popups": true
1010
}
11+
},
12+
"pages": {
13+
"settings": "/#/settings",
14+
"help": "https://github.com/ExLibrisGroup/cloudapp-tutorials"
15+
},
16+
"icon": {
17+
"type": "font",
18+
"value": "fa fa-graduation-cap"
1119
}
1220
}

0 commit comments

Comments
 (0)