-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Note expiry time now use times instead of timestamps! #33262
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,17 @@ public sealed partial class NoteEdit : FancyWindow | |
[Dependency] private readonly IGameTiming _gameTiming = default!; | ||
[Dependency] private readonly IClientConsoleHost _console = default!; | ||
|
||
private enum Multipliers | ||
{ | ||
Minutes, | ||
Hours, | ||
Days, | ||
Weeks, | ||
Months, | ||
Years, | ||
Centuries | ||
} | ||
|
||
public event Action<int, NoteType, string, NoteSeverity?, bool, DateTime?>? SubmitPressed; | ||
|
||
public NoteEdit(SharedAdminNote? note, string playerName, bool canCreate, bool canEdit) | ||
|
@@ -31,6 +42,20 @@ public NoteEdit(SharedAdminNote? note, string playerName, bool canCreate, bool c | |
|
||
ResetSubmitButton(); | ||
|
||
// It's weird to use minutes as the IDs, but it works and makes sense kind of :) | ||
ExpiryLengthDropdown.AddItem(Loc.GetString("admin-note-button-minutes"), (int) Multipliers.Minutes); | ||
ExpiryLengthDropdown.AddItem(Loc.GetString("admin-note-button-hours"), (int) Multipliers.Hours); | ||
ExpiryLengthDropdown.AddItem(Loc.GetString("admin-note-button-days"), (int) Multipliers.Days); | ||
ExpiryLengthDropdown.AddItem(Loc.GetString("admin-note-button-weeks"), (int) Multipliers.Weeks); | ||
ExpiryLengthDropdown.AddItem(Loc.GetString("admin-note-button-months"), (int) Multipliers.Months); | ||
ExpiryLengthDropdown.AddItem(Loc.GetString("admin-note-button-years"), (int) Multipliers.Years); | ||
ExpiryLengthDropdown.AddItem(Loc.GetString("admin-note-button-centuries"), (int) Multipliers.Centuries); | ||
Comment on lines
+46
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These all end up showing as "1 Minutes", etc. Something to note I guess? Localized downstreams might be a bit annoyed too, as numbers can cause words to change a fair bit. |
||
ExpiryLengthDropdown.OnItemSelected += OnLengthChanged; | ||
|
||
ExpiryLengthDropdown.SelectId((int) Multipliers.Weeks); | ||
|
||
ExpiryLineEdit.OnTextChanged += OnTextChanged; | ||
|
||
TypeOption.AddItem(Loc.GetString("admin-note-editor-type-note"), (int) NoteType.Note); | ||
TypeOption.AddItem(Loc.GetString("admin-note-editor-type-message"), (int) NoteType.Message); | ||
TypeOption.AddItem(Loc.GetString("admin-note-editor-type-watchlist"), (int) NoteType.Watchlist); | ||
|
@@ -172,8 +197,9 @@ private void UpdatePermanentCheckboxFields() | |
{ | ||
ExpiryLabel.Visible = !PermanentCheckBox.Pressed; | ||
ExpiryLineEdit.Visible = !PermanentCheckBox.Pressed; | ||
ExpiryLengthDropdown.Visible = !PermanentCheckBox.Pressed; | ||
|
||
ExpiryLineEdit.Text = !PermanentCheckBox.Pressed ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : string.Empty; | ||
ExpiryLineEdit.Text = !PermanentCheckBox.Pressed ? 1.ToString() : string.Empty; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Kinda odd but, I guess alright? |
||
} | ||
|
||
private void OnSecretPressed(BaseButton.ButtonEventArgs _) | ||
|
@@ -187,6 +213,16 @@ private void OnSeverityChanged(OptionButton.ItemSelectedEventArgs args) | |
SeverityOption.SelectId(args.Id); | ||
} | ||
|
||
private void OnLengthChanged(OptionButton.ItemSelectedEventArgs args) | ||
{ | ||
ExpiryLengthDropdown.SelectId(args.Id); | ||
} | ||
|
||
private void OnTextChanged(HistoryLineEdit.LineEditEventArgs args) | ||
{ | ||
ParseExpiryTime(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be neat to have it change between "60 minutes => 1 hour", but at the same time might be a bit annoying. |
||
} | ||
|
||
private void OnSubmitButtonPressed(BaseButton.ButtonEventArgs args) | ||
{ | ||
if (!ParseExpiryTime()) | ||
|
@@ -263,13 +299,24 @@ private bool ParseExpiryTime() | |
return true; | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(ExpiryLineEdit.Text) || !DateTime.TryParse(ExpiryLineEdit.Text, out var result) || DateTime.UtcNow > result) | ||
if (string.IsNullOrWhiteSpace(ExpiryLineEdit.Text) || !uint.TryParse(ExpiryLineEdit.Text, out var inputInt)) | ||
{ | ||
ExpiryLineEdit.ModulateSelfOverride = Color.Red; | ||
return false; | ||
} | ||
|
||
ExpiryTime = result.ToUniversalTime(); | ||
var mult = ExpiryLengthDropdown.SelectedId switch | ||
{ | ||
(int) Multipliers.Minutes => TimeSpan.FromMinutes(1).TotalMinutes, | ||
(int) Multipliers.Hours => TimeSpan.FromHours(1).TotalMinutes, | ||
(int) Multipliers.Days => TimeSpan.FromDays(1).TotalMinutes, | ||
(int) Multipliers.Weeks => TimeSpan.FromDays(7).TotalMinutes, | ||
(int) Multipliers.Months => TimeSpan.FromDays(30).TotalMinutes, | ||
(int) Multipliers.Years => TimeSpan.FromDays(365).TotalMinutes, | ||
(int) Multipliers.Centuries => TimeSpan.FromDays(36525).TotalMinutes, | ||
_ => throw new ArgumentOutOfRangeException(nameof(ExpiryLengthDropdown.SelectedId), "Multiplier out of range :(") | ||
}; | ||
ExpiryTime = DateTime.UtcNow.AddMinutes(inputInt * mult); | ||
ExpiryLineEdit.ModulateSelfOverride = null; | ||
return true; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do wish this somehow shown the resulting end date, get admins to double-check when the note expires. But probably not that big of a concern.