This repository has been archived by the owner on Oct 28, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add star rating, comment section and submit directive - #102
- Loading branch information
Ainel
committed
Apr 25, 2020
1 parent
485daf0
commit 3818ed1
Showing
9 changed files
with
166 additions
and
52 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,23 @@ | ||
<section id="star-rating"> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<p class="lead">Rate this question:</p> | ||
<span class="star text-warning" [ngClass]="{'rated': rated}" *ngFor="let star of stars; let i=index"> | ||
<fa-icon *ngIf="!star" [icon]="['far', 'star']" (click)="!rated ? select(i) : ''"></fa-icon> | ||
<fa-icon *ngIf="star" [icon]="['fas', 'star']" (click)="!rated ? select(i) : ''"></fa-icon> | ||
</span> | ||
<p *ngIf="rated" class="lead">Thank you for rating!</p> | ||
</div> | ||
<div class="col-12 col-sm-4 my-3" *ngIf="selected && !rated"> | ||
<form> | ||
<div class="form-group"> | ||
<label for="rating-comment">Tell us more (optional):</label> | ||
<textarea class="form-control" id="rating-comment" rows="3" placeholder="Let us know what you liked or we can improve..."></textarea> | ||
</div> | ||
<button type="submit" class="btn btn-primary btn-block" (click)="submit()">Submit</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</section> |
This file contains 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,10 @@ | ||
#star-rating { | ||
.star { | ||
cursor: pointer; | ||
font-size: 2rem; | ||
|
||
&.rated { | ||
pointer-events: none; | ||
} | ||
} | ||
} |
This file contains 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,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { RatingComponent } from './rating.component'; | ||
|
||
describe('RatingComponent', () => { | ||
let component: RatingComponent; | ||
let fixture: ComponentFixture<RatingComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ RatingComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(RatingComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains 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,36 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-rating', | ||
templateUrl: './rating.component.html', | ||
styleUrls: ['./rating.component.scss'] | ||
}) | ||
export class RatingComponent implements OnInit { | ||
|
||
stars: boolean[]; | ||
selected: boolean = false; | ||
rated: boolean = false; | ||
|
||
constructor() { | ||
this.stars = [false, false, false, false, false]; | ||
} | ||
|
||
ngOnInit() { | ||
} | ||
|
||
select(selectedStar: number) { | ||
for(let i = 0; i < this.stars.length; i++) { | ||
if(i <= selectedStar) { | ||
this.stars[i] = true; | ||
} else { | ||
this.stars[i] = false; | ||
} | ||
} | ||
this.selected = true; | ||
} | ||
|
||
submit() { | ||
// TODO: POST REQUEST to API | ||
this.rated = true; | ||
} | ||
} |