From 58d2ff58a9a27ce5f4a1f538cadc6432997e41be Mon Sep 17 00:00:00 2001
From: Jaden Diefenbaugh <blakcap@users.noreply.github.com>
Date: Fri, 21 Apr 2017 16:29:40 +0200
Subject: [PATCH] add links to exps in tables

---
 .../reports/app/directives/tableItem.js       | 25 +++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/beat/web/reports/static/reports/app/directives/tableItem.js b/beat/web/reports/static/reports/app/directives/tableItem.js
index 3105eb9e0..20ccdc16a 100644
--- a/beat/web/reports/static/reports/app/directives/tableItem.js
+++ b/beat/web/reports/static/reports/app/directives/tableItem.js
@@ -26,7 +26,7 @@
  * 	displays a table report item
  */
 angular.module('reportApp')
-.directive("tableItem", ['GroupsService', 'ExperimentsService', function(GroupsService, ExperimentsService){
+.directive("tableItem", ['GroupsService', 'ExperimentsService', 'UrlService', function(GroupsService, ExperimentsService, UrlService){
 	return {
 		scope: {
 			group: '=',
@@ -139,6 +139,22 @@ angular.module('reportApp')
 
 				return str;
 			};
+
+			// get experiment url for linking to exps
+			// returns the url if successful else false
+			scope.getExperimentUrl = (expName) => {
+				// if theres more than 2 '/' in the expName,
+				// its the absolute URL, and the user has access
+				// to view the experiment.
+				if(expName.split('/').length > 3){
+					return UrlService.getExperimentUrl(expName);
+				}
+
+				// else, its the short name
+				// (just the exp name, not including author/toolchain)
+				// and the user cant see the exp
+				return false;
+			};
 		},
 		template: `
 <div ng-if='isViewingCsv.val'>
@@ -167,7 +183,12 @@ angular.module('reportApp')
 		<tbody>
 			<tr ng-repeat="exp in group.experiments | orderBy:sortFunc:sortField.isReversed">
 				<td ng-repeat='field in fields'>
-					{{ getFieldVal(exp, field) }}
+					<a ng-if='$index == 0 && getExperimentUrl(exp)' href='{{ getExperimentUrl(exp) }}'>
+						{{ getFieldVal(exp, field) }}
+					</a>
+					<span ng-if='!$index == 0 || !getExperimentUrl(exp)'>
+						{{ getFieldVal(exp, field) }}
+					</span>
 				</td>
 			</tr>
 		</tbody>
-- 
GitLab