Created
February 7, 2016 02:52
-
-
Save leosilvadev/79a3d27ec1a6d9825c3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var modulo = angular.module('rh'); | |
modulo.controller('EmployeesController', function($scope, rhManager){ | |
$scope.loadEmployees = function(){ | |
$scope.employees = rhManager.list(); | |
}; | |
$scope.loadEmployees(); | |
}); | |
modulo.controller('NewEmployeeController', function($scope, rhManager, $location){ | |
$scope.employee = {}; | |
$scope.add = function(employee){ | |
rhManager.add(employee); | |
$location.path('/employees') | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<DOCTYPE html> | |
<html ng-app="rh"> | |
<head> | |
<style> | |
@IMPORT url("bootstrap-3.3.6-dist/css/bootstrap.min.css"); | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<nav class="navbar navbar-default"> | |
<div> | |
<div class="navbar-header"> | |
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> | |
<span class="sr-only">Toggle navigation</span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</button> | |
<a class="navbar-brand" href="#">RH Manager</a> | |
</div> | |
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> | |
<ul class="nav navbar-nav"> | |
<li> | |
<a href="#employees">Funcionarios <span class="sr-only">(current)</span></a> | |
</li> | |
<li> | |
<a href="#employees/new">Contratar</a> | |
</li> | |
</ul> | |
</div> | |
</div> | |
</nav> | |
<div ng-view></div> | |
</div> | |
<script src="bower_components/angular/angular.min.js"></script> | |
<script src="bower_components/angular-route/angular-route.min.js"></script> | |
<script src="bower_components/angular-bootstrap/ui-bootstrap.min.js"></script> | |
<script src="bower_components/angular-input-masks/angular-input-masks-standalone.min.js"></script> | |
<script src="js/modules/employee/module.js"></script> | |
<script src="js/modules/employee/controller.js"></script> | |
<script src="js/modules/employee/service.js"></script> | |
<script src="js/modules/employee/views.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section> | |
<div class="row"> | |
<div class="well col-sm-12"> | |
<table class="table table-hover table-bordered"> | |
<thead> | |
<tr> | |
<th colspan="6"> | |
<div class="form-group"> | |
<div class="input-group" style="width: 100%;"> | |
<div class="input-group-addon"> | |
<span class="glyphicon glyphicon-search"></span> Pesquisar | |
</div> | |
<input class="form-control" ng-model="searchByName"> | |
</div> | |
</div> | |
</th> | |
</td> | |
<tr> | |
<th>Id</th> | |
<th>Name</th> | |
<th>Age</th> | |
<th>Job</th> | |
<th>Status</th> | |
<th>Salary</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr ng-repeat="emp in employees | filter:searchByName"> | |
<td>{{emp.id}}</td> | |
<td>{{emp.name}}</td> | |
<td>{{emp.age}}</td> | |
<td>{{emp.job}}</td> | |
<td>{{emp.status}}</td> | |
<td>{{emp.salary | currency}}</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
</div> | |
</section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('rh', ['ui.utils.masks', 'ngRoute']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section> | |
<form novalidate name="registrationForm" ng-submit="add(employee)"> | |
<div ng-show="registrationForm.$dirty"> | |
<div class="alert alert-warning" | |
ng-show="registrationForm.name.$dirty && registrationForm.name.$error.required"> | |
Insira o nome do Funcionário corretamente | |
</div> | |
<div class="alert alert-warning" | |
ng-show="registrationForm.age.$dirty && registrationForm.age.$error.required"> | |
Insira a idade do Funcionário corretamente | |
</div> | |
<div class="alert alert-warning" | |
ng-show="registrationForm.salary.$dirty &®istrationForm.salary.$error.required"> | |
Insira o salário do Funcionário corretamente | |
</div> | |
</div> | |
<div class="row well"> | |
<div class="col-sm-4"> | |
<label for="name">Name: </label> | |
<input id="name" name="name" ng-model="employee.name" class="form-control" ng-required="true"> | |
</div> | |
<div class="col-sm-4"> | |
<label for="age">Age:</label> | |
<input id="age" name="age" ng-model="employee.age" type="number" class="form-control" | |
ng-required="true" min="1" max="100"> | |
</div> | |
<div class="col-sm-4"> | |
<label for="salary">Salary:</label> | |
<input id="salary" name="salary" ng-model="employee.salary" class="form-control" ng-required="true" | |
ui-number-mask> | |
</div> | |
</div> | |
<div class="row well"> | |
<div class="col-sm-2"> | |
<button type="submit" class="btn btn-primary" ng-disabled="registrationForm.$invalid">Hire</button> | |
</div> | |
</div> | |
</form> | |
</section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var modulo = angular.module('rh'); | |
modulo.factory('rhManager', function(){ | |
var employees = []; | |
var add = function(emp){ | |
emp.id = Math.floor((Math.random() * 10) + 1); | |
emp.status = 'active'; | |
employees.push(emp); | |
}; | |
var update = function(emp){ | |
var found = find(emp); | |
found.name = emp.name; | |
found.age = emp.age; | |
found.job = emp.job; | |
return found; | |
}; | |
var find = function(emp){ | |
var found = employees.find(function(obj){ | |
return obj.id == emp.id; | |
}); | |
return found; | |
}; | |
var fire = function(emp){ | |
var found = find(emp); | |
found.status = 'fired'; | |
return found; | |
}; | |
var list = function(){ | |
return employees; | |
}; | |
return { | |
add: add, | |
update:update, | |
find:find, | |
fire:fire, | |
list: list | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('rh').config(function($routeProvider){ | |
$routeProvider | |
.when('/employees', { | |
templateUrl: 'js/modules/employee/views/list.html', | |
controller: 'EmployeesController' | |
}) | |
.when('/employees/new', { | |
templateUrl: 'js/modules/employee/views/new.html', | |
controller: 'NewEmployeeController' | |
}) | |
.otherwise({ | |
redirectTo: '/employees' | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment