Skip to content

Commit

Permalink
Merge pull request #577 from SpongePowered/feature/copy-url-at-download
Browse files Browse the repository at this point in the history
Add dropdown on download button for Copy URL
  • Loading branch information
phase authored Jul 19, 2018
2 parents 61d94b8 + 8fbb4f9 commit 7441986
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
15 changes: 10 additions & 5 deletions app/models/viewhelper/ProjectData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ case class ProjectData(joinable: Project,
flags: Seq[(Flag, String, Option[String])], // (Flag, user.name, resolvedBy)
noteCount: Int, // getNotes.size
lastVisibilityChange: Option[VisibilityChange],
lastVisibilityChangeUser: String // users.get(project.lastVisibilityChange.get.createdBy.get).map(_.username).getOrElse("Unknown")
lastVisibilityChangeUser: String, // users.get(project.lastVisibilityChange.get.createdBy.get).map(_.username).getOrElse("Unknown")
recommendedVersion: Option[Version]
) extends JoinableData[ProjectRole, ProjectMember, Project] {

def flagCount = flags.size
Expand Down Expand Up @@ -63,6 +64,7 @@ object ProjectData {
val logSize = 0
val lastVisibilityChange = None
val lastVisibilityChangeUser = "-"
val recommendedVersion = None

val data = new ProjectData(project.underlying,
projectOwner,
Expand All @@ -74,7 +76,8 @@ object ProjectData {
Seq.empty,
0,
lastVisibilityChange,
lastVisibilityChangeUser)
lastVisibilityChangeUser,
recommendedVersion)

data
}
Expand Down Expand Up @@ -103,9 +106,10 @@ object ProjectData {
flagUsersFut,
flagResolvedFut,
lastVisibilityChangeFut,
lastVisibilityChangeUserFut
lastVisibilityChangeUserFut,
project.recommendedVersion
).parMapN {
case (settings, projectOwner, ownerRole, versions, members, logSize, flags, flagUsers, flagResolved, lastVisibilityChange, lastVisibilityChangeUser) =>
case (settings, projectOwner, ownerRole, versions, members, logSize, flags, flagUsers, flagResolved, lastVisibilityChange, lastVisibilityChangeUser, recommendedVersion) =>
val noteCount = project.getNotes().size
val flagData = flags zip flagUsers zip flagResolved map { case ((fl, user), resolved) =>
(fl, user.name, resolved.map(_.username))
Expand All @@ -122,7 +126,8 @@ object ProjectData {
flagData.toSeq,
noteCount,
lastVisibilityChange,
lastVisibilityChangeUser)
lastVisibilityChangeUser,
Some(recommendedVersion))
}
}

Expand Down
1 change: 1 addition & 0 deletions app/views/bootstrap/layout.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<script type="text/javascript" src="@routes.Assets.at("lib/momentjs/min/moment.min.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("bootstrap/js/bootstrap.min.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("lib/filesize/lib/filesize.min.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("lib/clipboard/clipboard.min.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("highlight/highlight.pack.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("javascripts/main.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("javascripts/svg.js")"></script>
Expand Down
20 changes: 15 additions & 5 deletions app/views/projects/versions/view.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,21 @@ <h1 class="pull-left">@v.v.versionString</h1>
}
}

<a href="@versionRoutes.download(
v.p.project.ownerName, v.p.project.slug, v.v.versionString, None)"
class="btn btn-primary">
<i class="fa fa-download"></i> @messages("general.download")
</a>
<div class="btn-group btn-download">
<a href="@versionRoutes.download(v.p.project.ownerName, v.p.project.slug, v.v.versionString, None)"
title="@messages("project.download.recommend")" data-toggle="tooltip"
data-placement="bottom" class="btn btn-primary">
<i class="fa fa-download"></i> @messages("general.download")
</a>
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li><a href="@versionRoutes.download(v.p.project.ownerName, v.p.project.slug, v.v.versionString, None)">@messages("general.download")</a></li>
<li><a href="#" class="copy-url" data-clipboard-text="@config.app.get[String]("baseUrl")@versionRoutes.download(v.p.project.ownerName, v.p.project.slug, v.v.versionString, None)">Copy URL</a></li>
</ul>
</div>

</div>
</div>
Expand Down
20 changes: 15 additions & 5 deletions app/views/projects/view.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,21 @@ <h4 class="modal-title" id="label-flag">Flag project</h4>

<!-- Download button -->
@if(!p.project.isDeleted) {
<a href="@Versions.downloadRecommended(p.project.ownerName, p.project.slug, None)"
title="@messages("project.download.recommend")" data-toggle="tooltip"
data-placement="bottom" class="btn btn-primary">
<i class="fa fa-download"></i> @messages("general.download")
</a>
<div class="btn-group btn-download">
<a href="@Versions.downloadRecommended(p.project.ownerName, p.project.slug, None)"
title="@messages("project.download.recommend")" data-toggle="tooltip"
data-placement="bottom" class="btn btn-primary">
<i class="fa fa-download"></i> @messages("general.download")
</a>
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li><a href="@Versions.downloadRecommended(p.project.ownerName, p.project.slug, None)">@messages("general.download")</a></li>
<li><a href="#" class="copy-url" data-clipboard-text="@config.app.get[String]("baseUrl")@Versions.download(p.project.ownerName, p.project.slug, p.recommendedVersion.map(v => v.versionString).getOrElse(""), None)">Copy URL</a></li>
</ul>
</div>
}

@if(request.hasUser && (request.data.globalPerm(ReviewFlags) || request.data.globalPerm(ViewLogs))) {
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ libraryDependencies ++= Seq(
"org.webjars" % "jquery" % "2.2.4",
"org.webjars" % "font-awesome" % "4.7.0",
"org.webjars.bower" % "filesize" % "3.5.6",
"org.webjars.bower" % "momentjs" % "2.22.2"
"org.webjars.bower" % "momentjs" % "2.22.2",
"org.webjars.bowergithub.zenorocha" % "clipboard.js" % "2.0.1"
)

unmanagedResourceDirectories in Test += (baseDirectory.value / "target/web/public/test")
14 changes: 14 additions & 0 deletions public/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ var KEY_H = 72; // Home
var KEY_C = 67; // Create project
var KEY_ESC = 27; // De-focus

/*
* ==================================================
* = Clipboard =
* ==================================================
*/

var clipboardManager = new ClipboardJS('.copy-url');
clipboardManager.on('success', function(e) {
var element = $('.btn-download').tooltip({title: 'Copied!', placement: 'bottom', trigger: 'manual'}).tooltip('show');
setTimeout(function () {
element.tooltip('destroy');
}, 2200);
});

/*
* ==================================================
* = Helper functions =
Expand Down

0 comments on commit 7441986

Please sign in to comment.