Skip to content

Commit

Permalink
Merge pull request #33 from gismofx/dev
Browse files Browse the repository at this point in the history
Clean up code and comments
  • Loading branch information
gismofx committed May 3, 2022
2 parents ffeb992 + 174e3e3 commit b826b05
Show file tree
Hide file tree
Showing 17 changed files with 45,977 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,25 @@ public async Task InitCalendarDataAsync()
{
StartDate = DateTimeOffset.Now;
EndDate = DateTimeOffset.Now;

//Todo: Add More Template Examples
//TUITemplate calendarTemplate = null;
var calendarTemplate = new TUITemplate();
calendarTemplate.AddMonthGridHeaderExceed(@"return '<span class=""weekday-grid-more-schedules"">+' + hiddenSchedules + ' says gismofx' + '</span>';");


var month = new TUIMonthOptions()
{
//daynames = new[] { "Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado" },
//startDayOfWeek = 0,
visibleWeeksCount = 6,
//visibleScheduleCount = 0,
};


//optionally setup timezones for display
var timeZones = new TUICalendarTimeZoneOption();
timeZones.AddTimeZone(TimeZoneInfo.Local);
timeZones.AddTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time"));

//Set the Calendar Options
CalendarOptions = new TUICalendarOptions()
Expand All @@ -105,8 +115,9 @@ public async Task InitCalendarDataAsync()
defaultView = TUICalendarViewName.Month,
taskView = false,
scheduleView = true,
month = month

month = month,
TUItemplate = calendarTemplate,
timezone = timeZones
};

var calendarProps = new List<TUICalendarProps>();
Expand Down
34 changes: 5 additions & 29 deletions toast_ui.blazor_calendar/Models/TUICalendarOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using toast_ui.blazor_calendar.Services;
Expand Down Expand Up @@ -43,6 +44,8 @@ public class TUICalendarOptions
/// https://nhn.github.io/tui.calendar/latest/Template
/// had to rename from 'template' - violates naming rule
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("template")]
public TUITemplate TUItemplate { get; set; } = null;

/// <summary>
Expand Down Expand Up @@ -75,7 +78,8 @@ public class TUICalendarOptions
/// You can add secondary timezone in the weekly/daily view.
/// https://nhn.github.io/tui.calendar/latest/Timezone
/// </summary>
public TimeZoneInfo timezone { get; set; } //Todo: Map this or implement TUI timezone class
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public TUICalendarTimeZoneOption timezone { get; set; } = null;

/// <summary>
/// Disable double click to create a schedule.
Expand Down Expand Up @@ -187,32 +191,4 @@ private bool CompareMembers(TUICalendarOptions options)
}

}

public class TUICalendarViewName
{
private TUICalendarViewName(string value)
{
Value = value;
}
public string Value { get; set; }

public static TUICalendarViewName Day { get { return new TUICalendarViewName("day"); } }
public static TUICalendarViewName Week { get { return new TUICalendarViewName("week"); } }
public static TUICalendarViewName Month { get { return new TUICalendarViewName("month"); } }

}

public class TUITaskView
{
private TUITaskView(string[] value)
{
Value = value;
}
public string[] Value { get; set; }

public static TUITaskView MilestoneAndTask { get { return new TUITaskView(new[] { "milestone", "task" }); }}
public static TUITaskView Milestone { get { return new TUITaskView(new[] { "milestone" }); } }
public static TUITaskView Task { get { return new TUITaskView(new[] { "task" }); } }
public static TUITaskView None { get { return new TUITaskView(new[] { "" }); } }
}
}
118 changes: 118 additions & 0 deletions toast_ui.blazor_calendar/Models/TUICalendarTimeZoneOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace toast_ui.blazor_calendar.Models
{
/// <summary>
/// Timezone options defined here https://nhn.github.io/tui.calendar/latest/Timezone
/// </summary>
public class TUICalendarTimeZoneOption
{
/// <summary>
/// List of TUITimeZone calendar time zones
/// </summary>
public List<TUITimeZone> zones { get; set; }

/// <summary>
/// Function Expression to return the Display Label
/// </summary>
[JsonIgnore]
public Func<TimeZoneInfo, string> DisplayLabelFunction { get; set; } = null;

/// <summary>
/// Function Expression to return the Tool Tip
/// </summary>
[JsonIgnore]
public Func<TimeZoneInfo, string> ToolTipFunction { get; set; } = null;

/// <summary>
/// Constructs a default TUICalendarTimeZoneOption
/// </summary>
public TUICalendarTimeZoneOption()
{
zones = new List<TUITimeZone>();
}

/// <summary>
/// Constructs TUICalendarTimeZoneOption with expressions to set the display label and tool tip
/// </summary>
/// <param name="displayLabelFunction">Function Expression to return the Display Label</param>
/// <param name="toolTipFunction">Function Expression to return the Tool Tip</param>
public TUICalendarTimeZoneOption(Func<TimeZoneInfo, string> displayLabelFunction, Func<TimeZoneInfo, string> toolTipFunction): this()
{
DisplayLabelFunction = displayLabelFunction;
ToolTipFunction = toolTipFunction;
}

/// <summary>
/// Convert a TimeZoneInfo object into a TUITimeZone Object
/// </summary>
/// <param name="timeZoneInfo"></param>
/// <returns></returns>
public bool AddTimeZone(TimeZoneInfo timeZoneInfo)
{
var TUItz = ToTuiTimeZone(timeZoneInfo);
if (TUItz is null)
return false;

zones.Add(TUItz);
return true;
}

/// <summary>
/// Converts a TimeZoneInfo into a TUI Defined Time Zone object
/// </summary>
/// <param name="timeZoneInfo">TimeZoneInfo</param>
/// <returns>TUITimeZone</returns>
private TUITimeZone ToTuiTimeZone(TimeZoneInfo timeZoneInfo)
{
//if unable to get the IanaId return a null object
if (!TimeZoneInfo.TryConvertWindowsIdToIanaId(timeZoneInfo.Id, out string timezoneName)) return null;

//create default options based on the example https://nhn.github.io/tui.calendar/latest/Timezone
//if the user specified a function to get the
//display label use that
string displayLabel;
if (DisplayLabelFunction != null)
{
displayLabel = DisplayLabelFunction(timeZoneInfo);
}
else
{
string positiveOrNegative = timeZoneInfo.BaseUtcOffset < TimeSpan.Zero ? "-" : "+";
displayLabel = $"GMT{positiveOrNegative}{timeZoneInfo.BaseUtcOffset:hh\\:mm}";
}

/* Why won't this lamba compile
string displayLabel = DisplayLabelFunction(timeZoneInfo) ?? (() =>
{
string positiveOrNegative = timeZoneInfo.BaseUtcOffset < TimeSpan.Zero ? "-" : "+";
return $"GMT{positiveOrNegative}{timeZoneInfo.BaseUtcOffset:hh\\:mm}";
});
*/

//if the user specified a function to get the tooltip use that

//Why do these not work?
//var tooltip = ToolTipFunction?.Invoke(timeZoneInfo) ?? timeZoneInfo.StandardName;
//var tooltip = ToolTipFunction(timeZoneInfo) ?? timeZoneInfo.StandardName;
string tooltip;
if (ToolTipFunction is null)
{
tooltip = timeZoneInfo.StandardName;
}
else
{
tooltip = ToolTipFunction(timeZoneInfo);
}

return new TUITimeZone
{
timezoneName = timezoneName,
displayLabel = displayLabel,
tooltip = tooltip
};
}
}
}
30 changes: 30 additions & 0 deletions toast_ui.blazor_calendar/Models/TUICalendarViewName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace toast_ui.blazor_calendar.Models
{
/// <summary>
/// Enum Class/Helper For TUI Calendar Views
/// </summary>
public class TUICalendarViewName
{
public static TUICalendarViewName Day { get { return new TUICalendarViewName("day"); } }
public static TUICalendarViewName Week { get { return new TUICalendarViewName("week"); } }
public static TUICalendarViewName Month { get { return new TUICalendarViewName("month"); } }

private TUICalendarViewName(string value)
{
Value = value;
}
public string Value { get; set; }

public override string ToString()
{
return Value;
}

}
}
3 changes: 2 additions & 1 deletion toast_ui.blazor_calendar/Models/TUIMonthOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public class TUIMonthOptions
public int? visibleScheduleCount { get; set; } = null;

/// <summary>
/// The more layer size
/// The
/// layer size
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object moreLayerSize { get; set; } = null; //@Todo: What is this?
Expand Down
27 changes: 27 additions & 0 deletions toast_ui.blazor_calendar/Models/TUITaskView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace toast_ui.blazor_calendar.Models
{
/// <summary>
/// Enum Class/Helper For TUI Task View Modes
/// </summary>
public class TUITaskView
{

public static TUITaskView MilestoneAndTask { get { return new TUITaskView(new[] { "milestone", "task" }); } }
public static TUITaskView Milestone { get { return new TUITaskView(new[] { "milestone" }); } }
public static TUITaskView Task { get { return new TUITaskView(new[] { "task" }); } }
public static TUITaskView None { get { return new TUITaskView(new[] { "" }); } }

private TUITaskView(string[] value)
{
Value = value;
}
public string[] Value { get; set; }

}
}
Loading

0 comments on commit b826b05

Please sign in to comment.