📑 IrbyImaging | Views/FieldLog/ViewTimesheets.cshtml
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- ViewModel & DataModel
- Key Functional Areas
- Helper Methods & Utilities 🔧
- Error Handling & Return Types 🚨
- API Endpoints Overview 🌐
- Third‑Party Integrations 🤝
- Sample Code Blocks & Usage Examples 💡
- UML Diagram 📈
- Conclusion 🏁
Overview & Purpose
ViewTimesheets.cshtml is an ASP.NET MVC Razor View for the IrbyImaging FieldLog module. It allows users to:
- Filter timesheets by work date, crew, creator, job #, and cost code
- View results in a rich Syncfusion EJ2 Grid (paging, sorting, filtering, Excel export)
- Perform actions (Edit, Copy, Export, Delete) on individual timesheets
- Bulk export a week's timesheets to Excel, with timezone‐aware formatting
- Confirm destructive actions via Bootstrap modals
Dependencies & Technologies
| Category | Library / Framework |
|---|---|
| Backend | ASP.NET Core MVC, Razor |
| Frontend Controls | Syncfusion EJ2 (Grid, DatePicker, DropDownList, etc.) |
| Styling | Bootstrap 5, Custom CSS |
| AJAX | Fetch API (JSON), jQuery AJAX (Blob downloads) |
| Security | Anti-Forgery Token |
ViewModel & DataModel
@model IEnumerable<IrbyImaging.UI.Models.TimesheetListViewModel>
TimesheetListViewModel (inferred):
| Property | Type | Description |
|---|---|---|
| TimesheetId | Guid/int | Unique ID |
| TimesheetNumber | string | User‐friendly timesheet # |
| Job | string | Job Number |
| CrewName | string | Crew name |
| WorkDate | DateTime | Date of work |
| TotalHours | decimal | Total hours worked |
| CreatedBy | string | Name of creator |
Key Functional Areas
1. Search Form 🕵️♂️
A row of Syncfusion components for filtering:
<ejs-datepicker id="workDate" placeholder="Select Work Date"></ejs-datepicker>
<ejs-dropdownlist id="crewSearch" dataSource="@ViewBag.Crews" ...></ejs-dropdownlist>
<ejs-textbox id="createdBy" placeholder="Enter Creator Name"></ejs-textbox>
<ejs-textbox id="jobNumber" placeholder="Enter Job Number"></ejs-textbox>
<ejs-textbox id="costCode" placeholder="Enter Cost Code"></ejs-textbox>
<ejs-button id="searchBtn" content="Search" isPrimary="true"></ejs-button>
<ejs-button id="clearBtn" content="Clear"></ejs-button>
- DatePicker for Work Date
- DropDownList for Crew (filterable, clearable)
- TextBoxes for Creator, Job #, Cost Code
- Buttons trigger
performSearch()&clearForm()
2. Timesheet Grid 📊
<ejs-grid id="TimesheetGrid"
allowPaging="true"
allowSorting="true"
allowFiltering="true"
allowResizing="true"
allowExcelExport="true"
gridLines="Both"
height="450">
<e-grid-pagesettings pageSize="11"></e-grid-pagesettings>
<e-grid-filterSettings type="Excel"></e-grid-filterSettings>
<e-grid-columns>
<e-grid-column field="TimesheetNumber" headerText="Timesheet #" width="100"></e-grid-column>
<e-grid-column field="Job" headerText="Job Number" width="160"></e-grid-column>
<e-grid-column field="CrewName" headerText="Crew" width="140"></e-grid-column>
<e-grid-column field="WorkDate" headerText="Work Date" type="date" format="yMd" width="110"></e-grid-column>
<e-grid-column field="TotalHours" headerText="Total Hours" format="N2" width="100"></e-grid-column>
<e-grid-column field="CreatedBy" headerText="Created By" width="160"></e-grid-column>
<e-grid-column headerText="Actions" template="#actionTemplate" width="140"></e-grid-column>
</e-grid-columns>
</ejs-grid>
Features:
- Paging, Sorting, Filtering, Resizing
- Excel export on all pages
- Custom Actions column
3. Action Buttons 🎯
Defined via a <script id="actionTemplate"> template:
<a href="#" class="edit-link" data-id="${TimesheetId}">Edit</a>
<a href="#" class="copy-link" data-id="${TimesheetId}">Copy</a>
<a href="#" class="export-link" data-id="${TimesheetId}">Export</a>
@if (ViewBag.HasDeletePermission) {
<a href="#" class="delete-link" data-id="${TimesheetId}" data-number="${TimesheetNumber}">Delete</a>
}
- Edit →
/TimeEntry/EditTimesheet/{id}(new tab) - Copy →
/TimeEntry/CopyTimesheet/{id} - Export →
/TimeEntry/ExportFieldTimesheet/{id}+ timezone params - Delete → triggers
deleteTimesheet()modal flow
4. Bulk Export Modal 🔄
User selects a Sunday and exports the entire week (Mon–Sun):
<ejs-datepicker id="bulkExportDate" showClearButton="true"></ejs-datepicker>
<ejs-button id="bulkExportBtn" content="Export Timesheet Date Range"></ejs-button>
Modal summary:
- Calculates start (Monday) & end (Sunday)
- Displays a small table of timesheet summary
- On confirm → posts to
/TimeEntry/ExportBulkTimesheets - Receives an Excel file (Blob) via jQuery AJAX
5. Delete Confirmation Modal ❌
<div id="deleteConfirmModal" class="modal fade">
<div id="confirmPhase">Are you sure you want to delete Timesheet #<span id="timesheetToDelete"></span>?</div>
<div id="responsePhase" style="display:none;">
<div id="successMessage" class="alert alert-success"></div>
<div id="errorMessage" class="alert alert-danger"></div>
</div>
<button id="confirmDeleteBtn" class="btn btn-danger">Delete</button>
</div>
- deleteTimesheet(id, #) shows modal
- Confirm →
POST /TimeEntry/DeleteTimesheetwith{ timesheetId }+ Anti‑Forgery token - Success → removes row, shows success in modal
- Failure → shows error message
6. Loading Spinner Modal ⏳
<div id="loadingSpinnerModal" style="display:none;">
<div class="spinner-border"></div>
<p>Exporting to Excel...</p>
</div>
Used during bulk export to block UI until file download begins.
Helper Methods & Utilities 🔧
- deleteTimesheet
(id, number) - showConfirmationPhase / showResponsePhase
- crewFilter for DropDownList
- getComponentValue
- performSearch & clearForm
- getTimezoneAbbreviation
- TimesheetBulkExport IIFE
init,initDatePicker,showExportModal,performBulkExport
All initialized on DOMContentLoaded.
Error Handling & Return Types 🚨
- Fetch API: checks
response.ok,.catch()on network errors - Delete & Search → expects JSON
{ success: bool, message?: string } - Bulk Export → Blob response, extracts filename from
Content-Disposition - UI feedback via alerts and modal messages
API Endpoints Overview 🌐
| Action | Verb | URL | Payload/Query | Response |
|---|---|---|---|---|
| View Timesheets (AJAX) | GET | /TimeEntry/ViewTimesheets?filters… |
QueryString filters | JSON[] |
| Delete Timesheet | POST | /TimeEntry/DeleteTimesheet |
{ timesheetId } + XSRF token |
{ success, message } |
| Edit Timesheet | GET | /TimeEntry/EditTimesheet/{id} |
— | HTML form |
| Copy Timesheet | GET | /TimeEntry/CopyTimesheet/{id} |
— | HTML form |
| Export Single Timesheet | GET | /TimeEntry/ExportFieldTimesheet/{id} |
timezone, offset, label |
File (Excel) |
| Bulk Export Timesheets | POST | /TimeEntry/ExportBulkTimesheets |
timesheetIds[], startDate, etc. |
File Blob (Excel) |
Third‑Party Integrations 🤝
- Syncfusion EJ2 (DatePicker, DropDownList, Grid, Button)
- Bootstrap 5 (Grid, Modals, Buttons)
- jQuery AJAX (Blob download)
- Fetch API (JSON operations)
Sample Code Blocks & Usage Examples 💡
Perform Search
function performSearch() {
const workDate = getComponentValue('workDate');
const crewId = getComponentValue('crewSearch');
const createdBy = getComponentValue('createdBy');
const jobNumber = getComponentValue('jobNumber');
const costCode = getComponentValue('costCode');
const qs = new URLSearchParams({ workDate, crewId, createdBy, jobNumber, costCode }).toString();
grid.showSpinner();
fetch(`/TimeEntry/ViewTimesheets?${qs}`, {
headers: { 'X-Requested-With': 'XMLHttpRequest' }
})
.then(r => {
if (!r.ok) throw new Error(r.statusText);
return r.json();
})
.then(data => {
grid.dataSource = data;
grid.refresh();
})
.catch(err => { alert('Search error.'); console.error(err); })
.finally(() => grid.hideSpinner());
}
Delete Timesheet
confirmDeleteBtn.addEventListener('click', () => {
const token = document.querySelector('input[name="__RequestVerificationToken"]').value;
confirmDeleteBtn.disabled = true;
fetch('/TimeEntry/DeleteTimesheet', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'RequestVerificationToken': token
},
body: JSON.stringify({ timesheetId: timesheetIdToDelete })
})
.then(r => r.json())
.then(data => showResponsePhase(data.success, data.message))
.catch(err => showResponsePhase(false, 'Error deleting.'))
.finally(() => {
confirmDeleteBtn.disabled = false;
});
});
UML Diagram 📈
sequenceDiagram
participant U as User
participant V as ViewTimesheets.cshtml
participant S as TimeEntryController
participant DB as Database
U->>V: Fill & Submit Search
V->>S: GET /ViewTimesheets?filters
S->>DB: SELECT * FROM Timesheets
DB--)S: Timesheet records
S--)V: JSON data
V->>Grid: load rows
U->>V: Click Delete on Timesheet
V->>V: Show Delete Modal
U->>V: Confirm Delete
V->>S: POST /DeleteTimesheet {id}
S->>DB: DELETE timesheet
DB--)S: Success/Failure
S--)V: { success, message }
V->>V: showResponsePhase()
V->>Grid: remove row
Conclusion 🏁
The ViewTimesheets.cshtml Razor View delivers a powerful, user‑friendly interface for field timesheet management within IrbyImaging. By combining Syncfusion EJ2 components with Bootstrap styling and robust JavaScript utilities, it supports complex operations—filtering, editing, deleting, exporting (single & bulk)—while providing clear feedback and preserving security via anti‑forgery tokens. This modular design can be extended or customized for future business requirements.