Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@filerobot/explorer / lib / components / Details / Details.utils.js
Size: Mime:
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
import { VIEW_IDS } from '@filerobot/utils/lib/constants';
import { toLocaleNumber } from '@filerobot/utils/lib/formatNumbers';
import humanReadableDateWithTranslations from '@filerobot/utils/lib/humanReadableDateWithTranslations';
import formatDuration from '@filerobot/utils/lib/formatDuration';
import formatSeconds from '@filerobot/utils/lib/formatSeconds';
import formatResolution from '@filerobot/utils/lib/formatResolution';
import { getActualVisibility, getVisibilityI18nLabel } from '@filerobot/utils/lib/visibility';
import prettierBytes from '@transloadit/prettier-bytes';
import { DETAILS_VARINATS } from './Details.constants';
var getDetailsType = function getDetailsType(_ref) {
  var activeView = _ref.activeView,
    files = _ref.files,
    folders = _ref.folders,
    selectedFolders = _ref.selectedFolders,
    selectedFiles = _ref.selectedFiles;
  var multipleItems = selectedFolders.length + selectedFiles.length > 1;
  var hasNoItems = !files.length && !folders.length;
  var hasNotItemSelected = !selectedFolders.length && !selectedFiles.length;
  var checkHasItem = function checkHasItem(isFoldersView) {
    if (hasNotItemSelected) detailsVariant = DETAILS_VARINATS.NO_ITEM_SELECTED;
    if (hasNoItems) detailsVariant = DETAILS_VARINATS.NO_ITEMS;
    if (hasNotItemSelected && isFoldersView) detailsVariant = DETAILS_VARINATS.NO_ITEM_SELECTED_IN_FOLDERS;
    if (multipleItems) detailsVariant = DETAILS_VARINATS.MULTI_ITEMS;
  };
  var detailsVariant = '';
  switch (activeView) {
    case VIEW_IDS.ASSETS:
      detailsVariant = DETAILS_VARINATS.FILE;
      checkHasItem();
      break;
    case VIEW_IDS.FOLDERS:
      detailsVariant = selectedFiles.length ? DETAILS_VARINATS.FILE : DETAILS_VARINATS.FOLDER;
      checkHasItem(true);
      break;
    case VIEW_IDS.LABELS:
      detailsVariant = selectedFiles.length ? DETAILS_VARINATS.FILE : DETAILS_VARINATS.LABEL;
      checkHasItem();
      break;
    case VIEW_IDS.COLLECTIONS:
      detailsVariant = DETAILS_VARINATS.COLLECTION;
      checkHasItem();
      break;
    case VIEW_IDS.PRODUCTS:
      detailsVariant = DETAILS_VARINATS.PRODUCT;
      checkHasItem();
      break;
    case VIEW_IDS.FAVORITES:
      detailsVariant = DETAILS_VARINATS.FAVORITES;
      checkHasItem();
      break;
  }
  return detailsVariant;
};
var generateFolderDetails = function generateFolderDetails(_ref2) {
  var _ref2$folder = _ref2.folder,
    folder = _ref2$folder === void 0 ? {} : _ref2$folder,
    numberFormatLocale = _ref2.numberFormatLocale,
    i18n = _ref2.i18n,
    visibilities = _ref2.visibilities;
  var _folder$size = folder.size,
    size = _folder$size === void 0 ? {} : _folder$size,
    _folder$count = folder.count,
    _folder$count2 = _folder$count === void 0 ? {} : _folder$count,
    filesCount = _folder$count2.files_recursive,
    createdAt = folder.created_at,
    modifiedAt = folder.updated_at,
    visibility = folder.visibility;
  var actualVisibility = getActualVisibility(visibility);
  var totalRecursivePretty = size.total_recursive_pretty,
    totalRecursiveBytes = size.total_recursive_bytes;
  return [{
    i18nKey: 'mutualizedTypeLabel',
    value: 'mutualizedFolderLabel',
    translatableValue: true
  }, {
    i18nKey: 'mutualizedSizeKey',
    value: toLocaleNumber(totalRecursivePretty || totalRecursiveBytes, numberFormatLocale)
  }, {
    i18nKey: 'mutualizedFilesLabel',
    value: toLocaleNumber(filesCount, numberFormatLocale)
  }, {
    i18nKey: 'mutualizedVisibilityLabel',
    value: getVisibilityI18nLabel(actualVisibility || visibility),
    translatableValue: true
  }, {
    i18nKey: 'mutualizedCreatedAtText',
    value: humanReadableDateWithTranslations(createdAt, i18n),
    createdAt: true,
    showTooltip: true
  }, {
    i18nKey: 'mutualizedModifiedAtText',
    value: humanReadableDateWithTranslations(modifiedAt, i18n),
    showTooltip: true
  }].filter(function (_ref3) {
    var value = _ref3.value;
    return typeof value === 'number' || value && _typeof(value) !== 'object';
  });
};
var generateFileDetails = function generateFileDetails(_ref4) {
  var file = _ref4.file,
    numberFormatLocale = _ref4.numberFormatLocale,
    i18n = _ref4.i18n;
  var videoDuration = file.videoDuration,
    transcodingProgress = file.transcodingProgress,
    type = file.type,
    pretty = file.size.pretty,
    createdAt = file.created_at,
    _file$info = file.info,
    imageWidth = _file$info.img_w,
    imageHeight = _file$info.img_h,
    videoWidth = _file$info.video_w,
    videoHeight = _file$info.video_h,
    visibility = file.visibility;
  var width = imageWidth || videoWidth;
  var height = imageHeight || videoHeight;
  var ratio = width && height ? (width / height).toPrecision(3) : 0;
  var resolution = width && height ? width + 'x' + height : null;
  var actualVisibility = getActualVisibility(visibility);
  return [{
    i18nKey: 'mutualizedTypeLabel',
    value: type
  }, {
    i18nKey: 'mutualizedSizeKey',
    value: toLocaleNumber(pretty, numberFormatLocale)
  }, {
    i18nKey: 'mutualizedCreatedText',
    value: humanReadableDateWithTranslations(createdAt, i18n),
    showFileTooltip: true
  }, {
    i18nKey: 'mutualizedResolutionLabel',
    value: resolution && formatResolution(toLocaleNumber(resolution, numberFormatLocale), 'x', 'x', true)
  }, {
    i18nKey: 'itemsCardRatioTitle',
    value: toLocaleNumber(ratio, numberFormatLocale)
  }, {
    i18nKey: 'mutualizedDurationLabel',
    value: videoDuration && "".concat(formatDuration(formatSeconds(videoDuration), i18n))
  }, {
    i18nKey: 'mutualizedTranscoded',
    value: transcodingProgress
  }, {
    i18nKey: 'mutualizedVisibilityLabel',
    value: getVisibilityI18nLabel(actualVisibility),
    translatableValue: true
  }].filter(function (_ref5) {
    var value = _ref5.value;
    return value && _typeof(value) !== 'object';
  });
};
var generateMultiItemsDetails = function generateMultiItemsDetails(_ref6) {
  var totalSizeBytes = _ref6.totalSizeBytes,
    totalFilesCount = _ref6.totalFilesCount,
    selectedFoldersCount = _ref6.selectedFoldersCount,
    numberFormatLocale = _ref6.numberFormatLocale;
  return [{
    i18nKey: 'mutualizedSizeKey',
    value: toLocaleNumber(prettierBytes(totalSizeBytes), numberFormatLocale)
  }, {
    i18nKey: 'mutualizedFilesLabel',
    value: toLocaleNumber(totalFilesCount, numberFormatLocale)
  }, {
    i18nKey: 'mutualizeFoldersLabel',
    value: toLocaleNumber(selectedFoldersCount, numberFormatLocale)
  }].filter(function (_ref7) {
    var value = _ref7.value;
    return value && _typeof(value) !== 'object';
  });
};
var prepareHeader = function prepareHeader(_ref8) {
  var selectedFoldersCount = _ref8.selectedFoldersCount,
    selectedFilesCount = _ref8.selectedFilesCount,
    i18n = _ref8.i18n,
    numberFormatLocale = _ref8.numberFormatLocale;
  var showComma = selectedFoldersCount > 0 && selectedFilesCount > 0;
  var folderHeaderText = '';
  var fileHeaderText = '';
  var assetHeaderText = '';
  var selectedText = '';
  if (selectedFoldersCount) {
    folderHeaderText = "".concat(toLocaleNumber(selectedFoldersCount, numberFormatLocale), " ").concat(i18n('mutualizedFoldersLabel')).toLocaleLowerCase();
  }
  if (selectedFilesCount) {
    fileHeaderText = "".concat(toLocaleNumber(selectedFilesCount, numberFormatLocale), " ").concat(i18n('mutualizedFilesLabel')).toLocaleLowerCase();
  }
  if (!selectedFilesCount && !selectedFoldersCount) {
    assetHeaderText = i18n('mutualizedPreviewLabel');
  }
  if (selectedFilesCount || selectedFilesCount) selectedText = i18n('mutualizedSelectedLabel');
  return "".concat(folderHeaderText).concat(showComma ? ', ' : '').concat(fileHeaderText).concat(assetHeaderText, " ").concat(selectedText);
};
var generateProductDetails = function generateProductDetails() {
  var product = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var numberFormatLocale = arguments.length > 1 ? arguments[1] : undefined;
  var _product$stats = product.stats,
    size = _product$stats.size,
    countAssets = _product$stats.count_assets;
  return [{
    i18nKey: 'type',
    value: 'detailsNavProductLabel',
    translatableValue: true
  }, {
    i18nKey: 'size',
    value: toLocaleNumber(size, numberFormatLocale)
  }, {
    i18nKey: 'files',
    value: toLocaleNumber(countAssets, numberFormatLocale)
  }].filter(function (_ref9) {
    var value = _ref9.value;
    return value && _typeof(value) !== 'object';
  });
};
export { getDetailsType, generateFolderDetails, generateFileDetails, generateMultiItemsDetails, prepareHeader, generateProductDetails };