├── .editorconfig
├── .gitignore
├── README.md
├── app
├── app.ts
├── component
│ ├── stock-chart
│ │ └── stock-chart.ts
│ ├── stock-detail
│ │ ├── stock-detail.html
│ │ ├── stock-detail.scss
│ │ └── stock-detail.ts
│ └── stock
│ │ ├── pipe.ts
│ │ ├── stock.html
│ │ ├── stock.scss
│ │ └── stock.ts
├── pages
│ ├── detail
│ │ ├── detail.html
│ │ └── detail.ts
│ ├── quote-search
│ │ ├── quote-search.html
│ │ └── quote-search.ts
│ └── stock-list
│ │ ├── stock-list.html
│ │ └── stock-list.ts
├── providers
│ ├── stock-info.ts
│ └── storage.ts
└── theme
│ ├── app.core.scss
│ ├── app.ios.scss
│ ├── app.md.scss
│ ├── app.variables.scss
│ └── app.wp.scss
├── config.xml
├── gulpfile.js
├── hooks
├── README.md
└── after_prepare
│ └── 010_add_platform_class.js
├── ionic.config.json
├── package.json
├── resources
├── android
│ ├── icon
│ │ ├── drawable-hdpi-icon.png
│ │ ├── drawable-ldpi-icon.png
│ │ ├── drawable-mdpi-icon.png
│ │ ├── drawable-xhdpi-icon.png
│ │ ├── drawable-xxhdpi-icon.png
│ │ └── drawable-xxxhdpi-icon.png
│ └── splash
│ │ ├── drawable-land-hdpi-screen.png
│ │ ├── drawable-land-ldpi-screen.png
│ │ ├── drawable-land-mdpi-screen.png
│ │ ├── drawable-land-xhdpi-screen.png
│ │ ├── drawable-land-xxhdpi-screen.png
│ │ ├── drawable-land-xxxhdpi-screen.png
│ │ ├── drawable-port-hdpi-screen.png
│ │ ├── drawable-port-ldpi-screen.png
│ │ ├── drawable-port-mdpi-screen.png
│ │ ├── drawable-port-xhdpi-screen.png
│ │ ├── drawable-port-xxhdpi-screen.png
│ │ └── drawable-port-xxxhdpi-screen.png
├── icon.png
├── ios
│ ├── icon
│ │ ├── icon-40.png
│ │ ├── icon-40@2x.png
│ │ ├── icon-50.png
│ │ ├── icon-50@2x.png
│ │ ├── icon-60.png
│ │ ├── icon-60@2x.png
│ │ ├── icon-60@3x.png
│ │ ├── icon-72.png
│ │ ├── icon-72@2x.png
│ │ ├── icon-76.png
│ │ ├── icon-76@2x.png
│ │ ├── icon-small.png
│ │ ├── icon-small@2x.png
│ │ ├── icon-small@3x.png
│ │ ├── icon.png
│ │ └── icon@2x.png
│ └── splash
│ │ ├── Default-568h@2x~iphone.png
│ │ ├── Default-667h.png
│ │ ├── Default-736h.png
│ │ ├── Default-Landscape-736h.png
│ │ ├── Default-Landscape@2x~ipad.png
│ │ ├── Default-Landscape~ipad.png
│ │ ├── Default-Portrait@2x~ipad.png
│ │ ├── Default-Portrait~ipad.png
│ │ ├── Default@2x~iphone.png
│ │ └── Default~iphone.png
└── splash.png
├── tsconfig.json
├── tslint.json
├── typings.json
├── typings
├── globals
│ └── es6-shim
│ │ ├── index.d.ts
│ │ └── typings.json
└── index.d.ts
└── www
├── index.html
└── vendor
├── chartist-plugin-legend.js
├── chartist.css
└── chartist.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs
2 | # editorconfig.org
3 |
4 | root = true
5 |
6 | [*]
7 | indent_style = space
8 | indent_size = 2
9 |
10 | # We recommend you to keep these unchanged
11 | end_of_line = lf
12 | charset = utf-8
13 | trim_trailing_whitespace = true
14 | insert_final_newline = true
15 |
16 | [*.md]
17 | trim_trailing_whitespace = false
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | www/build/
3 | platforms/
4 | plugins/
5 | .DS_Store
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Stock Tracking App with Ionic 2 and Yahoo API
2 |
3 | # Steps to use
4 | * clone this repo
5 | * npm install
6 | * Install the required cordova plugins
7 | * Then ```ionic build android``` or ```ionic build ios```
8 |
9 |
10 | # Based on Ionic 2 Beta 10
--------------------------------------------------------------------------------
/app/app.ts:
--------------------------------------------------------------------------------
1 | import {Component} from '@angular/core';
2 | import {Platform, ionicBootstrap} from 'ionic-angular';
3 | import {StatusBar} from 'ionic-native';
4 | import {StockList} from './pages/stock-list/stock-list';
5 | import {StockInfo} from './providers/stock-info';
6 | import {StorageProvider} from './providers/storage';
7 |
8 | @Component({
9 | template: ''
10 | })
11 | export class MyApp {
12 | rootPage: any = StockList;
13 | constructor(platform: Platform) {
14 | platform.ready().then(() => {
15 | StatusBar.styleDefault();
16 | });
17 | }
18 | }
19 |
20 | ionicBootstrap(MyApp, [StockInfo, StorageProvider]);
21 |
--------------------------------------------------------------------------------
/app/component/stock-chart/stock-chart.ts:
--------------------------------------------------------------------------------
1 | import {Component, Input, Output, ViewChild, ElementRef, OnChanges} from '@angular/core';
2 | declare var Chartist;
3 | @Component({
4 | selector: 'stock-chart',
5 | template: ``
6 | })
7 | export class StockChart {
8 | @Input() data:{};
9 | constructor(public elm: ElementRef) {}
10 |
11 | ngOnChanges() {
12 | if(this.data) {
13 | let options = {
14 | showPoint: false,
15 | axisX: {
16 | showGrid: true,
17 | showLabel:true
18 | },
19 | showArea:true,
20 | chartPadding: {
21 | top: 15,
22 | bottom: 5,
23 | left: 10
24 | }
25 | };
26 | let chart = new Chartist.Line(this.elm.nativeElement,this.data, options);
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/app/component/stock-detail/stock-detail.html:
--------------------------------------------------------------------------------
1 |
2 | Detail
3 |
4 | Stock Exchange
5 | {{detail.StockExchange}}
6 | Currency
7 | {{detail.Currency}}
8 |
9 |
10 | Ask
11 | {{detail.Ask}}
12 | Bid
13 | {{detail.Bid}}
14 |
15 |
16 | Days High
17 | {{detail.DaysHigh}}
18 | Days Low
19 | {{detail.DaysLow}}
20 |
21 |
22 | Year High
23 | {{detail.YearHigh}}
24 | Year Low
25 | {{detail.YearLow}}
26 |
27 |
28 | Volume
29 | {{detail.Volume}}
30 | Average Daily Volume
31 | {{detail.AverageDailyVolume}}
32 |
33 |
--------------------------------------------------------------------------------
/app/component/stock-detail/stock-detail.scss:
--------------------------------------------------------------------------------
1 | .stock-detail-cmp {
2 | ion-col:nth-child(2n-1) {
3 | font-weight: bold;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/app/component/stock-detail/stock-detail.ts:
--------------------------------------------------------------------------------
1 | import {Component, Input, OnInit} from '@angular/core';
2 | import {StockInfo} from '../../providers/stock-info';
3 |
4 | @Component({
5 | selector: 'stock-detail',
6 | templateUrl: 'build/component/stock-detail/stock-detail.html',
7 | })
8 |
9 | export class StockDetailCmp {
10 | @Input() symbol;
11 | detail = {};
12 | constructor(public stockInfo: StockInfo) {
13 | }
14 |
15 | ngOnInit() {
16 | this.stockInfo.getDetail(this.symbol)
17 | .subscribe(data => {
18 | this.detail = data;
19 | });
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/app/component/stock/pipe.ts:
--------------------------------------------------------------------------------
1 | import {Pipe} from '@angular/core';
2 | @Pipe({
3 | name: 'numberString'
4 | })
5 | export class NumberStringPipe {
6 | transform(val, args) {
7 | return Number.parseFloat(val).toFixed(3);
8 | }
9 | }
--------------------------------------------------------------------------------
/app/component/stock/stock.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{info.symbol}}
5 |
6 |
7 | {{info.name}}
8 |
9 |
10 |
11 |
12 | {{data.LastTradePriceOnly | numberString}}
13 | {{data.Change | numberString}}%
14 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
--------------------------------------------------------------------------------
/app/component/stock/stock.scss:
--------------------------------------------------------------------------------
1 | .stockcmp {
2 | .number {
3 | padding:10px 20px;
4 | text-align: center;
5 | min-width: 120px;
6 | max-width:120px;
7 | border-radius:3px;
8 | };
9 |
10 | .percentage_pos {
11 | @extend .number;
12 | background: mediumseagreen;
13 | color:white;
14 | };
15 |
16 | .percentage_neg {
17 | @extend .number;
18 | background: indianred;
19 | color:white;
20 | }
21 | }
--------------------------------------------------------------------------------
/app/component/stock/stock.ts:
--------------------------------------------------------------------------------
1 | import {Component, Input, Output, OnChanges, OnInit, OnDestroy, EventEmitter} from '@angular/core';
2 | import {ViewController, Events} from 'ionic-angular';
3 | import {Http} from '@angular/http';
4 | import {StockInfo} from '../../providers/stock-info';
5 | import {NumberStringPipe} from './pipe';
6 | import {Subscription} from 'rxjs/Rx';
7 |
8 | @Component({
9 | selector: 'stock',
10 | templateUrl: 'build/component/stock/stock.html',
11 | pipes: [NumberStringPipe]
12 | })
13 |
14 | export class StockCmp {
15 | @Input() sliding;
16 | @Input() info;
17 | @Input() run;
18 | @Output() delete = new EventEmitter();
19 | data = {};
20 | down:Boolean;
21 | loading:Boolean;
22 | symbolStock:any;
23 | subscription:Subscription;
24 | constructor(public http:Http, public ss:StockInfo, public vc: ViewController, public events:Events) {
25 | this.loading = true;
26 | }
27 |
28 | ngOnInit() {
29 | this.sliding = (this.sliding === "true");
30 | this.symbolStock = this.ss.getPriceInfo(this.info.symbol);
31 | this.subscription = this.symbolStock.subscribe(data => {
32 | this.data = data;
33 | this.loading = false;
34 | });
35 | }
36 |
37 | percentageSign(value) {
38 | if(value === undefined || value === null) {
39 | return 'number';
40 | } else if(value[0] ==="-") {
41 | this.down = true;
42 | return 'percentage_neg'
43 | } else {
44 | this.down = false;
45 | return 'percentage_pos';
46 | }
47 | }
48 |
49 | ngOnChanges() {
50 | if(this.run) {
51 | if(this.symbolStock && this.subscription) {
52 | this.subscription = this.symbolStock.subscribe(data => {
53 | this.data = data;
54 | this.loading = false;
55 | });
56 | }
57 | } else {
58 | if(this.subscription) {
59 | this.subscription.unsubscribe();
60 | }
61 | }
62 | }
63 |
64 | deleteItem() {
65 | this.delete.emit("delete");
66 | }
67 | }
--------------------------------------------------------------------------------
/app/pages/detail/detail.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Stock Detail
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | Historical Data
16 |
17 |
18 | Select No. of Months of Data
19 |
20 | 1 Month
21 | 3 Month
22 | 6 Month
23 | 12 Month
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
Low
32 |
Close
33 |
34 |
35 |
36 |
37 |
38 |
39 | Enter Notes
40 |
41 |
42 |
43 |
44 |
45 |
46 | {{note.value}}
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/pages/detail/detail.ts:
--------------------------------------------------------------------------------
1 | import {Component} from '@angular/core';
2 | import {NavParams} from 'ionic-angular';
3 | import {StockInfo} from '../../providers/stock-info';
4 | import {StockChart} from '../../component/stock-chart/stock-chart';
5 | import {StockCmp} from '../../component/stock/stock';
6 | import {StockDetailCmp} from '../../component/stock-detail/stock-detail';
7 | import {StorageProvider} from '../../providers/storage';
8 |
9 | @Component({
10 | templateUrl: 'build/pages/detail/detail.html',
11 | directives:[StockChart, StockCmp, StockDetailCmp]
12 | })
13 | export class Detail {
14 | notes = [];
15 | month:number = 1;
16 | details:{};
17 | quote:any;
18 | data:any;
19 | constructor(params: NavParams, public stockinfo:StockInfo, public storageProvider: StorageProvider) {
20 | this.quote = params.get('quote');
21 | this.getChartData();
22 | this.getNotes();
23 | }
24 |
25 | addNote(noteElm) {
26 | if(noteElm.value) {
27 | this.storageProvider.setNotes(this.quote.symbol, noteElm.value)
28 | .then( (data)=> {
29 | this.notes.push({rowid: data.res.insertId, value:noteElm.value, symbol:this.quote.symbol});
30 | noteElm.value = "";
31 | })
32 | }
33 | }
34 |
35 | deleteNote(rowid,i) {
36 | this.storageProvider.removeNote(rowid);
37 | this.notes.splice(i,1);
38 | }
39 |
40 | getChartData() {
41 | this.stockinfo.getChart(this.quote.symbol, this.month)
42 | .subscribe(data=> {
43 | let newData:any = {};
44 | newData.series = [];
45 | newData.series.push({meta: 'Low', name: 'Low', data:[]});
46 | newData.series.push({meta: 'Close',name: 'Close', data:[]});
47 | data.forEach(day=> {
48 | newData.series[0].data.unshift(Number.parseFloat(day.Low));
49 | newData.series[1].data.unshift(Number.parseFloat(day.Close));
50 | });
51 | this.data = newData;
52 | });
53 | }
54 |
55 | getNotes() {
56 | this.storageProvider.getAllNotes(this.quote.symbol)
57 | .then(data => {
58 | let set = data.res.rows;
59 | this.notes = Array.from(set);
60 | });
61 | }
62 | }
--------------------------------------------------------------------------------
/app/pages/quote-search/quote-search.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Quote Search
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | {{quote.symbol}}
17 |
18 |
19 | {{quote.name}}
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/pages/quote-search/quote-search.ts:
--------------------------------------------------------------------------------
1 | import {Component} from '@angular/core';
2 | import {Control} from '@angular/common';
3 | import {Page, ViewController, Events} from 'ionic-angular';
4 | import {StockInfo} from '../../providers/stock-info';
5 | import {StorageProvider} from '../../providers/storage';
6 |
7 | @Component({
8 | templateUrl: 'build/pages/quote-search/quote-search.html'
9 | })
10 | export class QuoteSearch {
11 | searchbar = new Control();
12 | quoteList:Array;
13 | constructor(public stockInfo: StockInfo, public vc:ViewController, public storage: StorageProvider, public events:Events) {
14 | this.searchbar.valueChanges
15 | .filter(value => value.trim().length > 2)
16 | .distinctUntilChanged()
17 | .debounceTime(2000)
18 | .subscribe(value => {
19 | this.search(value);
20 | });
21 | }
22 |
23 | search(value) {
24 | this.stockInfo.getQuotes(value)
25 | .subscribe(list => {
26 | this.quoteList = list;
27 | });
28 | }
29 |
30 | watch(quote) {
31 | this.events.publish("stock:watch", quote);
32 | this.storage.setQuote(quote.symbol, quote);
33 | }
34 |
35 | close() {
36 | this.vc.dismiss();
37 | }
38 | }
--------------------------------------------------------------------------------
/app/pages/stock-list/stock-list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Stocks
4 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/pages/stock-list/stock-list.ts:
--------------------------------------------------------------------------------
1 | import {Component} from '@angular/core';
2 | import {NavController, Modal, Events} from 'ionic-angular';
3 | import {StockCmp} from '../../component/stock/stock';
4 | import {StockChart} from '../../component/stock-chart/stock-chart';
5 | import {QuoteSearch} from '../quote-search/quote-search';
6 | import {Detail} from '../detail/detail';
7 | import {StorageProvider} from '../../providers/storage';
8 |
9 | @Component({
10 | templateUrl: 'build/pages/stock-list/stock-list.html',
11 | directives: [StockCmp, StockChart]
12 | })
13 | export class StockList {
14 | quoteList = [];
15 | run:Boolean;
16 | constructor(public nav:NavController, public storageProvider: StorageProvider, public events: Events) {
17 | this.storageProvider.getAllQuotes()
18 | .then(data => {
19 | let result = data.res.rows;
20 | for(let i=0; i < result.length; i++) {
21 | this.quoteList.push(JSON.parse(result[i].value));
22 | }
23 | });
24 |
25 | this.events.subscribe("stock:watch", (stock) => {
26 | this.quoteList.push(stock[0]);
27 | });
28 |
29 | }
30 |
31 | searchQuote() {
32 | let modal = Modal.create(QuoteSearch);
33 | this.nav.present(modal);
34 | }
35 |
36 | deleteItem(index, symbol) {
37 | this.storageProvider.removeQuote(symbol)
38 | .then(()=>{
39 | this.quoteList.splice(index, 1);
40 | });
41 | }
42 |
43 | ionViewWillEnter() {
44 | this.run = true;
45 | }
46 |
47 | ionViewWillLeave() {
48 | this.run = false;
49 | }
50 |
51 | openDetail(quote) {
52 | this.nav.push(Detail, {quote:quote});
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/app/providers/stock-info.ts:
--------------------------------------------------------------------------------
1 | import {Injectable} from '@angular/core';
2 | import {Http} from '@angular/http';
3 | import {Observable} from 'rxjs/Rx';
4 | import 'rxjs/operator/map';
5 |
6 | @Injectable()
7 | export class StockInfo {
8 | constructor(public http:Http) {}
9 |
10 | encodeURI(string) {
11 | return encodeURIComponent(string).replace(/\"/g, "%22").replace(/\ /g, "%20").replace(/[!'()]/g, encodeURI);
12 | }
13 |
14 | getPriceInfo(symbol) {
15 | let query = `select * from yahoo.finance.quote where symbol IN('${symbol}')`;
16 | let url = 'http://query.yahooapis.com/v1/public/yql?q=' + this.encodeURI(query) + '&format=json&env=http://datatables.org/alltables.env';
17 | // let url = `https://finance.yahoo.com/webservice/v1/symbols/${symbol}/quote?format=json&view=detail`;
18 | let stocks = Observable.interval(5 * 1000)
19 | .flatMap(()=> {
20 | return this.http.get(url).retry(5);
21 | })
22 | .map(data => {
23 | let jsonData = data.json();
24 | return jsonData.query.results.quote;
25 | });
26 | return stocks;
27 | }
28 |
29 | getDetail(symbol) {
30 | let query = `select * from yahoo.finance.quotes where symbol IN ("' ${symbol} '")`;
31 | let url = 'http://query.yahooapis.com/v1/public/yql?q=' + this.encodeURI(query) + '&format=json&env=http://datatables.org/alltables.env';
32 | return this.http.get(url).map(data => data.json().query.results.quote);
33 | }
34 |
35 | getdate(m) {
36 | let d = new Date();
37 | d.setMonth(d.getMonth()-m);
38 | let year = d.getFullYear().toString();
39 | let month = (d.getMonth()+ 1).toString();
40 | let day = d.getDate().toString();
41 |
42 | if(month.length === 1) {
43 | month = "0" + month;
44 | }
45 |
46 | if(day.length === 1) {
47 | day = "0" + day;
48 | }
49 |
50 | let formatted = `${year}-${month}-${day}`;
51 | return formatted;
52 |
53 | }
54 |
55 | getQuotes(name) {
56 | let url = `https://s.yimg.com/aq/autoc?query=${name}®ion=CA&lang=en-CA`;
57 | return this.http.get(url)
58 | .map(data => {
59 | let result = data.json();
60 | return result.ResultSet.Result;
61 | });
62 | }
63 |
64 | getChart(symbol,from=1) {
65 | let todayDate = this.getdate(0);
66 | let fromDate = this.getdate(from);
67 | let query = 'select * from yahoo.finance.historicaldata where symbol = "' + symbol + '" and startDate = "' + fromDate + '" and endDate = "' + todayDate + '"';
68 | let url = 'http://query.yahooapis.com/v1/public/yql?q=' + this.encodeURI(query) + '&format=json&env=http://datatables.org/alltables.env';
69 | return this.http.get(url).map((data) => {
70 | console.log(url);
71 | let result = data.json().query.results;
72 | if(result) {
73 | return result.quote
74 | } else {
75 | return [];
76 | }
77 | });
78 | }
79 |
80 | }
--------------------------------------------------------------------------------
/app/providers/storage.ts:
--------------------------------------------------------------------------------
1 | import {Injectable} from '@angular/core';
2 | import {Storage, SqlStorage} from 'ionic-angular';
3 |
4 | @Injectable()
5 | export class StorageProvider {
6 | storage = new Storage(SqlStorage);
7 | constructor() {
8 | this.storage.query("create table IF NOT EXISTS quotes(stock unique, value)");
9 | this.storage.query("create table IF NOT EXISTS notes(symbol, value)");
10 | }
11 |
12 | setQuote(key, value) {
13 | value = JSON.stringify(value);
14 | let query = `insert into quotes values('${key}', '${value}');`;
15 | return this.storage.query(query);
16 | }
17 |
18 | getAllQuotes() {
19 | return this.storage.query("select * from quotes");
20 | }
21 |
22 | removeQuote(key) {
23 | let query = `delete from quotes where stock='${key}'`;
24 | return this.storage.query(query);
25 | }
26 |
27 | setNotes(symbol, value) {
28 | let query = `insert into notes(symbol, value) values('${symbol}', '${value}')`;
29 | return this.storage.query(query);
30 | }
31 |
32 | getAllNotes(symbol) {
33 | let query = `select rowid, * from notes where symbol='${symbol}';`;
34 | return this.storage.query(query);
35 | }
36 |
37 | removeNote(rowid) {
38 | let query = `delete from notes where rowid = ${rowid}`;
39 | return this.storage.query(query);
40 | }
41 | }
--------------------------------------------------------------------------------
/app/theme/app.core.scss:
--------------------------------------------------------------------------------
1 | // http://ionicframework.com/docs/v2/theming/
2 |
3 |
4 | // App Shared Imports
5 | // --------------------------------------------------
6 | // These are the imports which make up the design of this app.
7 | // By default each design mode includes these shared imports.
8 | // App Shared Sass variables belong in app.variables.scss.
9 |
10 | @import '../component/stock/stock';
11 | @import '../component/stock-detail/stock-detail';
12 |
13 | .ct-series-a {
14 | color:#d70206;
15 | }
16 |
17 | .ct-series-b {
18 | color: #f05b4f;
19 | }
--------------------------------------------------------------------------------
/app/theme/app.ios.scss:
--------------------------------------------------------------------------------
1 |
2 | // http://ionicframework.com/docs/v2/theming/
3 |
4 |
5 | // App Shared Variables
6 | // --------------------------------------------------
7 | // Shared Sass variables go in the app.variables.scss file
8 | @import 'app.variables';
9 |
10 |
11 | // App iOS Variables
12 | // --------------------------------------------------
13 | // iOS only Sass variables can go here
14 |
15 |
16 | // Ionic iOS Sass
17 | // --------------------------------------------------
18 | // Custom App variables must be declared before importing Ionic.
19 | // Ionic will use its default values when a custom variable isn't provided.
20 | @import 'ionic.ios';
21 |
22 |
23 | // App Shared Sass
24 | // --------------------------------------------------
25 | // All Sass files that make up this app goes into the app.core.scss file.
26 | // For simpler CSS overrides, custom app CSS must come after Ionic's CSS.
27 | @import 'app.core';
28 |
29 |
30 | // App iOS Only Sass
31 | // --------------------------------------------------
32 | // CSS that should only apply to the iOS app
33 |
--------------------------------------------------------------------------------
/app/theme/app.md.scss:
--------------------------------------------------------------------------------
1 | // http://ionicframework.com/docs/v2/theming/
2 |
3 |
4 | // App Shared Variables
5 | // --------------------------------------------------
6 | // Shared Sass variables go in the app.variables.scss file
7 | @import 'app.variables';
8 |
9 |
10 | // App Material Design Variables
11 | // --------------------------------------------------
12 | // Material Design only Sass variables can go here
13 |
14 |
15 | // Ionic Material Design Sass
16 | // --------------------------------------------------
17 | // Custom App variables must be declared before importing Ionic.
18 | // Ionic will use its default values when a custom variable isn't provided.
19 | @import 'ionic.md';
20 |
21 |
22 | // App Shared Sass
23 | // --------------------------------------------------
24 | // All Sass files that make up this app goes into the app.core.scss file.
25 | // For simpler CSS overrides, custom app CSS must come after Ionic's CSS.
26 | @import 'app.core';
27 |
28 |
29 | // App Material Design Only Sass
30 | // --------------------------------------------------
31 | // CSS that should only apply to the Material Design app
32 |
--------------------------------------------------------------------------------
/app/theme/app.variables.scss:
--------------------------------------------------------------------------------
1 | // http://ionicframework.com/docs/v2/theming/
2 |
3 | // Ionic Shared Functions
4 | // --------------------------------------------------
5 | // Makes Ionic Sass functions available to your App
6 |
7 | @import 'globals.core';
8 |
9 | // App Shared Variables
10 | // --------------------------------------------------
11 | // To customize the look and feel of this app, you can override
12 | // the Sass variables found in Ionic's source scss files. Setting
13 | // variables before Ionic's Sass will use these variables rather than
14 | // Ionic's default Sass variable values. App Shared Sass imports belong
15 | // in the app.core.scss file and not this file. Sass variables specific
16 | // to the mode belong in either the app.ios.scss or app.md.scss files.
17 |
18 |
19 | // App Shared Color Variables
20 | // --------------------------------------------------
21 | // It's highly recommended to change the default colors
22 | // to match your app's branding. Ionic uses a Sass map of
23 | // colors so you can add, rename and remove colors as needed.
24 | // The "primary" color is the only required color in the map.
25 | // Both iOS and MD colors can be further customized if colors
26 | // are different per mode.
27 |
28 | $colors: (
29 | primary: #387ef5,
30 | secondary: #32db64,
31 | danger: #f53d3d,
32 | light: #f4f4f4,
33 | dark: #222,
34 | favorite: #69BB7B
35 | );
36 |
--------------------------------------------------------------------------------
/app/theme/app.wp.scss:
--------------------------------------------------------------------------------
1 | // http://ionicframework.com/docs/v2/theming/
2 |
3 |
4 | // App Shared Variables
5 | // --------------------------------------------------
6 | // Shared Sass variables go in the app.variables.scss file
7 | @import 'app.variables';
8 |
9 |
10 | // App Windows Variables
11 | // --------------------------------------------------
12 | // Windows only Sass variables can go here
13 |
14 |
15 | // Ionic Windows Sass
16 | // --------------------------------------------------
17 | // Custom App variables must be declared before importing Ionic.
18 | // Ionic will use its default values when a custom variable isn't provided.
19 | @import "ionic.wp";
20 |
21 |
22 | // App Shared Sass
23 | // --------------------------------------------------
24 | // All Sass files that make up this app goes into the app.core.scss file.
25 | // For simpler CSS overrides, custom app CSS must come after Ionic's CSS.
26 | @import 'app.core';
27 |
28 |
29 | // App Windows Only Sass
30 | // --------------------------------------------------
31 | // CSS that should only apply to the Windows app
32 |
--------------------------------------------------------------------------------
/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | beta10
4 | An Ionic Framework and Cordova project.
5 | Ionic Framework Team
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | var gulp = require('gulp'),
2 | gulpWatch = require('gulp-watch'),
3 | del = require('del'),
4 | runSequence = require('run-sequence'),
5 | argv = process.argv;
6 |
7 |
8 | /**
9 | * Ionic hooks
10 | * Add ':before' or ':after' to any Ionic project command name to run the specified
11 | * tasks before or after the command.
12 | */
13 | gulp.task('serve:before', ['watch']);
14 | gulp.task('emulate:before', ['build']);
15 | gulp.task('deploy:before', ['build']);
16 | gulp.task('build:before', ['build']);
17 |
18 | // we want to 'watch' when livereloading
19 | var shouldWatch = argv.indexOf('-l') > -1 || argv.indexOf('--livereload') > -1;
20 | gulp.task('run:before', [shouldWatch ? 'watch' : 'build']);
21 |
22 | /**
23 | * Ionic Gulp tasks, for more information on each see
24 | * https://github.com/driftyco/ionic-gulp-tasks
25 | *
26 | * Using these will allow you to stay up to date if the default Ionic 2 build
27 | * changes, but you are of course welcome (and encouraged) to customize your
28 | * build however you see fit.
29 | */
30 | var buildBrowserify = require('ionic-gulp-browserify-typescript');
31 | var buildSass = require('ionic-gulp-sass-build');
32 | var copyHTML = require('ionic-gulp-html-copy');
33 | var copyFonts = require('ionic-gulp-fonts-copy');
34 | var copyScripts = require('ionic-gulp-scripts-copy');
35 | var tslint = require('ionic-gulp-tslint');
36 |
37 | var isRelease = argv.indexOf('--release') > -1;
38 |
39 | gulp.task('watch', ['clean'], function(done){
40 | runSequence(
41 | ['sass', 'html', 'fonts', 'scripts'],
42 | function(){
43 | gulpWatch('app/**/*.scss', function(){ gulp.start('sass'); });
44 | gulpWatch('app/**/*.html', function(){ gulp.start('html'); });
45 | buildBrowserify({ watch: true }).on('end', done);
46 | }
47 | );
48 | });
49 |
50 | gulp.task('build', ['clean'], function(done){
51 | runSequence(
52 | ['sass', 'html', 'fonts', 'scripts'],
53 | function(){
54 | buildBrowserify({
55 | minify: isRelease,
56 | browserifyOptions: {
57 | debug: !isRelease
58 | },
59 | uglifyOptions: {
60 | mangle: false
61 | }
62 | }).on('end', done);
63 | }
64 | );
65 | });
66 |
67 | gulp.task('sass', buildSass);
68 | gulp.task('html', copyHTML);
69 | gulp.task('fonts', copyFonts);
70 | gulp.task('scripts', copyScripts);
71 | gulp.task('clean', function(){
72 | return del('www/build');
73 | });
74 | gulp.task('lint', tslint);
75 |
--------------------------------------------------------------------------------
/hooks/README.md:
--------------------------------------------------------------------------------
1 |
21 | # Cordova Hooks
22 |
23 | Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. Hook scripts could be defined by adding them to the special predefined folder (`/hooks`) or via configuration files (`config.xml` and `plugin.xml`) and run serially in the following order:
24 | * Application hooks from `/hooks`;
25 | * Application hooks from `config.xml`;
26 | * Plugin hooks from `plugins/.../plugin.xml`.
27 |
28 | __Remember__: Make your scripts executable.
29 |
30 | __Note__: `.cordova/hooks` directory is also supported for backward compatibility, but we don't recommend using it as it is deprecated.
31 |
32 | ## Supported hook types
33 | The following hook types are supported:
34 |
35 | after_build/
36 | after_compile/
37 | after_docs/
38 | after_emulate/
39 | after_platform_add/
40 | after_platform_rm/
41 | after_platform_ls/
42 | after_plugin_add/
43 | after_plugin_ls/
44 | after_plugin_rm/
45 | after_plugin_search/
46 | after_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
47 | after_prepare/
48 | after_run/
49 | after_serve/
50 | before_build/
51 | before_compile/
52 | before_docs/
53 | before_emulate/
54 | before_platform_add/
55 | before_platform_rm/
56 | before_platform_ls/
57 | before_plugin_add/
58 | before_plugin_ls/
59 | before_plugin_rm/
60 | before_plugin_search/
61 | before_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
62 | before_plugin_uninstall/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being uninstalled
63 | before_prepare/
64 | before_run/
65 | before_serve/
66 | pre_package/ <-- Windows 8 and Windows Phone only.
67 |
68 | ## Ways to define hooks
69 | ### Via '/hooks' directory
70 | To execute custom action when corresponding hook type is fired, use hook type as a name for a subfolder inside 'hooks' directory and place you script file here, for example:
71 |
72 | # script file will be automatically executed after each build
73 | hooks/after_build/after_build_custom_action.js
74 |
75 |
76 | ### Config.xml
77 |
78 | Hooks can be defined in project's `config.xml` using `` elements, for example:
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | ...
89 |
90 |
91 |
92 |
93 |
94 |
95 | ...
96 |
97 |
98 | ### Plugin hooks (plugin.xml)
99 |
100 | As a plugin developer you can define hook scripts using `` elements in a `plugin.xml` like that:
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 | ...
109 |
110 |
111 | `before_plugin_install`, `after_plugin_install`, `before_plugin_uninstall` plugin hooks will be fired exclusively for the plugin being installed/uninstalled.
112 |
113 | ## Script Interface
114 |
115 | ### Javascript
116 |
117 | If you are writing hooks in Javascript you should use the following module definition:
118 | ```javascript
119 | module.exports = function(context) {
120 | ...
121 | }
122 | ```
123 |
124 | You can make your scipts async using Q:
125 | ```javascript
126 | module.exports = function(context) {
127 | var Q = context.requireCordovaModule('q');
128 | var deferral = new Q.defer();
129 |
130 | setTimeout(function(){
131 | console.log('hook.js>> end');
132 | deferral.resolve();
133 | }, 1000);
134 |
135 | return deferral.promise;
136 | }
137 | ```
138 |
139 | `context` object contains hook type, executed script full path, hook options, command-line arguments passed to Cordova and top-level "cordova" object:
140 | ```json
141 | {
142 | "hook": "before_plugin_install",
143 | "scriptLocation": "c:\\script\\full\\path\\appBeforePluginInstall.js",
144 | "cmdLine": "The\\exact\\command\\cordova\\run\\with arguments",
145 | "opts": {
146 | "projectRoot":"C:\\path\\to\\the\\project",
147 | "cordova": {
148 | "platforms": ["wp8"],
149 | "plugins": ["com.plugin.withhooks"],
150 | "version": "0.21.7-dev"
151 | },
152 | "plugin": {
153 | "id": "com.plugin.withhooks",
154 | "pluginInfo": {
155 | ...
156 | },
157 | "platform": "wp8",
158 | "dir": "C:\\path\\to\\the\\project\\plugins\\com.plugin.withhooks"
159 | }
160 | },
161 | "cordova": {...}
162 | }
163 |
164 | ```
165 | `context.opts.plugin` object will only be passed to plugin hooks scripts.
166 |
167 | You can also require additional Cordova modules in your script using `context.requireCordovaModule` in the following way:
168 | ```javascript
169 | var Q = context.requireCordovaModule('q');
170 | ```
171 |
172 | __Note__: new module loader script interface is used for the `.js` files defined via `config.xml` or `plugin.xml` only.
173 | For compatibility reasons hook files specified via `/hooks` folders are run via Node child_process spawn, see 'Non-javascript' section below.
174 |
175 | ### Non-javascript
176 |
177 | Non-javascript scripts are run via Node child_process spawn from the project's root directory and have the root directory passes as the first argument. All other options are passed to the script using environment variables:
178 |
179 | * CORDOVA_VERSION - The version of the Cordova-CLI.
180 | * CORDOVA_PLATFORMS - Comma separated list of platforms that the command applies to (e.g.: android, ios).
181 | * CORDOVA_PLUGINS - Comma separated list of plugin IDs that the command applies to (e.g.: org.apache.cordova.file, org.apache.cordova.file-transfer)
182 | * CORDOVA_HOOK - Path to the hook that is being executed.
183 | * CORDOVA_CMDLINE - The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate)
184 |
185 | If a script returns a non-zero exit code, then the parent cordova command will be aborted.
186 |
187 | ## Writing hooks
188 |
189 | We highly recommend writing your hooks using Node.js so that they are
190 | cross-platform. Some good examples are shown here:
191 |
192 | [http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/)
193 |
194 | Also, note that even if you are working on Windows, and in case your hook scripts aren't bat files (which is recommended, if you want your scripts to work in non-Windows operating systems) Cordova CLI will expect a shebang line as the first line for it to know the interpreter it needs to use to launch the script. The shebang line should match the following example:
195 |
196 | #!/usr/bin/env [name_of_interpreter_executable]
197 |
--------------------------------------------------------------------------------
/hooks/after_prepare/010_add_platform_class.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | // Add Platform Class
4 | // v1.0
5 | // Automatically adds the platform class to the body tag
6 | // after the `prepare` command. By placing the platform CSS classes
7 | // directly in the HTML built for the platform, it speeds up
8 | // rendering the correct layout/style for the specific platform
9 | // instead of waiting for the JS to figure out the correct classes.
10 |
11 | var fs = require('fs');
12 | var path = require('path');
13 |
14 | var rootdir = process.argv[2];
15 |
16 | function addPlatformBodyTag(indexPath, platform) {
17 | // add the platform class to the body tag
18 | try {
19 | var platformClass = 'platform-' + platform;
20 | var cordovaClass = 'platform-cordova platform-webview';
21 |
22 | var html = fs.readFileSync(indexPath, 'utf8');
23 |
24 | var bodyTag = findBodyTag(html);
25 | if(!bodyTag) return; // no opening body tag, something's wrong
26 |
27 | if(bodyTag.indexOf(platformClass) > -1) return; // already added
28 |
29 | var newBodyTag = bodyTag;
30 |
31 | var classAttr = findClassAttr(bodyTag);
32 | if(classAttr) {
33 | // body tag has existing class attribute, add the classname
34 | var endingQuote = classAttr.substring(classAttr.length-1);
35 | var newClassAttr = classAttr.substring(0, classAttr.length-1);
36 | newClassAttr += ' ' + platformClass + ' ' + cordovaClass + endingQuote;
37 | newBodyTag = bodyTag.replace(classAttr, newClassAttr);
38 |
39 | } else {
40 | // add class attribute to the body tag
41 | newBodyTag = bodyTag.replace('>', ' class="' + platformClass + ' ' + cordovaClass + '">');
42 | }
43 |
44 | html = html.replace(bodyTag, newBodyTag);
45 |
46 | fs.writeFileSync(indexPath, html, 'utf8');
47 |
48 | process.stdout.write('add to body class: ' + platformClass + '\n');
49 | } catch(e) {
50 | process.stdout.write(e);
51 | }
52 | }
53 |
54 | function findBodyTag(html) {
55 | // get the body tag
56 | try{
57 | return html.match(/])(.*?)>/gi)[0];
58 | }catch(e){}
59 | }
60 |
61 | function findClassAttr(bodyTag) {
62 | // get the body tag's class attribute
63 | try{
64 | return bodyTag.match(/ class=["|'](.*?)["|']/gi)[0];
65 | }catch(e){}
66 | }
67 |
68 | if (rootdir) {
69 |
70 | // go through each of the platform directories that have been prepared
71 | var platforms = (process.env.CORDOVA_PLATFORMS ? process.env.CORDOVA_PLATFORMS.split(',') : []);
72 |
73 | for(var x=0; x {
6 | done: boolean;
7 | value?: T;
8 | }
9 |
10 | interface IterableShim {
11 | /**
12 | * Shim for an ES6 iterable. Not intended for direct use by user code.
13 | */
14 | "_es6-shim iterator_"(): Iterator;
15 | }
16 |
17 | interface Iterator {
18 | next(value?: any): IteratorResult;
19 | return?(value?: any): IteratorResult;
20 | throw?(e?: any): IteratorResult;
21 | }
22 |
23 | interface IterableIteratorShim extends IterableShim, Iterator {
24 | /**
25 | * Shim for an ES6 iterable iterator. Not intended for direct use by user code.
26 | */
27 | "_es6-shim iterator_"(): IterableIteratorShim;
28 | }
29 |
30 | interface StringConstructor {
31 | /**
32 | * Return the String value whose elements are, in order, the elements in the List elements.
33 | * If length is 0, the empty string is returned.
34 | */
35 | fromCodePoint(...codePoints: number[]): string;
36 |
37 | /**
38 | * String.raw is intended for use as a tag function of a Tagged Template String. When called
39 | * as such the first argument will be a well formed template call site object and the rest
40 | * parameter will contain the substitution values.
41 | * @param template A well-formed template string call site representation.
42 | * @param substitutions A set of substitution values.
43 | */
44 | raw(template: TemplateStringsArray, ...substitutions: any[]): string;
45 | }
46 |
47 | interface String {
48 | /**
49 | * Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
50 | * value of the UTF-16 encoded code point starting at the string element at position pos in
51 | * the String resulting from converting this object to a String.
52 | * If there is no element at that position, the result is undefined.
53 | * If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.
54 | */
55 | codePointAt(pos: number): number;
56 |
57 | /**
58 | * Returns true if searchString appears as a substring of the result of converting this
59 | * object to a String, at one or more positions that are
60 | * greater than or equal to position; otherwise, returns false.
61 | * @param searchString search string
62 | * @param position If position is undefined, 0 is assumed, so as to search all of the String.
63 | */
64 | includes(searchString: string, position?: number): boolean;
65 |
66 | /**
67 | * Returns true if the sequence of elements of searchString converted to a String is the
68 | * same as the corresponding elements of this object (converted to a String) starting at
69 | * endPosition – length(this). Otherwise returns false.
70 | */
71 | endsWith(searchString: string, endPosition?: number): boolean;
72 |
73 | /**
74 | * Returns a String value that is made from count copies appended together. If count is 0,
75 | * T is the empty String is returned.
76 | * @param count number of copies to append
77 | */
78 | repeat(count: number): string;
79 |
80 | /**
81 | * Returns true if the sequence of elements of searchString converted to a String is the
82 | * same as the corresponding elements of this object (converted to a String) starting at
83 | * position. Otherwise returns false.
84 | */
85 | startsWith(searchString: string, position?: number): boolean;
86 |
87 | /**
88 | * Returns an HTML anchor element and sets the name attribute to the text value
89 | * @param name
90 | */
91 | anchor(name: string): string;
92 |
93 | /** Returns a HTML element */
94 | big(): string;
95 |
96 | /** Returns a