Professional Documents
Culture Documents
J
r
a
l
u
g
n
A
h
s
a
D
e
m
o
s
e
w
A
Engineer
rm
o
tf
la
P
k
a
il
h
T
j
a
R
m.com
ga
e
m
o
.g
w
w
/w
:/
tp
Megam Systems ht
rajthilak@megam.co
.in
AngularJs
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.
Well cover
Angular JS
o
Setup in Rails
)
s
l
i
a
R
n
i
p
u
t
e
S
Angular JS (
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
T
O
N
s
i
S
J
r
a
l
Angu
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).
Main Concepts
Model
- application data
View
Controller
- application behavior
Scope
- angular namespace
Module
Dashboard Flow
Angularjs
Directives
Rails
Templates
/widgets
Controller
Widgets
Model
Controller
Action to route
View
Router (app.js)
Steps.
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.
Steps...
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.
app.js
Create app.js in your assets folder.
angular.module('Megam', [ "ngResource", "ngRoute",ngAnimate" ]);
Dashboard view
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 %>
s
j
.
p
p
a
n
i
g
n
i
t
u
Setup ro
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 widget controller rendered this widget template and draw the graph into the
cpu_system_graph location.
.
.
.
o
f
n
i
e
r
o
m
r
Fo
http://www.gomegam.com
https://www.megam.co
code : https://github.com/megamsys/nilavu.git
email : rajthilak@megam.co.in
twitter:@megamsystems