Sha256: 74e74bbd7a1032965e8320bfd44890e17587deafdaacc8d2499986ab9544e4cd

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 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 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

9 entries across 9 versions & 1 rubygems

Version Path
foreman-tasks-3.0.6 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-5.0.0 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-4.1.2 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-4.1.1 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-4.0.1 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-4.1.0 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-3.0.5 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-4.0.0 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js
foreman-tasks-3.0.4 webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js