A Feedback App in Minutes With Ionic and Cloudant
Perfect for meetups and the like, you can create your own feedback app with the open source Ionic and the DBaaS Cloudant that works on iOS and Android.
Join the DZone community and get the full member experience.
Join For FreeAn Ionic feedback app using Cloudant NoSQL service on IBM Bluemix is an easy-to-configure mobile app for receiving feedback at meetups, events, etc.,
Ionic is a complete open-source SDK for hybrid mobile app development. Built on top of AngularJS and Apache Cordova, Ionic provides tools and services for developing hybrid mobile apps using web technologies like CSS, HTML5, and SASS.
Cloudant is a distributed database as a service (DBaaS) built from the ground up to deliver fast-growing application data to the edge.
The app runs on iOS and Android and is built using Ionic Version 1.7.13.
iOS
Android
Creating a Cloudant NoSQL DB Service on IBM Bluemix
- Don’t have Bluemix account? Sign up to create a free trial account.
- Have a Bluemix account? Use this link.
Add a new Cloudant data service in just a few clicks:
- Visit your Bluemix dashboard.
- Click Catalog.
- On the left pane, click on Data & Analytics under Services.
- Click the Cloudant NoSQL DB tile.
- Enter a unique, descriptive name in the Service name field.
- Check Features, Images, and Pricing Plans.
- Click the Create button.
Cloudant Dashboard 2.0
Once the Cloudant service is created:
- Click the LAUNCH button to launch the Cloudant Dashboard 2.0 (powerful querying, analytics, replication, and syncing happens here) in a separate tab:
- Create a new database by clicking on Create Database on the top ribbon. Your database is created.
- From the left pane, click on Account -> CORS Tab -> Check All domains ( * ).
*Not recommended for all use cases, but with this being a simple mobile app, we're taking this liberty. Check the CORS documentation for more info.
Configuring the Ionic App With a Configuration File
Install Ionic:
npm install -g cordova ionic@1.7.13
Clone the repo:
$ git clone https://github.com/VidyasagarMSC/Ionic-Cloudant-FeedbackApp.git
- Open the unzipped folder in an IDE (I use Brackets) of your choice and navigate to the www/js folder.
- Create a new JavaScript file — app.config. With the extension, the file will be app.config.js
- Paste the below code in app.config.js:
angular.module('app').constant('CLOUDANTDB_CONFIG', {
baseUrl: 'https://',
dbName: '',
userName: '',
password: ''
});
- DBName: Name of the Cloudant NoSQL DB you created within Dashboard 2.0.
- For hostname, username, and password: Navigate to the Cloudant Service page on Bluemix and click the Service Credentials tab.
- Click on View Credentials under Actions. We're looking at Placeholder Cloudant Service
The CLOUDANTDB_CONFIG constant values are utilized in controllers.js
// Define the Credentials string to be encoded.
var credentialstobeEncoded = CLOUDANTDB_CONFIG.userName + ":" + CLOUDANTDB_CONFIG.password;
// Encode the String
var encodedString = Base64.encode(credentialstobeEncoded);
console.log("ENCODED: " + encodedString);
$scope.createFeedback = function (feedback) {
$http({
method: 'POST',
url: CLOUDANTDB_CONFIG.baseUrl + "/" + CLOUDANTDB_CONFIG.dbName,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + encodedString
},
Customize the App UI
- Images can be replaced with the same name under the img folder.
- Customize the feedback fields in feedback.html.
- There are validations on the fields based on the type. For example, email checks for an @ in the entry. Submit will be disabled until the form is completely valid.
Testing the App
Desktop browser testing:
$ ionic serve
On an iOS Simulator or Android Emulator:
$ ionic emulate ios
$ ionic emulate android
Note: Follow the Android and iOS platform guides to install required tools for development.
Notes:
- This sample uses only the POST HTTP API call of Cloudant Service. To understand other HTTP API Verbs, refer to the Cloudant documentation.
- Cloudant Client Libraries.
Published at DZone with permission of Vidyasagar Machupalli, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments