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

NMS-15790: Transport bootstrap.jsp args in context #6791

Merged
merged 4 commits into from
Oct 25, 2023
Merged
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
142 changes: 142 additions & 0 deletions opennms-webapp/src/main/java/org/opennms/web/utils/Bootstrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2023 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2023 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <[email protected]>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.web.utils;

import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Set;
import java.util.HashSet;

public class Bootstrap {

private final PageContext pageContext;

private final List<String> headTitles = new ArrayList<>();

private final List<Breadcrumb> breadcrumbs = new ArrayList<>();

private String ngApp;
private String scrollSpy;

private Set<String> flags = new HashSet<>();

private Bootstrap(final PageContext pageContext) {
this.pageContext = Objects.requireNonNull(pageContext);
}

private static String eval(final PageContext pageContext, final String attr, final String expr) {
try {
return Objects.toString(ExpressionEvaluatorManager.evaluate(attr, expr, Object.class, pageContext));
} catch (final JspException e) {
throw new RuntimeException(e);
}
}

public void build(final HttpServletRequest request) throws JspException {
request.setAttribute("__bs_headTitles", this.headTitles);
request.setAttribute("__bs_ngApp", this.ngApp);
request.setAttribute("__bs_scrollSpy", this.scrollSpy);
request.setAttribute("__bs_breadcrumbs", this.breadcrumbs);
request.setAttribute("__bs_flags", this.flags);
}

public Bootstrap headTitle(final String headTitle) {
this.headTitles.add(eval(this.pageContext, "headTitle", Objects.requireNonNull(headTitle)));
return this;
}

private Bootstrap breadcrumb(final Breadcrumb entry) {
this.breadcrumbs.add(Objects.requireNonNull(entry));
return this;
}

public Bootstrap breadcrumb(final String title) {
final var breadcrumb = new Breadcrumb(eval(this.pageContext, "breadcrumb.title", title));
return this.breadcrumb(breadcrumb);
}

public Bootstrap breadcrumb(final String title, final String link) {
final var breadcrumb = new Breadcrumb(eval(this.pageContext, "breadcrumb.title", title))
.withLink(eval(this.pageContext, "breadcrumb.link", link));

return this.breadcrumb(breadcrumb);
}

public Bootstrap scrollSpy(final String scrollSpy) {
this.scrollSpy = scrollSpy;
return this;
}

public Bootstrap ngApp(final String ngApp) {
this.ngApp = ngApp;
return this;
}

public Bootstrap flags(final String... flags) {
this.flags.addAll(Arrays.asList(flags));
return this;
}

public static class Breadcrumb {
public final String title;
public final String link;

public Breadcrumb(final String title) {
this(title, null);
}

public Breadcrumb(final String title, final String link) {
this.title = Objects.requireNonNull(title);
this.link = link;
}

public Breadcrumb withLink(final String link) {
return new Breadcrumb(this.title, link);
}

public String getTitle() {
return this.title;
}

public String getLink() {
return this.link;
}
}

public static Bootstrap with(final PageContext pageContext) {
return new Bootstrap(pageContext);
}
}
22 changes: 12 additions & 10 deletions opennms-webapp/src/main/webapp/KSC/customGraphChooseResource.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<jsp:include page="/includes/bootstrap.jsp" flush="false" >
<jsp:param name="ngapp" value="onms-ksc-wizard" />
<jsp:param name="title" value="Key SNMP Customized Performance Reports" />
<jsp:param name="headTitle" value="Choose Resource" />
<jsp:param name="headTitle" value="KSC" />
<jsp:param name="headTitle" value="Reports" />
<jsp:param name="breadcrumb" value="<a href='report/index.jsp'>Reports</a>" />
<jsp:param name="breadcrumb" value="<a href='KSC/index.jsp'>KSC Reports</a>" />
<jsp:param name="breadcrumb" value="Custom Graph" />
</jsp:include>
<%@ page import="org.opennms.web.utils.Bootstrap" %>
<% Bootstrap.with(pageContext)
.headTitle("Choose Resource")
.headTitle("KSC")
.headTitle("Reports")
.breadcrumb("Reports", "report/index.jsp")
.breadcrumb("KSC Reports", "KSC/index.jsp")
.breadcrumb("Custom Graph")
.ngApp("onms-ksc-wizard")
.build(request);
%>
<jsp:directive.include file="/includes/bootstrap.jsp" />

<div class="container-fluid" ng-controller="KSCResourceCtrl">

Expand Down
21 changes: 11 additions & 10 deletions opennms-webapp/src/main/webapp/KSC/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@
pageContext.setAttribute("isReadOnly", isReadOnly);
%>

<jsp:include page="/includes/bootstrap.jsp" flush="false" >
<jsp:param name="ngapp" value="onms-ksc-wizard" />
<jsp:param name="title" value="Key SNMP Customized Performance Reports" />
<jsp:param name="headTitle" value="Performance" />
<jsp:param name="headTitle" value="Reports" />
<jsp:param name="headTitle" value="KSC" />
<jsp:param name="location" value="ksc" />
<jsp:param name="breadcrumb" value="<a href='report/index.jsp'>Reports</a>" />
<jsp:param name="breadcrumb" value="KSC Reports" />
</jsp:include>
<%@ page import="org.opennms.web.utils.Bootstrap" %>
<% Bootstrap.with(pageContext)
.headTitle("Performance")
.headTitle("Reports")
.headTitle("KSC")
.breadcrumb("Reports", "report/index.jsp")
.breadcrumb("KSC Reports")
.ngApp("onms-ksc-wizard")
.build(request);
%>
<jsp:directive.include file="/includes/bootstrap.jsp" />

<div class="container-fluid" ng-controller="KSCWizardCtrl">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@

<% final String baseHref = org.opennms.web.api.Util.calculateUrlBase( request ); %>

<jsp:include page="/includes/bootstrap.jsp" flush="false" >
<jsp:param name="title" value="Key SNMP Customized Performance Reports" />
<jsp:param name="headTitle" value="Performance " />
<jsp:param name="headTitle" value="Reports" />
<jsp:param name="headTitle" value="KSC" />
<jsp:param name="location" value="KSC Reports" />
<jsp:param name="breadcrumb" value="<a href='report/index.jsp'>Reports</a>" />
<jsp:param name="breadcrumb" value="<a href='KSC/index.jsp'>KSC Reports</a>" />
<jsp:param name="breadcrumb" value="Custom Graph" />
<jsp:param name="renderGraphs" value="true" />
</jsp:include>
<%@ page import="org.opennms.web.utils.Bootstrap" %>
<% Bootstrap.with(pageContext)
.headTitle("Performance ")
.headTitle("Reports")
.headTitle("KSC")
.breadcrumb("Reports", "report/index.jsp")
.breadcrumb("KSC Reports", "KSC/index.jsp")
.breadcrumb("Custom Graph")
.flags("renderGraphs")
.build(request);
%>
<jsp:directive.include file="/includes/bootstrap.jsp" />

<script type="text/javascript">
function saveGraph()
Expand Down
23 changes: 12 additions & 11 deletions opennms-webapp/src/main/webapp/WEB-INF/jsp/KSC/customReport.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@

<% final String baseHref = org.opennms.web.api.Util.calculateUrlBase( request ); %>

<jsp:include page="/includes/bootstrap.jsp" flush="false" >
<jsp:param name="title" value="Key SNMP Customized Performance Reports" />
<jsp:param name="headTitle" value="Performance" />
<jsp:param name="headTitle" value="Reports" />
<jsp:param name="headTitle" value="KSC" />
<jsp:param name="location" value="KSC Reports" />
<jsp:param name="breadcrumb" value="<a href='report/index.jsp'>Reports</a>" />
<jsp:param name="breadcrumb" value="<a href='KSC/index.jsp'>KSC Reports</a>" />
<jsp:param name="breadcrumb" value="Custom Report" />
<jsp:param name="renderGraphs" value="true" />
</jsp:include>
<%@ page import="org.opennms.web.utils.Bootstrap" %>
<% Bootstrap.with(pageContext)
.headTitle("Performance")
.headTitle("Reports")
.headTitle("KSC")
.breadcrumb("Reports", "report/index.jsp")
.breadcrumb("KSC Reports", "KSC/index.jsp")
.breadcrumb("Custom Report")
.flags("renderGraphs")
.build(request);
%>
<jsp:directive.include file="/includes/bootstrap.jsp" />

<%-- A script to Save the file --%>
<script type="text/javascript">
Expand Down
22 changes: 12 additions & 10 deletions opennms-webapp/src/main/webapp/WEB-INF/jsp/KSC/customView.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@

<% final String baseHref = org.opennms.web.api.Util.calculateUrlBase( request ); %>

<jsp:include page="/includes/bootstrap.jsp" flush="false" >
<jsp:param name="title" value="Key SNMP Customized Performance Reports" />
<jsp:param name="headTitle" value="Performance" />
<jsp:param name="headTitle" value="Reports" />
<jsp:param name="headTitle" value="KSC" />
<jsp:param name="breadcrumb" value="<a href='report/index.jsp'>Reports</a>" />
<jsp:param name="breadcrumb" value="<a href='KSC/index.jsp'>KSC Reports</a>" />
<jsp:param name="breadcrumb" value="Custom View" />
<jsp:param name="renderGraphs" value="true" />
</jsp:include>
<%@ page import="org.opennms.web.utils.Bootstrap" %>
<% Bootstrap.with(pageContext)
.headTitle("Performance")
.headTitle("Reports")
.headTitle("KSC")
.breadcrumb("Reports", "report/index.jsp")
.breadcrumb("KSC Reports", "KSC/index.jsp")
.breadcrumb("Custom View")
.flags("renderGraphs")
.build(request);
%>
<jsp:directive.include file="/includes/bootstrap.jsp" />

<%-- A script to Save the file --%>
<script type="text/javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<jsp:include page="/includes/bootstrap.jsp" flush="false">
<jsp:param name="title" value="Applications" />
<jsp:param name="headTitle" value="Applications" />
<jsp:param name="breadcrumb"
value="<a href='admin/index.jsp'>Admin</a>" />
<jsp:param name="breadcrumb" value="Applications" />
</jsp:include>
<%@ page import="org.opennms.web.utils.Bootstrap" %>
<% Bootstrap.with(pageContext)
.headTitle("Applications")
.breadcrumb("Admin", "admin/index.jsp")
.breadcrumb("Applications")
.build(request);
%>
<jsp:directive.include file="/includes/bootstrap.jsp" />

<div class="card-header">
<span>Applications</span>
Expand Down
15 changes: 8 additions & 7 deletions opennms-webapp/src/main/webapp/WEB-INF/jsp/admin/categories.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="https://www.owasp.org/index.php/OWASP_Java_Encoder_Project" prefix="e"%>

<jsp:include page="/includes/bootstrap.jsp" flush="false">
<jsp:param name="title" value="Categories" />
<jsp:param name="headTitle" value="Categories" />
<jsp:param name="breadcrumb"
value="<a href='admin/index.jsp'>Admin</a>" />
<jsp:param name="breadcrumb" value="Categories" />
</jsp:include>
<%@ page import="org.opennms.web.utils.Bootstrap" %>
<% Bootstrap.with(pageContext)
.headTitle("Categories")
.breadcrumb("Admin", "admin/index.jsp")
.breadcrumb("Categories")
.build(request);
%>
<jsp:directive.include file="/includes/bootstrap.jsp" />

<script type="text/javascript">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<jsp:include page="/includes/bootstrap.jsp" flush="false">
<jsp:param name="title" value="Application" />
<jsp:param name="headTitle" value="Application" />
<jsp:param name="breadcrumb"
value="<a href='admin/index.jsp'>Admin</a>" />
<jsp:param name="breadcrumb"
value="<a href='admin/applications.htm'>Applications</a>" />
<jsp:param name="breadcrumb" value="Show" />
</jsp:include>
<%@ page import="org.opennms.web.utils.Bootstrap" %>
<% Bootstrap.with(pageContext)
.headTitle("Application")
.breadcrumb("Admin", "admin/index.jsp")
.breadcrumb("Applications", "admin/applications.htm")
.breadcrumb("Show")
.build(request);
%>
<jsp:directive.include file="/includes/bootstrap.jsp" />

<div class="card">
<div class="card-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<jsp:include page="/includes/bootstrap.jsp" flush="false">
<jsp:param name="title" value="Category" />
<jsp:param name="headTitle" value="Category" />
<jsp:param name="breadcrumb"
value="<a href='admin/index.jsp'>Admin</a>" />
<jsp:param name="breadcrumb"
value="<a href='admin/categories.htm'>Category</a>" />
<jsp:param name="breadcrumb" value="Show" />
</jsp:include>
<%@ page import="org.opennms.web.utils.Bootstrap" %>
<% Bootstrap.with(pageContext)
.headTitle("Category")
.breadcrumb("Admin", "admin/index.jsp")
.breadcrumb("Category", "admin/categories.htm")
.breadcrumb("Show")
.build(request);
%>
<jsp:directive.include file="/includes/bootstrap.jsp" />

<script type="text/javascript">
var nodesToAddAuto = [
Expand Down
Loading
Loading