SlideShare a Scribd company logo
1 of 24
AngularJS is a Javascript MVC framework created by 
Google to build properly architectured and maintainable 
web applications. 
Focus more on HTML side of web apps.
● Angular JS 
o Setup in Rails 
● Basics (directives, controllers) 
● Our Experience in Building .. 
o Dash for Metrics/Monitoring 
o Stream Realtime Logs
Option #1: Via Gem file 
Add the following to your Gemfile: 
gem 'angularjs-rails' 
Add the following directive to your JavaScript manifest 
file (application.js): 
//= require angular
If you desire to require (*optional) Angular files, you 
may include them as well in your JavaScript manifest 
file (application.js). For example: 
//= require angular-animate 
//= require angular-resource
Option#2: Explicitly download angular.js 
Download here 
Put angular.js file in your “/vendor/assets/javascripts/” 
path. 
eg:https://github.com/megamsys/nilavu/tree/master/ve 
ndor/assets/javascripts
is NOT a JavaScript library (As they say). There are no 
functions which we can be directly called and used. 
is NOT a DOM manipulation library like jQuery. But it uses 
subset of jQuery for DOM manipulation (called jqLite).
Model - application data 
View - what the user sees 
Controller - application behavior
Scope - glue between application data and 
behavior 
$ - angular namespace 
Module - configures the injector 
Injector - assembles the application
Angularjs 
Directives Templates 
Controller 
Router (app.js) 
Rails 
Controller 
Model 
View 
Action to route 
Widgets 
/widgets
1. When an action is performed in rails dashboard view 
page that action will be handled by the Angularjs router. 
2./dashboards angularjs controllers is called which calls 
the rails controller for widgets.
3. When rails controller receives the request from 
angularjs controller(/dashboard) via a rest call, it loads 
all the widget names stored in a rails model. 
4. The templates for each of the widgets in angularjs are 
rendered by angularjs dashboard controller and a final 
rails view page is shown to the user.
Create app.js in your assets folder. 
angular.module('Megam', [ "ngResource", "ngRoute",ngAnimate" ]); 
Declare “Megam” - an angular module. 
We bootstrap the “Megam” module in our WebApp in 
index.html.erb using <html ng-app="Megam">
Create dashboard view page : 
An user clicks an action “/dashboards/:id” path from a Rails:Dashboards 
Controller. 
<%= link_to dashboard_path(one_app_service.id), :class=>"btn 
btn-primary btn-lg active", :id =>id="popover_dashboard_monitor", 
:target => "_blank" do %> Monitor <% end %>
Route for /dashboards/:id 
app.config([ "$routeProvider", "$locationProvider", 
function($routeProvider, $locationProvider) { 
$locationProvider.html5Mode(true); 
$routeProvider.when("/dashboards/:id", { 
templateUrl : 
'angular/templates/dashboards/show.html.erb', 
controller : "DashboardShowCtrl" 
}); 
} ]); 
● The above sets a route for /dashboards to “DashboardShowCtrl” controller
Setup angularjs dashboard controller: 
app.controller("DashboardShowCtrl", ["$scope", "$routeParams", "Dashboard", "Widget", 
function($scope, $routeParams, Dashboard, Widget) { 
$scope.dashboard = Dashboard.get({ id: $routeParams.id }); 
$scope.widgets = Widget.query({ dashboard_id: $routeParams.id }, function() { 
$rootScope.resolved = true; 
}); 
} 
● The Dashboard.get loads the current dashboard from Rails 
● Using the dashboard_id from above, the Widget.query method sends a rest api call to Rails 
controller for get all widgets for the dashboard_id 
● The parameters “Dashboard” and “Widget” are Angularjs services.
Setup Rails Dashboards controller: 
module Api 
class DashboardsController 
respond_to :json 
def index 
@user_id = current_user.id 
dashboards = current_user.apps 
respond_with dashboards 
end 
end 
end 
● The rails dashboards controller loads all stored widgets from the model and sends a response 
to angularjs dashboard controller.
Setup dashboard service: 
app.factory("Dashboard", ["$resource", function($resource) { 
return $resource("/api/dashboards/:id.json", { id: "@id" }, 
{ 
'show': { method: 'GET', isArray: false } 
}); 
}]); 
● This call the /api/dashboards/ url of the rails controller where the dashboard model (state), 
eg: how will my dashboard view look like ? is loaded.
Setup widget service: 
app.factory("Widget", ["$resource", function($resource) { 
return $resource("/api/dashboards/:dashboard_id/widgets/:id.json", { id: "@id", dashboard_id: 
"@dashboard_id" }, 
{ 
'index': { method: 'GET', isArray: true }, 
'show': { method: 'GET', isArray: false }, 
} 
); 
}]); 
● This calls the /api/dashboards/:dashboard_id/widgets/id url of the rails controller where the 
widgets in the dashboard model (state), eg: how will my widgets in dashboard view look like ? 
is loaded.
Setup dashboard template: 
<div id="content-header" class="mini"> 
<ul class="mini-stats box-3"> 
<li class="widget" ng-repeat="widget in widgets" widgetpernode></li> 
</ul> 
</div> 
● DashController in Rails will render the above template. 
● All the widgets will be shown in this template. The “widgetpernode” is an angularjs directive of 
widget. 
● The “ng-repeat="widget in widgets”” is equivalent to for loop, widgets contains list of 
widgets.
Setup widget controller: 
app.controller("WidgetCtrl", ["$scope", function($scope) { 
//graph : draws a running graph 
}]); 
The widget controller set actions for single widget, For eg: to draw a graph in widget to be put the 
following code 
var plot1 = 
$.plot("#cpu_system_graph",FlotrGraphHelper.transformSeriesOfDatapoints(cpu_system_data, 
scope.widget, currentColors), FlotrGraphHelper.defaultOptions(scope.widget, "cpu_system")); 
plot1.setData(FlotrGraphHelper.transformSeriesOfDatapoints(cpu_system_data, scope.widget, 
currentColors)); 
plot1.draw();
Setup widget template: 
<div class="row"> 
<div class="col-xs-11 col-sm-11 col-md-11"> 
<h1><small>CPU Usage </small></h1> 
<div id="cpu_system_graph"></div> 
</div> 
</div> 
● The widget controller rendered this widget template and draw the graph into the 
“cpu_system_graph” location.
Setup dashboard directive: 
app.directive("widgetpernode", ["$compile", function($compile) { 
var linkFn = function(scope, element, attrs) { 
var elm = element.find(".widget_content"); 
elm.append('<div '+ scope.widget.name + ' />'); 
$compile(elm)(scope); 
}; 
return { 
controller: "WidgetCtrl", 
templateUrl: 'angular/templates/widget/show.html.erb', 
link: linkFn 
}; 
}]); 
● widgetpernode directive, renders using angularjs WidgetCtrl and templateUrl : 
angular/templates/widgets/show.html.erb.
http://www.gomegam.com 
https://www.megam.co 
code : https://github.com/megamsys/nilavu.git 
email : rajthilak@megam.co.in 
twitter:@megamsystems

More Related Content

What's hot

Padrões Arquiteturais - MVC, MVP e MVVM
Padrões Arquiteturais - MVC, MVP e MVVMPadrões Arquiteturais - MVC, MVP e MVVM
Padrões Arquiteturais - MVC, MVP e MVVMAricelio Souza
 
Programmer en html5, css 3 et java script (70 480)
Programmer en html5, css 3 et java script (70 480)Programmer en html5, css 3 et java script (70 480)
Programmer en html5, css 3 et java script (70 480)Chamseddine Ouerhani
 
Karim Baina activities ensias
Karim Baina activities ensiasKarim Baina activities ensias
Karim Baina activities ensiasKarim Baïna
 
Presentacion de Moodle
Presentacion de MoodlePresentacion de Moodle
Presentacion de Moodlejveizaga
 
SAP UNIVERS ADVENTURE WORKS DW 2016
SAP UNIVERS ADVENTURE WORKS DW 2016SAP UNIVERS ADVENTURE WORKS DW 2016
SAP UNIVERS ADVENTURE WORKS DW 2016serigne diop
 
Design patterns comportementaux
Design patterns comportementauxDesign patterns comportementaux
Design patterns comportementauxYannick Chartois
 
Diagramme de classe
Diagramme de classeDiagramme de classe
Diagramme de classeIlhem Daoudi
 
Présentation de JEE et de son écosysteme
Présentation de JEE et de son écosystemePrésentation de JEE et de son écosysteme
Présentation de JEE et de son écosystemeStéphane Traumat
 
Chp2 - Conception UX-UI des Applications Mobiles
Chp2 - Conception UX-UI des Applications MobilesChp2 - Conception UX-UI des Applications Mobiles
Chp2 - Conception UX-UI des Applications MobilesLilia Sfaxi
 
Développement mobile multi-plateforme avec Flutter
Développement mobile multi-plateforme avec FlutterDéveloppement mobile multi-plateforme avec Flutter
Développement mobile multi-plateforme avec Fluttererick G
 
Systematiskt kvalitetsarbete ppt 151026
Systematiskt kvalitetsarbete ppt 151026Systematiskt kvalitetsarbete ppt 151026
Systematiskt kvalitetsarbete ppt 151026Hanna Askelund
 
Prise en main de Jhipster
Prise en main de JhipsterPrise en main de Jhipster
Prise en main de JhipsterKokou Gaglo
 
Sistemas Operacionais em redes
Sistemas Operacionais em redesSistemas Operacionais em redes
Sistemas Operacionais em redesDaniel Brandão
 
Expo diagramme cas d'utilisation
Expo diagramme cas d'utilisationExpo diagramme cas d'utilisation
Expo diagramme cas d'utilisationaminooovich
 

What's hot (20)

Padrões Arquiteturais - MVC, MVP e MVVM
Padrões Arquiteturais - MVC, MVP e MVVMPadrões Arquiteturais - MVC, MVP e MVVM
Padrões Arquiteturais - MVC, MVP e MVVM
 
Programmer en html5, css 3 et java script (70 480)
Programmer en html5, css 3 et java script (70 480)Programmer en html5, css 3 et java script (70 480)
Programmer en html5, css 3 et java script (70 480)
 
Karim Baina activities ensias
Karim Baina activities ensiasKarim Baina activities ensias
Karim Baina activities ensias
 
Presentacion de Moodle
Presentacion de MoodlePresentacion de Moodle
Presentacion de Moodle
 
Méthodes Agiles - La Méthode XP
Méthodes Agiles - La Méthode XPMéthodes Agiles - La Méthode XP
Méthodes Agiles - La Méthode XP
 
SAP UNIVERS ADVENTURE WORKS DW 2016
SAP UNIVERS ADVENTURE WORKS DW 2016SAP UNIVERS ADVENTURE WORKS DW 2016
SAP UNIVERS ADVENTURE WORKS DW 2016
 
Design patterns comportementaux
Design patterns comportementauxDesign patterns comportementaux
Design patterns comportementaux
 
Uml
UmlUml
Uml
 
Diagramme de classe
Diagramme de classeDiagramme de classe
Diagramme de classe
 
Support developpement applications mobiles avec ionic v3 et v4
Support developpement applications mobiles avec ionic v3 et v4Support developpement applications mobiles avec ionic v3 et v4
Support developpement applications mobiles avec ionic v3 et v4
 
Cours design pattern m youssfi partie 7 facade bridge flyweight
Cours design pattern m youssfi partie 7 facade bridge flyweightCours design pattern m youssfi partie 7 facade bridge flyweight
Cours design pattern m youssfi partie 7 facade bridge flyweight
 
Présentation de JEE et de son écosysteme
Présentation de JEE et de son écosystemePrésentation de JEE et de son écosysteme
Présentation de JEE et de son écosysteme
 
Chp2 - Conception UX-UI des Applications Mobiles
Chp2 - Conception UX-UI des Applications MobilesChp2 - Conception UX-UI des Applications Mobiles
Chp2 - Conception UX-UI des Applications Mobiles
 
Développement mobile multi-plateforme avec Flutter
Développement mobile multi-plateforme avec FlutterDéveloppement mobile multi-plateforme avec Flutter
Développement mobile multi-plateforme avec Flutter
 
Systematiskt kvalitetsarbete ppt 151026
Systematiskt kvalitetsarbete ppt 151026Systematiskt kvalitetsarbete ppt 151026
Systematiskt kvalitetsarbete ppt 151026
 
Prise en main de Jhipster
Prise en main de JhipsterPrise en main de Jhipster
Prise en main de Jhipster
 
Angular Avancé
Angular AvancéAngular Avancé
Angular Avancé
 
Sistemas Operacionais em redes
Sistemas Operacionais em redesSistemas Operacionais em redes
Sistemas Operacionais em redes
 
Support programmation orientée aspect mohamed youssfi (aop)
Support programmation orientée aspect mohamed youssfi (aop)Support programmation orientée aspect mohamed youssfi (aop)
Support programmation orientée aspect mohamed youssfi (aop)
 
Expo diagramme cas d'utilisation
Expo diagramme cas d'utilisationExpo diagramme cas d'utilisation
Expo diagramme cas d'utilisation
 

Similar to Building a dashboard using AngularJS

Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular jsTamer Solieman
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverSpike Brehm
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSmurtazahaveliwala
 
A Story about AngularJS modularization development
A Story about AngularJS modularization developmentA Story about AngularJS modularization development
A Story about AngularJS modularization developmentJohannes Weber
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedStéphane Bégaudeau
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Eliran Eliassy
 
One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJSYashobanta Bai
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.jsDev_Events
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeMark Meyer
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersOswald Campesato
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS BasicsRavi Mone
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseEPAM Systems
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJSBrajesh Yadav
 

Similar to Building a dashboard using AngularJS (20)

Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and server
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
A Story about AngularJS modularization development
A Story about AngularJS modularization developmentA Story about AngularJS modularization development
A Story about AngularJS modularization development
 
Custom directive and scopes
Custom directive and scopesCustom directive and scopes
Custom directive and scopes
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
Starting with angular js
Starting with angular js Starting with angular js
Starting with angular js
 
One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJS
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.js
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers Make
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
 
Vue js and Dyploma
Vue js and DyplomaVue js and Dyploma
Vue js and Dyploma
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
 
AngularJS
AngularJSAngularJS
AngularJS
 
Angular Js Basics
Angular Js BasicsAngular Js Basics
Angular Js Basics
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Building a dashboard using AngularJS

  • 1.
  • 2. AngularJS is a Javascript MVC framework created by Google to build properly architectured and maintainable web applications. Focus more on HTML side of web apps.
  • 3. ● Angular JS o Setup in Rails ● Basics (directives, controllers) ● Our Experience in Building .. o Dash for Metrics/Monitoring o Stream Realtime Logs
  • 4. Option #1: Via Gem file Add the following to your Gemfile: gem 'angularjs-rails' Add the following directive to your JavaScript manifest file (application.js): //= require angular
  • 5. If you desire to require (*optional) Angular files, you may include them as well in your JavaScript manifest file (application.js). For example: //= require angular-animate //= require angular-resource
  • 6. Option#2: Explicitly download angular.js Download here Put angular.js file in your “/vendor/assets/javascripts/” path. eg:https://github.com/megamsys/nilavu/tree/master/ve ndor/assets/javascripts
  • 7. is NOT a JavaScript library (As they say). There are no functions which we can be directly called and used. is NOT a DOM manipulation library like jQuery. But it uses subset of jQuery for DOM manipulation (called jqLite).
  • 8. Model - application data View - what the user sees Controller - application behavior
  • 9. Scope - glue between application data and behavior $ - angular namespace Module - configures the injector Injector - assembles the application
  • 10. Angularjs Directives Templates Controller Router (app.js) Rails Controller Model View Action to route Widgets /widgets
  • 11. 1. When an action is performed in rails dashboard view page that action will be handled by the Angularjs router. 2./dashboards angularjs controllers is called which calls the rails controller for widgets.
  • 12. 3. When rails controller receives the request from angularjs controller(/dashboard) via a rest call, it loads all the widget names stored in a rails model. 4. The templates for each of the widgets in angularjs are rendered by angularjs dashboard controller and a final rails view page is shown to the user.
  • 13. Create app.js in your assets folder. angular.module('Megam', [ "ngResource", "ngRoute",ngAnimate" ]); Declare “Megam” - an angular module. We bootstrap the “Megam” module in our WebApp in index.html.erb using <html ng-app="Megam">
  • 14. Create dashboard view page : An user clicks an action “/dashboards/:id” path from a Rails:Dashboards Controller. <%= link_to dashboard_path(one_app_service.id), :class=>"btn btn-primary btn-lg active", :id =>id="popover_dashboard_monitor", :target => "_blank" do %> Monitor <% end %>
  • 15. Route for /dashboards/:id app.config([ "$routeProvider", "$locationProvider", function($routeProvider, $locationProvider) { $locationProvider.html5Mode(true); $routeProvider.when("/dashboards/:id", { templateUrl : 'angular/templates/dashboards/show.html.erb', controller : "DashboardShowCtrl" }); } ]); ● The above sets a route for /dashboards to “DashboardShowCtrl” controller
  • 16. Setup angularjs dashboard controller: app.controller("DashboardShowCtrl", ["$scope", "$routeParams", "Dashboard", "Widget", function($scope, $routeParams, Dashboard, Widget) { $scope.dashboard = Dashboard.get({ id: $routeParams.id }); $scope.widgets = Widget.query({ dashboard_id: $routeParams.id }, function() { $rootScope.resolved = true; }); } ● The Dashboard.get loads the current dashboard from Rails ● Using the dashboard_id from above, the Widget.query method sends a rest api call to Rails controller for get all widgets for the dashboard_id ● The parameters “Dashboard” and “Widget” are Angularjs services.
  • 17. Setup Rails Dashboards controller: module Api class DashboardsController respond_to :json def index @user_id = current_user.id dashboards = current_user.apps respond_with dashboards end end end ● The rails dashboards controller loads all stored widgets from the model and sends a response to angularjs dashboard controller.
  • 18. Setup dashboard service: app.factory("Dashboard", ["$resource", function($resource) { return $resource("/api/dashboards/:id.json", { id: "@id" }, { 'show': { method: 'GET', isArray: false } }); }]); ● This call the /api/dashboards/ url of the rails controller where the dashboard model (state), eg: how will my dashboard view look like ? is loaded.
  • 19. Setup widget service: app.factory("Widget", ["$resource", function($resource) { return $resource("/api/dashboards/:dashboard_id/widgets/:id.json", { id: "@id", dashboard_id: "@dashboard_id" }, { 'index': { method: 'GET', isArray: true }, 'show': { method: 'GET', isArray: false }, } ); }]); ● This calls the /api/dashboards/:dashboard_id/widgets/id url of the rails controller where the widgets in the dashboard model (state), eg: how will my widgets in dashboard view look like ? is loaded.
  • 20. Setup dashboard template: <div id="content-header" class="mini"> <ul class="mini-stats box-3"> <li class="widget" ng-repeat="widget in widgets" widgetpernode></li> </ul> </div> ● DashController in Rails will render the above template. ● All the widgets will be shown in this template. The “widgetpernode” is an angularjs directive of widget. ● The “ng-repeat="widget in widgets”” is equivalent to for loop, widgets contains list of widgets.
  • 21. Setup widget controller: app.controller("WidgetCtrl", ["$scope", function($scope) { //graph : draws a running graph }]); The widget controller set actions for single widget, For eg: to draw a graph in widget to be put the following code var plot1 = $.plot("#cpu_system_graph",FlotrGraphHelper.transformSeriesOfDatapoints(cpu_system_data, scope.widget, currentColors), FlotrGraphHelper.defaultOptions(scope.widget, "cpu_system")); plot1.setData(FlotrGraphHelper.transformSeriesOfDatapoints(cpu_system_data, scope.widget, currentColors)); plot1.draw();
  • 22. Setup widget template: <div class="row"> <div class="col-xs-11 col-sm-11 col-md-11"> <h1><small>CPU Usage </small></h1> <div id="cpu_system_graph"></div> </div> </div> ● The widget controller rendered this widget template and draw the graph into the “cpu_system_graph” location.
  • 23. Setup dashboard directive: app.directive("widgetpernode", ["$compile", function($compile) { var linkFn = function(scope, element, attrs) { var elm = element.find(".widget_content"); elm.append('<div '+ scope.widget.name + ' />'); $compile(elm)(scope); }; return { controller: "WidgetCtrl", templateUrl: 'angular/templates/widget/show.html.erb', link: linkFn }; }]); ● widgetpernode directive, renders using angularjs WidgetCtrl and templateUrl : angular/templates/widgets/show.html.erb.
  • 24. http://www.gomegam.com https://www.megam.co code : https://github.com/megamsys/nilavu.git email : rajthilak@megam.co.in twitter:@megamsystems