Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few metadata-mgmt app fixes #80

Merged
merged 8 commits into from
Apr 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 70 additions & 23 deletions common/src/main/webapp/js/lightblue-apps.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
function showErrorMessage(message) {
"use strict";
// TODO: show it on page
alert("Error: " + message);

$('#alert-box').append(createBoostrapAlertDiv('alert-danger', "<strong>Error!</strong> "+message));
}

function showLightblueErrorMessage(jsonMessage) {
"use strict";
// TODO: show it on page
alert("Lightblue error: "+ jsonMessage.errorCode);
console.error(JSON.stringify(jsonMessage));
showErrorMessage(jsonMessage.errorCode);
}

function showSuccessMessage(message) {
"use strict";
// TODO: show it on page
alert(message);

var div = createBoostrapAlertDiv('alert-success', "<strong>Success!</strong> "+message);

$('#alert-box').append(div);

// remove success message after 3s
setTimeout(function() {
div.slideUp('slow', function() { $(this).remove(); });
}, 3000);
}

function createBoostrapAlertDiv(clazz, htmlMessage) {
"use strict";

return $(document.createElement('div'))
.addClass('alert')
.addClass(clazz)
.html("<a href='#' class='close' data-dismiss='alert'>&times;</a>"+htmlMessage);
}

function isAdmin() {
Expand Down Expand Up @@ -238,8 +254,9 @@ function callLightblue(uri, jsonData, method) {
showLightblueErrorMessage(msg);
}
else {
showSuccessMessage( "Data Saved: " + JSON.stringify(msg) );
// TODO: update entity list
console.debug("Data Saved: "+JSON.stringify(msg));
showSuccessMessage("Data Saved");
loadEntities();
}
});

Expand Down Expand Up @@ -272,6 +289,49 @@ function loadVersions() {
});
}

function loadEntities() {
"use strict";

var entitySelect = $("#entities");
$.getJSON( metadataServicePath, function( json ) {
var entities = json.entities;
entitySelect.empty();
entitySelect.append("<option value='' disabled selected>Entity:</option>");
$.each( entities, function(index, entity) {
entitySelect.append("<option value='" + entity + "'>" + entity + "</option>");
});
loadEntityVersions(null);
}).fail(function( jqxhr, textStatus, error ) {
showErrorMessage(textStatus + " "+error);
});
}

function loadEntityVersions(entity) {
"use strict";

var versionSelect = $("#versions");
versionSelect.empty();
versionSelect.append("<option value='' disabled selected>Version:</option>");

if (entity == null || entity == "") {
// just clear the selection dropdown
return;
}

$.getJSON( metadataServicePath + entity, function( json ) {
var versions = json;
versions.sort(function(v1, v2) {
return v1.version.localeCompare(v2.version);
});
$.each( versions, function( index, version ) {
if(version.status == "active")
versionSelect.append("<option value='" + version.version + "'>" + version.version + "</option>");
});
}).fail(function( jqxhr, textStatus, error ) {
showErrorMessage(textStatus + " "+error);
});
}

$(document).ready(function() {
"use strict";

Expand All @@ -288,23 +348,10 @@ $(document).ready(function() {
var jsonTextArea = $("#json");
var jsonTreeEditor = $("#editor");

$.getJSON( metadataServicePath, function( json ) {
$.each( json, function( key, val ) {
$.each( val, function( arrayVal ) {
entitySelect.append("<option value='" + val[arrayVal] + "'>" + val[arrayVal] + "</option>");
});
});
});
loadEntities();

entitySelect.change(function() {
versionSelect.empty();
versionSelect.append("<option value='' disabled selected>Version:</option>");
$.getJSON( metadataServicePath + entitySelect.val(), function( json ) {
$.each( json, function( versions, version ) {
if(version.status == "active")
versionSelect.append("<option value='" + version.version + "'>" + version.version + "</option>");
});
});
loadEntityVersions($(this).val());
});

submitButton.click(function() {
Expand Down
5 changes: 4 additions & 1 deletion metadata-mgmt/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<div id="view-jsonEditor" class="view-div">

<div id="alert-box"></div>

<div id="view-jsonEditor" class="view-div">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
Expand Down