Skip to content

Commit

Permalink
Adapt Webclient to new assoc def format.
Browse files Browse the repository at this point in the history
See #1063.
See #906.
  • Loading branch information
jri committed Feb 1, 2017
1 parent e6fb068 commit a9b4547
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 42 deletions.
Expand Up @@ -371,7 +371,7 @@ final void _addAssocDef(AssociationModel assoc) {
}

/**
* Adjusts the type cache on post-update-assoc time.
* Adjusts the type cache on post-update-assoc.
* Called from ApplicationModel's core internal postUpdate() hook, in 2 situations:
* - An assoc def has been updated.
* - An assoc def's underlying assoc has been updated.
Expand Down
2 changes: 1 addition & 1 deletion modules/dm4-help/src/main/resources/web/script/plugin.js
Expand Up @@ -15,7 +15,7 @@ dm4c.add_plugin("de.deepamehta.help", function() {
'<div class="field-label">Version</div>' +
'<div>${project.version}</div>' +
'<div class="field-label">Release Date</div>' +
'<div>Jan 29, 2017</div>' +
'<div>Feb 1, 2017</div>' +
'<div class="field-label">Copyright</div>' +
'<div>2000-2017 Jörg Richter et al.</div>' +
'<div class="field-label">License</div>' +
Expand Down
Expand Up @@ -34,31 +34,27 @@ function TypeRenderer() {
editors_list = $("<ul>").attr("id", "assoc-def-editors")
dm4c.render.page(editors_list)
for (var i = 0, assoc_def; assoc_def = type.assoc_defs[i]; i++) {
var label_state = type.get_label_config(assoc_def.assoc_def_uri)
editors_list.append(new AssociationDefEditor(assoc_def, label_state).dom)
editors_list.append(new AssociationDefEditor(assoc_def).dom)
}
editors_list.sortable()
}

/**
* @param label_state a boolean
*/
function AssociationDefEditor(assoc_def, label_state) {
function AssociationDefEditor(assoc_def) {
var parent_type_label = $("<span>").addClass("label").text(type.value)
var child_type_label = $("<span>").addClass("label").addClass("child-type-label")
.text(dm4c.topic_type_name(assoc_def.child_type_uri))
var parent_card_menu = dm4c.render.topic_menu("dm4.core.cardinality", assoc_def.parent_cardinality_uri)
var child_card_menu = dm4c.render.topic_menu("dm4.core.cardinality", assoc_def.child_cardinality_uri)
var assoc_type_menu = create_assoc_type_menu()
var custom_assoc_type_menu = create_custom_assoc_type_menu()
var label_config_checkbox = dm4c.render.checkbox(label_state)
var include_in_label_checkbox = dm4c.render.checkbox(assoc_def.include_in_label)
//
var optional_card_div = $("<div>").append(parent_type_label).append(parent_card_menu.dom)
optional_card_div.toggle(is_aggregation_selected())
//
this.dom = $("<li>").addClass("assoc-def-editor").addClass("ui-state-default")
.append($("<div>").append(child_type_label).append(child_card_menu.dom)
.append(label_config_checkbox).append(small_label("Include in Label")))
.append(include_in_label_checkbox).append(small_label("Include in Label")))
.append(optional_card_div)
.append($("<div>").append(small_label("Association Type")).append(assoc_type_menu.dom))
.append($("<div>").append(small_label("Custom Association Type")).append(custom_assoc_type_menu.dom))
Expand Down Expand Up @@ -94,15 +90,13 @@ function TypeRenderer() {

function build_assoc_def_model() {
return {
assoc_def: {
id: assoc_def.id,
child_type_uri: assoc_def.child_type_uri,
child_cardinality_uri: child_card_menu.get_selection().value,
parent_cardinality_uri: parent_card_menu.get_selection().value,
assoc_type_uri: assoc_type_menu.get_selection().value,
custom_assoc_type_uri: custom_assoc_type_uri()
},
label_state: label_config_checkbox.get(0).checked
id: assoc_def.id,
child_type_uri: assoc_def.child_type_uri,
child_cardinality_uri: child_card_menu.get_selection().value,
parent_cardinality_uri: parent_card_menu.get_selection().value,
assoc_type_uri: assoc_type_menu.get_selection().value,
custom_assoc_type_uri: custom_assoc_type_uri(),
include_in_label: include_in_label_checkbox.get(0).checked
}

// compare to form_element_function() in webclient's render_helper.js
Expand Down Expand Up @@ -145,30 +139,18 @@ function TypeRenderer() {
}
//
if (type.data_type_uri == "dm4.core.composite") {
var model = composite_model()
type_model.assoc_defs = model.assoc_defs
type_model.label_config = model.label_config
type_model.assoc_defs = assoc_defs()
}
//
return type_model

function composite_model() {
function assoc_defs() {
var assoc_defs = []
var label_config = []
editors_list.children().each(function() {
var editor_model = $(this).data("model_func")()
var assoc_def = editor_model.assoc_def
var assoc_def = $(this).data("model_func")()
assoc_defs.push(assoc_def)
if (editor_model.label_state) {
var type_uri = assoc_def.custom_assoc_type_uri
var qualifier = type_uri && !js.begins_with(type_uri, dm4c.DEL_URI_PREFIX) ? "#" + type_uri : ""
label_config.push(assoc_def.child_type_uri + qualifier)
}
})
return {
assoc_defs: assoc_defs,
label_config: label_config
}
return assoc_defs
}
}
}
Expand Down
Expand Up @@ -10,24 +10,29 @@ function Type(type) {
this.data_type_uri = type.data_type_uri
this.index_mode_uris = type.index_mode_uris
this.assoc_defs = deserialize(type.assoc_defs)
this.label_config = type.label_config
this.view_config_topics = dm4c.hash_by_type(dm4c.build_topics(type.view_config_topics))
}

function deserialize(assoc_defs) {
for (var i = 0, assoc_def; assoc_def = assoc_defs[i]; i++) {
//
// 1) hash view config topics
assoc_def.view_config_topics = dm4c.hash_by_type(dm4c.build_topics(assoc_def.view_config_topics))
//
// 2) add convenience properties
// Note: "parent_cardinality_uri" and "child_cardinality_uri" are available directly
// Note: an intermediate Association is instantiated in order to use its get_role() method
// ### TODO: instantiate proper AssociationDefinition objects?
var assoc = new Association(assoc_def)
assoc_def.parent_type_uri = assoc.get_role("dm4.core.parent_type").topic_uri
assoc_def.child_type_uri = assoc.get_role("dm4.core.child_type").topic_uri
//
var custom_assoc_type = assoc_def.childs["dm4.core.assoc_type#dm4.core.custom_assoc_type"]
assoc_def.custom_assoc_type_uri = custom_assoc_type && custom_assoc_type.uri
assoc_def.assoc_def_uri = assoc_def.child_type_uri +
(assoc_def.custom_assoc_type_uri ? "#" + assoc_def.custom_assoc_type_uri : "")
//
assoc_def.include_in_label = assoc_def.childs["dm4.core.include_in_label"].value
}
return assoc_defs
}
Expand Down Expand Up @@ -71,9 +76,3 @@ Type.prototype.is_hidden = function() {
Type.prototype.is_locked = function() {
return dm4c.get_view_config(this, "locked")
}

// ---

Type.prototype.get_label_config = function(assoc_def_uri) {
return js.contains(this.label_config, assoc_def_uri)
}

0 comments on commit a9b4547

Please sign in to comment.