Skip to content

Commit

Permalink
Replace Telerik table; add min/max date #26
Browse files Browse the repository at this point in the history
  • Loading branch information
geofranzi committed Dec 10, 2019
1 parent a2c33ac commit fd1c46a
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 25 deletions.
28 changes: 26 additions & 2 deletions Controllers/CalendarController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,26 @@ public ActionResult OnSelectTreeViewItemFilter(string selectedItems)
//index 0 = attrbute id, index1 domainvalue
List<string> i = item.Split('_').ToList();
ResourceFilterHelper.FilterTreeItem filterItem = new ResourceFilterHelper.FilterTreeItem();
filterItem.Id = Convert.ToInt64(i[0]);
filterItem.Value = i[1].ToString();
try
{
filterItem.Id = Convert.ToInt64(i[0]);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

try
{
filterItem.Value = i[1].ToString();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

filterList.Add(filterItem);
}

Expand Down Expand Up @@ -323,6 +341,12 @@ public ActionResult GetEventsAsList(string myBookings)
else
allEvents.ForEach(r => model.Add(new BookingEventModel(r)));

foreach (BookingEventModel m in model)
{
m.startDate = m.Schedules.Select(a => a.ScheduleDurationModel.StartDate).ToList().Min();
m.endDate = m.Schedules.Select(a => a.ScheduleDurationModel.EndDate).ToList().Min();
}

return PartialView("_listEvents", model);
}

Expand Down
3 changes: 3 additions & 0 deletions Models/Booking/BookingEventModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace BExIS.Web.Shell.Areas.RBM.Models.Booking
{
public class BookingEventModel
{
public DateTime startDate;
public DateTime endDate;

public long Id { get; set; }

[StringLength(50, ErrorMessage = "The name must be {2} - {1} characters long.", MinimumLength = 3)]
Expand Down
113 changes: 90 additions & 23 deletions Views/Calendar/_listEvents.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,106 @@
@model List<BookingEventModel>

@{
GridPagerStyles pagerStyles = GridPagerStyles.PageSizeDropDown;
pagerStyles |= GridPagerStyles.NextPreviousAndNumeric;
pagerStyles |= GridPagerStyles.Numeric;
/**/

GridPagerStyles pagerStyles = GridPagerStyles.PageSizeDropDown;
pagerStyles |= GridPagerStyles.NextPreviousAndNumeric;
pagerStyles |= GridPagerStyles.Numeric;
}

<div id="events">
@(Html.Telerik().Grid(Model)
.Name("Grid_Resource")
.Columns(columns =>
<table id="booking_table" class="display" style="width:100%">
<thead>
<tr>

<th title="Name">Name</th>
<th title="Description">Description</th>
<th title="Start date">Start date</th>
<th title="End date">End date</th>

</tr>
</thead>
<tbody>


@foreach (var m in Model)
{

columns.Bound(r => r.Name);
columns.Bound(r => r.Description);
// columns.Bound(r => r.Schedules.Select(a=>a.ScheduleDurationModel.StartDate).ToList().Min());
// columns.Bound(r => r.Schedules.Select(a => a.ScheduleDurationModel.EndDate).ToList().Min());
})
.Pageable(paging =>
paging
.Style(pagerStyles)
.PageSize(10)
.Position(GridPagerPosition.Both)
)
.Filterable()
)
</div>
<tr>
<td><a href="../../RBM/Schedule/Show/@m.Id">@m.Name</a></td>
<td>@m.Description</td>
<td>@m.startDate.ToString("dd.MM.yyyy")</td>
<td>@m.endDate.ToString("dd.MM.yyyy")</td>
</tr>
}
</tbody>

</table>

<script type="text/javascript">
$(document).ready(function () {
resetAllTelerikIconTitles();
addTooltips();
})
jQuery.fn.dataTable.render.ellipsis = function ( cutoff, wordbreak, escapeHtml ) {
var esc = function ( t ) {
return t
.replace( /&/g, '&amp;' )
.replace( /</g, '&lt;' )
.replace( />/g, '&gt;' )
.replace( /"/g, '&quot;' );
};
return function ( d, type, row ) {
// Order, search and type get the original data
if ( type !== 'display' ) {
return d;
}
if ( typeof d !== 'number' && typeof d !== 'string' ) {
return d;
}
d = d.toString(); // cast numbers
if ( d.length <= cutoff ) {
return d;
}
var shortened = d.substr(0, cutoff-1);
// Find the last white space character in the string
if ( wordbreak ) {
shortened = shortened.replace(/\s([^\s]*)$/, '');
}
// Protect against uncontrolled HTML input
if ( escapeHtml ) {
shortened = esc( shortened );
}
return '<span class="ellipsis" title="'+esc(d)+'">'+shortened+'&#8230;</span>';
};
};
$("#booking_table").DataTable({
"autoWidth": false,
ordering: true,
paging: false,
responsive: true,
"columns": [
{ "width": "30%" },
{ "width": "40%" },
null,
null,
],
columnDefs: [
{
targets: 1,
render: $.fn.dataTable.render.ellipsis( 60, true )
}]
});
});
</script>

0 comments on commit fd1c46a

Please sign in to comment.