Ionic Framework display dynamic value inside $ionicLoading - ionic-framework

How can I display a dynamic value inside of ionicLoading?
Here is my code to show $ionicLoading, the idea here is to display download progress:
$rootScope.updateProgress = 0;
$ionicLoading.show({
template: 'Updating...' + $rootScope.updateProgress
});
And later in my code I update $rootScope.updateProgress's value:
var iPecent = Math.round(downloadProgress.receivedBytes / downloadProgress.totalBytes * 100);
$rootScope.$apply(function () {
$rootScope.updateProgress = iPecent;
});
However, $rootScope.updateProgress's value is not reflected when $ionicLoading is displayed on the screen - just shows initial value of 0. If I log out $rootScope.updateProgress's value it is reflecting current download progress.

Let me use cordova-plugin-file-transfer as an example:
$ionicLoading.show({
template: 'downloading...'
});
$cordovaFileTransfer.download(source, filePath, options, trustAllHosts).then(function (result) {
console.log('download successfully!');
$ionicLoading.hide();
}, function (err) {
alert('download failed!' + err);
}, function (progress) {
var downloadProgress = (progress.loaded / progress.total) * 100;
$ionicLoading.show({
template: "Downloaded:" + Math.floor(downloadProgress) + "%"
});
if (downloadProgress >= 100) {
$ionicLoading.hide();
}
});

I believe this was requested and added here https://github.com/driftyco/ionic/issues/699.
I haven't tested it, but based on the statement:
Use $ionicLoading.show() while the loader is open with new content,
and it will update the content.
If you call .show() subsequent to a $ionicLoading already showing, it should update the content.. If this feature is in fact now part of Ionic, and you put in some sort of loop and delay routine, you should be able to achieve what you're after.

Hi i am using show percentage of image uploading like 19%...
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
$ionicLoading.show({
template: 'Uploading Start....' + parseInt(100.0 * evt.loaded /evt.total) + '%',
});
where evt is callback of progress method.

Related

How to use the numericRefinementList to set allowed distances?

I would like to be able to use the numericRefinementList to allow users to pick the distance from themselves an item can be? This would be using the IP geo-location feature or inputting the geo-location from browser if available.
Less than 50km
50 - 100km
100 - 150km
More than 150km
https://community.algolia.com/instantsearch.js/documentation/#numericrefinementlist
This is unfortunately not something you can do with the numericRefinementList but you can probably build a custom widget setting the aroundRadius depending on the link you've clicked on:
function radiusList(options) {
if (!options.container) {
throw new Error('radiusList: usage: radiusList({container, ...})');
}
var $container = $(options.container);
if ($container.length === 0) {
throw new Error('radiusList: cannot select \'' + options.container + '\'');
}
return {
init: function(args) {
// event delegation: set the aroundRadius of the underlying link
$(document).on('click', '.radius-link', function(e) {
e.preventDefault();
args.helper.setQueryParameter('aroundRadius', +$(this).data('radius'));
args.helper.search();
});
},
render: function(args) {
// FIXME: display the list of radius links
var html = '<ul>';
html += '<li>< 100km</li>';
html += '</ul>';
$container.html(html);
}
};
}
And then you use it with:
search.addWidget(radiusList({container: '#my-radius-list'}));

Cannot read property 'download' of undefined $cordovaFileTransfer in Ionic

I want to use $cordovaFileTransfer in my app to dowload image data, but after trying to implement the code, this error is showing up:
Cannot read property 'download' of undefined
here is my code:
var url = "blablabla.com/img.png";
var targetPath = "img/"+ imgpaths;
var trustHosts = true;
var options = {};
$cordovaFileTransfer.download(url, targetPath, options, trustHosts)
.then(function(result) {
// Success!
console.log('Download Success' + targetPath);
}, function(err) {
// Error
}, function (progress) {
$timeout(function () {
var downloadProgress = (progress.loaded / progress.total) * 100;
console.log('Progress : '+downloadProgress);
});
});
anybody can help me?
Check this issues list:
http://ngcordova.com/docs/common-issues/
For example have you wrapped the call to $cordovaFileTransfer.download() inside deviceready handler or better inside $ionicPlatform.ready() ?

Leaflet sidebar not opening on load

I'm using the leaflet-sidebarv2 plugin to create a sidebar for a cartodb/leaflet map. I'm running into problems that I a.) can't get the options to work – close button, autoPan, etc) and b.) can't use setContent to dynamically set data.
The sidebar functions as expected. The problem is modifying it seems to have no effect. I also get an error "Uncaught TypeError: undefined is not a function" on the setTimeout and setContent lines.
cartodb.createLayer(map, {
user_name: {{user_name}},
type: 'cartodb',
sublayers: [{
sql: 'select * from {{table_name}}',
cartocss: '#layer',
interactivity: 'cartodb_id, name',
auto_bound: true
}]
})
.addTo(map)
.done(function(layer) {
var barData;
barData = layer.createSubLayer({
sql: 'select * from {{table_name}}',
cartocss: '#layer {marker-fill: #bababa; marker-opacity: 0.3; marker-width: 4px; }',
interactivity: 'name, location'
});
//on click
barData.on('featureClick', function(e, pos, pixel, data) {
//log active data
console.log("Name: " + data.name + " # " + data.location);
$('#map').css('cursor', 'pointer');
});
barData.setInteraction(true);
//hover pop-up
var infobox = new cdb.geo.ui.InfoBox({
width: 100,
layer: layer,
template: '<p class="cartodb-infobox">{{name}}</p></br><p>{{location}}</p>',
position: 'top|right' // top, bottom, left and right are available
});
$("body").append(infobox.render().el);
// leaflet-sidebar> closeButton not engaging
var sidebar = L.control.sidebar('sidebar', {closeButton: true});
map.addControl(sidebar);
//content not showing up anywhere
sidebar.setContent('test <b>test</b> test');
// sidebar still collapsed at reload
setTimeout(function () {
sidebar.show();
}, 500);
});
}
window.onload = main;
Any suggestions on what I might be doing wrong? I've got all the right pieces loaded in the head.
You seem to be using the wrong API. The setContent() method and the options hash is part of the leaflet-sidebar library API, but not of sidebar-v2.

Json parse from Facebook events

I have had some trouble with fetching json from a groups events on facebook and then put them in a tableview to be used in a Appcelerator mobile app.
The idea is to have this as a calendar to show events for a club in a simple way.
I want to show the name of the event. The picture for that event and the date for the event.
All in a tablerow.
I have gotten to the part where i can get the Name and date for the events with this code:
Ti.UI.backgroundColor = '#dddddd';
var access_token='AAACEdEose0cBAAICGa4tFTcZAqCOGm2w9qPYGZBwNtJ1oZAcwaMAP2DDHZCN58cvVBZCHZADZAZBTPC8tTnpfQ7uGKI5j3SbMYcRmWquZCdPzhwZDZD';
var url = "https://graph.facebook.com/64306617564/events?&access_token=" + access_token ;
var win = Ti.UI.createWindow();
var table = Ti.UI.createTableView();
var tableData = [];
var json, data, row, name, start_time, id;
var xhr = Ti.Network.createHTTPClient({
onload: function() {
// Ti.API.debug(this.responseText);
json = JSON.parse(this.responseText);
for (i = 0; i < json.data.length; i++) {
data = json.data[i];
row = Ti.UI.createTableViewRow({
height:'60dp'
});
var name = Ti.UI.createLabel({
text:data.name,
font:{
fontSize:'18dp',
fontWeight:'bold'
},
height:'auto',
left:'50dp',
top:'5dp',
color:'#000',
touchEnabled:true
});
var start_time = Ti.UI.createLabel({
text:'"' + data.start_time + '"',
font:{
fontSize:'13dp'
},
height:'auto',
left:'15dp',
bottom:'5dp',
color:'#000',
touchEnabled:true
});
row.add(name);
row.add(start_time);
tableData.push(row);
}
table.setData(tableData);
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT: " + this.responseText);
Ti.API.debug("ERROR: " + e.error);
alert('There was an error retrieving the remote data. Try again.');
},
timeout:5000
});
xhr.open("GET", url);
xhr.send();
But when i want the specific event to open in a new window when clicked i just get the event that lies last on the screen when i put this in a browser:
https://graph.facebook.com/64306617564/events?&access_token=AAACEdEose0cBAOLAFWMKPmvgqEwap1ldnl7DeZBDKJC6YTZC4Goh6K5NHsvpOFmFQaGp1IekVsCxZCZCz3lwGpRcQG9ZBkcMrZAnLk4As8kgZDZD
And the access token expires REALLY fast. Any ideas how to make an access token that lasts longer?
Well, the code i am using to open the window is:
table.addEventListener('click',function(e) {
// Create the new window with the link from the post
var blogWindow = Ti.UI.createWindow({
title : data.name,
modal : true,
barColor: '#050505',
backgroundColor: '#050505'
});
var webView = Ti.UI.createWebView({url:'http://www.facebook.com/events/' + data.id});
blogWindow.add(webView);
// Create the close button to go in the left area of the navbar popup
var close = Titanium.UI.createButton({
title: 'Close',
style: Titanium.UI.iPhone.SystemButtonStyle.PLAIN
});
blogWindow.setLeftNavButton(close);
// Handle the close event
close.addEventListener('click',function() {
blogWindow.close();
});
blogWindow.open();
});
win.add(table);
win.open();
in my opinion that should open the event that is clicked on by parsing the ID from the row and putting it after the link.
Am i retarded or what is wrong?
It doesnt matter on which event i click it just open the last one all of the times.
And how can i get a thumbnail for the events?
Pls help........
When you click on table to get value from data which is not available.You can achieve it using you custom variable try to put this line of code at your row creation where you add your row in array i.e.row.data = data; and on table click event get that object using this alert(e.source.data); and check it. Best luck

help with onseek and selectors

I am using this:
$(function() {
// initialize scrollable
window.api = $("div.scrollable").scrollable({
clickable: true,
activeClass: "active",
onSeek: function() {
alert("current position is: " + this.getIndex());
//remove highlighting from all images
$(".items img").removeClass("selected");
var position = this.getIndex().toString();
var thisItem = $(".items:nth-child(" + position + ")");
//var thisItem = allItems(this.getIndex);
alert("item is: " + $(this).attr('alt'));
changeimage($(".items:nth-child(2)"));
}
}).circular().autoscroll({
interval: 4000,
api: true,
autoplay: false,
steps: 1
});
});
(just testing) so that I can parse the current item to my changeimage() function
But all I get in my alerts are undefined.
WHat do I need to do here to get the current item
You can get the current item using the api by calling the following:
var currentItem = window.api.getItems().eq(window.api.getIndex());
The getIndex() function gets a numerical position of the element and getItems gets a jquery object with all the items within it. Using the eq() function asks for the item at the given position.
I've sometimes had bad luck with it, but within the onSeek callback, you should be able to use 'this' variable in place of the windows.api which would look like:
var currentItem = this.getItems().eq(this.getIndex());