Commit 51db7d95 authored by đinh thị đầm's avatar đinh thị đầm

commit init

parent 61185cb8
......@@ -7,6 +7,7 @@ import org.springframework.validation.Validator;
import java.util.List;
public interface EmployeeBusiness extends Validator {
List<Employee> findAll();
......@@ -21,9 +22,8 @@ public interface EmployeeBusiness extends Validator {
void save(Employee employee);
void deleteById(int id);
// Optional<Employee> findOneWithEagerRelationships(@Param("id") int id);
boolean confirmEmployee(Employee employee);
Page<Employee> findAll(Pageable pageable);
Page<Employee>findAllWithEagerRelationships(Pageable pageable);
public Page<Employee> findAll(Pageable pageable);
}
......@@ -44,7 +44,7 @@ public class EmployeeBusinessImpl implements EmployeeBusiness {
@Override
public void save(Employee employee) {
employeeRepository.save(employee);
employeeRepository.save(employee);
}
@Override
......@@ -52,11 +52,6 @@ public class EmployeeBusinessImpl implements EmployeeBusiness {
employeeRepository.deleteById(id);
}
// @Override
// public Optional<Employee> findOneWithEagerRelationships(int id) {
// return Optional.empty();
// }
@Override
public boolean confirmEmployee(Employee employee) {
return true;
......@@ -64,13 +59,9 @@ public class EmployeeBusinessImpl implements EmployeeBusiness {
@Override
public Page<Employee> findAll(Pageable pageable) {
return null;
return employeeRepository.findAll(pageable);
}
@Override
public Page<Employee> findAllWithEagerRelationships(Pageable pageable) {
return null;
}
@Override
public boolean supports(Class<?> clazz) {
......
package com.itsol.quantrivanphong.manager.employee.controller;
import com.itsol.quantrivanphong.manager.employee.business.EmployeeBusiness;
import com.itsol.quantrivanphong.manager.employee.util.PaginationUtil;
import com.itsol.quantrivanphong.model.Employee;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -11,9 +15,12 @@ import org.springframework.web.util.UriComponentsBuilder;
import java.util.List;
@RestController
public class EmployeeController {
Logger logger = Logger.getLogger(EmployeeController.class);
@Autowired
//Retrieve Employee by id
private EmployeeBusiness employeeBusiness;
......@@ -26,7 +33,7 @@ public class EmployeeController {
System.out.println("Employee with id : " + id + " not found");
return new ResponseEntity<Employee>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<Employee>( employee ,HttpStatus.OK);
return new ResponseEntity<Employee>(employee, HttpStatus.OK);
}
//Retrieve all employee
......@@ -36,7 +43,7 @@ public class EmployeeController {
if (employees == null) {
return new ResponseEntity<List<Employee>>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<List<Employee>>( employees , null ,HttpStatus.OK);
return new ResponseEntity<List<Employee>>(employees, null, HttpStatus.OK);
}
//Update a Employee
......@@ -64,44 +71,44 @@ public class EmployeeController {
currentEmployee.setGraduationYear(employee.getGraduationYear());
currentEmployee.setPicture(employee.getPicture());
employeeBusiness.save(currentEmployee);
return new ResponseEntity<Employee>( currentEmployee ,HttpStatus.OK);
return new ResponseEntity<Employee>(currentEmployee, HttpStatus.OK);
}
//Create a Employee
@RequestMapping(value = "/list_employee", method = RequestMethod.POST)
public ResponseEntity<Void> createEmployee(@RequestBody Employee employee,
UriComponentsBuilder uriComponentsBuilder){
System.out.println("Create Employee "+ employee.getUsername());
UriComponentsBuilder uriComponentsBuilder) {
System.out.println("Create Employee " + employee.getUsername());
employeeBusiness.save(employee);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(uriComponentsBuilder.path("/employee/{id}").buildAndExpand(employee.getId()).toUri());
return new ResponseEntity<Void>( httpHeaders ,HttpStatus.CREATED);
httpHeaders.setLocation(uriComponentsBuilder.path("/employee/{id}").buildAndExpand(employee.getId()).toUri());
return new ResponseEntity<Void>(httpHeaders, HttpStatus.CREATED);
}
//Delete a Employee
@RequestMapping(value = "/employee/{id}" , method = RequestMethod.DELETE)
public ResponseEntity<Employee> deleteEmployee(@PathVariable("id") int id){
System.out.println("Fetching and deleting Employee with id :" + id );
@RequestMapping(value = "/employee/{id}", method = RequestMethod.DELETE)
public ResponseEntity<Employee> deleteEmployee(@PathVariable("id") int id) {
System.out.println("Fetching and deleting Employee with id :" + id);
Employee employee = employeeBusiness.findById(id);
if(employee == null) {
if (employee == null) {
System.out.println("Unable to delete. Employee with id :" + id + "not found");
return new ResponseEntity<Employee>(HttpStatus.NOT_FOUND);
}
employeeBusiness.deleteById(id);
return new ResponseEntity<Employee>(HttpStatus.NO_CONTENT);
return new ResponseEntity<Employee>(HttpStatus.NO_CONTENT);
}
// paging
@RequestMapping( value ="/paging_employee",params = {"page","size"}, method = RequestMethod.GET)
public ResponseEntity<List<Employee>> getAllEmployee(Pageable pageable) {
logger.info("Rest request to get a page of Employee");
Page<Employee> page = employeeBusiness.findAll(pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/paging_employee");
return ResponseEntity.ok().headers(headers).body(page.getContent());
}
// @GetMapping("/list_employee")
// public ResponseEntity<List<Employee>> getAllOperations(Pageable pageable, @RequestParam MultiValueMap<String, String> queryParams, UriComponentsBuilder uriBuilder, @RequestParam(required = false, defaultValue = "false") boolean eagerload) {
// Page<Employee> page;
// if (eagerload) {
// page = employeeBusiness.findAllWithEagerRelationships(pageable);
// } else {
// page = employeeBusiness.findAll(pageable);
// }
// HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/list_employee");
// return ResponseEntity.ok().headers(headers).body(page.getContent());
// }
}
......@@ -3,7 +3,6 @@ package com.itsol.quantrivanphong.manager.employee.repository;
import com.itsol.quantrivanphong.model.Employee;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
......@@ -20,17 +19,6 @@ public interface EmployeeRepository extends JpaRepository<Employee,Integer > {
Employee findByEmailAddress(String emailAddress);
Page<Employee> findByFirstName(String firstName, Pageable pageable);
Slice<Employee> findByFirstNameAndLastName(String firstName, String lastName, Pageable pageable);
// @Query(value = "select distinct employee from Employee employee left join fetch employee.labels",
// countQuery = "select count(distinct employee) from Employee employee")
// Page<Employee> findAllWithEagerRelationships(Pageable pageable);
//
// @Query("select distinct employee from Employee employee left join fetch employee.labels")
// List<Employee> findAllWithEagerRelationships();
//
// @Query("select employee from Employee employee left join fetch employee.labels where employee.id =:id")
// Optional<Employee> findOneWithEagerRelationships(@Param("id") int id);
//==================================================================================================================
......
This diff is collapsed.
......@@ -21,7 +21,8 @@ SmartPhone Compatible web template, free WebDesigns for Nokia, Samsung, LG, Sony
<link href="css/style.css" rel='stylesheet' type='text/css' />
<!-- font-awesome icons CSS -->
<link href="css/font-awesome.css" rel="stylesheet">
<link href="css/font-awesome.css" rel="stylesheet">
<!-- //font-awesome icons CSS-->
<!-- side nav css file -->
......@@ -50,6 +51,8 @@ SmartPhone Compatible web template, free WebDesigns for Nokia, Samsung, LG, Sony
<script src="js/app.js"></script>
<script src="pages/employee/employeeController.js"></script>
<script src="pages/employee/createEmployeeController.js"></script>
<script src="js/dirPagination.js"></script>
<!-- end anguarjs app-->
<link href="css/custom.css" rel="stylesheet">
<!--//Metis Menu -->
......@@ -110,7 +113,7 @@ SmartPhone Compatible web template, free WebDesigns for Nokia, Samsung, LG, Sony
lazyLoad : true,
autoPlay : true,
pagination : true,
nav:true,
nav:true
});
});
</script>
......@@ -489,85 +492,106 @@ SmartPhone Compatible web template, free WebDesigns for Nokia, Samsung, LG, Sony
}]
};
$(function() {
window.onload = function () {
var ctx = document.getElementById("canvas")
if(ctx)
{
ctx.getContext("2d");
window.myBar = new Chart(ctx, {
type: 'bar',
data: barChartData,
options: {
responsive: true,
legend: {
position: 'top'
},
title: {
display: true,
text: 'Chart.js Bar Chart'
}
}
});
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx, {
type: 'bar',
data: barChartData,
options: {
responsive: true,
legend: {
position: 'top',
},
title: {
display: true,
text: 'Chart.js Bar Chart'
}
}
});
};
document.getElementById('randomizeData').addEventListener('click', function() {
var zero = Math.random() < 0.2 ? true : false;
barChartData.datasets.forEach(function(dataset) {
dataset.data = dataset.data.map(function() {
return zero ? 0.0 : randomScalingFactor();
});
}
});
window.myBar.update();
});
}
});
var c= document.getElementById('randomizeData');
if(c) {
c.addEventListener('click', function () {
var zero = Math.random() < 0.2 ? true : false;
barChartData.datasets.forEach(function (dataset) {
dataset.data = dataset.data.map(function () {
return zero ? 0.0 : randomScalingFactor();
});
});
window.myBar.update();
});
}
var colorNames = Object.keys(window.chartColors);
document.getElementById('addDataset').addEventListener('click', function() {
var colorName = colorNames[barChartData.datasets.length % colorNames.length];;
var dsColor = window.chartColors[colorName];
var newDataset = {
label: 'Dataset ' + barChartData.datasets.length,
backgroundColor: color(dsColor).alpha(0.5).rgbString(),
borderColor: dsColor,
borderWidth: 1,
data: []
};
for (var index = 0; index < barChartData.labels.length; ++index) {
newDataset.data.push(randomScalingFactor());
}
barChartData.datasets.push(newDataset);
window.myBar.update();
});
document.getElementById('addData').addEventListener('click', function() {
if (barChartData.datasets.length > 0) {
var month = MONTHS[barChartData.labels.length % MONTHS.length];
barChartData.labels.push(month);
for (var index = 0; index < barChartData.datasets.length; ++index) {
//window.myBar.addData(randomScalingFactor(), index);
barChartData.datasets[index].data.push(randomScalingFactor());
}
window.myBar.update();
}
});
document.getElementById('removeDataset').addEventListener('click', function() {
barChartData.datasets.splice(0, 1);
window.myBar.update();
});
document.getElementById('removeData').addEventListener('click', function() {
barChartData.labels.splice(-1, 1); // remove the label first
var el= document.getElementById('addDataset');
if(el) {
addEventListener('click', function () {
var colorName = colorNames[barChartData.datasets.length % colorNames.length];
;
var dsColor = window.chartColors[colorName];
var newDataset = {
label: 'Dataset ' + barChartData.datasets.length,
backgroundColor: color(dsColor).alpha(0.5).rgbString(),
borderColor: dsColor,
borderWidth: 1,
data: []
};
for (var index = 0; index < barChartData.labels.length; ++index) {
newDataset.data.push(randomScalingFactor());
}
barChartData.datasets.forEach(function(dataset, datasetIndex) {
dataset.data.pop();
});
barChartData.datasets.push(newDataset);
window.myBar.update();
});
}
var els= document.getElementById('addData');
if(els) {
addEventListener('click', function () {
if (barChartData.datasets.length > 0) {
var month = MONTHS[barChartData.labels.length % MONTHS.length];
barChartData.labels.push(month);
for (var index = 0; index < barChartData.datasets.length; ++index) {
//window.myBar.addData(randomScalingFactor(), index);
barChartData.datasets[index].data.push(randomScalingFactor());
}
window.myBar.update();
}
});
}
var rs= document.getElementById('removeDataset');
if(rs) {
addEventListener('click', function () {
barChartData.datasets.splice(0, 1);
window.myBar.update();
});
}
var res =document.getElementById('removeData');
if(res) {
addEventListener('click', function () {
barChartData.labels.splice(-1, 1); // remove the label first
barChartData.datasets.forEach(function (dataset, datasetIndex) {
dataset.data.pop();
});
window.myBar.update();
});
}
window.myBar.update();
});
</script>
<!-- new added graphs chart js-->
......
This diff is collapsed.
/**
*
*/
angular.module("myApp", ["ui.router"]).config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
angular.module("myApp", ['ui.router']).config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
$locationProvider.hashPrefix('');
$urlRouterProvider.otherwise("/employees");
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -2,7 +2,7 @@
*
*/
angular.module("myApp").controller("createEmployeeController", function ($scope, $http, $state, $stateParams) {
console.log("Employee controller");
console.log("Create Employee controller");
console.log($stateParams.emp);
if ($stateParams.emp) {
......
......@@ -2,7 +2,7 @@
<div class="row">
<div class="col-md-8">
<td><a class="btn btn-info" href="#" ui-sref="createEmployee">Add</a></td>
<table class="table">
<thead>
......@@ -37,8 +37,7 @@
<td>{{emp.department}}</td>
<td>{{emp.position}}</td>
<td><a href="#" ng-click="updateEmp(emp);">Edit</a>
<td><a href="#" ng-confirm-click=" Do you want to delete this user?"
ng-click="delete(emp);">Delete</a>
<td><a href="#" ng-click="deleteEmp(emp);">Delete</a>
</td>
</tr>
......@@ -46,6 +45,10 @@
</tbody>
</table>
<tr>
<td><a class="btn btn-info" href="#" ui-sref="createEmployee">Add</a></td>
</tr>
</div>
</div>
......
......@@ -55,7 +55,7 @@ angular.module("myApp").controller("employeeController", function($scope, $http,
// HTTP DELETE- delete employee by Id
// Call: http://localhost:8080/employee/{id}
$scope.delete = function (emp) {
$scope.deleteEmp = function (emp) {
$http({
method: 'DELETE',
url: '/employee/' + emp.id
......@@ -91,7 +91,17 @@ angular.module("myApp").controller("employeeController", function($scope, $http,
}, function errorCallback(response) {
console.log(response)
});
// $scope.reload = reload;
// function reload() {
// $http.get("http://localhost:8081/employees")
// success(function (data) {
// $scope.employees = data.employees;
// });
// $timeout(function(){
// $scope.reload();
// },3)
// };
// $scope.reload();
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment