Commit 8b71bdb9 authored by Maria Arsuaga Rios's avatar Maria Arsuaga Rios
Browse files

FTS-442:Make more intuitive the interface for configuring Cloud storages

parent 079fac0f
Pipeline #74828 passed with stage
in 19 seconds
......@@ -40,6 +40,8 @@ function saveStorage(form)
});
}
/**
* Delete a storage
*/
......@@ -64,9 +66,9 @@ function deleteStorage(storage_name, div)
}
/**
* Save a user
* Save a dropbox user
*/
function saveUser(storage_name, form)
function saveDropboxUser(storage_name, form)
{
var msg = {
user_dn: form.find("input[name='user-dn']").val(),
......@@ -88,6 +90,29 @@ function saveUser(storage_name, form)
});
}
/**
* Save a S3 user
*/
function saveS3User(storage_name, form)
{
var msg = {
user_dn: form.find("input[name='user-dn']").val(),
vo_name: form.find("input[name='vo-name']").val(),
access-key: form.find("input[name='access-key']").val(),
secret-key: form.find("input[name='secret-key']").val(),
};
console.log(msg);
return $.ajax({
url: "/config/cloud_storage/" + encodeURIComponent(storage_name),
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(msg)
});
}
/**
* Delete a user
*/
......@@ -153,12 +178,26 @@ function refreshCloudStorage()
});
});
// Attach to add a user
var addUserFrm = div.find(".frm-add-user");
var addUserBtn = addUserFrm.find(".btn-add-user");
addUserBtn.click(function(event) {
// Attach to add a dropbox user
var addDropboxUserFrm = div.find(".frm-add-dropbox-user");
var addDropboxUserBtn = addDropboxUserFrm.find(".btn-add-dropbox-user");
addDropboxUserBtn.click(function(event) {
event.preventDefault();
saveDropboxUser(storage.storage_name, addDropboxUserFrm)
.done(function(data, textStatus, jqXHR) {
refreshCloudStorage();
})
.fail(function(jqXHR) {
errorMessage(jqXHR);
});
});
// Attach to add a s3 user
var addS3UserFrm = div.find(".frm-add-s3-user");
var addS3UserBtn = addS3UserFrm.find(".btn-add-s3-user");
addS3UserBtn.click(function(event) {
event.preventDefault();
saveUser(storage.storage_name, addUserFrm)
saveS3User(storage.storage_name, addS3UserFrm)
.done(function(data, textStatus, jqXHR) {
refreshCloudStorage();
})
......@@ -170,15 +209,29 @@ function refreshCloudStorage()
// Attach to remove and modify a user
div.find(".user-entry").each(function() {
var tr = $(this);
var deleteUserBtn = tr.find(".btn-delete-user");
deleteUserBtn.click(function(event) {
var deleteDropboxUserBtn = tr.find(".btn-delete-dropbox-user");
deleteDropboxUserBtn.click(function(event) {
event.preventDefault();
deleteUser(storage.storage_name, tr);
});
var saveUserBtn = tr.find(".btn-save-user");
saveUserBtn.click(function(event) {
var saveDropboxUserBtn = tr.find(".btn-save-dropbox-user");
saveDropboxUserBtn.click(function(event) {
event.preventDefault();
saveUser(storage.storage_name, tr)
saveDropboxUser(storage.storage_name, tr)
});
});
/ Attach to remove and modify a user
div.find(".user-entry").each(function() {
var tr = $(this);
var deleteS3UserBtn = tr.find(".btn-delete-s3-user");
deleteS3UserBtn.click(function(event) {
event.preventDefault();
deleteUser(storage.storage_name, tr);
});
var saveS3UserBtn = tr.find(".btn-save-s3-user");
saveS3UserBtn.click(function(event) {
event.preventDefault();
saveS3User(storage.storage_name, tr)
});
});
......@@ -190,6 +243,7 @@ function refreshCloudStorage()
});
}
/**
* Compile templates embedded into the HTML
*/
......@@ -207,14 +261,15 @@ function setupCloudStorage()
{
compileTemplates();
refreshCloudStorage();
// Bind to form
$("#add-cloud-frm").submit(function(event) {
event.preventDefault();
saveStorage($("#add-cloud-frm"))
.done(function(data, textStatus, jqXHR) {
$("#add-cloud-frm").trigger("reset");
refreshCloudStorage();
refreshDropboxCloudStorage();
refreshS3CloudStorage();
})
.fail(function(jqXHR) {
errorMessage(jqXHR);
......
......@@ -17,7 +17,6 @@
<dd>The name should have the form S3:hostname (i.e. S3:s3.example.com). App key and secret are not used.</dd>
<dt>Grant access to a set of VO and/or users</dt>
<dd>Empty user with a value in VO grant access to all members from that VO.
Access token = access key, access secret = secret key. Leave request fields empty.
</dd>
</dl>
......@@ -78,7 +77,7 @@
<tr class="user-entry">
<td>
<a><i class="glyphicon glyphicon-trash btn-delete-user"></i></a>
<a><i class="glyphicon glyphicon-floppy-disk btn-save-user"></i></a>
<a><i class="glyphicon glyphicon-floppy-disk btn-save-dropbox-user"></i></a>
</td>
<td>
<input type="hidden" name="user-dn" value="{{user_dn}}"/>
......@@ -103,10 +102,10 @@
</tr>
{{/each}}
</tbody>
<tbody class="frm-add-user">
<tbody class="frm-add-dropbox-user">
<tr>
<td>
<a><i class="glyphicon glyphicon-plus btn-add-user"></i></a>
<a><i class="glyphicon glyphicon-plus btn-add-dropbox-user"></i></a>
</td>
<td>
<input name="user-dn" type="text" class="form-control" value=""/>
......@@ -129,6 +128,62 @@
</tr>
</tbody>
</table>
<table class="table">
<thead>
<tr>
<th></th>
<th>User</th>
<th>VO</th>
<th>Access key</th>
<th>Secret key</th>
</tr>
</thead>
<tbody>
{{#each users}}
<tr class="user-entry">
<td>
<a><i class="glyphicon glyphicon-trash btn-delete-user"></i></a>
<a><i class="glyphicon glyphicon-floppy-disk btn-save-s3user"></i></a>
</td>
<td>
<input type="hidden" name="user-dn" value="{{user_dn}}"/>
{{user_dn}}
</td>
<td>
<input type="hidden" name="vo-name" value="{{vo_name}}"/>
{{vo_name}}
</td>
<td>
<input type="text" name="access-key" class="form-control" value="{{access_token}}"/>
</td>
<td>
<input type="text" name="secret-key" class="form-control" value="{{access_token_secret}}"/>
</td>
</tr>
{{/each}}
</tbody>
<tbody class="frm-add-s3-user">
<tr>
<td>
<a><i class="glyphicon glyphicon-plus btn-add-s3-user"></i></a>
</td>
<td>
<input name="user-dn" type="text" class="form-control" value=""/>
</td>
<td>
<input name="vo-name" type="text" class="form-control" value=""/>
</td>
<td>
<input name="access-key" type="text" class="form-control" value=""/>
</td>
<td>
<input name="secret-key" type="text" class="form-control" value=""/>
</td>
</tr>
</tbody>
</table>
<div class="panel-footer">
<button class="btn btn-success btn-save">Save</button>
<button class="btn btn-danger btn-delete">Delete</button>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment