Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ui check #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/resources/rebel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">

<classpath>
<dir name="/Users/integer/src/github/yet-another-docker-plugin/target/classes">
</dir>
</classpath>

</application>
4 changes: 4 additions & 0 deletions yet-another-docker-plugin/.rebel-remote.xml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<rebel-remote xmlns="http://www.zeroturnaround.com/rebel/remote">
<id>yet-another-docker-plugin</id>
</rebel-remote>
7 changes: 7 additions & 0 deletions yet-another-docker-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@
<!--</archive>-->
<!--<maskClasses>com.google.common.</maskClasses>-->
</configuration>
<executions>
<execution>
<goals>
<goal>generate-taglib-interface</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package com.github.kostyasha.yad;

import com.cloudbees.plugins.credentials.GlobalCredentialsConfiguration;
import com.github.kostyasha.yad_docker_java.com.github.dockerjava.api.model.Link;
import com.google.common.base.Predicate;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.BulkChange;
import hudson.Extension;
import hudson.Functions;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.ManagementLink;
import hudson.util.FormApply;
import hudson.util.FormValidation;
import jenkins.model.GlobalConfigurationCategory;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.interceptor.RequirePOST;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

import static com.github.kostyasha.yad.utils.BindUtils.joinToStr;
import static com.github.kostyasha.yad.utils.BindUtils.splitAndFilterEmpty;
import static java.util.Objects.isNull;

/**
* @author Kanstantsin Shautsou
*/
@Extension
public class DockerManagementLink extends ManagementLink implements Describable<DockerManagementLink> {

public static final Predicate<GlobalConfigurationCategory> FILTER = input -> input instanceof GlobalCredentialsConfiguration.Category;

@Override
public String getIconFileName() {
return "clipboard.png";
}

@Override
public String getDisplayName() {
return "display name";
}

@Override
public String getUrlName() {
return "yad";
}

@CheckForNull
private List<String> links = Collections.singletonList("sdfsdfsdf");

public DockerManagementLink() {
}

// links
@Nonnull
public List<String> getLinks() {
return isNull(links) ? Collections.EMPTY_LIST : links;
}

public void setLinks(List<String> links) {
this.links = links;
}

public String getLinksString() {
return joinToStr(getLinks());
}

@DataBoundSetter
public void setLinksString(String devicesString) {
setLinks(splitAndFilterEmpty(devicesString));
}


@RequirePOST
@NonNull
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler web method binding
public synchronized HttpResponse doConfigure(@NonNull StaplerRequest req) throws IOException, ServletException,
Descriptor.FormException {
Jenkins jenkins = Jenkins.getActiveInstance();
jenkins.checkPermission(Jenkins.ADMINISTER);
// logically this change starts from Jenkins
BulkChange bc = new BulkChange(jenkins);
try {
boolean result = configure(req, req.getSubmittedForm());
// LOGGER.log(Level.FINE, "credentials configuration saved: " + result);
jenkins.save();
return FormApply
.success(result ? req.getContextPath() + "/manage" : req.getContextPath() + "/" + getUrlName());
} finally {
bc.commit();
}
}

/**
* Performs the configuration.
*
* @param req the request.
* @param json the JSON object.
* @return {@code false} to keep the client in the same config page.
* @throws Descriptor.FormException if something goes wrong.
*/
private boolean configure(StaplerRequest req, JSONObject json) throws Descriptor.FormException {
// for compatibility reasons, the actual value is stored in Jenkins
Jenkins j = Jenkins.getActiveInstance();
j.checkPermission(Jenkins.ADMINISTER);

// persist all the provider configs
boolean result = true;
for (Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfig(FILTER)) {
result &= configureDescriptor(req, json, d);
}

return result;
}

/**
* Performs the configuration of a specific {@link Descriptor}.
*
* @param req the request.
* @param json the JSON object.
* @param d the {@link Descriptor}.
* @return {@code false} to keep the client in the same config page.
* @throws Descriptor.FormException if something goes wrong.
*/
private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor<?> d) throws
Descriptor.FormException {
// collapse the structure to remain backward compatible with the JSON structure before 1.
String name = d.getJsonSafeClassName();
JSONObject js = json.has(name) ? json.getJSONObject(name) : new JSONObject();
// if it doesn't have the property, the method returns invalid null object.
json.putAll(js);
return d.configure(req, js);
}

@SuppressWarnings("unchecked")
@Override
public Descriptor<DockerManagementLink> getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorOrDie(getClass());
}

/**
* Our {@link Descriptor}.
*/
@Extension
public static final class DescriptorImpl extends Descriptor<DockerManagementLink> {
@Override
public String getDisplayName() {
return "display bane";
}

public FormValidation doCheckLinksString(@QueryParameter String linksString) {
final List<String> links = splitAndFilterEmpty(linksString);
for (String linkString : links) {
try {
Link.parse(linkString);
} catch (Exception ex) {
return FormValidation.error("Bad link configuration", ex);
}
}

return FormValidation.ok();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.kostyasha.yad.DockerManagementLink

import com.github.kostyasha.yad.DockerManagementLink
import lib.FormTagLib
import lib.LayoutTagLib
import lib.YadTagLib

def l = namespace(LayoutTagLib)
def st = namespace("jelly:stapler")
def f = namespace(FormTagLib);
def yad = namespace(YadTagLib)

l.layout(permission: app.ADMINISTER) {
l.header(title: my.displayName)
l.main_panel {
h1(my.displayName)
f.entry(title: _("Links")) {
it = new DockerManagementLink()
yad.expandableTextbox(field: "linksString")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.github.kostyasha.yad.DockerSlave

import lib.FormTagLib
import lib.YadTagLib

def f = namespace(FormTagLib);
def yad = namespace(YadTagLib)


f.entry(title: _("Ctest"), field: "containerId") {
f.readOnlyTextbox()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package com.github.kostyasha.yad.commons.DockerCreateContainer

import lib.FormTagLib
import com.github.kostyasha.yad.commons.DockerCreateContainer
import lib.YadTagLib

def f = namespace(FormTagLib);
def yad = namespace(YadTagLib)

if (instance == null) {
instance = new DockerCreateContainer()
}

f.advanced(title: _("Container settings"), align: "left") {
f.advanced(title: _("Create Container settings"), align: "left") {
f.entry(title: _("Docker Command"), field: "command") {
f.textbox()
}
Expand Down Expand Up @@ -83,6 +85,11 @@ f.advanced(title: _("Container settings"), align: "left") {
}

f.entry(title: _("Links"), field: "linksString") {
f.expandableTextbox()
// f.textarea()
yad.expandableTextbox()
//// checkUrl: "${rootURL}/com.github.kostyasha.yad.commons.DockerCreateContainer/checkLinksString?linksString=" +
//// escape('Load rules are mandatory') +
//// ";value='+escape(this.value)"
// )
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core"
xmlns:d="jelly:define"
xmlns:f="/lib/form"
xmlns:st="jelly:stapler"
xmlns:m="jelly:hudson.util.jelly.MorphTagLibrary">
<!--<st:once>-->
<!--<script type="text/javascript" src="${rootURL}/plugin/yet-another-docker/js/yad.js"/>-->
<!--</st:once>-->
<st:adjunct includes="lib.yad.expandableTextbox.expandableTextbox"/>

<f:prepareDatabinding/>
<j:set var="value" value="${attrs.value?:instance[attrs.field]}"/>

<j:choose>
<j:when test="${h.isMultiline(value)}">
<!-- multiline text area to begin with -->
<!--BLd<br/>-->
<!--${attrs}<br/>-->
<!--BLAd<br/>-->
<f:textarea checkUrl="${attrs.checkUrl}" name='${attrs.name}' value="${value}" field="${attrs.field}"/>
</j:when>
<j:otherwise>
<!--BLAAA<br/>-->
<!--${attrs}<br/>-->
<!--BLA<br/>-->
<!-- single line textbox with expand button -->
<table border="0" style="width:100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<j:set var="name" value="${attrs.name ?: '_.'+attrs.field}"/>
<j:set var="default" value="${attrs.default ?: ''}"/>
<!--<m:input class="setting-input"-->
<m:input class="setting-input ${attrs.checkUrl != null ? 'validated':''} ${attrs.clazz}"
type="text"
name="${name}"
value="${value}"
id="textarea.${name}"
ATTRIBUTES="${attrs}" EXCEPT="field clazz"/>
<j:if test="${customizedFields != null and attrs.field != null and value != default}">
<j:mute>${customizedFields.add(name)}</j:mute>
</j:if>
</td>
<td width="1">
<input type="button" value="&#x25BC;" onclick="expandTextAreaYAD(this,'textarea.${name}')"
tooltip="${%tooltip}"/>
</td>
</tr>
<tr class="validation-error-area">
<td colspan="2"/>
<td/>
<td/>
</tr>
</table>
</j:otherwise>
</j:choose>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function expandTextAreaYAD(button, id) {
button.style.display = "none";
var field = button.parentNode.previousSibling.children[0];
var value = field.value.replace(/ +/g, '\n');

var n = button;
while (n.tagName != "TABLE") {
n = n.parentNode;
}

n.parentNode.innerHTML =
"<textarea rows=8 class='setting-input validated' name='" + field.name + "'>" + value + "</textarea>";
layoutUpdateCallback.call();
}
Empty file.
4 changes: 2 additions & 2 deletions yet-another-docker-plugin/src/main/resources/rebel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">

<classpath>
<dir name="/Users/integer/src/github/yet-another-docker-plugin/yet-another-docker-plugin/target/classes">
</dir>
<dir name="/Users/integer/src/github/yet-another-docker-plugin/yet-another-docker-plugin/target/classes"/>
<dir name="/Users/integer/src/github/yet-another-docker-plugin/yet-another-docker-plugin/src/main/resources"/>
</classpath>

</application>
14 changes: 14 additions & 0 deletions yet-another-docker-plugin/src/main/webapp/js/yad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function expandTextArea2(button, id) {
button.style.display = "none";
var field = button.parentNode.previousSibling.children[0];
var value = field.value.replace(/ +/g, '\n');

var n = button;
while (n.tagName != "TABLE") {
n = n.parentNode;
}

n.parentNode.innerHTML =
"<textarea rows=8 class='setting-input validated' name='" + field.name + "'>" + value + "</textarea>";
layoutUpdateCallback.call();
}
Empty file.
Empty file.