Add tables tree

This commit is contained in:
Naoki Takezoe
2017-12-29 04:50:58 +09:00
parent 5fd2d61861
commit ae9ee4779f
14 changed files with 10747 additions and 6 deletions

View File

@@ -13,16 +13,20 @@ import gitbucket.core.util.SyntaxSugars._
import gitbucket.core.util.Directory._
import gitbucket.core.util.StringUtil._
import org.scalatra.forms._
import org.apache.commons.io.{FileUtils, IOUtils}
import org.apache.commons.io.IOUtils
import org.scalatra.i18n.Messages
import com.github.zafarkhaja.semver.{Version => Semver}
import gitbucket.core.GitBucketCoreModule
import scala.collection.JavaConverters._
import scala.collection.JavaConverters._
import scala.collection.mutable.ListBuffer
class SystemSettingsController extends SystemSettingsControllerBase
with AccountService with RepositoryService with AdminAuthenticator
case class Table(name: String, columns: Seq[Column])
case class Column(name: String)
trait SystemSettingsControllerBase extends AccountManagementControllerBase {
self: AccountService with RepositoryService with AdminAuthenticator =>
@@ -153,7 +157,23 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
get("/admin/dbviewer")(adminOnly {
html.dbviewer()
val conn = request2Session(request).conn
val meta = conn.getMetaData
val tables = ListBuffer[Table]()
using(meta.getTables(null, "%", "%", Array("TABLE", "VIEW"))){ rs =>
while(rs.next()){
val tableName = rs.getString("TABLE_NAME")
val columns = ListBuffer[Column]()
using(meta.getColumns(null, "%", tableName, "%")){ rs =>
while(rs.next()){
columns += Column(rs.getString("COLUMN_NAME").toUpperCase)
}
}
tables += Table(tableName.toUpperCase, columns)
}
}
html.dbviewer(tables)
})
get("/admin/system")(adminOnly {

View File

@@ -1,15 +1,45 @@
@()(implicit context: gitbucket.core.controller.Context)
@(tables: Seq[gitbucket.core.controller.Table])(implicit context: gitbucket.core.controller.Context)
@gitbucket.core.html.main("Database viewer") {
@gitbucket.core.admin.html.menu("dbviewer") {
<div id="editor" style="width: 100%; height: 300px;"></div>
<div id="result"></div>
<div>
<div class="col-md-3">
<div id="table-tree">
<ul>
@tables.map { table =>
<li>@table.name
<ul>
@table.columns.map { column =>
<li>@column.name</li>
}
</ul>
</li>
}
</ul>
</div>
</div>
<div class="col-md-9">
<div id="editor" style="width: 100%; height: 300px;"></div>
<div class="block">
<input type="button" value="Run query" id="run-query" class="btn btn-success">
</div>
<div id="result"></div>
</div>
</div>
}
}
<script src="@gitbucket.core.view.helpers.assets("/vendors/ace/ace.js")" type="text/javascript" charset="utf-8"></script>
<script src="@gitbucket.core.view.helpers.assets("/vendors/vakata-jstree-3.3.4/jstree.min.js")" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="@gitbucket.core.view.helpers.assets("/vendors/vakata-jstree-3.3.4/themes/default/style.min.css")" />
<script>
$(function(){
$('#editor').text($('#initial').val());
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
$('#table-tree').jstree();
$('#run-query').click(function(){
console.log(editor.getValue());
});
});
</script>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB