From 1d8890ae9b885b969b4d11f5a1f11ea83981e486 Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Thu, 7 Apr 2022 15:42:12 +0200 Subject: [PATCH 01/10] feat(device): add transfer capabilties Add transfer view and functionality to edit device page --- app/index.html | 1 + app/scripts/app.js | 10 +++ .../controllers/account.box.edit.transfer.js | 70 +++++++++++++++++++ app/scripts/services/account.js | 41 ++++++++++- .../services/authenticationInterceptor.js | 1 + app/views/account.box.edit.html | 1 + app/views/account.box.edit.transfer.html | 40 +++++++++++ 7 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 app/scripts/controllers/account.box.edit.transfer.js create mode 100644 app/views/account.box.edit.transfer.html diff --git a/app/index.html b/app/index.html index 68dda2f5..dbe4a7ed 100644 --- a/app/index.html +++ b/app/index.html @@ -422,6 +422,7 @@ + diff --git a/app/scripts/app.js b/app/scripts/app.js index 33833063..cd9a5d5d 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -347,6 +347,16 @@ }, }, }) + .state('account.edit.transfer', { + url: '/transfer', + views: { + edit: { + controller: 'EditBoxTransferController', + controllerAs: 'transfer', + templateUrl: 'views/account.box.edit.transfer.html', + }, + }, + }) .state('account.dashboard', { url: '', views: { diff --git a/app/scripts/controllers/account.box.edit.transfer.js b/app/scripts/controllers/account.box.edit.transfer.js new file mode 100644 index 00000000..7603281f --- /dev/null +++ b/app/scripts/controllers/account.box.edit.transfer.js @@ -0,0 +1,70 @@ +(function () { + 'use strict'; + + angular + .module('openSenseMapApp') + .controller('EditBoxTransferController', EditBoxTransferController); + + EditBoxTransferController.$inject = ['boxData', 'AccountService']; + + function EditBoxTransferController (boxData, AccountService) { + var vm = this; + vm.device = {}; + vm.deviceName = ''; + vm.data = {}; + + vm.transferDevice = transferDevice; + vm.revokeToken = revokeToken; + + activate(); + + //// + + function activate () { + if (angular.isDefined(boxData)) { + angular.copy(boxData, vm.device); + + return AccountService.getTransferToken(vm.device._id) + .then(function (response) { + angular.copy(response.data, vm.data); + }) + .catch(function (error) { + console.log(error); + }); + } + } + + function transferDevice () { + + var payload = { + boxId: vm.device._id + }; + + return AccountService.transferDevice(payload) + .then(function (response) { + angular.copy(response.data, vm.data); + }) + .catch(function (error) { + console.log(error); + }); + } + + function revokeToken () { + var payload = { + boxId: vm.device._id, + token: vm.data.token + }; + + return AccountService.revokeToken(payload) + .then(function (response) { + if (response.status === 204) { + angular.copy({}, vm.data); + } + }) + .catch(function (error) { + console.log(error); + }); + } + + } +})(); diff --git a/app/scripts/services/account.js b/app/scripts/services/account.js index 89fa3496..b2ce140e 100644 --- a/app/scripts/services/account.js +++ b/app/scripts/services/account.js @@ -27,7 +27,10 @@ deleteMeasurement: deleteMeasurement, postNewBox: postNewBox, deleteAccount: deleteAccount, - compileSketch: compileSketch + compileSketch: compileSketch, + transferDevice: transferDevice, + revokeToken: revokeToken, + getTransferToken: getTransferToken }; return service; @@ -246,5 +249,41 @@ }) .catch(failed); } + + function getTransferToken (boxId) { + return $http + .get(app.API_URL + '/boxes/transfer/' + boxId, { + auth: true, + }) + .then(function (response) { + return response.data; + }) + .catch(failed); + } + + function transferDevice (data) { + return $http.post(app.API_URL + '/boxes/transfer', data, { + auth: true, + }) + .then(function (response) { + return response.data; + }) + .catch(failed); + } + + function revokeToken (data) { + return $http + .delete(app.API_URL + '/boxes/transfer', { + auth: true, + data: data, + headers: { + 'Content-type': 'application/json;charset=utf-8', + }, + }) + .then(function (response) { + return response; + }) + .catch(failed); + } } })(); diff --git a/app/scripts/services/authenticationInterceptor.js b/app/scripts/services/authenticationInterceptor.js index 03be6818..a5301f5f 100644 --- a/app/scripts/services/authenticationInterceptor.js +++ b/app/scripts/services/authenticationInterceptor.js @@ -54,6 +54,7 @@ }); return deferred.promise; + case 400: case 404: return $q.reject(response); default: diff --git a/app/views/account.box.edit.html b/app/views/account.box.edit.html index f415b8c6..e7b6c022 100644 --- a/app/views/account.box.edit.html +++ b/app/views/account.box.edit.html @@ -19,6 +19,7 @@
  • {{'EDIT_SCRIPT'|translate}}
  • {{'EDIT_MQTTOPTIONS'|translate}}
  • {{'EDIT_TTN'|translate}}
  • +
  • {{'EDIT_TRANSFER'|translate}}
  • diff --git a/app/views/account.box.edit.transfer.html b/app/views/account.box.edit.transfer.html new file mode 100644 index 00000000..f8dd0723 --- /dev/null +++ b/app/views/account.box.edit.transfer.html @@ -0,0 +1,40 @@ +
    +
    +
    +

    {{'EDIT_TRANSFER'|translate}}

    +
    +
    + +
    + +
    +

    + + Transfer this device to another user. +

    +
    +

    + Um den Transfer durchzuführen, klicke auf ___ und du bekommst einen Token angezeigt. + Diesen Token gibst du weiter an den neuen Besitzer. Der neue Besitzer muss in seinem Account auf ___ klicken und den Token + eingeben. Danach wird das Gerät in den neuen Account transferiert. +

    + Der Transfer kann sich verzögern, bis der neue Eigentümer den Token eingegeben hat. +

    +
    + +
    + Transfer Token: {{transfer.data.token}} - Expires at: {{transfer.data.expiresAt}} + +
    + +
    +
    + + +
    +
    + +
    +
    + +
    \ No newline at end of file From 3807dd2de3b80e2f6a933b77d0d46b228a18f7b9 Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Thu, 7 Apr 2022 16:08:16 +0200 Subject: [PATCH 02/10] Add basic claim functionality to dashboard --- app/scripts/controllers/account.dashboard.js | 17 +++++++++++++++++ app/scripts/controllers/header.js | 1 - app/scripts/services/account.js | 13 ++++++++++++- app/views/account.dashboard.html | 19 ++++++++++++++++++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/app/scripts/controllers/account.dashboard.js b/app/scripts/controllers/account.dashboard.js index 0be21c9d..317e92f8 100644 --- a/app/scripts/controllers/account.dashboard.js +++ b/app/scripts/controllers/account.dashboard.js @@ -15,6 +15,9 @@ vm.boxes = []; vm.listStyle = 'tiles'; vm.orderByProperty = 'createdAt'; + vm.claimToken = ''; + + vm.claimDevice = claimDevice; activate(); @@ -47,6 +50,20 @@ }); } + function claimDevice () { + var payload = { + token: vm.claimToken + }; + + return AccountService.claimDevice(payload) + .then(function (response) { + console.log(response); + }) + .catch(function (error) { + console.log(error); + }); + } + $scope.$watch('dashboard.listStyle', function (value) { LocalStorageService.setValue(localStorageKey, value); }); diff --git a/app/scripts/controllers/header.js b/app/scripts/controllers/header.js index dc880710..bcf753d7 100644 --- a/app/scripts/controllers/header.js +++ b/app/scripts/controllers/header.js @@ -207,7 +207,6 @@ }); $rootScope.$on('osemAnnouncementClosed', function () { - console.log('header closed'); vm.showAnnouncment = false; }); } diff --git a/app/scripts/services/account.js b/app/scripts/services/account.js index b2ce140e..6b0dc2bc 100644 --- a/app/scripts/services/account.js +++ b/app/scripts/services/account.js @@ -30,7 +30,8 @@ compileSketch: compileSketch, transferDevice: transferDevice, revokeToken: revokeToken, - getTransferToken: getTransferToken + getTransferToken: getTransferToken, + claimDevice: claimDevice }; return service; @@ -285,5 +286,15 @@ }) .catch(failed); } + + function claimDevice (data) { + return $http.post(app.API_URL + '/boxes/claim', data, { + auth: true + }) + .then(function (response) { + return response; + }) + .catch(failed); + } } })(); diff --git a/app/views/account.dashboard.html b/app/views/account.dashboard.html index 5788bdbe..3d814eb7 100644 --- a/app/views/account.dashboard.html +++ b/app/views/account.dashboard.html @@ -1,6 +1,6 @@
    -
    +

    @@ -16,6 +16,23 @@

    +
    +
    +

    Du möchtest ein Gerät von einem anderen Benutzer übernehmen?

    + + +

    Gib hier den Token ein, den du bekommen hast:

    +
    + + + + +
    +
    +
    +

    +
    From d0e4ca1bfa54091a53b8dd8112920d3e2ac37515 Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Fri, 8 Apr 2022 15:45:46 +0200 Subject: [PATCH 06/10] Wrap input-group in form-group --- app/views/account.dashboard.html | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/views/account.dashboard.html b/app/views/account.dashboard.html index 8c1877aa..1bde35a9 100644 --- a/app/views/account.dashboard.html +++ b/app/views/account.dashboard.html @@ -23,14 +23,16 @@

    Du möchtest ein Gerät von einem anderen Benutzer übernehmen?

    -

    Gib hier den Token ein, den du bekommen hast:

    -
    - - - - -
    - This is not a valid token!
    +
    + +
    + + + + +
    + This is not a valid token!
    +
    From 1b2c95dd11629b7460b9dfba0cd3f57363bb185e Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Fri, 8 Apr 2022 15:56:05 +0200 Subject: [PATCH 07/10] Add alert on errors --- app/scripts/controllers/account.dashboard.js | 7 +++++++ app/views/account.dashboard.html | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/app/scripts/controllers/account.dashboard.js b/app/scripts/controllers/account.dashboard.js index 20bad1c8..e85b8278 100644 --- a/app/scripts/controllers/account.dashboard.js +++ b/app/scripts/controllers/account.dashboard.js @@ -17,8 +17,10 @@ vm.orderByProperty = 'createdAt'; vm.claimToken = ''; vm.claimPattern = /^[a-z0-9]*$/; + vm.errorMessage = ''; vm.claimDevice = claimDevice; + vm.closeAlert = closeAlert; activate(); @@ -71,9 +73,14 @@ }) .catch(function (error) { console.log(error); + vm.errorMessage = error.message; }); } + function closeAlert () { + vm.errorMessage = ''; + } + $scope.$watch('dashboard.listStyle', function (value) { LocalStorageService.setValue(localStorageKey, value); }); diff --git a/app/views/account.dashboard.html b/app/views/account.dashboard.html index 1bde35a9..a5db25ae 100644 --- a/app/views/account.dashboard.html +++ b/app/views/account.dashboard.html @@ -34,6 +34,12 @@

    Du möchtest ein Gerät von einem anderen Benutzer übernehmen?

    This is not a valid token!
    +
    From 61404644eabb7e568e26d3c7cd9717bb76ed3293 Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Thu, 14 Apr 2022 12:10:30 +0200 Subject: [PATCH 08/10] Reorganize dashboard styling --- app/views/account.dashboard.html | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/views/account.dashboard.html b/app/views/account.dashboard.html index a5db25ae..cf2acd58 100644 --- a/app/views/account.dashboard.html +++ b/app/views/account.dashboard.html @@ -1,7 +1,8 @@
    -
    -
    -
    + +
    +
    +

    {{'REGISTERED_BOXES_INFO' | translate}}

    @@ -16,12 +17,10 @@

    -
    +
    +

    Du möchtest ein Gerät von einem anderen Benutzer übernehmen?

    - -
    @@ -43,7 +42,10 @@

    Du möchtest ein Gerät von einem anderen Benutzer übernehmen?

    +
    + +
    -
    +
    From 5d92ac8e313392b2ef43d22c18839352b4443dd9 Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Thu, 14 Apr 2022 13:15:16 +0200 Subject: [PATCH 09/10] Style transfer settings page --- .../controllers/account.box.edit.transfer.js | 17 +++- app/views/account.box.edit.transfer.html | 83 +++++++++++++------ 2 files changed, 69 insertions(+), 31 deletions(-) diff --git a/app/scripts/controllers/account.box.edit.transfer.js b/app/scripts/controllers/account.box.edit.transfer.js index 7603281f..dbdc63d2 100644 --- a/app/scripts/controllers/account.box.edit.transfer.js +++ b/app/scripts/controllers/account.box.edit.transfer.js @@ -5,13 +5,15 @@ .module('openSenseMapApp') .controller('EditBoxTransferController', EditBoxTransferController); - EditBoxTransferController.$inject = ['boxData', 'AccountService']; + EditBoxTransferController.$inject = ['boxData', 'moment', 'AccountService']; - function EditBoxTransferController (boxData, AccountService) { + function EditBoxTransferController (boxData, moment, AccountService) { var vm = this; vm.device = {}; vm.deviceName = ''; vm.data = {}; + vm.tokenExists = false; + vm.expiration = '1'; vm.transferDevice = transferDevice; vm.revokeToken = revokeToken; @@ -26,7 +28,10 @@ return AccountService.getTransferToken(vm.device._id) .then(function (response) { - angular.copy(response.data, vm.data); + if (response.data) { + angular.copy(response.data, vm.data); + vm.tokenExists = true; + } }) .catch(function (error) { console.log(error); @@ -37,12 +42,15 @@ function transferDevice () { var payload = { - boxId: vm.device._id + boxId: vm.device._id, + date: moment.utc().add(vm.expiration, 'd') + .toDate() }; return AccountService.transferDevice(payload) .then(function (response) { angular.copy(response.data, vm.data); + vm.tokenExists = true; }) .catch(function (error) { console.log(error); @@ -59,6 +67,7 @@ .then(function (response) { if (response.status === 204) { angular.copy({}, vm.data); + vm.tokenExists = false; } }) .catch(function (error) { diff --git a/app/views/account.box.edit.transfer.html b/app/views/account.box.edit.transfer.html index f8dd0723..861421db 100644 --- a/app/views/account.box.edit.transfer.html +++ b/app/views/account.box.edit.transfer.html @@ -1,4 +1,4 @@ - +

    {{'EDIT_TRANSFER'|translate}}

    @@ -7,34 +7,63 @@

    {{'EDIT_TRANSFER'|translate}} -
    -

    - - Transfer this device to another user. -

    -
    -

    - Um den Transfer durchzuführen, klicke auf ___ und du bekommst einen Token angezeigt. - Diesen Token gibst du weiter an den neuen Besitzer. Der neue Besitzer muss in seinem Account auf ___ klicken und den Token - eingeben. Danach wird das Gerät in den neuen Account transferiert. -

    - Der Transfer kann sich verzögern, bis der neue Eigentümer den Token eingegeben hat. -

    -
    +
    +
    -
    - Transfer Token: {{transfer.data.token}} - Expires at: {{transfer.data.expiresAt}} - -
    +
    +

    + + Transfer this device to another user. +

    +
    +

    + Um den Transfer durchzuführen, klicke auf ___ und du bekommst einen Token angezeigt. + Diesen Token gibst du weiter an den neuen Besitzer. Der neue Besitzer muss in seinem Account auf ___ klicken + und den Token + eingeben. Danach wird das Gerät in den neuen Account transferiert. +

    + Der Transfer kann sich verzögern, bis der neue Eigentümer den Token eingegeben hat. +

    +
    -
    -
    - - -
    -
    - +
    +
    +
    + +
    + + Created at: {{transfer.data.createdAt | amUtc | amLocal | amDateFormat:'l LTS'}} + + Token: + {{transfer.data.token}} +
    + Expires at: {{transfer.data.expiresAt | amUtc | amLocal | amDateFormat:'l LTS'}} +
    +
    +
    + +
    + +
    + + +
    +
    + + +
    +
    + +
    + +
    - \ No newline at end of file +
    \ No newline at end of file From c1ac5be5eb4376f709a0189d70d2f8ac2d5fe352 Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Thu, 21 Apr 2022 12:16:39 +0200 Subject: [PATCH 10/10] Add translation keys --- app/views/account.box.edit.transfer.html | 33 ++++++++++-------------- app/views/account.dashboard.html | 8 +++--- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/app/views/account.box.edit.transfer.html b/app/views/account.box.edit.transfer.html index 861421db..1f5297c1 100644 --- a/app/views/account.box.edit.transfer.html +++ b/app/views/account.box.edit.transfer.html @@ -13,31 +13,24 @@

    {{'EDIT_TRANSFER'|translate}}

    - Transfer this device to another user. + {{'TRANSFER_NOTICE' | translate}}


    -

    - Um den Transfer durchzuführen, klicke auf ___ und du bekommst einen Token angezeigt. - Diesen Token gibst du weiter an den neuen Besitzer. Der neue Besitzer muss in seinem Account auf ___ klicken - und den Token - eingeben. Danach wird das Gerät in den neuen Account transferiert. -

    - Der Transfer kann sich verzögern, bis der neue Eigentümer den Token eingegeben hat. -

    +

    - +
    - Created at: {{transfer.data.createdAt | amUtc | amLocal | amDateFormat:'l LTS'}} + {{'CREATED_AT' | translate}}: {{transfer.data.createdAt | amUtc | amLocal | amDateFormat:'l LTS'}} Token: {{transfer.data.token}}
    - Expires at: {{transfer.data.expiresAt | amUtc | amLocal | amDateFormat:'l LTS'}} + {{'EXPIRES_AT' | translate}}: {{transfer.data.expiresAt | amUtc | amLocal | amDateFormat:'l LTS'}}
    @@ -45,21 +38,21 @@

    {{'EDIT_TRANSFER'|translate}}
    - +
    - +
    - +

    diff --git a/app/views/account.dashboard.html b/app/views/account.dashboard.html index cf2acd58..2f03e0c6 100644 --- a/app/views/account.dashboard.html +++ b/app/views/account.dashboard.html @@ -20,17 +20,17 @@

    -

    Du möchtest ein Gerät von einem anderen Benutzer übernehmen?

    +

    {{'CLAIM_HEADER' | translate}}

    - +
    - +
    - This is not a valid token!
    + {{'CLAIM_VALID_TOKEN' | translate}}