fix: slug duplicado
All checks were successful
BCards Deployment Pipeline / Run Tests (push) Successful in 3s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 16m8s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Successful in 2m25s
BCards Deployment Pipeline / Deploy to Staging (x86 - Local) (push) Has been skipped
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s
All checks were successful
BCards Deployment Pipeline / Run Tests (push) Successful in 3s
BCards Deployment Pipeline / PR Validation (push) Has been skipped
BCards Deployment Pipeline / Build and Push Image (push) Successful in 16m8s
BCards Deployment Pipeline / Deploy to Production (ARM - OCI) (push) Successful in 2m25s
BCards Deployment Pipeline / Deploy to Staging (x86 - Local) (push) Has been skipped
BCards Deployment Pipeline / Cleanup Old Resources (push) Has been skipped
BCards Deployment Pipeline / Deployment Summary (push) Successful in 0s
This commit is contained in:
parent
4bad39ec85
commit
2eada5f44c
@ -93,8 +93,7 @@ public class UserPageRepository : IUserPageRepository
|
|||||||
{
|
{
|
||||||
var filter = Builders<UserPage>.Filter.And(
|
var filter = Builders<UserPage>.Filter.And(
|
||||||
Builders<UserPage>.Filter.Eq(x => x.Category, category),
|
Builders<UserPage>.Filter.Eq(x => x.Category, category),
|
||||||
Builders<UserPage>.Filter.Eq(x => x.Slug, slug),
|
Builders<UserPage>.Filter.Eq(x => x.Slug, slug)
|
||||||
Builders<UserPage>.Filter.Eq(x => x.IsActive, true)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(excludeId))
|
if (!string.IsNullOrEmpty(excludeId))
|
||||||
|
|||||||
@ -94,9 +94,12 @@
|
|||||||
<span class="input-group-text" id="categorySlug">@SlugHelper.CreateCategorySlug(Model.Category)</span>
|
<span class="input-group-text" id="categorySlug">@SlugHelper.CreateCategorySlug(Model.Category)</span>
|
||||||
<span class="input-group-text">/</span>
|
<span class="input-group-text">/</span>
|
||||||
<input type="text" class="form-control" id="slugPreview" value="@Model.Slug" readonly>
|
<input type="text" class="form-control" id="slugPreview" value="@Model.Slug" readonly>
|
||||||
|
<span class="input-group-text" id="slugValidationIcon" style="display: none;">
|
||||||
|
<i id="slugIcon" class=""></i>
|
||||||
|
</span>
|
||||||
<input asp-for="Slug" type="hidden">
|
<input asp-for="Slug" type="hidden">
|
||||||
</div>
|
</div>
|
||||||
<small class="form-text text-muted">URL gerada automaticamente</small>
|
<small class="form-text" id="slugValidationMessage">URL gerada automaticamente</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -974,6 +977,11 @@
|
|||||||
generateSlug();
|
generateSlug();
|
||||||
updateProgress();
|
updateProgress();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Validar slug inicial (para páginas em edição)
|
||||||
|
if ($('#Slug').val() && $('#Category').val()) {
|
||||||
|
validateSlugAvailability($('#Category').val(), $('#Slug').val());
|
||||||
|
}
|
||||||
|
|
||||||
// Theme selection
|
// Theme selection
|
||||||
$('.theme-card').on('click', function() {
|
$('.theme-card').on('click', function() {
|
||||||
@ -1110,17 +1118,77 @@
|
|||||||
function generateSlug() {
|
function generateSlug() {
|
||||||
const name = $('#DisplayName').val();
|
const name = $('#DisplayName').val();
|
||||||
const category = $('#Category').val();
|
const category = $('#Category').val();
|
||||||
|
|
||||||
if (name && category) {
|
if (name && category) {
|
||||||
$.post('@Url.Action("GenerateSlug", "Admin")', { category: category, name: name })
|
$.post('@Url.Action("GenerateSlug", "Admin")', { category: category, name: name })
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
$('#Slug').val(data.slug);
|
$('#Slug').val(data.slug);
|
||||||
$('#slugPreview').val(data.slug);
|
$('#slugPreview').val(data.slug);
|
||||||
$('#categorySlug').text(data.category);
|
$('#categorySlug').text(data.category);
|
||||||
|
|
||||||
|
// Validar disponibilidade do slug gerado
|
||||||
|
validateSlugAvailability(category, data.slug);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validateSlugAvailability(category, slug) {
|
||||||
|
if (!category || !slug) return;
|
||||||
|
|
||||||
|
const excludeId = '@Model.Id' !== '' ? '@Model.Id' : null;
|
||||||
|
|
||||||
|
// Mostrar indicador de carregamento
|
||||||
|
showSlugValidationStatus('loading', 'Verificando disponibilidade...');
|
||||||
|
|
||||||
|
$.post('@Url.Action("CheckSlugAvailability", "Admin")', {
|
||||||
|
category: category,
|
||||||
|
slug: slug,
|
||||||
|
excludeId: excludeId
|
||||||
|
})
|
||||||
|
.done(function(response) {
|
||||||
|
if (response.available) {
|
||||||
|
showSlugValidationStatus('success', 'URL disponível!');
|
||||||
|
} else {
|
||||||
|
showSlugValidationStatus('error', response.message || 'Esta URL já está em uso.');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function() {
|
||||||
|
showSlugValidationStatus('error', 'Erro ao verificar disponibilidade.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function showSlugValidationStatus(type, message) {
|
||||||
|
const $icon = $('#slugIcon');
|
||||||
|
const $message = $('#slugValidationMessage');
|
||||||
|
const $iconContainer = $('#slugValidationIcon');
|
||||||
|
|
||||||
|
$iconContainer.show();
|
||||||
|
|
||||||
|
// Remover classes anteriores
|
||||||
|
$icon.removeClass('fas fa-check-circle fas fa-times-circle fas fa-spinner fa-spin text-success text-danger text-primary');
|
||||||
|
$message.removeClass('text-success text-danger text-primary text-muted');
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case 'success':
|
||||||
|
$icon.addClass('fas fa-check-circle text-success');
|
||||||
|
$message.addClass('text-success');
|
||||||
|
break;
|
||||||
|
case 'error':
|
||||||
|
$icon.addClass('fas fa-times-circle text-danger');
|
||||||
|
$message.addClass('text-danger');
|
||||||
|
break;
|
||||||
|
case 'loading':
|
||||||
|
$icon.addClass('fas fa-spinner fa-spin text-primary');
|
||||||
|
$message.addClass('text-primary');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$iconContainer.hide();
|
||||||
|
$message.addClass('text-muted');
|
||||||
|
}
|
||||||
|
|
||||||
|
$message.text(message);
|
||||||
|
}
|
||||||
|
|
||||||
function addLinkInput(title = '', url = '', description = '', icon = '', linkType = 'Normal', id='new') {
|
function addLinkInput(title = '', url = '', description = '', icon = '', linkType = 'Normal', id='new') {
|
||||||
// Encontrar o próximo índice disponível baseado em todos os campos Links[] existentes
|
// Encontrar o próximo índice disponível baseado em todos os campos Links[] existentes
|
||||||
const existingIndexes = [];
|
const existingIndexes = [];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user