webui: entity facets in facet registry

All entity facets are automatically registered as a new type in
reg.facet.

The type name is: <entity_name>_<facet_name>

The name of facets is kept same, mainly to support the same url routes.

This change allows to get facet instance by calling, e.g.:
  reg.facet.get('user_details')

It allows to make declarative links to facet which are not yet instantiated.

Reviewed-By: David Kupka <dkupka@redhat.com>
Reviewed-By: Thierry Bordaz <tbordaz@redhat.com>
This commit is contained in:
Petr Vobornik 2015-04-24 16:04:45 +02:00
parent de374a0d3a
commit ae62bd6914
5 changed files with 56 additions and 15 deletions

View File

@ -823,9 +823,8 @@ exp.association_facet_pre_op = function(spec, context) {
return has_indirect;
};
var entity = context.entity;
su.context_entity(spec, context);
spec.entity = entity;
var entity = reg.entity.get(spec.entity);
var index = spec.name.lastIndexOf('_');
spec.attribute_member = spec.attribute_member ||
@ -1298,8 +1297,8 @@ exp.association_facet = IPA.association_facet = function (spec, no_init) {
*/
exp.attribute_facet_pre_op = function(spec, context) {
var entity = context.entity;
su.context_entity(spec, context);
var entity = reg.entity.get(spec.entity);
spec.title = spec.title || entity.metadata.label_singular;
spec.label = spec.label || entity.metadata.label_singular;

View File

@ -461,8 +461,8 @@ exp.facet_policies = IPA.facet_policies = function(spec) {
*/
exp.details_facet_pre_op = function(spec, context) {
var entity = context.entity;
su.context_entity(spec, context);
var entity = reg.entity.get(spec.entity);
spec.name = spec.name || 'details';
spec.title = spec.title || entity.metadata.label_singular;
@ -2019,7 +2019,8 @@ exp.register = function() {
factory: IPA.details_facet,
pre_ops: [
exp.details_facet_pre_op
]
],
spec: { name: 'details' }
});
};

View File

@ -299,6 +299,14 @@ exp.entity = IPA.entity = function(spec) {
}
};
that.create_facet_type = function(facet_name) {
// Keep names unique among all facets.
// Facets added later should also follow this pattern but it's not
// enforced.
return that.name + '_' + facet_name;
};
/**
* Get facet with given name.
*
@ -315,13 +323,15 @@ exp.entity = IPA.entity = function(spec) {
*/
that.get_facet = function(name) {
var i, facets;
var i, l, facets;
//build all facets on the first time
if(!that.facets_created) {
facets = builder.build('facet', that.facet_specs, { entity: that });
for (i=0; i<facets.length; i++) {
var facet = facets[i];
var facet_specs = that.facet_specs;
for (i=0,l=facet_specs.length; i<l; i++) {
var type_name = that.create_facet_type(facet_specs[i].name);
var facet = reg.facet.get(type_name);
that.add_facet(facet);
if (facet.name === 'search') {
that.add_redirect_info(facet.name);
@ -361,7 +371,6 @@ exp.entity = IPA.entity = function(spec) {
* @param {string} facet.facet_group - facet group to add the facet
*/
that.add_facet = function(facet) {
facet.entity = that;
that.facets.put(facet.name, facet);
@ -788,6 +797,27 @@ exp.entity_post_ops = {
entity.builder.deleter_dialog(spec.deleter_dialog);
}
return entity;
},
facets: function(entity, spec, context) {
var facet_specs = entity.facet_specs;
for (var i=0,l=facet_specs.length; i<l; i++) {
var f_spec = facet_specs[i];
if (!f_spec.entity) {
f_spec.entity = entity;
}
reg.facet.register_from_spec(function(spec) {
// replace the original spec with the merged one so there is
// only one
facet_specs[i] = spec;
return entity.create_facet_type(spec.name);
}, f_spec);
}
return entity;
}
};
@ -1066,7 +1096,8 @@ registry.builder.post_ops.push(
exp.entity_post_ops.containing_entity,
exp.entity_post_ops.standard_association_facets,
exp.entity_post_ops.adder_dialog,
exp.entity_post_ops.deleter_dialog);
exp.entity_post_ops.deleter_dialog,
exp.entity_post_ops.facets);
return exp;
});

View File

@ -321,6 +321,14 @@ exp.facet = IPA.facet = function(spec, no_init) {
*/
that.state = new FacetState();
that.get_full_name = function() {
if (that.entity) {
return that.entity.create_facet_type(that.name);
}
return that.name;
};
/**
* Set and normalize pkeys. Merges with existing if present. If keys length
* differs, the alignment is from the last one to the first one.

View File

@ -74,8 +74,8 @@ exp.search_facet_control_buttons_pre_op = function(spec, context) {
exp.search_facet_pre_op = function(spec, context) {
var entity = context.entity;
su.context_entity(spec, context);
var entity = reg.entity.get(spec.entity);
spec.name = spec.name || 'search';
spec.title = spec.title || entity.metadata.label;
@ -397,8 +397,8 @@ IPA.search_deleter_dialog = function(spec) {
exp.nested_search_facet_preop = function(spec, context) {
var entity = context.entity;
su.context_entity(spec, context);
var entity = reg.entity.get(spec.entity);
spec.name = spec.name || 'search';
spec.title = spec.title || entity.metadata.label_singular;
@ -597,7 +597,8 @@ exp.register = function() {
factory: IPA.search_facet,
pre_ops: [
exp.search_facet_pre_op
]
],
spec: { name: 'search' }
});
f.register({
@ -605,7 +606,8 @@ exp.register = function() {
factory: IPA.nested_search_facet,
pre_ops: [
exp.nested_search_facet_preop
]
],
spec: { name: 'nestedsearch' }
});
};