-
- “ ' + joke.joke">
+ “ ' + (joke.joke | shyriiwook: chewie)">
-
+
0">
diff --git a/src/pages/joke/joke.module.ts b/src/pages/joke/joke.module.ts
index dce3d06..4bb5c10 100644
--- a/src/pages/joke/joke.module.ts
+++ b/src/pages/joke/joke.module.ts
@@ -2,19 +2,18 @@ import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { JokePage } from './joke';
import { ComponentsModule } from "../../components/components.modules";
-import { SwJokeProvider } from "../../providers/sw-joke/sw-joke";
+import { ShyriiwookPipe } from "../../pipes/shyriiwook/shyriiwook";
@NgModule({
declarations: [
JokePage,
+ ShyriiwookPipe
],
imports: [
IonicPageModule.forChild(JokePage),
ComponentsModule,
],
- providers: [
- SwJokeProvider
- ],
+ providers: [],
exports: [
JokePage
]
diff --git a/src/pages/joke/joke.scss b/src/pages/joke/joke.scss
index b488bdd..eef4909 100644
--- a/src/pages/joke/joke.scss
+++ b/src/pages/joke/joke.scss
@@ -9,6 +9,15 @@ page-joke {
width: auto;
margin-right: 1em;
}
+ #jokeBtn {
+ width:90%;
+ .button-inner {
+ span {
+ display: inline-block;
+ white-space: normal;
+ }
+ }
+ }
p {
font-style: italic;
font-size: 1.5em;
@@ -18,4 +27,10 @@ page-joke {
p span.quote {
font-size: 2em;
}
+
+ ion-list-header.item-md {
+ background-color: transparent;
+ border-top: none;
+ color: #444;
+ }
}
diff --git a/src/pages/joke/joke.ts b/src/pages/joke/joke.ts
index 7865d59..fcf7aa9 100644
--- a/src/pages/joke/joke.ts
+++ b/src/pages/joke/joke.ts
@@ -1,8 +1,11 @@
import { Component } from '@angular/core';
-import { IonicPage, NavController, NavParams } from 'ionic-angular';
+import { IonicPage, NavController, NavParams, Events } from 'ionic-angular';
import { SwJokeProvider } from "../../providers/sw-joke/sw-joke";
import * as _ from 'lodash';
+import { GlobalScopeService } from "../../providers/global-scope-service/global-scope-service";
+import { Subscription } from "rxjs/Subscription";
+import { BasePage } from "../base/base";
/**
* Generated class for the JokePage page.
@@ -13,36 +16,67 @@ import * as _ from 'lodash';
@IonicPage()
@Component({
selector: 'page-joke',
- templateUrl: 'joke.html',
+ templateUrl: 'joke.html'
})
-export class JokePage {
- public joke: any = {};
+export class JokePage extends BasePage {
+ joke: any = {};
+ isJedi: boolean = false;
+ isJedi$: Subscription;
- constructor(public navCtrl: NavController, public navParams: NavParams, public jokeProvider: SwJokeProvider) {
+ chewie: boolean = false;
+ chewie$: Subscription;
+
+
+
+ variables: any;
+
+ constructor(public navCtrl: NavController, public navParams: NavParams, public jokeProvider: SwJokeProvider, private rootScope: GlobalScopeService,
+ eventsCtrl: Events) {
+
+ super(eventsCtrl);
+
+ this.isJedi = rootScope.getItem('isJedi');
+ this.isJedi$ = rootScope.watch('isJedi').subscribe(variable => {
+ this.isJedi = (variable != undefined) ? variable.value : undefined;
+ });
+
+ this.chewie = this.rootScope.getItem('chewieMode');
+ if(this.rootScope.getItem('chewieMode') === undefined) {
+ this.chewie = false;
+ this.rootScope.setItem('chewieMode', this.chewie);
+ }
+ this.chewie$ = this.rootScope.watch('chewieMode')
+ .subscribe(chewie => {
+ this.chewie = (chewie != undefined) ? chewie.value : false;
+ });
+
}
- ionViewDidLoad() {
- console.log('ionViewDidLoad JokePage');
+ ionViewWillLeave() {
+ //if(!!this.isJedi$){
+ this.isJedi$.unsubscribe();
+ this.chewie$.unsubscribe();
+ //}
}
- getNewJoke() {
- console.log('getNewJoke');
+ ionViewDidLoad() {}
+
+ getNewJoke() {
this.joke = this.jokeProvider.getJoke();
}
- ionViewWillEnter(): void {
- console.log('ionViewWillEnter JokePage', this.navParams);
- if(!!this.navParams.data && this.navParams.data.back){
- console.log(this.joke);
- if(!!!this.navParams.data.joke.joke) {
- console.log('Loading new joke, from back button.');
+ ionViewWillEnter(): void {
+ if(!!this.navParams.data && this.navParams.data.back){
+ if(!!!this.navParams.data.joke.joke) {
this.getNewJoke();
} else {
- this.joke = this.navParams.data.joke;
- console.log('Do nothing. Back from Joke annotations.');
+ this.joke = this.navParams.data.joke;
}
- } else {
- console.log('Loading new joke');
+ } else {
+ this.getNewJoke();
+ }
+
+ if(!!!this.joke){
this.getNewJoke();
}
@@ -50,7 +84,7 @@ export class JokePage {
loadMoreInfo(refData: any) {
_.assign(refData, { joke: this.joke });
- this.navCtrl.push('MoreInfoPage', refData);
+ this.navCtrl.setRoot('MoreInfoPage', refData);
}
}
diff --git a/src/pages/more-info/more-info.scss b/src/pages/more-info/more-info.scss
index a4557ed..8035519 100644
--- a/src/pages/more-info/more-info.scss
+++ b/src/pages/more-info/more-info.scss
@@ -14,7 +14,7 @@ page-more-info {
}
ion-col h2 {
padding-top: 0.9em;
- color: #fff;
+ color: #cecece;
}
padding: 0;
}
@@ -26,4 +26,13 @@ page-more-info {
padding-left: 1.5em;
}
+ ion-list-header.list-header.item-md {
+ background-color: transparent;
+ margin-bottom: 0;
+ }
+
+ ion-list.list-md {
+ margin-top: 0;
+ }
+
}
diff --git a/src/pages/more-info/more-info.ts b/src/pages/more-info/more-info.ts
index c1967a1..44afcf8 100644
--- a/src/pages/more-info/more-info.ts
+++ b/src/pages/more-info/more-info.ts
@@ -1,8 +1,11 @@
import { Component } from '@angular/core';
-import { IonicPage, NavController, NavParams } from 'ionic-angular';
+import { IonicPage, NavController, NavParams, Events } from 'ionic-angular';
import { SwApiServiceProvider } from "../../providers/sw-api-service/sw-api-service";
import * as _ from 'lodash';
+import { GlobalScopeService } from "../../providers/global-scope-service/global-scope-service";
+import { Subscription } from "rxjs/Subscription";
+import { BasePage } from "../base/base";
/**
* Generated class for the MoreInfoPage page.
@@ -15,63 +18,65 @@ import * as _ from 'lodash';
selector: 'page-more-info',
templateUrl: 'more-info.html',
})
-export class MoreInfoPage {
+export class MoreInfoPage extends BasePage {
category: string;
queryUrl: string;
ellapsed: number;
response: Array;
- constructor(public navCtrl: NavController, public navParams: NavParams, private swApiService: SwApiServiceProvider) {
- }
+ chewie$: Subscription;
- ionViewDidLoad() {
- console.log('ionViewDidLoad MoreInfoPage');
+ constructor(public navCtrl: NavController, public navParams: NavParams, private swApiService: SwApiServiceProvider, private rootScope: GlobalScopeService,
+ eventsCtrl: Events) {
+ super(eventsCtrl);
}
- ionViewWillEnter(): void {
- console.log('ionViewWillEnter MoreInfoPage');
- console.log(this.navParams);
-
- let params = this.navParams.data;
- let self: any = this;
+ ionViewDidLoad() { }
- this.category = params.category;
- this.queryUrl = params.url;
+ ionViewWillLeave() {
+ //if(!!this.chewie$){
+ this.chewie$.unsubscribe();
+ //}
+ }
+ retrieveData(category: string, queryUrl: string) {
- this.swApiService.retrieveData(this.category + this.queryUrl).then(res => {
- console.log('Query is done ', self.queryUrl, res);
+ this.swApiService.retrieveData(category + queryUrl).then(res => {
this.response = _.map(res['results'], (v, k) => {
- console.log('v, k', v, k);
- let adjustedData = _.map(_.omit(v, ['films', 'people', 'species', 'starships', 'planets', 'vehicles', 'opening_crawl', 'characters', 'pilots', 'homeworld', 'created', 'edited', 'url']), (vv, kk) => {
- console.log('vv, kk', vv, kk);
+
+ let exceptions = ['films', 'people', 'species', 'starships', 'planets', 'vehicles', 'opening_crawl', 'characters', 'pilots', 'homeworld', 'created', 'edited', 'url'];
+ let shyriiwookExceptions = ['wwahanscc', 'akwoooakanwo', 'cakwooaahwoc', 'caorarccacahakc', 'akanrawhwoaoc', 'howoacahoaanwoc', 'ooakwowhahwhrroarcraohan', 'oaacrarcraoaaoworcc', 'akahanooaoc', 'acooscwoohoorcanwa', 'oarcworaaowowa', 'wowaahaowowa', 'hurcan'];
+ let adjustedData = _.map(_.omit(v, _.concat([], exceptions, shyriiwookExceptions)), (vv, kk) => {
return {
label: kk.replace(/_/g, ' '),
value: vv
};
});
- console.log('adjustedData', adjustedData);
+
return { data: adjustedData };
- });
-
- console.log('Adjusted response data: ', this.response)
+ });
});
- //Store data
- //Get keys from data
- //Adjust key text (replace _)
- // Iterate over response using only the keys
- // or iterate over an adjusted arrray
+ }
+
+ ionViewWillEnter(): void {
+ let params = this.navParams.data;
+
+ this.category = params.category;
+ this.queryUrl = params.url;
+
+ //this.retrieveData(this.category, this.queryUrl);
+ this.chewie$ = this.rootScope.watch('chewieMode').subscribe(chewie => {
+ this.retrieveData(this.category, this.queryUrl);
+ });
}
goBack() {
- this.navCtrl.push('JokePage', { back: true, joke: this.navParams.data.joke });
+ this.navCtrl.setRoot('JokePage', { back: true, joke: this.navParams.data.joke });
}
-
-
}
diff --git a/src/pages/splash/splash.ts b/src/pages/splash/splash.ts
index 61feb2d..0d85292 100644
--- a/src/pages/splash/splash.ts
+++ b/src/pages/splash/splash.ts
@@ -1,5 +1,6 @@
import { Component } from '@angular/core';
-import { IonicPage, NavController, NavParams } from 'ionic-angular';
+import { IonicPage, NavController, NavParams, Events } from 'ionic-angular';
+import { BasePage } from "../base/base";
/**
* Generated class for the SplashPage page.
@@ -12,13 +13,17 @@ import { IonicPage, NavController, NavParams } from 'ionic-angular';
selector: 'page-splash',
templateUrl: 'splash.html',
})
-export class SplashPage {
+export class SplashPage extends BasePage {
public showBtn: boolean = false;
- constructor(public navCtrl: NavController, public navParams: NavParams) {}
+ constructor(public navCtrl: NavController, public navParams: NavParams, eventsCtrl: Events) {
+ super(eventsCtrl);
+ }
+
+
showHideBtn() {
this.showBtn = false;
diff --git a/src/pipes/shyriiwook/shyriiwook.ts b/src/pipes/shyriiwook/shyriiwook.ts
new file mode 100644
index 0000000..87a3e52
--- /dev/null
+++ b/src/pipes/shyriiwook/shyriiwook.ts
@@ -0,0 +1,46 @@
+import { Pipe, PipeTransform } from '@angular/core';
+import * as _ from 'lodash';
+
+/**
+ * Generated class for the ShyriiwookPipe pipe.
+ *
+ * See https://angular.io/docs/ts/latest/guide/pipes.html for more info on
+ * Angular Pipes.
+ */
+@Pipe({
+ name: 'shyriiwook',
+ pure: false
+})
+export class ShyriiwookPipe implements PipeTransform {
+
+ // Ref.: https://github.com/dmke/wookie-translator/blob/master/lib/wookie/dialects/simple.rb
+ static wookieMap:any = {
+ 'a' : 'ra', 'b' : 'rh', 'c' : 'oa', 'd' : 'wa', 'e' : 'wo', 'f' : 'ww',
+ 'g' : 'rr', 'h' : 'ac', 'i' : 'ah', 'j' : 'sh', 'k' : 'or', 'l' : 'an',
+ 'm' : 'sc', 'n' : 'wh', 'o' : 'oo', 'p' : 'ak', 'q' : 'rq', 'r' : 'rc',
+ 's' : 'c', 't' : 'ao', 'u' : 'hu', 'v' : 'ho', 'w' : 'oh', 'x' : 'k',
+ 'y' : 'ro', 'z' : 'uf'
+ };
+
+ private toShyriiwook(text: string): string {
+ let translatedText: string = text;
+ let translatedTextArr: Array = _.map(text.split(''), (v: string) => {
+ let origChar: string = ShyriiwookPipe.wookieMap[v.toLowerCase()];
+ let tChar: string = (!origChar) ? v : origChar;
+ //tChar = (!!origChar && v === v.toUpperCase()) ? _.startCase(tChar) : tChar;
+ // Proper names mantain the original character
+ tChar = (!!origChar && v === v.toUpperCase()) ? v : tChar;
+
+ return tChar;
+ });
+
+ translatedText = translatedTextArr.join('');
+ translatedText = translatedText.replace(//g,'
');
+
+ return translatedText;
+ }
+
+ transform(value: string, translate?: boolean | false) {
+ return (!!value && translate) ? this.toShyriiwook(value) : value;
+ }
+}
diff --git a/src/providers/global-scope-service/global-scope-service.ts b/src/providers/global-scope-service/global-scope-service.ts
new file mode 100644
index 0000000..aefc98d
--- /dev/null
+++ b/src/providers/global-scope-service/global-scope-service.ts
@@ -0,0 +1,94 @@
+import { BehaviorSubject } from "rxjs/BehaviorSubject";
+import { Injectable } from "@angular/core";
+import * as _ from 'lodash';
+import { Subscription } from "rxjs/Subscription";
+import { Observable } from "rxjs/Observable";
+import { Subscriber } from "rxjs/Subscriber";
+
+/*
+ Generated class for the GlobalScopeServiceProvider provider.
+
+ See https://angular.io/docs/ts/latest/guide/dependency-injection.html
+ for more info on providers and Angular 2 DI.
+*/
+// Ref.: https://coryrylan.com/blog/angular-observable-data-services
+// Most logic based on http://stackoverflow.com/questions/34434057/angular-2-x-watching-for-variable-change
+export interface Data {
+ key: string,
+ value: any
+}
+
+@Injectable()
+export class GlobalScopeService {
+
+ private keyIndex: any;
+ private dataArray: Array>;
+ private dataObservables: Array>;
+
+ constructor() {
+ this.keyIndex = {};
+ this.dataArray = [];
+ this.dataObservables = [];
+ }
+
+ // TODO Use Ionic Cache
+ // Ref. :https://github.com/Nodonisko/ionic-cache
+ setItem(key: string, data:any) {
+ let dataObj: Data = {
+ key: key,
+ value: data
+ };
+ let idx: number;
+
+ if(_.find(this.dataArray, { value: { key: key } }) === undefined) {
+ let changeSubject = new BehaviorSubject(dataObj);
+ this.dataArray.push(changeSubject);
+ this.dataObservables.push(changeSubject.asObservable());
+
+ idx = this.dataArray.length - 1;
+ this.keyIndex[key] = idx;
+ } else {
+ idx = this.keyIndex[key];
+ }
+ this.dataArray[idx].next(dataObj);
+
+ }
+
+ getItem(key: string): any {
+ let idx: number = this.keyIndex[key];
+ return (!!this.dataArray[idx]) ? this.dataArray[idx].value.value : undefined;
+ }
+
+ clearItem(key: string) {
+ this.setItem(key, undefined);
+ }
+
+ getAll() {
+ return _.map(this.dataArray, (v) => { return v.value; });
+ }
+
+ watch(variable: string): any {
+ let idx: number = this.keyIndex[variable];
+ try{
+ // let watchVar: Observable = this.dataObservables[idx];
+ // return watchVar;
+ return this.dataArray[idx].asObservable();
+ } catch(err) {
+ throw new Error('Variable ' + variable + ' not present. Try setItem("' + variable + '", this.' + variable + ') first.');
+ }
+
+ }
+
+ unWatch(variable: string): void {
+ console.log('unWatch ', variable);
+ let idx: number = this.keyIndex[variable];
+ try{
+ let dataValue = this.dataArray[idx].value;
+ this.dataArray[idx].next(dataValue);
+ this.dataArray[idx].complete();
+ } catch(err) {
+ throw new Error('Variable ' + variable + ' not present. Try setItem("' + variable + '", this.' + variable + ') first.');
+ }
+ }
+
+}
diff --git a/src/providers/sw-api-service/sw-api-service.ts b/src/providers/sw-api-service/sw-api-service.ts
index faf0211..ff182ca 100644
--- a/src/providers/sw-api-service/sw-api-service.ts
+++ b/src/providers/sw-api-service/sw-api-service.ts
@@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
+import { GlobalScopeService } from "../global-scope-service/global-scope-service";
+import { Subscription } from "rxjs/Subscription";
/*
Generated class for the SwApiServiceProvider provider.
@@ -12,9 +14,17 @@ import 'rxjs/add/operator/map';
export class SwApiServiceProvider {
private baseUrl: string = 'http://swapi.co/api/';
private data: any;
+ private wookiee: string;
+ private wookiee$: Subscription;
- constructor(public http: Http) {
- console.log('Hello SwApiServiceProvider Provider');
+ constructor(public http: Http, private rootScope: GlobalScopeService) {
+ this.wookiee = (this.rootScope.getItem('chewieMode')) ? '?format=wookiee' : '';
+ if(this.rootScope.getItem('chewieMode') === undefined) {
+ this.rootScope.setItem('chewieMode', false);
+ }
+ this.wookiee$ = this.rootScope.watch('chewieMode').subscribe(chewie => {
+ this.wookiee = (!!chewie && chewie.value) ? 'format=wookiee' : '';
+ });
}
retrieveData(queryUrl) {
@@ -28,8 +38,19 @@ export class SwApiServiceProvider {
// We're using Angular HTTP provider to request the data,
// then on the response, it'll map the JSON data to a parsed JS object.
// Next, we process the data and resolve the promise with the new data.
- this.http.get(this.baseUrl + queryUrl)
- .map(res => res.json())
+ let and: string = (this.wookiee !== '') ? (queryUrl.indexOf('?') !== -1) ? '&' : '?' : '';
+ this.http.get(this.baseUrl + queryUrl + and + this.wookiee)
+ .map(res => {
+ let responseString = res['_body'];
+ if(responseString.indexOf('whhuanan') !== -1 || responseString.indexOf('rcwochuanaoc') !== -1){
+ let newResponse = responseString.replace(/whhuanan/g, 'null');
+ newResponse = newResponse.replace(/rcwochuanaoc/g, 'results');
+ newResponse = newResponse.replace(/\\/g, '');
+ return JSON.parse(newResponse);
+ } else {
+ return res.json()
+ }
+ })
.subscribe(data => {
// we've got back the raw data, now generate the core schedule data
// and save the data for later reference
diff --git a/src/providers/sw-joke/sw-joke.ts b/src/providers/sw-joke/sw-joke.ts
index 33687e1..648c227 100644
--- a/src/providers/sw-joke/sw-joke.ts
+++ b/src/providers/sw-joke/sw-joke.ts
@@ -20,15 +20,12 @@ export class SwJokeProvider {
}>
getJoke() {
- let rndJoke = _.sample(this.jokes);
- console.log(rndJoke);
+ let rndJoke = _.sample(this.jokes);
return rndJoke;
}
constructor(public http: Http) {
- console.log('Hello SwJokeProvider Provider');
-
/*
{