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

Add Intermediate Artifact page #2

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 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
Binary file added cs
Binary file not shown.
109 changes: 70 additions & 39 deletions modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,46 +37,46 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)(
routes = get {
path(projectM)(getProjectPage(_, user))
},
get {
path(projectM / "artifacts" / artifactNameM) { (ref, artifactName) =>
artifactsParams { params =>
getProjectOrRedirect(ref, user) { project =>
val artifactsF = database.getArtifacts(ref, artifactName, params)
val headerF = service.getProjectHeader(project).map(_.get)
for (artifacts <- artifactsF; header <- headerF) yield {
val binaryVersions = artifacts
.map(_.binaryVersion)
.distinct
.sorted(BinaryVersion.ordering.reverse)
// get {
// path(projectM / "artifacts" / artifactNameM) { (ref, artifactName) =>
ayushkoli772 marked this conversation as resolved.
Show resolved Hide resolved
// artifactsParams { params =>
// getProjectOrRedirect(ref, user) { project =>
// val artifactsF = database.getArtifacts(ref, artifactName, params)
// val headerF = service.getProjectHeader(project).map(_.get)
// for (artifacts <- artifactsF; header <- headerF) yield {
// val binaryVersions = artifacts
// .map(_.binaryVersion)
// .distinct
// .sorted(BinaryVersion.ordering.reverse)

val artifactsByVersion =
artifacts
.groupBy(_.version)
.filter {
case (_, artifacts) =>
params.binaryVersions
.forall(binaryVersion => artifacts.exists(_.binaryVersion == binaryVersion))
}
.map { case (version, artifacts) => (artifacts.map(_.releaseDate).min, version) -> artifacts }
val sortedArtifactsByVersion = SortedMap.from(artifactsByVersion)(
Ordering.Tuple2(Ordering[Instant].reverse, Ordering[SemanticVersion].reverse)
)
val page = html.artifacts(
env,
user,
project,
header,
artifactName,
binaryVersions,
sortedArtifactsByVersion,
params
)
complete(page)
}
}
}
}
},
// val artifactsByVersion =
// artifacts
// .groupBy(_.version)
// .filter {
// case (_, artifacts) =>
// params.binaryVersions
// .forall(binaryVersion => artifacts.exists(_.binaryVersion == binaryVersion))
// }
// .map { case (version, artifacts) => (artifacts.map(_.releaseDate).min, version) -> artifacts }
// val sortedArtifactsByVersion = SortedMap.from(artifactsByVersion)(
// Ordering.Tuple2(Ordering[Instant].reverse, Ordering[SemanticVersion].reverse)
// )
// val page = html.artifacts(
// env,
// user,
// project,
// header,
// artifactName,
// binaryVersions,
// sortedArtifactsByVersion,
// params
// )
// complete(page)
// }
// }
// }
// }
// },
get {
path(projectM / "artifacts" / artifactNameM / versionM) { (ref, artifactName, artifactVersion) =>
artifactParams { params =>
Expand Down Expand Up @@ -111,6 +111,37 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)(
}
}
},

get {
path(projectM / "artifacts" ) { ref =>
getProjectOrRedirect(ref,user) { project =>
ayushkoli772 marked this conversation as resolved.
Show resolved Hide resolved
val headerF = service.getProjectHeader(project)
for {
header <- headerF
} yield {
val allArtifacts = header.toSeq.flatMap(_.artifacts)

// Group by artifact name
val artifactsByName = allArtifacts.groupBy(_.artifactName)

val groupedArtifacts = artifactsByName
.groupBy { case (artifactName, artifacts) =>
artifacts.maxBy(_.version).version
}
.map { case (latestVersion, artifactsByName) =>
latestVersion -> artifactsByName.map { case (name, artifacts) => name -> artifacts.filter(_.version == latestVersion)
}
}
ayushkoli772 marked this conversation as resolved.
Show resolved Hide resolved

val page = html.artifacts(env, user, project, header, groupedArtifacts)
ayushkoli772 marked this conversation as resolved.
Show resolved Hide resolved
complete(page)
}

}

}
},

get {
path(projectM / "version-matrix") { ref =>
getProjectOrRedirect(ref, user) { project =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,139 +10,92 @@
@import scaladex.view.Formats

@import java.time.Instant

@(
env: Env,
user: Option[UserState],
project: Project,
header: ProjectHeader,
artifactName: Artifact.Name,
allBinaryVersions: Seq[BinaryVersion],
artifactByVersions: SortedMap[(Instant, SemanticVersion), Seq[Artifact]],
params: ArtifactsPageParams
header: Option[ProjectHeader],
groupedArtifacts: Map[SemanticVersion, Map[Artifact.Name, Seq[Artifact]]]
)

@main(env, title = project.repository.toString, user) {
<main id="container-project">
@headproject(env, user, project, Some(header), "Artifacts")
@headproject(env, user, project, header, "Artifacts")
<div class="container">
<div class="content-project artifacts box" data-organization="@project.reference.organization"
data-repository="@project.reference.repository">
<div class="artifacts-filter">
@filters()
<div class="result-count">
<b>@artifactByVersions.size</b>
@Formats.wordPlural(artifactByVersions.size, "version") found for
<b>@artifactName</b>
<b>@groupedArtifacts.values.flatten.size</b> @Formats.wordPlural(groupedArtifacts.values.flatten.size, "artifact") found
</div>
</div>
@if(artifactByVersions.isEmpty) {
<div>We can't find any release that matches all you criteria</div>
@if(groupedArtifacts.isEmpty) {
<div>We can't find any artifacts for this project.</div>
} else {
<div>
@artifactByVersions.map { case ((releaseDate, version), artifacts) =>
<div class="panel">
<div class="artifact-row panel-body center">
<div class="col-md-3 center">
<a class="artifact-version" href="/@project.reference/artifacts/@artifactName/@version">@version</a>
</div>
<div class="col-md-9">
<div class="artifact-info">
<a data-toggle="tooltip" data-placement="top" title="@formatInstant(releaseDate)">
@TimeUtils.toFiniteDuration(releaseDate, Instant.now()).prettyPrint
ago<i class="fa-solid fa-calendar-days"></i>
</a>
<br>
@artifacts.head.licenses.map { license =>
<a href="@license.url.getOrElse("#")">@license.shortName<i class="fa-solid fa-scale-balanced"></i></a>
}
</div>
<div class="artifact-content">
@for(
(platform, binaryVersions) <- artifacts
.map(_.binaryVersion)
.distinct
.sorted
.reverse
.groupBy(_.platform)
.toSeq
) {
<h5>@platform:</h5>
@for(binaryVersion <- binaryVersions) {
<a href="/@project.reference/artifacts/@artifactName/@version?binary-version=@binaryVersion.encode" class="scala-version">
@binaryVersion.language.label
</a>
}
<br>
}
<div>
@for((version, artifactsByName) <- groupedArtifacts.toSeq.sortBy(_._1).reverse) {
<h3>Version @version</h3>
@for((artifactName, artifacts) <- artifactsByName.toSeq.sortBy(_._1)) {
<div class="panel">
<div class="artifact-row panel-body center">
<div class="col-md-3 center">
<a class="artifact-version" href="/@project.reference/artifacts/@artifactName">@artifactName</a>
</div>
<div class="col-md-9">
<div class="artifact-info">
<a data-toggle="tooltip" data-placement="top" title="@formatInstant(artifacts.head.releaseDate)">
@TimeUtils.toFiniteDuration(artifacts.head.releaseDate, Instant.now()).prettyPrint
ago<i class="fa-solid fa-calendar-days"></i>
</a>
<br>
@artifacts.head.licenses.map { license =>
<a href="@license.url.getOrElse("#")">@license.shortName<i class="fa-solid fa-scale-balanced"></i></a>
}
</div>
<div class="artifact-content">
@for(
(platform, binaryVersions) <- artifacts
.groupBy(_.platform)
.toSeq
.sortBy(_._1)
.reverse
) {
<h5>@platform:</h5>
@for(binaryVersion <- binaryVersions.map(_.binaryVersion).distinct.sorted.reverse) {
<a href="/@project.reference/artifacts/@artifactName/@version?binary-version=@binaryVersion.encode" class="scala-version">
@binaryVersion.language.label
</a>
}
<br>
}
</div>
</div>
</div>
</div>
</div>
</div>
}
}
</div>
}
}
</div>
</div>
</div>
</main>
}

@filters() = {
<form action="#" action="GET">
<select class="selectpicker" data-style="btn-primary" onchange="window.location=this.value">
@for(name <- header.allArtifactNames) {
<option value="@artifactsUri(project.reference, name, params)"
@if(name == artifactName) {selected}>
@name
</option>
}
</select>

<form action="#" action="GET">
<select class="selectpicker" name="binary-versions"
title= "Scala Versions" multiple data-style="btn-primary" data-actions-box="true" data-selected-text-format="static"
title="Scala Versions" multiple data-style="btn-primary" data-actions-box="true" data-selected-text-format="static"
onchange="this.form.submit()">
@for((platform, binaryVersions) <- allBinaryVersions.sorted.groupBy(_.platform)) {
@for((platform, binaryVersions) <- groupedArtifacts.values.flatten.flatMap(_._2).map(_.binaryVersion).toSeq.distinct.groupBy(_.platform).toSeq.sortBy(_._1).reverse) {
ayushkoli772 marked this conversation as resolved.
Show resolved Hide resolved
<optgroup label="@platform">
@for(binaryVersion <- binaryVersions.reverse) {
<option value="@binaryVersion.label"
@if(params.binaryVersions.contains(binaryVersion)) {selected}>
@for(binaryVersion <- binaryVersions) {
<option value="@binaryVersion.label">
@binaryVersion.language.label
</option>
</option>
}
</optgroup>
}
</select>
<label class="filter btn btn-default">
<input type="checkbox" @if(params.preReleases) { checked } name="pre-releases" value="true" onclick="this.form.submit()">
Show pre-release versions
</label>
</form>
<div class="options-checked">
<ul class="list-inline">
@for(binaryVersion <- params.binaryVersions) {
<li>
<a href="@artifactsUri(project.reference, artifactName, params.remove(binaryVersion))" class="label label-default">
<i class="fa-solid fa-xmark"></i>
@binaryVersion
</a>
</li>
}
@if(params.preReleases) {
<li>
<a class="label label-info" href="@artifactsUri(project.reference, artifactName, params.withPreReleases(false))">
<i class="fa-solid fa-xmark"></i>
Show pre-release versions
</a>
</li>
}
@if(params.binaryVersions.nonEmpty || params.preReleases) {
<li>
<a href="@artifactsUri(project.reference, artifactName, ArtifactsPageParams.empty)" class="label label-warning clear-all">
<i class="fa-solid fa-xmark"></i>
Clear all filters
</a>
</li>
}
</ul>

</div>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ <h1>
<ul class="nav nav-tabs">
<li role="project" class="@isActive("Project")"><a href="/@project.reference">Project</a></li>
@for(header <- header) {
<li role="artifacts" class="@isActive("Artifacts")"><a href="@header.artifactsUrl">@plural(header.versionCount, "Version")</a></li>
<!-- <li role="artifacts" class="@isActive("Artifacts")"><a href="@header.artifactsUrl">@plural(header.versionCount, "Version")</a></li> -->
<li role="artifacts" class="@isActive("Artifacts")"><a href="/@project.reference/artifacts">Artifacts</a></li>
<!-- <li role="version-matrix" class="@isActive("Version Matrix")"><a href="/@project.reference/version-matrix">Version Matrix</a></li> -->
<li role="badges" class="@isActive("Badges")"><a href="/@project.reference/badges">Badges</a></li>
}
Expand Down
Loading