fix: move campaign templates to dedicated tab
This commit is contained in:
@@ -90,53 +90,20 @@
|
||||
<div class="glass-card campaign-template-panel animate-slide-up">
|
||||
<div class="batch-bulk-header">
|
||||
<div>
|
||||
<h3>Шаблоны кампаний</h3>
|
||||
<p>@campaignTemplateModels.Count сохранённых</p>
|
||||
<h3>Применить шаблон</h3>
|
||||
<p>@campaignTemplateModels.Count доступных для этой группы</p>
|
||||
</div>
|
||||
<span class="status-badge status-info">Template</span>
|
||||
<a href="/templates" class="btn-gm btn-gm-outline">⚙️ Управлять шаблонами</a>
|
||||
</div>
|
||||
|
||||
<EditForm Model="@campaignTemplateModel" OnValidSubmit="CreateCampaignTemplate">
|
||||
<div class="campaign-template-fields">
|
||||
<div class="gm-form-group">
|
||||
<label class="gm-form-label">Название шаблона</label>
|
||||
<InputText @bind-Value="campaignTemplateModel.Name" class="gm-form-control" />
|
||||
</div>
|
||||
<div class="gm-form-group">
|
||||
<label class="gm-form-label">Название кампании</label>
|
||||
<InputText @bind-Value="campaignTemplateModel.Title" class="gm-form-control" />
|
||||
</div>
|
||||
<div class="gm-form-group">
|
||||
<label class="gm-form-label">Ссылка</label>
|
||||
<InputText @bind-Value="campaignTemplateModel.JoinLink" class="gm-form-control" />
|
||||
</div>
|
||||
<div class="gm-form-group">
|
||||
<label class="gm-form-label">Игр</label>
|
||||
<InputNumber @bind-Value="campaignTemplateModel.SessionCount" class="gm-form-control" min="1" max="52" />
|
||||
</div>
|
||||
<div class="gm-form-group">
|
||||
<label class="gm-form-label">Интервал, дней</label>
|
||||
<InputNumber @bind-Value="campaignTemplateModel.IntervalDays" class="gm-form-control" min="1" max="365" />
|
||||
</div>
|
||||
<div class="gm-form-group">
|
||||
<label class="gm-form-label">Мест</label>
|
||||
<InputNumber @bind-Value="campaignTemplateModel.MaxPlayers" class="gm-form-control" min="1" />
|
||||
</div>
|
||||
<div class="gm-form-group">
|
||||
<label class="gm-form-label">Уведомления</label>
|
||||
<select @bind="campaignTemplateModel.NotificationMode" class="gm-form-control">
|
||||
<option value="@SessionNotificationModeExtensions.GroupAndDirectValue">В группе и в личку</option>
|
||||
<option value="@SessionNotificationModeExtensions.GroupOnlyValue">Только в группе</option>
|
||||
</select>
|
||||
</div>
|
||||
@if (campaignTemplateModels.Count == 0)
|
||||
{
|
||||
<div class="empty-state empty-state-compact">
|
||||
<div class="empty-state-title">Шаблонов пока нет</div>
|
||||
<p class="empty-state-text">Создайте шаблоны в отдельной вкладке, а здесь запускайте из них новые batch-расписания.</p>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-gm btn-gm-primary" disabled="@isCreatingTemplate">
|
||||
@(isCreatingTemplate ? "⏳ Сохраняем..." : "💾 Сохранить шаблон")
|
||||
</button>
|
||||
</EditForm>
|
||||
|
||||
@if (campaignTemplateModels.Count > 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="campaign-template-list">
|
||||
@foreach (var template in campaignTemplateModels)
|
||||
@@ -151,9 +118,6 @@
|
||||
<button type="button" class="btn-gm btn-gm-success" disabled="@IsTemplateBusy(template)" @onclick="() => CreateBatchFromTemplate(template)">
|
||||
@(processingTemplateId == template.Id ? "⏳ Создаём..." : "📅 Создать batch")
|
||||
</button>
|
||||
<button type="button" class="btn-gm btn-gm-danger" disabled="@IsTemplateBusy(template)" @onclick="() => DeleteCampaignTemplate(template)">
|
||||
@(deletingTemplateId == template.Id ? "⏳ Удаляем..." : "Удалить")
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -347,15 +311,12 @@
|
||||
private Guid? promotingSessionId;
|
||||
private Guid? processingBatchId;
|
||||
private Guid? processingTemplateId;
|
||||
private Guid? deletingTemplateId;
|
||||
private long? removingCoGmId;
|
||||
private bool isAddingCoGm;
|
||||
private bool isCreatingTemplate;
|
||||
private long telegramId;
|
||||
private string? errorMessage;
|
||||
private string? successMessage;
|
||||
private CoGmEditModel coGmModel = new();
|
||||
private CampaignTemplateEditModel campaignTemplateModel = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@@ -588,51 +549,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreateCampaignTemplate()
|
||||
{
|
||||
errorMessage = null;
|
||||
successMessage = null;
|
||||
|
||||
if (!ValidateCampaignTemplate(campaignTemplateModel))
|
||||
{
|
||||
errorMessage = "Шаблон должен иметь название, ссылку, 1-52 игр, шаг 1-365 дней и положительный лимит мест, если он указан.";
|
||||
return;
|
||||
}
|
||||
|
||||
isCreatingTemplate = true;
|
||||
|
||||
try
|
||||
{
|
||||
await SessionService.CreateCampaignTemplateForGmAsync(
|
||||
GroupId,
|
||||
telegramId,
|
||||
new CreateCampaignTemplateRequest(
|
||||
campaignTemplateModel.Name,
|
||||
campaignTemplateModel.Title,
|
||||
campaignTemplateModel.JoinLink,
|
||||
campaignTemplateModel.SessionCount,
|
||||
campaignTemplateModel.IntervalDays,
|
||||
campaignTemplateModel.MaxPlayers,
|
||||
SessionNotificationModeExtensions.FromDatabaseValue(campaignTemplateModel.NotificationMode)));
|
||||
|
||||
campaignTemplateModel = new();
|
||||
successMessage = "Шаблон кампании сохранён.";
|
||||
await LoadSessions();
|
||||
}
|
||||
catch (SessionAccessDeniedException)
|
||||
{
|
||||
Navigation.NavigateTo("/access-denied");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errorMessage = "Не удалось сохранить шаблон: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
isCreatingTemplate = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreateBatchFromTemplate(CampaignTemplateUsageModel template)
|
||||
{
|
||||
errorMessage = null;
|
||||
@@ -666,32 +582,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteCampaignTemplate(CampaignTemplateUsageModel template)
|
||||
{
|
||||
errorMessage = null;
|
||||
successMessage = null;
|
||||
deletingTemplateId = template.Id;
|
||||
|
||||
try
|
||||
{
|
||||
await SessionService.DeleteCampaignTemplateForGmAsync(template.Id, telegramId);
|
||||
successMessage = "Шаблон кампании удалён.";
|
||||
await LoadSessions();
|
||||
}
|
||||
catch (SessionAccessDeniedException)
|
||||
{
|
||||
Navigation.NavigateTo("/access-denied");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errorMessage = "Не удалось удалить шаблон: " + ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
deletingTemplateId = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void RebuildBatchModels()
|
||||
{
|
||||
batchModels = sessions?
|
||||
@@ -746,28 +636,9 @@
|
||||
return batch.Title.Length > 0 && batch.JoinLink.Length > 0;
|
||||
}
|
||||
|
||||
private static bool ValidateCampaignTemplate(CampaignTemplateEditModel template)
|
||||
{
|
||||
template.Name = template.Name.Trim();
|
||||
template.Title = template.Title.Trim();
|
||||
template.JoinLink = template.JoinLink.Trim();
|
||||
|
||||
if (template.MaxPlayers.HasValue && template.MaxPlayers.Value <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return template.Name.Length > 0 &&
|
||||
template.Title.Length > 0 &&
|
||||
template.JoinLink.Length > 0 &&
|
||||
template.SessionCount is >= 1 and <= 52 &&
|
||||
template.IntervalDays is >= 1 and <= 365;
|
||||
}
|
||||
|
||||
private bool IsBatchBusy(BatchBulkEditModel batch) => processingBatchId == batch.BatchId;
|
||||
|
||||
private bool IsTemplateBusy(CampaignTemplateUsageModel template) =>
|
||||
processingTemplateId == template.Id || deletingTemplateId == template.Id;
|
||||
private bool IsTemplateBusy(CampaignTemplateUsageModel template) => processingTemplateId == template.Id;
|
||||
|
||||
private string CurrentUserRole =>
|
||||
groupManagement?.Managers.FirstOrDefault(manager => manager.TelegramId == telegramId)?.Role
|
||||
@@ -864,17 +735,6 @@
|
||||
public string CloneInterval { get; set; } = "week";
|
||||
}
|
||||
|
||||
private sealed class CampaignTemplateEditModel
|
||||
{
|
||||
public string Name { get; set; } = "";
|
||||
public string Title { get; set; } = "";
|
||||
public string JoinLink { get; set; } = "";
|
||||
public int SessionCount { get; set; } = 6;
|
||||
public int IntervalDays { get; set; } = 7;
|
||||
public int? MaxPlayers { get; set; }
|
||||
public string NotificationMode { get; set; } = SessionNotificationModeExtensions.GroupAndDirectValue;
|
||||
}
|
||||
|
||||
private sealed class CampaignTemplateUsageModel
|
||||
{
|
||||
public Guid Id { get; init; }
|
||||
|
||||
Reference in New Issue
Block a user