Skip to content

Commit 153c859

Browse files
Update - Market page refactor
1 parent 0a17c18 commit 153c859

File tree

15 files changed

+2095
-3552
lines changed

15 files changed

+2095
-3552
lines changed

app/assets/images/market-bg.webp

-411 KB
Binary file not shown.
-376 KB
Binary file not shown.
122 KB
Loading
86.9 KB
Loading
23.4 KB
Loading

app/controllers/catacombs_controller.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
class CatacombsController < ApplicationController
2+
before_action :check_user_eligibility, except: [:index]
23

34
def index
5+
# Redirect banned users away from catacombs
6+
if current_user&.banned?
7+
redirect_to root_path, alert: "You cannot access the catacombs."
8+
return
9+
end
10+
411
@betting_enabled = Flipper.enabled?(:betting, current_user)
512
@current_week = ApplicationController.helpers.current_week_number
613
@personal_bet = current_user.personal_bets.find_by(week: @current_week) if current_user
@@ -22,6 +29,7 @@ def index
2229
@emerald_unlocked = current_user.emerald_unlocked
2330
@amethyst_unlocked = current_user.amethyst_unlocked
2431
@current_runes = current_user.current_runes
32+
@user_is_out = current_user.out?
2533
end
2634

2735
# Calculate current hours for personal bet if exists
@@ -412,4 +420,12 @@ def log_runes
412420

413421
render json: { success: true }
414422
end
423+
424+
private
425+
426+
def check_user_eligibility
427+
if current_user&.out?
428+
render json: { success: false, message: "You cannot use catacombs actions while out of Siege" }, status: :forbidden
429+
end
430+
end
415431
end

app/controllers/market_controller.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,14 @@ def purchase
8787
render json: { success: false, error: "You've already purchased the maximum amount of this item! (#{purchased_count}/#{max_purchases})" }
8888
return
8989
end
90-
elsif tech_tree_item[:maxPurchases].nil?
91-
# Infinite purchases (like grants) - no purchase limit
9290
elsif tech_tree_item[:maxPurchases] && tech_tree_item[:maxPurchases] > 1
9391
# Multi-purchase item with static limit
9492
if purchased_count >= tech_tree_item[:maxPurchases]
9593
render json: { success: false, error: "You've already purchased the maximum amount of this item!" }
9694
return
9795
end
9896
else
99-
# Single purchase item
97+
# Default: Single purchase item (maxPurchases nil or 1)
10098
if purchased_count > 0
10199
render json: { success: false, error: "You already own this item!" }
102100
return
@@ -206,9 +204,15 @@ def purchase
206204

207205
def set_main_device
208206
device_id = params[:device_id]
207+
should_refund = params[:refund] == true || params[:refund] == "true"
208+
209+
if should_refund
210+
refunded_coins = current_user.refund_tech_tree_purchases
211+
Rails.logger.info "Refunded #{refunded_coins} coins to user #{current_user.id}"
212+
end
209213

210214
if current_user.set_main_device(device_id)
211-
render json: { success: true, message: "Main device updated successfully" }
215+
render json: { success: true, message: "Main device updated successfully", refunded: should_refund }
212216
else
213217
render json: { success: false, error: "Invalid device selection" }
214218
end

app/models/user.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,39 @@ def set_main_device(device_id)
349349
update(main_device: device_id)
350350
end
351351

352+
def refund_tech_tree_purchases
353+
# Load tech tree data to get the list of actual tech tree items
354+
tech_tree_data = JSON.parse(File.read(Rails.root.join("config", "tech_tree_data.json")))
355+
tech_tree_item_names = []
356+
357+
# Extract all tech tree item names
358+
tech_tree_data.each do |category_name, category_data|
359+
next unless category_data["branches"]
360+
361+
category_data["branches"].each do |device_name, device_branches|
362+
device_branches.each do |direction, item|
363+
tech_tree_item_names << item["title"] if item["title"]
364+
end
365+
end
366+
end
367+
368+
# Find purchases that match tech tree items
369+
tech_tree_purchases = shop_purchases.where(item_name: tech_tree_item_names)
370+
total_refund = 0
371+
372+
tech_tree_purchases.each do |purchase|
373+
total_refund += purchase.coins_spent
374+
end
375+
376+
tech_tree_purchases.destroy_all
377+
378+
if total_refund > 0
379+
update(coins: coins + total_refund)
380+
end
381+
382+
total_refund
383+
end
384+
352385
def main_device_name
353386
case main_device
354387
when "framework_12"

app/views/admin/users.html.erb

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -717,28 +717,43 @@ document.addEventListener('DOMContentLoaded', function() {
717717
.then(response => response.json())
718718
.then(data => {
719719
// Update the display with the trust status
720-
let statusHtml = '';
720+
element.innerHTML = '';
721+
const span = document.createElement('span');
722+
span.style.fontWeight = '600';
723+
721724
switch(data.status) {
722725
case 'trusted':
723-
statusHtml = '<span style="color: #059669; font-weight: 600;">✓ Trusted</span>';
726+
span.style.color = '#059669';
727+
span.textContent = '✓ Trusted';
724728
break;
725729
case 'neutral':
726-
statusHtml = '<span style="color: #2563eb; font-weight: 600;">○ Neutral</span>';
730+
span.style.color = '#2563eb';
731+
span.textContent = '○ Neutral';
727732
break;
728733
case 'banned':
729-
statusHtml = '<span style="color: #dc2626; font-weight: 600;">✗ Banned</span>';
734+
span.style.color = '#dc2626';
735+
span.textContent = '✗ Banned';
730736
break;
731737
case 'error':
732-
statusHtml = `<span style="color: #dc2626; font-weight: 600;" title="${data.message || 'API Error'}">⚠ Error</span>`;
738+
span.style.color = '#dc2626';
739+
span.textContent = '⚠ Error';
740+
span.title = data.message || 'API Error';
733741
break;
734742
default:
735-
statusHtml = `<span style="color: #6b7280; font-weight: 600;" title="${data.message || 'Unknown status'}">? Unknown</span>`;
743+
span.style.color = '#6b7280';
744+
span.textContent = '? Unknown';
745+
span.title = data.message || 'Unknown status';
736746
}
737-
element.innerHTML = statusHtml;
747+
element.appendChild(span);
738748
})
739749
.catch(error => {
740750
console.error('Error loading hackatime trust for user', userId, ':', error);
741-
element.innerHTML = '<span style="color: #dc2626; font-weight: 600;">⚠ Error</span>';
751+
element.innerHTML = '';
752+
const span = document.createElement('span');
753+
span.style.color = '#dc2626';
754+
span.style.fontWeight = '600';
755+
span.textContent = '⚠ Error';
756+
element.appendChild(span);
742757
});
743758
});
744759
});

app/views/admin/weekly_overview_user.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,8 @@
14371437
const addHeight = Math.max((commit.additions / maxChanges) * 130, 3);
14381438
const delHeight = Math.max((commit.deletions / maxChanges) * 130, 3);
14391439

1440-
const commitTitle = `${commit.message}\\nAdditions: +${commit.additions}\\nDeletions: -${commit.deletions}\\nAuthor: ${commit.author}`;
1440+
const escapeAttr = (str) => String(str).replace(/[&<>"']/g, m => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[m]));
1441+
const commitTitle = escapeAttr(`${commit.message}\nAdditions: +${commit.additions}\nDeletions: -${commit.deletions}\nAuthor: ${commit.author}`);
14411442

14421443
// Calculate opacity based on stack position (darker = more recent)
14431444
const opacity = 1 - (stackIndex * 0.15);

0 commit comments

Comments
 (0)