164 lines
5.4 KiB
Plaintext
164 lines
5.4 KiB
Plaintext
@namespace Oqtane.Modules.Admin.Jobs
|
|
@inherits ModuleBase
|
|
@inject NavigationManager NavigationManager
|
|
@inject IJobService JobService
|
|
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Name: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@_name" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Type: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@_jobType" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Enabled? </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@_isEnabled">
|
|
<option value="True">Yes</option>
|
|
<option value="False">No</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Runs Every: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@_interval" />
|
|
<select class="form-control" @bind="@_frequency">
|
|
<option value="m">Minute(s)</option>
|
|
<option value="H">Hour(s)</option>
|
|
<option value="d">Day(s)</option>
|
|
<option value="M">Month(s)</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Starting: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@_startDate" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Ending: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@_endDate" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label">Retention Log (Items): </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@_retentionHistory" />
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<button type="button" class="btn btn-success" @onclick="SaveJob">Save</button>
|
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
|
|
|
@code {
|
|
private int _jobId;
|
|
private string _name = string.Empty;
|
|
private string _jobType = string.Empty;
|
|
private string _isEnabled = "True";
|
|
private string _interval = string.Empty;
|
|
private string _frequency = string.Empty;
|
|
private string _startDate = string.Empty;
|
|
private string _endDate = string.Empty;
|
|
private string _retentionHistory = string.Empty;
|
|
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
_jobId = Int32.Parse(PageState.QueryString["id"]);
|
|
Job job = await JobService.GetJobAsync(_jobId);
|
|
if (job != null)
|
|
{
|
|
_name = job.Name;
|
|
_jobType = job.JobType;
|
|
_isEnabled = job.IsEnabled.ToString();
|
|
_interval = job.Interval.ToString();
|
|
_frequency = job.Frequency;
|
|
_startDate = (job.StartDate != null) ? job.StartDate.ToString() : string.Empty;
|
|
_endDate = (job.EndDate != null) ? job.EndDate.ToString() : string.Empty;
|
|
_retentionHistory = job.RetentionHistory.ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Loading Job {JobId} {Error}", _jobId, ex.Message);
|
|
AddModuleMessage("Error Loading Job", MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task SaveJob()
|
|
{
|
|
if (_name != string.Empty && !string.IsNullOrEmpty(_jobType) && _frequency != string.Empty && _interval != string.Empty && _retentionHistory != string.Empty)
|
|
{
|
|
var job = await JobService.GetJobAsync(_jobId);
|
|
job.Name = _name;
|
|
job.JobType = _jobType;
|
|
job.IsEnabled = Boolean.Parse(_isEnabled);
|
|
job.Frequency = _frequency;
|
|
job.Interval = int.Parse(_interval);
|
|
|
|
if (_startDate == string.Empty)
|
|
{
|
|
job.StartDate = null;
|
|
}
|
|
else
|
|
{
|
|
job.StartDate = DateTime.Parse(_startDate);
|
|
}
|
|
|
|
if (_endDate == string.Empty)
|
|
{
|
|
job.EndDate = null;
|
|
}
|
|
else
|
|
{
|
|
job.EndDate = DateTime.Parse(_endDate);
|
|
}
|
|
|
|
job.RetentionHistory = int.Parse(_retentionHistory);
|
|
|
|
try
|
|
{
|
|
job = await JobService.UpdateJobAsync(job);
|
|
await logger.LogInformation("Job Updated {Job}", job);
|
|
NavigationManager.NavigateTo(NavigateUrl());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Udate Job {Job} {Error}", job, ex.Message);
|
|
AddModuleMessage("Error Updating Job", MessageType.Error);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage("You Must Provide The Job Name, Type, Frequency, and Retention", MessageType.Warning);
|
|
}
|
|
}
|
|
|
|
}
|