Commit 20f2fba7 by kevalbhatt Committed by Madhan Neethiraj

ATLAS-2156: save-search UI to allow user to edit name

parent 454eb66a
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2 required" for="name">Name</label> <label class="control-label col-sm-2 required" for="name">Name</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input class="form-control" data-id="saveAsName" placeholder="Name(required)" autofocus/> <input class="form-control" data-id="saveAsName" placeholder="Name(required)" value="{{selectedModel.name}}" autofocus/>
</div> </div>
</div> </div>
</form> </form>
\ No newline at end of file
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
<button type="button" class="btn btn-action btn-sm" data-id="saveAsBtn">Save As</button> <button type="button" class="btn btn-action btn-sm" data-id="saveAsBtn">Save As</button>
</div> </div>
</div> </div>
<ul data-id="itemViewContent" class="tag-tree saveSearchList gray-text"> <span class="gray-text noFavoriteSearch">You don't have any favorite search.</span>
<ul data-id="itemViewContent" class="tag-tree saveSearchList">
<div class="fontLoader-relative" style="display: block;"> <div class="fontLoader-relative" style="display: block;">
<i class="fa fa-refresh fa-spin-custom"></i> <i class="fa fa-refresh fa-spin-custom"></i>
</div> </div>
......
...@@ -447,9 +447,8 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum ...@@ -447,9 +447,8 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
CommonViewFunction.generateObjectForSaveSearchApi = function(options) { CommonViewFunction.generateObjectForSaveSearchApi = function(options) {
var obj = { var obj = {
name: options.name, name: options.name,
searchParameters: { guid: options.guid,
excludeDeletedEntities: true searchParameters: {}
}
}; };
var value = options.value; var value = options.value;
if (value) { if (value) {
...@@ -470,6 +469,9 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum ...@@ -470,6 +469,9 @@ define(['require', 'utils/Utils', 'modules/Modal', 'utils/Messages', 'utils/Enum
} }
} }
} }
if (k == "includeDE") {
val = _.isUndefinedNull(val) ? true : val;
}
obj.searchParameters[v] = val; obj.searchParameters[v] = val;
}); });
return obj; return obj;
......
...@@ -102,8 +102,10 @@ define(['require', ...@@ -102,8 +102,10 @@ define(['require',
type: null, type: null,
tag: null, tag: null,
attributes: null, attributes: null,
tagFilters: null,
pageOffset: null, pageOffset: null,
pageLimit: null, pageLimit: null,
entityFilters: null,
includeDE: null includeDE: null
} }
}; };
...@@ -119,7 +121,7 @@ define(['require', ...@@ -119,7 +121,7 @@ define(['require',
}, },
renderSaveSearch: function() { renderSaveSearch: function() {
var that = this; var that = this;
require(['views/search/SaveSearchView'], function(SaveSearchView) { require(['views/search/save/SaveSearchView'], function(SaveSearchView) {
var saveSearchBaiscCollection = new VSearchList(), var saveSearchBaiscCollection = new VSearchList(),
saveSearchAdvanceCollection = new VSearchList(), saveSearchAdvanceCollection = new VSearchList(),
saveSearchCollection = new VSearchList(); saveSearchCollection = new VSearchList();
...@@ -137,6 +139,7 @@ define(['require', ...@@ -137,6 +139,7 @@ define(['require',
tagObj = that.searchTableFilters['tagFilters'], tagObj = that.searchTableFilters['tagFilters'],
urlObj = Utils.getUrlState.getQueryParams(); urlObj = Utils.getUrlState.getQueryParams();
if (urlObj) { if (urlObj) {
// includeDE value in because we need to send "true","false" to the server.
if (urlObj.includeDE == "true") { if (urlObj.includeDE == "true") {
urlObj.includeDE = true; urlObj.includeDE = true;
} else { } else {
...@@ -329,8 +332,10 @@ define(['require', ...@@ -329,8 +332,10 @@ define(['require',
type: null, type: null,
tag: null, tag: null,
attributes: null, attributes: null,
tagFilters: null,
pageOffset: null, pageOffset: null,
pageLimit: null, pageLimit: null,
entityFilters: null,
includeDE: null includeDE: null
}), param); }), param);
}, },
...@@ -439,6 +444,7 @@ define(['require', ...@@ -439,6 +444,7 @@ define(['require',
this.value = paramObj; this.value = paramObj;
} }
if (this.value) { if (this.value) {
this.ui.searchInput.val(this.value.query || "");
if (this.value.dslChecked == "true") { if (this.value.dslChecked == "true") {
if (!this.ui.searchType.prop("checked")) { if (!this.ui.searchType.prop("checked")) {
this.ui.searchType.prop("checked", true).trigger("change"); this.ui.searchType.prop("checked", true).trigger("change");
...@@ -470,7 +476,6 @@ define(['require', ...@@ -470,7 +476,6 @@ define(['require',
} }
} }
} }
this.ui.searchInput.val(this.value.query || "");
setTimeout(function() { setTimeout(function() {
that.ui.searchInput.focus(); that.ui.searchInput.focus();
}, 0); }, 0);
...@@ -482,15 +487,11 @@ define(['require', ...@@ -482,15 +487,11 @@ define(['require',
triggerSearch: function(value) { triggerSearch: function(value) {
var params = { var params = {
searchType: this.type, searchType: this.type,
dslChecked: this.ui.searchType.is(':checked'), dslChecked: this.ui.searchType.is(':checked')
tagFilters: null,
entityFilters: null,
attributes: null,
includeDE: null
} }
this.query[this.type].type = this.ui.typeLov.select2('val') || null; params['type'] = this.ui.typeLov.select2('val') || null;
if (!this.dsl) { if (!this.dsl) {
this.query[this.type].tag = this.ui.tagLov.select2('val') || null; params['tag'] = this.ui.tagLov.select2('val') || null;
var entityFilterObj = this.searchTableFilters['entityFilters'], var entityFilterObj = this.searchTableFilters['entityFilters'],
tagFilterObj = this.searchTableFilters['tagFilters']; tagFilterObj = this.searchTableFilters['tagFilters'];
if (this.value.tag) { if (this.value.tag) {
...@@ -503,25 +504,27 @@ define(['require', ...@@ -503,25 +504,27 @@ define(['require',
if (columnList) { if (columnList) {
params['attributes'] = columnList.join(','); params['attributes'] = columnList.join(',');
} }
if (this.value.includeDE) { if (_.isUndefinedNull(this.value.includeDE)) {
params['includeDE'] = false;
} else {
params['includeDE'] = this.value.includeDE; params['includeDE'] = this.value.includeDE;
} }
} }
if (this.value.pageLimit) { if (this.value.pageLimit) {
this.query[this.type].pageLimit = this.value.pageLimit; params['pageLimit'] = this.value.pageLimit;
} }
if (this.value.pageOffset) { if (this.value.pageOffset) {
if (this.query[this.type].query && this.query[this.type].query != value) { if (this.query[this.type].query && this.query[this.type].query != value) {
this.query[this.type].pageOffset = 0; params['pageOffset'] = 0;
} else { } else {
this.query[this.type].pageOffset = this.value.pageOffset; params['pageOffset'] = this.value.pageOffset;
} }
} }
this.query[this.type].query = value || null; params['query'] = value || null;
_.extend(this.query[this.type], params);
Utils.setUrl({ Utils.setUrl({
url: '#!/search/searchResult', url: '#!/search/searchResult',
urlParams: _.extend({}, this.query[this.type], params), urlParams: _.extend({}, this.query[this.type]),
mergeBrowserUrl: false, mergeBrowserUrl: false,
trigger: true, trigger: true,
updateTabState: true updateTabState: true
...@@ -555,10 +558,6 @@ define(['require', ...@@ -555,10 +558,6 @@ define(['require',
this.$('.searchText').text('Search By Text'); this.$('.searchText').text('Search By Text');
this.ui.searchInput.attr("placeholder", "Search By Text"); this.ui.searchInput.attr("placeholder", "Search By Text");
} }
if (paramObj && this.type == "basic") {
this.query[this.type].attributes = paramObj.attributes ? paramObj.attributes : null;
this.query[this.type].includeDE = this.value.includeDE;
}
if (Utils.getUrlState.isSearchTab()) { if (Utils.getUrlState.isSearchTab()) {
Utils.setUrl({ Utils.setUrl({
url: '#!/search/searchResult', url: '#!/search/searchResult',
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
define(['require', define(['require',
'backbone', 'backbone',
'hbs!tmpl/search/SaveAsLayoutView_tmpl', 'hbs!tmpl/search/save/SaveModalLayoutView_tmpl',
'utils/Utils', 'utils/Utils',
'modules/Modal', 'modules/Modal',
'utils/UrlLinks', 'utils/UrlLinks',
...@@ -26,31 +26,39 @@ define(['require', ...@@ -26,31 +26,39 @@ define(['require',
'models/VSearch', 'models/VSearch',
'utils/CommonViewFunction', 'utils/CommonViewFunction',
'utils/Messages' 'utils/Messages'
], function(require, Backbone, SaveAsLayoutViewTmpl, Utils, Modal, UrlLinks, platform, VSearch, CommonViewFunction, Messages) { ], function(require, Backbone, SaveModalLayoutViewTmpl, Utils, Modal, UrlLinks, platform, VSearch, CommonViewFunction, Messages) {
var SaveAsLayoutView = Backbone.Marionette.LayoutView.extend({ var SaveModalLayoutView = Backbone.Marionette.LayoutView.extend({
_viewName: 'SaveAsLayoutView', _viewName: 'SaveModalLayoutView',
template: SaveAsLayoutViewTmpl, template: SaveModalLayoutViewTmpl,
regions: {}, regions: {},
ui: { ui: {
saveAsName: "[data-id='saveAsName']" saveAsName: "[data-id='saveAsName']"
}, },
templateHelpers: function() {
return {
selectedModel: this.selectedModel ? this.selectedModel.toJSON() : null
};
},
events: function() { events: function() {
var events = {}; var events = {};
return events; return events;
}, },
initialize: function(options) { initialize: function(options) {
var that = this; var that = this;
_.extend(this, _.pick(options, 'value', 'collection', 'searchVent', 'typeHeaders', 'fetchFavioriteCollection', 'getValue', 'isBasic')); _.extend(this, _.pick(options, 'selectedModel', 'collection', 'getValue', 'isBasic', 'saveObj'));
this.model = new VSearch(); this.model = new VSearch();
if (this.saveObj) {
this.onCreateButton();
} else {
var modal = new Modal({ var modal = new Modal({
title: 'Enter your search name', title: (this.selectedModel ? 'Update' : 'Create') + ' your favorite search ' + (this.selectedModel ? 'name' : ''),
content: this, content: this,
cancelText: "Cancel", cancelText: "Cancel",
okCloses: false, okCloses: false,
okText: 'Create', okText: this.selectedModel ? 'Update' : 'Create',
allowCancel: true allowCancel: true
}).open(); }).open();
modal.$el.find('button.ok').attr("disabled", "true"); modal.$el.find('button.ok').attr("disabled", "true");
...@@ -69,29 +77,55 @@ define(['require', ...@@ -69,29 +77,55 @@ define(['require',
modal.on('closeModal', function() { modal.on('closeModal', function() {
modal.trigger('cancel'); modal.trigger('cancel');
}); });
}
}, },
onCreateButton: function(modal) { onCreateButton: function(modal) {
var that = this, var that = this,
obj = { value: this.getValue(), name: this.ui.saveAsName.val() }, obj = { name: this.ui.saveAsName.val ? this.ui.saveAsName.val() : null };
saveObj = CommonViewFunction.generateObjectForSaveSearchApi(obj); if (this.selectedModel) {
// Update Name only.
var saveObj = this.selectedModel.toJSON();
saveObj.name = obj.name;
} else {
obj.value = this.getValue();
if (this.saveObj) {
// Save search Filter
_.extend(obj, this.saveObj);
}
var saveObj = CommonViewFunction.generateObjectForSaveSearchApi(obj);
if (this.isBasic) { if (this.isBasic) {
saveObj['searchType'] = "BASIC"; saveObj['searchType'] = "BASIC";
} else { } else {
saveObj['searchType'] = "ADVANCED"; saveObj['searchType'] = "ADVANCED";
} }
that.model.urlRoot = UrlLinks.saveSearchApiUrl(); }
that.model.save(saveObj, { this.model.urlRoot = UrlLinks.saveSearchApiUrl();
this.model.save(saveObj, {
type: (saveObj.guid ? 'PUT' : 'POST'),
success: function(model, data) { success: function(model, data) {
if (that.collection) { if (that.collection) {
that.collection.add(data); if (saveObj.guid) {
var collectionRef = that.collection.find({ guid: data.guid });
if (collectionRef) {
collectionRef.set(data);
} }
Utils.notifySuccess({ Utils.notifySuccess({
content: obj.name + Messages.editSuccessMessage
});
} else {
that.collection.add(data);
Utils.notifySuccess({
content: obj.name + Messages.addSuccessMessage content: obj.name + Messages.addSuccessMessage
}); });
} }
}
}
}); });
if (modal) {
modal.trigger('cancel'); modal.trigger('cancel');
} }
}
}); });
return SaveAsLayoutView; return SaveModalLayoutView;
}); });
\ No newline at end of file
...@@ -17,15 +17,15 @@ ...@@ -17,15 +17,15 @@
*/ */
define(['require', define(['require',
'backbone', 'backbone',
'hbs!tmpl/search/SaveSearchItemView_tmpl', 'hbs!tmpl/search/save/SaveSearchItemView_tmpl',
'utils/UrlLinks', 'utils/UrlLinks',
'utils/Utils', 'utils/Utils',
'utils/CommonViewFunction', 'utils/CommonViewFunction',
'utils/Messages' 'utils/Messages'
], function(require, Backbone, SaveSearchItemView_tmpl, UrlLinks, Utils, CommonViewFunction, Messages) { ], function(require, Backbone, SaveSearchItemViewTmpl, UrlLinks, Utils, CommonViewFunction, Messages) {
'use strict'; 'use strict';
return Backbone.Marionette.ItemView.extend({ return Backbone.Marionette.ItemView.extend({
template: SaveSearchItemView_tmpl, template: SaveSearchItemViewTmpl,
tagName: 'li', tagName: 'li',
className: 'parent-node', className: 'parent-node',
ui: { ui: {
...@@ -61,6 +61,9 @@ define(['require', ...@@ -61,6 +61,9 @@ define(['require',
this.trigger('item:clicked'); this.trigger('item:clicked');
this.ui.stateChange.parent('li').addClass('active').siblings().removeClass('active'); this.ui.stateChange.parent('li').addClass('active').siblings().removeClass('active');
}, },
modelEvents: {
'change': 'render'
},
showToolTip: function(e) { showToolTip: function(e) {
var that = this; var that = this;
Utils.generatePopover({ Utils.generatePopover({
...@@ -69,7 +72,8 @@ define(['require', ...@@ -69,7 +72,8 @@ define(['require',
popoverOptions: { popoverOptions: {
content: function() { content: function() {
return "<ul class='saveSearchPopoverList'>" + return "<ul class='saveSearchPopoverList'>" +
"<li class='th' ><i class='fa fa-search'></i> <a href='javascript:void(0)' data-fn='onSearch'>Search </a></li>" + "<li class='listTerm' ><i class='fa fa-search'></i> <a href='javascript:void(0)' data-fn='onSearch'>Search </a></li>" +
"<li class='listTerm' ><i class='fa fa-pencil'></i> <a href='javascript:void(0)' data-fn='onRename'>Rename</a></li>" +
"<li class='listTerm' ><i class='fa fa-trash-o'></i> <a href='javascript:void(0)' data-fn='onDelete'>Delete</a></li>" + "<li class='listTerm' ><i class='fa fa-trash-o'></i> <a href='javascript:void(0)' data-fn='onDelete'>Delete</a></li>" +
"</ul>"; "</ul>";
} }
...@@ -95,6 +99,14 @@ define(['require', ...@@ -95,6 +99,14 @@ define(['require',
updateTabState: true updateTabState: true
}); });
}, },
onRename: function() {
var that = this;
require([
'views/search/save/SaveModalLayoutView'
], function(SaveModalLayoutView) {
new SaveModalLayoutView({ 'selectedModel': that.model, 'collection': that.collection, 'getValue': that.getValue, 'isBasic': that.isBasic });
});
},
onDelete: function() { onDelete: function() {
var that = this; var that = this;
var notifyObj = { var notifyObj = {
......
...@@ -18,18 +18,18 @@ ...@@ -18,18 +18,18 @@
define(['require', define(['require',
'backbone', 'backbone',
'hbs!tmpl/search/SaveSearch_tmpl', 'hbs!tmpl/search/save/SaveSearchView_tmpl',
'views/search/SaveSearchItemView', 'views/search/save/SaveSearchItemView',
'collection/VSearchList', 'collection/VSearchList',
'utils/Utils', 'utils/Utils',
'utils/UrlLinks', 'utils/UrlLinks',
'utils/CommonViewFunction', 'utils/CommonViewFunction',
'utils/Messages' 'utils/Messages'
], function(require, Backbone, SaveSearch_Tmpl, SaveSearchItemView, VSearchList, Utils, UrlLinks, CommonViewFunction, Messages) { ], function(require, Backbone, SaveSearchViewTmpl, SaveSearchItemView, VSearchList, Utils, UrlLinks, CommonViewFunction, Messages) {
'use strict'; 'use strict';
return Backbone.Marionette.CompositeView.extend({ return Backbone.Marionette.CompositeView.extend({
template: SaveSearch_Tmpl, template: SaveSearchViewTmpl,
childView: SaveSearchItemView, childView: SaveSearchItemView,
childViewContainer: "[data-id='itemViewContent']", childViewContainer: "[data-id='itemViewContent']",
ui: { ui: {
...@@ -68,23 +68,22 @@ define(['require', ...@@ -68,23 +68,22 @@ define(['require',
this.bindEvents(); this.bindEvents();
}, },
bindEvents: function() { bindEvents: function() {
this.listenTo(this.collection, "reset error", function(model, response) { this.listenTo(this.collection, "add reset error", function(model, collection) {
this.$('.fontLoader-relative').hide(); this.$('.fontLoader-relative').hide();
if (model && model.length) { if (this.collection && this.collection.length) {
this.$("[data-id='itemViewContent']").text(""); this.$(".noFavoriteSearch").hide();
} else { } else {
this.$("[data-id='itemViewContent']").text("You don't have any favorite search.") this.$(".noFavoriteSearch").show();
} }
}, this); }, this);
}, },
saveAs: function(e) { saveAs: function(e) {
var that = this, var value = this.getValue();
value = this.getValue();
if (value && (value.type || value.tag || value.query)) { if (value && (value.type || value.tag || value.query)) {
require([ this.callSaveModalLayoutView({
'views/search/SaveAsLayoutView' 'collection': this.collection,
], function(SaveAsLayoutView) { 'getValue': this.getValue,
new SaveAsLayoutView({ 'value': that.value, 'searchVent': that.searchVent, 'collection': that.collection, 'getValue': that.getValue, 'isBasic': that.isBasic }); 'isBasic': this.isBasic
}); });
} else { } else {
Utils.notifyInfo({ Utils.notifyInfo({
...@@ -99,45 +98,33 @@ define(['require', ...@@ -99,45 +98,33 @@ define(['require',
modal: true, modal: true,
html: true, html: true,
ok: function(argument) { ok: function(argument) {
that.onSaveNotifyOk(obj); that.callSaveModalLayoutView({
'saveObj': obj,
'collection': that.collection,
'getValue': that.getValue,
'isBasic': that.isBasic
})
}, },
cancel: function(argument) {} cancel: function(argument) {}
}, },
selectedEl = this.$('.saveSearchList li.active').find('div.item'); selectedEl = this.$('.saveSearchList li.active').find('div.item');
obj.name = selectedEl.find('a').text(); obj.name = selectedEl.find('a').text();
obj.id = selectedEl.data('id'); obj.guid = selectedEl.data('id');
if (selectedEl && selectedEl.length) { if (selectedEl && selectedEl.length) {
notifyObj['text'] = Messages.search.favoriteSearch.save + " <b>" + obj.name + "</b> ?"; notifyObj['text'] = Messages.search.favoriteSearch.save + " <b>" + obj.name + "</b> ?";
Utils.notifyConfirm(notifyObj); Utils.notifyConfirm(notifyObj);
} else { } else {
Utils.notifyInfo({ Utils.notifyInfo({
content: Messages.search.favoriteSearch.notSelectedElement content: Messages.search.favoriteSearch.notSelectedFavoriteElement
}) })
} }
}, },
onSaveNotifyOk: function(obj) { callSaveModalLayoutView: function(options) {
var that = this require([
if (obj && obj.id) { 'views/search/save/SaveModalLayoutView'
var model = new this.collection.model(); ], function(SaveModalLayoutView) {
obj.value = this.getValue(); new SaveModalLayoutView(options);
var saveObj = CommonViewFunction.generateObjectForSaveSearchApi(obj);
saveObj['guid'] = obj.id;
model.urlRoot = UrlLinks.saveSearchApiUrl();
model.save(saveObj, {
type: 'PUT',
success: function(model, data) {
if (that.collection) {
var collectionRef = that.collection.find({ guid: data.guid });
if (collectionRef) {
collectionRef.set(data);
}
}
Utils.notifySuccess({
content: obj.name + Messages.editSuccessMessage
});
}
}); });
} }
}
}); });
}); });
\ No newline at end of file
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