Reviewer Results

View live sample

Description

ArcGIS Data Reviewer stores features and rows as results in a Reviewer workspace. Results represent a feature or row that has been marked as an anomaly by validation or manual inspection.

ReviewerResultsTask has functions that retrieve no-spatial feature sets of these results. ReviewerResultsTask differs from DashboardTask in that DashboardTask retrieves aggregate information about data quality from a Reviewer workspace.

This sample uses the getResults function to return a feature set of Reviewer results. A callback function defined in a deferred object receives the results.

The live sample retrieves Reviewer results from a hosted instance of Data Reviewer for Server. The following code sample fetches Reviewer results from a local instance of Data Reviewer for Server. You must specify the URL of your own Data Reviewer for Server and relative paths to your local copies of drs.js, style.css, and proxy.ashx.

NoteNote:

The Data Reviewer API for JavaScript 3.4 or later requires a proxy page to support POST requests and ArcGIS token-based authentication.

Code

The following code sample requests Reviewer results from Data Reviewer for Server.

<!DOCTYPE html>
<!--
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011-2015 Esri
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this software, with or without
// modification, provided you include the original copyright and use
// restrictions. See use restrictions in the file use_restrictions.txt.
//
////////////////////////////////////////////////////////////////////////////////
-->
<html>
   <head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.13/dijit/themes/claro/claro.css">
	<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.13/dojox/grid/resources/claroGrid.css">
	<link rel="stylesheet" type="text/css" href="../style.css"/>

	<title>DRS Reviewer Results reviewerResults.getResults Sample</title>
	<!-- configure dojo -->
	<script>
	 dojoConfig = {
		async : true
	 };
	</script>      

	<!--  load esri api and dojo -->
	<script src="http://js.arcgis.com/3.13/"></script>
	<!--  load drs api -->
	<script src="../drs_js_api/drs.js"></script>
	
	<script>  
	//This should point to the Data Reviewer soe
	var drsSoeUrl = "http://datareviewer.arcgisonline.com/arcgis/rest/services/Samples/reviewerDashboard/MapServer/exts/DataReviewerServer";
	//array of return fields
	var returnFields = [];
	//Records per page
	var recordsPerPage;
	
	require(
	[
	 "dojo/parser",
	 "dojo/dom",
	 "dojo/on",
	 "dojo/_base/array",
	 "dojo/data/ItemFileReadStore",
	 "dojox/grid/DataGrid", 
	 "dijit/form/MultiSelect",
	 "drs/ReviewerResultsTask",
	 "drs/GetResultsQueryParameters",
	 "dijit/registry",
	 "dojo/domReady!"
	], 
	function(parser, dom, on, array, ItemFileReadStore, DataGrid, MultiSelect, ReviewerResultsTask, GetResultsQueryParameters,registry) {

		parser.parse();
		//identify proxy page to use
        esri.config.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx"; 
        esri.config.defaults.io.alwaysUseProxy = false;

		//RevTableFields object. 
		//Add any custom fields if required
		revTableFields =  [
		{ field:'recordId',			name:'Record Id' },
		{ field:'objectId',			name:'Object Id' },
		{ field:'category',			name:'Category' },
		{ field:'sessionId',		name:'Session Id' },
		{ field:'checktitle',		name:'Checktitle' },
		{ field:'resourceName',		name:'Resource Name' },
		{ field:'subtype',			name:'Subtype' },
		{ field:'checkName',		name:'Check Name' },
		{ field:'notes',			name:'Notes' },
		{ field:'severity',			name:'Severity' },
		{ field:'reviewStatus',		name:'Review Status' },
		{ field:'reviewTechnician',	name:'Review Technician' },
		{ field:'reviewDateUtc',	name:'Review Date Utc' },
		{ field:'lifecycleStatus',	name:'Life Cycle Status' }];

		//Populate field names to be returned by Get Results operation
		array.forEach(revTableFields, function(field, i) {
			dom.byId("fieldNamesCombo")[i] = new Option(field.name, i);
		});
		//Click event of previousButton button
		on(dom.byId("previousButton"), "click", loadPreviousPage);
		//Click event of nextButton button
		on(dom.byId("nextButton"), "click", loadNextPage);
		//Click even of getResultsButton button
		on(dom.byId("getResultsButton"), "click", populateDataGrid);

		function populateDataGrid() {
			// Get the number of records per page
			recordsPerPage = parseInt(dom.byId("RecordsPerPage").value);
			//Get Selected fields from the list box
			var selectItem = registry.byId('fieldNamesCombo').getSelected()

			if(isNaN(recordsPerPage) || recordsPerPage < 1) 
			{
			   alert("Please fill out records per page.");
			   return;
			}
			if(recordsPerPage>1000)
			{
			  alert("Records per page can not be greater than 1000.");
			  return;
			}
			if(selectItem.length < 1)
			{
				alert("Please select return fields.");
				return;
			}
			//Generate grid layout and returnFields based on fields selected in the list box
			var layout = [];
			returnFields = [];
			array.forEach(selectItem, function(option) {
				var selectedIndex =  option.value;
				layout.push(revTableFields[selectedIndex]);	
                returnFields.push(revTableFields[selectedIndex].field)
			});
			//set default page number for the grid
			dom.byId('lblPageNumber').innerHTML=1
			//show the grid with a loading message and populate it
			loadDataInGrid("",layout);
		}
	 
		function loadDataInGrid(moveType,layout) {
			showGrid(true, 'loading');
			// create ReviewerResultsTask instance 
			var reviewerResultsTask = new ReviewerResultsTask(drsSoeUrl);
			var queryParameters=GetQueryParameters(moveType);
			// call getResults to retrieve the results stored in the reviewer workspace.
			var deferred = reviewerResultsTask.getResults(queryParameters);            
			// we're using dojo deferred 'then' function to set callback and errback functions
			deferred.then(function(response) {
				// map attributes from features to items array to populate dataGrid
				var items = array.map(response.featureSet.features, function(feature) {
				return feature.attributes;
				});
				// create a dojo ReadStore
				var store = new ItemFileReadStore({
				  data : {
					 items : items
				  }
				});
				// set the store in the DataGrid, this will populate the datagrid with the reviewer results
				reviewerResultsGrid.setStore(store);
				reviewerResultsGrid.setStructure(layout);
				//update current page number label
				if(moveType == "previous" && (parseInt(dom.byId('lblPageNumber').innerHTML) > 1))
				{
					dom.byId('lblPageNumber').innerHTML =  parseInt(dom.byId('lblPageNumber').innerHTML) - 1;
				}
				else if(moveType == "next")
				{
					dom.byId('lblPageNumber').innerHTML =  parseInt(dom.byId('lblPageNumber').innerHTML) + 1;
				}
			}, function(err) {
			   if(moveType == "next" && (err.message.indexOf("No results returned for specified query:") == 0))
			   {
					showGrid(true);
					alert("You are already at the last page.");	
			   }
			   else
			   {
			   		showGrid(false);
			   		reviewerResultsGrid.setStore(null);
			   		alert("Error retrieving reviewer results: " + err.message);
			   }
			   return;
			});
		}
		function GetQueryParameters(moveType){
			var queryParameters = new GetResultsQueryParameters();
			queryParameters.pageSize = recordsPerPage;
			if(moveType == "previous" && (parseInt(dom.byId('lblPageNumber').innerHTML) > 1))
			{
				queryParameters.pageNumber = parseInt(dom.byId('lblPageNumber').innerHTML) - 2;
			}
			else if(moveType == "next")
			{
				queryParameters.pageNumber = parseInt(dom.byId('lblPageNumber').innerHTML);
			}
			else
			{
				queryParameters.pageNumber = 0;
			}
			queryParameters.returnFields = returnFields;
			return queryParameters;
		}
		//load next page
		function loadNextPage() {
			loadDataInGrid("next","");	   		   		
		}	
			
		//load previous page
		function loadPreviousPage() 
		{
			if(parseInt(dom.byId('lblPageNumber').innerHTML) == 1)
			{
				alert("You are already at the first page.");
				return;
			}
			else
			{
				loadDataInGrid("previous", "");	
			}
		}
		
		//handle grid visibility
		function showGrid(show,message) {
			 reviewerResultsGrid.showMessage(message || "");
			 dom.byId('gridDiv').style.visibility = show ? "visible" : "hidden";
		}    
	});

	</script>
   
	</head>
	<body class="claro">
		<!--[if IE]>
		<div id="IEroot">
		<![endif]-->
		 <h2 align="center">Get Reviewer Results with Paging Sample</h2>
		<div style="width:100%; overflow-x: auto;" >
			<div style="padding: 0px 20px 0px 20px; float:left;">
				<div class="reviewerForm" >
					<label for="RecordsPerPage">Records per page:</label>
					<input type="number" id="RecordsPerPage" placeholder="valid values are from 1 to 1000"/>
					<label for="fieldNamesCombo">Return fields:</label>
					 <select class ="reviewerMultiSelect" id="fieldNamesCombo" data-dojo-type="dijit/form/MultiSelect"></select>
					
					<label for="getResultsButton"></label>
					<button id="getResultsButton" class="submitButton">Get Results</button>
				</div>
			 </div>
		</div>
		<div id = "gridDiv" style="width: 100%; overflow-x: auto;visibility: hidden" class="reviewerGrid">
			<button id="previousButton"> &lt; </button>
			<label id = "lblPageNumber" >1</label>
			<button id="nextButton"> &gt; </button>	
			<table data-dojo-id="reviewerResultsGrid" data-dojo-type="dojox/grid/DataGrid" autoheight="true" autowidth="true"></table>	 
		</div>
		<!--[if IE]>
		</div>
		<![endif]-->
	</body>
</html>

5/7/2015