Sha256: 5d14b1a0bca03eefc2df8d1ed2b66e26723d0a3d33dbe0d51db9989ad6142121

Contents?: true

Size: 1.7 KB

Versions: 12

Compression:

Stored size: 1.7 KB

Contents

import URI from 'urijs';
import { translate as __, documentLocale } from 'foremanReact/common/I18n';
import humanizeDuration from 'humanize-duration';
import { isoCompatibleDate } from 'foremanReact/common/helpers';

export const updateURlQuery = (query, history) => {
  const uri = new URI(history.location.pathname + history.location.search);
  uri.setSearch(query);
  history.push(uri.search());
};

export const getApiPathname = url => {
  const uri = new URI(url);
  return uri.pathname().replace('foreman_tasks/', 'foreman_tasks/api/');
};

export const resolveSearchQuery = (search, history) => {
  const uriQuery = {
    search,
    page: 1,
  };
  updateURlQuery(uriQuery, history);
};

export const getCSVurl = (path, query) => {
  let url = new URI(path);
  url = url.pathname(`${url.pathname()}.csv`);
  url.addSearch(query);
  return url.toString();
};

export const getDuration = (start, finish) => {
  if (!start && !finish)
    return { text: __('N/A'), tooltip: __('No start or end dates') };

  if (!start && finish) {
    return { text: __('N/A'), tooltip: __('Task was canceled') };
  }

  const dateOptions = {
    largest: 1,
    language: documentLocale(),
    fallbacks: ['en'],
    round: true,
  };

  const startDate = new Date(isoCompatibleDate(start));

  if (!finish) {
    const finishDate = new Date();
    const duration = finishDate - startDate;
    return {
      text: `${__('More than')} ${humanizeDuration(duration, dateOptions)}`,
    };
  }

  const finishDate = new Date(isoCompatibleDate(finish));
  const duration = finishDate - startDate;
  return {
    text:
      duration > 0 && duration < 1000
        ? __('Less than a second')
        : humanizeDuration(duration, dateOptions),
  };
};

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
foreman-tasks-2.0.3 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-3.0.3 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-3.0.2 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-3.0.1 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-3.0.0 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-2.0.2 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-1.1.3 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-1.1.2 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-2.0.1 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-2.0.0 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-1.2.0 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-1.1.1 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js