-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(device): add transfer capabilties (#446)
* feat(device): add transfer capabilties Add transfer view and functionality to edit device page * Add basic claim functionality to dashboard * Refresh devices after claiming * Remove unused variables * Add form and use pattern for validation * Wrap input-group in form-group * Add alert on errors * Reorganize dashboard styling * Style transfer settings page * Add translation keys
- Loading branch information
Showing
9 changed files
with
273 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('openSenseMapApp') | ||
.controller('EditBoxTransferController', EditBoxTransferController); | ||
|
||
EditBoxTransferController.$inject = ['boxData', 'moment', '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; | ||
|
||
activate(); | ||
|
||
//// | ||
|
||
function activate () { | ||
if (angular.isDefined(boxData)) { | ||
angular.copy(boxData, vm.device); | ||
|
||
return AccountService.getTransferToken(vm.device._id) | ||
.then(function (response) { | ||
if (response.data) { | ||
angular.copy(response.data, vm.data); | ||
vm.tokenExists = true; | ||
} | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
}); | ||
} | ||
} | ||
|
||
function transferDevice () { | ||
|
||
var payload = { | ||
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); | ||
}); | ||
} | ||
|
||
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); | ||
vm.tokenExists = false; | ||
} | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
}); | ||
} | ||
|
||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
}); | ||
|
||
return deferred.promise; | ||
case 400: | ||
case 404: | ||
return $q.reject(response); | ||
default: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<div class="transferSettings"> | ||
<div class="row"> | ||
<div class="col-md-6 col-lg-6"> | ||
<h2 style="margin-top: 0px; margin-bottom: 0px">{{'EDIT_TRANSFER'|translate}}</h2> | ||
</div> | ||
</div> | ||
|
||
<hr> | ||
|
||
<div class="row"> | ||
<div class="col-md-6 col-lg-6"> | ||
|
||
<div uib-alert class="alert-warning"> | ||
<p> | ||
<span class="fa fa-exclamation-circle" aria-hidden="true"></span> | ||
{{'TRANSFER_NOTICE' | translate}} | ||
</p> | ||
<hr> | ||
<p ng-bind-html="'TRANSFER_INFORMATION'|translate"></p> | ||
</div> | ||
|
||
<div ng-show="transfer.tokenExists" style="border: 1px solid grey; border-radius: 6px;"> | ||
<div style="min-height: inherit; padding: 8px; box-sizing: border-box;"> | ||
<div style="display: flex; float: right; box-sizing: border-box;"> | ||
<button ng-click="transfer.revokeToken()" class="btn btn-danger">{{'REVOKE' | translate}}</button> | ||
</div> | ||
<small style="margin-right: 8px; float: right;"> | ||
{{'CREATED_AT' | translate}}: {{transfer.data.createdAt | amUtc | amLocal | amDateFormat:'l LTS'}} | ||
</small> | ||
<span>Token:</span> | ||
<code>{{transfer.data.token}} <button osem-clipboard class="btn-toClipboard" text="transfer.data.token" title="Copy to Clipboard"><i class="fa fa-clipboard"></i></button></code> | ||
<div> | ||
<span>{{'EXPIRES_AT' | translate}}: {{transfer.data.expiresAt | amUtc | amLocal | amDateFormat:'l LTS'}}</span> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div ng-hide="transfer.tokenExists"> | ||
<form name="tokenForm" novalidate> | ||
<div class="form-group"> | ||
<label for="expiration">{{'EXPIRATION' | translate}}</label> | ||
<select class="form-control" ng-model="transfer.expiration" ng-change="transfer.changeExpiration()" name="expiration" id="expiration"> | ||
<option value="1">1 {{'DAY' | translate}}</option> | ||
<option value="7">7 {{'DAYS' | translate}}</option> | ||
<option value="30">30 {{'DAYS' | translate}}</option> | ||
<option value="60">60 {{'DAYS' | translate}}</option> | ||
<option value="90">90 {{'DAYS' | translate}}</option> | ||
</select> | ||
</div> | ||
<div class="form-group" > | ||
<label class="control-label" translate="TRANSFER_INPUT_LABEL" translate-value-name="{{transfer.device.name}}"></label> | ||
<input type="text" name="name" id="name" class="form-control" ng-model="transfer.deviceName" required> | ||
</div> | ||
<div class="form-group"> | ||
<button ng-disabled="transfer.deviceName !== transfer.device.name" ng-click="transfer.transferDevice()" class="btn btn-danger col-md-12">{{'TRANSFER_BUTTON_TEXT' | translate}}</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters