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

UI improvement: added icon to copy basket URL for requests collection… #60

Merged
merged 1 commit into from
Jul 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 32 additions & 6 deletions web/basket.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
body { padding-top: 70px; }
h1 { margin-top: 2px; }
#more { margin-left: 100px; }
.copy-req-btn:hover { cursor: pointer; }
.copy-req-btn:hover,
.copy-url-btn:hover { cursor: pointer; }
</style>

<script >
Expand All @@ -26,7 +27,12 @@
return (params && params.length) ? params[1] : null;
}

function getBasketUrl() {
return window.location.protocol + "//" + window.location.host + "/" + getParam("name");
}

var name = getParam("name");
var basketUrl = getBasketUrl();
var fetchedCount = 0;
var fetchedRequests = {};
var totalCount = 0;
Expand Down Expand Up @@ -263,18 +269,31 @@
return formatted;
}

function resetCopyButtonsState() {
$(".copy-req-btn").html('<span title="Copy Request Details" class="glyphicon glyphicon-copy"></span>');
$(".copy-url-btn").html('<span title="Copy URL" class="glyphicon glyphicon-copy"></span>');
}

function copyRequest(btn) {
var button = $(btn);
var requestId = button.attr("for");

if (copyToClipboard(fetchedRequests[requestId], button.get(0))) {
// reset check
$(".copy-req-btn").html('<span title="Copy Request Details" class="glyphicon glyphicon-copy"></span>');
resetCopyButtonsState();
// mark as copied
button.html('<span title="This request is copied to your clipboard." class="glyphicon glyphicon-check"></span>');
}
}

function copyBasketUrl(btn) {
var button = $(btn);
if (copyToClipboard(basketUrl, button.get(0))) {
resetCopyButtonsState();
// mark as copied
button.html('<span title="Basket URL is copied to your clipboard." class="glyphicon glyphicon-check"></span>');
}
}

function fetchRequests() {
$.ajax({
method: "GET",
Expand Down Expand Up @@ -513,6 +532,7 @@
function shareBasket() {
var token = getBasketToken();
if (token && copyToClipboard(window.location + "&token=" + token)) {
resetCopyButtonsState();
alert("A link to share this basket was copied to your clipboard.");
}
}
Expand Down Expand Up @@ -542,7 +562,7 @@
// Initialization
$(document).ready(function() {
$("#name").html(name);
$(".basket_uri").html(window.location.protocol + "//" + window.location.host + "/" + name);
$(".basket_uri").html(basketUrl);
// dialog handlers
$("#token_dialog").on("hidden.bs.modal", function (event) {
localStorage.setItem("basket_" + name, $("#basket_token").val());
Expand Down Expand Up @@ -587,6 +607,10 @@
$("#update_response").on("click", function(event) {
updateResponse();
});
// copy basket URL
$(".copy-url-btn").on("click", function(event) {
copyBasketUrl(this);
});
// shared basket link
acceptSharedBasket();
// hide share basket button
Expand Down Expand Up @@ -794,7 +818,8 @@ <h4 class="modal-title" id="error_message_label">HTTP error</h4>
<div class="row">
<div class="col-md-8">
<h1>Basket: <span id="name"></span></h1>
<p id="requests_link" class="hide">Requests are collected at <kbd class="basket_uri"></kbd></p>
<p id="requests_link" class="hide">Requests are collected at <kbd class="basket_uri"></kbd>
<kbd class="copy-url-btn"><span title="Copy URL" class="glyphicon glyphicon-copy"></span></kbd></p>
</div>
<div class="col-md-3 col-md-offset-1">
<h4><abbr title="Current requests count (Total count)">Requests</abbr>: <span id="requests_count"></span></h4>
Expand All @@ -812,7 +837,8 @@ <h4><abbr title="Current requests count (Total count)">Requests</abbr>: <span id
<!-- Empty basket -->
<div class="jumbotron text-center hide" id="empty_basket">
<h1>Empty basket!</h1>
<p>This basket is empty, send requests to <kbd class="basket_uri"></kbd> and they will appear here.</p>
<p>This basket is empty, send requests to <kbd class="basket_uri"></kbd>
<kbd class="copy-url-btn"><span title="Copy URL" class="glyphicon glyphicon-copy"></span></kbd> and they will appear here.</p>
</div>
</div>

Expand Down
34 changes: 28 additions & 6 deletions web_basket.html.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ const (
body { padding-top: 70px; }
h1 { margin-top: 2px; }
#more { margin-left: 100px; }
.copy-req-btn:hover { cursor: pointer; }
.copy-req-btn:hover,
.copy-url-btn:hover { cursor: pointer; }
</style>

<script>
(function($) {
var basketUrl = window.location.protocol + "//" + window.location.host + "/{{.}}";
var fetchedCount = 0;
var fetchedRequests = {};
var totalCount = 0;
Expand Down Expand Up @@ -262,18 +264,31 @@ const (
return formatted;
}

function resetCopyButtonsState() {
$(".copy-req-btn").html('<span title="Copy Request Details" class="glyphicon glyphicon-copy"></span>');
$(".copy-url-btn").html('<span title="Copy URL" class="glyphicon glyphicon-copy"></span>');
}

function copyRequest(btn) {
var button = $(btn);
var requestId = button.attr("for");

if (copyToClipboard(fetchedRequests[requestId], button.get(0))) {
// reset check
$(".copy-req-btn").html('<span title="Copy Request Details" class="glyphicon glyphicon-copy"></span>');
resetCopyButtonsState();
// mark as copied
button.html('<span title="This request is copied to your clipboard." class="glyphicon glyphicon-check"></span>');
}
}

function copyBasketUrl(btn) {
var button = $(btn);
if (copyToClipboard(basketUrl, button.get(0))) {
resetCopyButtonsState();
// mark as copied
button.html('<span title="Basket URL is copied to your clipboard." class="glyphicon glyphicon-check"></span>');
}
}

function fetchRequests() {
$.ajax({
method: "GET",
Expand Down Expand Up @@ -515,6 +530,7 @@ const (
function shareBasket() {
var token = getBasketToken();
if (token && copyToClipboard(window.location + "?token=" + token)) {
resetCopyButtonsState();
alert("A link to share this basket was copied to your clipboard.");
}
}
Expand Down Expand Up @@ -543,7 +559,7 @@ const (

// Initialization
$(document).ready(function() {
$(".basket_uri").html(window.location.protocol + "//" + window.location.host + "/{{.}}");
$(".basket_uri").html(basketUrl);
// dialogs
$("#token_dialog").on("hidden.bs.modal", function (event) {
localStorage.setItem("basket_{{.}}", $("#basket_token").val());
Expand Down Expand Up @@ -588,6 +604,10 @@ const (
$("#update_response").on("click", function(event) {
updateResponse();
});
// copy basket URL
$(".copy-url-btn").on("click", function(event) {
copyBasketUrl(this);
});
// shared basket link
acceptSharedBasket();
// hide share basket button
Expand Down Expand Up @@ -800,7 +820,8 @@ const (
<div class="row">
<div class="col-md-8">
<h1>Basket: {{.}}</h1>
<p id="requests_link" class="hide">Requests are collected at <kbd class="basket_uri"></kbd></p>
<p id="requests_link" class="hide">Requests are collected at <kbd class="basket_uri"></kbd>
<kbd class="copy-url-btn"><span title="Copy URL" class="glyphicon glyphicon-copy"></span></kbd></p>
</div>
<div class="col-md-3 col-md-offset-1">
<h4><abbr title="Current requests count (Total count)">Requests</abbr>: <span id="requests_count"></span></h4>
Expand All @@ -818,7 +839,8 @@ const (
<!-- Empty basket -->
<div class="jumbotron text-center hide" id="empty_basket">
<h1>Empty basket!</h1>
<p>This basket is empty, send requests to <kbd class="basket_uri"></kbd> and they will appear here.</p>
<p>This basket is empty, send requests to <kbd class="basket_uri"></kbd>
<kbd class="copy-url-btn"><span title="Copy URL" class="glyphicon glyphicon-copy"></span></kbd> and they will appear here.</p>
</div>
</div>

Expand Down