šŸ“„ DocPreview.cshtml Documentation

Welcome to the in-depth documentation for IrbyImaging/Views/Imaging/DocPreview.cshtml. This Razor view powers the ā€œIndex Documentsā€ page, allowing users to preview, select, index, and delete uploaded PDF documents within the Imaging area of the application.


šŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. View Models & Data Models
  5. API Endpoints Overview
  6. Detailed Code Walkthrough
  7. Helper Methods & Utilities
  8. Third‑party Integrations
  9. Usage Examples & Code Snippets
  10. Error Handling & Return Types
  11. Conclusion

1. Overview & Purpose

šŸ“ DocPreview.cshtml is a Razor View that:

  • Previews uploaded PDF documents in a grid layout.
  • Allows selecting single or multiple documents via checkboxes.
  • Provides ā€œSelect Allā€ functionality.
  • Supports indexing (i.e., saving metadata) for selected documents.
  • Enables deletion of selected documents.
  • Offers a modal preview for a closer look at each PDF.
  • Handles both multi-page and single-page upload scenarios.

This page is part of the Imaging module and works in tandem with the ImagingController actions:

  • SaveDocument (POST)
  • Preview (GET)
  • myModalPreview (GET)
  • DocumentPreview (GET)

2. Key Functional Areas

Area Description
šŸ“‹ Model Binding Binds to IrbyImaging.Models.DocumentImaging to access BatchIds, SinglePageUpload, etc.
šŸ” Preview Display Uses <embed> tags and AJAX‑powered modal for PDF preview.
āœ… Selection & Bulk Actions Checkboxes, ā€œSelect Allā€ toggle, Submit buttons for indexing or deleting docs.
šŸ—‚ļø Multi‑page vs. Single‑page Conditional rendering based on BatchIds.Count and SinglePageUpload.
šŸ–Šļø Metadata Capture When uploading a single page, presents a form to collect document metadata.
šŸ› ļø Helper Scripts JavaScript functions for confirmation dialogs, AJAX calls, and checkbox toggling.

3. Dependencies & Technologies

Category Libraries / Frameworks
UI Framework ASP.NET MVC Razor, Bootstrap 5
JavaScript & Plugins jQuery, Bootstrap Bundle, MetisMenu, SimpleBar, Waves.js, Bootstrap Datepicker
WYSIWYG Editor TinyMCE
File Upload Support Dropzone (CSS included)
Styling Custom CSS for flex layouts, Bootstrap classes

4. View Models & Data Models

4.1. DocumentImaging Model (Simplified)

+---------------------------+
|    DocumentImaging        |
+---------------------------+
| Guid DocumentImageId      |
| List<Guid> BatchIds       |
| bool SinglePageUpload     |
| bool DeleteFiles          |
| string DocumentType       |
| string JobNumber          |
| string JobName            |
| string JobOwner           |
| string JobAddress         |
| string UnitNumber         |
| string AssignedToEmployeeId   |
| string AssignedToEmployeeName |
| string WorkOrder          |
| string CompletedBy        |
| string JobDate            |
| string DocumentNotes      |
+---------------------------+
  • BatchIds: IDs of uploaded documents pending indexing.
  • SinglePageUpload: Flag for single-page vs. multi-page upload workflows.
  • DeleteFiles: Hidden value set when the user confirms deletion.

5. API Endpoints Overview

Action Method HTTP Verb Route Purpose
Preview GET /Imaging/Preview?id={GUID} Returns PDF to embed in page or modal.
myModalPreview GET /Imaging/myModalPreview Returns partial view HTML for modal content.
SaveDocument POST /Imaging/SaveDocument Persists indexing selections/metadata.
DocumentPreview GET /Imaging/DocumentPreview Shows final saved document in an embed.

6. Detailed Code Walkthrough

6.1 Initial Setup & Model Binding

@model IrbyImaging.Models.DocumentImaging
@{
    ViewData["Title"] = "Save Uploaded Document";
    Layout = "~/Views/Shared/_Layout.cshtml";

    // Build comma-separated GUID list for metadata forms
    var lists = new List<Guid>();
    string guidList = "";
    if (Model?.BatchIds != null) {
        lists = Model.BatchIds;
        foreach (var id in lists) { guidList += id + ","; }
    }
}
  • Model Declaration: Binds the page to DocumentImaging.
  • Layout & Title: Uses the shared _Layout.cshtml and sets a descriptive title.
  • Batch ID Enumeration: Prepares a guidList string for later hidden fields.

6.2 Styles & Scripts Sections

@section styles {
  <!-- Datepicker & Dropzone CSS -->
  <link href="~/assets/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet">
  <link href="~/assets/libs/dropzone/min/dropzone.min.css" rel="stylesheet">
}

<style>
  .flex-container { display: flex; flex-wrap: wrap; }
  .flex-container > div { /* styling for demo */ }
</style>
  • @section styles: Injects page‑specific CSS dependencies.
  • Inline CSS: Defines a simple flex layout (used in commented/demo code).

At the bottom of the file, the @section scripts block includes:

  • jQuery, Bootstrap JavaScript, MetisMenu, SimpleBar, Waves
  • Bootstrap Datepicker, TinyMCE
  • Custom JS:
    • deleteFiles() – prompts user for confirmation.
    • Checkbox ā€œSelect Allā€ toggler.
    • AJAX preview loader for modals.

6.3 Document Indexing Forms (Multi‑page)

When BatchIds.Count > 1, the view renders:

  1. Form:

    @using (Html.BeginForm("SaveDocument","Imaging",FormMethod.Post,Model)) {
      @Html.HiddenFor(m=>m.DocumentImageId)
      @Html.HiddenFor(m=>m.BatchIds)
      <!-- Bulk actions toolbar -->
      <label>Select All</label>
      <input id="ckbCheckAll" type="checkbox" />
      <button type="submit">Index Selected Documents</button>
      <button type="submit" onclick="deleteFiles();" class="btn btn-danger">Delete</button>
      ...
    }
    
  2. Document Grid:

    • Loops through each Model.BatchIds.
    • Uses <embed src="@Url.Action("Preview","Imaging", new { id = docId })#zoom=FitH" type="application/pdf"> to inline the PDF.
    • A checkbox (name="docIds") to select each document.
    • A Preview link that triggers an AJAX call to myModalPreview.
  3. Layout:

    • Groups 4 documents per Bootstrap row (.col-md-3).
    • Provides bottom‑aligned Index button for convenience.

6.4 Single‑page Upload & Metadata Capture

When BatchIds.Count == 1 && SinglePageUpload == true, the interface switches to a metadata capture form:

  • Dropdown: DocumentType (pre-populated list of document categories).
  • Textareas: JobNumber, JobName, JobOwner, JobAddress, etc.
  • Hidden: batchId containing the comma-separated GUID list.
  • Save Document button triggers Save action via SubmitForm() JavaScript (validation hook).
@using(Html.BeginForm("Save","Imaging",FormMethod.Post)) {
  @Html.HiddenFor(m=>m.DocumentImageId)
  @Html.Hidden("batchId", guidList)
  <!-- Document Type select -->
  <select asp-for="DocumentType">
    <option>Select Type</option>
    <option>ANNUAL CRANE INSPECT REP</option>
    ...
  </select>
  <!-- Metadata fields -->
  <textarea asp-for="JobNumber" placeholder="Enter the Job Number..."></textarea>
  ...
  <button type="submit" id="saveDocument" class="btn btn-primary">Save Document</button>
}

After saving metadata, the view continues to embed the processed PDF preview via:

<embed src="@Url.Action("DocumentPreview","Imaging", new { id = guidList })#zoom=FitH" type="application/pdf">

6.5 No Pending Documents Scenario

If Model.BatchIds.Count == 0, a friendly message is shown:

No Pending Documents are available to Index. Please upload documents to continue Indexing.


7. Helper Methods & Utilities

  • deleteFiles()
    function deleteFiles() {
      var r = confirm("Are you sure you want to delete the selected documents?");
      if (!r) return false;
      $("#DeleteFiles").val("True");
    }
    
  • Select All Toggle
    $("#ckbCheckAll").click(function () {
      $(".checkBoxClass").prop('checked', $(this).prop('checked'));
    });
    
  • AJAX Preview Modal
    $(".previewDetail").click(function () {
      var id = $(this).data('id');
      $.ajax({
        type: "GET",
        url: '/Imaging/myModalPreview',
        data: { id: id, Preview: true },
        success: function(html) {
          $('#myModalContent').html(html);
          $('#myModal').modal('show');
        },
        error: function() { alert("Failed to load preview."); }
      });
    });
    

8. Third‑party Integrations

  • Bootstrap Datepicker for date fields (if extended).
  • Dropzone (CSS only in this view) – ready for drag‑and‑drop uploads elsewhere.
  • TinyMCE – WYSIWYG support (scripts loaded but not currently used).

9. Usage Examples & Code Snippets

Example: Index Multiple PDFs

@model IrbyImaging.Models.DocumentImaging
<!-- Suppose Model.BatchIds has 5 GUIDs -->
@Html.BeginForm("SaveDocument","Imaging", FormMethod.Post) {
  <input type="checkbox" id="ckbCheckAll"/> Select All
  @foreach(var id in Model.BatchIds) {
    <embed src="@Url.Action("Preview","Imaging", new { id = id })#zoom=FitH" type="application/pdf"/>
    <input type="checkbox" name="docIds" value="@id"/>
  }
  <button type="submit">Index Selected</button>
  <button onclick="deleteFiles()">Delete</button>
}

Example: Single‑Page Metadata Form

@using(Html.BeginForm("Save","Imaging", FormMethod.Post)) {
  @Html.HiddenFor(m=>m.DocumentImageId)
  <select asp-for="DocumentType">…</select>
  <textarea asp-for="JobNumber"></textarea>
  <button type="submit">Save Document</button>
}

10. Error Handling & Return Types

  • Client‑side:
    • confirm() for deletion.
    • alert() on AJAX errors.
  • Server‑side (ImagingController):
    • Should validate Model.BatchIds and metadata fields.
    • Returns PartialView for myModalPreview or redirects after SaveDocument.

11. Conclusion

šŸš€ DocPreview.cshtml is a dynamic, feature‑rich Razor view enabling:

  • Flexible handling of batch vs. single document workflows.
  • Inline PDF previews and detailed metadata capture.
  • Bulk operations (indexing & deletion) with user‑friendly confirmations.
  • AJAX‑powered modal popups for a seamless preview experience.

By combining ASP.NET MVC helpers, Bootstrap layouts, and custom JavaScript utilities, it provides a robust interface for indexing and managing document images within the Irby Imaging system.


Thank you for exploring the DocPreview.cshtml documentation! šŸ If you have any further questions or need code samples, feel free to reach out.