feat: Working on implementing calendar. Javascript work left
This commit is contained in:
		
							parent
							
								
									c914649a8b
								
							
						
					
					
						commit
						f282b39d57
					
				
					 2 changed files with 71 additions and 17 deletions
				
			
		|  | @ -14,19 +14,15 @@ namespace turf_tasker.Controllers | ||||||
|             _context = context; |             _context = context; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // GET: LawnCareEvents |  | ||||||
|         public async Task<IActionResult> Index(string sortOrder, string searchString) |         public async Task<IActionResult> Index(string sortOrder, string searchString) | ||||||
|         { |         { | ||||||
|             // Use ViewData to pass sort order info to the view |  | ||||||
|             ViewData["DateSortParm"] = String.IsNullOrEmpty(sortOrder) ? "date_desc" : ""; |             ViewData["DateSortParm"] = String.IsNullOrEmpty(sortOrder) ? "date_desc" : ""; | ||||||
|             ViewData["TypeSortParm"] = sortOrder == "Type" ? "type_desc" : "Type"; |             ViewData["TypeSortParm"] = sortOrder == "Type" ? "type_desc" : "Type"; | ||||||
|             ViewData["CurrentFilter"] = searchString; |             ViewData["CurrentFilter"] = searchString; | ||||||
| 
 | 
 | ||||||
|             // Start with a base query that can be modified |  | ||||||
|             var events = from e in _context.LawnCareEvents |             var events = from e in _context.LawnCareEvents | ||||||
|                 select e; |                 select e; | ||||||
| 
 | 
 | ||||||
|             // Apply the filter if a search string is provided |  | ||||||
|             if (!String.IsNullOrEmpty(searchString)) |             if (!String.IsNullOrEmpty(searchString)) | ||||||
|             { |             { | ||||||
|                 events = events.Where(e =>  |                 events = events.Where(e =>  | ||||||
|  | @ -35,7 +31,6 @@ namespace turf_tasker.Controllers | ||||||
|                 ); |                 ); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             // Apply the sorting based on the sortOrder parameter |  | ||||||
|             switch (sortOrder) |             switch (sortOrder) | ||||||
|             { |             { | ||||||
|                 case "date_desc": |                 case "date_desc": | ||||||
|  | @ -51,12 +46,9 @@ namespace turf_tasker.Controllers | ||||||
|                     events = events.OrderBy(e => e.EventDate); |                     events = events.OrderBy(e => e.EventDate); | ||||||
|                     break; |                     break; | ||||||
|             } |             } | ||||||
| 
 |  | ||||||
|             // Execute the query and return the view with the filtered/sorted list |  | ||||||
|             return View(await events.AsNoTracking().ToListAsync()); |             return View(await events.AsNoTracking().ToListAsync()); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // GET: LawnCareEvents/Details/5 |  | ||||||
|         public async Task<IActionResult> Details(int? id) |         public async Task<IActionResult> Details(int? id) | ||||||
|         { |         { | ||||||
|             if (id == null) |             if (id == null) | ||||||
|  | @ -74,15 +66,13 @@ namespace turf_tasker.Controllers | ||||||
|             return View(lawnCareEvent); |             return View(lawnCareEvent); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // GET: LawnCareEvents/Create |          | ||||||
|         // MODIFIED: We now create a model with a default date. |  | ||||||
|         public IActionResult Create() |         public IActionResult Create() | ||||||
|         { |         { | ||||||
|             var model = new LawnCareEvent { EventDate = DateTime.Now }; |             var model = new LawnCareEvent { EventDate = DateTime.Now }; | ||||||
|             return View(model); |             return View(model); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // POST: LawnCareEvents/Create |  | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [ValidateAntiForgeryToken] |         [ValidateAntiForgeryToken] | ||||||
|         public async Task<IActionResult> Create([Bind("Id,EventType,EventDate,MowingPattern,Notes")] LawnCareEvent lawnCareEvent) |         public async Task<IActionResult> Create([Bind("Id,EventType,EventDate,MowingPattern,Notes")] LawnCareEvent lawnCareEvent) | ||||||
|  | @ -96,7 +86,6 @@ namespace turf_tasker.Controllers | ||||||
|             return View(lawnCareEvent); |             return View(lawnCareEvent); | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         // GET: LawnCareEvents/Edit/5 |  | ||||||
|         public async Task<IActionResult> Edit(int? id) |         public async Task<IActionResult> Edit(int? id) | ||||||
|         { |         { | ||||||
|             if (id == null) |             if (id == null) | ||||||
|  | @ -112,7 +101,6 @@ namespace turf_tasker.Controllers | ||||||
|             return View(lawnCareEvent); |             return View(lawnCareEvent); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // POST: LawnCareEvents/Edit/5 |  | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [ValidateAntiForgeryToken] |         [ValidateAntiForgeryToken] | ||||||
|         public async Task<IActionResult> Edit(int id, [Bind("Id,EventType,EventDate,MowingPattern,Notes")] LawnCareEvent lawnCareEvent) |         public async Task<IActionResult> Edit(int id, [Bind("Id,EventType,EventDate,MowingPattern,Notes")] LawnCareEvent lawnCareEvent) | ||||||
|  | @ -131,7 +119,7 @@ namespace turf_tasker.Controllers | ||||||
|                 } |                 } | ||||||
|                 catch (DbUpdateConcurrencyException) |                 catch (DbUpdateConcurrencyException) | ||||||
|                 { |                 { | ||||||
|                     if (!LawnCareEventExists(lawnCareEvent.Id)) |                     if (!LawnCareEventExists(lawnCareEvent.Id)) // This uses the private method below | ||||||
|                     { |                     { | ||||||
|                         return NotFound(); |                         return NotFound(); | ||||||
|                     } |                     } | ||||||
|  | @ -145,7 +133,6 @@ namespace turf_tasker.Controllers | ||||||
|             return View(lawnCareEvent); |             return View(lawnCareEvent); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // GET: LawnCareEvents/Delete/5 |  | ||||||
|         public async Task<IActionResult> Delete(int? id) |         public async Task<IActionResult> Delete(int? id) | ||||||
|         { |         { | ||||||
|             if (id == null) |             if (id == null) | ||||||
|  | @ -163,7 +150,6 @@ namespace turf_tasker.Controllers | ||||||
|             return View(lawnCareEvent); |             return View(lawnCareEvent); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // POST: LawnCareEvents/Delete/5 |  | ||||||
|         [HttpPost, ActionName("Delete")] |         [HttpPost, ActionName("Delete")] | ||||||
|         [ValidateAntiForgeryToken] |         [ValidateAntiForgeryToken] | ||||||
|         public async Task<IActionResult> DeleteConfirmed(int id) |         public async Task<IActionResult> DeleteConfirmed(int id) | ||||||
|  | @ -182,5 +168,36 @@ namespace turf_tasker.Controllers | ||||||
|         { |         { | ||||||
|             return _context.LawnCareEvents.Any(e => e.Id == id); |             return _context.LawnCareEvents.Any(e => e.Id == id); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         public IActionResult Calendar() | ||||||
|  |         { | ||||||
|  |             return View(); | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         [HttpGet] | ||||||
|  |         public async Task<JsonResult> GetEventsJson() | ||||||
|  |         { | ||||||
|  |             var events = await _context.LawnCareEvents.AsNoTracking().ToListAsync(); | ||||||
|  | 
 | ||||||
|  |             var calendarEvents = events.Select(e => new | ||||||
|  |             { | ||||||
|  |                 id = e.Id, | ||||||
|  |                 title = $"{e.EventType} {((e.EventType == LawnCareEventType.Mowing && e.MowingPattern.HasValue) ? $"({e.MowingPattern})" : "")}", | ||||||
|  |                 start = e.EventDate.ToString("yyyy-MM-dd"), | ||||||
|  |                 allDay = true, | ||||||
|  |                 url = $"/LawnCareEvents/Details/{e.Id}", | ||||||
|  |                 color = e.EventType switch | ||||||
|  |                 { | ||||||
|  |                     LawnCareEventType.Mowing => "#28a745", | ||||||
|  |                     LawnCareEventType.Watering => "#007bff", | ||||||
|  |                     LawnCareEventType.Fertilizing => "#ffc107", | ||||||
|  |                     LawnCareEventType.Aeration => "#6f42c1", | ||||||
|  |                     LawnCareEventType.WeedControl => "#dc3545", | ||||||
|  |                     _ => "#6c757d" | ||||||
|  |                 } | ||||||
|  |             }).ToList(); | ||||||
|  | 
 | ||||||
|  |             return Json(calendarEvents); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
							
								
								
									
										37
									
								
								Views/LawnCareEvents/Calendar.cshtml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								Views/LawnCareEvents/Calendar.cshtml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,37 @@ | ||||||
|  | @{ | ||||||
|  |     ViewData["Title"] = "Lawn Care Calendar"; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | <h1>@ViewData["Title"]</h1> | ||||||
|  | 
 | ||||||
|  | <div class="calendar-container"> | ||||||
|  |     <div class="calendar-header"> | ||||||
|  |         <button id="prevMonth" class="btn btn-secondary">< Prev</button> | ||||||
|  |         <h2 id="currentMonthYear"></h2> | ||||||
|  |         <button id="nextMonth" class="btn btn-secondary">Next ></button> | ||||||
|  |     </div> | ||||||
|  |     <div class="calendar-grid"> | ||||||
|  |         <div class="day-name">Sun</div> | ||||||
|  |         <div class="day-name">Mon</div> | ||||||
|  |         <div class="day-name">Tue</div> | ||||||
|  |         <div class="day-name">Wed</div> | ||||||
|  |         <div class="day-name">Thu</div> | ||||||
|  |         <div class="day-name">Fri</div> | ||||||
|  |         <div class="day-name">Sat</div> | ||||||
|  |     </div> | ||||||
|  |     <div id="calendarDays" class="calendar-grid"> | ||||||
|  |          | ||||||
|  |     </div> | ||||||
|  | </div> | ||||||
|  | 
 | ||||||
|  | @section Scripts { | ||||||
|  |     <script src="~/lib/jquery/dist/jquery.min.js"></script> | ||||||
|  |     <script type="text/javascript"> | ||||||
|  |         // TODO ADD CALENDAR JAVASCRIPT | ||||||
|  |     </script> | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | @section Styles { | ||||||
|  |     <!-- NEW: Link to your external calendar.css file --> | ||||||
|  |     <link href="~/css/calendar.css" rel="stylesheet" asp-append-version="true" /> | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Blake Ridgway
						Blake Ridgway