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, $
"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;';
// <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 = {
......@@ -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'}
]
};
$scope.gridOptions.data = $scope.records;
$scope.gridOptionsOrgView = {
paginationPageSizes : [ 10, 20, 30, 40, 50, 100],
......@@ -108,6 +110,12 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
else{
$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;
}, function myError(response) {
showAlert("Something went wrong while fetching data!!!");
......@@ -490,7 +498,7 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
$scope.alertMsg = "";
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,
"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,
"b1ExpiryDate":$scope.b1ExpiryDate, "endDate":$scope.exitDate
};
......@@ -499,12 +507,15 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
$timeout(function(){updateGrid($scope.templateTitle, record)},500);
}
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,
"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);
$timeout(function(){updateGrid($scope.templateTitle, record)},500);
}
......@@ -522,96 +533,70 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
$scope.errorMessage = true;
};
isDataUpdated = function(){
if(dataToPass.action=="Update"){
console.log(dataToPass);
$scope.previousData={
EmpId:dataToPass.employeeId,
EmpName:dataToPass.employeeName,
Gender:dataToPass.gender,
Email:dataToPass.emailId,
EmploymentStatus:dataToPass.empStatus,
Role:dataToPass.role,
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;
objectConstructionBasedOnParameters = function(obj){
if(obj.hasB1 != "Yes"){
delete obj['b1ExpiryDate'];
}
if(obj.hasPassort != "Yes"){
delete obj['passportExpiryDate'];
}
if(obj.empStatus == "Active"){
delete obj['endDate'];
}
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() {
var showConfirmDialog = false;
if(dataToPass.action=="Update"){
if(isDataUpdated() != true){
$mdDialog.hide('Cancelled');
}
else{
$mdDialog.show($mdDialog.confirm({
skipHide: true,
textContent: 'Are you sure you want to cancel this?',
ok: 'ok',
cancel:'cancel'
})).then(function(){
$mdDialog.hide('Cancelled');
})
}
}
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,
"empStatus": $scope.empStatus,"employmentType": $scope.employmentType,"dateOfJoining":$scope.dateOfJoining,
"dateOfBirth":$scope.dateOfBirth,"hasPassort":$scope.hasPassort,"hasB1":$scope.hasB1,"passportExpiryDate":$scope.passportExpiryDate,
"b1ExpiryDate":$scope.b1ExpiryDate, "endDate":$scope.exitDate
};
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,
"empStatus": dataToPass.empStatus,"employmentType": dataToPass.employmentType,"dateOfJoining":new Date(dataToPass.dateOfJoining),
"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)
};
objectConstructionBasedOnParameters(recordFromDb);
objectConstructionBasedOnParameters(record);
if(dataToPass.action=="Add"){
var totalFields = $scope.myForm.$$controls;
for (key in totalFields) {
console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue)
if(totalFields[key].$modelValue !== '' && totalFields[key].$modelValue !== undefined) {
console.log("Came here!");
showConfirmDialog = true;
var employeeForm = myFactory.addFormDataCheck($scope.myForm);
if(Object.keys(employeeForm).length == 0){
$mdDialog.hide('Cancelled');
}
else{
confirmationMsg();
}
}
if(showConfirmDialog){
$mdDialog.show($mdDialog.confirm({
skipHide: true,
textContent: 'Are you sure you want to cancel this?',
ok: 'ok',
cancel:'cancel'
})).then(function(){
$mdDialog.hide('Cancelled');
})
else if(dataToPass.action=="Update"){
if(myFactory.updateFormDataCheck(record,recordFromDb) != true){
$mdDialog.hide('Cancelled');
}
else{
$mdDialog.hide('Cancelled');
confirmationMsg();
}
}
};
};
function updateGrid(action, record){
if($scope.alertMsg == ""){
if($scope.result == "Success"){
......
......@@ -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>' +
'&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>'
......
......@@ -209,8 +209,16 @@ myApp.factory('myFactory', function() {
}
function updateFormDataCheck(form,record){
var updatedForm = addFormDataCheck(form);
var sortedUpdatedForm = sortObjectBasedOnKeys(updatedForm);
var updatedForm;
var sortedUpdatedForm;
if(Array.isArray(form.$$controls)){
updatedForm = addFormDataCheck(form);
sortedUpdatedForm = sortObjectBasedOnKeys(updatedForm);
}
else{
sortedUpdatedForm = sortObjectBasedOnKeys(form);
}
var sortedRecord = sortObjectBasedOnKeys(record);
if(JSON.stringify(sortedUpdatedForm) == JSON.stringify(sortedRecord)){
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