Skip to content

Commit

Permalink
Questions integration #34 (#48)
Browse files Browse the repository at this point in the history
* Adds unit testing setup, initial questions service

* Adds a question controller
  • Loading branch information
th0rgall authored and oxnoctisxo committed Jul 24, 2017
1 parent 19e2fd4 commit 4e13afc
Show file tree
Hide file tree
Showing 23 changed files with 2,454 additions and 327 deletions.
2,240 changes: 2,108 additions & 132 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,32 @@
"zone.js": "0.8.12"
},
"devDependencies": {
"@angular/cli": "^1.2.1",
"@angular/cli": "^1.2.3",
"@ionic/app-scripts": "1.3.12",
"@ionic/cli-plugin-cordova": "1.4.1",
"@ionic/cli-plugin-ionic-angular": "1.3.2",
"typescript": "2.3.4"
"@types/jasmine": "^2.5.53",
"@types/node": "^8.0.15",
"angular-mocks": "^1.6.5",
"angular2-template-loader": "^0.6.2",
"codecov": "^2.2.0",
"jasmine-core": "^2.6.4",
"jasmine-spec-reporter": "^4.1.1",
"karma": "^1.7.0",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "^1.1.0",
"karma-mocha-reporter": "^2.2.3",
"karma-remap-istanbul": "^0.6.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.4",
"null-loader": "^0.1.1",
"sourcemap": "^0.1.0",
"ts-loader": "^2.3.1",
"ts-node": "^3.2.1",
"tslint": "^5.5.0",
"tslint-eslint-rules": "^4.1.1",
"typescript": "2.3.4",
"webpack": "^3.3.0"
},
"description": "An Ionic project",
"cordova": {
Expand All @@ -76,4 +97,4 @@
"android"
]
}
}
}
11 changes: 5 additions & 6 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import {NewStoryPage} from "../pages/new-story/new-story";
import {FileChooser} from "@ionic-native/file-chooser";
import {UtilService} from "../providers/util-service";

import {QuestionsPage} from "../pages/questions/questions";
import {QuestionPage} from "../pages/question/question";
import {NewStorySelectionPage} from "../pages/new-story-selection/new-story-selection";
import {EmptyPage} from "../pages/empty/empty";
import {ApiTestingPage} from "../pages/api-testing/api-testing";
Expand All @@ -36,6 +34,8 @@ import {FilePath} from "@ionic-native/file-path";
import {AlbumsPage} from "../pages/albums/albums";
import {AlbumDetailPage} from "../pages/album-detail/album-detail";
import { AuthService } from '../providers/auth-service/auth-service';
import { QuestionService } from "../providers/question-service/question.service";
import { AlbumQuestions } from "../pages/album-detail/album-questions";


@NgModule({
Expand All @@ -48,12 +48,11 @@ import { AuthService } from '../providers/auth-service/auth-service';
BrowsePage,
PatientProfilePage,
StoryDetailsPage,
QuestionsPage,
QuestionPage,
NewStoryPage,
EmptyPage,
NewStorySelectionPage,
ApiTestingPage,
AlbumQuestions
],
imports: [
BrowserModule,
Expand All @@ -72,17 +71,17 @@ import { AuthService } from '../providers/auth-service/auth-service';
PatientProfilePage,
StoryDetailsPage,
NewStoryPage,
QuestionsPage,
QuestionPage,
EmptyPage,
NewStorySelectionPage,
ApiTestingPage,
AlbumQuestions
],
providers: [
StatusBar,
SplashScreen,
UtilService,
StanizerService,
QuestionService,
PrismaService,
StoryService,
PatientService,
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ h1, h2, h3, .toolbar-title, ion-list-header .label, .tab-button-text {
// PAGE HEADER

.page-header {
padding: 2em 6em;
padding: 2em 3em;
//background-color: map-get($colors, 'primary');

}
Expand Down
5 changes: 1 addition & 4 deletions src/pages/album-detail/album-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
</ion-navbar>
</ion-header>
<ion-content>
<div class="page-header">
<h2>This is a test question? Or is it?</h2>
<ion-icon name="refresh"></ion-icon>
</div>
<album-questions [query]="album.title"></album-questions>
<ion-grid>
<ion-row>
<ion-col col-6 col-md-4 *ngFor="let story of album.stories,let i=index"
Expand Down
12 changes: 0 additions & 12 deletions src/pages/album-detail/album-detail.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ album-detail {
padding: 0;
}

.page-header {

ion-icon {
margin: auto;
font-size: 2em;
text-align: center;
color: map-get($colors, 'primary');
width: 100%;
}

}

.album-thumb {
height: 50vw; // todo: dynamic - set to width of comonent?
background-size: cover;
Expand Down
15 changes: 15 additions & 0 deletions src/pages/album-detail/album-questions.scss
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%;
}

}

}
34 changes: 34 additions & 0 deletions src/pages/album-detail/album-questions.ts
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 removed src/pages/album-detail/question.ts
Empty file.
Empty file.
Empty file.
17 changes: 0 additions & 17 deletions src/pages/question/question.html

This file was deleted.

31 changes: 0 additions & 31 deletions src/pages/question/question.scss

This file was deleted.

42 changes: 0 additions & 42 deletions src/pages/question/question.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/pages/questions/questions.html

This file was deleted.

6 changes: 0 additions & 6 deletions src/pages/questions/questions.scss

This file was deleted.

29 changes: 0 additions & 29 deletions src/pages/questions/questions.ts

This file was deleted.

49 changes: 49 additions & 0 deletions src/providers/question-service/question.service.ts
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());
}
));
}

}
Loading

0 comments on commit 4e13afc

Please sign in to comment.