-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds unit testing setup, initial questions service * Adds a question controller
- Loading branch information
1 parent
19e2fd4
commit 4e13afc
Showing
23 changed files
with
2,454 additions
and
327 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
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,15 @@ | ||
album-questions { | ||
|
||
.page-header { | ||
|
||
ion-icon { | ||
margin: auto; | ||
font-size: 2em; | ||
text-align: center; | ||
color: map-get($colors, 'primary'); | ||
width: 100%; | ||
} | ||
|
||
} | ||
|
||
} |
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,34 @@ | ||
import { QuestionService } from "../../providers/question-service/question.service"; | ||
import { OnInit, Component, Input } from "@angular/core"; | ||
|
||
@Component({ | ||
selector: 'album-questions', | ||
template: ` | ||
<div class="page-header" *ngIf="currentQuestion"> | ||
<h2>{{currentQuestion}}</h2> | ||
<ion-icon name="refresh" (click)="nextQuestion()"></ion-icon> | ||
</div> | ||
` | ||
}) | ||
|
||
export class AlbumQuestions implements OnInit { | ||
|
||
currentQuestion: string = ""; | ||
questions: string[]; | ||
|
||
@Input() query: string; | ||
|
||
constructor(private questionService: QuestionService) {} | ||
|
||
ngOnInit(): void { | ||
this.questions = this.questionService.getQuestions(this.query); | ||
this.nextQuestion(); | ||
} | ||
|
||
nextQuestion() { | ||
// TODO: implement a random question that avoids repetition | ||
this.currentQuestion = this.questions[Math.floor(Math.random() * this.questions.length)]; | ||
} | ||
|
||
|
||
} |
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { QUESTIONS } from "./questions.json"; | ||
|
||
@Injectable() | ||
export class QuestionService { | ||
|
||
constructor() { } | ||
|
||
private questions = QUESTIONS; | ||
|
||
getQuestions(query: string): string[] { | ||
|
||
let matchingCategories = this.questions.filter(category => | ||
this.containsQuery(query, category.keywords) | ||
); | ||
|
||
// return questions from matching categories | ||
if (matchingCategories.length > 0) { | ||
|
||
// a flatmap from [ {"questions": ["q1", "q2", ... ] }, { ... }, { ...}] to [ "q1", "q2", .., "qx"] | ||
return [].concat.apply([], matchingCategories.map(mc => mc.questions)); | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
|
||
/* keywords ==> questions | ||
if query name consists of any of the keywords, find the questions | ||
=> regex for each question-category - temp but easy solution*/ | ||
|
||
/* | ||
A function that get a single query string, | ||
and checks whether one of some given keywords can be found in it. | ||
Note: not capital sensitive | ||
*/ | ||
|
||
private containsQuery(query: string, keywords: string[]): boolean { | ||
|
||
return Boolean(keywords.find( kw => { | ||
let reg = new RegExp(kw.toLowerCase()); | ||
return reg.test(query.toLowerCase()); | ||
} | ||
)); | ||
} | ||
|
||
} |
Oops, something went wrong.