diff --git a/ng/src/gmp/models/task.js b/ng/src/gmp/models/task.js index 9713a89afc..4a9580f8db 100644 --- a/ng/src/gmp/models/task.js +++ b/ng/src/gmp/models/task.js @@ -46,8 +46,23 @@ export const AUTO_DELETE_KEEP = 'keep'; export const AUTO_DELETE_NO = 'no'; export const AUTO_DELETE_DEFAULT_VALUE = 5; -/* eslint-disable quote-props */ export const TASK_STATUS = { + running: 'Running', + stoprequested: 'Stop Requested', + deleterequested: 'Delete Requested', + ultimatedeleterequested: 'Ultimate Delete Requested', + resumerequested: 'Resume Requested', + requested: 'Requested', + stopped: 'Stopped', + new: 'New', + interrupted: 'Interrupted', + container: 'Container', + uploading: 'Uploading', + done: 'Done', +}; + +/* eslint-disable quote-props */ +const TASK_STATUS_TRANSLATIONS = { 'Running': _('Running'), 'Stop Requested': _('Stop Requested'), 'Delete Requested': _('Delete Requested'), @@ -57,6 +72,9 @@ export const TASK_STATUS = { 'Stopped': _('Stopped'), 'New': _('New'), 'Interrupted': _('Interrupted'), + 'Container': _('Container'), + 'Uploading': _('Uploading'), + 'Done': _('Done'), }; /* eslint-disable quote-props */ @@ -64,33 +82,39 @@ function parse_yes(value) { return value === 'yes' ? YES_VALUE : NO_VALUE; } +export const getTranslatableTaskStatus = status => { + console.log('in func status', status); + console.log('in func translation', TASK_STATUS_TRANSLATIONS[status]); + return TASK_STATUS_TRANSLATIONS[status]; +}; + class Task extends Model { static entity_type = 'task'; isActive() { - return this.status === 'Running' || - this.status === 'Stop Requested' || - this.status === 'Delete Requested' || - this.status === 'Ultimate Delete Requested' || - this.status === 'Resume Requested' || - this.status === 'Requested'; + return this.status === TASK_STATUS.running || + this.status === TASK_STATUS.stoprequested || + this.status === TASK_STATUS.deleterequested || + this.status === TASK_STATUS.ultimatedeleterequested || + this.status === TASK_STATUS.resumerequested || + this.status === TASK_STATUS.requested; } isRunning() { - return this.status === 'Running'; + return this.status === TASK_STATUS.running; } isStopped() { - return this.status === 'Stopped'; + return this.status === TASK_STATUS.stopped; } isInterrupted() { - return this.status === 'Interrupted'; + return this.status === TASK_STATUS.interrupted; } isNew() { - return this.status === 'New'; + return this.status === TASK_STATUS.new; } isChangeable() { @@ -105,6 +129,10 @@ class Task extends Model { return !is_defined(this.target); } + getTranslatableStatus() { + return TASK_STATUS_TRANSLATIONS[this.status]; + }; + parseProperties(elem) { elem = super.parseProperties(elem); diff --git a/ng/src/web/components/bar/statusbar.js b/ng/src/web/components/bar/statusbar.js index 2de50b9826..f5642159a5 100644 --- a/ng/src/web/components/bar/statusbar.js +++ b/ng/src/web/components/bar/statusbar.js @@ -2,6 +2,7 @@ * * Authors: * Björn Ricks + * Steffen Waterkamp * * Copyright: * Copyright (C) 2016 - 2018 Greenbone Networks GmbH @@ -24,46 +25,64 @@ import 'core-js/fn/string/includes'; import React from 'react'; +import _ from 'gmp/locale'; + +import { + getTranslatableTaskStatus, + TASK_STATUS, +} from 'gmp/models/task'; + import PropTypes from '../../utils/proptypes.js'; import ProgressBar from './progressbar.js'; const StatusBar = ({status = 'Unknown', progress = '0'}) => { - const st = status.toLowerCase(); - let text = status; - - if (st === 'unknown' || st === 'new' || st === 'done' || st === 'container' || - st.includes('requested')) { + let text = getTranslatableTaskStatus(status); + if (status === 'Unknown' || + status === TASK_STATUS.new || + status === TASK_STATUS.done || + status === TASK_STATUS.container || + status === TASK_STATUS.stoprequested || + status === TASK_STATUS.deleterequested || + status === TASK_STATUS.ultimatedeleterequested || + status === TASK_STATUS.resumerequested || + status === TASK_STATUS.requested) { progress = '100'; } - if (st === 'stopped') { - text = status + ' at ' + progress + ' %'; + if (status === TASK_STATUS.stopped || status === TASK_STATUS.interrupted) { + text = _('{{status}} at {{progress}} %', {status, progress}); } - else if (st === 'running') { - text = progress + ' %'; + else if (status === TASK_STATUS.running) { + text = _('{{progress}} %', {progress}); } let background; - if (st === 'stopped' || st.includes('requested') || st === 'interrupted') { + if (status === TASK_STATUS.stopped || + status === TASK_STATUS.stoprequested || + status === TASK_STATUS.deleterequested || + status === TASK_STATUS.ultimatedeleterequested || + status === TASK_STATUS.resumerequested || + status === TASK_STATUS.requested) { background = 'warn'; } - else if (st.includes('error')) { + else if (status === TASK_STATUS.interrupted) { background = 'error'; } - else if (st === 'uploading' || st === 'container' || - st === 'done') { + else if (status === TASK_STATUS.uploading || + status === TASK_STATUS.container || + status === TASK_STATUS.done) { background = 'low'; } - else if (st === 'new') { + else if (status === TASK_STATUS.new) { background = 'new'; } - else if (st === 'running') { + else if (status === TASK_STATUS.running) { background = 'run'; } return ( diff --git a/ng/src/web/pages/reports/row.js b/ng/src/web/pages/reports/row.js index 0a54788dd2..7012a4dc83 100644 --- a/ng/src/web/pages/reports/row.js +++ b/ng/src/web/pages/reports/row.js @@ -2,9 +2,10 @@ * * Authors: * Björn Ricks + * Steffen Waterkamp * * Copyright: - * Copyright (C) 2017 Greenbone Networks GmbH + * Copyright (C) 2017 - 2018 Greenbone Networks GmbH * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,6 +27,8 @@ import React from 'react'; import _, {datetime} from 'gmp/locale.js'; import {is_defined} from 'gmp/utils'; +import {TASK_STATUS} from 'gmp/models/task'; + import PropTypes from '../../utils/proptypes.js'; import {render_component} from '../../utils/render.js'; @@ -52,10 +55,10 @@ const IconActions = ({ onReportDeltaSelect, }) => { const {report} = entity; - const active = report.scan_run_status !== 'Running' && - report.scan_run_status !== 'Requested' && - report.scan_run_status !== 'Stop Requested' && - report.scan_run_status !== 'Resume Requested'; + const active = report.scan_run_status !== TASK_STATUS.running && + report.scan_run_status !== TASK_STATUS.requested && + report.scan_run_status !== TASK_STATUS.stoprequested && + report.scan_run_status !== TASK_STATUS.resumerequested; const title = active ? _('Delete Report') : _('Scan is active'); @@ -109,7 +112,9 @@ const Row = ({entity, links = true, actions, ...other}) => { if (is_defined(task)) { if (task.isContainer()) { - status = status === 'Running' ? 'Uploading' : 'Container'; + status = status === TASK_STATUS.running ? + TASK_STATUS.uploading : + TASK_STATUS.container; } progress = task.progress; } diff --git a/ng/src/web/pages/tasks/dashboard/statusdisplay.js b/ng/src/web/pages/tasks/dashboard/statusdisplay.js index 057517d116..a92c03497b 100644 --- a/ng/src/web/pages/tasks/dashboard/statusdisplay.js +++ b/ng/src/web/pages/tasks/dashboard/statusdisplay.js @@ -29,6 +29,7 @@ import {interpolateHcl} from 'd3-interpolate'; import _ from 'gmp/locale'; import Filter, {TASKS_FILTER_FILTER} from 'gmp/models/filter'; +import {TASK_STATUS} from 'gmp/models/task'; import {is_defined} from 'gmp/utils/identity'; @@ -58,15 +59,15 @@ const orange = interpolateHcl('#ff7f0e', '#ffbb78'); const taskStatusColorScale = scaleOrdinal() .domain([ - 'Delete Requested', - 'Ultimate Delete Requested', - 'Interrupted', - 'New', - 'Requested', - 'Running', - 'Stop Requested', - 'Stopped', - 'Done', + TASK_STATUS.deleterequested, + TASK_STATUS.ultimatedeleterequested, + TASK_STATUS.interrupted, + TASK_STATUS.new, + TASK_STATUS.requested, + TASK_STATUS.running, + TASK_STATUS.stoprequested, + TASK_STATUS.stopped, + TASK_STATUS.done, 'N/A', ]) .range([ diff --git a/ng/src/web/pages/tasks/status.js b/ng/src/web/pages/tasks/status.js index 2f51fb6c58..fd575077d7 100644 --- a/ng/src/web/pages/tasks/status.js +++ b/ng/src/web/pages/tasks/status.js @@ -2,9 +2,10 @@ * * Authors: * Björn Ricks + * Steffen Waterkamp * * Copyright: - * Copyright (C) 2017 Greenbone Networks GmbH + * Copyright (C) 2017 - 2018 Greenbone Networks GmbH * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,6 +24,8 @@ import React from 'react'; +import {TASK_STATUS} from 'gmp/models/task'; + import {is_defined} from 'gmp/utils'; import PropTypes from '../../utils/proptypes.js'; @@ -51,7 +54,7 @@ const TaskStatus = ({task, links = true}) => { textOnly={!links} > );