Commit 09b68c7e authored by Phạm Duy Phi's avatar Phạm Duy Phi

no message

parent 480f4a72
......@@ -2,10 +2,12 @@ package com.itsol.quantrivanphong;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@SpringBootApplication
@EnableJpaAuditing
//@ComponentScan(basePackages = {"com.itsol.quantrivanphong.report.timesheet.controller", "com.itsol.quantrivanphong.report.timesheet.business"})
public class QuantrivanphongApplication {
public static void main(String[] args) {
......
......@@ -21,10 +21,10 @@ public class TimeSheetBusiness {
EProjectRepository eProjectRepository;
@Autowired
EmployeeRepository employeeRepository;
public String insertTimeSheet(int employee_Id, TimeSheetDTO timeSheetDTO) {
public String insertTimeSheet(TimeSheetDTO timeSheetDTO) {
String message;
Employee employee = employeeRepository.findEmployeeById(employee_Id);
Eproject eproject = eProjectRepository.findEprojectByIdAndEmployee(timeSheetDTO.getEproject_id(), employee);
Employee employee = employeeRepository.findEmployeeById(timeSheetDTO.getEmployeeId());
Eproject eproject = eProjectRepository.findEprojectByIdAndEmployee(timeSheetDTO.getEprojectId(), employee);
if (eproject != null) {
// SimpleDateFormat formatter= new SimpleDateFormat("dd-MM-yyyy HH:mm");
// Date date = new Date(System.currentTimeMillis());
......@@ -49,14 +49,15 @@ public class TimeSheetBusiness {
return message;
}
public String deleteTimeSheet(int employee_Id, int timeSheet_Id) {
public String deleteTimeSheet(int timesheetId) {
String message;
Employee employee = employeeRepository.findEmployeeById(employee_Id);
Eproject eproject = eProjectRepository.findEprojectByEmployee(employee);
TimeSheet timeSheet = timeSheetRepository.findTimeSheetByEprojectAndId(eproject, timeSheet_Id);
// Employee employee = employeeRepository.findEmployeeById(timeSheetDTO.getEmployeeId());
// Eproject eproject = eProjectRepository.findEprojectByEmployee(employee);
// TimeSheet timeSheet = timeSheetRepository.findTimeSheetByEprojectAndId(eproject, timeSheetDTO.getId());
TimeSheet timeSheet = timeSheetRepository.findTimeSheetById(timesheetId);
if (timeSheet != null) {
timeSheetRepository.delete(timeSheet);
if (timeSheetRepository.findTimeSheetByEprojectAndId(eproject, timeSheet_Id) == null) {
if (timeSheetRepository.findTimeSheetById(timesheetId) == null) {
message = "Delete success";
} else {
message = "Delete failed";
......@@ -72,15 +73,15 @@ public class TimeSheetBusiness {
}
@Transactional
public String updateTimeSheet(int employee_Id, TimeSheetDTO timeSheetDTO, int timesheet_Id) {
public String updateTimeSheet(TimeSheetDTO timeSheetDTO) {
String message;
Employee employee = employeeRepository.findEmployeeById(employee_Id);
Employee employee = employeeRepository.findEmployeeById(timeSheetDTO.getEmployeeId());
Eproject eproject = eProjectRepository.findEprojectByEmployee(employee);
TimeSheet timeSheet = timeSheetRepository.findTimeSheetByEprojectAndId(eproject, timesheet_Id);
TimeSheet timeSheet = timeSheetRepository.findTimeSheetByEprojectAndId(eproject, timeSheetDTO.getId());
if (eproject != null) {
if (timeSheet != null) {
int i = timeSheetRepository.updateTimeSheet(timeSheetDTO.getTitle(), timeSheetDTO.getContent()
, timeSheetDTO.getNote(), timesheet_Id);
, timeSheetDTO.getNote(), timeSheetDTO.getId());
if (i == 1) {
message = "Update success";
} else {
......
......@@ -16,13 +16,13 @@ import java.util.List;
public class TimeSheetController {
@Autowired
TimeSheetBusiness timeSheetBusiness;
@PostMapping(path = "/{employee_Id}/timesheet", consumes = "application/json", produces = "application/json")
public ResponseEntity<String> insertTimeSheet(@PathVariable int employee_Id, @Valid @RequestBody TimeSheetDTO timeSheetDTO) {
@PostMapping(path = "/timesheet", consumes = "application/json", produces = "application/json")
public ResponseEntity<String> addTimeSheet(@RequestBody TimeSheetDTO timeSheetDTO) {
String message;
try {
if (timeSheetDTO.getTitle().trim().equals("")) throw new InputException("Tiêu đề không được để trống");
if (timeSheetDTO.getContent().trim().equals("")) throw new InputException("Nội dung không được để trống");
message = timeSheetBusiness.insertTimeSheet(employee_Id, timeSheetDTO);
message = timeSheetBusiness.insertTimeSheet(timeSheetDTO);
} catch (InputException e) {
message = e.getMessage();
}
......@@ -30,24 +30,24 @@ public class TimeSheetController {
return ResponseEntity.ok(message);
}
@DeleteMapping("/{employee_Id}/timesheet/{timesheet_Id}")
public ResponseEntity<String> deleteTimeSheet(@PathVariable int employee_Id, @Valid @PathVariable int timesheet_Id) {
return ResponseEntity.ok(timeSheetBusiness.deleteTimeSheet(employee_Id, timesheet_Id));
@DeleteMapping("/timesheet/delete/{timesheetId}")
public ResponseEntity<String> deleteTimeSheet(@PathVariable int timesheetId) {
return ResponseEntity.ok(timeSheetBusiness.deleteTimeSheet(timesheetId));
}
@GetMapping(path = "/timesheet")
@GetMapping(path = "/timesheet/show")
public List<TimeSheet> showAllTimeSheet() {
return timeSheetBusiness.findAll();
}
@PostMapping(path = "/{employee_Id}/timesheet/{timesheet_Id}", consumes = "application/json", produces = "application/json")
public ResponseEntity<String> updateTimeSheet(@PathVariable int employee_Id, @PathVariable int timesheet_Id, @Valid @RequestBody TimeSheetDTO timeSheetDTO) {
@PostMapping(path = "/timesheet/update", consumes = "application/json", produces = "application/json")
public ResponseEntity<String> updateTimeSheet(@RequestBody TimeSheetDTO timeSheetDTO) {
String message;
try {
if (timeSheetDTO.getTitle().trim().equals("")) throw new InputException("Tiêu đề không được để trống");
if (timeSheetDTO.getContent().trim().equals("")) throw new InputException("Nội dung không được để trống");
message = timeSheetBusiness.updateTimeSheet(employee_Id, timeSheetDTO, timesheet_Id);
message = timeSheetBusiness.updateTimeSheet(timeSheetDTO);
} catch (InputException e) {
message = e.getMessage();
}
......@@ -62,7 +62,7 @@ public class TimeSheetController {
// return ResponseEntity.ok(message);
// }
@GetMapping("/{employee_Id}/timesheet")
@GetMapping("/timesheet/show/{employee_Id}")
public ResponseEntity<List<TimeSheet>> showTimeSheetById(@PathVariable int employee_Id) {
return ResponseEntity.ok(timeSheetBusiness.findTimeSheetById(employee_Id));
}
......
......@@ -9,10 +9,11 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class TimeSheetDTO {
private int id;
private int employeeId;
private String title;
private String content;
private String note;
private String checked;
private boolean status;
private int eproject_id;
private int eprojectId;
}
......@@ -9,7 +9,7 @@ import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface TimeSheetRepository extends JpaRepository<TimeSheet, Integer> {
// TimeSheet findTimeSheetById(int id);
TimeSheet findTimeSheetById(int id);
// @Query("select ts from TimeSheet ts order by ts.createdAt desc")
// List<TimeSheet> getAllTimeSheet();
......
......@@ -32,7 +32,6 @@ Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, Sony
<!--End khai báo controllers-->
</head>
<body ng-app="myApp">
<!--start-main-->
<div class="container">
......
......@@ -78,4 +78,4 @@ angular.module("myApp", ["ui.router"]).config(function($stateProvider, $urlRoute
}
})
});
\ No newline at end of file
});
// /**
// *
// */
// angular.module("myApp", ["ui.router"]).config(function($stateProvider, $urlRouterProvider,$locationProvider) {
//
// $locationProvider.hashPrefix('');
// $urlRouterProvider.otherwise("/index");
//
// $stateProvider
//
// //index layout riêng
// .state("index", {
// url: "/index",
// views:{
// "index":{
// templateUrl: "pages/index/index.htm",
// controller: "indexController"
// },
// "banner":{
// templateUrl: "pages/index/banner.htm"
// }
// }
// })
//
// // State chứa layout chung cho các trang
// .state('app', {
// abstract: true,
// views: {
// 'main_layout': {
// templateUrl: 'main_layout.html',
// }
// }
// })
//
// // Các state bên dưới kế thừa state app
//
// .state("tintuc", { // Khai báo một state
// parent: 'app',
// url: "/tintuc", // URL hiển thị
// views:{
// "content":{
// templateUrl: "pages/tintuc/tintuc.htm",
// controller: "tintucController" // khai báo controller
// }
// }
// })
//
// .state("tuyendung", {
// parent: 'app',
// url: "/tuyendung",
// views:{
// "content":{
// templateUrl: "pages/tuyendung/tuyendung.htm",
// controller: "tuyendungController"
// }
// }
// })
//
// // .state("lienhe", {
// // parent: 'app',
// // url: "/lienhe",
// // views:{
// // "content":{
// // templateUrl: "pages/lienhe/lienhe.htm",
// // controller: "lienheController"
// // }
// // }
// // })
//
// .state("gioithieu", {
// parent: 'app',
// url: "/gioithieu",
// views:{
// "content":{
// templateUrl: "pages/gioithieu/gioithieu.htm",
// controller: "gioithieuController"
// }
// }
// })
//
// });
//
//--------------------Phi--------------------------------
const report = angular.module('quantrivanphong', ['ngRoute']);
report.config(function ($routeProvider) {
$routeProvider.when('/timesheet', {
templateUrl: 'timesheet.html',
controller: 'showTimeSheetController'
})
});
report.controller('showTimeSheetController', function ($scope, $http) {
$scope.timesheet = {
"id": "",
"title": "",
"content": "",
"note": "",
"eproject": "",
"createdAt": ""
};
$http({
method : 'GET',
url : "http://localhost:8080/eproject/timesheet/show",
}).then(function successCallback(response) {
console.log(response);
$scope.timesheets = response.data;
}, function errorCallback(response) {
console.log(response)
});
});
<!DOCTYPE html>
<html lang="en" ng-app = "quantrivanphong">
<head>
<meta charset="UTF-8">
<title>Report</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="//unpkg.com/@uirouter/angularjs/release/angular-ui-router.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-view></div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en" ng-app="MyTimeSheet" ng-controller="timesheetController">
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Time Sheet</title>
......@@ -11,58 +11,128 @@
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="timesheetController.js"></script>
<!-- <script>-->
<!-- function myFunction() {-->
<!-- const x = document.getElementById("mydiv");-->
<!-- if (x.style.display === "none") {-->
<!-- x.style.display = "block";-->
<!-- } else {-->
<!-- x.style.display = "none";-->
<!-- }-->
<!-- }-->
<!-- </script>-->
</head>
<body>
<body ng-controller="showTimeSheetController">
<div class="container">
<div class="row">
<div class="col-md-8">
<div>
<legend>Create Time Sheet</legend>
<table>
<tr>
<td><label>Title</label></td>
<td>
<input type="text" maxlength="29" ng-model="ts.title"/>
</td>
</tr>
<tr>
<td><label>Content</label></td>
<td>
<input type="text" maxlength="29" ng-model="ts.content"/>
</td>
</tr>
<tr>
<td><label>Note</label></td>
<td>
<input type="text" maxlength="29" ng-model="ts.note"/>
</td>
</tr>
</table>
</div>
<!-- <div>-->
<!-- <legend>Create Time Sheet</legend>-->
<!-- <table>-->
<!-- <tr>-->
<!-- <td><label>Title</label></td>-->
<!-- <td>-->
<!-- <input type="text" maxlength="29" ng-model="tsdto.title"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td><label>Content</label></td>-->
<!-- <td>-->
<!-- <input type="text" maxlength="29" ng-model="tsdto.content"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td><label>Note</label></td>-->
<!-- <td>-->
<!-- <input type="text" maxlength="29" ng-model="tsdto.note"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td><label>Employee Id</label></td>-->
<!-- <td>-->
<!-- <input type="text" maxlength="29" ng-model="tsdto.employeeId"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td><label>Employee Project Id</label></td>-->
<!-- <td>-->
<!-- <input type="text" maxlength="29" ng-model="tsdto.eprojectId"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td></td>-->
<!-- <td>-->
<!-- <input type="submit" name="submit" value="Submit" ng-click="save();"/>-->
<!-- <input type="submit" name="clear" value="Clear" ng-click="tsdto = null"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- </table>-->
<!-- </div>-->
<div>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Content</th>
<th>Note</th>
</tr>
<tr>
<th>ID</th>
<th>Title</th>
<th>Content</th>
<th>Note</th>
<th>Employee Project Id</th>
<th>Created at</th>
</tr>
</thead>
<tbody>
<tr class="vide" ng-repeat="ts in timesheet">
<td>{{$index + 1}}</td>
<td>{{ts.title}}</td>
<td>{{ts.content}}</td>
<td>{{ts.note}}</td>
<tr class="showTimeSheet" ng-repeat="timesheet in timesheets">
<td>{{$index + 1}}</td>
<td>{{timesheet.title}}</td>
<td>{{timesheet.content}}</td>
<td>{{timesheet.note}}</td>
<td>{{timesheet.eproject.project.name}}</td>
<td>{{timesheet.createdAt}}</td>
<!-- <td><a href="#" ng-click="update(emp);">Update</a>-->
<!-- <td><a href="#" confirmed-click="delete(employee);" ng-confirm-click=" Do you want to delete this user?">Delete</a></td>-->
</tr>
<td><a href="#" onclick="myFunction()" ng-click="update(timesheet);">Update</a>
<td><a href="http://localhost:8080/pages/timesheet/timesheet.html" ng-click="delete(timesheet);">Delete</a></td>
</tr>
</tbody>
</table>
</div>
<!-- <div id="mydiv" style="display: none">-->
<!-- <legend>Update Time Sheet</legend>-->
<!-- <table>-->
<!-- <tr>-->
<!-- <td><label>Employee Id</label></td>-->
<!-- <td>-->
<!-- <input type="text" maxlength="29" ng-model="tsdtou.employeeId"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td><label>Title</label></td>-->
<!-- <td>-->
<!-- <input type="text" maxlength="29" ng-model="tsdtou.title"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td><label>Content</label></td>-->
<!-- <td>-->
<!-- <input type="text" maxlength="29" ng-model="tsdtou.content"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td><label>Note</label></td>-->
<!-- <td>-->
<!-- <input type="text" maxlength="29" ng-model="tsdtou.note"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td>-->
<!-- <input type="submit" name="update" value="Update" ng-click="updatedto();"/>-->
<!-- <input type="submit" name="clear" value="Clear" ng-click="tsdtou = null"/>-->
<!-- </td>-->
<!-- </tr>-->
<!-- </table>-->
<!-- </div>-->
</div>
</div>
</div>
......
angular.module("MyTimeSheet",[]).controller("timesheetController", function($scope, $http,$window) {
console.log("Time Sheet controller");
$scope.ts = {
"title": "",
"content": "",
"note": ""
};
$http({
header : 'Access-Control-Allow-Origin: http://localhost:63342/MockProject_01/public/pages/timesheet/timesheet.html?_ijt=ee540pqfq7tplkmo9mjj447ne',
method : 'GET',
url : "http://localhost:8080/eproject/timesheet",
}).then(function successCallback(response) {
console.log(response)
$scope.timesheet=response.data;
}, function errorCallback(response) {
console.log(response)
});
});
\ No newline at end of file
//
//
//
// angular.module("MyTimeSheet",[]).controller("timesheetController", function($scope, $http, $window) {
// console.log("Time Sheet controller");
//
// $scope.ts = {
// "id": "",
// "title": "",
// "content": "",
// "note": "",
// "eproject": "",
// "createdAt": ""
// };
//
// $scope.tsdto = {
// "title": "",
// "content": "",
// "note": "",
// "employeeId": "",
// "eprojectId": ""
// };
//
// $scope.tsdtou = {
// "id": "",
// "title": "",
// "content": "",
// "note": "",
// "employeeId": ""
// };
//
// $http({
// method : 'GET',
// url : "http://localhost:8080/eproject/timesheet/show",
// }).then(function successCallback(response) {
// console.log(response);
// $scope.timesheet = response.data;
// }, function errorCallback(response) {
// console.log(response)
// });
//
//
// $scope.save = save;
// function save(){
// console.log($scope.tsdto);
// $http({
// method : 'POST',
// url : "http://localhost:8080/eproject/timesheet",
// data: $scope.tsdto
// }).then(function successCallback(response) {
// console.log(response);
// $window.location.href ='http://localhost:8080/#/eproject/timesheet';
// }, function errorCallback(response) {
// console.log(response)
// });
// }
//
//
// $scope.update = function (ts) {
// $scope.tsdtou.id = ts.id;
// $scope.tsdtou.title = ts.title;
// $scope.tsdtou.content = ts.content;
// $scope.tsdtou.note = ts.note;
// };
//
// $scope.updatedto = function () {
// console.log($scope.tsdtou);
// $http({
// method : 'POST',
// url : 'http://localhost:8080/eproject/timesheet/update',
// data: $scope.tsdtou
// }).then(function successCallback(response) {
// console.log(response);
// $window.location.href ='http://localhost:8080/eproject/timesheet#!';
// }, function errorCallback(response) {
// console.log(response)
// });
// };
//
//
// $scope.delete = function (ts) {
// $http({
// method : 'DELETE',
// url : 'http://localhost:8080/eproject/timesheet/delete/'+ts.id,
// }).then(function successCallback(response) {
// console.log(response);
// $window.location.href ='http://localhost:8080/#/eproject/timesheet#!';
// }, function errorCallback(response) {
// console.log(response)
// });
// }
// });
\ No newline at end of file
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