-
Notifications
You must be signed in to change notification settings - Fork 10
Exercise 9 - Templates - Buying Socks #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jonathanrasquin
wants to merge
18
commits into
itenium-be:master
Choose a base branch
from
jonathanrasquin:feature/exercise9
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c7f00de
pipes jonathan
jonathanrasquin fd17ac6
ngfor - Jonathan
jonathanrasquin d3711d8
fix
jonathanrasquin 590b106
fix whitespace
jonathanrasquin 4dd8a00
fix again
jonathanrasquin 91bbc92
remove ngfor
jonathanrasquin e6591ce
Merge branch 'ngfor'
jonathanrasquin 8fb91ba
Merge branch 'ngfor' into templates-socks-shop
jonathanrasquin 0619dfc
exercise 4 - Templates - Socks Shop
jonathanrasquin 0ccd4c3
Merge branch 'templates-socks-shop'
jonathanrasquin f4b7742
exercise 5 - Templates - No image
jonathanrasquin b5bee77
Merge branch 'feature/exercise5'
jonathanrasquin c33298d
exercise 6 - Templates - DEV vs PRD
jonathanrasquin 08488f6
exercise 6 - simplify app components when using environment
jonathanrasquin 6ef26dc
Merge branch 'feature/exercise6'
jonathanrasquin 85d5a69
Merge remote-tracking branch 'origin/master'
jonathanrasquin 1d809ee
Revert "Merge remote-tracking branch 'origin/master'"
jonathanrasquin ac3fdba
Exercise 9 - Templates - Buying Socks
jonathanrasquin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <div class="modal-backdrop" (click)="onClose()"></div> | ||
| <div class="modal-content"> | ||
| <ng-content></ng-content> | ||
| <button (click)="onClose()">Close</button> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| .modal-backdrop { | ||
| position: fixed; | ||
| top: 0; | ||
| left: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| background: rgba(0, 0, 0, 0.5); | ||
| z-index: 1000; | ||
| } | ||
|
|
||
| .modal-content { | ||
| position: fixed; | ||
| top: 50%; | ||
| left: 50%; | ||
| transform: translate(-50%, -50%); | ||
| background: white; | ||
| padding: 20px; | ||
| z-index: 1001; | ||
| box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Component, EventEmitter, Output } from '@angular/core'; | ||
|
|
||
| @Component({ | ||
| standalone: true, | ||
| selector: 'app-modal', | ||
| templateUrl: './modal.component.html', | ||
| styleUrls: ['./modal.component.scss'] | ||
| }) | ||
| export class ModalComponent { | ||
| @Output() close = new EventEmitter<void>(); | ||
|
|
||
| onClose() { | ||
| this.close.emit(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,16 +38,29 @@ <h1 style="margin-top: 25px;">{{ sock.name }}</h1> | |
|
|
||
| <br> | ||
| <br> | ||
|
|
||
| <button type="button" class="buy-socks" (click)="buy()"> | ||
| <p *ngIf="sock.inventory === 0" class="badge">SOLD OUT</p> | ||
| <button type="button" class="buy-socks" (click)="buy()" *ngIf="sock.inventory > 0"> | ||
| BUY NOW | ||
| </button> | ||
| <div *ngIf="showAlert" [ngClass]="alertType" class="alert"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of hier gewoon: |
||
| {{ alertMessage }} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </section> | ||
|
|
||
|
|
||
| <app-modal *ngIf="showModal" (close)="onCloseModal()"> | ||
| <h2>Enter Bank Details</h2> | ||
| <p>Free shipping and return policy!</p> | ||
| <!-- Add form for bank details here --> | ||
| <button (click)="onConfirmPurchase()">Confirm Purchase</button> | ||
| </app-modal> | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| <section class="contact_section" style="margin-bottom: 36px"> | ||
| <div class="container px-0"> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| .badge { | ||
| display: inline-block; | ||
| padding: 0.25em 0.4em; | ||
| font-size: 75%; | ||
| font-weight: 700; | ||
| line-height: 1; | ||
| text-align: center; | ||
| white-space: nowrap; | ||
| vertical-align: baseline; | ||
| border-radius: 0.25rem; | ||
| background-color: red; | ||
| color: white; | ||
| } | ||
|
|
||
| .alert { | ||
| position: fixed; | ||
| top: 20px; | ||
| left: 10%; | ||
| transform: translateX(-50%); | ||
| padding: 10px; | ||
| background-color: #28a745; /* Success background color */ | ||
| color: white; | ||
| border-radius: 5px; | ||
| } | ||
|
|
||
| .alert.success { | ||
| background-color: #28a745; | ||
| } | ||
|
|
||
| .alert.failure { | ||
| background-color: #dc3545; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,16 +2,23 @@ import { Component } from '@angular/core'; | |
| import { Observable } from 'rxjs'; | ||
| import { Sock } from './sock.model'; | ||
| import { SocksService } from './socks.service'; | ||
| import { AsyncPipe, NgIf, TitleCasePipe } from '@angular/common'; | ||
| import { AsyncPipe, NgIf, TitleCasePipe, CommonModule } from '@angular/common'; | ||
| import { ModalComponent } from '../modal/modal.component'; | ||
|
|
||
|
|
||
| @Component({ | ||
| selector: 'app-sock', | ||
| standalone: true, | ||
| imports: [NgIf, AsyncPipe, TitleCasePipe], | ||
| templateUrl: './sock.component.html' | ||
| imports: [NgIf, AsyncPipe, TitleCasePipe, ModalComponent, CommonModule], | ||
| templateUrl: './sock.component.html', | ||
| styleUrls: ['./sock.component.scss'] | ||
| }) | ||
| export class SockComponent { | ||
| sock$!: Observable<Sock>; | ||
| showModal = false; | ||
| showAlert = false; | ||
| alertMessage = ''; | ||
| alertType = ''; | ||
|
|
||
| constructor(private socksService: SocksService) {} | ||
|
|
||
|
|
@@ -22,8 +29,26 @@ export class SockComponent { | |
| } | ||
|
|
||
| buy(): void { | ||
| this.showModal = true; | ||
|
|
||
| } | ||
|
|
||
| onCloseModal() { | ||
| this.showModal = false; | ||
| } | ||
|
|
||
| onConfirmPurchase() { | ||
| const sockId = +window.location.pathname.split('/')[2]; | ||
| this.socksService.buySocks(sockId).subscribe(); | ||
| this.showModal = false; | ||
| this.showAlertMessage('Purchase successful!', 'success'); | ||
| } | ||
|
|
||
| showAlertMessage(message: string, type: string) { | ||
| this.alertMessage = message; | ||
| this.alertType = type; | ||
| this.showAlert = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minder fields, minder dingen om in sync te houden:: get showAlert(): boolean {
return !!this.alertMessage;
} |
||
| setTimeout(() => this.showAlert = false, 3000); | ||
| } | ||
|
|
||
| addReview(): void { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je hoeft niet altijd een functie te gebruiken:
(is waarschijnlijk ook (persoonlijke) smaak)