diff --git a/ionic/components/alert/test/basic/index.ts b/ionic/components/alert/test/basic/index.ts index f7ec13ba51..5534a52777 100644 --- a/ionic/components/alert/test/basic/index.ts +++ b/ionic/components/alert/test/basic/index.ts @@ -1,5 +1,4 @@ import {Component} from 'angular2/angular2'; -import {View} from 'angular2/src/core/annotations_impl/view'; import {IonicView} from 'ionic/ionic'; diff --git a/ionic/components/app/test/sink/pages/segment.ts b/ionic/components/app/test/sink/pages/segment.ts index a059e4960a..ddd6df0dfb 100644 --- a/ionic/components/app/test/sink/pages/segment.ts +++ b/ionic/components/app/test/sink/pages/segment.ts @@ -1,7 +1,5 @@ -import {NgFor, Injector, DomRenderer, ElementRef} from 'angular2/angular2'; -import {Ancestor} from 'angular2/src/core/annotations_impl/visibility'; -import {Component, Directive} from 'angular2/angular2'; -import {View} from 'angular2/src/core/annotations_impl/view'; +import {NgFor, Injector, DomRenderer, ElementRef, Ancestor} from 'angular2/angular2'; +import {Component, Directive, View} from 'angular2/angular2'; import {FormBuilder, Validators, formDirectives, Control, ControlGroup} from 'angular2/forms'; import {Segment, SegmentButton, List, Item, ActionMenu, Modal, ModalRef, diff --git a/ionic/components/app/test/weather/flickr.js b/ionic/components/app/test/weather/flickr.js deleted file mode 100644 index 8ae5dd975d..0000000000 --- a/ionic/components/app/test/weather/flickr.js +++ /dev/null @@ -1,37 +0,0 @@ -import {Http} from 'ionic/net/http'; - -let FLICKR_API_KEY = '504fd7414f6275eb5b657ddbfba80a2c'; - -let baseUrl = 'https://api.flickr.com/services/rest/'; - -export class Flickr { - constructor() { - - /* - var flickrSearch = $resource(baseUrl, { - method: 'flickr.groups.pools.getPhotos', - group_id: '1463451@N25', - safe_search: 1, - jsoncallback: 'JSON_CALLBACK', - api_key: FLICKR_API_KEY, - format: 'json' - }, { - get: { - method: 'JSONP' - } - }); - */ - } - - static search(tags, lat, lng) { - return new Promise((resolve, reject) => { - Http.get(baseUrl + '?method=flickr.groups.pools.getPhotos&group_id=1463451@N25&safe_search=1&api_key=' + FLICKR_API_KEY + '&jsoncallback=JSON_CALLBACK&format=json&tags=' + tags + '&lat=' + lat + '&lng=' + lng, { - method: 'jsonp' - }).then((val) => { - resolve(val); - }, (err) => { - reject(httpResponse); - }) - }) - } -} diff --git a/ionic/components/app/test/weather/flickr.ts b/ionic/components/app/test/weather/flickr.ts index 6cb32d9964..8ae5dd975d 100755 --- a/ionic/components/app/test/weather/flickr.ts +++ b/ionic/components/app/test/weather/flickr.ts @@ -25,7 +25,9 @@ export class Flickr { static search(tags, lat, lng) { return new Promise((resolve, reject) => { - Http.get(baseUrl + '?method=flickr.groups.pools.getPhotos&group_id=1463451@N25&safe_search=1&api_key=' + FLICKR_API_KEY + '&format=json&tags=' + tags + '&lat=' + lat + '&lng=' + lng).then((val) => { + Http.get(baseUrl + '?method=flickr.groups.pools.getPhotos&group_id=1463451@N25&safe_search=1&api_key=' + FLICKR_API_KEY + '&jsoncallback=JSON_CALLBACK&format=json&tags=' + tags + '&lat=' + lat + '&lng=' + lng, { + method: 'jsonp' + }).then((val) => { resolve(val); }, (err) => { reject(httpResponse); diff --git a/ionic/components/app/test/weather/geo.js b/ionic/components/app/test/weather/geo.js deleted file mode 100644 index c56b15e3e8..0000000000 --- a/ionic/components/app/test/weather/geo.js +++ /dev/null @@ -1,56 +0,0 @@ -export class Geo { - static reverseGeocode(lat, lng) { - return new Promise((resolve, reject) => { - - let geocoder = new google.maps.Geocoder(); - - geocoder.geocode({ - 'latLng': new google.maps.LatLng(lat, lng) - }, (results, status) => { - - if (status == google.maps.GeocoderStatus.OK) { - - console.log('Reverse', results); - - if(results.length > 1) { - var r = results[1]; - var a, types; - var parts = []; - var foundLocality = false; - var foundState = false; - - for(var i = 0; i < r.address_components.length; i++) { - a = r.address_components[i]; - types = a.types; - for(var j = 0; j < types.length; j++) { - if(!foundLocality && types[j] == 'locality') { - foundLocality = true; - parts.push(a.long_name); - } else if(!foundState && types[j] == 'administrative_area_level_1') { - foundState = true; - parts.push(a.short_name); - } - } - } - - console.log('Reverse', parts); - resolve(parts.join(', ')); - } - } else { - console.log('reverse fail', results, status); - reject(results); - } - }); - }); - } - - static getLocation() { - return new Promise((resolve, reject) => { - navigator.geolocation.getCurrentPosition((position) => { - resolve(position); - }, (error) => { - reject(error); - }) - }); - } -} diff --git a/ionic/components/app/test/weather/index.js b/ionic/components/app/test/weather/index.js deleted file mode 100644 index c688a7076a..0000000000 --- a/ionic/components/app/test/weather/index.js +++ /dev/null @@ -1,376 +0,0 @@ -import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations'; -import {View} from 'angular2/src/core/annotations_impl/view'; -import {NgIf, NgFor, CSSClass, ElementRef} from 'angular2/angular2'; -import {FormBuilder, Control, ControlGroup, Validators, formDirectives} from 'angular2/forms'; - -import {IonicView, Animation, Content, Scroll, Modal, NavController, NavParams, IonicComponent} from 'ionic/ionic'; - -import {Geo} from './geo'; -import {Weather} from './weather'; -import {Flickr} from './flickr'; - -@Component({ - selector: 'ion-app', - appInjector: [Modal] -}) -@View({ - templateUrl: 'main.html', - directives: [NgIf, NgFor, Content, Scroll, CurrentWeather, WeatherIcon, BackgroundCycler] -}) -class WeatherApp { - constructor(Modal: Modal) { - this.Modal = Modal; - - this.currentLocationString = 'Madison, WI'; - - this.activeBgImageIndex = 0; - - /* - $ionicPlatform.ready(function() { - // Hide the status bar - if(window.StatusBar) { - StatusBar.hide(); - } - }); - */ - - } - - onInit() { - this.refreshData(); - } - - showSettings() { - this.Modal.open(SettingsModal).then((settingsModal) => { - this.settingsModal = settingsModal; - }); - } - - getBackgroundImage(lat, lng, locString) { - Flickr.search(locString, lat, lng).then((resp) => { - let photos = resp.photos; - if(photos.photo.length) { - this.bgImages = photos.photo; - this.cycleBgImages(); - } - }, (error) => { - console.error('Unable to get Flickr images', error); - }); - } - - getCurrent(lat, lng, locString) { - Weather.getAtLocation(lat, lng).then((resp) => { - this.current = resp; - - // TODO: This should be in a custom pipe - let c, d, h; - for(let i = 0; i < this.current.hourly.data.length; i++) { - c = this.current.hourly.data[i]; - let t = c.temperature; - d = new Date(c.time * 1000); - c.temperature = Math.floor(t); - h = d.getHours() % 12; - h = (h == 0 ? 12 : h); - c.time_date = h + ' ' + (d.getHours() < 12 ? 'AM' : 'PM'); - } - for(let i = 0; i < this.current.daily.data.length; i++) { - c = this.current.daily.data[i]; - let max = c.temperatureMax; - let min = c.temperatureMin; - c.temperatureMax = Math.floor(max); - c.temperatureMin = Math.floor(min); - c.time_date = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][new Date(c.time*1000).getDay()]; - } - console.log('GOT CURRENT', this.current); - }, (error) => { - alert('Unable to get current conditions'); - console.error(error); - }); - } - - cycleBgImages() { - setTimeout(() => { - if(this.bgImages) { - this.activeBgImage = this.bgImages[this.activeBgImageIndex++ % this.bgImages.length]; - } - }); - } - - refreshData() { - Geo.getLocation().then((position) => { - let lat = position.coords.latitude; - let lng = position.coords.longitude; - - Geo.reverseGeocode(lat, lng).then((locString) => { - this.currentLocationString = locString; - this.getBackgroundImage(lat, lng, locString); - }); - - this.getCurrent(lat, lng); - }, (error) => { - alert('Unable to get current location: ' + error); - }); - } -} - -/* -.controller('SettingsCtrl', function($scope, Settings) { - $scope.settings = Settings.getSettings(); - - // Watch deeply for settings changes, and save them - // if necessary - $scope.$watch('settings', function(v) { - Settings.save(); - }, true); - - $scope.closeSettings = function() { - $scope.modal.hide(); - }; - -}); -*/ - -@IonicComponent(Modal) -@IonicView({ - template: ` - - Settings - - -
- - - Units - - - -
-
-
`, - directives: [formDirectives] -}) -export class SettingsModal extends Modal { - constructor(fb: FormBuilder) { - this.settingsForm = fb.group({ - mapStyle: ['hybrid', Validators.required] - }); - } -} - -export function main(ionicBootstrap) { - ionicBootstrap(WeatherApp); -} - - -let WEATHER_ICONS = { - 'partlycloudy': 'ion-ios-partlysunny-outline', - 'mostlycloudy': 'ion-ios-partlysunny-outline', - 'cloudy': 'ion-ios-cloudy-outline', - 'rain': 'ion-ios-rainy-outline', - 'tstorms': 'ion-ios-thunderstorm-outline', - 'sunny': 'ion-ios-sunny-outline', - 'clear-day': 'ion-ios-sunny-outline', - 'nt_clear': 'ion-ios-moon-outline', - 'clear-night': 'ion-ios-moon-outline' -}; - -@Component({ - selector: 'weather-icon', - properties: [ - 'icon' - ] -}) -@View({ - template: '', - directives: [CSSClass] -}) -export class WeatherIcon { - constructor() { - } - onAllChangesDone(data) { - var icon = this.icon; - - if(icon in WEATHER_ICONS) { - this.weatherIcon = WEATHER_ICONS[icon]; - } else { - this.weatherIcon = WEATHER_ICONS['cloudy']; - } - } -} - -@Component({ - selector: 'current-time', - properties: [ - 'localtz' - ] -}) -@View({ - template: '{{currentTime}}', -}) -export class CurrentTime { - constructor() { - } - onInit() { - if(this.localtz) { - this.currentTime = new Date(); - //this.currentTime = //$filter('date')(+(new Date), 'h:mm') + $scope.localtz; - } - } -} - -@Component({ - selector: 'current-weather', - properties: [ - 'current' - ] -}) -@View({ - templateUrl: 'current-weather.html', - directives: [NgIf] -}) -export class CurrentWeather { - constructor(elementRef: ElementRef) { - this.elementRef = elementRef; - - /* - $rootScope.$on('settings.changed', function(settings) { - var units = Settings.get('tempUnits'); - - if($scope.forecast) { - - var forecast = $scope.forecast; - var current = $scope.current; - - if(units == 'f') { - $scope.highTemp = forecast.forecastday[0].high.fahrenheit; - $scope.lowTemp = forecast.forecastday[0].low.fahrenheit; - $scope.currentTemp = Math.floor(current.temp_f); - } else { - $scope.highTemp = forecast.forecastday[0].high.celsius; - $scope.lowTemp = forecast.forecastday[0].low.celsius; - $scope.currentTemp = Math.floor(current.temp_c); - } - } - }); - */ - - // Delay so we are in the DOM and can calculate sizes - } - - onInit() { - var windowHeight = window.innerHeight; - var thisHeight = this.elementRef.nativeElement.offsetHeight; - var headerHeight = document.querySelector('#header').offsetHeight; - this.elementRef.nativeElement.style.paddingTop = (windowHeight - 250) + 'px'; - /* - document.querySelector('.content')).css('-webkit-overflow-scrolling', 'auto'); - $timeout(function() { - angular.element(document.querySelector('.content')).css('-webkit-overflow-scrolling', 'touch'); - }, 50); - */ - } - onAllChangesDone() { - var units = 'f';//Settings.get('tempUnits'); - - let current = this.current; - - console.log('ALL CHANGES DONE', current); - - if(current && current.currently) { - if(units == 'f') { - this.currentTemp = Math.floor(current.currently.temperature); - } else { - this.currentTemp = Math.floor(current.currently.temperature); - } - if(units == 'f') { - this.highTemp = Math.floor(current.daily.data[0].temperatureMax); - this.lowTemp = Math.floor(current.daily.data[0].temperatureMin); - } else { - this.highTemp = Math.floor(current.daily.data[0].temperatureMax); - this.lowTemp = Math.floor(current.daily.data[0].temperatureMin); - } - } - } -} - -@Component({ - selector: 'background-cycler', - properties: [ - 'image' - ] -}) -@View({ - template: '
' -}) -export class BackgroundCycler { - constructor(elementRef: ElementRef) { - this.elementRef = elementRef; - this.el = elementRef.nativeElement; - } - onInit() { - this.imageEl = this.el.children[0]; - } - onAllChangesDone() { - var item = this.image; - if(item) { - var url = "http://farm"+ item.farm +".static.flickr.com/"+ item.server +"/"+ item.id +"_"+ item.secret + "_z.jpg"; - this.imageEl.style.backgroundImage = 'url(' + url + ')'; - } - } -} - -/* -.directive('weatherBox', function($timeout) { - return { - restrict: 'E', - replace: true, - transclude: true, - scope: { - title: '@' - }, - template: '

{{title}}

', - link: function($scope, $element, $attr) { - } - } -}) - -.directive('scrollEffects', function() { - return { - restrict: 'A', - link: function($scope, $element, $attr) { - var amt, st, header; - var bg = document.querySelector('.bg-image'); - $element.bind('scroll', function(e) { - if(!header) { - header = document.getElementById('header'); - } - st = e.detail.scrollTop; - if(st >= 0) { - header.style.webkitTransform = 'translate3d(0, 0, 0)'; - } else if(st < 0) { - header.style.webkitTransform = 'translate3d(0, ' + -st + 'px, 0)'; - } - amt = Math.min(0.6, st / 1000); - - ionic.requestAnimationFrame(function() { - header.style.opacty = 1 - amt; - if(bg) { - bg.style.opacity = 1 - amt; - } - }); - }); - } - } -}) - - -*/ diff --git a/ionic/components/app/test/weather/index.ts b/ionic/components/app/test/weather/index.ts index 32f2896ce3..07c37e2755 100755 --- a/ionic/components/app/test/weather/index.ts +++ b/ionic/components/app/test/weather/index.ts @@ -1,28 +1,25 @@ -import {Component, Directive} from 'angular2/angular2'; +import {Component, Directive, View} from 'angular2/angular2'; +import {NgIf, NgFor, CSSClass, ElementRef} from 'angular2/angular2'; import {FormBuilder, Control, ControlGroup, Validators, formDirectives} from 'angular2/forms'; -import {IonicView, Animation, Modal, NavController, NavParams, IonicComponent} from 'ionic/ionic'; +import {IonicView, Animation, Content, Scroll, Modal, NavController, NavParams, IonicComponent} from 'ionic/ionic'; import {Geo} from './geo'; import {Weather} from './weather'; import {Flickr} from './flickr'; -console.log('Imported', Geo, Weather, Flickr); - @Component({ - selector: 'ion-app', + selector: 'ion-app' }) -@IonicView({ - templateUrl: 'main.html' +@View({ + templateUrl: 'main.html', + directives: [NgIf, NgFor, Content, Scroll, CurrentWeather, WeatherIcon, BackgroundCycler] }) class WeatherApp { constructor(modal: Modal) { - this.modal = Modal; + this.modal = modal; this.currentLocationString = 'Madison, WI'; - this.current = { - local_tz_short: 'CDT' - }; this.activeBgImageIndex = 0; @@ -61,7 +58,27 @@ class WeatherApp { getCurrent(lat, lng, locString) { Weather.getAtLocation(lat, lng).then((resp) => { - this.current = resp.data; + this.current = resp; + + // TODO: This should be in a custom pipe + let c, d, h; + for(let i = 0; i < this.current.hourly.data.length; i++) { + c = this.current.hourly.data[i]; + let t = c.temperature; + d = new Date(c.time * 1000); + c.temperature = Math.floor(t); + h = d.getHours() % 12; + h = (h == 0 ? 12 : h); + c.time_date = h + ' ' + (d.getHours() < 12 ? 'AM' : 'PM'); + } + for(let i = 0; i < this.current.daily.data.length; i++) { + c = this.current.daily.data[i]; + let max = c.temperatureMax; + let min = c.temperatureMin; + c.temperatureMax = Math.floor(max); + c.temperatureMin = Math.floor(min); + c.time_date = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][new Date(c.time*1000).getDay()]; + } console.log('GOT CURRENT', this.current); }, (error) => { alert('Unable to get current conditions'); @@ -112,12 +129,245 @@ class WeatherApp { */ @IonicView({ - template: '' + template: ` + + Settings + + +
+ + + Units + + + +
+
+
`, + directives: [formDirectives] }) export class SettingsModal { - + constructor(fb: FormBuilder) { + this.settingsForm = fb.group({ + mapStyle: ['hybrid', Validators.required] + }); + } } export function main(ionicBootstrap) { ionicBootstrap(WeatherApp); } + + +let WEATHER_ICONS = { + 'partlycloudy': 'ion-ios-partlysunny-outline', + 'mostlycloudy': 'ion-ios-partlysunny-outline', + 'cloudy': 'ion-ios-cloudy-outline', + 'rain': 'ion-ios-rainy-outline', + 'tstorms': 'ion-ios-thunderstorm-outline', + 'sunny': 'ion-ios-sunny-outline', + 'clear-day': 'ion-ios-sunny-outline', + 'nt_clear': 'ion-ios-moon-outline', + 'clear-night': 'ion-ios-moon-outline' +}; + +@Component({ + selector: 'weather-icon', + properties: [ + 'icon' + ] +}) +@View({ + template: '', + directives: [CSSClass] +}) +export class WeatherIcon { + constructor() { + } + onAllChangesDone(data) { + var icon = this.icon; + + if(icon in WEATHER_ICONS) { + this.weatherIcon = WEATHER_ICONS[icon]; + } else { + this.weatherIcon = WEATHER_ICONS['cloudy']; + } + } +} + +@Component({ + selector: 'current-time', + properties: [ + 'localtz' + ] +}) +@View({ + template: '{{currentTime}}', +}) +export class CurrentTime { + constructor() { + } + onInit() { + if(this.localtz) { + this.currentTime = new Date(); + //this.currentTime = //$filter('date')(+(new Date), 'h:mm') + $scope.localtz; + } + } +} + +@Component({ + selector: 'current-weather', + properties: [ + 'current' + ] +}) +@View({ + templateUrl: 'current-weather.html', + directives: [NgIf] +}) +export class CurrentWeather { + constructor(elementRef: ElementRef) { + this.elementRef = elementRef; + + /* + $rootScope.$on('settings.changed', function(settings) { + var units = Settings.get('tempUnits'); + + if($scope.forecast) { + + var forecast = $scope.forecast; + var current = $scope.current; + + if(units == 'f') { + $scope.highTemp = forecast.forecastday[0].high.fahrenheit; + $scope.lowTemp = forecast.forecastday[0].low.fahrenheit; + $scope.currentTemp = Math.floor(current.temp_f); + } else { + $scope.highTemp = forecast.forecastday[0].high.celsius; + $scope.lowTemp = forecast.forecastday[0].low.celsius; + $scope.currentTemp = Math.floor(current.temp_c); + } + } + }); + */ + + // Delay so we are in the DOM and can calculate sizes + } + + onInit() { + var windowHeight = window.innerHeight; + var thisHeight = this.elementRef.nativeElement.offsetHeight; + var headerHeight = document.querySelector('#header').offsetHeight; + this.elementRef.nativeElement.style.paddingTop = (windowHeight - 250) + 'px'; + /* + document.querySelector('.content')).css('-webkit-overflow-scrolling', 'auto'); + $timeout(function() { + angular.element(document.querySelector('.content')).css('-webkit-overflow-scrolling', 'touch'); + }, 50); + */ + } + onAllChangesDone() { + var units = 'f';//Settings.get('tempUnits'); + + let current = this.current; + + console.log('ALL CHANGES DONE', current); + + if(current && current.currently) { + if(units == 'f') { + this.currentTemp = Math.floor(current.currently.temperature); + } else { + this.currentTemp = Math.floor(current.currently.temperature); + } + if(units == 'f') { + this.highTemp = Math.floor(current.daily.data[0].temperatureMax); + this.lowTemp = Math.floor(current.daily.data[0].temperatureMin); + } else { + this.highTemp = Math.floor(current.daily.data[0].temperatureMax); + this.lowTemp = Math.floor(current.daily.data[0].temperatureMin); + } + } + } +} + +@Component({ + selector: 'background-cycler', + properties: [ + 'image' + ] +}) +@View({ + template: '
' +}) +export class BackgroundCycler { + constructor(elementRef: ElementRef) { + this.elementRef = elementRef; + this.el = elementRef.nativeElement; + } + onInit() { + this.imageEl = this.el.children[0]; + } + onAllChangesDone() { + var item = this.image; + if(item) { + var url = "http://farm"+ item.farm +".static.flickr.com/"+ item.server +"/"+ item.id +"_"+ item.secret + "_z.jpg"; + this.imageEl.style.backgroundImage = 'url(' + url + ')'; + } + } +} + +/* +.directive('weatherBox', function($timeout) { + return { + restrict: 'E', + replace: true, + transclude: true, + scope: { + title: '@' + }, + template: '

{{title}}

', + link: function($scope, $element, $attr) { + } + } +}) + +.directive('scrollEffects', function() { + return { + restrict: 'A', + link: function($scope, $element, $attr) { + var amt, st, header; + var bg = document.querySelector('.bg-image'); + $element.bind('scroll', function(e) { + if(!header) { + header = document.getElementById('header'); + } + st = e.detail.scrollTop; + if(st >= 0) { + header.style.webkitTransform = 'translate3d(0, 0, 0)'; + } else if(st < 0) { + header.style.webkitTransform = 'translate3d(0, ' + -st + 'px, 0)'; + } + amt = Math.min(0.6, st / 1000); + + ionic.requestAnimationFrame(function() { + header.style.opacty = 1 - amt; + if(bg) { + bg.style.opacity = 1 - amt; + } + }); + }); + } + } +}) + + +*/ diff --git a/ionic/components/app/test/weather/weather.js b/ionic/components/app/test/weather/weather.js deleted file mode 100644 index e68102427e..0000000000 --- a/ionic/components/app/test/weather/weather.js +++ /dev/null @@ -1,14 +0,0 @@ -import {Http} from 'ionic/net/http'; - -let WUNDERGROUND_API_KEY = '1cc2d3de40fa5af0'; - -let FORECASTIO_KEY = '4cd3c5673825a361eb5ce108103ee84a'; - -export class Weather { - static getAtLocation(lat, lng) { - let url = 'https://api.forecast.io/forecast/' + FORECASTIO_KEY + '/'; - return Http.get(url + lat + ',' + lng + '?callback=JSON_CALLBACK', { - method: 'jsonp' - }); - } -} diff --git a/ionic/components/app/test/weather/weather.ts b/ionic/components/app/test/weather/weather.ts index 0cefbe41c7..e68102427e 100755 --- a/ionic/components/app/test/weather/weather.ts +++ b/ionic/components/app/test/weather/weather.ts @@ -7,6 +7,8 @@ let FORECASTIO_KEY = '4cd3c5673825a361eb5ce108103ee84a'; export class Weather { static getAtLocation(lat, lng) { let url = 'https://api.forecast.io/forecast/' + FORECASTIO_KEY + '/'; - return Http.get(url + lat + ',' + lng); + return Http.get(url + lat + ',' + lng + '?callback=JSON_CALLBACK', { + method: 'jsonp' + }); } } diff --git a/ionic/components/content/content.js b/ionic/components/content/content.js deleted file mode 100644 index ef6f8aeacb..0000000000 --- a/ionic/components/content/content.js +++ /dev/null @@ -1,32 +0,0 @@ -import {ElementRef} from 'angular2/angular2' -import {Component} from 'angular2/src/core/annotations_impl/annotations'; -import {View} from 'angular2/src/core/annotations_impl/view'; - -import {Ion} from '../ion'; - - -@Component({ - selector: 'ion-content' -}) -@View({ - template: `
` -}) -export class Content extends Ion { - constructor(elementRef: ElementRef) { - super(elementRef); - - setTimeout(() => { - this.scrollElement = elementRef.nativeElement.children[0]; - }); - } - - addScrollEventListener(handler) { - if(!this.scrollElement) { return; } - - this.scrollElement.addEventListener('scroll', handler); - - return () => { - this.scrollElement.removeEventListener('scroll', handler); - } - } -} diff --git a/ionic/components/form/test/basic/index.ts b/ionic/components/form/test/basic/index.ts index 0c17dae075..d8cd1e8ac2 100644 --- a/ionic/components/form/test/basic/index.ts +++ b/ionic/components/form/test/basic/index.ts @@ -1,5 +1,4 @@ -import {Component, Directive} from 'angular2/angular2'; -import {View} from 'angular2/src/core/annotations_impl/view'; +import {Component, Directive, View} from 'angular2/angular2'; import {FormBuilder, Validators, formDirectives, ControlGroup} from 'angular2/forms'; //import {Switch, Form, List, Label, Item, Input, Content} from 'ionic/ionic'; diff --git a/ionic/components/ion.js b/ionic/components/ion.js deleted file mode 100644 index 927002c1e1..0000000000 --- a/ionic/components/ion.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Base class for all Ionic components. Exposes some common functionality - * that all Ionic components need, such as accessing underlying native elements and - * sending/receiving app-level events. - */ -export class Ion { - constructor(elementRef: ElementRef) { - console.log('ION INIT', elementRef); - this.elementRef = elementRef; - } - - getNativeElement() { - return this.elementRef.nativeElement; - } -} diff --git a/ionic/components/modal/test/basic/index.ts b/ionic/components/modal/test/basic/index.ts index 7fa4f14141..c6e8197b27 100644 --- a/ionic/components/modal/test/basic/index.ts +++ b/ionic/components/modal/test/basic/index.ts @@ -1,12 +1,6 @@ -import {ElementRef, ComponentRef, onDestroy} from 'angular2/angular2'; -import {bind, Injector} from 'angular2/di'; -import {Component, Directive} from 'angular2/angular2'; -import {View} from 'angular2/src/core/annotations_impl/view'; -import {Parent, Ancestor} from 'angular2/src/core/annotations_impl/visibility'; +import {Component} from 'angular2/angular2'; -import {IonicView, IonicConfig, Platform} from 'ionic/ionic'; - -import {IonicComponent} from 'ionic/ionic'; +import {IonicComponent, IonicView, IonicConfig, Platform} from 'ionic/ionic'; import {Modal, NavController, NavParams, Animation, ActionMenu} from 'ionic/ionic'; diff --git a/ionic/components/nav/nav.js b/ionic/components/nav/nav.js index 235e289d65..5afeba2b21 100644 --- a/ionic/components/nav/nav.js +++ b/ionic/components/nav/nav.js @@ -1,9 +1,4 @@ -import {Component, Directive, onInit} from 'angular2/src/core/annotations_impl/annotations'; -import {View} from 'angular2/src/core/annotations_impl/view'; -import {Parent} from 'angular2/src/core/annotations_impl/visibility'; -import {Optional} from 'angular2/src/di/annotations_impl'; -import {ElementRef} from 'angular2/src/core/compiler/element_ref'; -import {Injector} from 'angular2/di'; +import {Component, Directive, View, ElementRef, Parent, Optional, Injector, onInit, forwardRef} from 'angular2/angular2'; import {ViewController} from '../view/view-controller'; @@ -17,7 +12,7 @@ import {ViewController} from '../view/view-controller'; }) @View({ template: '', - directives: [PaneAnchor] + directives: [forwardRef(() => PaneAnchor)] }) export class Nav extends ViewController { diff --git a/ionic/components/scroll/scroll.js b/ionic/components/scroll/scroll.ts similarity index 100% rename from ionic/components/scroll/scroll.js rename to ionic/components/scroll/scroll.ts diff --git a/ionic/components/scroll/test/basic/index.js b/ionic/components/scroll/test/basic/index.js deleted file mode 100644 index 265d76f100..0000000000 --- a/ionic/components/scroll/test/basic/index.js +++ /dev/null @@ -1,21 +0,0 @@ -import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations'; - -import {IonicView} from 'ionic/ionic'; - - -@Component({ selector: 'ion-app' }) -@IonicView({ - templateUrl: 'main.html' -}) -class IonicApp { - constructor() { - console.log('IonicApp Start') - } - doRefresh() { - console.log('DOREFRESH') - } -} - -export function main(ionicBootstrap) { - ionicBootstrap(IonicApp); -} diff --git a/ionic/components/view/view.js b/ionic/components/view/view.js deleted file mode 100644 index 561d033339..0000000000 --- a/ionic/components/view/view.js +++ /dev/null @@ -1,17 +0,0 @@ -import {Directive} from 'angular2/src/core/annotations_impl/annotations'; -import {ElementRef} from 'angular2/src/core/compiler/element_ref'; -import {Optional} from 'angular2/src/di/annotations_impl' - -import {ViewItem} from './view-item'; - -import {Ion} from '../ion'; - -@Directive({ - selector: 'ion-view', -}) -export class IonView extends Ion { - constructor(@Optional() item: ViewItem, elementRef: ElementRef) { - super(elementRef); - this.ele = elementRef.nativeElement; - } -} diff --git a/ionic/config/annotations.js b/ionic/config/annotations.js deleted file mode 100644 index b4a930b8ef..0000000000 --- a/ionic/config/annotations.js +++ /dev/null @@ -1,143 +0,0 @@ -import {coreDirectives, Component, Directive} from 'angular2/angular2'; -import {View} from 'angular2/src/core/annotations_impl/view'; - -import * as util from 'ionic/util'; -import {IonicConfig} from './config'; -import { - Aside, Content, Scroll, Refresher, - Slides, Slide, SlidePager, - Tabs, Tab, - List, Item, - Icon, - Checkbox, Switch, Label, Input, - Segment, SegmentButton, SegmentControlValueAccessor, - RadioGroup, RadioButton, SearchBar, - Nav, NavbarTemplate, Navbar, NavPush, NavPop -} from 'ionic/ionic'; - - -export class IonicView extends View { - constructor(config) { - let directives = [ - - // Angular - coreDirectives, - - // Content - Aside, Content, Scroll, Refresher, - List, Item, - Slides, Slide, SlidePager, - Tabs, Tab, - - // Media - Icon, - - // Form elements - Segment, SegmentButton, SegmentControlValueAccessor, - //Checkbox, Switch, Label, Input - //RadioGroup, RadioButton, SearchBar, - - // Nav - Nav, NavbarTemplate, Navbar, NavPush, NavPop - ]; - - config.directives = (config.directives || []).concat(directives); - super(config); - } -} - - -export class IonicDirective extends Directive { - constructor(ComponentType) { - super( appendModeConfig(ComponentType) ); - } -} - -export class IonicComponent extends Component { - constructor(ComponentType) { - super( appendModeConfig(ComponentType) ); - } -} - -function appendModeConfig(ComponentType) { - if (!ComponentType) { - return {}; - } - if (typeof ComponentType === 'object') { - return ComponentType; - } - - let config = ComponentType.config; - config.host = config.host || {}; - - const defaultProperties = config.defaultProperties; - - config.properties = config.properties || []; - - for (let prop in defaultProperties) { - // add the property to the component "properties" - config.properties.push(prop); - - // set the component "hostProperties", so the instance's - // property value will be used to set the element's attribute - config.host['[attr.' + util.pascalCaseToDashCase(prop) + ']'] = prop; - } - - // called by the component's onInit when an instance has been created and properties bound - ComponentType.applyConfig = (instance) => { - for (let prop in defaultProperties) { - // Priority: - // --------- - // 1) Value set from within constructor - // 2) Value set from the host element's attribute - // 3) Value set by the users global config - // 4) Value set by the default mode/platform config - // 5) Value set from the component's default - - if (instance[prop]) { - // this property has already been set on the instance - // could be from the user setting the element's attribute - // or from the user setting it within the constructor - continue; - } - - // get the property values from a global user/platform config - let configVal = IonicConfig.global.setting(prop); - if (configVal) { - instance[prop] = configVal; - continue; - } - - // wasn't set yet, so go with property's default value - instance[prop] = defaultProperties[prop]; - } - }; - - if (config.delegates) { - ComponentType.getDelegate = (instance, delegateName) => { - let cases = config.delegates[delegateName] || []; - for (let i = 0; i < cases.length; i++) { - let delegateCase = cases[i]; - if (util.isArray(delegateCase)) { - let [ check, DelegateConstructor ] = delegateCase; - if (check(instance)) { - return new DelegateConstructor(instance); - } - } else { - return new delegateCase(instance); - } - } - }; - } - - if (!platformMode) { - platformMode = IonicConfig.global.setting('mode'); - } - - let id = config.classId || (config.selector && config.selector.replace('ion-', '')); - config.host['class'] = (id + ' ' + id + '-' + platformMode); - - return config; -} - -let platformMode = null; diff --git a/ionic/routing/path-recognizer.js b/ionic/routing/path-recognizer.js deleted file mode 100644 index 1749a76810..0000000000 --- a/ionic/routing/path-recognizer.js +++ /dev/null @@ -1,181 +0,0 @@ -import { - RegExp, - RegExpWrapper, - RegExpMatcherWrapper, - StringWrapper, - isPresent, - isBlank, - BaseException, - normalizeBlank -} from 'angular2/src/facade/lang'; -import { - Map, - MapWrapper, - StringMap, - StringMapWrapper, - List, - ListWrapper -} from 'angular2/src/facade/collection'; - - -class ContinuationSegment { - generate(params) { - return ''; - } -} - -class StaticSegment { - constructor(string) { - this.name = ''; - this.regex = escapeRegex(string); - } - - generate(params) { - return this.string; - } -} - -class DynamicSegment { - constructor(name) { - this.regex = "([^/]+)"; - } - - generate(params) { - if (!StringMapWrapper.contains(params, this.name)) { - throw new BaseException( - `Route generator for '${this.name}' was not included in parameters passed.`) - } - return normalizeBlank(StringMapWrapper.get(params, this.name)); - } -} - - -class StarSegment { - constructor(name) { - this.regex = "(.+)"; - } - - generate(params) { - return normalizeBlank(StringMapWrapper.get(params, this.name)); - } -} - - -var paramMatcher = RegExpWrapper.create("^:([^\/]+)$"); -var wildcardMatcher = RegExpWrapper.create("^\\*([^\/]+)$"); - -function parsePathString(route: string) { - // normalize route as not starting with a "/". Recognition will - // also normalize. - if (StringWrapper.startsWith(route, "/")) { - route = StringWrapper.substring(route, 1); - } - - var segments = splitBySlash(route); - var results = []; - var specificity = 0; - - // The "specificity" of a path is used to determine which route is used when multiple routes match - // a URL. - // Static segments (like "/foo") are the most specific, followed by dynamic segments (like - // "/:id"). Star segments - // add no specificity. Segments at the start of the path are more specific than proceeding ones. - // The code below uses place values to combine the different types of segments into a single - // integer that we can - // sort later. Each static segment is worth hundreds of points of specificity (10000, 9900, ..., - // 200), and each - // dynamic segment is worth single points of specificity (100, 99, ... 2). - if (segments.length > 98) { - throw new BaseException(`'${route}' has more than the maximum supported number of segments.`); - } - - var limit = segments.length - 1; - for (var i = 0; i <= limit; i++) { - var segment = segments[i], match; - - if (isPresent(match = RegExpWrapper.firstMatch(paramMatcher, segment))) { - results.push(new DynamicSegment(match[1])); - specificity += (100 - i); - } else if (isPresent(match = RegExpWrapper.firstMatch(wildcardMatcher, segment))) { - results.push(new StarSegment(match[1])); - } else if (segment == '...') { - if (i < limit) { - // TODO (matsko): setup a proper error here ` - throw new BaseException(`Unexpected "..." before the end of the path for "${route}".`); - } - results.push(new ContinuationSegment()); - } else if (segment.length > 0) { - results.push(new StaticSegment(segment)); - specificity += 100 * (100 - i); - } - } - - return {segments: results, specificity}; -} - -function splitBySlash(url: string): List { - return url.split('/'); -} - - -// represents something like '/foo/:bar' -export class PathRecognizer { - - constructor(path) { - this.segments = []; - - // TODO: use destructuring assignment - // see https://github.com/angular/ts2dart/issues/158 - var parsed = parsePathString(path); - var specificity = parsed['specificity']; - var segments = parsed['segments']; - var regexString = '^'; - - ListWrapper.forEach(segments, (segment) => { - if (segment instanceof ContinuationSegment) { - this.terminal = false; - } else { - regexString += '/' + segment.regex; - } - }); - - if (this.terminal) { - regexString += '$'; - } - - this.regex = RegExpWrapper.create(regexString); - this.segments = segments; - this.specificity = specificity; - } - - parseParams(url) { - var params = StringMapWrapper.create(); - var urlPart = url; - for (var i = 0; i < this.segments.length; i++) { - var segment = this.segments[i]; - if (segment instanceof ContinuationSegment) { - continue; - } - - var match = RegExpWrapper.firstMatch(RegExpWrapper.create('/' + segment.regex), urlPart); - urlPart = StringWrapper.substring(urlPart, match[0].length); - if (segment.name.length > 0) { - StringMapWrapper.set(params, segment.name, match[1]); - } - } - - return params; - } - - generate(params) { - return ListWrapper.join( - ListWrapper.map(this.segments, (segment) => '/' + segment.generate(params)), ''); - } -} - -var specialCharacters = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\']; -var escapeRe = RegExpWrapper.create('(\\' + specialCharacters.join('|\\') + ')', 'g'); - -function escapeRegex(string): string { - return StringWrapper.replaceAllMapped(string, escapeRe, (match) => { return "\\" + match; }); -} diff --git a/ionic/routing/router.js b/ionic/routing/router.js deleted file mode 100644 index 2cf624b362..0000000000 --- a/ionic/routing/router.js +++ /dev/null @@ -1,169 +0,0 @@ -import { - RegExp, - RegExpWrapper, - RegExpMatcherWrapper, - StringWrapper, - isPresent, - isBlank, - BaseException, - normalizeBlank -} from 'angular2/src/facade/lang'; - -import * as util from '../util/util'; -import {PathRecognizer} from './path-recognizer'; - - -export class IonicRouter { - constructor(config) { - this._routes = {}; - this._viewCtrls = []; - this.config(config); - } - - app(app) { - this._app = app; - } - - config(config) { - for (let routeName in config) { - this.addRoute(routeName, config[routeName]); - } - } - - addRoute(routeName, routeConfig) { - if (routeName && routeConfig && routeConfig.path) { - this._routes[routeName] = new Route(routeName, routeConfig) - } - } - - init() { - let rootViewCtrl = this.activeViewController(); - if (rootViewCtrl) { - let matchedRoute = this.match( this.getCurrentPath() ) || this.otherwise(); - this.push(rootViewCtrl, matchedRoute); - } - } - - match(path) { - let matchedRoute = null; - let routeMatch = null; - let highestSpecifity = 0; - - for (let routeName in this._routes) { - routeMatch = this._routes[routeName].match(path); - - if (routeMatch.match && (!matchedRoute || routeMatch.specificity > highestSpecifity)) { - matchedRoute = this._routes[routeName]; - highestSpecifity = routeMatch.specificity; - } - } - return matchedRoute; - } - - otherwise(val) { - if (arguments.length) { - this._otherwise = val; - - } else if (this._otherwise) { - return this._routes[this._otherwise]; - } - } - - push(viewCtrl, route) { - let self = this; - - function run() { - self._app.zone().run(() => { - viewCtrl.push(route.cls); - }); - } - - if (viewCtrl && route) { - if (route.cls) { - run(); - - } else if (route.module) { - System.import(route.module).then(m => { - if (m) { - route.cls = m[route.name]; - run(); - } - }); - } - } - } - - stateChange(activeView) { - if (activeView && activeView.ComponentType) { - - let routeConfig = activeView.ComponentType.route; - if (routeConfig) { - let matchedRoute = this.match(routeConfig.path); - - if (matchedRoute) { - this.updateState(matchedRoute); - } - } - } - } - - updateState(route) { - let newPath = route.path; - if (window.location.hash !== '#' + newPath) { - console.log('updateState', newPath); - window.location.hash = newPath; - } - } - - addViewController(viewCtrl) { - this._viewCtrls.push(viewCtrl); - } - - activeViewController() { - if (this._viewCtrls.length) { - return this._viewCtrls[ this._viewCtrls.length - 1 ]; - } - return null; - } - - getCurrentPath() { - let hash = window.location.hash; - // Grab the path without the leading hash - return hash.slice(1); - } - -} - - -export class Routable { - constructor(cls, routeConfig) { - cls.route = routeConfig; - } -} - - -class Route { - constructor(name, routeConfig) { - this.name = name; - this.cls = null; - util.extend(this, routeConfig); - this.recognizer = new PathRecognizer(this.path); - } - - match(matchPath) { - let routeMatch = new RouteMatch(this, matchPath); - if (routeMatch) { - return routeMatch; - } - return false; - } - -} - -class RouteMatch { - constructor(route, matchPath) { - this.route = route; - this.specificity = route.recognizer.specificity; - this.match = RegExpWrapper.firstMatch(route.recognizer.regex, matchPath); - } -}