šŸ“„ FieldLogDraft.cshtml Documentation


šŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Model
  4. Layout & Razor Markup
  5. Form: General Information Section
  6. Syncfusion EJ2 Grids
  7. Custom Styles & Themes
  8. JavaScript: Core Functionality
  9. Helper Methods & Utilities
  10. Integration Flows & Dialog Workflow
  11. Error Handling & Edge Cases
  12. UML Diagrams
  13. Sample Usage & Code Snippets
  14. Conclusion

1. Overview & Purpose

This FieldLogDraft.cshtml Razor view renders a Draft Field Log entry page for mechanics’ timesheets. It allows users to:

  • Capture general information (date, time, status, foreman, etc.)
  • Select and add Jobs, Cost Codes, Per Diem entries, Employees, and Equipment via a modal dialog
  • Edit, Save, Submit, or Cancel the draft
  • Automatically calculate work hours and update equipment hours based on start/stop times

:gear: Typical use‑case: a foreman or supervisor drafts daily field logs, adding detailed line‑item data before final submission.


2. Dependencies & Technologies

Technology Purpose Version / Link
ASP.NET MVC (Razor) Server‑side view engine —
Syncfusion EJ2 UI Grids, DropDownList, Dialog, DatePicker… 27.1.48 (CSS & JS from CDN)
jQuery DOM manipulation, AJAX 3.6.0
DataTables Client‑side exporting/printing 1.10.25 (JS & Buttons extension)
Dropzone.js File-upload support (if extended) 5.5.1
Bootstrap 4/5 & Icons Responsive layout & icons 4.5.2 / 1.10.5
Newtonsoft.Json JSON serialization in Razor —
IrbyImaging.DomainClasses DomainModels (MechanicTimesheet, Job, etc.) Internal library

3. View Model & Data Model

@model IrbyImaging.DomainClasses.MechanicTimesheet
  • MechanicTimesheet (Field Log Draft) properties used:
    • WorkDate, StartTime, EndTime, WorkHours
    • JobData, CostCodeClasses, PerDiemClasses, Employees, Equipment (populated via ViewBag)
    • Status tracking fields: Status, ModifiedBy, ApprovedBy, RejectedNotes, etc.

:memo: Actual property names may differ in your domain class. This view expects the model and various ViewBag lists to be populated by the controller.


4. Layout & Razor Markup

@{
    ViewData["Title"] = "Field Log Draft";
    Layout = "~/Views/Shared/_TimeLayout.cshtml";
}
@using Syncfusion.EJ2;
@using Syncfusion.EJ2.Grids;
@using Syncfusion.EJ2.Popups;
@using Syncfusion.EJ2.Navigations;
@using Syncfusion.JavaScript;
@using Newtonsoft.Json;
@using IrbyImaging.DomainClasses;
  • Title set to ā€œField Log Draftā€
  • Shared Layout: _TimeLayout.cshtml (provides navbar, footer, common scripts/styles)
  • Usings: Syncfusion EJ2 components & NewtonSoft.Json for inline serialization

5. Form: General Information Section

An expandable accordion titled General Information holds a <table> with:

Field Control Type Key Attributes
Field Log ID input[type=text] readonly, placeholder ā€œ(New)ā€
Status input[type=text] readonly, placeholder ā€œDraftā€
Modified By/On input[readonly] read-only user & timestamp
Approved By/On input[readonly]
Rejected On/Notes input[readonly] & input[readonly]
Work Start/Stop <ejs-datepicker> & <ejs-timepicker> change="onTimeChange"
Foreman <ejs-dropdownlist> Filtering, virtualization enabled
Shift Code <ejs-dropdownlist>
Supervisor input[type=text] free text
Work Hours input[type=text] readonly, auto‑calculated via JS
Field Office <ejs-dropdownlist>
Notes <textarea> free text
<label>Work Start:</label>
<ejs-datepicker id="WorkDate" name="WorkDate"
    format="MM/dd/yyyy" value="@ViewBag.WorkDate"></ejs-datepicker>
<ejs-timepicker id="StartTime" name="StartTime"
    value="@ViewBag.StartTime" placeholder="Start Time"
    change="onTimeChange"></ejs-timepicker>

6. Syncfusion EJ2 Grids

Each accordion panel below ā€œGeneral Informationā€ hosts a <ejs-grid>:

  1. Jobs
  2. Cost Codes
  3. Per Diem
  4. Employees
  5. Equipment

All grids share:

  • Toolbar: Create, Edit, Delete, Update, Cancel
  • Paging, Selection (Multiple), Hover, Resizing
  • Action/event handlers: onGridLoad, onActionComplete, toolbarClick

6.1 Jobs Grid Example

<ejs-grid id="FieldLogJobGrid"
    dataSource="@(ViewBag.JobData)"
    toolbar="@(new List<string>{ "Create","Edit","Delete","Update","Cancel"})"
    allowPaging="true" allowSelection="true" enableHover="true"
    actionComplete="onActionComplete" toolbarClick="toolbarClick"
    gridLines="Both" allowResizing="true" load="onGridLoad">

    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings>
    <e-grid-selectionsettings type="Multiple"></e-grid-selectionsettings>
    <e-grid-columns>
        <e-grid-column type="checkbox" width="50"></e-grid-column>
        <e-grid-column field="Value" headerText="Job Number" width="200" textAlign="Left" isPrimaryKey="true"></e-grid-column>
        <e-grid-column field="Text" headerText="Job Name" width="200" textAlign="Left"></e-grid-column>
    </e-grid-columns>
</ejs-grid>

šŸ“Œ Other grids follow a similar pattern but include fields specific to Cost Codes, Per Diem, Employees, Equipment.


7. Custom Styles & Themes

Inline <style> blocks override default Syncfusion/Bootstrap styling:

  • Fixed Top Navbar (.fixed-top-nav, .status-bar)
  • Accordion (.accordion, .panel)
  • Form Layout (.form-container, .form-table)
  • Grid Styles (.e-grid .e-headercell, .e-grid .e-gridcontent, toolbar button styling)
.accordion { cursor: pointer; transition: 0.4s; }
.accordion:after { content: '\002B'; float: right; }
.active:after { content: "\2212"; }
.panel { max-height: 0; overflow: hidden; transition: max-height 0.2s ease-out; }

8. JavaScript: Core Functionality

All scripts are loaded at the bottom of the view, including:

  • jQuery, DataTables, Dropzone, Syncfusion EJ2 (ej2.min.js), Bootstrap JS, custom app.js

  • Razor‑embedded JSON:

    dataSource="@Html.Raw(JsonConvert.SerializeObject(ViewBag.Employees))"
    
  • Document Ready ($(document).ready(...)) bootstraps:

    1. Grid Instances for FieldLogJobGrid, FieldLogEmployeeGrid, FieldLogEquipmentGrid
    2. Dialog & Tabs (ej.popups.Dialog, ej.navigations.Tab) for multi‑tab selection modal
    3. Dialog Grids (jobGrid, CostCodeGrid, PerDiemGrid, employeeGrid, equipmentGrid)
    4. Event Handlers:
      • onTimeChange āž” calculate & update work hours
      • onActionComplete āž” refresh equipment/grid data when jobs change
      • toolbarClick āž” intercept ā€œCreateā€ to open modal
      • Tab selection āž” lazy‑load grids once per tab
var dialogObj = new ej.popups.Dialog({
  header: 'Select Job Information',
  isModal: true, width: '60%', height: '70%', visible: false,
  buttons: [
    { click: addSelectedAndContinue, buttonModel: { content: 'Add & Continue', isPrimary: true } },
    { click: addSelectedItems,        buttonModel: { content: 'Add Selected' } },
    { click: ()=> dialogObj.hide(),    buttonModel: { content: 'Cancel', cssClass:'e-flat' } }
  ],
  open: dialogOpen, close: dialogClose
});
dialogObj.appendTo('#defaultDialog');

var tabObj = new ej.navigations.Tab({
  items: [
    { header:{'text':'Jobs'}, content:'#JobGrid' },
    { header:{'text':'Cost Code'}, content:'#CostCodeGrid' },
    { header:{'text':'Per Diem'}, content:'#PerDiemGrid' },
    { header:{'text':'Employees'}, content:'#EmployeeGrid' },
    { header:{'text':'Equipment'}, content:'#EquipmentGrid' }
  ],
  selected: function(args){ currentTab = this.items[args.selectedIndex].header.text; }
});
tabObj.appendTo('#tab_default');

9. Helper Methods & Utilities

Function Purpose
addUnionCodeColumn(jobNumber) Dynamically add a column under ā€œUnion Codeā€ for a newly added Job
removeUnionCodeColumn(jobNumber) Remove the Union Code sub‑column when a job is deleted
updateEquipmentBasedOnJobs() AJAX-post selected job numbers to /TimeEntry/GetFilteredEquipment endpoint, then filter/update main equipment grid
processSelectedItems() Core logic to add selected items from dialog tabs and detect duplicates
addSelectedJobs() Add selected jobs to main grid, update union code columns, refresh equipment
addSelectedEmployees() Add selected employees to main grid
addSelectedCostCodes() Add selected cost codes to main grid
addSelectedPerDiem() Add selected per diem entries
addSelectedEquipment() Add selected equipment with CalcHours set to current work hours
clearAllSelections() Clear selections in all dialog grids
dialogOpen() / dialogClose() Show/hide the ā€œAddā€ button and clear searches upon modal open/close
calculateHours() Compute hours between start & end times (wraps midnight) and update controls
updateEquipmentGridHours() Update all equipment rows’ CalcHours with newly calculated work hours

10. Integration Flows & Dialog Workflow

sequenceDiagram
    participant U as User
    participant V as View
    participant D as Dialog
    participant S as Server

    U->>V: Click "Add Job Information" (Create toolbar)
    V->>D: dialogObj.show() with selected tab
    U->>D: Select rows across tabs
    U->>D: Click "Add Selected"
    D->>V: processSelectedItems()
    V->>V: addSelectedJobs(), addSelectedEmployees(), ... duplicates check
    V->>S: AJAX /TimeEntry/GetFilteredEquipment (jobNumbers)
    S-->>V: filtered equipment list
    V->>V: updateEquipmentBasedOnJobs(), refresh grids
    V-->>D: dialogObj.hide()
    U<<--V: Updated main grids show new entries

11. Error Handling & Edge Cases

  • Duplicate detection: alerts user of duplicate selections per category
  • Time calculation: if end < start, wraps across midnight
  • Grid re‑focus: retains search focus & selection via event hooks
  • AJAX fallback: no explicit error callback—implement server‑side error checking in /TimeEntry/GetFilteredEquipment

12. UML Diagrams

12.1 Class Diagram (Simplified)

classDiagram
    class MechanicTimesheet {
      +DateTime WorkDate
      +DateTime StartTime
      +DateTime EndTime
      +decimal WorkHours
      +string FieldOfficeId
      +string Foreman
      +string ShiftCode
      +string Notes
      +List<JobEntry> JobData
      +List<CostCode> CostCodes
      +List<PerDiem> PerDiemEntries
      +List<Employee> Employees
      +List<Equipment> EquipmentList
    }

    class JobEntry {
      +string Value
      +string Text
    }
    class Equipment {
      +string AssetNumber
      +string DisplayName
      +decimal CalcHours
    }

    MechanicTimesheet --> JobEntry : JobData
    MechanicTimesheet --> Equipment : EquipmentList

13. Sample Usage & Code Snippets

13.1 Controller Action

public IActionResult FieldLogDraft(int? id)
{
    var model = id.HasValue 
        ? _service.GetMechanicTimesheet(id.Value)
        : new MechanicTimesheet();
    ViewBag.Jobs           = _jobService.GetSelectList();
    ViewBag.CostCodeClasses= _costCodeService.GetSelectList();
    ViewBag.PerDiemClasses = _perDiemService.GetSelectList();
    ViewBag.Employees      = _empService.GetSelectList();
    ViewBag.Equipment      = _equipService.GetAll();
    ViewBag.WorkDate       = DateTime.Today;
    ViewBag.StartTime      = DateTime.Today.AddHours(7);
    ViewBag.EndTime        = DateTime.Today.AddHours(16);
    return View(model);
}

13.2 Razor DropdownList Setup

@{ 
  var JobDropDownList = new Syncfusion.EJ2.DropDowns.DropDownList() {
    DataSource = ViewBag.Jobs,
    AllowFiltering = true,
    Placeholder = "Select a Job",
    Fields = new DropDownListFieldSettings { Text = "Text", Value = "Value" }
  };
}
@Html.EJS().DropDownList("jobSearch", JobDropDownList)

14. Conclusion

This Field Log Draft view merges rich client‑side UI components (Syncfusion EJ2 Grids, Dialogs, Date/Time pickers) with server‑side Razor data binding to deliver a feature‑complete timesheet drafting interface.

Key takeaways:

  • Modular grids for each data category with in‑place editing & selection dialog
  • Real‑time calculations for work and equipment hours
  • Dynamic column management (Union Code stacking)
  • Scalable architecture: new tabs or grid types can be added with minimal changes

:rocket: With this documentation, developers can understand, extend, and maintain the FieldLogDraft.cshtml view—ensuring seamless timesheet management for field operations.