Commit 5c9cb781 by kevalbhatt Committed by nixonrodrigues

ATLAS-3686 : UI : Allows user to add search weight in business-metadata for suggestion API.

parent 0d0a3899
...@@ -44,6 +44,24 @@ ...@@ -44,6 +44,24 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-group">
<label class="control-label col-sm-3 required" for="type">Search Weight</label>
<div class="col-sm-8">
<select class="form-control searchWeightSelector" data-id="searchWeightSelector">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option selected="selected">5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select>
</div>
</div>
<div class="form-group" data-id="multiValueSelect"> <div class="form-group" data-id="multiValueSelect">
<label class="control-label col-sm-3" for="multiValSelect">Enable Multivalues</label> <label class="control-label col-sm-3" for="multiValSelect">Enable Multivalues</label>
<div class="col-sm-8"> <div class="col-sm-8">
......
...@@ -103,14 +103,11 @@ define(['require', ...@@ -103,14 +103,11 @@ define(['require',
that.newAttr = isAttrEdit ? false : true; that.newAttr = isAttrEdit ? false : true;
_.each(attrributes, function(attrObj) { _.each(attrributes, function(attrObj) {
if (attrObj.name === attrName) { if (attrObj.name === attrName) {
attrDetails.attrTypeName = attrObj.typeName; attrDetails = $.extend(true, {}, attrObj);
if (attrObj.typeName.includes('array')) { if (attrObj.typeName.includes('array')) {
attrDetails.attrTypeName = attrObj.typeName.replace("array<", "").replace(">", ""); attrDetails.typeName = attrObj.typeName.replace("array<", "").replace(">", "");
attrDetails.multiValued = true; attrDetails.multiValued = true;
} }
attrDetails.attrEntityType = attrObj.options && attrObj.options.applicableEntityTypes ? JSON.parse(attrObj.options.applicableEntityTypes) : null;
attrDetails.maxStrLength = attrObj.options && attrObj.options.maxStrLength ? attrObj.options.maxStrLength : null;
attrDetails.enumValues = attrObj.enumValues ? attrObj.enumValues : null;
} }
}); });
this.showDetails = false; this.showDetails = false;
...@@ -121,10 +118,12 @@ define(['require', ...@@ -121,10 +118,12 @@ define(['require',
enumDefCollection.fetch({ reset: true }); enumDefCollection.fetch({ reset: true });
that.businessMetadataAttr.reset(that.model.get("attributeDefs")); that.businessMetadataAttr.reset(that.model.get("attributeDefs"));
}, },
onUpdateBusinessMetadata: function() { onUpdateBusinessMetadata: function(fetch) {
that.showDetails = true; that.showDetails = true;
that.toggleBusinessMetadataDetailsAttrView(); that.toggleBusinessMetadataDetailsAttrView();
that.entityDefCollection.fetch({ silent: true }); if (fetch) {
that.entityDefCollection.fetch({ silent: true });
}
}, },
parent: that.$el, parent: that.$el,
businessMetadataDefCollection: that.businessMetadataDefCollection, businessMetadataDefCollection: that.businessMetadataDefCollection,
......
...@@ -40,6 +40,7 @@ define(['require', ...@@ -40,6 +40,7 @@ define(['require',
attributeInput: "[data-id='attributeInput']", attributeInput: "[data-id='attributeInput']",
close: "[data-id='close']", close: "[data-id='close']",
dataTypeSelector: "[data-id='dataTypeSelector']", dataTypeSelector: "[data-id='dataTypeSelector']",
searchWeightSelector: "[data-id='searchWeightSelector']",
entityTypeSelector: "[data-id='entityTypeSelector']", entityTypeSelector: "[data-id='entityTypeSelector']",
enumTypeSelectorContainer: "[data-id='enumTypeSelectorContainer']", enumTypeSelectorContainer: "[data-id='enumTypeSelectorContainer']",
enumTypeSelector: "[data-id='enumTypeSelector']", enumTypeSelector: "[data-id='enumTypeSelector']",
...@@ -57,6 +58,9 @@ define(['require', ...@@ -57,6 +58,9 @@ define(['require',
events["keyup " + this.ui.attributeInput] = function(e) { events["keyup " + this.ui.attributeInput] = function(e) {
this.model.set({ "name": e.target.value.trim() }); this.model.set({ "name": e.target.value.trim() });
}; };
events["change " + this.ui.searchWeightSelector] = function(e) {
this.model.set({ "searchWeight": e.target.value.trim() });
};
events["change " + this.ui.dataTypeSelector] = function(e) { events["change " + this.ui.dataTypeSelector] = function(e) {
var obj = { options: this.model.get('options') || {} }; var obj = { options: this.model.get('options') || {} };
delete obj.enumValues; delete obj.enumValues;
...@@ -142,13 +146,16 @@ define(['require', ...@@ -142,13 +146,16 @@ define(['require',
* @constructs * @constructs
*/ */
initialize: function(options) { initialize: function(options) {
_.extend(this, _.pick(options, "typeHeaders", "businessMetadataDefCollection", "enumDefCollection", "isAttrEdit", "attrDetails", "viewId", "collection")); _.extend(this, _.pick(options, "typeHeaders", "businessMetadataDefCollection", "enumDefCollection", "isAttrEdit", "viewId", "collection"));
this.viewId = options.model ? options.model.cid : this.viewId; this.viewId = options.model ? options.model.cid : this.viewId;
}, },
onRender: function() { onRender: function() {
var that = this, var that = this,
entitytypes = '', entitytypes = '',
enumTypes = []; enumTypes = [],
searchWeightValue = '5',
stringLengthValue = '50',
applicableEntityType = '';
this.typeHeaders.fullCollection.each(function(model) { this.typeHeaders.fullCollection.each(function(model) {
if (model.toJSON().category == "ENTITY") { if (model.toJSON().category == "ENTITY") {
that.ui.entityTypeSelector.append("<option>" + model.get('name') + "</option>"); that.ui.entityTypeSelector.append("<option>" + model.get('name') + "</option>");
...@@ -162,51 +169,57 @@ define(['require', ...@@ -162,51 +169,57 @@ define(['require',
selectionAdapter: $.fn.select2.amd.require("TagHideDeleteButtonAdapter") selectionAdapter: $.fn.select2.amd.require("TagHideDeleteButtonAdapter")
}); });
this.ui.entityTypeSelector.html(entitytypes); this.ui.entityTypeSelector.html(entitytypes);
this.ui.entityTypeSelector.on('select2:open', function(e) { // to make selected option disable in dropdown added remove-from-list class this.ui.entityTypeSelector.on('select2:open', function(e) { // to make selected option disable in dropdown added remove-from-list class
$('.select2-dropdown--below').addClass('remove-from-list'); $('.select2-dropdown--below').addClass('remove-from-list');
}); });
this.ui.stringLengthValue.val('50').trigger('change'); //default length for string is 50 if (this.model.get("searchWeight") && this.model.get("searchWeight") != -1) {
searchWeightValue = this.model.get("searchWeight");
}
if (this.model.get("options")) {
stringLengthValue = this.model.get("options").maxStrLength || '50';
applicableEntityType = this.model.get("options").applicableEntityTypes ? JSON.parse(this.model.get("options").applicableEntityTypes) : null;
}
this.ui.stringLengthValue.val(stringLengthValue).trigger('change'); //default length for string is 50
this.ui.searchWeightSelector.val(searchWeightValue).trigger('change');
this.ui.enumValueSelector.attr("disabled", "false"); // cannot edit the values this.ui.enumValueSelector.attr("disabled", "false"); // cannot edit the values
this.emumTypeSelectDisplay(); this.emumTypeSelectDisplay();
this.ui.enumTypeSelectorContainer.hide(); this.ui.enumTypeSelectorContainer.hide();
this.ui.enumTypeSelector.hide(); this.ui.enumTypeSelector.hide();
this.ui.enumValueSelectorContainer.hide(); this.ui.enumValueSelectorContainer.hide();
if (this.isAttrEdit) { if (this.isAttrEdit) {
var typeName = this.model.get("typeName");
this.ui.close.hide(); this.ui.close.hide();
this.ui.createNewEnum.hide(); // cannot add new businessMetadata on edit view this.ui.createNewEnum.hide(); // cannot add new businessMetadata on edit view
this.ui.attributeInput.val(this.attrDetails.name); this.ui.attributeInput.val(this.model.get("name"));
this.ui.attributeInput.attr("disabled", "false"); this.ui.attributeInput.attr("disabled", "false");
this.ui.dataTypeSelector.attr("disabled", "false"); this.ui.dataTypeSelector.attr("disabled", "false");
this.ui.dataTypeSelector.attr("disabled", "false"); this.ui.dataTypeSelector.attr("disabled", "false");
this.ui.multiValueSelect.hide(); this.ui.multiValueSelect.hide();
this.ui.dataTypeSelector.val(this.attrDetails.attrTypeName); this.ui.dataTypeSelector.val(typeName);
if (this.attrDetails.attrTypeName == "string") { if (typeName == "string") {
this.ui.stringLengthContainer.show(); this.ui.stringLengthContainer.show();
this.ui.stringLengthValue.show(); this.ui.stringLengthValue.show();
this.ui.stringLengthValue.val(this.attrDetails.maxStrLength);
} else { } else {
this.ui.stringLengthContainer.hide(); this.ui.stringLengthContainer.hide();
this.ui.stringLengthValue.hide(); this.ui.stringLengthValue.hide();
} }
_.each(this.attrDetails.attrEntityType, function(valName) { if (applicableEntityType) {
that.ui.entityTypeSelector.find('option').each(function(o) { _.each(applicableEntityType, function(valName) {
var $el = $(this) that.ui.entityTypeSelector.find('option').each(function(o) {
if ($el.data("name") === valName) { var $el = $(this)
$el.attr("data-allowremove", "false"); if ($el.data("name") === valName) {
} $el.attr("data-allowremove", "false");
}) }
}); })
this.ui.entityTypeSelector.val(this.attrDetails.attrEntityType).trigger('change'); });
if (this.attrDetails && this.attrDetails.attrTypeName) { }
var typeName = this.attrDetails.attrTypeName; this.ui.entityTypeSelector.val(applicableEntityType).trigger('change');
if (typeName != "string" && typeName != "boolean" && typeName != "byte" && typeName != "short" && typeName != "int" && typeName != "float" && typeName != "double" && typeName != "long" && typeName != "date") { if (typeName != "string" && typeName != "boolean" && typeName != "byte" && typeName != "short" && typeName != "int" && typeName != "float" && typeName != "double" && typeName != "long" && typeName != "date") {
this.ui.enumTypeSelector.attr("disabled", "false"); this.ui.enumTypeSelector.attr("disabled", "false");
this.ui.dataTypeSelector.val("enumeration").trigger('change'); this.ui.dataTypeSelector.val("enumeration").trigger('change');
this.ui.enumTypeSelector.val(typeName).trigger('change'); this.ui.enumTypeSelector.val(typeName).trigger('change');
}
} }
if (this.attrDetails && this.attrDetails.multiValued) { if (this.model.get("multiValued")) {
this.ui.multiValueSelect.show(); this.ui.multiValueSelect.show();
$(this.ui.multiValueSelectStatus).prop('checked', true).trigger('change'); $(this.ui.multiValueSelectStatus).prop('checked', true).trigger('change');
this.ui.multiValueSelectStatus.attr("disabled", "false"); this.ui.multiValueSelectStatus.attr("disabled", "false");
......
...@@ -146,14 +146,11 @@ define(['require', ...@@ -146,14 +146,11 @@ define(['require',
that.guid = guid; that.guid = guid;
_.each(attrributes, function(attrObj) { _.each(attrributes, function(attrObj) {
if (attrObj.name === attrName) { if (attrObj.name === attrName) {
attrDetails.attrTypeName = attrObj.typeName; attrDetails = $.extend(true, {}, attrObj);
if (attrObj.typeName.includes('array')) { if (attrObj.typeName.includes('array')) {
attrDetails.attrTypeName = attrObj.typeName.replace("array<", "").replace(">", ""); attrDetails.typeName = attrObj.typeName.replace("array<", "").replace(">", "");
attrDetails.multiValued = true; attrDetails.multiValued = true;
} }
attrDetails.attrEntityType = attrObj.options && attrObj.options.applicableEntityTypes ? JSON.parse(attrObj.options.applicableEntityTypes) : null;
attrDetails.maxStrLength = attrObj.options && attrObj.options.maxStrLength ? attrObj.options.maxStrLength : null;
attrDetails.enumValues = attrObj.enumValues ? attrObj.enumValues : null;
} }
}); });
...@@ -165,13 +162,14 @@ define(['require', ...@@ -165,13 +162,14 @@ define(['require',
onEditCallback: function() { onEditCallback: function() {
that.businessMetadataDefCollection.fullCollection.sort({ silent: true }); that.businessMetadataDefCollection.fullCollection.sort({ silent: true });
that.renderTableLayoutView(); that.renderTableLayoutView();
}, },
onUpdateBusinessMetadata: function() { onUpdateBusinessMetadata: function(fetch) {
enumDefCollection.fetch({ reset: true });
that.showDetails = true; that.showDetails = true;
that.toggleBusinessMetadataDetailsAttrView(); that.toggleBusinessMetadataDetailsAttrView();
that.entityDefCollection.fetch({ silent: true }); if (fetch) {
enumDefCollection.fetch({ reset: true });
that.entityDefCollection.fetch({ silent: true });
}
}, },
parent: that.$el, parent: that.$el,
businessMetadataDefCollection: that.businessMetadataDefCollection, businessMetadataDefCollection: that.businessMetadataDefCollection,
...@@ -203,11 +201,13 @@ define(['require', ...@@ -203,11 +201,13 @@ define(['require',
that.toggleBusinessMetadataDetailsAttrView(); that.toggleBusinessMetadataDetailsAttrView();
require(["views/business_metadata/CreateBusinessMetadataLayoutView"], function(CreateBusinessMetadataLayoutView) { require(["views/business_metadata/CreateBusinessMetadataLayoutView"], function(CreateBusinessMetadataLayoutView) {
that.view = new CreateBusinessMetadataLayoutView({ that.view = new CreateBusinessMetadataLayoutView({
onUpdateBusinessMetadata: function() { onUpdateBusinessMetadata: function(fetch) {
enumDefCollection.fetch({ reset: true });
that.showDetails = true; that.showDetails = true;
that.toggleBusinessMetadataDetailsAttrView(); that.toggleBusinessMetadataDetailsAttrView();
that.entityDefCollection.fetch({ silent: true }); if (fetch) {
enumDefCollection.fetch({ reset: true });
that.entityDefCollection.fetch({ silent: true });
}
}, },
businessMetadataDefCollection: that.businessMetadataDefCollection, businessMetadataDefCollection: that.businessMetadataDefCollection,
enumDefCollection: enumDefCollection, enumDefCollection: enumDefCollection,
......
...@@ -54,7 +54,6 @@ define(['require', ...@@ -54,7 +54,6 @@ define(['require',
businessMetadataDefCollection: this.businessMetadataDefCollection, businessMetadataDefCollection: this.businessMetadataDefCollection,
enumDefCollection: this.enumDefCollection, enumDefCollection: this.enumDefCollection,
isAttrEdit: this.isAttrEdit, isAttrEdit: this.isAttrEdit,
attrDetails: this.attrDetails,
viewId: this.cid, viewId: this.cid,
collection: this.collection collection: this.collection
}; };
...@@ -104,16 +103,9 @@ define(['require', ...@@ -104,16 +103,9 @@ define(['require',
this.create = true; this.create = true;
} }
if (!this.isNewBusinessMetadata) { if (!this.isNewBusinessMetadata) {
this.collection = this.isAttrEdit ? new Backbone.Collection([{ this.collection = this.isAttrEdit ? new Backbone.Collection([
"name": this.attrDetails.name, this.attrDetails
"typeName": this.attrDetails.attrTypeName, ]) : new Backbone.Collection([{
"isOptional": true,
"cardinality": "SINGLE",
"valuesMinCount": 0,
"valuesMaxCount": 1,
"isUnique": false,
"isIndexable": false
}]) : new Backbone.Collection([{
"name": "", "name": "",
"typeName": "string", "typeName": "string",
"isOptional": true, "isOptional": true,
...@@ -263,7 +255,7 @@ define(['require', ...@@ -263,7 +255,7 @@ define(['require',
content: "Business Metadata " + name + Messages.getAbbreviationMsg(false, 'addSuccessMessage') content: "Business Metadata " + name + Messages.getAbbreviationMsg(false, 'addSuccessMessage')
}); });
} }
that.options.onUpdateBusinessMetadata(); that.options.onUpdateBusinessMetadata(true);
}, },
silent: true, silent: true,
reset: true, reset: true,
...@@ -306,7 +298,7 @@ define(['require', ...@@ -306,7 +298,7 @@ define(['require',
that.selectedBusinessMetadata.set(model.businessMetadataDefs[0]); that.selectedBusinessMetadata.set(model.businessMetadataDefs[0]);
} }
that.options.onEditCallback(); that.options.onEditCallback();
that.options.onUpdateBusinessMetadata(); that.options.onUpdateBusinessMetadata(true);
}, },
silent: true, silent: true,
reset: true, reset: true,
......
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