📄 IrbyImaging/Views/FieldLog/Create.cshtml Documentation


📖 Table of Contents

  1. 🎯 Overview & Purpose
  2. 🛠 Dependencies & Technologies
  3. 🗂 View Model & Data Model
  4. 🔑 Key Functional Areas
  5. 📋 Markup & Layout
  6. 🎨 Styling & Theming
  7. 🛰 Third‑Party Integrations
  8. 🛠 Helper Functions & Utilities (JavaScript)
  9. 🔄 Data Flow & Interaction (Sequence Diagram)
  10. 🖥 Usage Examples & Code Snippets
  11. 📈 API Endpoint Overview
  12. ⚠️ Error Handling & Validation
  13. ✅ Conclusion

🎯 Overview & Purpose

This Razor view Create.cshtml under Views/FieldLog implements a “Create New Field Log” form for the IrbyImaging application.
It allows mechanics to:

  • Pick a work date and start/end times
  • Select a field office
  • Add/remove job entries via a rich Syncfusion grid with a modal dialog
  • Submit the completed timesheet (backed by MechanicTimesheet model)

✨ Why?
Mechanics use this to log daily work activities, tying time to specific jobs and offices, and then save to the database via the TimeEntryController.


🛠 Dependencies & Technologies

Category Library / Tech
UI Components Syncfusion EJ2 (Grid, DatePicker, TimePicker, Dialog, DropDownList)
JavaScript Utilities jQuery, DataTables, Dropzone, MetisMenu, SimpleBar, Waves, Bootstrap Bundle
Styling Bootstrap Datepicker CSS, DataTables CSS, Fluent theme (Syncfusion)
Data Serialization Newtonsoft.Json
.NET / Razor ASP.NET Core MVC, Razor Pages

🗂 View Model & Data Model

Model Bound to View

@model IrbyImaging.DomainClasses.MechanicTimesheet
  • MechanicTimesheet likely contains:
    • DateTime WorkDate
    • TimeSpan StartTime, EndTime
    • string FieldOfficeId
    • List<JobEntry> Jobs

ViewBag Properties

  • ViewBag.Jobs – List of { Value: jobNumber, Text: jobName } used to populate the job-selection dialog
  • ViewBag.FieldOffices – List of field offices for the dropdown

🔑 Key Functional Areas

1. General Information Form

  • DatePicker & TimePicker for Work Start
    <ejs-datepicker id="WorkDate" name="WorkDate" format="MM/dd/yyyy" value="@DateTime.Now.ToString("MM/dd/yyyy")" />
    <ejs-timepicker id="StartTime" name="StartTime" placeholder="Start Time" value="7:00 AM" />
    
  • Read‑only End Date updated when WorkDate changes, with a hidden <input> to submit:
    <span id="EndTimeDate">@DateTime.Now.ToString("MM/dd/yyyy")</span>
    <input type="hidden" id="HiddenEndTimeDate" name="EndTimeDate" value="@DateTime.Now.ToString("MM/dd/yyyy")" />
    <ejs-timepicker id="EndTime" name="EndTime" placeholder="End Time" value="4:00 PM" />
    
  • Field Office dropdown:
    <ejs-dropdownlist id="FieldOfficeId" name="FieldOfficeId" 
                      dataSource="@(ViewBag.FieldOffices)" placeholder="Select a Field Office">
      <e-dropdownlist-fields text="Text" value="Text"></e-dropdownlist-fields>
    </ejs-dropdownlist>
    

2. Add Jobs Grid & Selection Dialog

  • Main Grid (#JobGrid) – initially empty, supports Add/Delete/Cancel toolbar:
    <ejs-grid id="JobGrid" dataSource="new List<object>()" allowPaging="true" 
              toolbar="@(new List<string>(){"Add","Delete","Cancel"})" toolbarClick="toolbarClick">
      <e-grid-editSettings allowAdding="true" allowDeleting="true" mode="Dialog" />
      <e-grid-columns>
        <e-grid-column field="Value" headerText="Job Number" width="200" />
        <e-grid-column field="Text" headerText="Job Name" width="200" />
      </e-grid-columns>
    </ejs-grid>
    
  • Modal Dialog using Syncfusion’s ej.popups.Dialog with an internal selection grid (jobSelectionGrid).
    • Checkbox selection
    • Search & Paging
    • On “Add Selected” → merge unique jobs into JobGrid.

3. Form Submission

  • Hidden Field jobData stores serialized jobs:
    <input type="hidden" id="jobData" name="jobData" />
    
  • submitJobGridData() runs on onsubmit to JSON-stringify JobGrid data into #jobData.
  • Standard <button type="submit">Submit</button> posts to:
    <form asp-controller="TimeEntry" asp-action="CreateFieldLog" onsubmit="submitJobGridData()">
      …  
    </form>
    

📋 Markup & Layout

  • Layout: ~/Views/Shared/_TimeLayout.cshtml
  • Head Imports:
    • Syncfusion CSS (Fluent theme)
    • Syncfusion EJ2 scripts
  • Section Styles: Bootstrap Datepicker, DataTables CSS
  • Section Scripts: Validation scripts partial

🎨 Styling & Theming

  • Scoped CSS within the view defines:
    • .header-background for section headers
    • .form-container & .form-table for layout
    • Overrides default Syncfusion styling (borders, focus states)
    • Custom grid toolbar and row coloring

🛰 Third‑Party Integrations

Library Purpose
Syncfusion EJ2 Rich UI: grids, date/time pickers, dialogs
DataTables (Optional) Data exporting / printing
Dropzone File uploads (though not used here)
jQuery Event handling, DOM operations
Bootstrap bundle Layout, responsive utilities
MetisMenu, Waves Side menus, ripple effects

🛠 Helper Functions & Utilities (JavaScript)

// Trigger adding jobs from selection dialog
function toolbarClick(args) {
  if (args.item.id === 'JobGrid_add') {
    args.cancel = true;
    openJobSelectionDialog();
  }
}

// Open the job-selection dialog
function openJobSelectionDialog() {
  jobSelectionDialog.show();
}

// Add selected jobs to main grid, ensure uniqueness
function addSelectedJobs() {
  var selected = jobSelectionGrid.getSelectedRecords();
  if (!selected.length) { alert('Select at least one job.'); return; }
  var existing = jobGrid.dataSource.map(i => i.Value);
  var newRec = selected
    .filter(r => !existing.includes(r.Value))
    .map(r => ({
      Value: r.Value,
      Text: (r.Text.indexOf(' - ') > -1) 
            ? r.Text.split(' - ').slice(1).join(' - ')
            : r.Text
    }));
  if (!newRec.length) { alert('Already added.'); }
  else {
    jobGrid.dataSource = jobGrid.dataSource.concat(newRec);
    jobGrid.refresh();
  }
  jobSelectionGrid.clearSelection();
  jobSelectionDialog.hide();
}

// Serialize job grid into hidden input on submit
function submitJobGridData() {
  var gridInstance = document.getElementById('JobGrid').ej2_instances[0];
  document.getElementById('jobData').value = JSON.stringify(gridInstance.dataSource);
}

🔄 Data Flow & Interaction (Sequence Diagram)

sequenceDiagram
  participant U as User
  participant V as Create.cshtml View
  participant JS as Browser (Syncfusion/EJ2)
  participant C as TimeEntryController

  U->>V: Opens “Create New Field Log”
  V->>JS: Renders DatePicker, TimePicker, Grid
  U->>JS: Clicks “Add” toolbar
  JS->>JS: Open job-selection dialog, search/filter
  U->>JS: Select jobs → Click “Add Selected”
  JS->>Grid: Merge selected jobs into main grid
  U->>V: Fills other fields → Click “Submit”
  V->>JS: submitJobGridData() serializes grid data
  V->>C: POST CreateFieldLog (MechanicTimesheet + jobData)
  C-->>DB: Saves timesheet & jobs
  C-->>V: Redirect / Confirmation

🖥 Usage Examples & Code Snippets

1. Including in Controller

public class TimeEntryController : Controller
{
    public IActionResult CreateFieldLog()
    {
        ViewBag.Jobs = jobService.GetAllJobs();          // List<{Value,Text}>
        ViewBag.FieldOffices = officeService.GetList();
        return View("Create", new MechanicTimesheet());
    }

    [HttpPost]
    public IActionResult CreateFieldLog(MechanicTimesheet model, string jobData)
    {
        var jobs = JsonConvert.DeserializeObject<List<JobEntry>>(jobData);
        model.Jobs = jobs;
        timeEntryService.SaveTimesheet(model);
        return RedirectToAction("Index");
    }
}

2. Sample JSON in jobData

[
  {"Value":"JOB123","Text":"Install HVAC"},
  {"Value":"JOB456","Text":"Repair Generator"}
]

📈 API Endpoint Overview

Method Route Description
GET /TimeEntry/CreateFieldLog Loads the Create New Field Log view
POST /TimeEntry/CreateFieldLog Receives form data, saves to DB

⚠️ Error Handling & Validation

  • Client‑side: Syncfusion controls enforce formats (date/time).
  • Form Validation: _ValidationScriptsPartial provides standard ASP.NET MVC validation.
  • Alert boxes notify user for no job selection or duplicate jobs.

Tip: Enhance with custom validation attributes on MechanicTimesheet (e.g., [Required], [Range]).


✅ Conclusion

The Create.cshtml Razor view offers a rich, interactive experience for mechanics to log daily work, leveraging Syncfusion EJ2 components and modern JavaScript.

  • Modular structure: clear separation of General Info vs. Job entries.
  • Custom styling ensures a consistent look & feel.
  • Dialog‑based job picker simplifies adding multiple jobs.

This documentation should help developers understand, maintain, and extend the Field Log creation functionality with confidence! 🚀