Skip to content

Commit

Permalink
Refactor codebase for modern practices
Browse files Browse the repository at this point in the history
- Updated `Gruntfile.js` to use `const` for declaring the `sass` variable.
- Renamed and simplified methods in `Constants.cs` for clarity and efficiency.
- Removed unnecessary `using` directives and renamed methods in `Location.Parser.cs` for better readability.
- Corrected logical operators in `StringHelper.cs` and `ColorMath.cs` to ensure proper short-circuit evaluation.
- Changed nullable boolean properties to non-nullable in `EditModel.cs`.
- Converted `CalendarDisplayModel` property to a method in `NewsletterModel.cs`.
- Improved variable checks and declarations in JavaScript files for robustness and modern standards.
- Applied similar updates to `Site.TempusDominusFactory.min.js` for consistency.
- Updated `Show.cshtml` to reflect changes in `NewsletterModel.cs`.
  • Loading branch information
axunonb committed Jul 19, 2024
1 parent ba4d371 commit 480f2b6
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Src/TournamentCalendar/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Click here to learn more. https://go.microsoft.com/fwlink/?LinkID=513275&clcid=0
console.log(`Node ${process.version}`); // node version
module.exports = function (grunt) {
'use strict';
var sass = require('node-sass'); // used in grunt-sass options, must be included in package.json
const sass = require('node-sass'); // used in grunt-sass options, must be included in package.json

grunt.loadNpmTasks('grunt-sass'); // Bootstrap 5 uses https://sass-lang.com/dart-sass; they also maintain the node-sass package
grunt.loadNpmTasks('@lodder/grunt-postcss'); // grunt-postcss is retired, use @lodder/grunt-postcss
Expand Down
10 changes: 5 additions & 5 deletions Src/TournamentCalendar/Library/Authentication/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ public class RoleName
/// Get the values of all constants in this class.
/// </summary>
/// <returns>Returns the values of all constants in this class.</returns>
public static IEnumerable<T?> GetAllValues<T>()
public static IEnumerable<T?> GetAllRoleValues<T>()
{
return Constants.GetAllValues<T>(typeof(RoleName));
return GetAllValues<T>(typeof(RoleName));
}

/// <summary>
/// Get the names of all constants in this class.
/// </summary>
/// <returns>Returns the names of all constants in this class.</returns>
public static IEnumerable<string> GetAllNames()
public static IEnumerable<string> GetAllRoleNames()
{
return Constants.GetAllNames(typeof(RoleName));
return GetAllNames(typeof(RoleName));
}
}

Expand Down Expand Up @@ -59,4 +59,4 @@ private static IEnumerable<string> GetAllNames(IReflect type)
if (val != null) yield return val;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;

namespace Axuno.Tools.GeoSpatial;

Expand Down Expand Up @@ -120,7 +118,7 @@ private static double MakeSameSign(double source, double value)
return value;
}

private static Location? Parse(string input, IFormatProvider? provider, Regex regex)
private static Location? ParseLocation(string input, IFormatProvider? provider, Regex regex)
{
var match = regex.Match(input.Replace(", ", " "));
if (!match.Success) return null;
Expand Down Expand Up @@ -199,7 +197,7 @@ private static double MakeSameSign(double source, double value)
internal static Location? ParseDegrees(string value, IFormatProvider? provider)
{
if (string.IsNullOrWhiteSpace(value)) return null;
return Parse(value, provider, DegreeRegex);
return ParseLocation(value, provider, DegreeRegex);
}

/// <summary>
Expand All @@ -216,7 +214,7 @@ private static double MakeSameSign(double source, double value)
internal static Location? ParseDegreesMinutes(string value, IFormatProvider? provider)
{
if (string.IsNullOrWhiteSpace(value)) return null;
return Parse(value, provider, DegreeMinuteRegex);
return ParseLocation(value, provider, DegreeMinuteRegex);
}

/// <summary>
Expand All @@ -233,7 +231,7 @@ private static double MakeSameSign(double source, double value)
internal static Location? ParseDegreesMinutesSeconds(string value, IFormatProvider? provider)
{
if (string.IsNullOrWhiteSpace(value)) return null;
return Parse(value, provider, DegreeMinuteSecondRegex);
return ParseLocation(value, provider, DegreeMinuteSecondRegex);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Src/TournamentCalendar/Library/Axuno.Tools/StringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ public static DataTable ConvertHtmlTableToDataTable(string html)
foreach (Match rowMatch in rowMatches)
{
// Only loop through the row if it isn't a header row
if (!(currRow == 0 & headerExists))
if (!(currRow == 0 && headerExists))
{
// Create a new row and reset the current column counter
var dr = dt.NewRow();
Expand Down
4 changes: 2 additions & 2 deletions Src/TournamentCalendar/Library/ColorMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class ColorMath
{
public static Color? FromHtmlColor(string htmlColor)
{
if (htmlColor.StartsWith("#") & (htmlColor.Length == 7 | htmlColor.Length == 4) &
if (htmlColor.StartsWith("#") && (htmlColor.Length == 7 || htmlColor.Length == 4) &&
htmlColor.Substring(1).All(c => "ABCDEF0123456789".IndexOf(char.ToUpper(c)) != -1))
{
return (Color?) new ColorConverter().ConvertFromString(htmlColor);
Expand Down Expand Up @@ -343,4 +343,4 @@ public HSLColor(double hue, double saturation, double luminosity)
this.Luminosity = luminosity;
}

}
}
4 changes: 2 additions & 2 deletions Src/TournamentCalendar/Models/Calendar/EditModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public int? MinMaxMale
/// means to toggle the approval status:
/// if (ShowTournament) { "Click to hide the tournament" } else { "Click to show the tournament" }
/// </summary>
public bool? ShowTournament
public bool ShowTournament
{
get
{
Expand All @@ -260,7 +260,7 @@ public bool? ShowTournament
else
{
// Set deletion date, if tournament shall not be displayed
base.DeletedOn = value is true ? DateTime.Now : null;
base.DeletedOn = value ? DateTime.Now : null;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Src/TournamentCalendar/Models/Contact/ContactModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public ContactModel()

public string? Subject { get; set; }
public string? Message { get; set; }
public bool? CarbonCopyToSender { get; set; }
public bool CarbonCopyToSender { get; set; } //NOSONAR


public new void Normalize(ModelStateDictionary modelState)
Expand Down
5 changes: 3 additions & 2 deletions Src/TournamentCalendar/Models/Newsletter/NewsletterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ private async Task LoadCalendarEntitiesSinceLastSend(CancellationToken cancellat

public ICollection<SentNewsletterEntity> Newsletters { get; private set; } = new HashSet<SentNewsletterEntity>();

public ICollection<CalendarEntityDisplayModel> CalendarDisplayModel => _tournaments
.Select(t => new CalendarEntityDisplayModel(t, _surfaces, _playingAbilities)).ToList();
public ICollection<CalendarEntityDisplayModel> GetCalendarDisplayModel() =>
_tournaments
.Select(t => new CalendarEntityDisplayModel(t, _surfaces, _playingAbilities)).ToList();

public DateTime LastSendDate { get; private set; }

Expand Down
12 changes: 6 additions & 6 deletions Src/TournamentCalendar/Scripts/Site.Location.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// All Site scripts go into the same namespace
if (Site === undefined) {
if (typeof Site === 'undefined') {
var Site = {};
}

Expand Down Expand Up @@ -94,7 +94,7 @@ Site.Location = class {
// requires https://maps.googleapis.com/maps/api/js
// Example for async/await: https://gabrieleromanato.name/javascript-how-to-use-the-google-maps-api-with-promises-and-async-await
const address = this.getAddress(true);
var response = await this.geocoder.geocode({ 'address': address })
const response = await this.geocoder.geocode({ 'address': address });
const results = response.results;
if (Array.isArray(results)) {
const latitude = results[0].geometry.location.lat();
Expand All @@ -116,10 +116,10 @@ Site.Location = class {
mapTypeId: google.maps.MapTypeId.ROADMAP
};

//create the map, and place it in the HTML map div
// create the map, and place it in the HTML map div
const map = new google.maps.Map(this.mapPlaceholderEle, mapOptions);

//place the initial marker
// place the initial marker
const marker = new google.maps.Marker({
position: coords,
map: map,
Expand All @@ -130,7 +130,7 @@ Site.Location = class {
/**
* Initializes the Google Maps canvas element
* @param {string} mapPlaceholderId - The Id of the map placeholder
* @param {any} coords - Optional: the LatLng coodinates to center the map initially. Default location is Kassel/Germany.
* @param {any} coords - Optional: the LatLng coordinates to center the map initially. Default location is Kassel/Germany.
*/
static initMap(mapPlaceholderId, coords) {
const mapPlaceholderEle = document.getElementById(mapPlaceholderId);
Expand All @@ -140,6 +140,6 @@ Site.Location = class {
mapTypeControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
new google.maps.Map(mapPlaceholderEle, mapOptions);
const map = new google.maps.Map(mapPlaceholderEle, mapOptions);
}
}
8 changes: 5 additions & 3 deletions Src/TournamentCalendar/Scripts/Site.TempusDominusFactory.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// All Site scripts go into the same namespace
if (Site === undefined) {
if (typeof Site === 'undefined') {
var Site = {};
}
if (tempusDominus === undefined) { tempusDominus = window.tempusDominus; }
if (typeof tempusDominus === 'undefined') {
var tempusDominus = window.tempusDominus;
}

Site.TempusDominusFactory = class {
'use strict';
Expand All @@ -18,7 +20,7 @@ Site.TempusDominusFactory = class {
this.tdLocale = tempusDominus.locales[locale] || tempusDominus.locales[fallbackLocale];
// .NET always uses ante meridiem designator for hours 0:00:00 (midnight) to 11:59:59.999,
// and post meridiem designator for later hours (after noon).
this.tdHourCycle = hourCycle == 12 ? 'h11' : 'h23';
this.tdHourCycle = hourCycle === 12 ? 'h11' : 'h23';
this.useBiIcons = useBiIcons;

this._setTdDefaults();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Src/TournamentCalendar/Views/Newsletter/Show.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="mb-4">
<h4 class="h4">Turniere seit letztem Newsletter</h4>
<span class="btn btn-primary me-2 mb-3">
@Model.CalendarDisplayModel.Count
@Model.GetCalendarDisplayModel().Count
</span>
<span>@((await Model.GetRecipients()).Count) aktive Abonnenten</span>
</div>
Expand Down

0 comments on commit 480f2b6

Please sign in to comment.