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 @@
</select>
</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">
<label class="control-label col-sm-3" for="multiValSelect">Enable Multivalues</label>
<div class="col-sm-8">
......
......@@ -103,14 +103,11 @@ define(['require',
that.newAttr = isAttrEdit ? false : true;
_.each(attrributes, function(attrObj) {
if (attrObj.name === attrName) {
attrDetails.attrTypeName = attrObj.typeName;
attrDetails = $.extend(true, {}, attrObj);
if (attrObj.typeName.includes('array')) {
attrDetails.attrTypeName = attrObj.typeName.replace("array<", "").replace(">", "");
attrDetails.typeName = attrObj.typeName.replace("array<", "").replace(">", "");
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;
......@@ -121,10 +118,12 @@ define(['require',
enumDefCollection.fetch({ reset: true });
that.businessMetadataAttr.reset(that.model.get("attributeDefs"));
},
onUpdateBusinessMetadata: function() {
onUpdateBusinessMetadata: function(fetch) {
that.showDetails = true;
that.toggleBusinessMetadataDetailsAttrView();
if (fetch) {
that.entityDefCollection.fetch({ silent: true });
}
},
parent: that.$el,
businessMetadataDefCollection: that.businessMetadataDefCollection,
......
......@@ -40,6 +40,7 @@ define(['require',
attributeInput: "[data-id='attributeInput']",
close: "[data-id='close']",
dataTypeSelector: "[data-id='dataTypeSelector']",
searchWeightSelector: "[data-id='searchWeightSelector']",
entityTypeSelector: "[data-id='entityTypeSelector']",
enumTypeSelectorContainer: "[data-id='enumTypeSelectorContainer']",
enumTypeSelector: "[data-id='enumTypeSelector']",
......@@ -57,6 +58,9 @@ define(['require',
events["keyup " + this.ui.attributeInput] = function(e) {
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) {
var obj = { options: this.model.get('options') || {} };
delete obj.enumValues;
......@@ -142,13 +146,16 @@ define(['require',
* @constructs
*/
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;
},
onRender: function() {
var that = this,
entitytypes = '',
enumTypes = [];
enumTypes = [],
searchWeightValue = '5',
stringLengthValue = '50',
applicableEntityType = '';
this.typeHeaders.fullCollection.each(function(model) {
if (model.toJSON().category == "ENTITY") {
that.ui.entityTypeSelector.append("<option>" + model.get('name') + "</option>");
......@@ -162,34 +169,42 @@ define(['require',
selectionAdapter: $.fn.select2.amd.require("TagHideDeleteButtonAdapter")
});
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
$('.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.emumTypeSelectDisplay();
this.ui.enumTypeSelectorContainer.hide();
this.ui.enumTypeSelector.hide();
this.ui.enumValueSelectorContainer.hide();
if (this.isAttrEdit) {
var typeName = this.model.get("typeName");
this.ui.close.hide();
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.dataTypeSelector.attr("disabled", "false");
this.ui.dataTypeSelector.attr("disabled", "false");
this.ui.multiValueSelect.hide();
this.ui.dataTypeSelector.val(this.attrDetails.attrTypeName);
if (this.attrDetails.attrTypeName == "string") {
this.ui.dataTypeSelector.val(typeName);
if (typeName == "string") {
this.ui.stringLengthContainer.show();
this.ui.stringLengthValue.show();
this.ui.stringLengthValue.val(this.attrDetails.maxStrLength);
} else {
this.ui.stringLengthContainer.hide();
this.ui.stringLengthValue.hide();
}
_.each(this.attrDetails.attrEntityType, function(valName) {
if (applicableEntityType) {
_.each(applicableEntityType, function(valName) {
that.ui.entityTypeSelector.find('option').each(function(o) {
var $el = $(this)
if ($el.data("name") === valName) {
......@@ -197,16 +212,14 @@ define(['require',
}
})
});
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") {
this.ui.enumTypeSelector.attr("disabled", "false");
this.ui.dataTypeSelector.val("enumeration").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.multiValueSelectStatus).prop('checked', true).trigger('change');
this.ui.multiValueSelectStatus.attr("disabled", "false");
......
......@@ -146,14 +146,11 @@ define(['require',
that.guid = guid;
_.each(attrributes, function(attrObj) {
if (attrObj.name === attrName) {
attrDetails.attrTypeName = attrObj.typeName;
attrDetails = $.extend(true, {}, attrObj);
if (attrObj.typeName.includes('array')) {
attrDetails.attrTypeName = attrObj.typeName.replace("array<", "").replace(">", "");
attrDetails.typeName = attrObj.typeName.replace("array<", "").replace(">", "");
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',
onEditCallback: function() {
that.businessMetadataDefCollection.fullCollection.sort({ silent: true });
that.renderTableLayoutView();
},
onUpdateBusinessMetadata: function() {
enumDefCollection.fetch({ reset: true });
onUpdateBusinessMetadata: function(fetch) {
that.showDetails = true;
that.toggleBusinessMetadataDetailsAttrView();
if (fetch) {
enumDefCollection.fetch({ reset: true });
that.entityDefCollection.fetch({ silent: true });
}
},
parent: that.$el,
businessMetadataDefCollection: that.businessMetadataDefCollection,
......@@ -203,11 +201,13 @@ define(['require',
that.toggleBusinessMetadataDetailsAttrView();
require(["views/business_metadata/CreateBusinessMetadataLayoutView"], function(CreateBusinessMetadataLayoutView) {
that.view = new CreateBusinessMetadataLayoutView({
onUpdateBusinessMetadata: function() {
enumDefCollection.fetch({ reset: true });
onUpdateBusinessMetadata: function(fetch) {
that.showDetails = true;
that.toggleBusinessMetadataDetailsAttrView();
if (fetch) {
enumDefCollection.fetch({ reset: true });
that.entityDefCollection.fetch({ silent: true });
}
},
businessMetadataDefCollection: that.businessMetadataDefCollection,
enumDefCollection: enumDefCollection,
......
......@@ -54,7 +54,6 @@ define(['require',
businessMetadataDefCollection: this.businessMetadataDefCollection,
enumDefCollection: this.enumDefCollection,
isAttrEdit: this.isAttrEdit,
attrDetails: this.attrDetails,
viewId: this.cid,
collection: this.collection
};
......@@ -104,16 +103,9 @@ define(['require',
this.create = true;
}
if (!this.isNewBusinessMetadata) {
this.collection = this.isAttrEdit ? new Backbone.Collection([{
"name": this.attrDetails.name,
"typeName": this.attrDetails.attrTypeName,
"isOptional": true,
"cardinality": "SINGLE",
"valuesMinCount": 0,
"valuesMaxCount": 1,
"isUnique": false,
"isIndexable": false
}]) : new Backbone.Collection([{
this.collection = this.isAttrEdit ? new Backbone.Collection([
this.attrDetails
]) : new Backbone.Collection([{
"name": "",
"typeName": "string",
"isOptional": true,
......@@ -263,7 +255,7 @@ define(['require',
content: "Business Metadata " + name + Messages.getAbbreviationMsg(false, 'addSuccessMessage')
});
}
that.options.onUpdateBusinessMetadata();
that.options.onUpdateBusinessMetadata(true);
},
silent: true,
reset: true,
......@@ -306,7 +298,7 @@ define(['require',
that.selectedBusinessMetadata.set(model.businessMetadataDefs[0]);
}
that.options.onEditCallback();
that.options.onUpdateBusinessMetadata();
that.options.onUpdateBusinessMetadata(true);
},
silent: 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