SlideShare a Scribd company logo
1 of 23
AngularJS 
for Interactive Application Behavior 
Brent Goldstein 
brent@kubilateam.com 
Practical Directives
Back Story 
● Building an app and want rich behavior 
○ Don’t limit goals because “it’s a web app” 
● Need an interactive Spreadsheet-like Grid 
○ Hierarchical data, specialized data entry needs 
○ Similarities to Google Sheets, some differences 
● Yikes, this seemed daunting at first 
○ Hierarchical Data Binding 
○ Navigation 
○ Complex element/range selection
Requirements - (be a product mgr) 
● Hierarchical Data Set 
o 3 Row Levels - Person, Projects, Tasks 
o Columns are calendar weeks 
● Navigate and Select like a Spreadsheet 
o Move w/ arrows, tab, shift-tab; mouse-click 
o Select single cell or range of cells 
● Specialized Editing 
o Business logic applied to keystrokes before display
How to Render Complex Data? 
● Resist thinking like an ‘engineer’ 
● Visual representation must be intuitive 
● Even more important that ‘being’ intuitive 
→ will someone actually use it? 
● Really must pass the dog food test
Digression - Dogfooding? 
● OK, this is one of many overused tech industry terms 
● Seems to put a rather unappetizing spin on one of the 
MOST IMPORTANT practices in application design 
● It does not matter what you think or say, or what others 
think or say about using your app 
● The application must draw you in (yes, YOU) 
● Otherwise, it’s just neat tech, and neat is not a product
Grid Hierarchy Rendering 
● Go “Flat” -- flat visual data modeling that is 
● Basically, de-normalize where it makes sense 
→ use grouping to organize 
● Greatly simplifies UI construction and interpretation 
● Still possible to “drill down”, but using filters and 
selection to show more/fewer rows 
● Avoid “nested grids”; hard to render, hard to read
So how to build it? 
<div grid-editor> 
<div class=’grid-person’> 
div div div div div div ….. div 
….. 
….. 
<div> 
….. 
<div> 
<div class=’grid-person’> 
<div> 
- Custom Directive “grid-editor” provides special behaviors 
- Grid-Editor looks for child DOM elements with special classes 
Note, grid constructed from divs, not tables, to support custom layout
DOM Location and Navigation 
Let’s consider one use case, Find the Next cell to the RIGHT 
<div grid-editor> 
<div> 
<div class=’grid-person’> 
<div> 
... 
<div class=’grid-project’> 
<div> 
<div class=’grid-project’> 
<div> 
1) At last cell, but not last in row 
2) At last cell in row 
3) At last cell/row in grid-project 
Actually requires handling several sub-cases...
Getting down to Business -- jqLite 
Assuming we know the selected cell, we can find the next like this: 
<div grid-editor> 
<div class=’grid-person’> 
<div class=’grid-project’> 
1) At last cell, but not last in row 
col=’1’ col=’2’ col=’3’ col=’4’ 
col=’5’ ... 
2) At last cell in row 
Case 1) Look for next sibling element, use attribute to be selective 
var newElement = currEle.next(‘[col]’); 
Case 2) Look for the FIRST element in the NEXT row (requires some maneuvering) 
var newElement = currEle.closest(‘grid-project’).next(‘grid-project’).find(‘.first’) 
Similar ‘traverse up, look for next’ can be applied to higher levels in hierarchy 
col=’6’ 
applied applied to first cell div: class=’first’ to every cell div: class=’cell’
Going down, same column, new row 
What about other cases, like the down arrow key? 
Need the next row, but column needs to remain the same. Now that’s why the 
“col=n” attribute is useful…. 
Look for next sibling row, use attribute to find the correct column 
var newElement = currEle.closest(‘grid-project’).next(‘grid-project’) 
.find(‘.cell[col=’ + currEle.attr(‘col’) + ‘]’); 
<div grid-editor> 
<div class=’grid-person’> 
<div class=’grid-project’> 
col=’1’ col=’2’ col=’3’ col=’4’ 
col=’5’ col=’6’ 
col=’4’
How to capture the arrow keys? 
Can be useful to step outside of Angular for event handling 
element.bind('keydown keypress', function (e){ 
if(!scope.editActive) return; // track the editing state 
var navArrow = function(e){ 
var arrowKeys = { 37:'left', 38:'up', 39:'right', 40:'down' }; 
return arrowKeys[e.which]; 
}; 
var navTab = function(e){ // tab key 
return (e.which === 9) ? (e.shiftKey?"left":"right") : null; 
}; 
var doNav = navFromArrow(e) || navFromTab(e); 
if(doNav){ 
e.preventDefault(); // prevent the browser default action 
theFunctionThatNavigatesToNextCell(doNav) 
} 
}; 
The ‘element’ above could be the $document root, or a sub-document, 
depending on the desired behavior. If a sub-doc, the keys will only be 
captured when that element or children have focus
Rendering the Selection Band 
To indicate selected cell, a “rectangle select band” 
is typically used to surround the cells 
How to accomplish this in DOM? 
A couple of options: 
1) Identify and alter the display the underlying 
DIVs 
2) Add new elements that Overlay the native grid
Draw band using actual grid cells? 
Altering the display of underlying cells can be tricky. 
How to actually make the highlight band? 
- Alter the div/span border(s) 
Not ideal. Positioning is limited to element border 
Also harder to make a multi-cell rectangle
Overlay Rendering 
What about creating a new element/set of 
elements that display ON TOP of the grid? 
Let’s timewarp back to 1998 when graphics 
were rendered into framebuffers. 
Remember the Overlay Framebuffer? 
Let’s apply the same logical concept
The Magic Select Rectangle Band 
How to render the select rectangle in DOM? 
We’ll construct with separate banding elements for max control 
It will simplify hover/select options since we can know exactly which side of the band is 
under the mouse 
Top DIV 
Bottom DIV 
Left Div 
Right Div 
With this approach we can also add other visual elements, like a cursor select target for 
dragging, etc.
Dynamic Element Creation 
The select band is managed by the GridEditor Directive: 
- Create: When the directive is instantiated 
- Move: When the arrow/tab keys are captured 
- Grow/Shrink: Based on shift-click 
This function is called inside the directive link() function to instantiate the band elements: 
var _installBand = function(){ 
var html = 
"<div id='magic-square'>"+ 
"<div class='band-horiz top'></div>" + 
"<div class='band-horiz bottom'></div>"+ 
"<div class='band-vert left'></div>"+ 
"<div class='band-vert right'></div>" + 
"<div class='band-grabbox'></div>" + 
"</div>"; 
_band = angular.element(html); // this creates the dom element 
_gridEditorElement.prepend(_band); // attach to directive element 
return _band; // to adjust properties and location later 
};
Dynamically alter DOM properties 
Properties are updated to adjust the rectangle band size 
when needed 
Note, _unitWidth is already set with the pixel width of a single cell 
var _setBandWidth = function(){ 
var rangeWidth = _range(); // gets the desired #cells to cover 
// update the top/bottom horizontal div widths 
_band.children(".band-horiz").width((_unitWidth-1) * rangeWidth); 
// update the right vertical div position 
var rightVert = _magicSquare.children(".band-vert.right"); 
var posLeft = (_unitWidth-1) * rangeWidth -1; 
rightVert.css({left: posLeft}); 
};
Let’s take a look - Initial View 
Top-level view, summary data 
User sees this view when page is loaded 
● Threshold coloring (red means too much) 
● Click on row to expand 
● Expand All/Collapse All buttons
Let’s take a look - Expanded View 
Details for each person visible when expanded 
● Project-task rows at same indent level 
● Grouping by project 
● Optional project sub-total rows
Let’s take a look - Editing 
Behaviors to streamline complex editing needs 
● Single Select and Range select 
● Smart Navigation across projects/people 
● Shortcut keys for pre-defined operations
Coding tidbit - $emit for messaging 
Both $scope.$broadcast() and $scope.$emit() can be used 
to communicate between directives and controllers 
What’s the difference? Well, direction: 
$emit goes UP, $broadcast goes DOWN 
As a result, $emit is more efficient bubbling only to parents 
$broadcast fans out to all child scopes 
Maybe you really need $broadcast... but often not 
$emit can be applied in a message-bus pattern to achieve 
efficient dedicated communication across an app
$emit for messaging 
Message bus approach can often replace $broadcast 
1) Bubble Up 2) Message Bus 
Higher level controller 
or directive 
$scope.$on(‘hello.world’, 
function(event){//dosomething)); 
$scope.$emit(‘hello.world’); 
Originating Controller or 
Directive 
RootScope actiing as 
message Bus 
$rootScope.$on(‘hello.world’, 
function(event){//dosomething)); 
$rootScope.$emit(‘hello.world’); 
Originating Controller or 
Directive 
Listening Directive or 
Controller
thanks! 
contact: brent@kubilateam.com

More Related Content

What's hot

Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014Christian Lilley
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architectureMichael He
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJSFITC
 
Ext JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell SimeonsExt JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell SimeonsSencha
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practicesHenry Tao
 
Backbone/Marionette recap [2015]
Backbone/Marionette recap [2015]Backbone/Marionette recap [2015]
Backbone/Marionette recap [2015]Andrii Lundiak
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS BasicsRavi Mone
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & VuexBernd Alter
 
Building AngularJS Custom Directives
Building AngularJS Custom DirectivesBuilding AngularJS Custom Directives
Building AngularJS Custom DirectivesDan Wahlin
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)Gary Arora
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners WorkshopSathish VJ
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework Sakthi Bro
 
Advanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSSimon Guest
 

What's hot (20)

Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
 
AngularJS Basic Training
AngularJS Basic TrainingAngularJS Basic Training
AngularJS Basic Training
 
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Ext JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell SimeonsExt JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell Simeons
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
 
Backbone/Marionette recap [2015]
Backbone/Marionette recap [2015]Backbone/Marionette recap [2015]
Backbone/Marionette recap [2015]
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
 
AngularJs
AngularJsAngularJs
AngularJs
 
Building AngularJS Custom Directives
Building AngularJS Custom DirectivesBuilding AngularJS Custom Directives
Building AngularJS Custom Directives
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
 
Advanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JS
 
Intro to AngularJs
Intro to AngularJsIntro to AngularJs
Intro to AngularJs
 

Similar to Angular.js Directives for Interactive Web Applications

The Future State of Layout
The Future State of LayoutThe Future State of Layout
The Future State of LayoutStephen Hay
 
Designing and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tabletsDesigning and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tabletsTeddy Koornia
 
Performance #3 layout&amp;animation
Performance #3  layout&amp;animationPerformance #3  layout&amp;animation
Performance #3 layout&amp;animationVitali Pekelis
 
Additional 3174 mp3174 - navisworks 2014 - quick reference guide
Additional 3174 mp3174 - navisworks 2014 - quick reference guideAdditional 3174 mp3174 - navisworks 2014 - quick reference guide
Additional 3174 mp3174 - navisworks 2014 - quick reference guideTrần Hoàng Quí
 
Grids of Tomorrow: CSS Grid Layout
Grids of Tomorrow: CSS Grid LayoutGrids of Tomorrow: CSS Grid Layout
Grids of Tomorrow: CSS Grid LayoutSimone Lelli
 
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)Oleksii Prohonnyi
 
But what about old browsers?
But what about old browsers?But what about old browsers?
But what about old browsers?Rachel Andrew
 
What you need to know about FEMAP v11.3
What you need to know about FEMAP v11.3What you need to know about FEMAP v11.3
What you need to know about FEMAP v11.3Aswin John
 
Start Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSStart Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSRachel Andrew
 
Visualizing large data sets with wijmo enterprise webinar
Visualizing large data sets with wijmo enterprise webinarVisualizing large data sets with wijmo enterprise webinar
Visualizing large data sets with wijmo enterprise webinarRoss Dederer
 
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)Spiros
 
CSS- Smacss Design Rule
CSS- Smacss Design RuleCSS- Smacss Design Rule
CSS- Smacss Design Rule皮馬 頑
 
Goodbye Nightmare : Tops and Tricks for creating Layouts
Goodbye Nightmare : Tops and Tricks for creating LayoutsGoodbye Nightmare : Tops and Tricks for creating Layouts
Goodbye Nightmare : Tops and Tricks for creating LayoutsLuc Bors
 
Supervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking systemSupervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking systemMarsan Ma
 
Js info vis_toolkit
Js info vis_toolkitJs info vis_toolkit
Js info vis_toolkitnikhilyagnic
 

Similar to Angular.js Directives for Interactive Web Applications (20)

The Future State of Layout
The Future State of LayoutThe Future State of Layout
The Future State of Layout
 
Designing and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tabletsDesigning and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tablets
 
Performance #3 layout&amp;animation
Performance #3  layout&amp;animationPerformance #3  layout&amp;animation
Performance #3 layout&amp;animation
 
Additional 3174 mp3174 - navisworks 2014 - quick reference guide
Additional 3174 mp3174 - navisworks 2014 - quick reference guideAdditional 3174 mp3174 - navisworks 2014 - quick reference guide
Additional 3174 mp3174 - navisworks 2014 - quick reference guide
 
Grids of Tomorrow: CSS Grid Layout
Grids of Tomorrow: CSS Grid LayoutGrids of Tomorrow: CSS Grid Layout
Grids of Tomorrow: CSS Grid Layout
 
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
 
But what about old browsers?
But what about old browsers?But what about old browsers?
But what about old browsers?
 
What you need to know about FEMAP v11.3
What you need to know about FEMAP v11.3What you need to know about FEMAP v11.3
What you need to know about FEMAP v11.3
 
Start Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSStart Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJS
 
Visualizing large data sets with wijmo enterprise webinar
Visualizing large data sets with wijmo enterprise webinarVisualizing large data sets with wijmo enterprise webinar
Visualizing large data sets with wijmo enterprise webinar
 
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
 
CSS- Smacss Design Rule
CSS- Smacss Design RuleCSS- Smacss Design Rule
CSS- Smacss Design Rule
 
Sign in
Sign inSign in
Sign in
 
Goodbye Nightmare : Tops and Tricks for creating Layouts
Goodbye Nightmare : Tops and Tricks for creating LayoutsGoodbye Nightmare : Tops and Tricks for creating Layouts
Goodbye Nightmare : Tops and Tricks for creating Layouts
 
Goodbye Nightmare: Tips and Tricks for Creating Complex Layouts with Oracle A...
Goodbye Nightmare: Tips and Tricks for Creating Complex Layouts with Oracle A...Goodbye Nightmare: Tips and Tricks for Creating Complex Layouts with Oracle A...
Goodbye Nightmare: Tips and Tricks for Creating Complex Layouts with Oracle A...
 
Supervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking systemSupervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking system
 
INTRODUCTIONS OF CSS PART 2
INTRODUCTIONS OF CSS PART 2INTRODUCTIONS OF CSS PART 2
INTRODUCTIONS OF CSS PART 2
 
Bootstrap 4 ppt
Bootstrap 4 pptBootstrap 4 ppt
Bootstrap 4 ppt
 
Hello Android
Hello AndroidHello Android
Hello Android
 
Js info vis_toolkit
Js info vis_toolkitJs info vis_toolkit
Js info vis_toolkit
 

Recently uploaded

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 

Recently uploaded (20)

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 

Angular.js Directives for Interactive Web Applications

  • 1. AngularJS for Interactive Application Behavior Brent Goldstein brent@kubilateam.com Practical Directives
  • 2. Back Story ● Building an app and want rich behavior ○ Don’t limit goals because “it’s a web app” ● Need an interactive Spreadsheet-like Grid ○ Hierarchical data, specialized data entry needs ○ Similarities to Google Sheets, some differences ● Yikes, this seemed daunting at first ○ Hierarchical Data Binding ○ Navigation ○ Complex element/range selection
  • 3. Requirements - (be a product mgr) ● Hierarchical Data Set o 3 Row Levels - Person, Projects, Tasks o Columns are calendar weeks ● Navigate and Select like a Spreadsheet o Move w/ arrows, tab, shift-tab; mouse-click o Select single cell or range of cells ● Specialized Editing o Business logic applied to keystrokes before display
  • 4. How to Render Complex Data? ● Resist thinking like an ‘engineer’ ● Visual representation must be intuitive ● Even more important that ‘being’ intuitive → will someone actually use it? ● Really must pass the dog food test
  • 5. Digression - Dogfooding? ● OK, this is one of many overused tech industry terms ● Seems to put a rather unappetizing spin on one of the MOST IMPORTANT practices in application design ● It does not matter what you think or say, or what others think or say about using your app ● The application must draw you in (yes, YOU) ● Otherwise, it’s just neat tech, and neat is not a product
  • 6. Grid Hierarchy Rendering ● Go “Flat” -- flat visual data modeling that is ● Basically, de-normalize where it makes sense → use grouping to organize ● Greatly simplifies UI construction and interpretation ● Still possible to “drill down”, but using filters and selection to show more/fewer rows ● Avoid “nested grids”; hard to render, hard to read
  • 7. So how to build it? <div grid-editor> <div class=’grid-person’> div div div div div div ….. div ….. ….. <div> ….. <div> <div class=’grid-person’> <div> - Custom Directive “grid-editor” provides special behaviors - Grid-Editor looks for child DOM elements with special classes Note, grid constructed from divs, not tables, to support custom layout
  • 8. DOM Location and Navigation Let’s consider one use case, Find the Next cell to the RIGHT <div grid-editor> <div> <div class=’grid-person’> <div> ... <div class=’grid-project’> <div> <div class=’grid-project’> <div> 1) At last cell, but not last in row 2) At last cell in row 3) At last cell/row in grid-project Actually requires handling several sub-cases...
  • 9. Getting down to Business -- jqLite Assuming we know the selected cell, we can find the next like this: <div grid-editor> <div class=’grid-person’> <div class=’grid-project’> 1) At last cell, but not last in row col=’1’ col=’2’ col=’3’ col=’4’ col=’5’ ... 2) At last cell in row Case 1) Look for next sibling element, use attribute to be selective var newElement = currEle.next(‘[col]’); Case 2) Look for the FIRST element in the NEXT row (requires some maneuvering) var newElement = currEle.closest(‘grid-project’).next(‘grid-project’).find(‘.first’) Similar ‘traverse up, look for next’ can be applied to higher levels in hierarchy col=’6’ applied applied to first cell div: class=’first’ to every cell div: class=’cell’
  • 10. Going down, same column, new row What about other cases, like the down arrow key? Need the next row, but column needs to remain the same. Now that’s why the “col=n” attribute is useful…. Look for next sibling row, use attribute to find the correct column var newElement = currEle.closest(‘grid-project’).next(‘grid-project’) .find(‘.cell[col=’ + currEle.attr(‘col’) + ‘]’); <div grid-editor> <div class=’grid-person’> <div class=’grid-project’> col=’1’ col=’2’ col=’3’ col=’4’ col=’5’ col=’6’ col=’4’
  • 11. How to capture the arrow keys? Can be useful to step outside of Angular for event handling element.bind('keydown keypress', function (e){ if(!scope.editActive) return; // track the editing state var navArrow = function(e){ var arrowKeys = { 37:'left', 38:'up', 39:'right', 40:'down' }; return arrowKeys[e.which]; }; var navTab = function(e){ // tab key return (e.which === 9) ? (e.shiftKey?"left":"right") : null; }; var doNav = navFromArrow(e) || navFromTab(e); if(doNav){ e.preventDefault(); // prevent the browser default action theFunctionThatNavigatesToNextCell(doNav) } }; The ‘element’ above could be the $document root, or a sub-document, depending on the desired behavior. If a sub-doc, the keys will only be captured when that element or children have focus
  • 12. Rendering the Selection Band To indicate selected cell, a “rectangle select band” is typically used to surround the cells How to accomplish this in DOM? A couple of options: 1) Identify and alter the display the underlying DIVs 2) Add new elements that Overlay the native grid
  • 13. Draw band using actual grid cells? Altering the display of underlying cells can be tricky. How to actually make the highlight band? - Alter the div/span border(s) Not ideal. Positioning is limited to element border Also harder to make a multi-cell rectangle
  • 14. Overlay Rendering What about creating a new element/set of elements that display ON TOP of the grid? Let’s timewarp back to 1998 when graphics were rendered into framebuffers. Remember the Overlay Framebuffer? Let’s apply the same logical concept
  • 15. The Magic Select Rectangle Band How to render the select rectangle in DOM? We’ll construct with separate banding elements for max control It will simplify hover/select options since we can know exactly which side of the band is under the mouse Top DIV Bottom DIV Left Div Right Div With this approach we can also add other visual elements, like a cursor select target for dragging, etc.
  • 16. Dynamic Element Creation The select band is managed by the GridEditor Directive: - Create: When the directive is instantiated - Move: When the arrow/tab keys are captured - Grow/Shrink: Based on shift-click This function is called inside the directive link() function to instantiate the band elements: var _installBand = function(){ var html = "<div id='magic-square'>"+ "<div class='band-horiz top'></div>" + "<div class='band-horiz bottom'></div>"+ "<div class='band-vert left'></div>"+ "<div class='band-vert right'></div>" + "<div class='band-grabbox'></div>" + "</div>"; _band = angular.element(html); // this creates the dom element _gridEditorElement.prepend(_band); // attach to directive element return _band; // to adjust properties and location later };
  • 17. Dynamically alter DOM properties Properties are updated to adjust the rectangle band size when needed Note, _unitWidth is already set with the pixel width of a single cell var _setBandWidth = function(){ var rangeWidth = _range(); // gets the desired #cells to cover // update the top/bottom horizontal div widths _band.children(".band-horiz").width((_unitWidth-1) * rangeWidth); // update the right vertical div position var rightVert = _magicSquare.children(".band-vert.right"); var posLeft = (_unitWidth-1) * rangeWidth -1; rightVert.css({left: posLeft}); };
  • 18. Let’s take a look - Initial View Top-level view, summary data User sees this view when page is loaded ● Threshold coloring (red means too much) ● Click on row to expand ● Expand All/Collapse All buttons
  • 19. Let’s take a look - Expanded View Details for each person visible when expanded ● Project-task rows at same indent level ● Grouping by project ● Optional project sub-total rows
  • 20. Let’s take a look - Editing Behaviors to streamline complex editing needs ● Single Select and Range select ● Smart Navigation across projects/people ● Shortcut keys for pre-defined operations
  • 21. Coding tidbit - $emit for messaging Both $scope.$broadcast() and $scope.$emit() can be used to communicate between directives and controllers What’s the difference? Well, direction: $emit goes UP, $broadcast goes DOWN As a result, $emit is more efficient bubbling only to parents $broadcast fans out to all child scopes Maybe you really need $broadcast... but often not $emit can be applied in a message-bus pattern to achieve efficient dedicated communication across an app
  • 22. $emit for messaging Message bus approach can often replace $broadcast 1) Bubble Up 2) Message Bus Higher level controller or directive $scope.$on(‘hello.world’, function(event){//dosomething)); $scope.$emit(‘hello.world’); Originating Controller or Directive RootScope actiing as message Bus $rootScope.$on(‘hello.world’, function(event){//dosomething)); $rootScope.$emit(‘hello.world’); Originating Controller or Directive Listening Directive or Controller