mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Fixed created assets not showing on list until site refresh
This commit is contained in:
@@ -66,6 +66,7 @@ public class AssetsController : Controller
|
|||||||
[HttpPost("Create")]
|
[HttpPost("Create")]
|
||||||
public async Task<AssetsCreateResponseModel> Create([FromBody]AssetsCreateRequestModel assetModel)
|
public async Task<AssetsCreateResponseModel> Create([FromBody]AssetsCreateRequestModel assetModel)
|
||||||
{
|
{
|
||||||
|
string? assetId;
|
||||||
AssetsCreateResponseModel result;
|
AssetsCreateResponseModel result;
|
||||||
if (assetModel is null)
|
if (assetModel is null)
|
||||||
{
|
{
|
||||||
@@ -82,8 +83,8 @@ public class AssetsController : Controller
|
|||||||
[
|
[
|
||||||
new LdapAttribute("objectClass", ["top", "device", "extensibleObject"]),
|
new LdapAttribute("objectClass", ["top", "device", "extensibleObject"]),
|
||||||
];
|
];
|
||||||
|
assetId = await _ldap.GetAssetCounterAndIncrementAsync();
|
||||||
attributeSet.Add(new LdapAttribute("cn", await _ldap.GetAssetCounterAndIncrementAsync()));
|
attributeSet.Add(new LdapAttribute("cn", assetId));
|
||||||
if (assetModel.SerialNumber != null)
|
if (assetModel.SerialNumber != null)
|
||||||
{
|
{
|
||||||
attributeSet.Add(new LdapAttribute("serialNumber", assetModel.SerialNumber));
|
attributeSet.Add(new LdapAttribute("serialNumber", assetModel.SerialNumber));
|
||||||
@@ -107,7 +108,7 @@ public class AssetsController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
await _ldap.CreateAsset(attributeSet);
|
await _ldap.CreateAsset(attributeSet);
|
||||||
result = new AssetsCreateResponseModel(successful: true);
|
result = new AssetsCreateResponseModel(successful: true, assetId);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using Berufsschule_HAM.Models;
|
using Berufsschule_HAM.Models;
|
||||||
|
|
||||||
public class AssetsCreateResponseModel(bool successful, string exception = "None")
|
public class AssetsCreateResponseModel(bool successful, string? assetId = null, string exception = "None")
|
||||||
{
|
{
|
||||||
public bool Success { get; set; } = successful;
|
public bool Success { get; set; } = successful;
|
||||||
|
public string? AssetId { get; set; } = assetId;
|
||||||
|
|
||||||
public string? Exception { get; set; } = exception;
|
public string? Exception { get; set; } = exception;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -333,6 +333,39 @@
|
|||||||
bootstrap.Modal.getInstance(createModalEl).hide();
|
bootstrap.Modal.getInstance(createModalEl).hide();
|
||||||
createForm.reset();
|
createForm.reset();
|
||||||
attributesContainer.innerHTML = '';
|
attributesContainer.innerHTML = '';
|
||||||
|
const tableBody = document.querySelector('table tbody');
|
||||||
|
if (tableBody) {
|
||||||
|
const newRow = document.createElement('tr');
|
||||||
|
newRow.innerHTML = `
|
||||||
|
<td>${jsonData.Owner || ''}</td>
|
||||||
|
<td>${result.assetId || ''}</td>
|
||||||
|
<td>${jsonData.Name || ''}</td>
|
||||||
|
<td>${jsonData.Location || ''}</td>
|
||||||
|
<td>
|
||||||
|
<div class="d-flex gap-2">
|
||||||
|
<button class="btn btn-sm btn-warning btn-update"
|
||||||
|
data-asset-id="${result.assetId}"
|
||||||
|
data-bs-toggle="modal"
|
||||||
|
data-bs-target="#updateAssetModal">
|
||||||
|
@T["Update"]
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-sm btn-danger btn-delete"
|
||||||
|
data-asset-id="${result.assetId}"
|
||||||
|
data-asset-name="${jsonData.Name || ''}"
|
||||||
|
data-bs-toggle="modal"
|
||||||
|
data-bs-target="#deleteModal">
|
||||||
|
@T["Delete"]
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
`;
|
||||||
|
|
||||||
|
newRow.classList.add('table-success');
|
||||||
|
setTimeout(() => {
|
||||||
|
newRow.classList.toggle('table-success');
|
||||||
|
}, 500);
|
||||||
|
tableBody.append(newRow);
|
||||||
|
}
|
||||||
showToast('@T["Asset created successfully"]', 'success');
|
showToast('@T["Asset created successfully"]', 'success');
|
||||||
} else {
|
} else {
|
||||||
showToast(`${result.reason || '@T["Error creating asset"]'}`, 'danger');
|
showToast(`${result.reason || '@T["Error creating asset"]'}`, 'danger');
|
||||||
|
|||||||
Reference in New Issue
Block a user