Commit fdbc36e8 by kevalbhatt

ATLAS-3375: UI : Allows user to associate term to multiple entities

parent 6fbda5bc
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
tr.empty {
td {
......@@ -41,6 +39,7 @@ tr.empty {
.table-action-btn {
position: absolute;
right: 0px;
top: -5px;
}
.entity-detail-table,
......
......@@ -17,13 +17,13 @@
<div class="position-relative">
<div class="tableOverlay"></div>
<div class="inline-content-fr table-action-btn">
<div class="clearfix inline">
<a href="javascript:void(0)" title="Assign Classification" class="inputAssignTag multiSelectTag assignTag btn btn-action btn-sm" style="display:none" data-id="addAssignTag"><i class="fa fa-plus"></i>&nbsp;Classification</a>
</div>
<div class="inline" data-id="checkDeletedEntity">
<label class="checkbox-inline btn">
<input type="checkbox" class="input" name="queryType" value="text" name="check" value="1" />Show historical entities</label>
</div>
<div class="clearfix inline">
<a href="javascript:void(0)" class="inputAssignTag multiSelectTag assignTag btn btn-action btn-sm" style="display:none" data-id="addAssignTag"><i class="fa fa-plus"></i> Assign Tag</a>
</div>
</div>
<div id="r_schemaTableLayoutView">
</div>
......
......@@ -42,10 +42,15 @@
<span class="labelShowRecord pull-left" data-id="pageRecordText"> </span>
</div>
<div class="col-sm-9 inline-content-fr no-padding-left">
<div class="inline" data-id="colManager"></div>
<div class="inline">
<a href="javascript:void(0)" class=" multiSelectTag assignTag btn btn-action btn-sm" style="display:none" title="Assign Classification" data-id="addAssignTag"><i class="fa fa-plus"></i>&nbsp;Classification</a>
<a href="javascript:void(0)" class="multiSelectTag assignTag btn btn-action btn-sm" style="display:none" title="Assign Classification" data-id="addAssignTag"><i class="fa fa-plus"></i>&nbsp;Classification</a>
</div>
<div class="inline" data-id="colManager"></div>
{{#unless isGlossaryView}}
<div class="inline">
<a href="javascript:void(0)" class="multiSelectTerm assignTerm btn btn-action btn-sm" style="display:none" title="Assign Term" data-id="addAssignTerm"><i class="fa fa-plus"></i>&nbsp;Term</a>
</div>
{{/unless}}
<div class="inline" data-id="containerCheckBox" style="display: none;">
<label class="checkbox-inline btn" for="historicalentities">
<input type="checkbox" data-id="checkDeletedEntity" data-value="includeDE" id="historicalentities" />
......
......@@ -186,7 +186,6 @@ define(['require'], function(require) {
"totalFailed": "number",
"totalUpdates": "number",
"processedMessageCount": "number",
"lastMessageProcessedTime": "day",
"failedMessageCount": "number"
}
};
......
......@@ -30,6 +30,7 @@ define(['require'], function(require) {
removeErrorMessage: " could not be removed",
editSuccessMessage: " has been updated successfully",
assignDeletedEntity: " is deleted, Classification cannot be assigned",
assignTermDeletedEntity: " is deleted, Term cannot be assigned",
conformation: {
deleteMessage: "Are you sure you want to delete "
},
......
......@@ -21,10 +21,11 @@ define(['require',
'hbs!tmpl/glossary/AssignTermLayoutView_tmpl',
'utils/Utils',
'utils/Enums',
'utils/Messages',
'utils/UrlLinks',
'modules/Modal',
'jquery-steps'
], function(require, Backbone, AssignTermLayoutViewTmpl, Utils, Enums, UrlLinks, Modal) {
], function(require, Backbone, AssignTermLayoutViewTmpl, Utils, Enums, Messages, UrlLinks, Modal) {
var AssignTermLayoutView = Backbone.Marionette.LayoutView.extend(
/** @lends AssignTermLayoutView */
......@@ -59,7 +60,7 @@ define(['require',
* @constructs
*/
initialize: function(options) {
_.extend(this, _.pick(options, 'glossaryCollection', 'guid', 'callback', 'hideLoader', 'isCategoryView', 'categoryData', 'isTermView', 'termData', 'isAttributeRelationView', 'selectedTermAttribute', 'associatedTerms'));
_.extend(this, _.pick(options, 'glossaryCollection', 'guid', 'callback', 'hideLoader', 'isCategoryView', 'categoryData', 'isTermView', 'termData', 'isAttributeRelationView', 'selectedTermAttribute', 'associatedTerms', 'multiple'));
var that = this;
this.options = options;
if (!this.isCategoryView && !this.isTermView && !this.isAttributeRelationView) {
......@@ -80,7 +81,6 @@ define(['require',
"title": title,
"content": this,
"cancelText": "Cancel",
"okCloses": false,
"okText": "Assign",
"allowCancel": true,
"showFooter": this.isAttributeRelationView ? false : true,
......@@ -151,6 +151,7 @@ define(['require',
termAttributeFormData = [],
selectedItem = this.glossary.selectedItem,
selectedGuid = selectedItem.guid,
termName = selectedItem.text,
ajaxOptions = {
success: function(rModel, response) {
Utils.notifySuccess({
......@@ -195,8 +196,70 @@ define(['require',
}
model.assignTermToAttributes(_.extend(ajaxOptions, { data: JSON.stringify(data), guid: data.guid }));
} else {
data.push({ "guid": that.guid });
model.assignTermToEntity(selectedGuid, _.extend(ajaxOptions, { data: JSON.stringify(data) }));
var deletedEntity = [],
skipEntity = [];
if (this.multiple) {
_.each(that.multiple, function(entity, i) {
var name = Utils.getName(entity.model);
if (Enums.entityStateReadOnly[entity.model.status]) {
deletedEntity.push(name);
} else {
if (_.indexOf((entity.model.meaningNames || _.pluck(entity.model.meanings, 'displayText')), termName) === -1) {
data.push({ guid: entity.model.guid })
} else {
skipEntity.push(name);
}
}
});
if (deletedEntity.length) {
Utils.notifyError({
html: true,
content: "<b>" + deletedEntity.join(', ') +
"</b> " + (deletedEntity.length === 1 ? "entity " : "entities ") +
Messages.assignTermDeletedEntity
});
}
} else {
data.push({ "guid": that.guid });
}
if (skipEntity.length) {
var text = "<b>" + skipEntity.length + " of " + that.multiple.length +
"</b> entities selected have already been associated with <b>" + termName +
"</b> term, Do you want to associate the term with other entities ?",
removeCancelButton = false;
if ((skipEntity.length + deletedEntity.length) === that.multiple.length) {
text = (skipEntity.length > 1 ? "All selected" : "Selected") + " entities have already been associated with <b>" + termName + "</b> term";
removeCancelButton = true;
}
var notifyObj = {
text: text,
modal: true,
ok: function(argument) {
if (data.length) {
model.assignTermToEntity(selectedGuid, _.extend(ajaxOptions, { data: JSON.stringify(data) }));
}
},
cancel: function(argument) {}
}
if (removeCancelButton) {
notifyObj['confirm'] = {
confirm: true,
buttons: [{
text: 'Ok',
addClass: 'btn-atlas btn-md',
click: function(notice) {
notice.remove();
}
},
null
]
}
}
Utils.notifyConfirm(notifyObj);
} else if (data.length) {
model.assignTermToEntity(selectedGuid, _.extend(ajaxOptions, { data: JSON.stringify(data) }));
}
}
},
renderGlossaryTree: function() {
......
......@@ -60,6 +60,7 @@ define(['require',
nextData: "[data-id='nextData']",
pageRecordText: "[data-id='pageRecordText']",
addAssignTag: "[data-id='addAssignTag']",
addAssignTerm: "[data-id='addAssignTerm']",
createEntity: "[data-id='createEntity']",
checkDeletedEntity: "[data-id='checkDeletedEntity']",
checkSubClassification: "[data-id='checkSubClassification']",
......@@ -129,9 +130,10 @@ define(['require',
};
events["change " + this.ui.showPage] = 'changePageLimit';
events["click " + this.ui.gotoPagebtn] = 'gotoPagebtn';
events["click " + this.ui.addTag] = 'checkedValue';
events["click " + this.ui.addTag] = 'onClickAddTag';
events["click " + this.ui.addTerm] = 'onClickAddTermBtn';
events["click " + this.ui.addAssignTag] = 'checkedValue';
events["click " + this.ui.addAssignTag] = 'onClickAddTag';
events["click " + this.ui.addAssignTerm] = 'onClickAddTermBtn';
events["click " + this.ui.nextData] = "onClicknextData";
events["click " + this.ui.previousData] = "onClickpreviousData";
events["click " + this.ui.createEntity] = 'onClickCreateEntity';
......@@ -152,7 +154,7 @@ define(['require',
this.asyncFetchCounter = 0;
this.offset = 0;
this.bindEvents();
this.arr = [];
this.multiSelectEntity = [];
this.searchType = 'Basic Search';
this.columnOrder = null;
if (this.value) {
......@@ -186,7 +188,7 @@ define(['require',
var that = this;
this.onClickLoadMore();
this.listenTo(this.searchCollection, 'backgrid:selected', function(model, checked) {
this.arr = [];
this.multiSelectEntity = [];
if (checked === true) {
model.set("isEnable", true);
} else {
......@@ -195,17 +197,17 @@ define(['require',
this.searchCollection.find(function(item) {
if (item.get('isEnable')) {
var obj = item.toJSON();
that.arr.push({
that.multiSelectEntity.push({
id: obj.guid,
model: obj
});
}
});
if (this.arr.length > 0) {
this.$('.multiSelectTag').show();
if (this.multiSelectEntity.length > 0) {
this.$('.multiSelectTag,.multiSelectTerm').show();
} else {
this.$('.multiSelectTag').hide();
this.$('.multiSelectTag,.multiSelectTerm').hide();
}
});
this.listenTo(this.searchCollection, "error", function(model, response) {
......@@ -263,7 +265,7 @@ define(['require',
saveState: false
},
visibilityControlOpts: {
buttonTemplate: _.template("<button class='btn btn-action btn-sm pull-right'>Attributes&nbsp<i class='fa fa-caret-down'></i></button>")
buttonTemplate: _.template("<button class='btn btn-action btn-sm pull-right'>Columns&nbsp<i class='fa fa-caret-down'></i></button>")
},
el: this.ui.colManager
},
......@@ -942,8 +944,9 @@ define(['require',
guid: guid,
multiple: multiple,
callback: function() {
that.multiSelectEntity = [];
that.$('.multiSelectTag,.multiSelectTerm').hide();
that.fetchCollection();
that.arr = [];
},
tagList: that.getTagList(guid, multiple),
showLoader: that.showLoader.bind(that),
......@@ -985,12 +988,12 @@ define(['require',
options && options.type === 'error' ? this.$('.ellipsis-with-margin,.pagination-box').hide() : this.$('.ellipsis-with-margin,.pagination-box').show(); // only show for first time and hide when type is error
this.$('.tableOverlay').removeClass('show');
},
checkedValue: function(e) {
onClickAddTag: function(e) {
var guid = "",
that = this,
isTagMultiSelect = $(e.currentTarget).hasClass('multiSelectTag');
if (isTagMultiSelect && this.arr && this.arr.length) {
that.addTagModalView(guid, this.arr);
if (isTagMultiSelect && this.multiSelectEntity && this.multiSelectEntity.length) {
that.addTagModalView(guid, this.multiSelectEntity);
} else {
guid = that.$(e.currentTarget).data("guid");
that.addTagModalView(guid);
......@@ -998,14 +1001,26 @@ define(['require',
},
onClickAddTermBtn: function(e) {
var that = this,
guid = "",
entityGuid = $(e.currentTarget).data("guid"),
associatedTerms = undefined,
multiple = undefined,
isTermMultiSelect = $(e.currentTarget).hasClass('multiSelectTerm');
if (isTermMultiSelect && this.multiSelectEntity && this.multiSelectEntity.length) {
multiple = this.multiSelectEntity;
} else if (entityGuid) {
associatedTerms = this.searchCollection.find({ guid: entityGuid }).get('meanings');
}
require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
var view = new AssignTermLayoutView({
guid: entityGuid,
multiple: multiple,
associatedTerms: associatedTerms,
callback: function() {
that.multiSelectEntity = [];
that.$('.multiSelectTag,.multiSelectTerm').hide();
that.fetchCollection();
},
glossaryCollection: that.glossaryCollection,
});
......
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