Skip to content

Commit

Permalink
added search for dataset list page
Browse files Browse the repository at this point in the history
  • Loading branch information
datasetutil committed Oct 3, 2016
1 parent 2d15f14 commit e8ef3a2
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>Analytics Cloud Datatset Utils</description>
<artifactId>datasetutils</artifactId>
<packaging>jar</packaging>
<version>37.0.3-SNAPSHOT</version>
<version>37.0.4-SNAPSHOT</version>
<url>https://github.com/forcedotcom/Analytics-Cloud-Dataset-Utils</url>
<organization>
<name>salesforce.com</name>
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/sforce/dataset/server/ListServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,13 @@ else if(value.equalsIgnoreCase("dataflowCopy"))
{
current = true;
}
List<DatasetType> datasets = DatasetUtils.listDatasets(conn, current);
String search = null;
tmp = request.getParameter("search");
if(tmp!=null && !tmp.trim().isEmpty() && !tmp.equalsIgnoreCase("null"))
{
search = tmp;
}
List<DatasetType> datasets = DatasetUtils.listDatasets(conn, current, search);
DatasetType def = new DatasetType();
def.name = "";
def._alias = "";
Expand All @@ -287,7 +293,13 @@ else if(value.equalsIgnoreCase("dataflowCopy"))
{
current = true;
}
List<DatasetType> datasets = DatasetUtils.listDatasets(conn, current);
String search = null;
tmp = request.getParameter("search");
if(tmp!=null && !tmp.trim().isEmpty() && !tmp.equalsIgnoreCase("null"))
{
search = tmp;
}
List<DatasetType> datasets = DatasetUtils.listDatasets(conn, current, search);
response.setContentType("application/json");
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(response.getOutputStream(), datasets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class DatasetAugmenter {
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void augmentEM(PartnerConnection partnerConnection) throws Exception
{
List<DatasetType> list = DatasetUtils.listDatasets(partnerConnection, true);
List<DatasetType> list = DatasetUtils.listDatasets(partnerConnection, true, null);
System.out.println("\n");
if(list==null || list.size()==0)
{
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/sforce/dataset/util/DatasetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static boolean deleteDataset(String alias, String datasetId,PartnerConnec
{
if(datasetId==null || datasetId.trim().isEmpty())
{
List<DatasetType> temp = listDatasets(partnerConnection, false);
List<DatasetType> temp = listDatasets(partnerConnection, false, alias);
for(DatasetType t:temp)
{
if(t._alias.equals(alias))
Expand Down Expand Up @@ -211,7 +211,7 @@ public static Map<String,Map> listPublicDataset(PartnerConnection connection, bo
{
GetUserInfoResult userInfo = connection.getUserInfo();
String userID = userInfo.getUserId();
Map<String, Map> dataSetMap = listDataset(connection, isCurrent);
Map<String, Map> dataSetMap = listDataset(connection, isCurrent, null);
if(dataSetMap==null || dataSetMap.size()==0)
{
return dataSetMap;
Expand Down Expand Up @@ -245,7 +245,7 @@ public static Map<String,Map> listPublicDataset(PartnerConnection connection, bo
* @throws IOException Signals that an I/O exception has occurred.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Map<String,Map> listDataset(PartnerConnection partnerConnection, boolean isCurrent) throws ConnectionException, URISyntaxException, ClientProtocolException, IOException {
private static Map<String,Map> listDataset(PartnerConnection partnerConnection, boolean isCurrent, String search) throws ConnectionException, URISyntaxException, ClientProtocolException, IOException {
LinkedHashMap<String,Map> dataSetMap = new LinkedHashMap<String,Map>();
// partnerConnection.getServerTimestamp();
ConnectorConfig config = partnerConnection.getConfig();
Expand All @@ -257,8 +257,12 @@ private static Map<String,Map> listDataset(PartnerConnection partnerConnection,


URI u = new URI(serviceEndPoint);

URI listEMURI = new URI(u.getScheme(),u.getUserInfo(), u.getHost(), u.getPort(), "/insights/internal_api/v1.0/esObject/edgemart", "current="+isCurrent+"&sortOrder=Mru",null);
URI listEMURI;
if(search==null||search.trim().isEmpty() || search.trim().equalsIgnoreCase("null"))
listEMURI = new URI(u.getScheme(),u.getUserInfo(), u.getHost(), u.getPort(), "/insights/internal_api/v1.0/esObject/edgemart", "current="+isCurrent+"&sortOrder=Mru",null);
else
listEMURI = new URI(u.getScheme(),u.getUserInfo(), u.getHost(), u.getPort(), "/insights/internal_api/v1.0/esObject/edgemart", "current="+isCurrent+"&sortOrder=Mru"+"&search="+search,null);

HttpGet listEMPost = new HttpGet(listEMURI);

listEMPost.setConfig(requestConfig);
Expand Down Expand Up @@ -307,11 +311,11 @@ private static Map<String,Map> listDataset(PartnerConnection partnerConnection,
* @throws IOException Signals that an I/O exception has occurred.
*/
@SuppressWarnings("rawtypes")
public static List<DatasetType> listDatasets(PartnerConnection connection, boolean isCurrent) throws ClientProtocolException, ConnectionException, URISyntaxException, IOException
public static List<DatasetType> listDatasets(PartnerConnection connection, boolean isCurrent, String search) throws ClientProtocolException, ConnectionException, URISyntaxException, IOException
{
List<DatasetType> datasetList = new LinkedList<DatasetType>();
List<FolderType> apps = listFolders(connection);
Map<String, Map> dataSetMap = listDataset(connection, isCurrent);
Map<String, Map> dataSetMap = listDataset(connection, isCurrent, search);
if(dataSetMap != null && !dataSetMap.isEmpty())
{
for(String alias:dataSetMap.keySet())
Expand Down
17 changes: 15 additions & 2 deletions src/main/webapp/finder.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,20 @@
</div>

<div id="navbar-collapse1" class="collapse navbar-collapse">

<ul class="nav navbar-nav navbar-right">
<li>
<div class="navbar-form">
<!--form class="navbar-form" role="search" action="none"-->
<div class="input-group">
<input id="searchinput" type="text" class="form-control" placeholder="Search..." name="searchinput">
<div class="input-group-btn">
<button id="searchbtn" class="btn btn-default" name="searchbtn"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
<!--/form-->
</div>
</li>
<li>
<a data-toggle="dropdown" class="dropdown-toggle" href="#" style="color: white;"><i style="font-size:1.5em;" class="glyphicon glyphicon-th-list"></i></a>
<ul class="dropdown-menu">
Expand All @@ -68,8 +81,8 @@

<div class="container-fluid">
<div id="header" class="row">
<div class="col-md-11"></div>
<div id="header-count" class="col-md-1 label label-primary text-right">&nbsp;</div>
<div class="col-md-10"></div>
<div class="col-md-2 label label-primary text-right"><h5 id="header-count">&nbsp;</h5></div>
</div>
</div>

Expand Down
37 changes: 31 additions & 6 deletions src/main/webapp/js/finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $(document).ready(function() {
var currentData = null;
var gettingHistory = false;

var current = decodeURIComponent(urlParam('current'));
current = decodeURIComponent(urlParam('current'));

if (current == undefined || isEmpty(current) )
{
Expand All @@ -15,16 +15,41 @@ $(document).ready(function() {
else
current = false;
}

listDatasets(null);

listDatasets(current);
$('button[name=searchbtn]').click(searchDatasets);

$('#searchinput').keypress(function (e) {
if (e.which == 13) {
$('button[name=searchbtn]').click();
return false;
}
});

});

function searchDatasets(event){
query = $("#searchinput").val();
if(isEmpty(query))
{
listDatasets(null);
}else
{
listDatasets(query);
}
}

function listDatasets(current){
$.getJSON('list?type=datasetAndApps&current='+current,{},function(data){
function listDatasets(query){
$.getJSON('list?type=datasetAndApps&current='+current+'&search='+query,{},function(data){
if (typeof data !== 'undefined' && data.length > 0) {
$("#header-count").text('Dataset Count: '+data.length);
if(data.length == 500)
{
$("#header-count").text('Dataset Count: '+data.length + ' out of 500+');
}else
{
$("#header-count").text('Dataset Count: '+data.length);
}
printTable(data);
}else
{
Expand All @@ -40,7 +65,7 @@ function listDatasets(current){
self.location.href = 'login.html';
}else
{
handleError($("#title2").get(0),jqXHR.responseText);
handleError($("#title2").get(0),jqXHR.responseText);
}
});
}
Expand Down

0 comments on commit e8ef3a2

Please sign in to comment.