You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by pi...@apache.org on 2022/02/03 05:15:11 UTC
[atlas] branch master updated: ATLAS-3985: UI: Not able to assign classification with mandatory attribute of type 'array'
This is an automated email from the ASF dual-hosted git repository.
pinal pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new e1726d6 ATLAS-3985: UI: Not able to assign classification with mandatory attribute of type 'array<string>'
e1726d6 is described below
commit e1726d6cb85aa5821176a149d7b9aa9d4abb4df3
Author: Prasad Pawar <pr...@freestoneinfotech.com>
AuthorDate: Tue Feb 1 19:40:11 2022 +0530
ATLAS-3985: UI: Not able to assign classification with mandatory attribute of type 'array<string>'
Signed-off-by: Pinal Shah <pi...@freestoneinfotech.com>
---
.../templates/tag/TagAttributeItemView_tmpl.html | 2 +-
dashboardv2/public/js/views/tag/AddTagModalView.js | 105 ++++++++++++++++++---
.../public/js/views/tag/TagAttributeItemView.js | 10 +-
.../templates/tag/TagAttributeItemView_tmpl.html | 2 +-
dashboardv3/public/js/views/tag/AddTagModalView.js | 105 ++++++++++++++++++---
.../public/js/views/tag/TagAttributeItemView.js | 10 +-
6 files changed, 204 insertions(+), 30 deletions(-)
diff --git a/dashboardv2/public/js/templates/tag/TagAttributeItemView_tmpl.html b/dashboardv2/public/js/templates/tag/TagAttributeItemView_tmpl.html
index 0212e8a..012c310 100644
--- a/dashboardv2/public/js/templates/tag/TagAttributeItemView_tmpl.html
+++ b/dashboardv2/public/js/templates/tag/TagAttributeItemView_tmpl.html
@@ -28,7 +28,7 @@
<option>int</option>
<option>float</option>
<option>double</option>
- <option>date</option>
+ <option>array<string></option>
</select>
</div>
<div class="col-sm-2 attributePlusData" align="right">
diff --git a/dashboardv2/public/js/views/tag/AddTagModalView.js b/dashboardv2/public/js/views/tag/AddTagModalView.js
index da70dc4..d846276 100644
--- a/dashboardv2/public/js/views/tag/AddTagModalView.js
+++ b/dashboardv2/public/js/views/tag/AddTagModalView.js
@@ -154,14 +154,28 @@ define(['require',
guid: [],
skipEntity: [],
deletedEntity: []
- };
+ },
+ isValidateAttrValue = true,
+ validationKey = [];
tagAttributeNames.each(function(i, item) {
- var selection = $(item).data("key");
- var datatypeSelection = $(item).data("type");
+ var selection = $(item).data("key"),
+ isRequired = $(item).hasClass('required'),
+ datatypeSelection = $(item).data("type");
+ $(item).removeClass('errorValidate');
if (datatypeSelection === "date") {
tagAttributes[selection] = Date.parse($(item).val()) || null;
} else {
- tagAttributes[selection] = $(item).val() || null;
+ if (isRequired) {
+ if ($(item).val().length) {
+ tagAttributes[selection] = $(item).val() || null;
+ } else {
+ isValidateAttrValue = false;
+ $(item).addClass('errorValidate');
+ validationKey.push($(item).data("key"));
+ }
+ } else {
+ tagAttributes[selection] = $(item).val() || null;
+ }
}
});
@@ -246,6 +260,18 @@ define(['require',
that.hideLoader();
}
}
+ } else if (isValidateAttrValue === false) {
+ var validationMsg = "" + _.each(validationKey, function(key) {
+ return key + " ";
+ });
+ that.modal.$el.find('button.ok').hideButtonLoader();
+ Utils.notifyInfo({
+ content: "Value for " + validationMsg + " cannot be empty"
+ });
+ if (this.hideLoader) {
+ this.hideLoader();
+ };
+ return;
} else {
obj.guid.push(that.guid);
that.saveTagData(obj);
@@ -385,7 +411,9 @@ define(['require',
if (attributeDefs) {
_.each(attributeDefs, function(obj) {
var name = Utils.getName(obj, 'name');
- var typeName = Utils.getName(obj, 'typeName');
+ var typeName = Utils.getName(obj, 'typeName'),
+ isOptional = obj.isOptional,
+ inputClassName = "form-control attributeInputVal attrName" + (isOptional ? "" : " required");
var typeNameValue = that.enumDefCollection.fullCollection.findWhere({ 'name': typeName });
if (typeNameValue) {
var str = '<option value=""' + (!that.tagModel ? 'selected' : '') + '>-- Select ' + typeName + " --</option>";
@@ -393,12 +421,17 @@ define(['require',
_.each(enumValue, function(key, value) {
str += '<option ' + ((that.tagModel && key.value === that.tagModel.attributes[name]) ? 'selected' : '') + '>' + _.escape(key.value) + '</option>';
})
- that.ui.tagAttribute.append('<div class="form-group"><label>' + name + '</label>' + ' (' + typeName + ')' +
- '<select class="form-control attributeInputVal attrName" data-key="' + name + '">' + str + '</select></div>');
+ that.ui.tagAttribute.append('<div class="form-group"><label class="' + (isOptional ? "" : " required") + '">' + name + '</label>' + ' (' + typeName + ')' +
+ '<select class="' + inputClassName + '" data-key="' + name + '">' + str + '</select></div>');
+ } else if (typeName.indexOf('array') == 0) {
+ var arraytTypeName = new DOMParser().parseFromString(typeName, "text/html");
+
+ that.ui.tagAttribute.append('<div class="form-group"><label class="' + (isOptional ? "" : " required") + '">' + name + '</label>' + ' (' + typeName + ')' +
+ '<select class="' + inputClassName + '" data-id="addArryString" multiple="multiple" data-key="' + name + '" data-type="' + arraytTypeName.documentElement.textContent + '"></select></div>');
} else {
- var textElement = that.getElement(name, typeName);
+ var textElement = that.getElement(name, typeName, inputClassName);
if (_.isTypePrimitive(typeName)) {
- that.ui.tagAttribute.append('<div class="form-group"><label>' + name + '</label>' + ' (' + typeName + ')' + textElement + '</div>');
+ that.ui.tagAttribute.append('<div class="form-group"><label class="' + (isOptional ? "" : " required") + '">' + name + '</label>' + ' (' + typeName + ')' + textElement + '</div>');
}
}
});
@@ -428,18 +461,64 @@ define(['require',
this.value = that.tagModel.attributes[labelName];
}
});
+ that.$('select[data-type="array<string>"]').each(function() {
+ var stringData = $(this).data('key');
+ if (that.tagModel) {
+ var stringValues = that.tagModel.attributes[stringData] || [],
+ str = stringValues.map(function(label) {
+ return "<option selected > " + _.escape(label) + " </option>";
+ });
+ $(this).html(str);
+ }
+ var getLabelData = function(data, selectedData) {
+ if (data.suggestions.length) {
+ return _.map(data.suggestions, function(name, index) {
+ var findValue = _.find(selectedData, { id: name })
+ if (findValue) {
+ return findValue;
+ } else {
+ return {
+ id: name,
+ text: name
+ }
+ }
+ });
+ } else {
+ var findValue = _.find(selectedData, { id: data.prefixString })
+ return findValue ? [findValue] : [];
+ }
+ };
+ $(this).select2({
+ placeholder: "Select String",
+ allowClear: false,
+ tags: true,
+ multiple: true,
+ createTag: function(data) {
+ var found = _.find(this.$element.select2("data"), { id: data.term });
+ if (!found) {
+ return { id: data.term, text: data.term };
+ }
+ },
+ templateResult: that.formatResultSearch
+ })
+
+ });
this.showAttributeBox();
}
},
- getElement: function(labelName, typeName) {
+ formatResultSearch: function(state) {
+ if (!state.element && state.text.trim() !== "") {
+ return $("<span>Add<strong> '" + _.escape(state.text) + "'</strong></span>");
+ }
+ },
+ getElement: function(labelName, typeName, inputClassName) {
var value = this.tagModel && this.tagModel.attributes ? (this.tagModel.attributes[_.unescape(labelName)] || "") : "",
- isTypeNumber = typeName === "int" || typeName === "byte" || typeName === "short" || typeName === "double" || typeName === "float",
- inputClassName = "form-control attributeInputVal attrName";
+ isTypeNumber = typeName === "int" || typeName === "byte" || typeName === "short" || typeName === "double" || typeName === "float";
if (isTypeNumber) {
inputClassName += ((typeName === "int" || typeName === "byte" || typeName === "short") ? " number-input-negative" : " number-input-exponential");
}
if (typeName === "boolean") {
- return '<select class="form-control attributeInputVal attrName" data-key="' + labelName + '" data-type="' + typeName + '"> ' +
+ return '<select class="' + inputClassName + '" data-key="' + labelName + '" data-type="' + typeName + '"> ' +
'<option value="">--Select true or false--</option>' +
'<option value="true">true</option>' +
'<option value="false">false</option></select>';
diff --git a/dashboardv2/public/js/views/tag/TagAttributeItemView.js b/dashboardv2/public/js/views/tag/TagAttributeItemView.js
index 0016bbe..55d1f91 100644
--- a/dashboardv2/public/js/views/tag/TagAttributeItemView.js
+++ b/dashboardv2/public/js/views/tag/TagAttributeItemView.js
@@ -44,7 +44,15 @@ define(['require',
this.model.set({ "name": e.target.value.trim() });
};
events["change " + this.ui.dataTypeSelector] = function(e) {
- this.model.set({ "typeName": e.target.value.trim() });
+ var typeName = e.target.value.trim();
+ if (typeName.indexOf("array") == 0) {
+ this.model.set({
+ "cardinality": "SET",
+ "valuesMinCount": 1,
+ "valuesMaxCount": 2147483647
+ });
+ }
+ this.model.set({ "typeName": typeName });
};
events["click " + this.ui.close] = 'onCloseButton';
return events;
diff --git a/dashboardv3/public/js/templates/tag/TagAttributeItemView_tmpl.html b/dashboardv3/public/js/templates/tag/TagAttributeItemView_tmpl.html
index 0212e8a..012c310 100644
--- a/dashboardv3/public/js/templates/tag/TagAttributeItemView_tmpl.html
+++ b/dashboardv3/public/js/templates/tag/TagAttributeItemView_tmpl.html
@@ -28,7 +28,7 @@
<option>int</option>
<option>float</option>
<option>double</option>
- <option>date</option>
+ <option>array<string></option>
</select>
</div>
<div class="col-sm-2 attributePlusData" align="right">
diff --git a/dashboardv3/public/js/views/tag/AddTagModalView.js b/dashboardv3/public/js/views/tag/AddTagModalView.js
index da70dc4..d846276 100644
--- a/dashboardv3/public/js/views/tag/AddTagModalView.js
+++ b/dashboardv3/public/js/views/tag/AddTagModalView.js
@@ -154,14 +154,28 @@ define(['require',
guid: [],
skipEntity: [],
deletedEntity: []
- };
+ },
+ isValidateAttrValue = true,
+ validationKey = [];
tagAttributeNames.each(function(i, item) {
- var selection = $(item).data("key");
- var datatypeSelection = $(item).data("type");
+ var selection = $(item).data("key"),
+ isRequired = $(item).hasClass('required'),
+ datatypeSelection = $(item).data("type");
+ $(item).removeClass('errorValidate');
if (datatypeSelection === "date") {
tagAttributes[selection] = Date.parse($(item).val()) || null;
} else {
- tagAttributes[selection] = $(item).val() || null;
+ if (isRequired) {
+ if ($(item).val().length) {
+ tagAttributes[selection] = $(item).val() || null;
+ } else {
+ isValidateAttrValue = false;
+ $(item).addClass('errorValidate');
+ validationKey.push($(item).data("key"));
+ }
+ } else {
+ tagAttributes[selection] = $(item).val() || null;
+ }
}
});
@@ -246,6 +260,18 @@ define(['require',
that.hideLoader();
}
}
+ } else if (isValidateAttrValue === false) {
+ var validationMsg = "" + _.each(validationKey, function(key) {
+ return key + " ";
+ });
+ that.modal.$el.find('button.ok').hideButtonLoader();
+ Utils.notifyInfo({
+ content: "Value for " + validationMsg + " cannot be empty"
+ });
+ if (this.hideLoader) {
+ this.hideLoader();
+ };
+ return;
} else {
obj.guid.push(that.guid);
that.saveTagData(obj);
@@ -385,7 +411,9 @@ define(['require',
if (attributeDefs) {
_.each(attributeDefs, function(obj) {
var name = Utils.getName(obj, 'name');
- var typeName = Utils.getName(obj, 'typeName');
+ var typeName = Utils.getName(obj, 'typeName'),
+ isOptional = obj.isOptional,
+ inputClassName = "form-control attributeInputVal attrName" + (isOptional ? "" : " required");
var typeNameValue = that.enumDefCollection.fullCollection.findWhere({ 'name': typeName });
if (typeNameValue) {
var str = '<option value=""' + (!that.tagModel ? 'selected' : '') + '>-- Select ' + typeName + " --</option>";
@@ -393,12 +421,17 @@ define(['require',
_.each(enumValue, function(key, value) {
str += '<option ' + ((that.tagModel && key.value === that.tagModel.attributes[name]) ? 'selected' : '') + '>' + _.escape(key.value) + '</option>';
})
- that.ui.tagAttribute.append('<div class="form-group"><label>' + name + '</label>' + ' (' + typeName + ')' +
- '<select class="form-control attributeInputVal attrName" data-key="' + name + '">' + str + '</select></div>');
+ that.ui.tagAttribute.append('<div class="form-group"><label class="' + (isOptional ? "" : " required") + '">' + name + '</label>' + ' (' + typeName + ')' +
+ '<select class="' + inputClassName + '" data-key="' + name + '">' + str + '</select></div>');
+ } else if (typeName.indexOf('array') == 0) {
+ var arraytTypeName = new DOMParser().parseFromString(typeName, "text/html");
+
+ that.ui.tagAttribute.append('<div class="form-group"><label class="' + (isOptional ? "" : " required") + '">' + name + '</label>' + ' (' + typeName + ')' +
+ '<select class="' + inputClassName + '" data-id="addArryString" multiple="multiple" data-key="' + name + '" data-type="' + arraytTypeName.documentElement.textContent + '"></select></div>');
} else {
- var textElement = that.getElement(name, typeName);
+ var textElement = that.getElement(name, typeName, inputClassName);
if (_.isTypePrimitive(typeName)) {
- that.ui.tagAttribute.append('<div class="form-group"><label>' + name + '</label>' + ' (' + typeName + ')' + textElement + '</div>');
+ that.ui.tagAttribute.append('<div class="form-group"><label class="' + (isOptional ? "" : " required") + '">' + name + '</label>' + ' (' + typeName + ')' + textElement + '</div>');
}
}
});
@@ -428,18 +461,64 @@ define(['require',
this.value = that.tagModel.attributes[labelName];
}
});
+ that.$('select[data-type="array<string>"]').each(function() {
+ var stringData = $(this).data('key');
+ if (that.tagModel) {
+ var stringValues = that.tagModel.attributes[stringData] || [],
+ str = stringValues.map(function(label) {
+ return "<option selected > " + _.escape(label) + " </option>";
+ });
+ $(this).html(str);
+ }
+ var getLabelData = function(data, selectedData) {
+ if (data.suggestions.length) {
+ return _.map(data.suggestions, function(name, index) {
+ var findValue = _.find(selectedData, { id: name })
+ if (findValue) {
+ return findValue;
+ } else {
+ return {
+ id: name,
+ text: name
+ }
+ }
+ });
+ } else {
+ var findValue = _.find(selectedData, { id: data.prefixString })
+ return findValue ? [findValue] : [];
+ }
+ };
+ $(this).select2({
+ placeholder: "Select String",
+ allowClear: false,
+ tags: true,
+ multiple: true,
+ createTag: function(data) {
+ var found = _.find(this.$element.select2("data"), { id: data.term });
+ if (!found) {
+ return { id: data.term, text: data.term };
+ }
+ },
+ templateResult: that.formatResultSearch
+ })
+
+ });
this.showAttributeBox();
}
},
- getElement: function(labelName, typeName) {
+ formatResultSearch: function(state) {
+ if (!state.element && state.text.trim() !== "") {
+ return $("<span>Add<strong> '" + _.escape(state.text) + "'</strong></span>");
+ }
+ },
+ getElement: function(labelName, typeName, inputClassName) {
var value = this.tagModel && this.tagModel.attributes ? (this.tagModel.attributes[_.unescape(labelName)] || "") : "",
- isTypeNumber = typeName === "int" || typeName === "byte" || typeName === "short" || typeName === "double" || typeName === "float",
- inputClassName = "form-control attributeInputVal attrName";
+ isTypeNumber = typeName === "int" || typeName === "byte" || typeName === "short" || typeName === "double" || typeName === "float";
if (isTypeNumber) {
inputClassName += ((typeName === "int" || typeName === "byte" || typeName === "short") ? " number-input-negative" : " number-input-exponential");
}
if (typeName === "boolean") {
- return '<select class="form-control attributeInputVal attrName" data-key="' + labelName + '" data-type="' + typeName + '"> ' +
+ return '<select class="' + inputClassName + '" data-key="' + labelName + '" data-type="' + typeName + '"> ' +
'<option value="">--Select true or false--</option>' +
'<option value="true">true</option>' +
'<option value="false">false</option></select>';
diff --git a/dashboardv3/public/js/views/tag/TagAttributeItemView.js b/dashboardv3/public/js/views/tag/TagAttributeItemView.js
index 0016bbe..55d1f91 100644
--- a/dashboardv3/public/js/views/tag/TagAttributeItemView.js
+++ b/dashboardv3/public/js/views/tag/TagAttributeItemView.js
@@ -44,7 +44,15 @@ define(['require',
this.model.set({ "name": e.target.value.trim() });
};
events["change " + this.ui.dataTypeSelector] = function(e) {
- this.model.set({ "typeName": e.target.value.trim() });
+ var typeName = e.target.value.trim();
+ if (typeName.indexOf("array") == 0) {
+ this.model.set({
+ "cardinality": "SET",
+ "valuesMinCount": 1,
+ "valuesMaxCount": 2147483647
+ });
+ }
+ this.model.set({ "typeName": typeName });
};
events["click " + this.ui.close] = 'onCloseButton';
return events;