Ionic 2 (beta 6) / Angular 2 - Styled Upload / Attachment compoment

According to this issue: github.com/driftyco/ionic/issues/6628 we needed a solution to the problem. It ended up in a little custom component. Maybe this will be a temporary solution to others too or it could be basis for an ionic included solution.

Attention: As this was my first typescript, angular 2 component and also the first project with these tools, please be merciful if it includes bad practices or other mistakes. It is more a first draft than a final solution. Any improvements and fixes are welcome. We used the common practice for this styling issues and translate it to Angular. A hidden input element combined with a button doing the work.

Usage is simple just use the newly created tag ant tell it which ionic icon to use for the button. Also a callback must be defined which is executed after files are selected (FileList is passsed as parameter to it):

<upload-button [btnCallback]="addCallback" [btnStyle]="icon"></upload-button>
import {IONIC_DIRECTIVES} from "ionic-angular";
import {Component, ElementRef, Input, Inject, ViewChild, Renderer} from "angular2/core";
import {Log} from "../../log";

@Component({
  directives: [IONIC_DIRECTIVES],
  selector: "upload-button",
  template: `<button (click)="callback($event)" clear>
               <ion-icon name="{{btnStyle}}"></ion-icon>
             </button>
             <input type="file" (change)="filesAdded($event)" style="display: none" multiple #input />`
})

/**
 * Upload button component.
 *
 * As native input elements with type file are diffcult to style, it is common
 * practice to hide them and trigger the needed events manually as it done here.
 * A button is is used for user interaction, next to the hidden input.
 */
export class UploadButton {

  /**
   * The callback executed when button pressed, set by parent
   */
  @Input()
  private btnStyle: String;

  /**
   * The callback executed when files are selected, set by parent
   */
  @Input()
  private btnCallback: Function;

  /**
   * Native upload button (hidden)
   */
  @ViewChild("input")
  private nativeInputBtn: ElementRef;

  /**
   * Constructor
   * @param  {Renderer} renderer for invoking native methods
   * @param  {Log}      logger instance
   */
  constructor(private renderer: Renderer, @Inject(Log) private logger: Log) {}

  /**
   * Callback executed when the visible button is pressed
   * @param  {Event}  event should be a mouse click event
   */
  public callback(event: Event): void {
    this.logger.debug("upload-button callback executed");

    // trigger click event of hidden input
    let clickEvent: MouseEvent = new MouseEvent("click", {bubbles: true});
    this.renderer.invokeElementMethod(
        this.nativeInputBtn.nativeElement, "dispatchEvent", [clickEvent]);
  }

  /**
   * Callback which is executed after files from native popup are selected.
   * @param  {Event}    event change event containing selected files
   */
  public filesAdded(event: Event): void {
    let files: FileList = this.nativeInputBtn.nativeElement.files;
    this.logger.debug("Added files", files);
    this.btnCallback(files);
  }
}

/bin/bash: error while loading shared libraries: libgcc_s.so.1

After a couple of Portage-based updates, including GCC, I was the victim of a loss of connection to my headless RaspberryPi server. Afterwards I was not able to use "su" or "sudo" because of the following error message:

error while loading shared libraries: libgcc_s.so.1: cannot open shared object file: No such file or directory

RaspberryPi - A little USB device speed test

After installing sucessfully Gentoo on my Raspberry Pi, I decided to do a little speed test one of my USB sticks to find the best filesystem to enhance Pi's storage capabilities. The candidate is the SanDisk's Cruzer Blade with 32GB (PCI 0781:5567).

RaspberryPi - Install Gentoo (headless)

After buying a Raspberry Pi for home automation and a building a little home server, I decided to install again Gentoo as my favorite OS. There a lot of Tutorials out there which handles this topic. Also there are some of them that describe the steps to do for a working installation without monitor and keyboard. So, I want to thank all the contributors, blog an howto writers that have inspired me to write this one. Even if I try to comment every step in detail, this is more like a Todo list for myself.

Eclipse & jrunscript: Auto completion

To get jrunscript auto completion working inside Eclipse, there are only a few steps needed. First the source code (including JSDoc) of the used JDK has to be extracted. Jrunscript's global functions and objects are located in the init.js file which is part of the tools.jar. For my Win7 / Cygwin setup I used the command line:

PhoneGap Build - Facebook Connect (Part 3)

PhoneGap Build - Facebook Connect (Part 3)

After helping many people with Part 2 there is the time to update the guide. If using PG > 2.9 you have to slightly change your config.xml for PhoneGap's build service. The correct syntax now is the following:

MongoDB as Cache: Some performance tests

As we needed some kind of ID cache for synchronization purposes, which is fast and durable. By having some experience with CouchDB, a NoSQL solution seems to be worth a try. I decided to do some performance tests against the already available and running MongoDB in our server infrastructure.

Formerly we filled a LinkedList (yes, it is a bigger Java project as the "java" tag suggests ;)) by an expensive SQL database at server start (Oracle or SQL Server). Afterwards we had to check, again very expensive, with "contains" if elements are inside. Also the list was limited to a fixed size and contained only the newest IDs.

Javascript - Getter are evil? - Some performance tests

According to this nice article Javaworld (09-2003)  I decided to check getters and setters runtime behavior with JavaScript inside different browsers and on different machines. I tested also the different initialization possibilities, with some unexpected, but not really surprising, results.

Some interpretation tries... Chrome seems to be very constant in each kind of implementation, also it slightly improve its performance in newer versions. Firefox has the highest variation, but again newer version have better times. IE9 does a good job in this case, constant times and very fast. As expected IE8 has runtime problems even with this simple script.

It would be nice if some people add their results, maybe with some more browser versions, like Safari, IE10, Opera, ...

PhoneGap - Remote error logging (incl. uncaught script errors)

Catching and logging runtime errors, like script errors, in PhoneGap can be a challenge. There are several possibilities to write logs and to handle errors with different advantages and disadvantages.

First, local error logging means to create a functionality to send data to a place where someone cares about. Also this will spam the device with a text file or database, occupies memory and the question "when to send where?" has to be solved.

PhoneGap 2.5 - FileTransfer options filename issue

One short missing documentation hint concerning the filename. If using Camera.PictureSourceType.SAVEDPHOTOALBUM you have, at least on Android, to distinguish for FileUploadOptions. If using CAMERA as source type with Camera.DestinationType.FILE_URI the options.filename is not needed for transferring correctly. Check following code snippet:

PhoneGap build, hydration & require.js

Newer versions of PhoneGap support lazy loading of javascript, > 2.4 iOs is working as well. To load injected js files (like phonegap.js and plugins) from the build service with requirejs and hydration enabled, you'll have to include the /data/data/XXX/hydra_app/ directory in paths config (replace XXX with your widget id in config.xml) The starting slash will bypass the baseUrl parameter:

jQuery Mobile - Panel height with big content

To have a nice menu in my PhoneGap application, I decided to use jQuery Mobile 1.3 panels. Because of loading content dynamically, I had some problems with scrolling.

If my dynamically loaded content was higher than the menu, the panel scroll didn't fit. The scroll behavior is dependent on the page scroll (nicely described in jQuery Mobile's issue tracker: "Make panel and page content scroll independently"). But I have found a solution based on the panel events and css overflow & height properties, testet only on Android > 4 so far.

Phonegap - Real persistent storage module (incl jQuery deferred example)

There are several possibilities to store persistent data for a mobile app in Phonegap. But because you cannot be not sure that native HTML capabilities, e.g. localStorage is really stored permanently (see discussion on GoogleGroups), I decided to share my little RequireJS module prototype. It uses JSON and the mobile filesystem which enables also the possibility to use the data even after the app was completely deleted and reinstalled.

Howto: PhoneGap & Youtube (API)

Just a quick win... if your target is to show Youtube videos,  full screen, inside a PhoneGap mobile app... just use Youtube's HTML5 embedding possibilities in combination with PhoneGap's InAppBrowser:

PhoneGap Build - Facebook Connect (Part 2)

After several inquiries, in addition of the links provided in Part 1 here is some sample code for Facebook SSO in a PhoneGap environment (using build.phonegap.com and jQuery Mobile 1.3 for user interface). The connect worked for me currently only on Android devices, but no longer on iOs (using PG version 2.3.0). One obstacle is certainly that I have no Apple device for development, local builds or debugging, only Android.

Cygwin - VisualVM

I tried to use VisualVm for profiling purposes in my current development setup (running Win7 and Cygwin). But the tool did not find my running Java server nor the client, only Eclipse IDE was listed as local application. After some research on the web I figured out that VisualVM searches for the PID file of running java processes in the system's temporary folder. Because of starting the server and client on commandline via Cygwin the PID files were stored in Cygwin's /tmp folder (which is by default not the same than the system' temp).

Google Drive - Bulk letter generation

After having found no solution on the web to generate bulk letters, I decided to write a little script (MS-Word style but using Google Drive). Also a good start for me to get in touch with Google Apps Scripts, the requirements are simple:

PhoneGap Build API - Ant deploy helper script

After starting to develop a mobile app based on PhoneGap and its build service, I decided to automate the deployment via REST. Here is my little ant script. Feel free to adopt, extend, comment and / or share.

Cygwin - Switching Java version

A little bash script to switch your JAVA_HOME and PATH in Cygwin:


PhoneGap Build - Facebook Connect (Part 1)

I am currently developing a mobile app / client based on the frameworks; PhoneGap and jQueryMobile. My current implementation uses Cordova / PhoneGap  Version 2.2.0 and the build service provided by Adobe.

Because the app is connected to a social website, it uses the Facebook OAuth capabilities for easy single sign on (as on web version too). There came up several issues during integration of the Facebook Connect Plugin into my beta version. For saving the web from redundancy, I am documenting the issues here, by linking:

The story continues, for sample code checkout Part 2