From 9e510dfd203b2f6dc6a27c8df49d515d9f171b9a Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 28 Sep 2015 13:49:23 +0200 Subject: [PATCH] add project-level background tasks page --- .../src/main/js/apps/background-tasks/app.js | 2 +- .../src/main/js/apps/background-tasks/main.js | 34 ++++++++++++++++--- .../apps/nav/component/component-nav-menu.jsx | 7 ++++ .../app/controllers/project_controller.rb | 4 +++ .../views/project/background_tasks.html.erb | 7 ++++ 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/app/views/project/background_tasks.html.erb diff --git a/server/sonar-web/src/main/js/apps/background-tasks/app.js b/server/sonar-web/src/main/js/apps/background-tasks/app.js index 260457a03c6..7a94708fcc2 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/app.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/app.js @@ -4,6 +4,6 @@ import Main from './main'; export default { start (options) { var el = document.querySelector(options.el); - React.render(
, el); + React.render(
, el); } }; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/main.js b/server/sonar-web/src/main/js/apps/background-tasks/main.js index a92d1c23ba1..0ea7eb73487 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/main.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/main.js @@ -22,10 +22,28 @@ export default React.createClass({ }; }, + filterQueueForComponent(queue) { + if (this.props.options.componentId) { + return queue.filter(task => { + return task.componentId === this.props.options.componentId + }); + } else { + return queue; + } + }, + componentDidMount() { this.requestData(); }, + getComponentFilter() { + if (this.props.options.componentId) { + return { componentId: this.props.options.componentId }; + } else { + return {}; + } + }, + getCurrentFilters() { let filters = {}; if (this.state.statusFilter !== STATUSES.ALL) { @@ -46,10 +64,11 @@ export default React.createClass({ requestQueue() { if (!Object.keys(this.getCurrentFilters()).length) { getQueue().done(queue => { + let tasks = this.filterQueueForComponent(queue.tasks); this.setState({ - queue: this.orderTasks(queue.tasks), - pendingCount: this.countPending(queue.tasks), - inProgressDuration: this.getInProgressDuration(queue.tasks) + queue: this.orderTasks(tasks), + pendingCount: this.countPending(tasks), + inProgressDuration: this.getInProgressDuration(tasks) }); }); } else { @@ -58,7 +77,10 @@ export default React.createClass({ }, requestActivity() { - let filters = _.extend(this.getCurrentFilters(), { p: this.state.activityPage, ps: PAGE_SIZE }); + let filters = _.extend( + this.getCurrentFilters(), + this.getComponentFilter(), + { p: this.state.activityPage, ps: PAGE_SIZE }); getActivity(filters).done(activity => { let newActivity = activity.paging.pageIndex === 1 ? activity.tasks : [].concat(this.state.activity, activity.tasks); @@ -71,7 +93,9 @@ export default React.createClass({ }, requestFailures() { - let filters = { ps: 1, onlyCurrents: true, status: STATUSES.FAILED }; + let filters = _.extend( + this.getComponentFilter(), + { ps: 1, onlyCurrents: true, status: STATUSES.FAILED }); getActivity(filters).done(failures => { this.setState({ failuresCount: failures.paging.total }); }); diff --git a/server/sonar-web/src/main/js/apps/nav/component/component-nav-menu.jsx b/server/sonar-web/src/main/js/apps/nav/component/component-nav-menu.jsx index fd55fa80097..30e8f14619b 100644 --- a/server/sonar-web/src/main/js/apps/nav/component/component-nav-menu.jsx +++ b/server/sonar-web/src/main/js/apps/nav/component/component-nav-menu.jsx @@ -71,6 +71,7 @@ export default React.createClass({ {this.renderLinksLink()} {this.renderPermissionsLink()} {this.renderHistoryLink()} + {this.renderBackgroundTasksLink()} {this.renderUpdateKeyLink()} {this.renderDeletionLink()} {this.renderExtensions()} @@ -143,6 +144,12 @@ export default React.createClass({ return this.renderLink(url, window.t('project_history.page'), '/project/history'); }, + renderBackgroundTasksLink() { + // TODO check permissions + const url = `/project/background_tasks?id=${encodeURIComponent(this.props.component.key)}`; + return this.renderLink(url, 'Background Tasks', '/project/background_tasks'); + }, + renderUpdateKeyLink() { if (!this.props.conf.showUpdateKey) { return null; diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb index f53883b9aa4..8601e579f68 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb @@ -225,6 +225,10 @@ class ProjectController < ApplicationController :include => 'events', :order => 'snapshots.created_at DESC') end + def background_tasks + @project = get_current_project(params[:id]) + end + def delete_snapshot_history @project = get_current_project(params[:id]) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/project/background_tasks.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/project/background_tasks.html.erb new file mode 100644 index 00000000000..43ebdf92fc1 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/project/background_tasks.html.erb @@ -0,0 +1,7 @@ +<% content_for :extra_script do %> + +<% end %> -- 2.39.5