in dashboardv3/public/js/views/search/SearchResultLayoutView.js [410:602]
fetchCollection: function(value, options) {
var that = this,
isPostMethod = (this.value && this.value.searchType === "basic"),
isSearchTab = Utils.getUrlState.isSearchTab(),
tagFilters = null,
entityFilters = null;
that.activeEntityCountSelected = 0;
that.updateMultiSelect();
if (isSearchTab) {
tagFilters = CommonViewFunction.attributeFilter.generateAPIObj(this.value.tagFilters);
entityFilters = CommonViewFunction.attributeFilter.generateAPIObj(this.value.entityFilters);
}
if (isPostMethod && isSearchTab) {
var excludeDefaultColumn = ((this.value.type || this.value.tag) && this.searchTableColumns) ? _.difference(this.searchTableColumns[this.value.type || this.value.tag], this.defaultColumns) : null,
filterObj = {
'entityFilters': entityFilters,
'tagFilters': tagFilters,
'attributes': excludeDefaultColumn ? excludeDefaultColumn : null
};
}
this.showLoader();
if (Globals.searchApiCallRef && Globals.searchApiCallRef.readyState === 1) {
Globals.searchApiCallRef.abort();
}
var apiObj = {
skipDefaultError: true,
sort: false,
success: function(dataOrCollection, response) {
if (that.isDestroyed) {
return;
}
Globals.searchApiCallRef = undefined;
var isFirstPage = that.offset === 0,
dataLength = 0,
goToPage = that.ui.gotoPage.val();
that.ui.gotoPage.val('');
that.ui.gotoPage.parent().removeClass('has-error');
that.ui.gotoPagebtn.prop("disabled", true);
if (!(that.ui.pageRecordText instanceof jQuery)) {
return;
}
if (isPostMethod && dataOrCollection && dataOrCollection.entities) {
dataLength = dataOrCollection.entities.length;
} else {
dataLength = dataOrCollection.length;
}
if (!dataLength && that.offset >= that.limit && ((options && options.next) || goToPage) && (options && !options.fromUrl)) {
/* User clicks on next button and server returns
empty response then disabled the next button without rendering table*/
that.hideLoader();
var pageNumber = that.activePage + 1;
if (goToPage) {
pageNumber = goToPage;
that.offset = (that.activePage - 1) * that.limit;
} else {
that.finalPage = that.activePage;
that.ui.nextData.attr('disabled', true);
that.offset = that.offset - that.limit;
}
if (that.value) {
that.value.pageOffset = that.offset;
that.triggerUrl();
}
Utils.notifyInfo({
html: true,
content: Messages.search.noRecordForPage + '<b>' + Utils.getNumberSuffix({ number: pageNumber, sup: true }) + '</b> page'
});
return;
}
if (isPostMethod) {
Utils.findAndMergeRefEntity({
attributeObject: dataOrCollection.entities,
referredEntities: dataOrCollection.referredEntities
});
that.searchCollection.reset(dataOrCollection.entities, { silent: true });
that.searchCollection.fullCollection.reset(dataOrCollection.entities, { silent: true });
}
/*Next button check.
It's outside of Previous button else condition
because when user comes from 2 page to 1 page than we need to check next button.*/
if (dataLength < that.limit) {
that.ui.nextData.attr('disabled', true);
} else {
that.ui.nextData.attr('disabled', false);
}
if (isFirstPage && (!dataLength || dataLength < that.limit)) {
that.ui.paginationDiv.hide();
} else {
that.ui.paginationDiv.show();
}
// Previous button check.
if (isFirstPage) {
that.ui.previousData.attr('disabled', true);
that.pageFrom = 1;
that.pageTo = that.limit;
} else {
that.ui.previousData.attr('disabled', false);
}
if (options && options.next) {
//on next click, adding "1" for showing the another records.
that.pageTo = that.offset + that.limit;
that.pageFrom = that.offset + 1;
} else if (!isFirstPage && options && options.previous) {
that.pageTo = that.pageTo - that.limit;
that.pageFrom = (that.pageTo - that.limit) + 1;
}
that.ui.pageRecordText.html("Showing <u>" + that.searchCollection.models.length + " records</u> From " + that.pageFrom + " - " + that.pageTo);
that.activePage = Math.round(that.pageTo / that.limit);
that.ui.activePage.attr('title', "Page " + that.activePage);
that.ui.activePage.text(that.activePage);
that.renderTableLayoutView();
that.multiSelectEntity = [];
if (dataLength > 0) {
that.$('.searchTable').removeClass('noData')
}
if (Utils.getUrlState.isSearchTab() && value && !that.profileDBView) {
// var searchString = 'Results for: <span class="filterQuery">' + CommonViewFunction.generateQueryOfFilter(that.value, true) + "</span>";
var isCapsuleView = true;
var searchString = '<span class="filterQuery">' + CommonViewFunction.generateQueryOfFilter(that.value, isCapsuleView) + "</span>";
if (Globals.entityCreate && Globals.entityTypeConfList && Utils.getUrlState.isSearchTab()) {
// searchString += "<p>If you do not find the entity in search result below then you can" + '<a href="javascript:void(0)" data-id="createEntity"> create new entity</a></p>';
}
that.$('.searchResult').html(searchString);
}
if (dataOrCollection.approximateCount || dataOrCollection.length) {
that.ui.downloadResults.show();
} else {
that.ui.downloadResults.hide();
}
},
silent: true,
reset: true
}
if (this.value) {
var checkBoxValue = {
'excludeDeletedEntities': (this.value.includeDE ? false : true),
'includeSubClassifications': (this.value.excludeSC ? false : true),
'includeSubTypes': (this.value.excludeST ? false : true),
'includeClassificationAttributes': true // server will return classication details with guid
}
}
if (value) {
if (value.searchType) {
this.searchCollection.url = UrlLinks.searchApiUrl(value.searchType);
}
_.extend(this.searchCollection.queryParams, { 'limit': this.limit, 'offset': this.offset, 'query': _.trim(value.query), 'typeName': value.type || null, 'classification': value.tag || null, 'termName': value.term || null });
if (this.profileDBView && value.typeName && value.guid) {
var profileParam = {};
profileParam['guid'] = value.guid;
profileParam['relation'] = value.typeName === 'hive_db' ? '__hive_table.db' : '__hbase_table.namespace';
profileParam['sortBy'] = 'name';
profileParam['sortOrder'] = 'ASCENDING';
_.extend(this.searchCollection.queryParams, profileParam);
}
if (isPostMethod) {
this.searchCollection.filterObj = _.extend({}, filterObj);
apiObj['data'] = _.extend(checkBoxValue, filterObj, _.pick(this.searchCollection.queryParams, 'query', 'excludeDeletedEntities', 'limit', 'offset', 'typeName', 'classification', 'termName'));
Globals.searchApiCallRef = this.searchCollection.getBasicRearchResult(apiObj);
} else {
apiObj.data = null;
this.searchCollection.filterObj = null;
if (this.profileDBView) {
_.extend(this.searchCollection.queryParams, checkBoxValue);
}
Globals.searchApiCallRef = this.searchCollection.fetch(apiObj);
}
} else {
_.extend(this.searchCollection.queryParams, { 'limit': this.limit, 'offset': this.offset });
if (isPostMethod) {
apiObj['data'] = _.extend(checkBoxValue, filterObj, _.pick(this.searchCollection.queryParams, 'query', 'excludeDeletedEntities', 'limit', 'offset', 'typeName', 'classification', 'termName'));
Globals.searchApiCallRef = this.searchCollection.getBasicRearchResult(apiObj);
} else {
apiObj.data = null;
if (this.profileDBView) {
_.extend(this.searchCollection.queryParams, checkBoxValue);
}
Globals.searchApiCallRef = this.searchCollection.fetch(apiObj);
}
}
this.downloadSearchResultsParams.searchParameters = apiObj.data;
this.generateBusinessMetadataAttrList();
},