mirror of
https://github.com/ysoftdevs/odc-analyzer.git
synced 2026-01-16 00:34:18 +01:00
Keep filter when switching between pages (mostly; does not work in Notifications and Status)
This commit is contained in:
@@ -19,6 +19,7 @@ sealed trait Filter{
|
||||
def filters: Boolean
|
||||
def descriptionHtml: Html
|
||||
def descriptionText: String
|
||||
def filterProjectsWithReports(projectsWithReports: ProjectsWithReports): Option[ProjectsWithReports] = ???
|
||||
}
|
||||
final case class ProjectFilter(project: ReportInfo) extends Filter{
|
||||
override def filters: Boolean = true
|
||||
@@ -100,6 +101,7 @@ object NoFilter extends Filter{
|
||||
override def descriptionText: String = "all projects"
|
||||
override def subReports(r: Result): Option[Result] = Some(r)
|
||||
override def selector: Option[String] = None
|
||||
override def filterProjectsWithReports(projectsWithReports: ProjectsWithReports): Option[ProjectsWithReports] = Some(projectsWithReports)
|
||||
}
|
||||
private final case class BadFilter(pattern: String) extends Filter{
|
||||
override def filters: Boolean = true
|
||||
@@ -107,6 +109,7 @@ private final case class BadFilter(pattern: String) extends Filter{
|
||||
override def descriptionHtml: Html = Html("<b>bad filter</b>")
|
||||
override def descriptionText: String = "bad filter"
|
||||
override def selector: Option[String] = Some(pattern)
|
||||
override def filterProjectsWithReports(projectsWithReports: ProjectsWithReports): Option[ProjectsWithReports] = None
|
||||
}
|
||||
|
||||
object DependencyCheckReportsParser{
|
||||
|
||||
@@ -36,7 +36,7 @@ class Notifications @Inject()(
|
||||
|
||||
import secureRequestConversion._
|
||||
|
||||
def listProjects() = SecuredAction.async { implicit req =>
|
||||
def listProjects(filter: Option[String]) = SecuredAction.async { implicit req =>
|
||||
val (lastRefreshTime, resultsFuture) = projectReportsProvider.resultsForVersions(versions)
|
||||
val myWatchesFuture = notificationService.watchedProjectsByUser(req.identity.loginInfo).map(_.map(_.project).toSet)
|
||||
for{
|
||||
@@ -44,7 +44,8 @@ class Notifications @Inject()(
|
||||
myWatches <- myWatchesFuture
|
||||
} yield {
|
||||
val projects = dependencyCheckReportsParser.parseReports(successfulReports, failedReports).projectsReportInfo.sortedReportsInfo
|
||||
Ok(views.html.notifications.index(projects, myWatches, failedReports.keySet))
|
||||
//val projects = dependencyCheckReportsParser.parseReports(successfulReports, failedReports).selection(filter).get.projectsWithSelection.projectsWithReportsSubset.sortedReportsInfo
|
||||
Ok(views.html.notifications.index(projects, myWatches, failedReports.keySet, filter))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,15 +197,15 @@ class Notifications @Inject()(
|
||||
}
|
||||
}
|
||||
|
||||
// Redirection to a specific position does not look intuituve now, so it has been disabled for now.
|
||||
private def redirectToProject(project: String)(implicit th: DefaultRequest) = Redirect(routes.Notifications.listProjects()/*.withFragment("project-" + URLEncoder.encode(project, "utf-8")).absoluteURL()*/)
|
||||
// Redirection to a specific position does not look intuitive now, so it has been disabled for now.
|
||||
private def redirectToProject(project: String, filter: Option[String])(implicit th: DefaultRequest) = Redirect(routes.Notifications.listProjects(filter)/*.withFragment("project-" + URLEncoder.encode(project, "utf-8")).absoluteURL()*/)
|
||||
|
||||
def watch(project: String) = SecuredAction.async{ implicit req =>
|
||||
for( _ <-notificationService.subscribe(req.identity.loginInfo, project) ) yield redirectToProject(project)
|
||||
def watch(project: String, filter: Option[String]) = SecuredAction.async{ implicit req =>
|
||||
for( _ <-notificationService.subscribe(req.identity.loginInfo, project) ) yield redirectToProject(project, filter)
|
||||
}
|
||||
|
||||
def unwatch(project: String) = SecuredAction.async{ implicit req =>
|
||||
for( _ <-notificationService.unsubscribe(req.identity.loginInfo, project) ) yield redirectToProject(project)
|
||||
def unwatch(project: String, filter: Option[String]) = SecuredAction.async{ implicit req =>
|
||||
for( _ <-notificationService.unsubscribe(req.identity.loginInfo, project) ) yield redirectToProject(project, filter)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,4 +11,5 @@ final case class ProjectsWithSelection(filter: Filter, projectsWithReports: Proj
|
||||
def isProjectSpecified: Boolean = filter.filters
|
||||
def selectorString = filter.selector
|
||||
def projectNameText: String = filter.descriptionText
|
||||
def projectsWithReportsSubset: Option[ProjectsWithReports] = filter.filterProjectsWithReports(projectsWithReports)
|
||||
}
|
||||
|
||||
@@ -44,13 +44,14 @@
|
||||
</div>
|
||||
<div id="navbar" class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="@routes.Statistics.vulnerableLibraries(None)">Vulnerable libraries</a></li>
|
||||
<li><a href="@routes.Statistics.vulnerabilities(None, None)">Vulnerabilities</a></li>
|
||||
<li><a href="@routes.Notifications.listProjects()">Notifications</a></li>
|
||||
@filter = @{projectsOption.flatMap(_._1.selectorString)}
|
||||
<li><a href="@routes.Statistics.vulnerableLibraries(filter)">Vulnerable libraries</a></li>
|
||||
<li><a href="@routes.Statistics.vulnerabilities(filter, None)">Vulnerabilities</a></li>
|
||||
<li><a href="@routes.Notifications.listProjects(filter)">Notifications</a></li>
|
||||
<li><a href="@routes.Application.index(Map())">Status</a></li>
|
||||
<li><a href="#" data-toggle="collapse" data-target=".extended-menu">…</a></li>
|
||||
<li class="collapse extended-menu"><a href="@routes.Application.dependencies(None)">Tags</a></li>
|
||||
<li class="collapse extended-menu"><a href="@routes.Statistics.basic(None)">Tag statistics</a></li>
|
||||
<li class="collapse extended-menu"><a href="@routes.Statistics.basic(filter)">Tag statistics</a></li>
|
||||
<li>
|
||||
@for((ProjectsWithSelection(filter, projects, teams), link) <- projectsOption){
|
||||
<div id="project-selector">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@import helper._
|
||||
@(projects: Seq[ReportInfo], watchedProjects: Set[String], failedReports: Set[String])(implicit req: DefaultRequest)
|
||||
@(projects: Seq[ReportInfo], watchedProjects: Set[String], failedReports: Set[String], filter: Option[String])(implicit req: DefaultRequest)
|
||||
@button(action: Call)(label: String) = {
|
||||
@form(action, 'style -> "display: inline-block"){
|
||||
@CSRF.formField
|
||||
@@ -54,9 +54,9 @@
|
||||
<button disabled class="btn btn-link">unwatch</button>
|
||||
}else{
|
||||
@if(isWatchedDirectly){
|
||||
@button(routes.Notifications.unwatch(project.fullId))("unwatch")
|
||||
@button(routes.Notifications.unwatch(project.fullId, filter))("unwatch")
|
||||
}else{
|
||||
@button(routes.Notifications.watch(project.fullId))("watch")
|
||||
@button(routes.Notifications.watch(project.fullId, filter))("watch")
|
||||
}
|
||||
}
|
||||
@children
|
||||
|
||||
@@ -31,9 +31,9 @@ GET /stats/libraries/all controllers.Statistics.allLibrarie
|
||||
GET /stats/libraries/files controllers.Statistics.allFiles(selector: Option[String])
|
||||
GET /stats/libraries/gavs controllers.Statistics.allGavs(selector: Option[String])
|
||||
|
||||
GET /notifications controllers.Notifications.listProjects()
|
||||
POST /notifications/watch controllers.Notifications.watch(project: String)
|
||||
POST /notifications/unwatch controllers.Notifications.unwatch(project: String)
|
||||
GET /notifications controllers.Notifications.listProjects(filter: Option[String])
|
||||
POST /notifications/watch controllers.Notifications.watch(project: String, filter: Option[String])
|
||||
POST /notifications/unwatch controllers.Notifications.unwatch(project: String, filter: Option[String])
|
||||
GET /notifications/cron/:key controllers.Notifications.cron(key: String, purgeCache: Boolean ?= true)
|
||||
|
||||
GET /libraries/vulnerabilities controllers.Statistics.searchVulnerableSoftware(versionlessCpes: Seq[String], versionOption: Option[String])
|
||||
|
||||
Reference in New Issue
Block a user