Unverified Commit 5d6cd3ed authored by mshaik-nisum-com's avatar mshaik-nisum-com Committed by GitHub

Merge pull request #158 from nisum-inc/FEATURE/REFACTOR_AND_BUG_FIX

refactored the manage employee and few bug fixes
parents 73b00024 75fff52c
...@@ -11,7 +11,7 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $ ...@@ -11,7 +11,7 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
"passportExpiryDate":"" "passportExpiryDate":""
}; };
var getCellTemplate = '<p class="col-lg-12"><i class="fa fa-pencil-square-o fa-2x" aria-hidden="true" style="font-size:1.5em;margin-top:3px;cursor:pointer;" ng-click="grid.appScope.getRowData(row,\'Update\')"></i>'+ var getCellTemplate = '<p ng-show="row.entity.empStatus == \'Active\'" class="col-lg-12"><i class="fa fa-pencil-square-o fa-2x" aria-hidden="true" style="font-size:1.5em;margin-top:3px;cursor:pointer;" ng-click="grid.appScope.getRowData(row,\'Update\')"></i>'+
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
// <i class="fa fa-minus-circle fa-2x" aria-hidden="true" style="font-size:1.5em;margin-top:3px;cursor:pointer;" ng-click="grid.appScope.getRowData(row,\'Delete\')"></i></p> // <i class="fa fa-minus-circle fa-2x" aria-hidden="true" style="font-size:1.5em;margin-top:3px;cursor:pointer;" ng-click="grid.appScope.getRowData(row,\'Delete\')"></i></p>
$scope.gridOptions = { $scope.gridOptions = {
...@@ -30,6 +30,8 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $ ...@@ -30,6 +30,8 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
{name : 'Actions', displayName: 'Actions',cellTemplate: getCellTemplate, enableColumnMenu: false, enableSorting: false,enableFiltering: false, width:100,cellClass: 'grid-align'} {name : 'Actions', displayName: 'Actions',cellTemplate: getCellTemplate, enableColumnMenu: false, enableSorting: false,enableFiltering: false, width:100,cellClass: 'grid-align'}
] ]
}; };
$scope.gridOptions.data = $scope.records; $scope.gridOptions.data = $scope.records;
$scope.gridOptionsOrgView = { $scope.gridOptionsOrgView = {
paginationPageSizes : [ 10, 20, 30, 40, 50, 100], paginationPageSizes : [ 10, 20, 30, 40, 50, 100],
...@@ -108,6 +110,12 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $ ...@@ -108,6 +110,12 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
else{ else{
$scope.gridOptions.enablePaginationControls = false; $scope.gridOptions.enablePaginationControls = false;
} }
if($scope.status == "In Active"){
$scope.gridOptions.columnDefs[6].visible = false;
}
else{
$scope.gridOptions.columnDefs[6].visible = true;
}
$scope.gridOptions.data = response.data; $scope.gridOptions.data = response.data;
}, function myError(response) { }, function myError(response) {
showAlert("Something went wrong while fetching data!!!"); showAlert("Something went wrong while fetching data!!!");
...@@ -490,7 +498,7 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $ ...@@ -490,7 +498,7 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
$scope.alertMsg = ""; $scope.alertMsg = "";
var record = {"employeeId":$scope.empId, "employeeName": $scope.empName, "gender": $scope.gender,"emailId": $scope.empEmail, var record = {"employeeId":$scope.empId, "employeeName": $scope.empName, "gender": $scope.gender,"emailId": $scope.empEmail,
"role": $scope.empRole, "empLocation": $scope.empLocation,"designation": $scope.designation,"functionalGroup": $scope.functionalGroup, "role": $scope.empRole, "empLocation": $scope.empLocation,"designation": $scope.designation,"functionalGroup": $scope.functionalGroup,
"empStatus": $scope.empStatus,"employmentType": $scope.employmentType,"domain": $scope.domain,"dateOfJoining":$scope.dateOfJoining, "empStatus": $scope.empStatus,"employmentType": $scope.employmentType,"dateOfJoining":$scope.dateOfJoining,
"dateOfBirth":$scope.dateOfBirth,"hasPassort":$scope.hasPassort,"hasB1":$scope.hasB1,"passportExpiryDate":$scope.passportExpiryDate, "dateOfBirth":$scope.dateOfBirth,"hasPassort":$scope.hasPassort,"hasB1":$scope.hasB1,"passportExpiryDate":$scope.passportExpiryDate,
"b1ExpiryDate":$scope.b1ExpiryDate, "endDate":$scope.exitDate "b1ExpiryDate":$scope.b1ExpiryDate, "endDate":$scope.exitDate
}; };
...@@ -499,12 +507,15 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $ ...@@ -499,12 +507,15 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
$timeout(function(){updateGrid($scope.templateTitle, record)},500); $timeout(function(){updateGrid($scope.templateTitle, record)},500);
} }
else{ else{
var dbRecord = {"employeeId":dataToPass.employeeId, "employeeName": dataToPass.employeeName, "gender": dataToPass.gender,"emailId": dataToPass.emailId, var recordFromDb = {"employeeId":dataToPass.employeeId, "employeeName": dataToPass.employeeName, "gender": dataToPass.gender,"emailId": dataToPass.emailId,
"role": dataToPass.role, "empLocation": dataToPass.empLocation,"designation": dataToPass.designation,"functionalGroup": dataToPass.functionalGroup, "role": dataToPass.role, "empLocation": dataToPass.empLocation,"designation": dataToPass.designation,"functionalGroup": dataToPass.functionalGroup,
"empStatus": dataToPass.empStatus,"employmentType": dataToPass.employmentType,"dateOfJoining":new Date(dataToPass.dateOfJoining), "empStatus": dataToPass.empStatus,"employmentType": dataToPass.employmentType,"dateOfJoining":new Date(dataToPass.dateOfJoining),
"dateOfBirth":new Date(dataToPass.dateOfBirth),"hasPassort":dataToPass.hasPassort,"hasB1":dataToPass.hasB1 "dateOfBirth":new Date(dataToPass.dateOfBirth),"hasPassort":dataToPass.hasPassort,"hasB1":dataToPass.hasB1,"passportExpiryDate":new Date(dataToPass.passportExpiryDate),
"b1ExpiryDate":new Date(dataToPass.b1ExpiryDate), "endDate":new Date(dataToPass.endDate)
}; };
if(myFactory.updateFormDataCheck($scope.myForm,dbRecord)){ objectConstructionBasedOnParameters(recordFromDb);
objectConstructionBasedOnParameters(record);
if(myFactory.updateFormDataCheck(record,recordFromDb)){
addOrUpdateRole(record, $scope.templateTitle); addOrUpdateRole(record, $scope.templateTitle);
$timeout(function(){updateGrid($scope.templateTitle, record)},500); $timeout(function(){updateGrid($scope.templateTitle, record)},500);
} }
...@@ -522,96 +533,70 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $ ...@@ -522,96 +533,70 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
$scope.errorMessage = true; $scope.errorMessage = true;
}; };
isDataUpdated = function(){ objectConstructionBasedOnParameters = function(obj){
if(dataToPass.action=="Update"){ if(obj.hasB1 != "Yes"){
console.log(dataToPass); delete obj['b1ExpiryDate'];
$scope.previousData={ }
EmpId:dataToPass.employeeId,
EmpName:dataToPass.employeeName, if(obj.hasPassort != "Yes"){
Gender:dataToPass.gender, delete obj['passportExpiryDate'];
Email:dataToPass.emailId, }
EmploymentStatus:dataToPass.empStatus, if(obj.empStatus == "Active"){
Role:dataToPass.role, delete obj['endDate'];
Designation:dataToPass.designation,
WorkLocation:dataToPass.empLocation,
EmploymentType:dataToPass.employmentType,
FunctionalGroup:dataToPass.functionalGroup,
HasPassport:dataToPass.hasPassort,
HasB1Visa:dataToPass.hasB1,
Dateofjoining: (dataToPass.dateOfJoining == null ) ? null : new Date(dataToPass.dateOfJoining),
DateofBirth: (dataToPass.dateOfBirth == null ) ? null : new Date(dataToPass.dateOfBirth),
passportExpiryDate: (dataToPass.passportExpiryDate == null )? null :new Date(dataToPass.passportExpiryDate) ,
b1ExpiryDate: (dataToPass.b1ExpiryDate == null )? null :new Date(dataToPass.b1ExpiryDate)
}
$scope.currentData={
EmpId: $scope.empId,
EmpName:$scope.empName,
Gender:$scope.gender,
Email:$scope.empEmail,
EmploymentStatus:$scope.empStatus,
Role:$scope.empRole,
Designation:$scope.designation,
WorkLocation:$scope.empLocation,
EmploymentType:$scope.employmentType,
FunctionalGroup:$scope.functionalGroup,
HasPassport:$scope.hasPassort,
HasB1Visa:$scope.hasB1,
Dateofjoining:$scope.dateOfJoining,
DateofBirth:$scope.dateOfBirth,
passportExpiryDate: $scope.passportExpiryDate,
b1ExpiryDate: $scope.b1ExpiryDate,
}
var predata=JSON.stringify($scope.previousData);
var curdata=JSON.stringify($scope.currentData);
if(predata == curdata){
return false;
} }
return true; return obj;
} }
}
var confirmationMsg = function(){
$mdDialog.show($mdDialog.confirm({
skipHide: true,
textContent: 'Are you sure you want to cancel this?',
ok: 'ok',
cancel: 'cancel'
})).then(function () {
$mdDialog.hide('Cancelled');
})
}
$scope.cancel = function() { $scope.cancel = function() {
var showConfirmDialog = false; var record = {
if(dataToPass.action=="Update"){ "employeeId":$scope.empId, "employeeName": $scope.empName, "gender": $scope.gender,"emailId": $scope.empEmail,
if(isDataUpdated() != true){ "role": $scope.empRole, "empLocation": $scope.empLocation,"designation": $scope.designation,"functionalGroup": $scope.functionalGroup,
$mdDialog.hide('Cancelled'); "empStatus": $scope.empStatus,"employmentType": $scope.employmentType,"dateOfJoining":$scope.dateOfJoining,
} "dateOfBirth":$scope.dateOfBirth,"hasPassort":$scope.hasPassort,"hasB1":$scope.hasB1,"passportExpiryDate":$scope.passportExpiryDate,
else{ "b1ExpiryDate":$scope.b1ExpiryDate, "endDate":$scope.exitDate
$mdDialog.show($mdDialog.confirm({ };
skipHide: true, var recordFromDb = {
textContent: 'Are you sure you want to cancel this?', "employeeId":dataToPass.employeeId, "employeeName": dataToPass.employeeName, "gender": dataToPass.gender,"emailId": dataToPass.emailId,
ok: 'ok', "role": dataToPass.role, "empLocation": dataToPass.empLocation,"designation": dataToPass.designation,"functionalGroup": dataToPass.functionalGroup,
cancel:'cancel' "empStatus": dataToPass.empStatus,"employmentType": dataToPass.employmentType,"dateOfJoining":new Date(dataToPass.dateOfJoining),
})).then(function(){ "dateOfBirth":new Date(dataToPass.dateOfBirth),"hasPassort":dataToPass.hasPassort,"hasB1":dataToPass.hasB1,"passportExpiryDate":new Date(dataToPass.passportExpiryDate),
$mdDialog.hide('Cancelled'); "b1ExpiryDate":new Date(dataToPass.b1ExpiryDate), "endDate":new Date(dataToPass.endDate)
}) };
} objectConstructionBasedOnParameters(recordFromDb);
} objectConstructionBasedOnParameters(record);
if(dataToPass.action=="Add"){ if(dataToPass.action=="Add"){
var totalFields = $scope.myForm.$$controls; var employeeForm = myFactory.addFormDataCheck($scope.myForm);
for (key in totalFields) { if(Object.keys(employeeForm).length == 0){
console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue) $mdDialog.hide('Cancelled');
if(totalFields[key].$modelValue !== '' && totalFields[key].$modelValue !== undefined) { }
console.log("Came here!"); else{
showConfirmDialog = true; confirmationMsg();
} }
} }
if(showConfirmDialog){ else if(dataToPass.action=="Update"){
$mdDialog.show($mdDialog.confirm({ if(myFactory.updateFormDataCheck(record,recordFromDb) != true){
skipHide: true, $mdDialog.hide('Cancelled');
textContent: 'Are you sure you want to cancel this?',
ok: 'ok',
cancel:'cancel'
})).then(function(){
$mdDialog.hide('Cancelled');
})
} }
else{ else{
$mdDialog.hide('Cancelled'); confirmationMsg();
} }
} }
};
};
function updateGrid(action, record){ function updateGrid(action, record){
if($scope.alertMsg == ""){ if($scope.alertMsg == ""){
if($scope.result == "Success"){ if($scope.result == "Success"){
......
...@@ -34,7 +34,7 @@ myApp.controller("projectController", function ($scope, myFactory, exportUiGridS ...@@ -34,7 +34,7 @@ myApp.controller("projectController", function ($scope, myFactory, exportUiGridS
var getCellTemplate = '<p class="col-lg-12"><i class="fa fa-users fa-2x" aria-hidden="true" style="font-size:1.4em;margin-top:3px;cursor:pointer;" data-placement="center" title="View" onmouseenter="$(this).tooltip(\'show\')" ng-click="grid.appScope.getRowData(row,\'View\')" ></i>' + var getCellTemplate = '<p class="col-lg-12"><i class="fa fa-users fa-2x" aria-hidden="true" style="font-size:1.4em;margin-top:3px;cursor:pointer;" data-placement="center" title="View" onmouseenter="$(this).tooltip(\'show\')" ng-click="grid.appScope.getRowData(row,\'View\')" ></i>' +
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i ng-show="row.entity.projectName != \'Bench\'" class="fa fa-pencil-square-o fa-2x" aria-hidden="true" style="font-size:1.5em;margin-top:3px;cursor:pointer;" data-placement="center" title="Edit" onmouseenter="$(this).tooltip(\'show\')" ng-click="grid.appScope.getRowData(row,\'Update\')"></i></p>' ; '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i ng-show="row.entity.projectName == \'Bench\'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</i><i ng-show="row.entity.projectName != \'Bench\'" class="fa fa-pencil-square-o fa-2x" aria-hidden="true" style="font-size:1.5em;margin-top:3px;cursor:pointer;" data-placement="center" title="Edit" onmouseenter="$(this).tooltip(\'show\')" ng-click="grid.appScope.getRowData(row,\'Update\')"></i></p>' ;
// '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i class="fa fa-minus-circle fa-2x" aria-hidden="true" style="font-size:1.5em;margin-top:3px;cursor:pointer;" data-placement="left" title="Delete" onmouseenter="$(this).tooltip(\'show\')" ng-click="grid.appScope.getRowData(row,\'Delete\')"></i></p>' // '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i class="fa fa-minus-circle fa-2x" aria-hidden="true" style="font-size:1.5em;margin-top:3px;cursor:pointer;" data-placement="left" title="Delete" onmouseenter="$(this).tooltip(\'show\')" ng-click="grid.appScope.getRowData(row,\'Delete\')"></i></p>'
......
...@@ -209,8 +209,16 @@ myApp.factory('myFactory', function() { ...@@ -209,8 +209,16 @@ myApp.factory('myFactory', function() {
} }
function updateFormDataCheck(form,record){ function updateFormDataCheck(form,record){
var updatedForm = addFormDataCheck(form); var updatedForm;
var sortedUpdatedForm = sortObjectBasedOnKeys(updatedForm); var sortedUpdatedForm;
if(Array.isArray(form.$$controls)){
updatedForm = addFormDataCheck(form);
sortedUpdatedForm = sortObjectBasedOnKeys(updatedForm);
}
else{
sortedUpdatedForm = sortObjectBasedOnKeys(form);
}
var sortedRecord = sortObjectBasedOnKeys(record); var sortedRecord = sortObjectBasedOnKeys(record);
if(JSON.stringify(sortedUpdatedForm) == JSON.stringify(sortedRecord)){ if(JSON.stringify(sortedUpdatedForm) == JSON.stringify(sortedRecord)){
return false; return false;
......
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