Skip to content

Commit 27b9c01

Browse files
committed
Implement database creation.
1 parent 3f8b5fc commit 27b9c01

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

assets/webathena-sql/manage.js

+38-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ function showConfirmDialog(database) {
2929
}
3030

3131
function formatSize(bytes) {
32+
if (bytes == 0)
33+
return "0\xA0MB";
3234
var suffixes = ["bytes", "kB", "MB",
3335
// Eh, why not? :-D
3436
"GB", "TB", "PB", "EB", "ZB", "YB"];
@@ -60,10 +62,14 @@ function createRow(name, size) {
6062
return tr;
6163
}
6264

63-
function loadInfo() {
65+
function refreshInfo() {
6466
var locker = getCurrentLocker();
6567
$(".field-locker-name").text(locker);
66-
sqlCommand(["database", "list", locker]).then(function(data) {
68+
clearAlerts("manage-alert");
69+
// showAlert("manage-alert", "Loading...", "Please wait.");
70+
sqlCommand(["database", "list", locker]).finally(function() {
71+
clearAlerts("manage-alert");
72+
}).then(function(data) {
6773
var totalSize = 0;
6874

6975
var tbody = $(".field-database-tbody");
@@ -78,9 +84,36 @@ function loadInfo() {
7884
$(".field-quota").text(formatSize(data.quota));
7985
$(".field-used-percent").text(((totalSize / data.quota) * 100).toFixed(1));
8086
}, function(err) {
81-
// FIXME!
82-
alert(err);
87+
// TODO(davidben): Distinguish UserError from others.
88+
showAlert("manage-alert", "Error", err, "alert-error");
89+
}).done();
90+
}
91+
92+
function setupForms() {
93+
var form = $("#database-create-form");
94+
form.submit(function(ev) {
95+
ev.preventDefault();
96+
var name = form.find(".field-database-name").val();
97+
if (!name)
98+
return;
99+
100+
var locker = getCurrentLocker();
101+
102+
clearAlerts("create-alert");
103+
showAlert("create-alert", "Creating database...", "Please wait.");
104+
form.find(":submit").attr("disabled", "");
105+
106+
sqlCommand(["database", "create", locker, name]).finally(function() {
107+
form.find(":submit").removeAttr("disabled");
108+
clearAlerts("create-alert");
109+
}).then(function() {
110+
refreshInfo();
111+
}, function(err) {
112+
// TODO(davidben): Distinguish UserError from others.
113+
showAlert("create-alert", "Error", err, "alert-error");
114+
}).done();
83115
});
84116
}
85117

86-
loadInfo();
118+
refreshInfo();
119+
setupForms();

manage/index.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ <h3>Are you sure?</h3>
2626
</div>
2727
</div>
2828

29-
<div id="manage-alert-placeholder">
30-
</div>
29+
<div id="manage-alert-placeholder"></div>
3130

3231
<p>
33-
Using <span class="field-used-size"></span> out
34-
of <span class="field-quota"></span>
35-
(<span class="field-used-percent"></span>%).
32+
Using <span class="field-used-size">0 MB</span> out
33+
of <span class="field-quota">0 MB</span>
34+
(<span class="field-used-percent">0</span>%).
3635
</p>
3736
<table class="table table-striped table-hover table-bordered">
3837
<thead>
@@ -60,7 +59,7 @@ <h3>Are you sure?</h3>
6059
-->
6160
</tbody>
6261
</table>
63-
<form class="form-inline">
62+
<form class="form-inline" id="database-create-form">
6463
<fieldset>
6564
<legend>New database</legend>
6665
<div class="input-prepend database-field">
@@ -70,4 +69,5 @@ <h3>Are you sure?</h3>
7069
<button type="submit" class="btn btn-primary">Create</button>
7170
</fieldset>
7271
</form>
72+
<div id="create-alert-placeholder"></div>
7373
<p><em>Limit of 10 databases.</em></p>

0 commit comments

Comments
 (0)