From 7ea6e7b0c1901f49d23a9e85b4023bc519faca43 Mon Sep 17 00:00:00 2001 From: singharaj usai Date: Sun, 13 Oct 2024 13:30:17 -0400 Subject: [PATCH] fixed missing bracket in assets.js --- client/js/admin/assets.js | 414 +++++++++++++++++++------------------- client/js/admin/init.js | 2 - 2 files changed, 207 insertions(+), 209 deletions(-) diff --git a/client/js/admin/assets.js b/client/js/admin/assets.js index b1f8a41..7d02b75 100644 --- a/client/js/admin/assets.js +++ b/client/js/admin/assets.js @@ -1,45 +1,45 @@ function loadAssets() { - const contentArea = $('#content-area'); - contentArea.empty(); - - const assetSearchHtml = ` -
-
-

Asset Lookup

-
-
-
-
- - -
- -
-
-
-
-
-
-

Recent Assets

+ const contentArea = $('#content-area'); + contentArea.empty(); + + const assetSearchHtml = ` +
+
+

Asset Lookup

+
+
+
+
+ + +
+ +
+
+
-
-
+
+
+

Recent Assets

+
+
+
+
-
- `; - - contentArea.html(assetSearchHtml); - - $('#asset-search-form').on('submit', function (e) { - e.preventDefault(); - const assetId = $('#asset-id').val(); - searchAsset(assetId); - }); - - loadRecentAssets(); -} - -function openEditAssetModal(assetId) { + `; + + contentArea.html(assetSearchHtml); + + $('#asset-search-form').on('submit', function (e) { + e.preventDefault(); + const assetId = $('#asset-id').val(); + searchAsset(assetId); + }); + + loadRecentAssets(); + } + + function openEditAssetModal(assetId) { $.ajax({ url: `/api/admin/assets/${assetId}`, method: 'GET', @@ -60,187 +60,188 @@ function openEditAssetModal(assetId) { }, }); } - -function redrawAsset(assetId) { - if (confirm('Are you sure you want to redraw this asset?')) { - $.ajax({ - url: `/api/admin/assets/${assetId}/redraw`, - method: 'POST', - headers: { - Authorization: `Bearer ${localStorage.getItem('token')}`, - }, - success: function (response) { - alert(response.message); - loadRecentAssets(); - }, - error: function (xhr, status, error) { - const errorMessage = xhr.responseJSON ? xhr.responseJSON.error : 'Unknown error occurred'; - alert('Error queuing asset redraw: ' + errorMessage); - console.error('Error queuing asset redraw:', error); - }, - }); -} - -function deleteAsset(assetId) { - if (confirm('Are you sure you want to delete this asset?')) { + + function redrawAsset(assetId) { + if (confirm('Are you sure you want to redraw this asset?')) { + $.ajax({ + url: `/api/admin/assets/${assetId}/redraw`, + method: 'POST', + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}`, + }, + success: function (response) { + alert(response.message); + loadRecentAssets(); + }, + error: function (xhr, status, error) { + const errorMessage = xhr.responseJSON ? xhr.responseJSON.error : 'Unknown error occurred'; + alert('Error queuing asset redraw: ' + errorMessage); + console.error('Error queuing asset redraw:', error); + }, + }); + } + } + + function deleteAsset(assetId) { + if (confirm('Are you sure you want to delete this asset?')) { + $.ajax({ + url: `/api/admin/assets/${assetId}`, + method: 'DELETE', + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}`, + }, + success: function () { + alert('Asset deleted successfully'); + loadAssets(); + }, + error: function (xhr, status, error) { + alert('Error deleting asset'); + }, + }); + } + } + + function displayAssetResult(asset) { + const assetHtml = ` +
+
+

Asset Details

+
+
+

ID: ${asset.assetId}

+

Name: ${asset.Name}

+

Description: ${asset.Description}

+

Type: ${asset.AssetType}

+

Creator: ${asset.creator.username}

+

Price: ${asset.Price}

+

Sales: ${asset.Sales}

+ ${asset.Name} +
+ + + ${asset.canRedraw ? `` : ''} +
+
+
+ `; + $('#asset-result').html(assetHtml); + + $('.edit-asset').on('click', function () { + const assetId = $(this).data('asset-id'); + openEditAssetModal(assetId); + }); + + $('.delete-asset').on('click', function () { + const assetId = $(this).data('asset-id'); + deleteAsset(assetId); + }); + + if (asset.canRedraw) { + $('.redraw-asset').on('click', function () { + const assetId = $(this).data('asset-id'); + redrawAsset(assetId); + }); + } + } + + function searchAsset(assetId) { $.ajax({ url: `/api/admin/assets/${assetId}`, - method: 'DELETE', + method: 'GET', headers: { Authorization: `Bearer ${localStorage.getItem('token')}`, }, - success: function () { - alert('Asset deleted successfully'); - loadAssets(); + success: function (asset) { + displayAssetResult(asset); }, error: function (xhr, status, error) { - alert('Error deleting asset'); + $('#asset-result').html( + '

Error: Asset not found

' + ); }, }); } -} - -function displayAssetResult(asset) { - const assetHtml = ` -
-
-

Asset Details

-
-
-

ID: ${asset.assetId}

-

Name: ${asset.Name}

-

Description: ${asset.Description}

-

Type: ${asset.AssetType}

-

Creator: ${asset.creator.username}

-

Price: ${asset.Price}

-

Sales: ${asset.Sales}

- ${asset.Name} -
- - - ${asset.canRedraw ? `` : ''} -
-
-
+ + function displayRecentAssets(assets) { + const assetsContainer = $('#recent-assets'); + assetsContainer.empty(); + + if (assets.length === 0) { + assetsContainer.append('

No recent assets found.

'); + return; + } + + const assetsTable = ` + + + + + + + + + + + + + + ${assets.map((asset) => ` + + + + + + + + + + `).join('')} + +
IDNameTypeCreatorPriceSalesActions
${asset.assetId}${asset.Name}${asset.AssetType}${asset.creator.username}${asset.Price}${asset.Sales} + + + ${asset.AssetType !== 'Image' ? `` : ''} +
`; - $('#asset-result').html(assetHtml); - - $('.edit-asset').on('click', function () { - const assetId = $(this).data('asset-id'); - openEditAssetModal(assetId); - }); - - $('.delete-asset').on('click', function () { - const assetId = $(this).data('asset-id'); - deleteAsset(assetId); - }); - - if (asset.canRedraw) { + + assetsContainer.html(assetsTable); + + $('.edit-asset').on('click', function () { + const assetId = $(this).data('asset-id'); + openEditAssetModal(assetId); + }); + + $('.delete-asset').on('click', function () { + const assetId = $(this).data('asset-id'); + deleteAsset(assetId); + }); + $('.redraw-asset').on('click', function () { const assetId = $(this).data('asset-id'); redrawAsset(assetId); }); } -} - -function searchAsset(assetId) { - $.ajax({ - url: `/api/admin/assets/${assetId}`, - method: 'GET', - headers: { - Authorization: `Bearer ${localStorage.getItem('token')}`, - }, - success: function (asset) { - displayAssetResult(asset); - }, - error: function (xhr, status, error) { - $('#asset-result').html( - '

Error: Asset not found

' - ); - }, - }); -} - -function displayRecentAssets(assets) { - const assetsContainer = $('#recent-assets'); - assetsContainer.empty(); - - if (assets.length === 0) { - assetsContainer.append('

No recent assets found.

'); - return; + + function loadRecentAssets() { + $.ajax({ + url: '/api/admin/assets/recent', + method: 'GET', + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}`, + }, + success: function (assets) { + displayRecentAssets(assets); + }, + error: function (xhr, status, error) { + console.error('Error fetching recent assets:', error); + $('#recent-assets').html( + '

Error fetching recent assets.

' + ); + }, + }); } - - const assetsTable = ` - - - - - - - - - - - - - - ${assets.map((asset) => ` - - - - - - - - - - `).join('')} - -
IDNameTypeCreatorPriceSalesActions
${asset.assetId}${asset.Name}${asset.AssetType}${asset.creator.username}${asset.Price}${asset.Sales} - - - ${asset.AssetType !== 'Image' ? `` : ''} -
- `; - - assetsContainer.html(assetsTable); - - $('.edit-asset').on('click', function () { - const assetId = $(this).data('asset-id'); - openEditAssetModal(assetId); - }); - - $('.delete-asset').on('click', function () { - const assetId = $(this).data('asset-id'); - deleteAsset(assetId); - }); - - $('.redraw-asset').on('click', function () { - const assetId = $(this).data('asset-id'); - redrawAsset(assetId); - }); -} - -function loadRecentAssets() { - $.ajax({ - url: '/api/admin/assets/recent', - method: 'GET', - headers: { - Authorization: `Bearer ${localStorage.getItem('token')}`, - }, - success: function (assets) { - displayRecentAssets(assets); - }, - error: function (xhr, status, error) { - console.error('Error fetching recent assets:', error); - $('#recent-assets').html( - '

Error fetching recent assets.

' - ); - }, - }); -} - -function createEditAssetModal() { + + function createEditAssetModal() { const modalHtml = `