{"size": 4101, "ext": "js", "max_stars_repo_path": "addon/components/workflow-visualiser/lane/task.js", "max_stars_repo_name": "onedata/onedata-gui-common", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "addon/components/workflow-visualiser/lane/task.js", "max_issues_repo_name": "onedata/onedata-gui-common", "max_issues_repo_issues_event_min_datetime": "2020-04-07T15:31:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-15T02:27:22.000Z", "max_forks_repo_path": "addon/components/workflow-visualiser/lane/task.js", "max_forks_repo_name": "onedata/onedata-gui-common", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 25.3148148148, "max_line_length": 113, "alphanum_fraction": 0.6483784443}
/**
 * Task - single job with progress.
 *
 * @module components/workflow-visualiser/lane/task
 * @author Michał Borzęcki
 * @copyright (C) 2021 ACK CYFRONET AGH
 * @license This software is released under the MIT license cited in 'LICENSE.txt'.
 */

import VisualiserElement from 'onedata-gui-common/components/workflow-visualiser/visualiser-element';
import layout from 'onedata-gui-common/templates/components/workflow-visualiser/lane/task';
import { get, computed } from '@ember/object';
import { reads, collect } from '@ember/object/computed';
import { tag, raw, conditional, equal, or } from 'ember-awesome-macros';
import { scheduleOnce } from '@ember/runloop';
import { normalizeTaskStatus, translateTaskStatus } from 'onedata-gui-common/utils/workflow-visualiser/statuses';
import { inject as service } from '@ember/service';

export default VisualiserElement.extend({
  layout,
  classNames: ['workflow-visualiser-task'],
  classNameBindings: ['statusClass'],

  clipboardActions: service(),

  /**
   * @override
   */
  i18nPrefix: 'components.workflowVisualiser.task',

  /**
   * @type {Boolean}
   */
  areActionsOpened: false,

  /**
   * @type {Boolean}
   */
  areDetailsExpanded: false,

  /**
   * @type {ComputedProperty<Utils.WorkflowVisualiser.Lane.Task>}
   */
  task: reads('elementModel'),

  /**
   * @type {ComputedProperty<String>}
   */
  name: reads('task.name'),

  /**
   * @type {ComputedProperty<String>}
   */
  statusTranslation: computed('effectiveStatus', function statusTranslation() {
    const {
      i18n,
      effectiveStatus,
    } = this.getProperties('i18n', 'effectiveStatus');
    return translateTaskStatus(i18n, effectiveStatus);
  }),

  /**
   * @type {ComputedProperty<Number>}
   */
  itemsInProcessing: or('task.itemsInProcessing', raw(0)),

  /**
   * @type {ComputedProperty<Number>}
   */
  itemsProcessed: or('task.itemsProcessed', raw(0)),

  /**
   * @type {ComputedProperty<Number>}
   */
  itemsFailed: or('task.itemsFailed', raw(0)),

  /**
   * @type {ComputedProperty<String>}
   */
  effectiveStatus: computed('task.status', function effectiveStatus() {
    return normalizeTaskStatus(this.get('task.status'));
  }),

  /**
   * @type {ComputedProperty<String>}
   */
  statusClass: conditional(
    equal('mode', raw('view')),
    tag `status-${'effectiveStatus'}`,
    raw('')
  ),

  /**
   * @type {ComputedProperty<Util.Action>}
   */
  copyInstanceIdAction: computed('task.instanceId', function copyIdAction() {
    const {
      clipboardActions,
      task,
    } = this.getProperties('clipboardActions', 'task');
    return clipboardActions.createCopyRecordIdAction({
      record: { entityId: get(task, 'instanceId') },
    });
  }),

  /**
   * @type {ComputedProperty<Utils.Action>}
   */
  modifyTaskAction: computed('actionsFactory', 'task', function modifyTaskAction() {
    const {
      actionsFactory,
      task,
    } = this.getProperties('actionsFactory', 'task');

    return actionsFactory.createModifyTaskAction({ task });
  }),

  /**
   * @type {ComputedProperty<Utils.Action>}
   */
  removeTaskAction: computed('actionsFactory', 'task', function removeTaskAction() {
    const {
      actionsFactory,
      task,
    } = this.getProperties('actionsFactory', 'task');

    return actionsFactory.createRemoveTaskAction({ task });
  }),

  /**
   * @type {ComputedProperty<Array<Utils.Action>>}
   */
  taskActions: collect('modifyTaskAction', 'removeTaskAction'),

  actions: {
    changeName(newName) {
      return this.get('task').modify({ name: newName });
    },
    toggleActionsOpen(state) {
      scheduleOnce('afterRender', this, 'set', 'areActionsOpened', state);
    },
    headerClick() {
      if (this.get('mode') !== 'view') {
        return;
      }

      this.toggleProperty('areDetailsExpanded');
    },
    showAuditLog() {
      if (this.get('mode') !== 'view') {
        return;
      }

      const {
        actionsFactory,
        task,
      } = this.getProperties('actionsFactory', 'task');
      actionsFactory.createViewTaskAuditLogAction({ task }).execute();
    },
  },
});
