Let me start this post with a disclaimer that “Don’t panic by reading the post title”. It might look bit lengthy, but still summarises what we are trying to achieve here.
Let me explain you in four steps,
- Creating a Cordova project with ionic and Angularjs in Visual Studio 2015.
- Creating a new MobileFirst Hybrid Application.
- Importing required files from Visual studio 2015 Cordova project to MobileFirst application.
- Code tweaks here and there to make it work with MobileFirst Platform server.
So, let’s get started !!!
Visual Studio 2015 Cordova Project with Ionic and Angular
Visual studio started supporting Cordova as an option for web developers to leverage their HTML,CSS and Javascript skills in mobile app development.
As Visual studio 2015(VS2015) is the latest release from Microsoft, I will be using Visual Studio 2015 Community edition for this blog post.
- Open Visual Studio (Run as an Administrator) and on the menu bar choose File -> New -> project.
- On the New Project dialog box, navigate to Javascript on the left and choose Blank App under Apache Cordova Apps as shown in the snapshot below.
Note: If you don’t see this option, install Cordova Tools for Visual Studio 2015.
Creating a MobileFirst Hybrid Application
First of all, Let me take the privilege of answering an unasked question.Just think that this is a Q which my own soul is asking myself.
What is IBM MobileFirst platform?
IBM MobileFirst Platform(MFP) is a mobile development platform that provides development and deploy options both on the cloud (Bluemix) and on-premise (installed locally). MobileFirst Platform enables you to build, enhance, and continuously deliver mobile apps efficiently and effectively. It extends the development, delivery, and management capabilities of MobileFirst Platform Foundation by adding scalable data services.
To know more, please visit our developer website or Andrew Trice’s blog .
Note: For this post, we will be using MFP 7.0 Version and will start by adding a windows phone environment and then see how to add ios and android to it.
You may be wondering, why i haven’t explained about the Cordova app folder structure in-detail. The answer is – There is a good link which guides you on how to create a hybrid application and also explains the structure of Cordova app as MobileFirst uses Cordova under the hood for hybrid apps.
Creating your first Hybrid application.
Note: MobileFirst environment setup is out of the scope of this post and you can learn more about it here.
With the hope that everything went smooth and you are all set with MobileFirst Platform including MFP Server. Let’s preview our application by deploying it to MFP server. To do that here’s what you do
Once your Hybrid application is successfully deployed to MFP Server. You should see your windows phone app running on Mobile Browser Simulator as shown in the snapshot below.
Importing Cordova Windows Phone App into MobileFirst
It’s time to import our Cordova Windows Phone app with UI framework Ionic and angularJS included into our newly created MobileFirst Hybrid application which is just saying “Hello MobileFirst” as of now.
- Rename the common folder to common_original– just in case something goes wrong we can always revert.
- Create a new folder common next to the common_original folder and copy all the files + folders from www folder of VS 2015 Windows phone solution to the newly created common folder.
Now your folder structure should look like this
Code tweaks to playlist app
To make our Visual Studio imported playlist app to work on MFP server, there are few code changes to be made.
- Open index.html and comment Cordova.js script inclusion.This is required as MobileFirst will include this script tag later.
<!--<script src="cordova.js">-->
- Copy & Paste the MobileFirst initialisation code sitting in initOptions.js and main.js under common_original/js/ folder to app.js under common/js/ (don’t remove existing contents of app.js)
Note: To understand more on this, read Ray’s blog Here’s the complete app.js,
angular.module('starter', ['ionic', 'starter.controllers'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function ($compileProvider, $stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.search', {
url: "/search",
views: {
'menuContent': {
templateUrl: "templates/search.html"
}
}
})
.state('app.browse', {
url: "/browse",
views: {
'menuContent': {
templateUrl: "templates/browse.html"
}
}
})
.state('app.playlists', {
url: "/playlists",
views: {
'menuContent': {
templateUrl: "templates/playlists.html",
controller: 'PlaylistsCtrl'
}
}
})
.state('app.single', {
url: "/playlists/:playlistId",
views: {
'menuContent': {
templateUrl: "templates/playlist.html",
controller: 'PlaylistCtrl'
}
}
});
$urlRouterProvider.otherwise('/app/playlists');
});
var wlInitOptions = {
};
if (window.addEventListener) {
window.addEventListener('load', function() { WL.Client.init(wlInitOptions); }, false);
} else if (window.attachEvent) {
window.attachEvent('onload', function() { WL.Client.init(wlInitOptions); });
}
function wlCommonInit(){
}
- Open style.css under common/css and paste this code.
html,body{
height:100%;
}
As Ray says “This is required because the application ends up with a 0% height when run under MobileFirst.”
We are all done. The only pending thing is to build and deploy our imported Cordova playlists app.
As we are good with Windows phone app, Let’s see how to add iOS and android MobileFirst environments to our existing MobileFirst playlists app in this silent video.
Finally, Build & Deploy the imported playlist app to see….Would like to hear from you.
Hope you enjoyed the walkthrough.Add your comments and Happy Coding !!!!
CodeProject
The post Importing Visual studio Cordova project with Ionic and AngularJS into IBM MobileFirst appeared first on Vidyasagar MSC.