Skip to content

Commit

Permalink
fix demo and tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrehault committed Jun 20, 2020
1 parent 33aa15f commit 73c4c79
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.3.2 (2020-06-20)

### Improvement
- Better demo and turorial
- More utilities (getContextAs, addInContext, and deleteContext)
- add refreshChildren method in folder view

# 1.3.1 (2020-05-28)

### Improvement
Expand Down
22 changes: 14 additions & 8 deletions docs/TUTORAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export class TeamComponent extends FolderView {

Note we do not need the equivalent of `loadTeams` method here, as we just use the `refreshChildren` provided by `FolderView`.

To make it look better, let's use Pastanaga expand panels (note: we must import `ExpandModule` in `app.module.ts`):
To make it look better, let's use Pastanaga expand panels (note: we must import `ExpandModule` plus Angular's `BrowserAnimationsModule` in `app.module.ts`):

```html
<h2>{{ (context | async).title }}</h2>
Expand All @@ -373,7 +373,7 @@ Note badges are now links to traverse to players "edit" view:
[traverseTo]="player['@id'] + '/@@edit'"
```

Let's implement a component for that.
But if we click, we get the default Pastanaga Edit view, and we want our own form here. Let's implement a component for that.

### Player

Expand All @@ -392,7 +392,7 @@ This component is a form allowing to enter player's name and rank or to delete t
<pa-button (click)="delete()" color="destructive">Delete</pa-button>
```

Let's make it extend `BaseView` so we can access the view context easily. The context is always typed as `any`.
Let's make it extend `ViewView` so we can access the view context easily. The context is always typed as `any`.
As we know the context is a player object, it would be nice to map it to a custom `Player` interface:

```ts
Expand All @@ -404,7 +404,7 @@ interface Player extends Resource {
selector: 'app-player',
templateUrl: 'player.component.html'
})
export class PlayerComponent extends BaseView implements OnInit {
export class PlayerComponent extends ViewView implements OnInit {
title = '';
rank = 0;
player = this.context.pipe(map(res => res as Player));
Expand Down Expand Up @@ -441,7 +441,6 @@ If we want to take an action after saving – like redirecting to the home page
save() {
this.grange.updateContext({
title: this.title,
team: this.team,
rank: this.rank,
}).onComplete.subscribe(success => {
if (success) {
Expand Down Expand Up @@ -508,7 +507,14 @@ It is not a view, so we will have to inject the Grange service ourselves:
constructor(private grange: Grange) { }
```

To create th elist of radio buttons, we get all the items from our Guillotina root container that are Teams and we map them to `ControlModel`:
We get the current player fromn the context (and add a `newTeam` attribute to store the user's selection):

```ts
player = this.grange.getContext();
newTeam = '';
```

To create the list of radio buttons, we get all the items from our Guillotina root container that are Teams and we map them to `ControlModel`:

```ts
teams: Observable<ControlModel[]> = this.grange.core.resource.items('/').pipe(
Expand Down Expand Up @@ -605,10 +611,10 @@ This view displays all team contests in a table, and the last table row allows t

Note: to use `pa-icon`, we have to import `SvgModule` in `app.module.ts`.

`TeamContestsComponent` extends `BaseView` so we can use the context, and we get the `contests` value (which is a dictionnary) and turn it into a list.
`TeamContestsComponent` extends `ViewView` so we can use the context, and we get the `contests` value (which is a dictionnary) and turn it into a list.

```ts
export class TeamContestsComponent extends BaseView {
export class TeamContestsComponent extends ViewView {
year = '';
victory = false;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"@angular/platform-browser-dynamic": "~9.0.4",
"@angular/router": "~9.0.4",
"@briebug/jest-schematic": "^2.1.0",
"@guillotinaweb/grange-core": "latest",
"@guillotinaweb/grange-core": "^1.2.3",
"@guillotinaweb/grange-form": "latest",
"@guillotinaweb/ngx-state-traverser": "latest",
"@guillotinaweb/ngx-state-traverser": "^1.2.5",
"@guillotinaweb/pastanaga-angular": "^1.18.2",
"@ngrx/core": "^1.2.0",
"@ngrx/effects": "^8.4.0",
"@ngrx/store": "^8.4.0",
"@ngrx/effects": "^8.6.0",
"@ngrx/store": "^8.6.0",
"angular-svg-icon": "^8.0.0",
"angular-traversal": "latest",
"date-fns": "^2.9.0",
Expand Down
1 change: 1 addition & 0 deletions projects/demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { AngularSvgIconModule } from 'angular-svg-icon';
BACKEND_URL: environment.backend,
CLIENT_TIMEOUT: 5000,
LOGO: 'assets/logo.svg',
SOCIAL_LOGIN: false,
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions projects/demo/src/app/player/player.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { BaseView } from '../../../../grange/src';
import { ViewView } from '../../../../grange/src';
import { Resource } from '@guillotinaweb/grange-core';
import { map } from 'rxjs/operators';
import { MovePlayerComponent } from './move-player.dialog';
Expand All @@ -12,7 +12,7 @@ interface Player extends Resource {
selector: 'app-player',
templateUrl: 'player.component.html'
})
export class PlayerComponent extends BaseView implements OnInit {
export class PlayerComponent extends ViewView implements OnInit {
title = '';
rank = 0;
player = this.context.pipe(map(res => res as Player));
Expand Down
4 changes: 2 additions & 2 deletions projects/demo/src/app/team/team-contests.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Component } from '@angular/core';
import { BaseView } from '../../../../grange/src';
import { ViewView } from '../../../../grange/src';
import { map } from 'rxjs/operators';

@Component({
selector: 'app-team-contests',
templateUrl: 'team-contests.component.html',
})
export class TeamContestsComponent extends BaseView {
export class TeamContestsComponent extends ViewView {
year = '';
victory = false;

Expand Down
2 changes: 1 addition & 1 deletion projects/grange/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@guillotinaweb/grange",
"version": "1.3.1",
"version": "1.3.2",
"license": "MIT",
"author": {
"name": "Eric Brehault",
Expand Down

0 comments on commit 73c4c79

Please sign in to comment.