HU a datatables-hez

This commit is contained in:
2025-03-19 09:59:42 +01:00
parent 2fd147bb36
commit f74922d01e
10 changed files with 78 additions and 18 deletions
+4 -1
View File
@@ -38,7 +38,10 @@ namespace WorkFlowCheck.BL.Services
try try
{ {
var user = await _dbContext.Users.Where(w => w.Id == Id).FirstOrDefaultAsync(); var user = await _dbContext.Users
.Include(i => i.UserRoles)
.ThenInclude(i => i.Role)
.Where(w => w.Id == Id).FirstOrDefaultAsync();
if (user != null) if (user != null)
{ {
retVal = _mapper.Map<UserDTO>(user); retVal = _mapper.Map<UserDTO>(user);
@@ -32,10 +32,12 @@
</div> </div>
</form> </form>
</div> </div>
<br />
<div class="card shadow p-4"> <div class="card shadow p-4">
<div class="d-flex justify-content-end"> <div class="d-flex justify-content-end">
<button class="btn btn-primary float-right">Új elem hozzáadása</button> <button class="btn btn-primary float-right new-btn" data-bs-toggle="tooltip" data-bs-placement="top" title="Új elem hozzáadása">
<i class="bi bi-plus-square"></i>
</button>
</div> </div>
<table id="tbCheckPointsEditPage" class="table table-bordered table-hover table-sm" style="width:100%"> <table id="tbCheckPointsEditPage" class="table table-bordered table-hover table-sm" style="width:100%">
<thead class="table-primary"> <thead class="table-primary">
@@ -89,15 +91,16 @@
} }
], ],
processing:true processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
}); });
$('#tbCheckPointsEditPage').on('click', '.edit-btn', function () $('#tbCheckPointsEditPage').on('click', '.edit-btn', function ()
{ {
const row = table.row($(this).closest('tr')).data(); const row = table.row($(this).closest('tr')).data();
window.location.href = `@Url.Page("./CheckListTemplateRowEditPage")?id=${row.id}`; window.location.href = `@Url.Page("./CheckListTemplateRowEditPage")?id=${row.id}`;
}); });
$('#tbCheckPointsEditPage').on('click', '.delete-btn', function () $('#tbCheckPointsEditPage').on('click', '.delete-btn', function ()
{ {
const row = table.row($(this).closest('tr')).data(); const row = table.row($(this).closest('tr')).data();
@@ -112,7 +115,7 @@
} }
}); });
}); });
$("#saveCheckPoint").click(function () { $("#saveCheckPoint").click(function () {
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
var formData = getFormAsNestedObject('#checkPointForm'); var formData = getFormAsNestedObject('#checkPointForm');
@@ -59,7 +59,8 @@
} }
], ],
processing:true processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
}); });
$('#tbCheckPointsPage').on('click', '.edit-btn', function () $('#tbCheckPointsPage').on('click', '.edit-btn', function ()
@@ -54,7 +54,8 @@
} }
], ],
processing:true processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
}); });
$('#tbEquipmentsPage').on('click', '.edit-btn', function () $('#tbEquipmentsPage').on('click', '.edit-btn', function ()
@@ -54,7 +54,8 @@
} }
], ],
processing:true processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
}); });
$('#tbLocationsPage').on('click', '.edit-btn', function () $('#tbLocationsPage').on('click', '.edit-btn', function ()
@@ -56,7 +56,8 @@
} }
], ],
processing:true processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
}); });
$('#newRoleBtn').on('click', function () $('#newRoleBtn').on('click', function ()
@@ -5,10 +5,12 @@
@{ @{
ViewData["Title"] = "Ellenőrzési pont"; ViewData["Title"] = "Ellenőrzési pont";
var UserId = Model.UserDTO.Id; var UserId = Model.UserDTO.Id;
var url = Url.Page("./UserEditPage", "LoadRoles", new { id = UserId });
var urlPost = Url.Page("./UserEditPage", "Save"); var urlPost = Url.Page("./UserEditPage", "Save");
} }
<h1>@ViewData["Title"]</h1> <h1>@ViewData["Title"]</h1>
<input type="hidden" id="UserEditUrl" value="@url" />
<input type="hidden" id="UserEditPostUrl" value="@urlPost" /> <input type="hidden" id="UserEditPostUrl" value="@urlPost" />
<div class="card shadow p-4"> <div class="card shadow p-4">
@@ -52,9 +54,48 @@
</div> </div>
</form> </form>
</div> </div>
<br></br>
<div class="card shadow p-4">
<table id="tbUserPage" class="table table-bordered table-hover table-sm" style="width:100%">
<thead class="table-primary">
<tr>
<th>ID</th>
<th>Role Name</th>
</tr>
</thead>
<tfoot class="table-light">
<tr>
<th>ID</th>
<th>Role Name</th>
</tr>
</tfoot>
</table>
</div>
@section Scripts { @section Scripts {
<script> <script>
console.log($('#UserEditUrl').val());
const table = new DataTable('#tbUserPage', {
ajax: {
url: $('#UserEditUrl').val(),
type: "GET",
dataSrc : "data"
},
columns: [
{ data: "id" },
{ data: "roleName" }
],
columnDefs: [
{
"targets": 0,
"visible": false
}
],
processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
});
$("#saveUser").click(function () { $("#saveUser").click(function () {
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
@@ -98,7 +139,7 @@
}); });
$(document).ready(function () { $(document).ready(function () {
const $form = $("#userForm"); const $form = $("#UserForm");
$form.validate({ $form.validate({
errorClass: "text-danger small", errorClass: "text-danger small",
@@ -46,5 +46,10 @@ namespace WorkFlowCheck.Web.Pages.UserAndRole
return new JsonResult(new { success = false }); return new JsonResult(new { success = false });
} }
public async Task<JsonResult> OnGetLoadRoles(int id)
{
UserDTO = await _userService.GetUser(id);
return new JsonResult(new { data = UserDTO.RoleDTO });
}
} }
} }
@@ -7,7 +7,9 @@
<div class="card shadow p-4"> <div class="card shadow p-4">
<div class="d-flex justify-content-end"> <div class="d-flex justify-content-end">
<button id="newUserBtn" class="btn btn-primary float-right new-btn">Új elem hozzáadása</button> <button id="newUserBtn" class="btn btn-primary float-right new-btn" data-bs-toggle="tooltip" data-bs-placement="top" title="Új felhasználó">
<i class="bi bi-plus-square"></i>
</button>
</div> </div>
<table id="tbUsersPage" class="table table-bordered table-hover table-sm" style="width:100%"> <table id="tbUsersPage" class="table table-bordered table-hover table-sm" style="width:100%">
<thead class="table-primary"> <thead class="table-primary">
@@ -63,7 +65,8 @@
} }
], ],
processing:true processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
}); });
$('#newUserBtn').on('click', function () $('#newUserBtn').on('click', function ()
@@ -71,13 +74,13 @@
console.log('New button clicked!"'); console.log('New button clicked!"');
window.location.href = `@Url.Page("./UserEditPage")?id=0`; window.location.href = `@Url.Page("./UserEditPage")?id=0`;
}); });
$('#tbUsersPage').on('click', '.edit-btn', function () $('#tbUsersPage').on('click', '.edit-btn', function ()
{ {
const row = table.row($(this).closest('tr')).data(); const row = table.row($(this).closest('tr')).data();
window.location.href = `@Url.Page("./UserEditPage")?id=${row.id}`; window.location.href = `@Url.Page("./UserEditPage")?id=${row.id}`;
}); });
$('#tbUsersPage').on('click', '.delete-btn', function () $('#tbUsersPage').on('click', '.delete-btn', function ()
{ {
const row = table.row($(this).closest('tr')).data(); const row = table.row($(this).closest('tr')).data();
@@ -59,7 +59,8 @@
} }
], ],
processing:true processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
}); });
$('#newUserRoleBtn').on('click', function () $('#newUserRoleBtn').on('click', function ()