From 6075340e6c02352d1902a9dee10d7a8f2526f3a3 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 25 Sep 2015 16:46:14 +0200 Subject: [PATCH] SONAR-5770 add a analysis status to the component's header --- server/sonar-web/src/main/js/api/ce.js | 5 +++ .../apps/nav/component/component-nav-meta.jsx | 35 +++++++++++++++++-- .../js/apps/nav/component/component-nav.jsx | 22 ++++++++++-- .../js/components/shared/pending-icon.jsx | 13 +++++++ .../sonar-web/src/main/less/init/icons.less | 24 +++++++++++-- .../resources/org/sonar/l10n/core.properties | 19 ++++++++++ 6 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 server/sonar-web/src/main/js/components/shared/pending-icon.jsx diff --git a/server/sonar-web/src/main/js/api/ce.js b/server/sonar-web/src/main/js/api/ce.js index e31b8a4cbf3..2c019eff3b5 100644 --- a/server/sonar-web/src/main/js/api/ce.js +++ b/server/sonar-web/src/main/js/api/ce.js @@ -19,3 +19,8 @@ export function cancelTask (id) { let url = baseUrl + '/api/ce/cancel'; return $.post(url, { id }).then(getTask.bind(null, id)); } + +export function getTasksForComponent(componentId) { + let url = baseUrl + '/api/ce/project'; + return $.get(url, { componentId }); +} diff --git a/server/sonar-web/src/main/js/apps/nav/component/component-nav-meta.jsx b/server/sonar-web/src/main/js/apps/nav/component/component-nav-meta.jsx index 8ebb8e91a42..eb64c48a64c 100644 --- a/server/sonar-web/src/main/js/apps/nav/component/component-nav-meta.jsx +++ b/server/sonar-web/src/main/js/apps/nav/component/component-nav-meta.jsx @@ -1,12 +1,41 @@ import React from 'react'; +import PendingIcon from '../../../components/shared/pending-icon'; export default React.createClass({ render() { - const version = this.props.version ? `Version ${this.props.version}` : null; - const snapshotDate = this.props.snapshotDate ? moment(this.props.snapshotDate).format('LLL') : null; + let metaList = []; + + if (this.props.isInProgress) { + metaList.push( +
  • + {window.t('background_task.status.IN_PROGRESS')} +
  • + ); + } else if (this.props.isPending) { + metaList.push( +
  • + {window.t('background_task.status.PENDING')} +
  • + ); + } else if (this.props.isFailed) { + metaList.push( +
  • + {window.t('background_task.status.FAILED')} +
  • + ); + } + + if (this.props.snapshotDate) { + metaList.push(
  • {moment(this.props.snapshotDate).format('LLL')}
  • ); + } + + if (this.props.version) { + metaList.push(
  • Version {this.props.version}
  • ); + } + return (
    - {version} {snapshotDate} +
      {metaList}
    ); } diff --git a/server/sonar-web/src/main/js/apps/nav/component/component-nav.jsx b/server/sonar-web/src/main/js/apps/nav/component/component-nav.jsx index 29d93a87b64..ce2b4da804d 100644 --- a/server/sonar-web/src/main/js/apps/nav/component/component-nav.jsx +++ b/server/sonar-web/src/main/js/apps/nav/component/component-nav.jsx @@ -1,5 +1,8 @@ import $ from 'jquery'; +import _ from 'underscore'; import React from 'react'; +import {STATUSES} from '../../background-tasks/constants'; +import {getTasksForComponent} from '../../../api/ce'; import ComponentNavFavorite from './component-nav-favorite'; import ComponentNavBreadcrumbs from './component-nav-breadcrumbs'; import ComponentNavMeta from './component-nav-meta'; @@ -11,13 +14,13 @@ export default React.createClass({ }, componentDidMount() { - this.loadDetails(); + this.loadDetails().then(this.loadStatus); }, loadDetails() { const url = `${window.baseUrl}/api/navigation/component`; const data = { componentKey: this.props.componentKey }; - $.get(url, data).done(r => { + return $.get(url, data).done(r => { this.setState({ component: r, conf: r.configuration || {} @@ -25,6 +28,20 @@ export default React.createClass({ }); }, + loadStatus(component) { + getTasksForComponent(component.uuid).done(r => { + this.setState({ + isPending: !!_.findWhere(r.queue, { status: STATUSES.PENDING }), + isInProgress: !!_.findWhere(r.queue, { status: STATUSES.IN_PROGRESS }), + isFailed: r.current && r.current.status === STATUSES.FAILED + }, this.initTooltips); + }); + }, + + initTooltips() { + $('[data-toggle="tooltip"]', React.findDOMNode(this)).tooltip({ container: 'body', placement: 'bottom' }); + }, + render() { return (
    @@ -37,6 +54,7 @@ export default React.createClass({ breadcrumbs={this.state.component.breadcrumbs}/> diff --git a/server/sonar-web/src/main/js/components/shared/pending-icon.jsx b/server/sonar-web/src/main/js/components/shared/pending-icon.jsx new file mode 100644 index 00000000000..6749e973287 --- /dev/null +++ b/server/sonar-web/src/main/js/components/shared/pending-icon.jsx @@ -0,0 +1,13 @@ +import React from 'react'; + +export default React.createClass({ + render() { + return ( + + + + + + ); + } +}); diff --git a/server/sonar-web/src/main/less/init/icons.less b/server/sonar-web/src/main/less/init/icons.less index b6f03b49d91..4fb95d59cc8 100644 --- a/server/sonar-web/src/main/less/init/icons.less +++ b/server/sonar-web/src/main/less/init/icons.less @@ -320,7 +320,7 @@ a[class^="icon-"], a[class*=" icon-"] { } .icon-star-favorite { - animation: spin .6s forwards; + animation: spin-star .6s forwards; } .icon-star-favorite path { @@ -329,7 +329,7 @@ a[class^="icon-"], a[class*=" icon-"] { fill-opacity: 1; } -@keyframes spin { +@keyframes spin-star { 0% { transform: rotate(0deg); } @@ -560,6 +560,26 @@ a[class^="icon-"], a[class*=" icon-"] { background-repeat: no-repeat; } +.icon-pending { + position: relative; + top: -1px; +} +.icon-pending path { + fill: #777; + animation: animation-pending 2s linear infinite; +} +@keyframes animation-pending { + 0% { + fill: #777; + } + 50% { + fill: #aaa; + } + 100% { + fill: #777; + } +} + /* * Spinner diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 10a5feaa031..45bb035fc6c 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -3035,3 +3035,22 @@ update_center.status.COMPATIBLE=Compatible update_center.status.INCOMPATIBLE=Incompatible update_center.status.REQUIRES_SYSTEM_UPGRADE=Requires system update update_center.status.DEPS_REQUIRE_SYSTEM_UPGRADE=Some of dependencies requires system update + + + +#------------------------------------------------------------------------------ +# +# BACKGROUND TASKS +# +#------------------------------------------------------------------------------ +component_navigation.status.failed=The last analysis has failed. +component_navigation.status.pending=There is a pending analysis. +component_navigation.status.in_progress=The analysis is in progress. + +background_task.status.PENDING=Pending +background_task.status.IN_PROGRESS=In Progress +background_task.status.SUCCESS=Success +background_task.status.FAILED=Failed +background_task.status.CANCELED=Canceled + + -- 2.39.5