support custom nuget.exe selection
authorEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 16 Aug 2011 22:10:01 +0000 (02:10 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 16 Aug 2011 22:10:01 +0000 (02:10 +0400)
nuget-server/resources/tool/runnerSettings.jsp
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/ui/ToolSelectorController.java

index 6d37cdfbce990058cef11a5ec1fcb99115e2192d..bca899749e2e15743bbe87ad89703a0ebde451d9 100644 (file)
 <jsp:useBean id="clazz" scope="request" type="java.lang.String"/>\r
 <jsp:useBean id="style" scope="request" type="java.lang.String"/>\r
 <jsp:useBean id="value" scope="request" type="java.lang.String"/>\r
+<jsp:useBean id="customValue" scope="request" type="java.lang.String"/>\r
 <jsp:useBean id="settingsUrl" scope="request" type="java.lang.String"/>\r
 <jsp:useBean id="items" scope="request" type="java.util.Collection<jetbrains.buildServer.nuget.server.toolRegistry.ui.ToolInfo >"/>\r
 \r
-<props:selectProperty name="${name}" className="${clazz}" style="${style}">\r
+<props:hiddenProperty name="${name}" value="${value}"/>\r
+\r
+<props:selectProperty name="nugetPathSelector" className="${clazz}" style="${style}" onchange="BS.NuGet.RunnerSettings.selectionChanged();">\r
   <c:set var="isSelected" value="${value eq ''}"/>\r
   <props:option value="" selected="${isSelected}">-- Select NuGet version to run --</props:option>\r
+\r
   <c:set var="hasSelected" value="${isSelected}"/>\r
   <c:forEach var="it" items="${items}">\r
     <c:set var="isSelected" value="${it.id eq value}"/>\r
     <props:option value="${it.id}" selected="${isSelected}"><c:out value="${it.version}"/></props:option>\r
     <c:if test="${isSelected}"><c:set var="hasSelected" value="${true}"/></c:if>\r
   </c:forEach>\r
-  <c:if test="${not hasSelected}">\r
-    <props:option value="${value}" selected="${true}">Custom: <c:out value="${value}"/></props:option>\r
-  </c:if>\r
+  <props:option value="custom" selected="${not hasSelected}">Custom</props:option>\r
 </props:selectProperty>\r
 <span class="smallNote">Specify NuGet.exe version.\r
   Check intalled NuGet Commandline tools in <a href="<c:url value="${settingsUrl}"/>">NuGet Settings</a>\r
 </span>\r
+\r
+<div id="customPathContainer">\r
+  <props:textProperty name="nugetCustomPath" className="${clazz}" style="${style}" onchange="BS.NuGet.RunnerSettings.customPathChanged();"/>\r
+  <span class="smallNote">Specify custom path to NuGet.exe</span>\r
+</div>\r
 <span class="error" id="error_${name}"></span>\r
+\r
+<script type="text/javascript">\r
+  if (!BS) BS = {};\r
+  if (!BS.NuGet) BS.NuGet = {};\r
+  BS.NuGet.RunnerSettings = {\r
+    isPackage : function(x) {\r
+      return x.length > 0 && x.charAt(0) == '?';\r
+    },\r
+\r
+    setValue : function(x) {\r
+      $('${name}').value = x;\r
+    },\r
+\r
+    getValue : function() {\r
+      return $('${name}').value;\r
+    },\r
+\r
+    selectionChanged : function() {\r
+      var selected = $('nugetPathSelector').value;\r
+      if (this.isPackage(selected)) {\r
+        this.setValue(selected);\r
+        BS.Util.hide($('customPathContainer'));\r
+      } else if(selected == "custom") {\r
+        var val = this.getValue();\r
+        $('nugetCustomPath').value = this.isPackage(val) ? "<bs:forJs>${customValue}</bs:forJs>" : val;\r
+        this.customPathChanged();\r
+        BS.Util.show($('customPathContainer'));\r
+      } else {\r
+        this.setValue("");\r
+      }\r
+      BS.MultilineProperties.updateVisible();\r
+    },\r
+    customPathChanged : function() {\r
+      $('${name}').value = $('nugetCustomPath').value;\r
+    }\r
+  };\r
+\r
+  BS.NuGet.RunnerSettings.selectionChanged();\r
+</script>\r
index 3627b16a4d2e23c337c671903f9920bfab0b01b7..def62d1541fc068a56be38f7a99708b31416e238 100644 (file)
@@ -59,7 +59,7 @@ public class ToolSelectorController extends BaseController {
   @Override\r
   protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {\r
     final String name = safe(request.getParameter("name"));\r
-    String value = parseValue(request, name);\r
+    String value = parseValue(request, "value", name);\r
     final Collection<ToolInfo> tools = getTools();\r
     ensureVersion(value, tools);\r
 \r
@@ -67,6 +67,7 @@ public class ToolSelectorController extends BaseController {
     ModelAndView mv = new ModelAndView(myDescriptor.getPluginResourcesPath("tool/runnerSettings.jsp"));\r
     mv.getModel().put("name", name);\r
     mv.getModel().put("value", value);\r
+    mv.getModel().put("customValue", safe(parseValue(request, "customValue", "nugetCustomPath")));\r
     mv.getModel().put("clazz", safe(request.getParameter("class")));\r
     mv.getModel().put("style", safe(request.getParameter("style")));\r
     mv.getModel().put("items", tools);\r
@@ -97,15 +98,15 @@ public class ToolSelectorController extends BaseController {
   }\r
 \r
   @NotNull\r
-  private String parseValue(HttpServletRequest request, String name) {\r
+  private String parseValue(HttpServletRequest request, final String requestName, String propertyName) {\r
     String value = null;\r
 \r
     final BasePropertiesBean bean = (BasePropertiesBean)request.getAttribute("propertiesBean");\r
     if (bean != null) {\r
-      value = bean.getProperties().get(name);\r
+      value = bean.getProperties().get(propertyName);\r
     }\r
     if (value == null) {\r
-      value = request.getParameter("value");\r
+      value = request.getParameter(requestName);\r
     }\r
     if (value == null) {\r
       value = "";\r