From d8f14f611aaaf7dc6796705d2bed5839eaad8f98 Mon Sep 17 00:00:00 2001 From: SamSys Date: Mon, 16 Sep 2024 20:34:57 +0330 Subject: [PATCH] camera ui changes - rollcall bug fixed --- .../RollCallEmployeeViewModel.cs | 3 + .../Repository/RollCallEmployeeRepository.cs | 8 +- .../Repository/RollCallRepository.cs | 4 +- ServiceHost/Areas/Camera/Pages/Index.cshtml | 27 +- .../Areas/Camera/Pages/Shared/_Layout.cshtml | 15 +- .../Pages/Shared/_validationAlert.cshtml | 45 ++ .../Camera/Pages/ViewPersonnelModal.cshtml | 36 +- .../Pages/Company/RollCall/CurrentDay.cshtml | 185 +++---- .../Company/RollCall/CurrentDay.cshtml.cs | 1 + .../RollCall/EmployeeUploadPicture.cshtml | 66 +-- .../RollCall/EmployeeUploadPicture.cshtml.cs | 84 ++- .../Company/RollCall/ModalTakeImages.cshtml | 53 +- .../wwwroot/AssetsCamera/css/Index.css | 2 +- ServiceHost/wwwroot/AssetsCamera/js/Index.js | 43 +- .../pages/RollCall/css/CurrentDay.css | 6 + .../pages/RollCall/css/ModalTakeImages.css | 16 + .../RollCall/js/EmployeeUploadPicture.js | 363 ++++++++++--- .../pages/RollCall/js/ModalTakeImages.js | 499 +++++++++++++----- 18 files changed, 1069 insertions(+), 387 deletions(-) create mode 100644 ServiceHost/Areas/Camera/Pages/Shared/_validationAlert.cshtml diff --git a/CompanyManagment.App.Contracts/RollCallEmployee/RollCallEmployeeViewModel.cs b/CompanyManagment.App.Contracts/RollCallEmployee/RollCallEmployeeViewModel.cs index 43f97c3d..0488d25d 100644 --- a/CompanyManagment.App.Contracts/RollCallEmployee/RollCallEmployeeViewModel.cs +++ b/CompanyManagment.App.Contracts/RollCallEmployee/RollCallEmployeeViewModel.cs @@ -31,4 +31,7 @@ public class RollCallEmployeeViewModel : EditRollCallEmployee public string EmployeeSlug { get; set; } public List PersonnelInfoViewModels { get; set; } public IEnumerable Statuses { get; set; } + + public string EmployeeLName { get; set; } + public string EmployeeFName { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs index 634317aa..b243830a 100644 --- a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs @@ -238,13 +238,15 @@ public class RollCallEmployeeRepository : RepositoryBase && x.IsActiveString == "true" && x.HasUploadedImage == "true"); var personnel = - _context.PersonnelCodeSet.Include(x => x.Employee).Where(x => rollCallEmployeeIdQuery.Any(y => y.EmployeeId == x.EmployeeId)); + _context.PersonnelCodeSet.Include(x => x.Employee).Where(x => rollCallEmployeeIdQuery.Any(y => y.EmployeeId == x.EmployeeId && y.WorkshopId == x.WorkshopId)); return personnel.Select(x => new RollCallEmployeeViewModel() { PersonelCode = x.PersonnelCode, - EmployeeFullName = $"{x.Employee.FName} {x.Employee.LName}", - }).ToList(); + EmployeeFName = x.Employee.FName, + EmployeeLName = x.Employee.LName + }).OrderBy(x => x.EmployeeLName).ToList(); + } diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index 7967a2d1..14f1b08c 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -319,7 +319,7 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var personnelCodeList = - _context.PersonnelCodeSet.Where(x => activeEmployeesQuery.Any(y => y.EmployeeId == x.EmployeeId)); + _context.PersonnelCodeSet.Where(x => activeEmployeesQuery.Any(y => y.EmployeeId == x.EmployeeId && y.WorkshopId == x.WorkshopId)); var rollCallsList = rollCallsQuery.ToList(); var activatedEmployeesList = activeEmployeesQuery.ToList(); var leavesList = leavesQuery.ToList(); @@ -462,7 +462,7 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var absentsViewModel = absentsQuery.Select(x => new AbsentEmployeeViewModel() { PersonnelCode = personnelCodes - .FirstOrDefault(y => y.EmployeeId == x.EmployeeId)? + .FirstOrDefault(y => y.EmployeeId == x.EmployeeId && y.WorkshopId == x.WorkshopId)? .PersonnelCode.ToString(), EmployeeId = x.EmployeeId, EmployeeFullName = x.EmployeeFullName, diff --git a/ServiceHost/Areas/Camera/Pages/Index.cshtml b/ServiceHost/Areas/Camera/Pages/Index.cshtml index 11c95b2f..a3d45134 100644 --- a/ServiceHost/Areas/Camera/Pages/Index.cshtml +++ b/ServiceHost/Areas/Camera/Pages/Index.cshtml @@ -37,7 +37,7 @@ .title-logo-mobile { font-size: 16px; font-weight: 700; - margin: 0 0 40px 0; + /* margin: 0 0 40px 0; */ } } @@ -47,8 +47,8 @@
-
@@ -75,7 +75,7 @@ -

خاموش

+

خاموش

@@ -136,9 +136,12 @@
-
- -
+
+ + + + +
@@ -285,10 +288,10 @@
*@ @section Script diff --git a/ServiceHost/Areas/Camera/Pages/Shared/_Layout.cshtml b/ServiceHost/Areas/Camera/Pages/Shared/_Layout.cshtml index a9aa9178..2d00f01b 100644 --- a/ServiceHost/Areas/Camera/Pages/Shared/_Layout.cshtml +++ b/ServiceHost/Areas/Camera/Pages/Shared/_Layout.cshtml @@ -1,4 +1,6 @@ - + + + @@ -12,7 +14,15 @@ + + + @RenderSection("Styles", false) @@ -39,8 +49,9 @@
+ - + @RenderSection("Script", false) diff --git a/ServiceHost/Areas/Camera/Pages/Shared/_validationAlert.cshtml b/ServiceHost/Areas/Camera/Pages/Shared/_validationAlert.cshtml new file mode 100644 index 00000000..8b8cb456 --- /dev/null +++ b/ServiceHost/Areas/Camera/Pages/Shared/_validationAlert.cshtml @@ -0,0 +1,45 @@ + + + + + + + \ No newline at end of file diff --git a/ServiceHost/Areas/Camera/Pages/ViewPersonnelModal.cshtml b/ServiceHost/Areas/Camera/Pages/ViewPersonnelModal.cshtml index 4043abb5..8d2b4ac5 100644 --- a/ServiceHost/Areas/Camera/Pages/ViewPersonnelModal.cshtml +++ b/ServiceHost/Areas/Camera/Pages/ViewPersonnelModal.cshtml @@ -8,12 +8,13 @@ .itemSection { display: flex; align-items: center; - justify-content: space-between; + /* justify-content: space-between; */ background-color: #253247; padding: 7px 5px; border-radius: 10px; margin: 5px 0; font-size: 13px; + gap: 10px; } .itemSection.header { @@ -56,6 +57,24 @@ width: 100%; color: #ffffff; } + + .employee-lname { + width: 50%; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + } + + .employee-name { + width: 30%; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + } + + .employee-code { + width: 20%; + } @@ -92,16 +111,18 @@
- نام پرسنل - کد پرسنل + نام خانوادگی پرسنل + نام پرسنل + کد پرسنل
@foreach (var item in Model) {
- @item.EmployeeFullName - @item.PersonelCode + @item.EmployeeLName + @item.EmployeeFName + @item.PersonelCode
}
@@ -121,10 +142,11 @@ $('#searchPersonnel').on('keyup', function() { var value = $(this).val().toLowerCase(); $('#employeeList .employee-item').filter(function() { - var employeeName = $(this).find('.employee-name').text().toLowerCase(); + var employeeFName = $(this).find('.employee-name').text().toLowerCase(); + var employeeLName = $(this).find('.employee-lname').text().toLowerCase(); var employeeCode = $(this).find('.employee-code').text().toLowerCase(); - if (employeeName.includes(value) || employeeCode.includes(value)) { + if (employeeFName.includes(value) || employeeLName.includes(value) || employeeCode.includes(value)) { $(this).show(); } else { $(this).hide(); diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/CurrentDay.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/CurrentDay.cshtml index 8cec90aa..b0c69421 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/CurrentDay.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/CurrentDay.cshtml @@ -46,11 +46,11 @@
-
+
-
+
ردیف
نام پرسنل
شماره پرسنلی
@@ -61,101 +61,102 @@
مجموع ساعات کاری
-
-
- @if (@Model.RollCallViewModels.PresentEmployees.Any()) + @if (@Model.RollCallViewModels.PresentEmployees.Any()) + { + @foreach (var item in Model.RollCallViewModels.PresentEmployees) { - @foreach (var item in Model.RollCallViewModels.PresentEmployees) - { -
-
-
- ردیف -
-
-
- @(index++) -
+
+
+
+ ردیف +
+
+
+ @(index++)
- -
-
نام پرسنل
-
- @item.EmployeeFullName -
-
- -
-
-
شماره پرسنلی:
-
@item.PersonnelCode
-
-
- -
-
-
تاخیر در ورود:
-
-
-
-
- -
- @foreach (var itemTime in item.RollCallTimesList) - { -
ساعت ورود
-
-
@(itemTime.StartDate ?? "-")
-
- } -
- -
- @foreach (var itemTime in item.RollCallTimesList) - { -
ساعت خروج
-
-
@(itemTime.EndDate ?? "-")
-
- } -
- -
-
-
تجمیع در خروج:
-
-
-
-
- -
-
-
مجموع ساعات کاری:
-
- @if (item.RollCallTimesList.Last().EndDate == null) - { - - - - - - - } - else - { - @item.TotalWorkingHours - } -
-
-
-
- } + +
+
نام پرسنل
+
+ @item.EmployeeFullName +
+
+ +
+
+
شماره پرسنلی:
+
@item.PersonnelCode
+
+
+ +
+
+
تاخیر در ورود:
+
-
+
+
+ +
+ @foreach (var itemTime in item.RollCallTimesList) + { +
ساعت ورود
+
+
@(itemTime.StartDate ?? "-")
+
+ } +
+ +
+ @foreach (var itemTime in item.RollCallTimesList) + { +
ساعت خروج
+
+
@(itemTime.EndDate ?? "-")
+
+ } +
+ +
+
+
تجمیع در خروج:
+
-
+
+
+ +
+
+
مجموع ساعات کاری:
+
+ @if (item.RollCallTimesList.Last().EndDate == null) + { + + + + + + + } + else + { + @item.TotalWorkingHours + } +
+
+
+ +
} - else - { - - } -
+ } + else + { + + } + @*
+
+ +
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/CurrentDay.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/RollCall/CurrentDay.cshtml.cs index 65fa2d3d..f7bd4896 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/CurrentDay.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/CurrentDay.cshtml.cs @@ -68,6 +68,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall } + public IActionResult OnGetCurrentDayAjax(string type) { var workshopHash = User.FindFirstValue("WorkshopSlug"); diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/EmployeeUploadPicture.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/EmployeeUploadPicture.cshtml index dedaeffa..8eac9a81 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/EmployeeUploadPicture.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/EmployeeUploadPicture.cshtml @@ -68,20 +68,20 @@
-
+
-

تعداد پرسنل سرویس خریداری شده: @(Model.MaxPersonValid == -1 ? "نامحدود" : Model.MaxPersonValid)

+

تعداد پرسنل سرویس خریداری شده:

-

تعداد افراد فعال: @Model.Employees.PersonnelInfoViewModels.Count(x => x.IsActiveString == "true")

+

تعداد افراد فعال:

-

تعداد افراد غیرفعال: @Model.Employees.PersonnelInfoViewModels.Count(x => x.IsActiveString == "false")

+

تعداد افراد غیرفعال:

@@ -90,7 +90,7 @@
@if (@Model.HasEmployees) { -
+
ردیف
نام و نام خانوادگی
@@ -145,21 +145,20 @@
- @if (item.IsActiveString == "true") - { - - } - else - { - + @{ + var isActive = item.IsActiveString == "true" ? "deactive" : "active"; } + -
@@ -201,20 +200,18 @@
+ + - @if (item.IsActiveString == "true") - { - - } - else - { - - }
@@ -240,6 +237,8 @@
+ + *@
- *@
@@ -178,5 +215,7 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/ServiceHost/wwwroot/AssetsCamera/css/Index.css b/ServiceHost/wwwroot/AssetsCamera/css/Index.css index 9dbde0eb..34a885b7 100644 --- a/ServiceHost/wwwroot/AssetsCamera/css/Index.css +++ b/ServiceHost/wwwroot/AssetsCamera/css/Index.css @@ -518,7 +518,7 @@ canvas { } } - +/* ----------------------------------------------------------------------------------------- Responsive */ @media (min-width: 680px) { .cameraSection { width: 650px; diff --git a/ServiceHost/wwwroot/AssetsCamera/js/Index.js b/ServiceHost/wwwroot/AssetsCamera/js/Index.js index 729e1464..2671c2d8 100644 --- a/ServiceHost/wwwroot/AssetsCamera/js/Index.js +++ b/ServiceHost/wwwroot/AssetsCamera/js/Index.js @@ -1,5 +1,4 @@ - -$(document).ready(function () { +$(document).ready(function () { if ($(window).width() > 992) { $('#desktopDisplay').show(); $('#mobileDisplay').hide(); @@ -473,17 +472,25 @@ function out(flagId) { success: function (response) { if (response.isSuccess) { // $.Notification.autoHideNotify('success', 'top center', 'پیام سیستم ', "خروج شما ثبت شد"); - alert("خروج شما ثبت شد"); + $('.alert-success-msg').show(); + $('.alert-success-msg p').text('خروج شما ثبت شد'); + setTimeout(function () { + $('.alert-success-msg').hide(); + $('.alert-success-msg p').text(''); + }, 1500); roloadAgain(); } else { - // $.Notification.autoHideNotify('error', 'top center', 'پیام سیستم ', "خطا در ثبت اطلاعات"); - alert("خطا در ثبت اطلاعات"); + $('.alert-msg').show(); + $('.alert-msg p').text('خطا در ثبت اطلاعات'); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + }, 1500); } }, failure: function (response) { console.log(5, response); - } }); } @@ -501,18 +508,26 @@ function inCom(employeeId) { success: function (response) { if (response.isSuccess) { // $.Notification.autoHideNotify('success', 'top center', 'پیام سیستم ', "ورود شما ثبت شد"); - alert("ورود شما ثبت شد"); + $('.alert-success-msg').show(); + $('.alert-success-msg p').text('ورود شما ثبت شد'); + setTimeout(function () { + $('.alert-success-msg').hide(); + $('.alert-success-msg p').text(''); + }, 1500); roloadAgain(); } else { // $.Notification.autoHideNotify('error', 'top center', 'پیام سیستم ', "خطا در ثبت اطلاعات"); - alert("خطا در ثبت اطلاعات"); - + $('.alert-msg').show(); + $('.alert-msg p').text('خطا در ثبت اطلاعات'); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + }, 1500); } }, failure: function (response) { console.log(5, response); - } }); } @@ -521,11 +536,6 @@ function inCom(employeeId) { // ------------------------------------------------------------- keyboard number $(document).ready(function () { - //const androidUserAgentString = window.navigator.userAgent.slice(window.navigator.userAgent.indexOf("Android")); - //const androidDeviceName = androidUserAgentString.slice(androidUserAgentString.indexOf("; ") + 1, androidUserAgentString.indexOf(")")); - //console.log(androidDeviceName); - - $('#errorMessage').text(androidUserAgentString); $('.keypad-numbers .item').click(function () { let number = $(this).text().trim(); @@ -554,6 +564,7 @@ function enterPersonnelCode() { if (code === "") { $('#errorMessage').text('کد پرسنلی خود را وارد کنید.'); } else { + $('#errorMessage').text(''); sendPersonelCodeToGetEmployeeId(code); } } @@ -561,4 +572,4 @@ function enterPersonnelCode() { function openPersonnelModal() { var goTo = `#showmodal=/Camera/Index?handler=PersonnelWorkshopAjax`; window.location.href = goTo; -} \ No newline at end of file +} diff --git a/ServiceHost/wwwroot/AssetsClient/pages/RollCall/css/CurrentDay.css b/ServiceHost/wwwroot/AssetsClient/pages/RollCall/css/CurrentDay.css index d74badbb..3499a12f 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/RollCall/css/CurrentDay.css +++ b/ServiceHost/wwwroot/AssetsClient/pages/RollCall/css/CurrentDay.css @@ -46,3 +46,9 @@ bottom: -10px; right: 20px; } + +.sticky { + position: sticky; + top: 0; + z-index: 10; +} diff --git a/ServiceHost/wwwroot/AssetsClient/pages/RollCall/css/ModalTakeImages.css b/ServiceHost/wwwroot/AssetsClient/pages/RollCall/css/ModalTakeImages.css index 86bb07e8..b61f01cf 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/RollCall/css/ModalTakeImages.css +++ b/ServiceHost/wwwroot/AssetsClient/pages/RollCall/css/ModalTakeImages.css @@ -147,3 +147,19 @@ video { height: 100% !important; object-fit: cover !important; } + +.loadingImage { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + z-index: 5; + background: #75ffff99; + width: 100%; + height: 100%; + display: flex; + align-items: center; + justify-content: center; + border-radius: 10px; + display: none; +} \ No newline at end of file diff --git a/ServiceHost/wwwroot/AssetsClient/pages/RollCall/js/EmployeeUploadPicture.js b/ServiceHost/wwwroot/AssetsClient/pages/RollCall/js/EmployeeUploadPicture.js index 8e7ac01b..a7976ea5 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/RollCall/js/EmployeeUploadPicture.js +++ b/ServiceHost/wwwroot/AssetsClient/pages/RollCall/js/EmployeeUploadPicture.js @@ -3,9 +3,218 @@ var button = $(this); var loadingDiv = button.find('.loading'); loadingDiv.show(); - }); + }); + + $('.desktop-btn, .mobile-btn').on('click', function () { + var id = $(this).attr('id').split('_')[1]; + var isActive = $(this).hasClass('btn-deactive') ? 'deactive' : 'active'; + togglePersonnelStatus(id, isActive); + }); + + loadInfoCount(); }); +function loadDataAjax() { + let pageIndex = Number($('#pageIndex').val()); + var b = pageIndex % 30; + var html = ''; + + console.log(pageIndex); + + if (b === 0 && pageIndex > 0) { + $.ajax({ + async: false, + contentType: 'charset=utf-8', + dataType: 'json', + type: 'GET', + url: loadEmployeeUploadDataAjax, + data: { + pageIndex: pageIndex + }, + headers: { "RequestVerificationToken": `${antiForgeryToken}` }, + success: function (response) { + if (response.pageIndex > 0) { + var n = pageIndex + 1; + var dataLoad = response.data.personnelInfoViewModels; + + dataLoad.forEach(function(item) { + html += ` + +
+ +
+
+ ردیف +
+
+ + ${n} + +
+
+
+
نام و نام خانوادگی
+
`; + + if (item.hasUploadedImage === "true") { + html += ``; + } + else + { + html += ``; + } + html += `${item.employeeFullName} +
+
+
+
کد ملی
+
${item.nationalCode}
+
+
+
وضعیت عکس
+
`; + if (item.hasUploadedImage === "true") { + html += `

عکس پرسنل آپلود شده است

`; + } + else { + html += `

عکس پرسنل آپلود نشده است

`; + } + html += `
+
+
+
`; + var isActive = item.isActiveString === "true" ? "deactive" : "active"; + html += ` + + +
+
+ + +
+
+
+ + ${n} + +
+
+ `; + if (item.hasUploadedImage === "true") { + html += ``; + } + else { + html += ``; + } + html += ` +
+
+
@item.EmployeeFullName
+
`; + if (item.hasUploadedImage === "true") { + html += `

عکس پرسنل آپلود شده است

`; + } + else { + html += `

عکس پرسنل آپلود نشده است

`; + } + html += `
+
+
+
+
+
+ + + +
+
+
+
+
`; + n += 1; + }); + + $('#ajaxDataLoad').append(html); + var newPageIndex = pageIndex + response.pageIndex; + $('#pageIndex').val(newPageIndex); + } + }, + failure: function (response) { + console.log(5, response); + } + }); + } +} + +$('.goToTop').on('click', function () { + $('html, body').animate({ scrollTop: 0 }, 360); + return false; +}); + +$(window).scroll(function () { + if ($(window).scrollTop() + $(window).height() > $(document).height() - 600) { + loadDataAjax(); + } + + if ($(this).scrollTop() > 100) { + $('.goToTop').show().fadeIn(); + } else { + $('.goToTop').fadeOut().hide(); + } +}); + +function loadInfoCount() { + $.ajax({ + async: false, + dataType: 'json', + url: loadInfoCountAjax, + type: 'GET', + success: function (response) { + if (response.isSuccedded) { + $('#maxPersonValid').text(response.maxPersonValid); + $('#isTrueActiveCount').text(response.isTrueActiveCount); + $('#isFalseActiveCount').text(response.isFalseActiveCount); + } else { + $('.alert-msg').show(); + $('.alert-msg p').text(response.message); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + }, 3500); + } + }, + error: function (err) { + console.log(err); + } + }); + +} + function ModalUploadPics(employeeID) { $.ajax({ @@ -31,76 +240,86 @@ function ModalUploadPics(employeeID) }); } -function deactivePersonnel(id) { - $.ajax({ - async: false, - dataType: 'json', - type: 'POST', - url: deActivePersonnelAjax, - headers: { "RequestVerificationToken": antiForgeryToken }, - data: { id: Number(id) }, - success: function (response) { - if (response.isSuccedded) { - $('.alert-success-msg').show(); - $('.alert-success-msg p').text(response.message); - setTimeout(function () { - $('.alert-success-msg').hide(); - $('.alert-success-msg p').text(''); - window.location.reload(); - }, 2000); - } else { - $('.alert-msg').show(); - $('.alert-msg p').text(response.message); - setTimeout(function () { - $('.alert-msg').hide(); - $('.alert-msg p').text(''); - }, 3500); - } - }, - error: function (err) { - console.log(err); - } - }); - } +function togglePersonnelStatus(id, type) { + var urlType = ""; + switch (type) { + case 'deactive': + urlType = deActivePersonnelAjax; + break; + case 'active': + urlType = activePersonnelAjax; + break; + default: + return; + } -function activePersonnel(id, hasUploadedImage) { - if (hasUploadedImage) { - $.ajax({ - async: false, - dataType: 'json', - type: 'POST', - url: activePersonnelAjax, - headers: { "RequestVerificationToken": antiForgeryToken }, - data: { id: Number(id) }, - success: function (response) { - if (response.isSuccedded) { - $('.alert-success-msg').show(); - $('.alert-success-msg p').text(response.message); - setTimeout(function () { - $('.alert-success-msg').hide(); - $('.alert-success-msg p').text(''); - window.location.reload(); - }, 2000); - } else { - $('.alert-msg').show(); - $('.alert-msg p').text(response.message); - setTimeout(function () { - $('.alert-msg').hide(); - $('.alert-msg p').text(''); - }, 3500); - } - }, - error: function (err) { - console.log(err); - } - }); - } else { - var errorText = "برای این پرسنل، هنوز هیچ عکسی آپلود نشده است. بعد از آپلود عکس بطور خودکار فعال خواهد شد"; - $('.alert-msg').show(); - $('.alert-msg p').text(errorText); - setTimeout(function () { - $('.alert-msg').hide(); - $('.alert-msg p').text(''); - }, 3500); - } + const buttonDesktop = $(`#togglePersonnelStatus_${id}_desktop`); + const buttonMobile = $(`#togglePersonnelStatus_${id}_mobile`); + + if (type === "deactive") { + swal.fire({ + title: "اخطار", + text: "در صورت غیر فعال کردن این پرسنل، حقوق این ماه ایشان محاسبه نخواهد شد. آیا مطمئن هستید؟", + icon: "warning", + showCancelButton: true, + confirmButtonText: "بله", + cancelButtonText: "خیر", + confirmButtonColor: '#84cc16', + reverseButtons: true + }).then((result) => { + if (result.isConfirmed) { + actionPersonnelStatus(urlType, id, type, buttonDesktop, buttonMobile); + } else { + return; + } + }); + } else { + actionPersonnelStatus(urlType, id, type, buttonDesktop, buttonMobile); + } } + +function actionPersonnelStatus(url, id, type, buttonDesktop, buttonMobile) { + $.ajax({ + async: false, + dataType: 'json', + type: 'POST', + url: url, + headers: { "RequestVerificationToken": antiForgeryToken }, + data: { id: id }, + success: function (response) { + if (response.isSuccedded) { + $('.alert-success-msg').show(); + $('.alert-success-msg p').text(response.message); + setTimeout(function () { + $('.alert-success-msg').hide(); + $('.alert-success-msg p').text(''); + }, 2000); + + loadInfoCount(); + + // Toggle both desktop and mobile buttons + if (type === "deactive") { + $(`#IsActiveString_${id}_desktop`).text('فعال کردن'); + $(`#IsActiveString_${id}_mobile`).text('فعال کردن'); + buttonDesktop.removeClass('btn-deactive').addClass('btn-active'); + buttonMobile.removeClass('btn-deactive').addClass('btn-active'); + } else { + $(`#IsActiveString_${id}_desktop`).text('غیر فعال کردن'); + $(`#IsActiveString_${id}_mobile`).text('غیر فعال کردن'); + buttonDesktop.removeClass('btn-active').addClass('btn-deactive'); + buttonMobile.removeClass('btn-active').addClass('btn-deactive'); + } + } else { + $('.alert-msg').show(); + $('.alert-msg p').text(response.message); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + }, 3500); + } + }, + error: function (err) { + console.log(err); + } + }); +} \ No newline at end of file diff --git a/ServiceHost/wwwroot/AssetsClient/pages/RollCall/js/ModalTakeImages.js b/ServiceHost/wwwroot/AssetsClient/pages/RollCall/js/ModalTakeImages.js index 7922d035..7eb765f2 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/RollCall/js/ModalTakeImages.js +++ b/ServiceHost/wwwroot/AssetsClient/pages/RollCall/js/ModalTakeImages.js @@ -120,164 +120,319 @@ // } - $(document).ready(function () { - if ($(window).width() > 992) { - $('#desktopDisplay').show(); - $('#mobileDisplay').hide(); - $('#mobileDisplay').html(''); - } +$(document).ready(function () { + if ($(window).width() > 992) { + $('#desktopDisplay').show(); + $('#mobileDisplay').hide(); + $('#mobileDisplay').html(''); + } - if ($(window).width() <= 992) { - $('#desktopDisplay').html(''); - $('#desktopDisplay').hide(); - $('#mobileDisplay').show(); - } + if ($(window).width() <= 992) { + $('#desktopDisplay').html(''); + $('#desktopDisplay').hide(); + $('#mobileDisplay').show(); + } - $(document).on('click', '.upload-image1', function () { - $('.md-modal').addClass('md-show'); - $('.take_snapshot1').show(); - $('.take_snapshot2').hide(); - startCamera(); - }); - - $(document).on('click', '.upload-image2', function () { - $('.md-modal').addClass('md-show'); - $('.take_snapshot1').hide(); - $('.take_snapshot2').show(); - startCamera(); - }); - - $(document).on('click', '.camera_close', function () { - $('.md-modal').removeClass('md-show'); - stopCamera(); - }); + $(document).on('click', '.upload-image1', function () { + $('.md-modal').addClass('md-show'); + $('.take_snapshot1').show(); + $('.take_snapshot2').hide(); + startCamera(); }); - var FACING_MODES = JslibHtml5CameraPhoto.FACING_MODES; - var IMAGE_TYPES = JslibHtml5CameraPhoto.IMAGE_TYPES; - - // Check if videoElement is already declared to avoid redeclaration - // if (typeof videoElement === 'undefined') { - var videoElement = document.getElementById('videoElement'); - var cameraPhoto = new JslibHtml5CameraPhoto.default(videoElement); - // } - - function startCamera() { - // startCameraMaxResolution - cameraPhoto.startCamera(FACING_MODES.USER).then(() => { - console.log('Camera started!'); - }).catch((error) => { - console.log(error); - console.error('Camera not started!', error); - }); - } - - function stopCamera() { - cameraPhoto.stopCamera().then(() => { - console.log('Camera stopped!'); - }).catch((error) => { - console.log('No camera to stop!:', error); - }); - } - - function cropAndResizeImage(base64Str, newWidth, newHeight) { - return new Promise((resolve) => { - let img = new Image(); - img.src = base64Str; - img.onload = () => { - let canvas = document.createElement('canvas'); - let ctx = canvas.getContext('2d'); - - let sideLength = Math.min(img.width, img.height); - let startX = (img.width - sideLength) / 2; - let startY = (img.height - sideLength) / 2; - - canvas.width = newWidth; - canvas.height = newHeight; - - ctx.drawImage(img, startX, startY, sideLength, sideLength, 0, 0, newWidth, newHeight); - resolve(canvas.toDataURL('image/jpeg')); - }; - }); - } - - function take_snapshot1() { - var sizeFactor = 1; - var imageType = IMAGE_TYPES.JPG; - var imageCompression = 1; - - var config = { - sizeFactor, - imageType, - imageCompression - }; - - var dataUri = cameraPhoto.getDataUri(config); - cropAndResizeImage(dataUri, 1800, 1800).then((resizedDataUri) => { - document.getElementById('result1').innerHTML = ''; - document.getElementById('demoResult1').innerHTML = ''; - }).catch((error) => { - console.error('Error cropping and resizing photo:', error); - }); + $(document).on('click', '.upload-image2', function () { + $('.md-modal').addClass('md-show'); + $('.take_snapshot1').hide(); + $('.take_snapshot2').show(); + startCamera(); + }); + $(document).on('click', '.camera_close', function () { $('.md-modal').removeClass('md-show'); stopCamera(); + }); + + updateSaveButton(); +}); + +window.onload = async () => { + await loadModels(); + modelsLoaded = true; +}; + +var loadModels = async () => { + await Promise.all([ + faceapi.nets.ssdMobilenetv1.loadFromUri("\\weights\\"), + faceapi.nets.faceRecognitionNet.loadFromUri("\\weights\\"), + faceapi.nets.faceLandmark68Net.loadFromUri("\\weights\\") + ]); +}; +var modelsLoaded = false; + +var ensureModelsLoaded = async () => { + if (!modelsLoaded) { + await loadModels(); + modelsLoaded = true; + } +}; + +var updateSaveButton = () => { + if (checkFace === 2) { + $('#SaveImageEmployee').removeClass('disable'); + } else { + $('#SaveImageEmployee').addClass('disable'); + } +}; + +var runCheckFace1 = async () => { + await ensureModelsLoaded(); + + const img1 = document.getElementById('pic1'); + + const detectionPromise1 = faceapi.detectSingleFace(img1).withFaceLandmarks().withFaceDescriptor(); + const delayPromise1 = new Promise(resolve => setTimeout(resolve, 2000)); + + const [detection1] = await Promise.all([detectionPromise1, delayPromise1]); + + //const detection1 = await faceapi.detectSingleFace(img1).withFaceLandmarks().withFaceDescriptor(); + if (detection1) { + console.log('چهره در تصویر اول شناسایی شد'); + + if (checkFace < 2) { + checkFace = checkFace + 1; + } + $('#demoResult1').css('border', '2px dashed #148b8b'); + } else { + $('.alert-msg').show(); + $('.alert-msg p').text('چهره‌ای در تصویر اول شناسایی نشد'); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + }, 2000); + + if (checkFace > 0) { + checkFace = checkFace - 1; + } + + $('#SaveImageEmployee').addClass('disable'); + $('.upload-image1').css('background', '#ff090940'); + $('#demoResult1').css('border', '2px dashed #ff5c5c'); } + updateSaveButton(); + $('#loadingImage1').hide(); +}; - function take_snapshot2() { - var sizeFactor = 1; - var imageType = IMAGE_TYPES.JPG; - var imageCompression = 1; +var runCheckFace2 = async () => { + await ensureModelsLoaded(); + const img2 = document.getElementById('pic2'); - var config = { - sizeFactor, - imageType, - imageCompression + const detectionPromise2 = faceapi.detectSingleFace(img2).withFaceLandmarks().withFaceDescriptor(); + const delayPromise2 = new Promise(resolve => setTimeout(resolve, 2000)); + + const [detection2] = await Promise.all([detectionPromise2, delayPromise2]); + + //const detection2 = await faceapi.detectSingleFace(img2).withFaceLandmarks().withFaceDescriptor(); + if (detection2) { + console.log('چهره در تصویر دوم شناسایی شد'); + + if (checkFace < 2) { + checkFace = checkFace + 1; + } + $('#demoResult2').css('border', '2px dashed #148b8b'); + } else { + $('.alert-msg').show(); + $('.alert-msg p').text('چهره‌ای در تصویر دوم شناسایی نشد'); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + }, 2000); + + if (checkFace > 0) { + checkFace = checkFace - 1; + } + + $('#SaveImageEmployee').addClass('disable'); + $('.upload-image2').css('background', '#ff090940'); + $('#demoResult2').css('border', '2px dashed #ff5c5c'); + } + updateSaveButton(); + $('#loadingImage2').hide(); +}; + + +var FACING_MODES = JslibHtml5CameraPhoto.FACING_MODES; +var IMAGE_TYPES = JslibHtml5CameraPhoto.IMAGE_TYPES; + +// Check if videoElement is already declared to avoid redeclaration +// if (typeof videoElement === 'undefined') { + var videoElement = document.getElementById('videoElement'); + var cameraPhoto = new JslibHtml5CameraPhoto.default(videoElement); +// } + +function startCamera() { + // startCameraMaxResolution + cameraPhoto.startCamera(FACING_MODES.USER).then(() => { + console.log('Camera started!'); + }).catch((error) => { + console.log(error); + console.error('Camera not started!', error); + }); +} + +function stopCamera() { + cameraPhoto.stopCamera().then(() => { + console.log('Camera stopped!'); + }).catch((error) => { + console.log('No camera to stop!:', error); + }); +} + +function cropAndResizeImage(base64Str, newWidth, newHeight) { + return new Promise((resolve) => { + let img = new Image(); + img.src = base64Str; + img.onload = () => { + let canvas = document.createElement('canvas'); + let ctx = canvas.getContext('2d'); + + let sideLength = Math.min(img.width, img.height); + let startX = (img.width - sideLength) / 2; + let startY = (img.height - sideLength) / 2; + + canvas.width = newWidth; + canvas.height = newHeight; + + ctx.drawImage(img, startX, startY, sideLength, sideLength, 0, 0, newWidth, newHeight); + resolve(canvas.toDataURL('image/jpeg')); }; + }); +} - var dataUri = cameraPhoto.getDataUri(config); - cropAndResizeImage(dataUri, 1800, 1800).then((resizedDataUri) => { - document.getElementById('result2').innerHTML = ''; - document.getElementById('demoResult2').innerHTML = ''; - }).catch((error) => { - console.error('Error cropping and resizing photo:', error); - }); +function take_snapshot1() { + $('#SaveImageEmployee').addClass('disable'); + var sizeFactor = 1; + var imageType = IMAGE_TYPES.JPG; + var imageCompression = 1; - $('.md-modal').removeClass('md-show'); - stopCamera(); - } + var config = { + sizeFactor, + imageType, + imageCompression + }; - function set() { - let pic1 = $("#pic1").attr('src'); - let pic2 = $("#pic2").attr('src'); - let workshopId = Number($('#workshopId').val()); - let employeeId = Number($('#employeeId').val()); + var dataUri = cameraPhoto.getDataUri(config); + cropAndResizeImage(dataUri, 1800, 1800).then((resizedDataUri) => { + document.getElementById('result1').innerHTML = ''; + document.getElementById('demoResult1').innerHTML = '
Loading...
'; + $('#loadingImage1').css('display', 'flex'); + runCheckFace1(); + }).catch((error) => { + console.error('Error cropping and resizing photo:', error); + }); + $('.md-modal').removeClass('md-show'); + + stopCamera(); +} + +function take_snapshot2() { + $('#SaveImageEmployee').addClass('disable'); + var sizeFactor = 1; + var imageType = IMAGE_TYPES.JPG; + var imageCompression = 1; + + var config = { + sizeFactor, + imageType, + imageCompression + }; + + var dataUri = cameraPhoto.getDataUri(config); + cropAndResizeImage(dataUri, 1800, 1800).then((resizedDataUri) => { + document.getElementById('result2').innerHTML = ''; + document.getElementById('demoResult2').innerHTML = '
Loading...
'; + $('#loadingImage2').css('display', 'flex'); + runCheckFace2(); + }).catch((error) => { + console.error('Error cropping and resizing photo:', error); + }); + + $('.md-modal').removeClass('md-show'); + stopCamera(); + loadModels(); + runCheckFace2(); +} + + +function set() { + let pic1 = $("#pic1").attr('src'); + let pic2 = $("#pic2").attr('src'); + let workshopId = Number($('#workshopId').val()); + let employeeId = Number($('#employeeId').val()); + + if (checkFace) { if (pic1 != null && pic2 != null) { + const loading = $('.spinner-loading-progress').show(); + const loadingBtn = $('.spinner-loading').show(); + let startTime = Date.now(); + + $('#SaveImageEmployee').addClass('disable'); + + $.ajax({ type: 'POST', url: takePictureAjax, - data: { "base64pic1": pic1, "base64pic2": pic2, "workshopId": workshopId, "employeeId": employeeId }, - headers: { "RequestVerificationToken": antiForgeryToken }, - success: function (response) { - if (response.isSuccedded) { - $('.alert-success-msg').show(); - $('.alert-success-msg p').text(response.message); - setTimeout(function () { - $('.alert-success-msg').hide(); - $('.alert-success-msg p').text(''); - window.location.reload(); - }, 2000); - } else { - $('.alert-msg').show(); - $('.alert-msg p').text(response.message); - setTimeout(function () { - $('.alert-msg').hide(); - $('.alert-msg p').text(''); - }, 3500); - } + data: { + "base64pic1": pic1, + "base64pic2": pic2, + "workshopId": workshopId, + "employeeId": employeeId }, - failure: function (response) { + headers: { + "RequestVerificationToken": antiForgeryToken + }, + xhr: function () { + let xhr = new XMLHttpRequest(); + // Track the progress of the upload + xhr.upload.onprogress = function (e) { + if (e.lengthComputable) { + var percentComplete = (e.loaded / e.total) * 100; + $('#progressBar').text(Math.round(percentComplete) + '%'); + $('.spinner-loading-progress').css('width', `${Math.round(percentComplete)}%`); + } + }; + return xhr; + }, + success: function (response) { + let elapsedTime = Date.now() - startTime; + let delay = Math.max(1000 - elapsedTime, 0); + + setTimeout(function () { + + if (response.isSuccedded) { + $('.alert-success-msg').show(); + $('.alert-success-msg p').text(response.message); + setTimeout(function () { + $('.alert-success-msg').hide(); + $('.alert-success-msg p').text(''); + + $('#SaveImageEmployee').removeClass('disable'); + //loading.hide(); + $('#MainModal').modal('hide'); + //window.location.reload(); + }, 1000); + } else { + $('#SaveImageEmployee').removeClass('disable'); + $('.alert-msg').show(); + $('.alert-msg p').text(response.message); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + }, 3500); + } + }, delay); // Delay the hiding of the spinner + }, + error: function (response) { console.log(5, response); } }); @@ -289,4 +444,70 @@ $('.alert-msg p').text(''); }, 3500); } - } \ No newline at end of file + } else { + $('.alert-msg').show(); + $('.alert-msg p').text('گرفتن دو عکس الزامیست'); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + }, 3500); + } +} + + + +//function set() { +// let pic1 = $("#pic1").attr('src'); +// let pic2 = $("#pic2").attr('src'); +// let workshopId = Number($('#workshopId').val()); +// let employeeId = Number($('#employeeId').val()); + +// if (checkFace) { +// if (pic1 != null && pic2 != null) { +// $.ajax({ +// type: 'POST', +// url: takePictureAjax, +// data: { "base64pic1": pic1, "base64pic2": pic2, "workshopId": workshopId, "employeeId": employeeId }, +// headers: { "RequestVerificationToken": antiForgeryToken }, +// success: function(response) { +// if (response.isSuccedded) { +// $('.alert-success-msg').show(); +// $('.alert-success-msg p').text(response.message); +// setTimeout(function() { +// $('.alert-success-msg').hide(); +// $('.alert-success-msg p').text(''); +// window.location.reload(); +// }, +// 2000); +// } else { +// $('.alert-msg').show(); +// $('.alert-msg p').text(response.message); +// setTimeout(function() { +// $('.alert-msg').hide(); +// $('.alert-msg p').text(''); +// }, +// 3500); +// } +// }, +// failure: function(response) { +// console.log(5, response); +// } +// }); +// } else { +// $('.alert-msg').show(); +// $('.alert-msg p').text('گرفتن دو عکس الزامیست'); +// setTimeout(function() { +// $('.alert-msg').hide(); +// $('.alert-msg p').text(''); +// }, +// 3500); +// } +// } else { +// $('.alert-msg').show(); +// $('.alert-msg p').text('گرفتن دو عکس الزامیست'); +// setTimeout(function () { +// $('.alert-msg').hide(); +// $('.alert-msg p').text(''); +// }, 3500); +// } +//} \ No newline at end of file