eLabSDK2.Inventory.Sample.SampleList

Hierarchy

Properties

eventQueue

Static eventQueue: any[] = []

Register a custom bulk action button in the sample list page.

This adds a custom action button that appears when one or more samples are selected
in the sample list. Bulk actions allow you to perform operations on multiple samples
at once, such as exporting data, moving samples, changing statuses, or triggering
custom workflows. The action visibility can be controlled using the showCondition function.

Param

{
id: string,
label: string,
title?: string,
icon?: string,
onClick: () => void,
showCondition?: () => boolean
}

Param

Unique identifier for this action.

Param

Text label displayed on the action button.

Param

Optional tooltip text shown on hover.

Param

Optional FontAwesome icon class (e.g., 'fas fa-download', 'fas fa-trash').

Param

Function executed when the action is clicked. Use getSelectedSamples() or getSelectedSamplesIDs() to access selected items.

Param

Optional function that returns boolean to control when the action is visible/enabled.

Example

// Add bulk export action for selected samples
eLabSDK2.Inventory.Sample.SampleList.registerAction({
  id: 'bulk-export-samples',
  label: 'Export to CSV',
  title: 'Export selected samples to CSV',
  icon: 'fas fa-file-csv',
  onClick: () => {
    const selected = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamples();
    const csvData = convertSamplesToCSV(selected);
    downloadFile(csvData, 'samples.csv');
  },
  showCondition: () => {
    return eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs().length > 0;
  }
});

Example

// Add bulk status update action
eLabSDK2.Inventory.Sample.SampleList.registerAction({
  id: 'mark-as-consumed',
  label: 'Mark as Consumed',
  icon: 'fas fa-check',
  onClick: async () => {
    const sampleIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
    await updateSampleStatus(sampleIds, 'CONSUMED');
    eLabSDK2.Inventory.Sample.SampleList.reloadSamples();
    eLabSDK2.UI.Toast.showToast('Samples marked as consumed', 3000);
  },
  showCondition: () => {
    return eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs().length > 0;
  }
});

Methods

getSelectedSamples

Static getSelectedSamples(): SampleListItem[]

Get the complete sample objects for currently selected samples from the sample list page.

This retrieves an array of full sample objects for all samples that the user has selected
(checked) in the sample list view. Each sample object contains comprehensive information
including name, barcode, metadata, location, and more. The function automatically handles
both individual samples and samples within series, extracting individual samples from
series when needed. Returns an empty array if no samples are selected.

Returns

SampleListItem[]

An array of SampleListItem objects representing the selected samples. Each object contains properties like sampleID, name, barcode, sampleTypeID, storageLayerID, and metadata.

Example

// Get selected samples and display their details
const selected = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamples();
console.log(`${selected.length} samples selected:`);
selected.forEach(sample => {
  console.log(`- ${sample.name} (Barcode: ${sample.barcode})`);
});

Example

// Filter selected samples by type
const selected = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamples();
const antibodies = selected.filter(s => s.sampleTypeID === 5);
const reagents = selected.filter(s => s.sampleTypeID === 10);
console.log(`Antibodies: ${antibodies.length}, Reagents: ${reagents.length}`);

Example

// Export selected samples with full details
const selected = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamples();
const exportData = selected.map(sample => ({
  id: sample.sampleID,
  name: sample.name,
  barcode: sample.barcode,
  location: sample.storageLayerName,
  type: sample.sampleTypeName
}));
downloadCSV(exportData, 'selected-samples.csv');

Example

// Perform operations on selected samples
const selected = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamples();
for (const sample of selected) {
  if (sample.quantity && sample.quantity.amount < sample.quantity.thresholdAmount) {
    console.log(`Warning: ${sample.name} is below threshold`);
  }
}

getSelectedSamplesIDs

Static getSelectedSamplesIDs(): number[]

Get the IDs of currently selected samples from the sample list page.

This retrieves an array of sample IDs for all samples that the user has selected
(checked) in the sample list view. Use this for bulk operations where you only
need the IDs rather than the full sample objects, which is more efficient for
API calls and data processing. Returns an empty array if no samples are selected.

Returns

number[]

An array of numeric sample IDs for all currently selected samples.

Example

// Get selected sample IDs and log count
const selectedIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
console.log(`${selectedIds.length} samples selected`);
console.log('Sample IDs:', selectedIds);

Example

// Use IDs for bulk API call
const sampleIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
if (sampleIds.length > 0) {
  await api.updateSamples(sampleIds, { status: 'ARCHIVED' });
  eLabSDK2.UI.Toast.showToast(`${sampleIds.length} samples archived`, 3000);
}

Example

// Check selection before performing action
const selectedIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
if (selectedIds.length === 0) {
  eLabSDK2.UI.Toast.showToast('Please select at least one sample');
  return;
}
performBulkOperation(selectedIds);

onAfterPageLoad

Static onAfterPageLoad(callback, id): void

Register a callback to execute after the sample list page DOM has been fully rendered.

This event fires after the page has completed rendering the DOM and all initial sample
data is loaded and displayed. Use this for tasks that require the DOM to exist, such as
manipulating page elements, attaching event listeners, initializing UI components, or
performing actions based on the loaded sample data.

Parameters

NameTypeDescription
callbackFunctionFunction to execute after the DOM is rendered. Receives detail information as parameter.
idstringUnique identifier for this callback registration.

Returns

void

Example

// Manipulate DOM after page loads
eLabSDK2.Inventory.Sample.SampleList.onAfterPageLoad((detail) => {
  console.log('Sample list rendered:', detail);
  // Add custom styling or elements
  const listContainer = document.querySelector('.sample-list');
  if (listContainer) {
    listContainer.classList.add('custom-theme');
  }
}, 'customize-ui');

Example

// Attach event listeners after render
eLabSDK2.Inventory.Sample.SampleList.onAfterPageLoad(() => {
  document.querySelectorAll('.sample-row').forEach(row => {
    row.addEventListener('dblclick', handleSampleDoubleClick);
  });
}, 'attach-event-listeners');

Example

// Initialize third-party components
eLabSDK2.Inventory.Sample.SampleList.onAfterPageLoad(() => {
  // Initialize DataTables, tooltips, or other UI libraries
  $('.sample-tooltip').tooltip();
  initializeCustomFilters();
}, 'init-ui-components');

Example

// Measure page load time
eLabSDK2.Inventory.Sample.SampleList.onAfterPageLoad(() => {
  const loadTime = Date.now() - window.sampleListLoadStart;
  console.log(`Sample list loaded in ${loadTime}ms`);
  trackAnalytics('sample_list_load_time', loadTime);
}, 'measure-performance');

Overrides

Sample.onAfterPageLoad


onBeforePageLoad

Static onBeforePageLoad(callback, id): void

Register a callback to execute before the sample list page loads data and renders the DOM.

This event fires at the very beginning of the page load process, before any sample data
is fetched or the DOM is rendered. Use this for early initialization tasks such as
setting up global state, preparing data structures, modifying filters, or configuring
the page loading behavior. This is the earliest hook available in the sample list
page lifecycle.

Parameters

NameTypeDescription
callbackFunctionFunction to execute before page load begins. Receives detail information as parameter.
idstringUnique identifier for this callback registration.

Returns

void

Example

// Initialize custom state before page loads
eLabSDK2.Inventory.Sample.SampleList.onBeforePageLoad((detail) => {
  console.log('Sample list loading:', detail);
  initializeCustomFilters();
  setupAnalyticsTracking();
}, 'init-sample-list');

Example

// Modify filters before data loads
eLabSDK2.Inventory.Sample.SampleList.onBeforePageLoad(() => {
  // Apply custom default filters
  const userRole = getUserRole();
  if (userRole === 'restricted') {
    applyRestrictedFilters();
  }
}, 'apply-custom-filters');

Example

// Track page load performance
eLabSDK2.Inventory.Sample.SampleList.onBeforePageLoad(() => {
  window.sampleListLoadStart = Date.now();
}, 'performance-tracking');

Overrides

Sample.onBeforePageLoad


registerAddSampleAction

Static registerAddSampleAction(action): void

Register a custom action in the 'Add Sample' workflow.

This adds a custom action that appears in the sample creation workflow, allowing you
to extend or customize the sample creation process. Use this to add validation,
trigger additional workflows, or integrate custom functionality when samples are created.

Parameters

NameTypeDescription
actionAction{ id: string, label: string, onClick: (sampleData: any) => void | boolean }

Returns

void

Example

// Add validation action during sample creation
eLabSDK2.Inventory.Sample.SampleList.registerAddSampleAction({
  id: 'validate-sample-barcode',
  label: 'Validate Barcode',
  onClick: (sampleData) => {
    const isValid = validateBarcode(sampleData.barcode);
    if (!isValid) {
      eLabSDK2.UI.Toast.showToast('Invalid barcode format', 5000);
      return false;
    }
    return true;
  }
});

Example

// Trigger external system integration
eLabSDK2.Inventory.Sample.SampleList.registerAddSampleAction({
  id: 'sync-to-external-system',
  label: 'Sync to LIMS',
  onClick: async (sampleData) => {
    await syncToExternalLIMS(sampleData);
    eLabSDK2.UI.Toast.showToast('Sample synced to LIMS', 3000);
  }
});

reloadSamples

Static reloadSamples(): void

Reload the sample list to reflect the latest data from the server.

This refreshes the sample list view by fetching the latest sample data based on the
current filters and active storage layer. Use this after performing operations that
modify samples (create, update, delete) to ensure the list displays current data.
The function automatically clears the current selection and applies the existing
filter settings to the reload.

Returns

void

Example

// Reload after creating a new sample
async function createSample(sampleData) {
  await api.createSample(sampleData);
  eLabSDK2.Inventory.Sample.SampleList.reloadSamples();
  eLabSDK2.UI.Toast.showToast('Sample created successfully', 3000);
}

Example

// Reload after bulk update
async function updateSelectedSamples(updates) {
  const sampleIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
  await api.updateSamples(sampleIds, updates);
  eLabSDK2.Inventory.Sample.SampleList.reloadSamples();
}

Example

// Reload in a custom bulk action
eLabSDK2.Inventory.Sample.SampleList.registerAction({
  id: 'archive-samples',
  label: 'Archive',
  onClick: async () => {
    const sampleIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
    await archiveSamples(sampleIds);
    eLabSDK2.Inventory.Sample.SampleList.reloadSamples();
    eLabSDK2.UI.Toast.showToast('Samples archived', 3000);
  }
});

© 2023 eLabNext