DocPreview.cshtml 📄🔍

Location: IrbyImaging/Views/HRImaging/DocPreview.cshtml
Purpose: Display, preview, select, index, and delete uploaded HR documents in batch.


Table of Contents

  1. Overview & Purpose
  2. Layout & Metadata
  3. Model & ViewData
  4. Styles & CSS
  5. Main Content & Form Handling
  6. JavaScript & Client‑Side Behavior
  7. Dependencies & Third‑Party Libraries
  8. UML Diagrams
  9. Sample Usage & Code Snippets
  10. Conclusion

1. Overview & Purpose

The DocPreview.cshtml Razor view is part of the HRImaging area in an ASP.NET MVC application.
It provides an interface for:

  • Displaying uploaded document PDF thumbnails.
  • Allowing users to select, index, or delete one or multiple documents.
  • Previewing documents in a modal pop‑up via AJAX.

🎯 Intended Use Case:
HR personnel upload scanned documents (e.g., employee records), then index them in batches, or remove incorrectly uploaded files.


2. Layout & Metadata

@model IrbyImaging.Models.DocumentImaging
@{
    ViewData["Title"] = "Save Uploaded Document";
    Layout = "~/Views/Shared/_Layout.cshtml";
    // Prepare a comma-separated GUID list if Model.BatchIds is not null
}
  • @model: Binds the view to DocumentImaging view‑model.
  • ViewData["Title"]: Sets the page title.
  • Layout: Inherits the site-wide _Layout.cshtml.

3. Model & ViewData

Property Type Description
DocumentImageId Guid Single document identifier.
BatchIds List<Guid> List of uploaded document identifiers.
DeleteFiles (hidden flag) bool Indicates deletion action on Post.
ViewBag.category string Document category metadata.

4. Styles & CSS

@section styles {
  <!-- Datepicker -->
  <link href="~/assets/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet">
  <!-- Dropzone (future file uploads) -->
  <link href="~/assets/libs/dropzone/min/dropzone.min.css" rel="stylesheet" type="text/css" />
}
<style>
  .flex-container { display: flex; flex-wrap: wrap; }
  .flex-container > div { background-color: #f1f1f1; /* ... */ }
</style>
  • Custom .flex-container for responsive thumbnail layout.
  • Third-party CSS for datepicker & dropzone integration.

5. Main Content & Form Handling

5.1 Batch Processing Logic

@if (Model != null && Model.BatchIds != null) {
    // Check how many docs are pending indexing
    if (Model.BatchIds.Count > 1) { … }
    else if (Model.BatchIds.Count == 1) { … }
    else { <h5>No Pending Documents…</h5> }
}
  • Multiple Documents (>1): Show checkboxes, “Index Selected Documents” & “Delete” buttons.
  • Single Document: Similar UI with slight form adjustments.
  • No Documents: Informational message.

5.2 Conditional Rendering

  • Uses Html.BeginForm("SaveDocument", "HRImaging", FormMethod.Post) to post selections.
  • Hidden fields track DocumentImageId, BatchIds[], and deletion flag.

5.3 Document Thumbnails & Selection

<div class="col-md-3">
  <div class="thumbnail">
    <embed 
      src="@Url.Action("Preview","HRImaging", new { id = Model.BatchIds[k] })#zoom=FitH"
      type="application/pdf">
    <div class="preference">
      <label>Select</label>
      <input class="checkBoxClass" type="checkbox" name="docIds" 
             value="@Model.BatchIds[k]" id="[@k].docIds" />
    </div>
    <a href="javascript:void(0);" class="previewDetail" 
       data-id="@Model.BatchIds[k]">Preview</a>
  </div>
</div>
  • <embed> displays the PDF inline (fit‑to‑width).
  • Checkbox for each doc selection.
  • Preview Link opens a modal via AJAX.

6. JavaScript & Client‑Side Behavior

6.1 Select All Checkbox

$("#ckbCheckAll").click(function () {
  $(".checkBoxClass").prop('checked', $(this).prop('checked'));
});
  • Toggles all individual checkboxes when “Select All” is clicked.

6.2 Delete Confirmation

function deleteFiles() {
  var r = confirm("Are you sure you want to delete the selected documents?");
  if (!r) return false;
  $("#DeleteFiles").attr("value", "True");
}
  • Prompts user before deletion; sets hidden DeleteFiles flag.

6.3 AJAX Preview Modal

$(function () {
  $(".previewDetail").click(function () {
    var id = $(this).data('id');
    $.ajax({
      type: "GET",
      url: "/HRImaging/myModalPreview",
      data: { id: id, Preview: true },
      success: function (data) {
        $('#myModalContent').html(data);
        $('#myModal').modal('show');
      },
      error: function () {
        alert("Dynamic content load failed.");
      }
    });
  });
});
  • Workflow:
    1. User clicks “Preview.”
    2. AJAX GET to /HRImaging/myModalPreview with id.
    3. Injects returned HTML into the modal and displays it.

7. Dependencies & Third‑Party Libraries

Library Purpose
jQuery DOM manipulation, AJAX
Bootstrap (CSS & JS) Responsive UI, modals
Bootstrap-datepicker Datepicker components
Dropzone (CSS only) File upload placeholder
tinymce Rich text editor (unused here)
MetisMenu, Simplebar, Node‑Waves Layout & UI enhancements

8. UML Diagrams

8.1 Class Diagram

classDiagram
    DocumentImaging <|-- DocPreview
    DocPreview ..> HRImagingController : SaveDocument()
    DocPreview ..> HRImagingController : Preview(Guid id)
    HRImagingController o-- PartialView : myModalPreview()

8.2 Sequence Diagram

sequenceDiagram
    participant User
    participant View as DocPreview.cshtml
    participant AJAX
    participant Controller as HRImagingController

    User->>View: Loads page with BatchIds
    View->>Controller: Preview(Guid id) for each PDF embed
    User->>View: Clicks “Preview”
    View->>AJAX: GET /HRImaging/myModalPreview?id
    AJAX->>Controller: myModalPreview(id)
    Controller-->>AJAX: PartialView(html)
    AJAX-->>View: Inject HTML into modal
    User->>View: Select/docs & Submit
    View->>Controller: SaveDocument(docIds[], category, deleteFiles)

9. Sample Usage & Code Snippets

Rendering the View

public IActionResult DocPreview(Guid documentImageId, string category)
{
    var model = _imagingService.GetDocumentImagingModel(documentImageId, category);
    return View("DocPreview", model);
}

Controller Action: SaveDocument

[HttpPost]
public IActionResult SaveDocument(DocumentImaging model, Guid[] docIds, string category, bool DeleteFiles)
{
    if(DeleteFiles) _imagingService.DeleteDocuments(docIds);
    else _imagingService.IndexDocuments(docIds, category);
    return RedirectToAction("DocPreview", new { documentImageId = model.DocumentImageId, category });
}

10. Conclusion

DocPreview.cshtml is a comprehensive Razor view enabling:

  • Batch indexing and deletion of HR-related documents
  • Interactive PDF previews via AJAX
  • Responsive layout with Bootstrap

By leveraging the DocumentImaging model, MVC form helpers, and jQuery, it delivers a user-friendly interface for high-volume document processing. 🚀


Happy indexing! 🗂️