]> source.dussan.org Git - sonarqube.git/commitdiff
add project-level background tasks page
authorStas Vilchik <vilchiks@gmail.com>
Mon, 28 Sep 2015 11:49:23 +0000 (13:49 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Mon, 28 Sep 2015 13:01:53 +0000 (15:01 +0200)
server/sonar-web/src/main/js/apps/background-tasks/app.js
server/sonar-web/src/main/js/apps/background-tasks/main.js
server/sonar-web/src/main/js/apps/nav/component/component-nav-menu.jsx
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
server/sonar-web/src/main/webapp/WEB-INF/app/views/project/background_tasks.html.erb [new file with mode: 0644]

index 260457a03c6c607d1a52c7b832365a7f8a04bee0..7a94708fcc2e456571ddf71cf550bc9b72eff020 100644 (file)
@@ -4,6 +4,6 @@ import Main from './main';
 export default {
   start (options) {
     var el = document.querySelector(options.el);
-    React.render(<Main/>, el);
+    React.render(<Main options={options}/>, el);
   }
 };
index a92d1c23ba172a1d99f815831caa46d344e4ca95..0ea7eb73487ec8868a00872d003e462144c0ab20 100644 (file)
@@ -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 });
     });
index fd55fa80097cf29c6fb5aefac9f21866d1096155..30e8f14619be4a3af3fb895112943ac0292c6cd2 100644 (file)
@@ -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;
index f53883b9aa406d8ff742d54f186fc1b0ce5021d1..8601e579f6808d679f3800b74f65de6b3a85ca4d 100644 (file)
@@ -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 (file)
index 0000000..43ebdf9
--- /dev/null
@@ -0,0 +1,7 @@
+<% content_for :extra_script do %>
+  <script>
+    require(['apps/background-tasks/app'], function (App) {
+      App.start({ el: '#content', componentId: '<%= @project.uuid -%>' });
+    });
+  </script>
+<% end %>