Building mobile applications with DrupalGap

49
SCHEDROV ALEXANDER SANCHIZ BUILDING MOBILE APPLICATIONS WITH DRUPALGAP

description

Building mobile applications with DrupalGap

Transcript of Building mobile applications with DrupalGap

Page 1: Building mobile applications with DrupalGap

SCHEDROV ALEXANDER !

SANCHIZ

BUILDING MOBILE APPLICATIONS

WITH DRUPALGAP

Page 2: Building mobile applications with DrupalGap

SCHEDROV ALEXANDER AKA

SANCHIZLead Drupal Developer at TrellonMaintainer : • pathauto_i18n • user_profile_comment • DrupalGapManager

https://github.com/Sanchiz/DrupalGapManager

Participant: • crm_core • relation_lists

Page 3: Building mobile applications with DrupalGap

“Never memorise what you can look up in books.”

- Albert Einstein

Page 4: Building mobile applications with DrupalGap

“Never memorise what you can look up IN YOUR PHONE.”

- not Albert Einstein

Page 5: Building mobile applications with DrupalGap

WHY WE NEED PROVIDES MOBILE APPLICATION TO

OUR CUSTOMERS?

Page 6: Building mobile applications with DrupalGap

MOBILE WEBSITE TRAFFICPercentage of website traffic from mobile devices

0

8

16

24

32

Q1 2013 Q2 2013 Q3 2013 Q4 2013 Q1 2014

32.0%30.0%

28.0%29.0%

23.9%

Page 7: Building mobile applications with DrupalGap

REGULAR SITE

Website

+

Responsive Website

Page 8: Building mobile applications with DrupalGap

Drupal Bootstrap

Site

Load CSS files

Load JS files

Load theme files(images, fonts)

Load content images

Receive response as markup

Show content to user

Drupal Bootstrap

Mobile application

Load content images

Receive response as JSON

Show content to user

Page 9: Building mobile applications with DrupalGap

HOW MOBILE APPLICATION DIFFERENT FROM RESPONSIVE SITE?

Our mobile phone have features which don't

have our regular devices!

It’s handy!

Page 10: Building mobile applications with DrupalGap

WHAT IS DRUPALGAP?

Page 11: Building mobile applications with DrupalGap

• Created by Tyler Frankenstein

• First release Feb 25, 2012 ~100 lines

• Currently ~10,000 lines

Page 12: Building mobile applications with DrupalGap

DRUPALGAP

Drupal module hosted on d.org

It's connection between mobile applications and Drupal websites via web Services.

Development Kit hosted on GitHub

Developers can create custom multi-platform mobile applications that communicate with their Drupal websites.

Page 13: Building mobile applications with DrupalGap

DRUPALGAP FEATURESYou don't need a Objective-C and Java developers.

!

If you know how to build Drupal modules and know JavaScript - Welcome to DrupalGap developers.

Page 14: Building mobile applications with DrupalGap

DrupalGap application it’s a good example of using headless Drupal

Page 15: Building mobile applications with DrupalGap
Page 16: Building mobile applications with DrupalGap

HOW IT WORKS?PhoneGap generates HTML, CSS

and JavaScript and make application iOS and Android mobile

devices.Apache Cordova provides access

via JavaScript to device features such as the

Camera, GPS, File System, Contacts, Compass, etc.

Page 17: Building mobile applications with DrupalGap

TYPES OF SITES WHICH CAN USE MOBILE APPLICATION

Any sites that you can imagine.

Page 18: Building mobile applications with DrupalGap

DRUPALGAP INSIDE

Page 19: Building mobile applications with DrupalGap

DEVELOPMENT REQUIREMENTS

ENVIRONMENTS

1. Google Chrome and Ripple Emulator extension

2. node.jscordova(node.js package)Java SDK for Android or xCode for iOS

DRUPAL

• services

• rest_server

• views_datasource

• views_json

Page 20: Building mobile applications with DrupalGap

DRUPALGAP INHERITS DRUPAL DEVELOPER CONCEPTS

• Themes, modules

• Blocks

• Menus

• Pages

• Entities

• Fields

• Forms

• Views

• Messages

• Services

• Other Drupal tools

Page 21: Building mobile applications with DrupalGap

EXTENSIBLE WITH CONTRIB MODULES• Force Authentication

• Telephone

• Address Field

• AmazonS3

• AudioField

• Colorbox

• Commerce

• Commerce DrupalGap Stripe

• Date

• Email Registration

• Entity reference

• Fivestar

• Flag

• Geofield

• GeoTracker

• Link

• Location

• LoginToboggan

• Pathfix

• Push Notifications

• Rate

• Services Menu

• Shadowbox

• User registration password

• Voting API

• Webform

http://www.drupalgap.org/project/modules

Page 22: Building mobile applications with DrupalGap

EXTENSIBLE API

http://api.drupalgap.org

Page 23: Building mobile applications with DrupalGap

We have a special tool for the Jedi!

Page 24: Building mobile applications with DrupalGap

DRUPALGAP MANAGER

https://github.com/Sanchiz/DrupalGapManager

https://www.npmjs.org/package/dgm

is a command-line tool and interface for DrupalGap

Page 25: Building mobile applications with DrupalGap

http://tylerfrankenstein.com/code/build-mobile-app-sell-products-with-drupal

Page 26: Building mobile applications with DrupalGap

SPECIAL FEATURES

Page 27: Building mobile applications with DrupalGap

GEOLOCATIONvar onSuccess = function(position) { console.log(position); }; var onError = function(error) { console.log(error.message); } navigator.geolocation.getCurrentPosition(onSuccess, onError);

var onSuccess = function(position) { console.log(position); } var onError = onError(error) { console.log(error.message); } !// Update is received every 30 seconds. var watchID = navigator.geolocation.watchPosition( onSuccess, onError, { timeout: 30000 } );

Page 28: Building mobile applications with DrupalGap

CAMERA ACCESS AND FILE BROWSER

Page 29: Building mobile applications with DrupalGap

PUSH NOTIFICATIONS

Google Cloud Messaging or

Apple Push Notification Service

Drupal site

Other systems

Sender Target deviceCloud server

Page 30: Building mobile applications with DrupalGap

Drupal module: https://www.drupal.org/project/push_notifications Cordova plugin: https://github.com/phonegap-build/PushPlugin DrupalGap module: https://github.com/signalpoint/push_notifications

Rules integration in 7.x-1.x-dev: https://www.drupal.org/node/1658132#comment-8512423

Page 31: Building mobile applications with DrupalGap

EXTENSIBLE WITH CORDOVA PLUGINS

http://plugins.cordova.io

Page 32: Building mobile applications with DrupalGap

DRUPAL 8

Page 33: Building mobile applications with DrupalGap

DRUPAL 8RESTful Web Services in Core

Page 34: Building mobile applications with DrupalGap

DRUPAL 8Views supports REST

Page 35: Building mobile applications with DrupalGap

#D8CX

#D8CX: I pledge that DrupalGap will have a full Drupal 8 release on the day that Drupal 8 is released (c) Tyler

All that we need - update DrupalGap SDK according to the changes in Drupal 8.

Page 36: Building mobile applications with DrupalGap

DEVELOPMENT

Page 37: Building mobile applications with DrupalGap

FILE STRUCTURE

modules

custom themes

settings.js

Page 38: Building mobile applications with DrupalGap

• MODULE_NAME (module folder) • MODULE_NAME.js (module file)

Drupal.modules.custom['MODULE_NAME'] = {};

app/settings.js:

/** * Implements hook_menu(). */ function MODULE_NAME_menu() { var items = {}; items['homepage'] = { title: 'New Sandbox', page_callback: 'MODULE_NAME_homepage' }; return items; } !function MODULE_NAME_homepage() { var content = {}; content['homepage'] = { markup: 'some markup' }; return content; }

Page 39: Building mobile applications with DrupalGap

drupalgap.settings.menus['homepage_menu'] = { links:[ {title:'News', path:'news'}, {title:'About', path:'node/1'}, {title:'Contact', path:'contact'}, {title:'Our team', path:'team'} ] };

app/settings.js:

Page 40: Building mobile applications with DrupalGap

drupalgap.settings.blocks.THEME_NAME = { content: { homepage_menu: { pages:{ value:['homepage'], mode:'include' } }, users_block: { pages:{ value:['node/*', 'user/*'], mode:'include' }, roles:{ value:['authenticated user'], mode:'include' } }, }, };

app/settings.js:

<div id="{:drupalgap_page_id:}" data-role="page"> {:header:} {:navigation:} {:content:} {:footer:} </div>

page.tpl.html

Page 41: Building mobile applications with DrupalGap

1. Need to create page with JSON data document format (views_json module)

2. Implement hook_menu

3. Implement page_callback

4. Implement row_callback(function to process and render each row)

VIEWS

Page 42: Building mobile applications with DrupalGap

function MODULE_NAME_menu() { var items = {}; items['team'] = { title: 'Our team', page_callback: 'MODULE_NAME_page' } return items; }

app/modules/custom/module_name/module_name.js:

Page 43: Building mobile applications with DrupalGap

function MODULE_NAME_page() { var content = {}; content['team'] = { theme: 'view', format: ‘ul', /* ul, ol, table, unformatted_list */ path: 'mobile/team_new', /* the path to the view in Drupal */ row_callback: 'MODULE_NAME_page_row', empty_callback: 'MODULE_NAME_page_empty', attributes: { id: 'team-view' } }; return content; } !function MODULE_NAME_page_row(view, row) { var output = ''; output += '<img class="team-image" src="' + row.field_photo + '">'; output += l(row.title, 'node/' + row.Nid); return output; } !function MODULE_NAME_page_empty(view) { return 'Sorry, no results.'; }

app/modules/custom/module_name/module_name.js:

Page 44: Building mobile applications with DrupalGap

NEED ADDITIONAL FUNCTIONALITY? YOU GOT IT!

1. Create custom services resource in Drupal module hook_services_resources();

2. Create custom services call in DrupalGap moduleDrupal.services.call(options);

var output = ''; Drupal.services.call({ method: 'POST', path: 'news.json', data: args, success: function(result) { output = ''; $.each(result, function(i, node) { output += node.title; }); } });

Page 45: Building mobile applications with DrupalGap

RELEASE

Page 46: Building mobile applications with DrupalGap

ANDROIDDevices Android 2.1 (Deprecated May 2013) Android 2.2 Android 2.3 Android 3.x (Deprecated May 2013) Android 4.x

Development Any OS JDK 6+ and Apache Ant

Developer license: $25 one time

Page 47: Building mobile applications with DrupalGap

IOS

Development Intel-based Computer with Mac OS X Lion or greater (10.7.4+) Xcode Command Line Tools Xcode 4.5+ and iOS 6 SDK

Devices iOS Device with at least iOS 5.x+

Developer license: $99 per year

Page 48: Building mobile applications with DrupalGap

CONCLUSION

• DrupalGap is growing • Needs support from a community • We have incredible tool that allows

us to build mobile application from scratch

Page 49: Building mobile applications with DrupalGap

THANK YOU!

https://www.drupal.org/u/sanchiz

https://github.com/Sanchiz

http://sanchiz.net

Email: [email protected]

Twitter : @alexschedrov