]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6660 rewrite setup page
authorStas Vilchik <vilchiks@gmail.com>
Fri, 31 Jul 2015 12:06:14 +0000 (14:06 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Mon, 3 Aug 2015 07:29:15 +0000 (09:29 +0200)
21 files changed:
server/sonar-web/src/main/js/apps/maintenance/main-view.js
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-failed.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-not-supported.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-required.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-running.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-succeeded.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-no-migration.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-failed.hbs [deleted file]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-needed.hbs [deleted file]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-not-supported.hbs [deleted file]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-running.hbs [deleted file]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-succeeded.hbs [deleted file]
server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-no-migration.hbs [deleted file]
server/sonar-web/src/main/js/apps/maintenance/templates/maintenance-main.hbs
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb
server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/db_uptodate.html.erb [deleted file]
server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/dbdown.html.erb [deleted file]
server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/failed.html.erb [deleted file]
server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/form.html.erb [deleted file]
server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/index.html.erb [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/migration_running.html.erb [deleted file]

index 65bcc701939bd71df9165e8169b4f366cc6e0adf..281f6872b8f5277441c7584bece5c6c560a8ba38 100644 (file)
@@ -2,12 +2,21 @@ define([
   './templates'
 ], function () {
 
+  var $ = jQuery;
+
   return Marionette.ItemView.extend({
     template: Templates['maintenance-main'],
 
+    events: {
+      'click #start-migration': 'startMigration'
+    },
+
     initialize: function () {
       var that = this;
-      this.requestOptions = { type: 'GET', url: baseUrl + '/api/system/status' };
+      this.requestOptions = {
+        type: 'GET',
+        url: baseUrl + '/api/system/' + (this.options.setup ? 'db_migration_status' : 'status')
+      };
       setInterval(function () {
         that.refresh();
       }, 5000);
@@ -21,6 +30,21 @@ define([
       });
     },
 
+    startMigration: function () {
+      var that = this;
+      Backbone.ajax({
+        url: baseUrl + '/api/system/migrate_db',
+        type: 'POST'
+      }).done(function (r) {
+        that.model.set(r);
+        that.render();
+      })
+    },
+
+    onRender: function () {
+      $('.page-simple').toggleClass('panel-warning', this.model.get('state') === 'MIGRATION_REQUIRED');
+    },
+
     serializeData: function () {
       return _.extend(this._super(), { setup: this.options.setup });
     }
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-failed.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-failed.hbs
new file mode 100644 (file)
index 0000000..2392a0f
--- /dev/null
@@ -0,0 +1,2 @@
+<h1 class="maintenance-title text-danger">Upgrade Failed</h1>
+<p class="maintenance-text">Database connection cannot be established. Please check database status and JDBC settings.</p>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-not-supported.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-not-supported.hbs
new file mode 100644 (file)
index 0000000..c139aa3
--- /dev/null
@@ -0,0 +1,2 @@
+<h1 class="maintenance-title text-danger">Migration not supported</h1>
+<p>Migration is not supported on embedded databases.</p>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-required.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-required.hbs
new file mode 100644 (file)
index 0000000..ec59b03
--- /dev/null
@@ -0,0 +1,8 @@
+<h1 class="maintenance-title">Upgrade Database</h1>
+<p class="maintenance-text">The database upgrade can take several minutes.</p>
+<p class="maintenance-text">It is mandatory to <strong>back up database</strong> before upgrading.</p>
+<p class="maintenance-text"><strong>Copy the directory /extensions</strong> from previous version before upgrading.
+</p>
+<div class="maintenance-spinner">
+  <button id="start-migration">Upgrade</button>
+</div>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-running.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-running.hbs
new file mode 100644 (file)
index 0000000..52702e2
--- /dev/null
@@ -0,0 +1,11 @@
+<h1 class="maintenance-title">Database Migration</h1>
+{{#if message}}
+  <p class="maintenance-text text-center">{{message}}</p>
+{{/if}}
+{{#if startedAt}}
+  <p class="maintenance-text text-center">
+    Started {{fromNow startedAt}}<br>
+    <small class="text-muted">{{dt startedAt}}</small>
+  </p>
+{{/if}}
+<p class="maintenance-spinner"><i class="spinner"></i></p>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-succeeded.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-migration-succeeded.hbs
new file mode 100644 (file)
index 0000000..ee14eb8
--- /dev/null
@@ -0,0 +1,4 @@
+<h1 class="maintenance-title text-success">Database is up-to-date</h1>
+<p class="maintenance-text text-center">
+  <a href="{{link '/'}}">Go Home</a>
+</p>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-no-migration.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-state-no-migration.hbs
new file mode 100644 (file)
index 0000000..ee20022
--- /dev/null
@@ -0,0 +1,4 @@
+<h1 class="maintenance-title">Database is up-to-date</h1>
+<p class="maintenance-text text-center">
+  <a href="{{link '/'}}">Go Home</a>
+</p>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-failed.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-failed.hbs
deleted file mode 100644 (file)
index 2392a0f..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-<h1 class="maintenance-title text-danger">Upgrade Failed</h1>
-<p class="maintenance-text">Database connection cannot be established. Please check database status and JDBC settings.</p>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-needed.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-needed.hbs
deleted file mode 100644 (file)
index ec59b03..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<h1 class="maintenance-title">Upgrade Database</h1>
-<p class="maintenance-text">The database upgrade can take several minutes.</p>
-<p class="maintenance-text">It is mandatory to <strong>back up database</strong> before upgrading.</p>
-<p class="maintenance-text"><strong>Copy the directory /extensions</strong> from previous version before upgrading.
-</p>
-<div class="maintenance-spinner">
-  <button id="start-migration">Upgrade</button>
-</div>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-not-supported.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-not-supported.hbs
deleted file mode 100644 (file)
index c139aa3..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-<h1 class="maintenance-title text-danger">Migration not supported</h1>
-<p>Migration is not supported on embedded databases.</p>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-running.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-running.hbs
deleted file mode 100644 (file)
index 52702e2..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<h1 class="maintenance-title">Database Migration</h1>
-{{#if message}}
-  <p class="maintenance-text text-center">{{message}}</p>
-{{/if}}
-{{#if startedAt}}
-  <p class="maintenance-text text-center">
-    Started {{fromNow startedAt}}<br>
-    <small class="text-muted">{{dt startedAt}}</small>
-  </p>
-{{/if}}
-<p class="maintenance-spinner"><i class="spinner"></i></p>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-succeeded.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-migration-succeeded.hbs
deleted file mode 100644 (file)
index 8b8c7b8..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<h1 class="maintenance-title text-success">Done</h1>
-<p>Database migration has run and has been successful.</p>
-{{#if startedAt}}
-  <p class="maintenance-text text-center">
-    Started {{fromNow startedAt}}<br>
-    <small class="text-muted">{{dt startedAt}}</small>
-  </p>
-{{/if}}
-<p class="maintenance-spinner"><i class="spinner"></i></p>
diff --git a/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-no-migration.hbs b/server/sonar-web/src/main/js/apps/maintenance/templates/_maintenance-status-no-migration.hbs
deleted file mode 100644 (file)
index ee20022..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<h1 class="maintenance-title">Database is up-to-date</h1>
-<p class="maintenance-text text-center">
-  <a href="{{link '/'}}">Go Home</a>
-</p>
index 668eaee8ba4ec4bbdd04303be786cf0061b1b57c..4e99545bc55ee72494718f723a5bb612825ffb4f 100644 (file)
@@ -7,17 +7,11 @@
 
 {{else}}
 
-  {{#notNull state}}
-    {{#eq state 'NO_MIGRATION'}}{{> '_maintenance-status-no-migration'}}{{/eq}}
-    {{#eq state 'NOT_SUPPORTED'}}{{> '_maintenance-status-migration-not-supported'}}{{/eq}}
-    {{#eq state 'MIGRATION_RUNNING'}}{{> '_maintenance-status-migration-running'}}{{/eq}}
-    {{#eq state 'MIGRATION_SUCCEEDED'}}{{> '_maintenance-status-migration-succeeded'}}{{/eq}}
-    {{#eq state 'MIGRATION_FAILED'}}{{> '_maintenance-status-migration-failed'}}{{/eq}}
-  {{else}}
-    {{#eq status 'UP'}}{{> '_maintenance-status-up'}}{{/eq}}
-    {{#eq status 'DOWN'}}{{> '_maintenance-status-down'}}{{/eq}}
-    {{#eq status 'DB_MIGRATION_NEEDED'}}{{> '_maintenance-status-migration-needed'}}{{/eq}}
-    {{#eq status 'DB_MIGRATION_RUNNING'}}{{> '_maintenance-status-migration-running'}}{{/eq}}
-  {{/notNull}}
+  {{#eq state 'NO_MIGRATION'}}{{> '_maintenance-state-no-migration'}}{{/eq}}
+  {{#eq state 'MIGRATION_REQUIRED'}}{{> '_maintenance-state-migration-required'}}{{/eq}}
+  {{#eq state 'NOT_SUPPORTED'}}{{> '_maintenance-state-migration-not-supported'}}{{/eq}}
+  {{#eq state 'MIGRATION_RUNNING'}}{{> '_maintenance-state-migration-running'}}{{/eq}}
+  {{#eq state 'MIGRATION_SUCCEEDED'}}{{> '_maintenance-state-migration-succeeded'}}{{/eq}}
+  {{#eq state 'MIGRATION_FAILED'}}{{> '_maintenance-state-migration-failed'}}{{/eq}}
 
 {{/unless}}
index 2ea401ffd3f5b4b9c5bf0e0c560d215ed669a226..9223009f5d4f908786b788f7900cb2239e895bb9 100644 (file)
@@ -21,34 +21,9 @@ class SetupController < ApplicationController
   skip_before_filter :check_database_version, :check_authentication
 
   SECTION=Navigation::SECTION_CONFIGURATION
-  
-  verify :method => :post, :only => [ :setup_database ], :redirect_to => { :action => :index }
-    
-  def index
-    if !ActiveRecord::Base.connected?
-      render :template => 'setup/dbdown', :layout => 'nonav'
-    elsif DatabaseMigrationManager.instance.requires_migration?
-      render :template => 'setup/form', :layout => 'nonav'
-    elsif DatabaseMigrationManager.instance.migration_running?
-      render :template => 'setup/migration_running', :layout => 'nonav'
-    elsif DatabaseMigrationManager.instance.migration_failed?
-      render :template => 'setup/failed', :layout => 'nonav'
-    else
-      # migration succeeded, or no need for migration
-      render :template => 'setup/db_uptodate', :layout => 'nonav' 
-    end
-  end
 
-  def setup_database
-    # Ask the DB migration manager to start the migration
-    # => No need to check for authorizations (actually everybody can run the upgrade)
-    # nor concurrent calls (this is handled directly by DatabaseMigrationManager)
-    DatabaseMigrationManager.instance.start_migration
-    redirect_to :action => :index
-  end
-
-  def maintenance
-    render :template => 'setup/maintenance', :layout => 'nonav'
+  def index
+    render :template => 'setup/index', :layout => 'nonav'
   end
   
 end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/db_uptodate.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/db_uptodate.html.erb
deleted file mode 100644 (file)
index cbe4b12..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<meta http-equiv='refresh' content='5;url=<%= home_path -%>'>
-<h1 class="maintenance-title text-success">Database is up-to-date</h1>
-<p class="maintenance-text">
-  You will be redirected shortly to SonarQube.
-  <br>
-  <small class="text-muted">
-    (if this does not happen, you can <a href="<%= home_path -%>">click here to be redirected</a>)
-  </small>
-</p>
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/dbdown.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/dbdown.html.erb
deleted file mode 100644 (file)
index 1040fb7..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<h1 class="maintenance-title text-danger">Fail to connect to database</h1>
-<p class="maintenance-text">Database connection cannot be established. Please check database status and JDBC settings.</p>
-<div class="maintenance-spinner">
-  <%= button_to "Try again", { :action => "index" }, :method => :get %>
-</div>
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/failed.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/failed.html.erb
deleted file mode 100644 (file)
index 3606245..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-<h1 class="maintenance-title text-danger">Impossible to upgrade database</h1>
-<p class="maintenance-text"><%= DatabaseMigrationManager.instance.message -%></p>
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/form.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/form.html.erb
deleted file mode 100644 (file)
index 032d9c3..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<form action="<%= ApplicationController.root_context -%>/setup/setup_database" method="POST">
-  <h1 class="maintenance-title">Upgrade database</h1>
-  <p class="maintenance-text">The database upgrade can take several minutes.</p>
-  <p class="maintenance-text">It is mandatory to <strong>back up database</strong> before upgrading.</p>
-  <p class="maintenance-text"><strong>Copy the directory /extensions</strong> from previous version before upgrading.
-  </p>
-  <div class="maintenance-spinner">
-    <input type="submit" value="Upgrade">
-  </div>
-</form>
-
-<script>
-  (function () {
-    document.querySelector('.page-simple').className += ' panel-warning';
-  })();
-</script>
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/index.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/index.html.erb
new file mode 100644 (file)
index 0000000..d3dacd3
--- /dev/null
@@ -0,0 +1,8 @@
+<% content_for :extra_script do %>
+  <script>
+    require(['apps/maintenance/app'], function (App) {
+      App.start({ el: '#content', setup: true });
+    });
+  </script>
+<% end %>
+
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/migration_running.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/setup/migration_running.html.erb
deleted file mode 100644 (file)
index d10ba7c..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<meta http-equiv='refresh' content='5;'>
-
-<% start_time = DatabaseMigrationManager.instance.migration_start_time %>
-<h1 class="maintenance-title">Database is currently upgrading</h1>
-<p class="maintenance-text text-center">Started <%= distance_of_time_in_words(start_time, Time.now) -%> ago (<%= l start_time -%>)</p>
-<div class="maintenance-spinner"><i class="spinner"></i></div>