📄 DocumentsDirectory.cshtml Documentation

Welcome to the comprehensive guide for IrbyImaging/Views/HRImaging/DocumentsDirectory.cshtml! This view leverages Syncfusion’s EJ2 components to provide a powerful file manager with inline document, PDF, and spreadsheet viewers.


🔖 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Layout & Structure
  4. Key Functional Components
    4.1. 📁 File Manager Integration
    4.2. 📝 Document Editor Viewer
    4.3. 📖 PDF Viewer
    4.4. 📊 Spreadsheet Viewer
  5. Script Hooks & Event Handlers
  6. Helper Methods & Utilities
  7. API Endpoints Overview
  8. Error Handling & Logging
  9. Styling & Layout
  10. UML Diagrams
  11. Sample Code Blocks
  12. Usage Examples
  13. Conclusion

1. Overview & Purpose

This Razor view, DocumentsDirectory.cshtml, is part of the HRImaging area of IrbyImaging. It serves as a central UI for:

  • Managing files and folders (create, rename, delete, drag‑drop, multi‑select 📂).
  • Uploading and downloading documents.
  • Previewing/editing Word, Text, HTML, RTF, XML files inline.
  • Viewing PDF files in‑browser.
  • Opening Excel (.xlsx) spreadsheets with custom data annotations.

The end‑user can seamlessly navigate and manipulate the documents related to HR processes (e.g., employee files, policies).


2. Dependencies & Technologies

Category Library / Framework
Server‑Side ASP.NET Core MVC (Razor)
Client‑Side jQuery
Syncfusion EJ2 FileManager, DocumentEditorContainer, PdfViewer, Spreadsheet, Tooltip
AJAX / JSON $.ajax calls for HTTP POST/GET with JSON payloads
Styling / Layout Bootstrap grid (row, col-lg-*), custom CSS

Note: Syncfusion EJ2 scripts and styles must be referenced in _Layout.cshtml or equivalent.


3. View Layout & Structure

@{ ViewData["Title"] = "Irby HR"; }

<div class="row">
  <div class="col-lg-14">
    <div class="card">
      <div class="card-body">
        <h4 class="card-title mb-4">Manage Documents</h4>
        <div class="control-section">
          <!-- File Manager -->
          <div class="sample-container"> … </div>
          <!-- Document / PDF / Excel Viewers -->
          <div class="doc-container">…</div>
          <div class="pdf-container">…</div>
          <div class="excel-container">…</div>
        </div>
      </div>
    </div>
  </div>
</div>
  • .row / .col-lg-14: Bootstrap grid to center the card.
  • .card / .card-body: Wraps the UI and header.
  • .control-section: Parent of file manager & viewers.

4. Key Functional Components

4.1 📁 File Manager Integration

<ejs-filemanager
  id="file"
  fileOpen="fileOpen"
  created="addTooltip"
  height="650px"
  showThumbnail="true"
  enablePersistence="true"
  allowMultiSelection="true"
  view="Details"
  allowDragAndDrop="true"
  fileDragStart="onFileDragStart"
  fileDragStop="onFileDragStop"
  fileDragging="onFileDragging"
  fileDropped="onFileDropped">
  
  <e-filemanager-ajaxsettings
    url="/HRImaging/FileOperations"
    downloadUrl="/HRImaging/Download"
    uploadUrl="/HRImaging/UploadFiles"
    getImageUrl="/HRImaging/GetImage">
  </e-filemanager-ajaxsettings>
  
  <e-filemanager-contextmenusettings visible="true"></e-filemanager-contextmenusettings>
  <e-filemanager-navigationpanesettings visible="true"></e-filemanager-navigationpanesettings>
  <e-filemanager-toolbarsettings visible="true"></e-filemanager-toolbarsettings>
</ejs-filemanager>
  • ejs-filemanager: Core file‑browsing component.
  • AJAX Settings: Connects to backend endpoints for CRUD, download, thumbnail retrieval.
  • Event Hooks: fileOpen, drag/drop events, created for toolbar tooltips.

4.2 📝 Document Editor Viewer

<ejs-documenteditorcontainer
  id="document"
  enableToolbar="true"
  style="display:block;height:calc(100% - 22px)">
</ejs-documenteditorcontainer>
  • Renders Word‑like editing surface via Syncfusion Document Editor.
  • enableToolbar provides ribbon UI for formatting.

4.3 📖 PDF Viewer

<ejs-pdfviewer
  id="pdfViewer"
  serviceUrl="https://ej2services.syncfusion.com/production/web-services/api/pdfviewer"
  style="height:calc(100% - 22px);display:block">
</ejs-pdfviewer>
  • Embeds a PDF viewing interface.
  • Uses Syncfusion public PDF service for rendering.

4.4 📊 Spreadsheet Viewer

<ejs-spreadsheet
  id="spreadsheet"
  openUrl="/IrbyForms/OpenExcel"
  allowOpen="true"
  saveUrl="/IrbyForms/SaveExcel"
  select="onSelect"
  openComplete="onOpenComplete">
</ejs-spreadsheet>
<div id="customvalue"></div>
  • Loads Excel files in‑browser.
  • Hooks: onOpenComplete to read custom metadata, onSelect to display custom cell info.

5. Script Hooks & Event Handlers

5.1 File Drag & Drop Logging

function onFileDragStart()  { console.log("🚚 Drag start"); }
function onFileDragging()   { console.log("🚚 Dragging"); }
function onFileDragStop()   { console.log("✅ Drag stop"); }
function onFileDropped()    { console.log("📌 File Dropped"); }

5.2 Toolbar Tooltip Customization

function addTooltip() {
  var fm = document.getElementById("file").ej2_instances[0];
  var tooltip = new ej.popups.Tooltip({
    target: '#' + fm.element.id + '_toolbar [title]',
    beforeRender: onTooltipBeforeRender
  });
  tooltip.appendTo('#' + fm.element.id + '_toolbar');
}

function onTooltipBeforeRender(args) {
  // Map toolbar button IDs to human‑readable descriptions
  var btnId = args.target.childNodes[0].id;
  var desc = {
    '_tb_newfolder': 'Create a new folder',
    '_tb_upload':    'Upload new files',
    '_tb_cut':       'Cut selected items',
    '_tb_copy':      'Copy selected items',
    '_tb_paste':     'Paste from clipboard',
    '_tb_delete':    'Delete selected items',
    '_tb_download':  'Download items',
    '_tb_rename':    'Rename item',
    '_tb_sortby':    'Change sorting order',
    '_tb_refresh':   'Refresh view',
    '_tb_view':      'Change layout view',
    '_tb_details':   'Show item details'
  }[btnId.replace(/^file_tb/, '')] || '';
  this.content = args.target.getAttribute('title') + '<br/>' + desc;
}

5.3 Native File Load Tooltip

function fileLoad(args) {
  if (args.module === 'DetailsView') {
    var ele = ej.base.select('[title]', args.element);
    ele.setAttribute('title', `${args.fileDetails.name}\n${args.fileDetails.dateModified}`);
  }
  else if (args.module === 'LargeIconsView') {
    args.element.setAttribute('title', `${args.fileDetails.name}\n${args.fileDetails.dateModified}`);
  }
}

5.4 File Open Dispatcher

function fileOpen(args) {
  var name = args.fileDetails.name,
      path = args.fileDetails.filterPath.replace(/\\/g, "/") + name,
      ext  = args.fileDetails.type;

  if ([".docx",".txt",".html",".rtf",".xml"].includes(ext)) {
    getFileStream(path, false);
  }
  else if (ext === ".pdf") {
    getFileStream(path, true);
  }
  else if (ext === ".xlsx") {
    getBlob(name, path);
  }
}

6. Helper Methods & Utilities

6.1 getFileStream (Documents & PDFs)

  • Purpose: Fetches base64 payload from /HRImaging/GetDocuments and opens a new window with the appropriate Syncfusion viewer.
function getFileStream(filePath, isPDF) {
  $.ajax({
    url: '/HRImaging/GetDocuments',
    type: 'POST',
    dataType: 'text',
    contentType: 'application/json; charset=utf-8',
    data: JSON.stringify({
      FileName: filePath,
      Action: isPDF ? "LoadPDF" : "ImportFile"
    }),
    success: function(data) {
      var popup = window.open("", "_blank", "width=800,height=1200");
      // Inject CSS, JS and create viewer...
      if (!isPDF) {
        // DocumentEditor initialization
      } else {
        // PdfViewer initialization
      }
    },
    error: function(xhr) {
      alert('❌ Exception: ' + xhr.responseText);
    }
  });
}

6.2 getBlob (Spreadsheet)

  • Purpose: Retrieves an Excel file as a Blob and opens it in a new window via Syncfusion Spreadsheet.
function getBlob(fileName, filePath) {
  var popup = window.open("", "_blank", "width=800,height=1200");
  popup.document.write(/* inject Syncfusion CSS/JS and init Spreadsheet */);
}

6.3 Viewer Toggle & Cleanup

function onClicked() {
  // Hide doc/pdf/xls, show file manager
}

6.4 Spreadsheet Events

function onOpenComplete(args) {
  customArgs = args.response.data.customArgs;
}
function onSelect(args) {
  // Show custom cell metadata in #customvalue
}

7. API Endpoints Overview

Endpoint HTTP Purpose
/HRImaging/FileOperations POST FileManager CRUD operations (create/move/rename)
/HRImaging/Download GET Download a file/folder
/HRImaging/UploadFiles POST Upload selected files
/HRImaging/GetImage GET Retrieve thumbnails for images
/HRImaging/GetDocuments POST Returns base64 payload of DOC/RTF/PDF
/IrbyForms/OpenExcel POST Opens Excel for Spreadsheet component
/IrbyForms/SaveExcel POST Saves Excel changes back to server
Syncfusion EJ2 Services GET Public services for PDF/Spreadsheet open & save

8. Error Handling & Logging

  • Console Logs: Drag/drop events, AJAX success debugging.
  • AJAX Error Callbacks: Alerts user via alert('Exception'+…).
  • Missing File Types: Unhandled extensions simply do nothing—can be extended.

9. Styling & Layout

.e-empty-inner-content { display: none; }
.file-container { height:100%; width:100%; }
.title-container { background:#eee; height:22px; }
.doc-container,
.pdf-container,
.excel-container {
  position:absolute; top:0; width:100%; height:100%; visibility:hidden;
}
.excel-container { height:calc(100% - 22px); }
.close-button { float:right; }
body, html { margin:0; width:100%; height:100%; }
  • .title-container: Header bar for each viewer with a close button.
  • .*-container: Overlays above file manager; toggled via JavaScript.

10. UML Diagrams

10.1 Component Diagram

@startuml
package "HRImaging UI" {
  [FileManager] --> [DocumentsDirectory.cshtml]
  [DocumentEditor] <-- [DocumentsDirectory.cshtml]
  [PdfViewer]     <-- [DocumentsDirectory.cshtml]
  [Spreadsheet]   <-- [DocumentsDirectory.cshtml]
}
package "Server Endpoints" {
  [FileOperations]
  [GetDocuments]
  [OpenExcel]
  [SaveExcel]
}
[FileManager] --> [FileOperations]
[DocumentOpen] --> [GetDocuments]
[Spreadsheet] --> [OpenExcel]
[Spreadsheet] --> [SaveExcel]
@enduml

10.2 Sequence Diagram (Open PDF)

@startuml
actor User
participant FileManager
participant DocumentsDirectory.cshtml
participant Server as /HRImaging/GetDocuments
participant Popup as BrowserWindow
User -> FileManager: double-click “report.pdf”
FileManager -> DocumentsDirectory.cshtml: fileOpen(args)
DocumentsDirectory.cshtml -> Server: POST GetDocuments({LoadPDF})
Server --> DocumentsDirectory.cshtml: base64 PDF
DocumentsDirectory.cshtml -> Popup: open window + inject PdfViewer
Popup --> User: displays PDF
@enduml

11. Sample Code Blocks

11.1 Initializing FileManager

<ejs-filemanager id="file" created="addTooltip" fileOpen="fileOpen">
  <!-- AJAX Settings -->
  <e-filemanager-ajaxsettings
     url="/HRImaging/FileOperations"
     downloadUrl="/HRImaging/Download"
     ...
  ></e-filemanager-ajaxsettings>
</ejs-filemanager>

11.2 AJAX Call to Fetch Document

$.ajax({
  url: '/HRImaging/GetDocuments',
  type: 'POST',
  data: JSON.stringify({ FileName: "/Docs/policy.docx", Action: "ImportFile" }),
  contentType: 'application/json',
  success: function(data) {
    // open DocumentEditor in new window
  }
});

12. Usage Examples

  1. Navigate to the HR Documents page via /HRImaging/DocumentsDirectory.
  2. Browse folders in the left pane (tree navigation).
  3. Upload a file using the toolbar or drag‑drop.
  4. Right‑click a file/folder for context menu (rename, delete, etc.).
  5. Double‑click a .docx file → opens new window with syncfusion Document Editor.
  6. Double‑click a .pdf file → opens new window with PDF Viewer.
  7. Double‑click an .xlsx → opens new spreadsheet with custom annotations.

💡 Tip: Customize endpoints and permissions in the HRImaging controllers to suit your environment.


13. Conclusion

This view unifies file management and rich content viewers into one streamlined interface for HR document workflows. By leveraging Syncfusion EJ2 components, it offers:

  • Robust file operations with persistence, thumbnails, multi‑select, and drag‑and‑drop.
  • Inline previews for documents, PDFs, and spreadsheets.
  • Extensible event hooks for tooltips, custom metadata display, and advanced behaviors.

Feel free to extend the helper methods, add new file-type handlers, and integrate further business logic as required! 🚀


Authored with ❤️ by the IrbyImaging DevOps Team