@IsAllowed(Operation.UPDATE) public static Result labelsForm(String ownerName, String projectName) { Project project = Project.findByOwnerAndProjectName(ownerName, projectName); List<IssueLabel> labels = IssueLabel.findByProject(project); return ok(views.html.project.issuelabels.render(project, labels)); }
private static Result labelsAsPjax(String ownerName, String projectName) { response().setHeader("Cache-Control", "no-cache, no-store"); Project project = Project.findByOwnerAndProjectName(ownerName, projectName); List<IssueLabel> labels = IssueLabel.findByProject(project); return ok(views.html.project.partial_issuelabels_list.render(project, labels)); }
/** * Responds to a request for the CSS styles of all issue labels in the specified project. * * <p>This method is used when CSS styles of issue labels are required in any page which uses * issue label. * * @param ownerName the name of a project owner * @param projectName the name of a project * @return the response to the request for the css styles in text/css. */ @IsAllowed(Operation.READ) public static Result labelStyles(String ownerName, String projectName) { Project project = Project.findByOwnerAndProjectName(ownerName, projectName); List<IssueLabel> labels = IssueLabel.findByProject(project); String eTag = "\"" + labels.hashCode() + "\""; String ifNoneMatchValue = request().getHeader("If-None-Match"); if (ifNoneMatchValue != null && ifNoneMatchValue.equals(eTag)) { response().setHeader("ETag", eTag); return status(NOT_MODIFIED); } response().setHeader("ETag", eTag); return ok(views.html.common.issueLabelColor.render(labels)).as("text/css"); }
/** * Retrieves a project corresponding to {@code ownerName} and {@code projectName}, and returns its * list of all issue labels in {@code application/json}. Each label has four fields: {@link * IssueLabel#id}, {@link IssueLabel#category}, {@link IssueLabel#color}, and {@link * IssueLabel#name}. * * <p>Returns 406 Not Acceptable if the client cannot accept {@code application/json}. Success * response can only be returned when the content type of the body is {@code application/json}. * * @param ownerName * @param projectName * @return the response to the request for issue labels */ private static Result labelsAsJSON(String ownerName, String projectName) { if (!request().accepts("application/json")) { return status(Http.Status.NOT_ACCEPTABLE); } Project project = Project.findByOwnerAndProjectName(ownerName, projectName); List<Map<String, String>> labels = new ArrayList<>(); for (IssueLabel label : IssueLabel.findByProject(project)) { Map<String, String> labelPropertyMap = new HashMap<>(); labelPropertyMap.put("id", "" + label.id); labelPropertyMap.put("category", label.category.name); labelPropertyMap.put("categoryId", "" + label.category.id); labelPropertyMap.put("color", label.color); labelPropertyMap.put("name", label.name); labels.add(labelPropertyMap); } response().setHeader("Content-Type", "application/json"); return ok(toJson(labels)); }