Skip to content

Commit c068595

Browse files
committed
feat(server, modal): added modal on remove hero and moved server files because of watch
1 parent 643d1e9 commit c068595

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"angular-cli": {},
66
"scripts": {
77
"start": "npm run server | npm run ng",
8-
"server": "json-server --port 3000 --watch src/server/db.json --routes src/server/routes.json",
8+
"server": "json-server --port 3000 --watch server/db.json --routes server/routes.json",
99
"ng": "ng serve --proxy-config proxy.conf.json",
1010
"tslint": "tslint \"src/**/*.ts\"; exit 0",
1111
"test": "ng test",
File renamed without changes.
File renamed without changes.

src/app/heroes/hero-list/hero-list.component.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,31 @@ <h3>Pick a highlight color</h3>
4141
<i class="fa fa-pencil-square-o" aria-hidden="true"></i>
4242
</button>
4343
<button class="btn btn-danger"
44-
(click)="remove(hero); $event.stopPropagation()">
44+
(click)="showRemoveModal(hero)">
4545
<i class="fa fa-times" aria-hidden="true"></i>
4646
</button>
4747
</div>
48+
<div class="modal fade" id="askForRemove" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
49+
<div class="modal-dialog" role="document">
50+
<div class="modal-content">
51+
<div class="modal-header">
52+
<h5 class="modal-title" id="exampleModalLabel">Alert</h5>
53+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
54+
<span aria-hidden="true">&times;</span>
55+
</button>
56+
</div>
57+
<div class="modal-body">
58+
Do you want to remove the hero?
59+
</div>
60+
<div class="modal-footer">
61+
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
62+
<button type="button" class="btn btn-primary" (click)="remove()">
63+
Remove hero
64+
</button>
65+
</div>
66+
</div>
67+
</div>
68+
</div>
4869
</li>
4970
</ul>
5071
</div>

src/app/heroes/hero-list/hero-list.component.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {IAppConfig} from '../../config/iapp.config';
66

77
import {Hero} from '../shared/hero.model';
88
import {HeroService} from '../shared/hero.service';
9+
declare const $:any;
910

1011
@Component({
1112
selector: 'toh-hero-list',
@@ -16,6 +17,7 @@ import {HeroService} from '../shared/hero.service';
1617
export class HeroListComponent implements OnInit {
1718
heroes: Hero[];
1819
selectedHero: Hero;
20+
heroToRemove: Hero;
1921
color: string;
2022
createNewHero: boolean;
2123

@@ -40,14 +42,20 @@ export class HeroListComponent implements OnInit {
4042
this.router.navigate([`/${this.appConfig.routes.heroes}/`, this.selectedHero.id]);
4143
}
4244

43-
remove(hero: Hero): void {
45+
remove(): void {
46+
$('#askForRemove').modal('hide');
4447
this.heroService
45-
.remove(hero.id)
48+
.remove(this.heroToRemove.id)
4649
.then(() => {
47-
this.heroes = this.heroes.filter(h => h !== hero);
48-
if (this.selectedHero === hero) {
50+
this.heroes = this.heroes.filter(h => h !== this.heroToRemove);
51+
if (this.selectedHero === this.heroToRemove) {
4952
this.selectedHero = null;
5053
}
5154
});
5255
}
56+
57+
showRemoveModal(hero: Hero): void {
58+
this.heroToRemove = hero;
59+
$('#askForRemove').modal('show');
60+
}
5361
}

0 commit comments

Comments
 (0)