Skip to content

Commit

Permalink
Frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen Ngoc Nam committed Aug 9, 2019
1 parent 1ba43ed commit f33e32d
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 117 deletions.
11 changes: 6 additions & 5 deletions app/Http/Controllers/Api/EmployeeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ public function show(Employee $employee)
*/
public function store(Request $request)
{
$model = new Employee();
$model->fill($request->all());
$id = $model->save();
$model = Employee::create($request->all());
$saved_result = $model->save();

$result["id"] = $id;
$result["model"] = $model;
$result["request"] = $request->all();
$result["result"] = $saved_result;

return response()->json($result);
}
Expand All @@ -89,7 +90,7 @@ public function update(Request $request, Employee $employee)
return response()->json($result);
}

public function delete(Employee $employee)
public function destroy(Employee $employee)
{
$result = $employee->delete();

Expand Down
4 changes: 2 additions & 2 deletions app/Model/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Employee extends BaseModel
{
use EmployeeTrait;

protected $fillable = [
'id',
protected $fillable = [
// 'id',
'firstname',
'lastname',
'birthday',
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 34 additions & 9 deletions database/nam_wealthpark.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
-- version 4.4.15.10
-- https://www.phpmyadmin.net
--
-- Host: localhost:3306
-- Generation Time: 2019 年 8 月 0814:28
-- サーバのバージョン: 10.4.6-MariaDB
-- PHP Version: 7.2.20
-- Host: localhost
-- Generation Time: 2019 年 8 月 0912:19
-- サーバのバージョン: 10.3.14-MariaDB
-- PHP Version: 7.2.19

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
Expand All @@ -17,7 +17,7 @@ SET time_zone = "+00:00";
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `nam_wealthpark`
-- Database: `nam_hr`
--

-- --------------------------------------------------------
Expand All @@ -33,18 +33,43 @@ CREATE TABLE IF NOT EXISTS `employees` (
`birthday` date DEFAULT NULL,
`address` varchar(1000) DEFAULT NULL,
`boss` varchar(100) DEFAULT NULL,
`salary` decimal(20,3) DEFAULT NULL,
`salary` decimal(20,0) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp(),
`deleted_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8mb4;

--
-- テーブルのデータのダンプ `employees`
--

INSERT INTO `employees` (`id`, `firstname`, `lastname`, `birthday`, `address`, `boss`, `salary`, `created_at`, `updated_at`, `deleted_at`) VALUES
(1, 'Nam', 'Nguyen', '2019-08-08', 'Tokyo, Toyosu', 'Urban', '1.000', '2019-08-07 15:00:00', '2019-08-07 15:00:00', NULL);
(1, 'Nam 1', 'Nguyen', '2019-08-08', 'Tokyo, Toyosu', 'Urban', '1', '2019-08-07 15:00:00', '2019-08-09 02:24:23', NULL),
(2, 'Nam 2', 'Nguyen 2', '2019-08-08', 'Tokyo, Toyosu', 'Urban', '10000', '2019-08-07 15:00:00', '2019-08-07 15:00:00', NULL),
(3, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-08 23:30:31', '2019-08-08 23:30:31', NULL),
(4, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-08 23:33:50', '2019-08-08 23:33:50', NULL),
(5, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-08 23:34:21', '2019-08-08 23:34:21', NULL),
(6, 'Nam 6', 'Nguyen', '2019-08-09', 'Earth', '地球', '6000', '2019-08-08 23:35:46', '2019-08-09 02:23:53', NULL),
(7, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-08 23:40:39', '2019-08-09 01:11:46', '2019-08-09 01:11:46'),
(8, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-08 23:41:22', '2019-08-09 01:11:41', '2019-08-09 01:11:41'),
(9, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-08 23:43:15', '2019-08-08 23:43:15', NULL),
(10, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-08 23:48:10', '2019-08-08 23:48:10', NULL),
(11, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-08 23:54:23', '2019-08-09 01:11:36', '2019-08-09 01:11:36'),
(12, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-09 00:00:15', '2019-08-09 00:00:15', NULL),
(13, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-09 00:18:02', '2019-08-09 00:18:02', NULL),
(14, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-09 00:25:19', '2019-08-09 00:25:19', NULL),
(15, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-09 00:25:50', '2019-08-09 00:25:50', NULL),
(16, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-09 00:30:27', '2019-08-09 00:30:27', NULL),
(17, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-09 00:32:51', '2019-08-09 01:11:32', '2019-08-09 01:11:32'),
(18, NULL, NULL, NULL, NULL, NULL, NULL, '2019-08-09 00:35:59', '2019-08-09 00:35:59', NULL),
(19, '19', NULL, NULL, NULL, NULL, NULL, '2019-08-09 00:37:03', '2019-08-09 00:37:03', NULL),
(20, '20', NULL, NULL, NULL, NULL, '2000000', '2019-08-09 00:37:37', '2019-08-09 00:37:37', NULL),
(21, '21', NULL, NULL, NULL, NULL, '21000', '2019-08-09 00:38:43', '2019-08-09 00:38:43', NULL),
(22, '22', 'Nguyen', '2019-08-09', 'Tokyo', 'Urban', '2200', '2019-08-09 00:40:33', '2019-08-09 00:40:33', NULL),
(23, 'Nam 23', 'Nguyen', '2019-08-09', 'Earth', '地球', '11111111', '2019-08-09 00:41:16', '2019-08-09 02:22:48', NULL),
(24, 'Nam 24', 'Nguyen', '2019-08-09', 'Tokyo, Toyosu', 'Coupon', '240000', '2019-08-09 00:41:21', '2019-08-09 01:03:41', NULL),
(25, 'Nam 25', 'Nguyen', '2019-08-09', 'Tokyo', 'Urban', '2500', '2019-08-09 00:42:43', '2019-08-09 02:23:01', NULL),
(26, 'Nam 26', 'Nguyen', '2019-08-09', '東京都足立区', NULL, '260000', '2019-08-09 02:59:39', '2019-08-09 02:59:39', NULL);

--
-- Indexes for dumped tables
Expand All @@ -64,7 +89,7 @@ ALTER TABLE `employees`
-- AUTO_INCREMENT for table `employees`
--
ALTER TABLE `employees`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=27;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
203 changes: 176 additions & 27 deletions public/js/employee/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
jQuery(document).ready(function($) {
$("#edit_modal").on('show.bs.modal', function(){
$("#create_modal").on('show.bs.modal', function(){
var employee_id = $("[name=id]").val();
});

$(document).on("click", ".btn-submit-modal", function (event) {
var $form = $(this).parents("form");
var url = $form.attr("action");

$.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: $form,
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});

});
});

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$scope.get = function ($argument) {
$scope.get = function ($argument = {}) {
var $form = $("#filter_form");
var url = "/api/employee";
var page = 1;
if($argument != undefined){
if(($argument["page"] == undefined) || ($argument["page"] == "") || ($argument["page"] == "undefined") || ($argument["page"] == null)){
}else{
page = $argument["page"];
}

}

var params = {
page:page,
id:$($form).find("[name=id]").val(),
firstname:$($form).find("[name=firstname]").val(),
lastname:$($form).find("[name=lastname]").val(),
Expand All @@ -40,6 +29,9 @@ app.controller('myCtrl', function($scope, $http) {
salary:$($form).find("[name=salary]").val(),
birthday:$($form).find("[name=birthday]").val(),
};

params = objectAttributeFilter(params);

// console.log("params");
// console.log(params);
var config = {
Expand Down Expand Up @@ -75,14 +67,171 @@ app.controller('myCtrl', function($scope, $http) {
// pagination(app, $argument);
}

$scope.loadData = function(page, keyword){
$scope.get();
$scope.loadData = function(page){
$scope.get({page:page});
};

$scope.reset = function(){
var $form = $("#filter_form");
$form.trigger("reset");
$scope.get();
};

$scope.store = function () {
var $form = $("#create_form");
var url = "/api/employee";
$form.attr("action", url);

var params = {
_method : 'POST',
id : $($form).find("[name=id]").val(),
_token : $($form).find("[name=_token]").val(),
firstname : $($form).find("[name=firstname]").val(),
lastname : $($form).find("[name=lastname]").val(),
address : $($form).find("[name=address]").val(),
boss : $($form).find("[name=boss]").val(),
salary : $($form).find("[name=salary]").val(),
birthday : $($form).find("[name=birthday]").val(),
};

params = objectAttributeFilter(params);
$http.post(url, JSON.stringify(params))
.then(
function($response) { // 成功
$scope.get();

$form.trigger("reset");

}, function ($response) { // エラー発生
}
);

// pagination(app, $argument);
}

$scope.edit = function (id) {
var url = "/api/employee/" + id;

$http.get(url)
.then(
function($response) { // 成功
var $form = $("#edit_modal");
$form.find("[name=id]").val($response.data.id);
$form.find("[name=firstname]").val($response.data.firstname);
$form.find("[name=lastname]").val($response.data.lastname);
$form.find("[name=boss]").val($response.data.boss);
$form.find("[name=address]").val($response.data.address);
$form.find("[name=birthday]").val($response.data.birthday);
$form.find("[name=salary]").val($response.data.salary);

}, function ($response) { // エラー発生
}
);

}

$scope.update = function () {
var $form = $("#edit_form");
var id = $($form).find("[name=id]").val();
var url = "/api/employee/" + id;
$form.attr("action", url);

var params = {
_method : 'PUT',
_token : $($form).find("[name=_token]").val(),
firstname : $($form).find("[name=firstname]").val(),
lastname : $($form).find("[name=lastname]").val(),
address : $($form).find("[name=address]").val(),
boss : $($form).find("[name=boss]").val(),
salary : $($form).find("[name=salary]").val(),
birthday : $($form).find("[name=birthday]").val(),
};

params = objectAttributeFilter(params);

// console.log("params");
// console.log(params);

$http.post(url, JSON.stringify(params))
.then(
function($response) { // 成功
$scope.get();

$form.trigger("reset");

}, function ($response) { // エラー発生
}
);

pagination(app);
}

$scope.deleteModelOpen = function (id) {
var $form = $("#delete_modal");
$($form).find("[name=id]").val(id);

}

$scope.delete = function () {
var $form = $("#delete_modal");
var id = $($form).find("[name=id]").val();
var url = "/api/employee/" + id;
$form.attr("action", url);

var params = {
_method : 'DELETE',
_token : $($form).find("[name=_token]").val(),
};

params = objectAttributeFilter(params);

$http.post(url, JSON.stringify(params))
.then(
function($response) { // 成功
$scope.get();

}, function ($response) { // エラー発生
}
);

pagination(app);
}

$scope.get();

// $http.get("customers.php")
// .then(function (response) {$scope.names = response.data.records;});

});

pagination(app);

function objectAttributeFilter(obj) {
for (var propName in obj) {
if (obj[propName] == "" || obj[propName] == null || obj[propName] == "undefined") {
delete obj[propName];
}
}

return obj;
}

function pagination(app) {
app.directive('listPagination', function(){
template =
'<div ng-show="last_page > 1">'
+ '<ul class="pagination justify-content-center">'
+ '<li class="page-item" ng-show="1 < current_page"><a class="page-link" href="javascript:void(0)" ng-click="loadData(1)">&laquo;</a></li>'
+ '<li class="page-item" ng-show="1 < current_page"><a class="page-link" href="javascript:void(0)" ng-click="loadData(current_page-1)">&lsaquo;</a></li>'
+ '<li class="page-item" ng-repeat="i in range" ng-class="{active : current_page == i}">'
+ ' <a class="page-link" href="javascript:void(0)" ng-click="loadData(i)">{{i}}</a>'
+ '</li>'
+ '<li class="page-item" ng-show="current_page < last_page"><a class="page-link" href="javascript:void(0)" ng-click="loadData(current_page+1)">&rsaquo;</a></li>'
+ '<li class="page-item" ng-show="current_page < last_page"><a class="page-link" href="javascript:void(0)" ng-click="loadData(last_page)">&raquo;</a></li>'
+ '</ul>'
+ '</div>'
;
return {
restrict: 'E',
template: template
};
});
}
3 changes: 2 additions & 1 deletion resources/views/_include/footer.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<footer class="container">
<a href="https://coxanh.coupon-pon.net/about" target="_blank">NGUYEN NGOC NAM</a>
<a href=""><i class="fas fa-home"></i></a> |
<a href="https://coxanh.coupon-pon.net/about" target="_blank"><i class="fas fa-info"></i> NGUYEN NGOC NAM</a>
</footer>
2 changes: 1 addition & 1 deletion resources/views/_include/header.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<header class="container">
<h1>EMPLOYEE SYSTEM</h1>
<h1 class="text-center">EMPLOYEE SYSTEM</h1>
</header>
Loading

0 comments on commit f33e32d

Please sign in to comment.