📄 IrbyImaging/Views/AccountingImaging/ViewDoc.cshtml Documentation
Welcome to the detailed Markdown documentation of the ViewDoc.cshtml Razor view used in the Accounting Imaging module of IrbyImaging. This document will walk you through every section, explain its purpose, outline dependencies, and provide usage examples and UML diagrams.
📑 Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- View Models & Data Models
- Helper Methods & Utilities
- API Endpoints Overview
- Third-party Integrations
- Detailed Code Walkthrough
8.1. Razor Declaration & Imports
8.2. Dynamic Category Resolution
8.3. Form & Hidden Fields
8.4. Metadata Rendering (IndexList Loop)
8.5. PDF Preview Embed
8.6. Loading Overlay & Spinner
8.7. Scripts & Stylesheets - UML Class Diagram 📊
- Usage Examples 🛠️
- Conclusion 🎯
🌟 1. Overview & Purpose
ViewDoc.cshtml is the read‑only Razor View responsible for displaying:
- ✅ Document metadata (index fields)
- ✅ PDF preview of the scanned/archived document
- ✅ A loading spinner during post‑back operations
It enables Accounting users to inspect uploaded documents, view all indexed attributes, and scroll through the embedded PDF within a unified, responsive interface.
🔑 2. Key Functional Areas
| Area | Description |
|---|---|
| Metadata Rendering | Dynamically generates controls for each document attribute. |
| PDF Preview | Embeds a PDF viewer for in-browser document inspection. |
| Dynamic Category Resolution | Determines document category (legal, safety, IT, accounting, etc.). |
| Loading Overlay & Spinner | Displays UI feedback during long‑running save or load operations. |
| Select2 Integration | Provides enhanced <select> styling/search capabilities. |
🛠️ 3. Dependencies & Technologies
| Technology | Purpose |
|---|---|
| ASP.NET Core MVC | Server-side framework & Razor view engine |
| Razor Syntax | Dynamic HTML templating |
| Bootstrap 4/5 | Layout & responsive grid, forms, cards |
| jQuery | DOM manipulation, event handling |
| Select2 | Advanced <select> UI |
| bootstrap‑datepicker | Date selection widget |
| spin.js | High-performance spinner |
| TinyMCE | Rich text / textarea support (loaded but not active here) |
| Dropzone.js | File‑upload widget (CSS loaded) |
🗂️ 4. View Models & Data Models
Primary Model
@model IrbyImaging.Models.DocumentImaging
DocumentImaging contains:
| Property | Type | Description |
|---|---|---|
| DocumentImageId | Guid / int | Unique identifier |
| DocumentType | string | Type name (e.g. “Invoice”, “Receipt”) |
| TotalPages, Page | int | PDF pagination details |
| ImageContents | byte[] / string | Raw image or OCR text |
| IndexList | List | Collection of index metadata fields |
| IsAccounting, IsLegal, … | bool | Flags for category determination |
| DocumentTypes | IEnumerable | Dropdown items for types |
| EmployeeData, JobData, … | IEnumerable | Linked lookup data |
IndexItem (model for each metadata field):
| Property | Type | Description |
|---|---|---|
| Id | int | Primary key |
| AttributeName | string | Label of the metadata field |
| AttributeType | AttributeType Enum | (Text, Character, Date, Number, Currency, Boolean) |
| IsMultiValue | bool | Indicates multiple options selection |
| LinkEmployeeData | bool | Should fetch from EmployeeData |
| LinkJobData | bool | Should fetch from JobData |
| LinkCustomerData | bool | Should fetch from CustomerData |
| MultiValueTypes | IEnumerable | Available options if IsMultiValue == true |
| IndexValue | string / object | The currently saved value |
⚙️ 5. Helper Methods & Utilities
Html.HiddenFor()
Renders hidden inputs to preserve model state across post‑backs.- Select2 Initialization
$(document).ready(function () { $('.js-example-basic-single').select2(); }); - Spin.js
Instantiates a spinner during save operations:var spinner = new Spinner(opts).spin(document.getElementById('loading')); Url.Action()
Generates URLs for embedding PDF preview:src="@Url.Action("EditDocumentPreview", "AccountingImaging", new { id = Model.DocumentImageId, category = category })"
🚀 6. API Endpoints Overview
| Action | Controller | HTTP Method | Purpose |
|---|---|---|---|
| Edit (Form Post) | AccountingImaging | POST | Save updated document metadata (hidden now) |
| EditDocumentPreview | AccountingImaging | GET | Returns PDF stream for embed preview |
🌐 7. Third‑party Integrations
| Library | Feature |
|---|---|
| jQuery | DOM traversal & events |
| Select2 | Searchable dropdowns |
| Bootstrap Datepicker | Date selection |
| TinyMCE | Rich text editing (setup only) |
| Dropzone.js (CSS only) | Drag/drop uploads (not used here) |
| spin.js | In‑page spinner |
🔍 8. Detailed Code Walkthrough
8.1 Razor Declaration & Imports
@model IrbyImaging.Models.DocumentImaging
@{
ViewData["Title"] = "View Document";
// Optional custom layout:
// Layout = "~/Views/Shared/_LegalLayout.cshtml";
}
@model: Strongly‑typed view modelViewData["Title"]: Sets page title
8.2 Dynamic Category Resolution
@{
var category = Model.IsLegalDocument ? "legal" :
Model.IsSafety ? "safety" :
Model.IsIT ? "it" :
Model.IsAccounting ? "accounting" :
Model.IsBidding ? "bidding" : null;
}
- Determines category string for routing the PDF preview.
8.3 Form & Hidden Fields
<form asp-action="Edit" class="form-horizontal" id="validation-form" method="post">
@* Preserve all critical properties *@
@Html.HiddenFor(m => m.DocumentImageId)
@Html.HiddenFor(m => m.DocumentType)
@* … 20+ hidden inputs … *@
</form>
- Hidden fields carry entire
DocumentImagingstate if a POST is triggered. - Currently the view is read‑only, so the form submit is not exposed.
8.4 Metadata Rendering (IndexList Loop)
@for (var i = 0; i < Model.IndexList.Count; i++)
{
<!-- Always hide the core metadata -->
<input type="hidden" asp-for="@Model.IndexList[i].Id" />
<input type="hidden" asp-for="@Model.IndexList[i].AttributeName" />
<!-- … other hidden … -->
@* Render the correct control based on AttributeType and flags *@
@if (Model.IndexList[i].AttributeType == DomainClasses.AttributeType.Text && !Model.IndexList[i].IsMultiValue && !Model.IndexList[i].LinkEmployeeData && !Model.IndexList[i].AttributeName.Contains("State"))
{
<!-- Single‑line text as disabled textarea -->
}
else if (Model.IndexList[i].LinkEmployeeData)
{
<!-- Dropdown bound to EmployeeData -->
}
<!-- … more branches for Date, Number, Currency, Boolean, MultiValue … -->
}
- Branches cover all combinations:
- Text & Character →
<textarea disabled> - LinkWorker →
<select asp-items="@Model.EmployeeData" disabled> - Date →
<input type="date" disabled> - Number/Currency →
<input type="number" disabled> - Boolean →
<select disabled><option>Yes</option><option>No</option> - Default → fallback
<textarea>
- Text & Character →
8.5 PDF Preview Embed
<div class="col-lg-6">
<embed
id="frPDF"
height="100%" width="100%"
src="@Url.Action("EditDocumentPreview","AccountingImaging", new { id = Model.DocumentImageId, category = category })#zoom=FitH"
type="application/pdf">
</div>
- Uses
<embed>for in‑browser PDF viewing #zoom=FitH: Fits width of PDF to container
8.6 Loading Overlay & Spinner
<div id="loading">
<div id="loadingcontent">
<p id="loadingspinner">Saving document. Please wait…</p>
</div>
</div>
#loading { display: none; position: fixed; /* … */ }
$("#saveDocument").click(function(){
$("#loading").fadeIn();
var spinner = new Spinner(opts).spin($("#loading")[0]);
});
#loadingoverlay covers entire viewport- spin.js generates a dynamic spinner
8.7 Scripts & Stylesheets
<!-- Styles -->
<link href="~/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet">
<link href="~/libs/dropzone/min/dropzone.min.css" rel="stylesheet">
<!-- Core JS -->
<script src="~/libs/jquery/jquery.min.js"></script>
<script src="~/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/js/app.js"></script>
<!-- … other libs … -->
<!-- Select2 -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
- Note: Some scripts/styles are duplicated (bottom of file).
- Best Practice: Consolidate to avoid multiple loads.
UML Class Diagram 📊
classDiagram
class DocumentImaging {
+Guid DocumentImageId
+string DocumentType
+int TotalPages
+int Page
+byte[] ImageContents
+List<IndexItem> IndexList
+bool IsLegalDocument
+bool IsSafety
+bool IsIT
+bool IsAccounting
+bool IsBidding
+IEnumerable<SelectListItem> DocumentTypes
+IEnumerable<SelectListItem> EmployeeData
+IEnumerable<SelectListItem> JobData
+IEnumerable<SelectListItem> CustomerData
+IEnumerable<SelectListItem> StateData
}
class IndexItem {
+int Id
+string AttributeName
+AttributeType AttributeType
+bool IsMultiValue
+bool LinkEmployeeData
+bool LinkJobData
+bool LinkCustomerData
+IEnumerable<SelectListItem> MultiValueTypes
+object IndexValue
}
DocumentImaging "1" --> "*" IndexItem
🛠️ 10. Usage Examples
1. Controller Action
public IActionResult ViewDoc(Guid id)
{
var model = _docService.GetDocumentImaging(id);
return View("ViewDoc", model);
}
2. URL Navigation
GET /AccountingImaging/ViewDoc?id=3fa85f64-5717-4562-b3fc-2c963f66afa6
3. Rendered Page
| Left Column: Metadata | Right Column: PDF Preview |
|---|---|
🎯 11. Conclusion
ViewDoc.cshtml provides a clean, responsive, and dynamic interface for Accounting users to:
- Inspect detailed metadata saved per document
- View the actual PDF scan in an embedded viewer
- Enjoy smooth UX with loading spinners and enhanced selects
By understanding this walkthrough, you can confidently extend, maintain, or optimize the document viewing experience in IrbyImaging.
Happy coding! 🚀
End of documentation for IrbyImaging/Views/AccountingImaging/ViewDoc.cshtml