diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2016-08-22 13:20:05 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2016-08-23 11:42:54 +0200 |
commit | 87c95bc05d147ae016dd9ad5ea48961dec01de68 (patch) | |
tree | addb5a8ced219e8ed44b969723c749124ab8b8a5 /server/sonar-web | |
parent | 502b4c6f0d3eca88237f9351f94c675203530184 (diff) | |
download | sonarqube-87c95bc05d147ae016dd9ad5ea48961dec01de68.tar.gz sonarqube-87c95bc05d147ae016dd9ad5ea48961dec01de68.zip |
SONAR-7847 Add a way to see scanner context in the background page
Diffstat (limited to 'server/sonar-web')
-rw-r--r-- | server/sonar-web/src/main/js/api/ce.js | 4 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/background-tasks/components/Task.js | 30 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js | 86 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.hbs | 17 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.js (renamed from server/sonar-web/src/main/js/apps/background-tasks/components/TaskCancelButton.js) | 42 |
5 files changed, 137 insertions, 42 deletions
diff --git a/server/sonar-web/src/main/js/api/ce.js b/server/sonar-web/src/main/js/api/ce.js index 9eb33301774..3143a1ec9e4 100644 --- a/server/sonar-web/src/main/js/api/ce.js +++ b/server/sonar-web/src/main/js/api/ce.js @@ -39,9 +39,9 @@ export function getStatus (componentId) { return getJSON(url, data); } -export function getTask (id) { +export function getTask (id, additionalFields) { const url = '/api/ce/task'; - return getJSON(url, { id }).then(r => r.task); + return getJSON(url, { id, additionalFields }).then(r => r.task); } export function cancelTask (id) { diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Task.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Task.js index a2084647461..00e41c9b63e 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Task.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Task.js @@ -19,15 +19,13 @@ */ import React from 'react'; import shallowCompare from 'react-addons-shallow-compare'; - import TaskStatus from './TaskStatus'; import TaskComponent from './TaskComponent'; import TaskId from './TaskId'; import TaskDay from './TaskDay'; import TaskDate from './TaskDate'; import TaskExecutionTime from './TaskExecutionTime'; -import TaskCancelButton from './TaskCancelButton'; -import { STATUSES } from './../constants'; +import TaskActions from './TaskActions'; export default class Task extends React.Component { static propTypes = { @@ -44,13 +42,8 @@ export default class Task extends React.Component { return shallowCompare(this, nextProps, nextState); } - handleFilterTask (task, e) { - e.preventDefault(); - this.props.onFilterTask(task); - } - render () { - const { task, index, tasks, component, types, onCancelTask } = this.props; + const { task, index, tasks, component, types, onCancelTask, onFilterTask } = this.props; const prevTask = index > 0 ? tasks[index - 1] : null; @@ -64,20 +57,11 @@ export default class Task extends React.Component { <TaskDate date={task.startedAt} baseDate={task.submittedAt} format="LTS"/> <TaskDate date={task.executedAt} baseDate={task.submittedAt} format="LTS"/> <TaskExecutionTime task={task}/> - - <td className="thin nowrap"> - {!component && ( - <a - onClick={this.handleFilterTask.bind(this, task)} - className="icon-filter icon-half-transparent spacer-left" - href="#" - title={`Show only "${task.componentName}" tasks`} - data-toggle="tooltip"/> - )} - {task.status === STATUSES.PENDING && ( - <TaskCancelButton task={task} onCancelTask={onCancelTask}/> - )} - </td> + <TaskActions + component={component} + task={task} + onFilterTask={onFilterTask} + onCancelTask={onCancelTask}/> </tr> ); } diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js new file mode 100644 index 00000000000..82be5d23870 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js @@ -0,0 +1,86 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import React from 'react'; +import shallowCompare from 'react-addons-shallow-compare'; +import ScannerContextView from '../views/ScannerContextView'; +import { STATUSES } from './../constants'; +import { translate } from '../../../helpers/l10n'; + +export default class TaskActions extends React.Component { + shouldComponentUpdate (nextProps, nextState) { + return shallowCompare(this, nextProps, nextState); + } + + handleFilterClick (e) { + e.preventDefault(); + this.props.onFilterTask(this.props.task); + } + + handleCancelClick (e) { + e.preventDefault(); + this.props.onCancelTask(this.props.task); + } + + handleShowScannerContextClick (e) { + e.preventDefault(); + new ScannerContextView({ task: this.props.task }).render(); + } + + render () { + const { component, task } = this.props; + + return ( + <td className="thin nowrap"> + <div className="dropdown js-task-action"> + <button className="dropdown-toggle" data-toggle="dropdown"> + <i className="icon-dropdown"/> + </button> + <ul className="dropdown-menu dropdown-menu-right"> + {!component && ( + <li> + <a className="js-task-filter" href="#" onClick={this.handleFilterClick.bind(this)}> + <i className="spacer-right icon-filter icon-half-transparent"/> + Show only {task.componentName} tasks + </a> + </li> + )} + {task.status === STATUSES.PENDING && ( + <li> + <a className="js-task-cancel" href="#" onClick={this.handleCancelClick.bind(this)}> + <i className="spacer-right icon-delete"/> + {translate('background_tasks.cancel_task')} + </a> + </li> + )} + {task.hasScannerContext && ( + <li> + <a className="js-task-show-scanner-context" + href="#" + onClick={this.handleShowScannerContextClick.bind(this)}> + {translate('background_tasks.show_scanner_context')} + </a> + </li> + )} + </ul> + </div> + </td> + ); + } +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.hbs b/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.hbs new file mode 100644 index 00000000000..d1de3da84c7 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.hbs @@ -0,0 +1,17 @@ +<form id="deactivate-user-form" autocomplete="off"> + <div class="modal-head"> + <h2>{{t 'background_tasks.scanner_context'}}: {{task.componentName}} [{{t 'background_task.type' task.type}}]</h2> + </div> + <div class="modal-body modal-container"> + <div class="js-modal-messages"></div> + + {{#if scannerContext}} + <pre class="js-task-scanner-context">{{scannerContext}}</pre> + {{else}} + <i class="spinner"></i> + {{/if}} + </div> + <div class="modal-foot"> + <a href="#" class="js-modal-close">{{t 'close'}}</a> + </div> +</form> diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskCancelButton.js b/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.js index 4255f9f9ab8..21da975c6bb 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskCancelButton.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.js @@ -17,23 +17,31 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import React from 'react'; -import { translate } from '../../../helpers/l10n'; +import Modal from '../../../components/common/modals'; +import Template from './ScannerContextView.hbs'; +import { getTask } from '../../../api/ce'; -const TaskCancelButton = ({ task, onCancelTask }) => { - function handleClick (e) { - e.preventDefault(); - onCancelTask(task); - } +export default Modal.extend({ + template: Template, + className: 'modal modal-large', + + initialize () { + this.scannerContext = null; + this.loadScannerContext(); + }, - return ( - <a - onClick={handleClick} - className="spacer-left icon-delete" - title={translate('background_tasks.cancel_task')} - data-toggle="tooltip" - href="#"/> - ); -}; + loadScannerContext() { + getTask(this.options.task.id, ['scannerContext']).then(task => { + this.scannerContext = task.scannerContext; + this.render(); + }); + }, + + serializeData() { + return { + task: this.options.task, + scannerContext: this.scannerContext + }; + } +}); -export default TaskCancelButton; |