APACHE SLING&FRIENDSTECHMEETUP
BERLIN, 28-30SEPTEMBER 2015
Bridging theGap: Single-PageApps and AEM
Bruce Lefebvre, Adobe
adaptTo()2015 2
Hello
@brucelefebvre
Goals
adaptTo()2015 3
 Introduce theSPApattern
 Propose using AngularJS as our framework
 Involve our Authors withAEM
 Prosper in App Stores with PhoneGap
adaptTo()2015 4
The Case for Single-PageApps
SPAs: because your customers won’twait
adaptTo()2015 5
 <TODO: gif of image loading dial-up style>
SPAs: because connectivity is not a guarantee
adaptTo()2015 6
Benefitsof theSPA pattern
adaptTo()2015 7
 Fluid, fasttransitionsbetweenapp states
 Achieve that ‘native app’ feel
 Limitsnetwork requests
 Using page fragments and/or JSON
 Offlinecapable
 Many framework options available
Cons of theSPA pattern
adaptTo()2015 8
 SEO challenges
 Initial‘time to glass’ increase
 Requires JavaScript
 Many frameworkoptions available
adaptTo()2015 9
Speakingof JavaScript Frameworks…
You have options
adaptTo()2015 10
<Your framework here!>
adaptTo()2015 11
“Whenyou decide to not picka public framework, you willend up
witha framework anyway: yourown”
-Ryan Florence,YouCan'tNotHaveaFramework
<Your frameworkhere!>
adaptTo()2015 12
 GettingsimplerwithES6/2015
 Early AEM Apps used github.com/blefebvre/single-
page-nav
adaptTo()2015 13
For example:a Single-PageApp
adaptTo()2015 14
 Only one “complete” page
 often named index.html
 Everything else is loaded dynamically, as
required
https://github.com/blefebvre/cordova-sling-blog-sample
adaptTo()2015 15
IntroducingAngular
Proposal:AngularJS
adaptTo()2015 16
 Opinionated
 Means less boilerplate
 ExtendsHTML vocabulary
 Components (akaDirectives)
 Seamless SPA routing
 Hugecommunity& body of knowledge
Your first Angularcomponent
adaptTo()2015 17
 Augment theHTML vocabulary as you wish
 For example:
<cant-touch-this>
can't touch this!
</cant-touch-this>
bit.ly/cant-touch
Your first Angularcomponent
adaptTo()2015 18
app.directive('cantTouchThis', function() {
var link = function(scope, element, attrs) {
element.on('mouseenter', function() {
// move element to random location
});
};
return {
// link this directive to the DOM
link: link
};
});
bit.ly/cant-touch
adaptTo()2015 19
In ~30 lines of JS, we’ve extendedHTML
Basic Routingin Angular
adaptTo()2015 20
HTML:
<div ng-app="MyApp">
<a href="#/page1">Page 1</a>
<a href="#/page2">Page 2</a>
<ng-view />
</div>
bit.ly/basic-routing
Basic Routingin Angularcont’d
adaptTo()2015 21
JS:
$routeProvider
.when('/page1', {
template: '<h3>Page 1 content!</h3>'
})
// define other routes here
.otherwise({
redirectTo: '/page1'
});
bit.ly/basic-routing
Controllers
adaptTo()2015 22
 Provide data to your template
Route Config:
$routeProvider
.when('/page1', {
template: '<h3>Page 1. Hello {{name}}!</h3>',
controller: 'PageController’
})
bit.ly/basic-routing2
Controllers cont’d
adaptTo()2015 23
PageController:
.controller('PageController', function($scope) {
$scope.name = 'Bruce';
}]);
bit.ly/basic-routing2
Services
adaptTo()2015 24
 Wherethe work gets done
 Lazilyinstantiatedfor speed
 Singletons
 Core Angular services include:
 $http
 $scope
 $location (and many more)
Services Example
adaptTo()2015 25
 Each service is a factory function
app.factory(’counterService’, function() {
var count = 1;
return function() {
return count++;
}
}
);
bit.ly/basic-service
adaptTo()2015 26
Goal: Authorablecontentin an Angular SPA
+
Challenges
adaptTo()2015 27
 Singlepage apps vs. page based system
 Access control?
 Reusability of author’s skillset?
 Content reuse across channels?
 Automated testing?
adaptTo()2015 28
Solution
adaptTo()2015 29
 Serve complete page on author
 Produce partials for SPA
 Routesgenerated based on hierarchy
 go(..) navigates based on wcmmode:
<a ng-click="go('/content/phonegap/app/en/home/subpage')">
Subpage
</a>
Solution cont’d
adaptTo()2015 30
 Via Sling, each page produces:
 “Partial”
subpage.template.html
 Data
subpage.angular.json
 Supporting assets
 sling:resourceType inheritanceFTW!
Angular Componentsin AEM
adaptTo()2015 31
 Includecq:template node
 Prop: frameworkType: angular
 Optional: definea controller
 Via controller.js.jsp
 Optional: includea data file
 Via angular.json.jsp
adaptTo()2015 32
Goal: App store presence
Things you can doon Mobile
adaptTo()2015
33
Nothing ALL the things
Mobile website Native app
(2015)
Gap!
adaptTo()2015 34
Java
C#, C++
Objective-C,
Swift
Java
Mobileplatforms2015
adaptTo()2015 35
Enter Cordova/PhoneGap
35
 Web app wrapped in a devicenative shell
 Write once,run everywhere*
 *aka“the promisedland”
Native SDKs
adaptTo()2015 36
But… Webvs. Native!
 Both built on the same set of technologies
 Web capabilities sufficient for most apps
“If abrowserdoesn’tdosomething its notbecauseit can’t;
it’sjustbecausewehaven’tgottenaroundtoimplementing thatpartyet.”
-BrianLeRoux
Cordova/PhoneGap
adaptTo()2015 37
 Supported platforms
 iOS
 Android
 BB10
 WP7, WP8, Windows 8
 Amazon Fire OS
 Tizen
 and more…
Cordova CLI ata glance
adaptTo()2015 38
 Create your app:
cordova create helloAdaptTo
 Add a platform:
cd helloAdaptTo
cordova platform add ios
 Run your app on a simulator:
cordova emulate ios
Cordova Plugins
adaptTo()2015 39
 Core:
 Camera
 Geolocation
 Accelerometer
 File
 Contacts
 Events
 Connection
 Notification
 Andmanymore…
 New!
 ContentSync
 Push plugin
 NativePageTransitions
adaptTo()2015 40
Let’s bring it all together
+ +
AEMApps: In Action
adaptTo()2015 41
localhost:4502/aem/apps.html
AEMApps
adaptTo()2015 42
 Manageapp contentw/o writing code
 PushOver the Air content updates
 AngularJSintegration
 Send push notificationsfrom AEM
 App analytics with Adobe Mobile Services
PhoneGap Enterprise
adaptTo()2014 43
“PhoneGapEnterprise”ViewerApp
adaptTo()2015 44
Development Staging Production
Internal
Stakeholders
Users
adaptTo()2015 45
AEM Apps: Demo time!
+ +
Recap
adaptTo()2015 46
 Introduce theSPApattern
 Propose using AngularJS as our framework
 Involve our Authors withAEM
 Prosper in App Stores with PhoneGap
adaptTo()2015 47
Thanks!
@brucelefebvre
bit.ly/aem-pg
References
adaptTo()2015 48
 YouCan'tNotHave a Framework- RyanFlorence
 Thumbsupimage
 Thumbsdownimage
 U can’ttouchthis– MC Hammer
 PedestrianDetour
 N64controllerGray–Evan-Amos
 Hardhatandgloves –Compliance and Safety
 Devices image
 Unixstickers‘all thethings’

Bridging the Gap: Single-Page Apps and AEM

Editor's Notes

  • #2 Something for the sling users as well
  • #3 Adobe for 3.5 yrs CQ/AEM mobile team
  • #4 Why AEM and Angular are a good fit
  • #5 For example
  • #6 TODO: Add some stats to this page on how quickly sites are abandoned
  • #7 Whether we’re talking apps or web, connectivity is not a guarantee Lets talk about some of the benefits TODO: add iPhone borders
  • #8 ..following best practices… …don’t reinvent the wheel…
  • #9 JS; does not follow progressive enhancement techniques
  • #11 Dojo Ember Backbone Angular Monolithic vs micro
  • #14 “there’s a lot of fashion in JS” - don’t just pick a framework cause all the cool kids are doing it
  • #16 Simply handle the business logic for a view For everything else, there’s services
  • #17 Backed by Google; not going anywhere Community: Ionic Framework Snap.js btford/angular-phonegap-ready Docs + Stack Overflow
  • #18 Backed by Google; not going anywhere
  • #20 PRETTY COOL .. Of course there are a few lines of angular behind the scenes..
  • #25 Singletons: “Each component dependent on a service gets a reference to the single instance generated by the service factory” TIME: 17 min
  • #26 Singletons: “Each component dependent on a service gets a reference to the single instance generated by the service factory”
  • #27 Simply handle the business logic for a view
  • #28 Singletons: “Each component dependent on a service gets a reference to the single instance generated by the service factory”
  • #30 Singletons: “Each component dependent on a service gets a reference to the single instance generated by the service factory”
  • #31 Singletons: “Each component dependent on a service gets a reference to the single instance generated by the service factory”
  • #32 Singletons: “Each component dependent on a service gets a reference to the single instance generated by the service factory”
  • #35 2016?
  • #36 A cross-platform app framework Initially PhoneGap, created by Nitobi Donated to ASF in 2011 as Cordova of which PhoneGap is a distribution
  • #37 - like (C, C++)
  • #42 TODO: include AEM apps image
  • #44 mobile services details
  • #48 would be wrong to tout the virtues of the open web, and keep all my source code closed: everything is available on github I’ll be around for the hackathon this aft Thank you very much for your attention.