From 9f44f918cc11b822ef9a8bdb034bacd04da8d3a5 Mon Sep 17 00:00:00 2001 From: Marko Zivanovic Date: Wed, 26 Nov 2014 21:46:58 +0100 Subject: [PATCH] Frontend improvements. --- .../secret/api/controllers/SasController.java | 4 +- src/main/resources/static/index.html | 61 ++++++++++++++----- src/main/resources/static/js/app.js | 3 +- src/main/resources/static/js/controllers.js | 25 +++++--- src/main/resources/static/sas.css | 19 +----- 5 files changed, 66 insertions(+), 46 deletions(-) diff --git a/src/main/java/rs/in/zivanovic/share/a/secret/api/controllers/SasController.java b/src/main/java/rs/in/zivanovic/share/a/secret/api/controllers/SasController.java index b6fdf67..1481fc6 100644 --- a/src/main/java/rs/in/zivanovic/share/a/secret/api/controllers/SasController.java +++ b/src/main/java/rs/in/zivanovic/share/a/secret/api/controllers/SasController.java @@ -58,8 +58,8 @@ public class SasController { return SasResponse.badRequest().withInvalidParameterValueError("threshold", params.getThreshold(), "must not be grater than 'total' (" + String.valueOf(params.getTotal()) + ")").build(); } - List shares = ShamirSecretSharing.split(params.getSecret(), params.getTotal(), params. - getThreshold()); + List shares = ShamirSecretSharing.split(params.getSecret(), params.getTotal(), + params.getThreshold()); return SasResponse.ok().withData(new Shares(shares)).build(); } } diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index 7934919..cc92be3 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -10,34 +10,41 @@ - + + + +
-
-
- +
+ +
-
+
- +
-
+
- +

-
+
@@ -47,18 +54,40 @@

Whoops, something's wrong ...

-
+
{{err.message}}
-
-
+
+
+

Here are your secret shares ...

-
-
{{share}}
-
+ + + + List +
+
+

Click on a share to select it for easy copying to clipboard. + After clicking it, the share will change color to indicate the ones you have already copied.

+
+
{{share}}
+
+
+
+
+ + Text +
+
+

Use this panel to easily copy all shares at once.

+ +
+
+
+
diff --git a/src/main/resources/static/js/app.js b/src/main/resources/static/js/app.js index 5072b11..90c3087 100644 --- a/src/main/resources/static/js/app.js +++ b/src/main/resources/static/js/app.js @@ -24,6 +24,7 @@ angular.module('sasApp', [ 'ngResource', + 'ui.bootstrap', 'sasControllers', 'sasServices' ]).directive('selectOnClick', function ($window) { @@ -37,5 +38,5 @@ angular.module('sasApp', [ selection.addRange(range); }); } - } + }; }); diff --git a/src/main/resources/static/js/controllers.js b/src/main/resources/static/js/controllers.js index 0124b0a..35180e8 100644 --- a/src/main/resources/static/js/controllers.js +++ b/src/main/resources/static/js/controllers.js @@ -32,18 +32,19 @@ angular.module('sasControllers', []). var clickedShares = {}; $scope.isShareClicked = function (share) { - console.log('iA: ' + JSON.stringify(clickedShares)); - console.log('iO: ' + clickedShares[share]); return clickedShares[share] !== undefined; }; $scope.shareClicked = function (share) { - console.log('cA: ' + JSON.stringify(clickedShares)); - console.log('cO: ' + clickedShares[share]); clickedShares[share] = true; }; $scope.split = function () { + if ($scope.secret === undefined || $scope.secret.length === 0 || + $scope.total === undefined || Number($scope.total) > 100 || + $scope.threshold === undefined || Number($scope.threshold) > 99) { + return; + } $scope.errors = []; $scope.shares = []; clickedShares = {}; @@ -52,17 +53,23 @@ angular.module('sasControllers', []). total: $scope.total, threshold: $scope.threshold}, function (response) { - console.log(JSON.stringify(response)); if (response.status === 'OK') { $scope.shares = response.data.shares; + $scope.sharesAsText = mergeSharesToString(response.data.shares); } else { $scope.errors = response.errors; - console.log("Errors: " + JSON.stringify(response.errors)); } }, function (response) { - console.log(JSON.stringify(response)); $scope.errors = response.data.errors; - console.log("Errors: " + JSON.stringify(response.data.errors)); }); }; - }]); \ No newline at end of file + }]); + +function mergeSharesToString(shares) { + var res = ""; + for (var i in shares) { + res = res + shares[i] + (i < shares.length - 1 ? "\n" : ""); + } + return res; +} + diff --git a/src/main/resources/static/sas.css b/src/main/resources/static/sas.css index eae1421..e8cf3de 100644 --- a/src/main/resources/static/sas.css +++ b/src/main/resources/static/sas.css @@ -1,18 +1 @@ -/* Sticky footer styles --------------------------------------------------- */ -html { - position: relative; - min-height: 100%; -} -body { - /* Margin bottom by footer height */ - margin-bottom: 60px; -} -.footer { - position: absolute; - bottom: 0; - width: 100%; - /* Set the fixed height of the footer here */ - height: 60px; - background-color: #f5f5f5; -} +.nav, .pagination, .carousel, .panel-title a { cursor: pointer; }