Commit c9a91264 by kalyani Committed by kevalbhatt

ATLAS-1433 : Atlas allows creation of tag with attributes' name same as that of its parent tags.

parent 97209e81
......@@ -118,3 +118,11 @@ g.type-TK > rect {
top: 4px;
right: 5px;
}
.legends {
> i {
> span {
font-family: 'Source Sans Pro';
}
}
}
......@@ -64,6 +64,7 @@
text-overflow: ellipsis;
max-width: 91%;
overflow: hidden;
font-size: 14px;
}
}
ul {
......@@ -252,6 +253,10 @@
}
}
.superType {
margin-bottom: 15px;
}
form-control .tagInpput {
margin-bottom: 15px;
margin-top: 15px;
......@@ -288,6 +293,13 @@ form-control .tagInpput {
margin-right: 5px;
}
.superTypeLabel {
font-weight: 600;
width: 90px;
margin-right: 5px;
float: left;
}
.inputAssignTag {
display: block;
padding: 2px 5px;
......
......@@ -48,7 +48,7 @@ define(['require',
}, options);
return this.constructor.nonCrudOperation.call(this, url, 'DELETE', options);
},
saveTagAttribute: function(guid, options) {
saveTagAttribute: function(options) {
var url = UrlLinks.typesClassicationApiUrl();
options = _.extend({
contentType: 'application/json',
......
......@@ -22,6 +22,11 @@
<h1><span data-id="title"></span></h1>
<button type="button" data-id="editButton" class="btn btn-default pull-right editbutton" id="editText"><i class="fa fa-pencil"></i></button>
<p class="sub-title" data-id="description"></p>
<div class="superType" style="display:none">
<span class="superTypeLabel">Derived From:</span>
<div data-id="showSuperType" style="display: inline-block;">
</div>
</div>
<div class="attributes">
<span class="attrLabel">Attributes:</span>
<div data-id="showAttribute">
......
......@@ -45,7 +45,8 @@ define(['require',
addTagPlus: '[data-id="addTagPlus"]',
addTagBtn: '[data-id="addTagBtn"]',
description: '[data-id="description"]',
publishButton: '[data-id="publishButton"]'
publishButton: '[data-id="publishButton"]',
showSuperType: "[data-id='showSuperType']"
},
/** ui events hash */
events: function() {
......@@ -100,8 +101,9 @@ define(['require',
},
renderTagDetail: function() {
var attributeData = "",
attributeDefs = this.model.get("attributeDefs");
supertypeData = "",
attributeDefs = this.model.get("attributeDefs"),
superTypeArr = this.model.get('superTypes');
this.ui.title.html('<span>' + (Utils.getName(this.model.toJSON())) + '</span>');
if (this.model.get("description")) {
this.ui.description.text(this.model.get("description"));
......@@ -115,6 +117,13 @@ define(['require',
});
this.ui.showAttribute.html(attributeData);
}
if (superTypeArr.length > 0) {
this.$(".superType").show();
_.each(superTypeArr, function(value, key) {
supertypeData += ' <a class="inputAttribute" href="#!/tag/tagAttribute/' + value + '">' + value + '</a>';
});
this.ui.showSuperType.html(supertypeData);
}
Utils.hideTitleLoader(this.$('.fontLoader'), this.$('.tagDetail'));
},
onSaveButton: function(saveObject, message) {
......@@ -138,7 +147,7 @@ define(['require',
return;
}
Utils.showTitleLoader(this.$('.page-title .fontLoader'), this.$('.tagDetail'));
this.model.saveTagAttribute(this.model.get('guid'), {
this.model.saveTagAttribute({
data: JSON.stringify({
classificationDefs: [saveObject],
entityDefs: [],
......@@ -154,6 +163,9 @@ define(['require',
Utils.notifySuccess({
content: message
});
},
cust_error: function() {
Utils.hideTitleLoader(that.$('.fontLoader'), that.$('.tagDetail'));
}
});
that.modal.close();
......@@ -182,20 +194,61 @@ define(['require',
}
});
that.modal.on('ok', function() {
var newAttributeList = view.collection.toJSON();
try {
var saveJSON = JSON.parse(JSON.stringify(that.model.toJSON()));
} catch (err) {
Utils.serverErrorHandler();
}
if (saveJSON) {
var oldAttributeList = saveJSON.attributeDefs;
}
var newAttributeList = view.collection.toJSON(),
activeTagAttribute = _.extend([], that.model.get('attributeDefs')),
superTypes = that.model.get('superTypes');
_.each(superTypes, function(name) {
var parentTags = that.collection.fullCollection.findWhere({ name: name });
activeTagAttribute = activeTagAttribute.concat(parentTags.get('attributeDefs'));
});
var duplicateAttributeList = [],
saveObj = $.extend(true, {}, that.model.toJSON());
_.each(newAttributeList, function(obj) {
oldAttributeList.push(obj);
var duplicateCheck = _.find(activeTagAttribute, function(activeTagObj) {
return activeTagObj.name.toLowerCase() === obj.name.toLowerCase();
});
if (duplicateCheck) {
duplicateAttributeList.push(obj.name);
} else {
saveObj.attributeDefs.push(obj);
}
});
if (saveJSON) {
that.onSaveButton(saveJSON, Messages.addAttributeSuccessMessage);
var notifyObj = {
confirm: {
confirm: true,
buttons: [{
text: 'Ok',
addClass: 'btn-primary',
click: function(notice) {
notice.remove();
}
},
null
]
}
}
if (saveObj && !duplicateAttributeList.length) {
that.onSaveButton(saveObj, Messages.addAttributeSuccessMessage);
} else {
if (duplicateAttributeList.length < 2) {
var text = "Attribute <b>" + duplicateAttributeList.join(",") + "</b> is duplicate !"
} else {
if (newAttributeList.length > duplicateAttributeList.length) {
var text = "Attributes: <b>" + duplicateAttributeList.join(",") + "</b> are duplicate ! Do you want to continue with other attributes ?"
notifyObj = {
ok: function(argument) {
that.onSaveButton(saveObj, Messages.addAttributeSuccessMessage);
},
cancel: function(argument) {}
}
} else {
var text = "All attributes are duplicate !"
}
}
notifyObj['text'] = text;
Utils.notifyConfirm(notifyObj);
}
});
that.modal.on('closeModal', function() {
......
......@@ -228,6 +228,7 @@ define(['require',
});
return;
}
this.name = ref.ui.tagName.val();
this.description = ref.ui.description.val();
var superTypes = [];
......@@ -238,6 +239,57 @@ define(['require',
if (ref.collection.length === 1 && ref.collection.first().get("name") === "") {
attributeObj = [];
}
if (attributeObj.length) {
var superTypesAttributes = [];
_.each(superTypes, function(name) {
var parentTags = that.collection.fullCollection.findWhere({ name: name });
superTypesAttributes = superTypesAttributes.concat(parentTags.get('attributeDefs'));
});
var duplicateAttributeList = [];
_.each(attributeObj, function(obj) {
var duplicateCheck = _.find(superTypesAttributes, function(activeTagObj) {
return activeTagObj.name.toLowerCase() === obj.name.toLowerCase();
});
if (duplicateCheck) {
duplicateAttributeList.push(obj.name);
}
});
var notifyObj = {
confirm: {
confirm: true,
buttons: [{
text: 'Ok',
addClass: 'btn-primary',
click: function(notice) {
notice.remove();
}
},
null
]
}
}
if (duplicateAttributeList.length) {
if (duplicateAttributeList.length < 2) {
var text = "Attribute <b>" + duplicateAttributeList.join(",") + "</b> is duplicate !"
} else {
if (attributeObj.length > duplicateAttributeList.length) {
var text = "Attributes: <b>" + duplicateAttributeList.join(",") + "</b> are duplicate !"
} else {
var text = "All attributes are duplicate !"
}
}
notifyObj['text'] = text;
Utils.notifyConfirm(notifyObj);
return false;
}
}
this.json = {
classificationDefs: [{
'name': this.name.trim(),
......
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