Compare commits

...

2 Commits

Author SHA1 Message Date
Ricardo Carneiro
951b44f7eb feat: pipeline 2025-08-17 21:35:45 -03:00
Ricardo Carneiro
0d9a0988fe feat: aparencia dashboard 2025-08-17 20:50:40 -03:00
8 changed files with 481 additions and 48 deletions

254
.github/workflows/deploy-bcards.yml vendored Normal file
View File

@ -0,0 +1,254 @@
name: Deploy BCards
on:
push:
branches: [ main, 'release/*' ]
pull_request:
branches: [ main ]
env:
REGISTRY: registry.redecarneir.us
IMAGE_NAME: bcards
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Test
run: dotnet test --no-build --configuration Release --verbosity normal --collect:"XPlat Code Coverage"
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
files: coverage.cobertura.xml
build-and-push:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Determine build settings
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "TAG=latest" >> $GITHUB_ENV
echo "PLATFORM=linux/arm64" >> $GITHUB_ENV
echo "ENVIRONMENT=Production" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == refs/heads/release/* ]]; then
# Extrai versão da branch (release/v1.0.0 -> v1.0.0)
VERSION=$(echo "${{ github.ref }}" | sed 's/refs\/heads\/release\///')
echo "TAG=${VERSION}" >> $GITHUB_ENV
echo "PLATFORM=linux/amd64" >> $GITHUB_ENV
echo "ENVIRONMENT=Staging" >> $GITHUB_ENV
fi
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
- name: Build and push to registry
run: |
# Build da imagem para a plataforma correta
docker buildx build \
--platform ${{ env.PLATFORM }} \
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} \
--push \
.
deploy-production:
needs: build-and-push
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Deploy to Production Servers (ARM - OCI)
run: |
# Configura SSH
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
# Deploy no Servidor 1 (ARM - OCI)
ssh -o StrictHostKeyChecking=no ubuntu@141.148.162.114 << 'EOF'
# Remove containers bcards-infrastructure se existirem
docker stop bcards-infrastructure || true
docker rm bcards-infrastructure || true
docker stop bcards-test-app || true
docker rm bcards-test-app || true
# Para o container BCards atual se existir
docker stop bcards-prod || true
docker rm bcards-prod || true
# Remove imagem antiga
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest || true
# Puxa nova imagem
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
# Executa novo container BCards
docker run -d \
--name bcards-prod \
--restart unless-stopped \
-p 5002:8080 \
-e ASPNETCORE_ENVIRONMENT=Production \
-e ASPNETCORE_URLS=http://+:8080 \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
# Recarrega NGINX
sudo nginx -t && sudo systemctl reload nginx
EOF
# Deploy no Servidor 2 (ARM - OCI)
ssh -o StrictHostKeyChecking=no ubuntu@129.146.116.218 << 'EOF'
# Remove containers bcards-infrastructure se existirem
docker stop bcards-infrastructure || true
docker rm bcards-infrastructure || true
docker stop bcards-test-app || true
docker rm bcards-test-app || true
# Para o container BCards atual se existir
docker stop bcards-prod || true
docker rm bcards-prod || true
# Remove imagem antiga
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest || true
# Puxa nova imagem
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
# Executa novo container BCards
docker run -d \
--name bcards-prod \
--restart unless-stopped \
-p 5002:8080 \
-e ASPNETCORE_ENVIRONMENT=Production \
-e ASPNETCORE_URLS=http://+:8080 \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
EOF
- name: Health Check Production
run: |
# Aguarda containers subirem
sleep 30
# Verifica se os serviços estão respondendo
echo "Verificando Servidor 1 (ARM)..."
ssh -o StrictHostKeyChecking=no ubuntu@141.148.162.114 'curl -f http://localhost:5002/health || echo "Servidor 1 pode não estar respondendo"'
echo "Verificando Servidor 2 (ARM)..."
ssh -o StrictHostKeyChecking=no ubuntu@129.146.116.218 'curl -f http://localhost:5002/health || echo "Servidor 2 pode não estar respondendo"'
deploy-staging:
needs: build-and-push
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/release/')
steps:
- name: Deploy to Staging Server (x86 - Local)
run: |
# Configura SSH
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
# Extrai versão da branch
VERSION=$(echo "${{ github.ref }}" | sed 's/refs\/heads\/release\///')
# Deploy no Servidor Local x86
ssh -o StrictHostKeyChecking=no ubuntu@192.168.0.100 << EOF
# Remove containers bcards-infrastructure se existirem
docker stop bcards-infrastructure || true
docker rm bcards-infrastructure || true
docker stop bcards-test-app || true
docker rm bcards-test-app || true
# Para o container BCards atual se existir
docker stop bcards-staging || true
docker rm bcards-staging || true
# Remove imagem antiga
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION} || true
# Puxa nova imagem
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION}
# Executa novo container BCards
docker run -d \
--name bcards-staging \
--restart unless-stopped \
-p 5002:8080 \
-e ASPNETCORE_ENVIRONMENT=Staging \
-e ASPNETCORE_URLS=http://+:8080 \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION}
EOF
- name: Health Check Staging
run: |
# Aguarda container subir
sleep 30
# Verifica se o serviço está respondendo
echo "Verificando Servidor Staging (x86)..."
ssh -o StrictHostKeyChecking=no ubuntu@192.168.0.100 'curl -f http://localhost:5002/health || echo "Servidor staging pode não estar respondendo"'
cleanup:
needs: [deploy-production, deploy-staging]
runs-on: ubuntu-latest
if: always() && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/'))
steps:
- name: Cleanup old containers and images
run: |
# Configura SSH
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
# Lista de servidores baseada na branch
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
SERVERS=("141.148.162.114" "129.146.116.218")
else
SERVERS=("192.168.0.100")
fi
# Limpeza em cada servidor
for server in "${SERVERS[@]}"; do
echo "Limpando servidor $server..."
ssh -o StrictHostKeyChecking=no ubuntu@$server << 'EOF'
# Remove containers parados
docker container prune -f
# Remove imagens não utilizadas (mantém as mais recentes)
docker image prune -f
# Remove redes não utilizadas
docker network prune -f
EOF
done

View File

@ -114,13 +114,14 @@ public class PaymentController : Controller
// Parse do plano atual (mesmo que o Dashboard)
var userPlanType = Enum.TryParse<PlanType>(user.CurrentPlan, true, out var planType) ? planType : PlanType.Trial;
var currentPlanString = userPlanType.ToString().ToLower();
var subscription = await _subscriptionRepository.GetByUserIdAsync(user.Id);
var viewModel = new ManageSubscriptionViewModel
{
User = user,
StripeSubscription = await _paymentService.GetSubscriptionDetailsAsync(user.Id),
PaymentHistory = await _paymentService.GetPaymentHistoryAsync(user.Id),
AvailablePlans = GetAvailablePlans(currentPlanString)
AvailablePlans = GetAvailablePlans(currentPlanString),
CurrentPeriodEnd = (DateTime?) subscription.CurrentPeriodEnd
};
// Pegar assinatura local se existir

View File

@ -87,7 +87,7 @@ builder.Services.AddAuthentication(options =>
{
OnRedirectToAuthorizationEndpoint = context =>
{
context.Response.Redirect(context.RedirectUri + "&prompt=select_account");
context.Response.Redirect(context.RedirectUri + "&prompt=login");
return Task.CompletedTask;
}
};

View File

@ -19,7 +19,7 @@ public class ManageSubscriptionViewModel
public bool CanDowngrade => HasActiveSubscription && User.CurrentPlan != "basic";
public bool WillCancelAtPeriodEnd => StripeSubscription?.CancelAtPeriodEnd == true;
public DateTime? CurrentPeriodEnd => null;
public DateTime? CurrentPeriodEnd { get; set; }
public DateTime? NextBillingDate => !WillCancelAtPeriodEnd ? CurrentPeriodEnd : null;
public decimal? MonthlyAmount => StripeSubscription?.Items?.Data?.FirstOrDefault()?.Price?.UnitAmount / 100m;

View File

@ -93,13 +93,15 @@
</div>
}
<div class="d-flex gap-1 align-items-center" data-page-id="@pageItem.Id" data-status="@pageItem.Status">
<!-- Botão Ver - sempre presente quando possível -->
</div>
<!-- Cards com Hover Effect -->
<div class="card-footer" data-page-id="@pageItem.Id" data-status="@pageItem.Status">
<div class="d-flex gap-2">
@if (pageItem.Status == BCards.Web.ViewModels.PageStatus.Active)
{
<a href="/page/@pageItem.Category/@pageItem.Slug" target="_blank"
class="btn btn-sm btn-success">
<i class="fas fa-external-link-alt me-1"></i>Ver
class="btn btn-success flex-fill">
<i class="fas fa-eye me-1"></i>Ver Página
</a>
}
else if (pageItem.Status == BCards.Web.ViewModels.PageStatus.Creating ||
@ -107,24 +109,30 @@
pageItem.Status == BCards.Web.ViewModels.PageStatus.PendingModeration)
{
<button type="button"
class="btn btn-sm btn-outline-info"
class="btn btn-outline-info flex-fill"
onclick="openPreview('@pageItem.Id')"
data-page-category="@pageItem.Category"
data-page-slug="@pageItem.Slug">
<i class="fas fa-eye me-1"></i>Testar
<i class="fas fa-vial me-1"></i>Testar Página
</button>
}
else
{
<button class="btn btn-secondary flex-fill" disabled>
<i class="fas fa-ban me-1"></i>Indisponível
</button>
}
<!-- Dropdown para outras ações -->
<div class="dropdown">
<button class="btn btn-sm btn-outline-secondary dropdown-toggle"
<div class="btn-group">
<button class="btn btn-outline-secondary dropdown-toggle"
type="button"
id="dropdownMenuButton@(pageItem.Id)"
data-bs-toggle="dropdown"
aria-expanded="false">
Ações
aria-expanded="false"
title="Mais opções">
<i class="fas fa-cog"></i>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton@(pageItem.Id)">
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdownMenuButton@(pageItem.Id)">
<!-- Editar - sempre presente -->
@if (pageItem.Status == BCards.Web.ViewModels.PageStatus.PendingModeration)
{
@ -144,7 +152,6 @@
</li>
}
@if (pageItem.Status == BCards.Web.ViewModels.PageStatus.Creating ||
pageItem.Status == BCards.Web.ViewModels.PageStatus.Rejected)
{
@ -170,12 +177,14 @@
</ul>
</div>
</div>
</div>
<div class="card-footer bg-transparent">
<!-- Informações da página movidas para baixo dos botões -->
<div class="px-3 pt-2 pb-1">
<small class="text-muted">Criada em @(pageItem.CreatedAt.ToString("dd/MM/yyyy"))</small>
@if ((pageItem.LastModerationStatus ?? pageItem.Status) == BCards.Web.ViewModels.PageStatus.Rejected && !string.IsNullOrEmpty(pageItem.Motive))
{
<div class="alert alert-danger alert-dismissible fade show mt-2" role="alert">
<div class="alert alert-danger alert-dismissible fade show mt-2 mb-0" role="alert">
<div class="d-flex align-items-start">
<i class="fas fa-exclamation-triangle me-2 mt-1"></i>
<div class="flex-grow-1">
@ -188,7 +197,7 @@
}
else if (pageItem.LastModerationStatus == BCards.Web.ViewModels.PageStatus.Active && !string.IsNullOrEmpty(pageItem.Motive))
{
<div class="alert alert-info alert-dismissible fade show mt-2" role="alert">
<div class="alert alert-info alert-dismissible fade show mt-2 mb-0" role="alert">
<div class="d-flex align-items-start">
<i class="fas fa-exclamation-triangle me-2 mt-1"></i>
<div class="flex-grow-1">
@ -198,11 +207,11 @@
</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
}
</div>
</div>
</div>
</div>
@if ((pageItem.LastModerationStatus ?? pageItem.Status) == BCards.Web.ViewModels.PageStatus.Creating)

View File

@ -100,7 +100,7 @@
</div>
<div class="mt-3">
<div class="btn-group" role="group">
<div class="d-flex gap-2 flex-wrap">
@if (!Model.WillCancelAtPeriodEnd)
{
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#cancelModal">
@ -109,7 +109,7 @@
</button>
}
<form method="post" action="@Url.Action("OpenStripePortal")" style="display: inline;">
<form method="post" action="@Url.Action("OpenStripePortal")" class="d-inline">
<button type="submit" class="btn btn-outline-primary">
<i class="fas fa-external-link-alt me-1"></i>
Portal de Pagamento

View File

@ -39,8 +39,76 @@
<link rel="icon" type="image/x-icon" href="~/favicon.ico" />
@await RenderSectionAsync("Styles", required: false)
<!-- Estilos para menu ativo e barra de carregamento -->
<style>
/* Barra de carregamento moderna */
#loading-bar {
position: fixed;
top: 0;
left: 0;
width: 0%;
height: 3px;
background: linear-gradient(90deg, #007bff, #0056b3, #007bff);
background-size: 200% 100%;
animation: loading-shimmer 1.5s infinite;
z-index: 9999;
transition: width 0.3s ease, opacity 0.3s ease;
opacity: 0;
}
#loading-bar.active {
opacity: 1;
}
@@keyframes loading-shimmer {
0% { background-position: -200% 0; }
100% { background-position: 200% 0; }
}
/* Destacar item ativo do menu */
.nav-link.active {
background-color: rgba(0, 123, 255, 0.1) !important;
border-radius: 6px !important;
font-weight: 600 !important;
}
/* Para homepage (fundo azul) */
.bg-home-blue .nav-link.active {
background-color: rgba(255, 255, 255, 0.2) !important;
}
/* Smooth transition para links */
.nav-link {
transition: all 0.2s ease;
padding: 8px 12px !important;
margin: 0 2px;
border-radius: 6px;
}
.nav-link:hover {
background-color: rgba(0, 123, 255, 0.05);
}
.bg-home-blue .nav-link:hover {
background-color: rgba(255, 255, 255, 0.1);
}
/* Suavizar transições de página */
main {
opacity: 1;
transition: opacity 0.2s ease;
}
main.page-loading {
opacity: 0.7;
}
</style>
</head>
<body>
<!-- Barra de carregamento -->
<div id="loading-bar"></div>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light fixed-top @(ViewBag.IsHomePage == true ? "bg-home-blue" : "bg-dashboard")" id="mainNavbar">
<div class="container-fluid">
@ -155,6 +223,107 @@
<script src="~/lib/jquery/jquery.min.js"></script>
<script src="~/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
<!-- Scripts para menu ativo e barra de carregamento -->
<script>
$(document).ready(function() {
// Destacar item ativo do menu baseado na URL atual
highlightActiveMenuItem();
// Interceptar cliques em links de navegação
setupLoadingBar();
});
function highlightActiveMenuItem() {
var currentPath = window.location.pathname.toLowerCase();
var currentController = '@ViewContext.RouteData.Values["Controller"]?.ToString()?.ToLower()';
var currentAction = '@ViewContext.RouteData.Values["Action"]?.ToString()?.ToLower()';
// Remover classes ativas existentes
$('.nav-link').removeClass('active');
// Lógica para destacar o item correto
$('.nav-link').each(function() {
var link = $(this);
var href = link.attr('href');
if (href) {
var linkPath = href.toLowerCase();
// Verificar correspondência exata primeiro
if (currentPath === linkPath ||
(currentPath === '/' && linkPath.includes('/home')) ||
(currentController === 'home' && currentAction === 'index' && linkPath.includes('/home')) ||
(currentController === 'home' && currentAction === 'pricing' && linkPath.includes('pricing')) ||
(currentController === 'admin' && linkPath.includes('dashboard')) ||
(currentController === 'moderation' && linkPath.includes('moderation')) ||
(currentController === 'auth' && linkPath.includes('login')) ||
(currentController === 'payment' && linkPath.includes('managesubscription'))) {
link.addClass('active');
}
}
});
}
function setupLoadingBar() {
var loadingBar = $('#loading-bar');
// Interceptar todos os cliques em links que navegam para outras páginas
$('a[href]:not([href^="#"]):not([href^="javascript:"]):not([target="_blank"]):not(.no-loading)').click(function(e) {
var href = $(this).attr('href');
// Ignorar links externos, downloads, ou âncoras
if (href && !href.startsWith('http') && !href.startsWith('mailto:') && !href.startsWith('tel:')) {
showLoadingBar();
}
});
// Interceptar submissão de formulários
$('form:not(.no-loading)').submit(function() {
showLoadingBar();
});
// Ocultar barra quando página carrega
$(window).on('load', function() {
hideLoadingBar();
});
// Ocultar barra em caso de erro ou volta do histórico
$(window).on('pageshow', function() {
hideLoadingBar();
});
}
function showLoadingBar() {
var loadingBar = $('#loading-bar');
loadingBar.addClass('active').css('width', '0%');
// Animação progressiva
setTimeout(function() { loadingBar.css('width', '20%'); }, 100);
setTimeout(function() { loadingBar.css('width', '40%'); }, 300);
setTimeout(function() { loadingBar.css('width', '60%'); }, 600);
setTimeout(function() { loadingBar.css('width', '80%'); }, 1000);
// Adicionar efeito de loading ao conteúdo
$('main').addClass('page-loading');
}
function hideLoadingBar() {
var loadingBar = $('#loading-bar');
loadingBar.css('width', '100%');
setTimeout(function() {
loadingBar.removeClass('active').css('width', '0%');
$('main').removeClass('page-loading');
}, 200);
}
// Fallback para esconder loading se demorar muito (mais de 5 segundos)
setTimeout(function() {
hideLoadingBar();
}, 5000);
</script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>

View File

@ -310,10 +310,10 @@
</div>
<div class="toast-body">
<p class="mb-2"><strong>Você está visualizando uma prévia!</strong></p>
<p class="mb-2 small">• Para fazer alterações, volte ao Dashboard</p>
<p class="mb-2 small">• Para fazer alterações, volte ao Dashboard e clique <i class="fas fa-cog"></i></p>
<p class="mb-2 small">• Esta prévia não é a página final publicada</p>
<button type="button" class="btn btn-sm btn-primary w-100" onclick="goBackToDashboard()">
<i class="fas fa-edit me-1"></i>
<i class="fas fa-cog"></i> >>
Editar Página
</button>
</div>