Commit f5deb24b authored by Kostas Papadimitriou's avatar Kostas Papadimitriou Committed by Georgios D. Tsoukalas
Browse files

Translate image owner uuid -> display name in UI

UI uses the introduced /user_catalog api to translate uuids to display
names when necessary.
parent 755d3886
......@@ -20,7 +20,7 @@ body {
background: url("../images/body-bg.png") repeat-x #FFFFFF;
text-align:center;
font-size: 16px;
background-position: 0px 35px;
background-position: 0px 34px;
overflow-y: scroll;
}
......
......@@ -122,7 +122,7 @@
get_personal_images: function() {
return _.filter(this.active(), function(i) {
return i.get_owner() == snf.user.username
return i.get_owner_uuid() == snf.user.username;
});
},
......@@ -134,7 +134,7 @@
return _.filter(this.active(), function(i){
return !_.include(_.keys(snf.config.system_images_owners),
i.get_owner()) &&
i.get_owner() != snf.user.username &&
i.get_owner_uuid() != snf.user.username &&
!i.is_public();
});
}
......
......@@ -229,7 +229,7 @@
// Image model
models.Image = models.Model.extend({
path: 'images',
get_size: function() {
return parseInt(this.get('metadata') ? this.get('metadata').values.size : -1)
},
......@@ -261,6 +261,10 @@
return this.get('owner') || _.keys(synnefo.config.system_images_owners)[0];
},
get_owner_uuid: function() {
return this.get('owner_uuid');
},
is_system_image: function() {
var owner = this.get_owner();
return _.include(_.keys(synnefo.config.system_images_owners), owner)
......@@ -268,7 +272,7 @@
owned_by: function(user) {
if (!user) { user = synnefo.user }
return user.username == this.get_owner();
return user.username == this.get('owner_uuid');
},
display_owner: function() {
......@@ -1740,8 +1744,48 @@
},
parse: function (resp, xhr) {
var data = _.map(resp.images.values, _.bind(this.parse_meta, this));
return resp.images.values;
var parsed = _.map(resp.images.values, _.bind(this.parse_meta, this));
parsed = this.fill_owners(parsed);
return parsed;
},
fill_owners: function(images) {
// do translate uuid->displayname if needed
// store display name in owner attribute for compatibility
var uuids = [];
var images = _.map(images, function(img, index) {
if (synnefo.config.translate_uuids) {
uuids.push(img['owner']);
}
img['owner_uuid'] = img['owner'];
return img;
});
if (uuids.length > 0) {
var handle_results = function(data) {
_.each(images, function (img) {
img['owner'] = data.uuid_catalog[img['owner_uuid']];
});
}
// notice the async false
var uuid_map = this.translate_uuids(uuids, false,
handle_results)
}
return images;
},
translate_uuids: function(uuids, async, cb) {
var url = synnefo.config.user_catalog_url;
var data = JSON.stringify({'uuids': uuids});
// post to user_catalogs api
snf.api.sync('create', undefined, {
url: url,
data: data,
async: async,
success: cb
});
},
get_meta_key: function(img, key) {
......
......@@ -635,6 +635,9 @@
synnefo.config.login_redirect = '{{ login_redirect }}';
synnefo.config.auth_cookie_name = '{{ auth_cookie_name }}';
synnefo.config.translate_uuids = {{ translate_uuids|safe }};
synnefo.config.user_catalog_url = {{ user_catalog_url|safe }};
synnefo.config.network_suggested_subnets = {{ network_suggested_subnets|safe }};
synnefo.config.network_available_types = {{ network_available_types|safe }};
synnefo.config.network_allow_duplicate_vm_nics = {{ network_allow_duplicate_vm_nics }};
......
......@@ -150,6 +150,9 @@ AUTOMATIC_NETWORK_RANGE_FORMAT = getattr(settings,
GROUP_PUBLIC_NETWORKS = getattr(settings, 'UI_GROUP_PUBLIC_NETWORKS', True)
GROUPED_PUBLIC_NETWORK_NAME = getattr(settings, 'UI_GROUPED_PUBLIC_NETWORK_NAME', 'Internet')
USER_CATALOG_URL = getattr(settings, 'UI_USER_CATALOG_URL', '/user_catalogs')
TRANSLATE_UUIDS = not getattr(settings, 'TRANSLATE_UUIDS', False)
def template(name, request, context):
template_path = os.path.join(os.path.dirname(__file__), "templates/")
current_template = template_path + name + '.html'
......@@ -173,6 +176,8 @@ def home(request):
'request': request,
'current_lang': get_language() or 'en',
'compute_api_url': json.dumps(COMPUTE_API_URL),
'user_catalog_url': json.dumps(USER_CATALOG_URL),
'translate_uuids': json.dumps(TRANSLATE_UUIDS),
# update interval settings
'update_interval': UPDATE_INTERVAL,
'update_interval_increase': UPDATE_INTERVAL_INCREASE,
......
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