Skip to content

Commit

Permalink
implemented copy&move of a record to another store (closes #134)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Apr 17, 2018
1 parent ee3aa2b commit bf160e4
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 5 deletions.
4 changes: 2 additions & 2 deletions arc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<script type="text/javascript" src="/js/libs/ace/ace.js"></script>
<script type="text/javascript" src="/js/libs/ace/ext-modelist.js"></script>

<script type="text/javascript" src="/js/api.js"></script>
<script type="text/javascript" src="/js/api.js?v=2"></script>
<script type="text/javascript" src="/js/encoding.js"></script>
<script type="text/javascript" src="/js/aes_cbc.js"></script>
<script type="text/javascript" src="/js/aes.js"></script>
Expand Down Expand Up @@ -178,7 +178,7 @@ <h5 class="editable" id="store_title">{{ arc.store.title }}</h5>
</li>
</ul>

<div ng-include src="'/views/modals/secret.html?v=27'"></div>
<div ng-include src="'/views/modals/secret.html?v=28'"></div>
</div>
</span>

Expand Down
7 changes: 5 additions & 2 deletions arc/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,15 @@ Arc.prototype.GetRecordBuffer = function( record_id, success, error ) {
return this.Api( 'GET', path, null, success, error, true );
};

Arc.prototype.AddRecordTo = function( record, data, store_id, success, error ) {
return this.ApiStream( 'POST', '/api/store/' + store_id + '/records', record, data, success, error );
}

Arc.prototype.AddRecord = function( record, data, success, error ) {
if( this.HasStore() == false ) {
return error("No store has been selected.");
}

return this.ApiStream( 'POST', '/api/store/' + this.store.id + '/records', record, data, success, error );
return this.AddRecordTo(record, data, this.store.id, success, error );
}

Arc.prototype.UpdateRecord = function( record, data, success, error) {
Expand Down
67 changes: 67 additions & 0 deletions arc/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,73 @@ app.controller('PMController', ['$scope', function (scope) {
}
};

scope.onShowMove = function() {
// this shouldn't happen, but better be safe than sorry :)
if( scope.secret == null ){
return;
}
scope.arc.Stores(function(stores){
var html = '';
for( var i = 0; i < stores.length; i++ ) {
var store = stores[i]
if( store.id != scope.store_id ) {
html += '<option value="' + store.id + '">' + store.title + '</option>';
}
}

$('#copy_move_title').html(scope.secret.title);
$('#copy_move_store').html(html);
$('#copy_move_modal').css('z-index', '1500').modal();
},
scope.errorHandler );
};

scope.onMove = function() {
var move = $('#copy_move_action').val() == '1';
var dest_store_id = $('#copy_move_store').val();

$('#copy_move_modal').modal('hide');
$('#secret_modal').modal('hide');

scope.showLoader("Encrypting record ...", function(){
var [ expire_at, prune, pinned, record ] = scope.buildRecord();
record.Encrypt(scope.key).then(function(data){
var action = move ? "Moving" : "Copying";
var size = data.length
scope.trackTotal = size;
scope.progressAt = new Date();
scope.uploading = true;

scope.showLoader(action + " record ...", function(){
var r = {
'title': record.title,
'expired_at': expire_at,
'prune': prune,
'pinned': pinned,
'encryption': 'aes',
'size': size
};

scope.arc.AddRecordTo( r, data, dest_store_id, function(record) {
if( move ) {
scope.arc.DeleteRecord(scope.secret, function(){
scope.setSecret(null);
scope.getStore( function() {
scope.$apply();
});
},
scope.errorHandler );
} else {
scope.getStore(function() {});
}
},
scope.errorHandler )
.uploadProgress(scope.trackProgress);
});
});
});
};

scope.showEvent = function(idx) {
var e = scope.status.events[idx];
$('#event_title').html( e.Title );
Expand Down
40 changes: 40 additions & 0 deletions arc/views/modals/copy_move.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class="modal fade" id="copy_move_modal" role="dialog" aria-hidden="true" tabindex="-1">
<div class="modal-dialog" role="document">
<div class="modal-content">


<div class="modal-header tb-container-small">
<div class="toolbar-small">
<button type="button" class="btn btn-default tb-elem btn-close-small" data-dismiss="modal">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</div>
</div>

<div class="modal-body container" id="copy_move_body">
<div class="row">

<div class="col-5">
<select class="add-on btn btn-default" style="width:100%" id="copy_move_action" name="copy_move_action">
<option value="0" selected>Copy to</option>
<option value="1">Move to</option>
</select>
</div>

<div class="col-5">
<select class="add-on btn btn-default" style="width:100%" id="copy_move_store" name="copy_move_store">
</select>
</div>

<div class="col-2">
<button class="btn btn-default" style="width:100%" type="button" ng-click="onMove()">
<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>
</button>
</div>

</div>
</div>

</div>
</div>
</div>
2 changes: 1 addition & 1 deletion arc/views/modals/secret.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div ng-include src="'/views/modals/field_selector.html?v=5'"></div>

<div ng-include src="'/views/modals/copy_move.html'"></div>
<div ng-include src="'/views/modals/password_generator.html?v=7'"></div>

<div class="modal modal-full" id="secret_modal" role="dialog" aria-hidden="true" tabindex="-1">
Expand Down
4 changes: 4 additions & 0 deletions arc/views/modals/secret.toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
</div>
</div>

<button type="button" class="btn btn-default btn-edit tb-elem" ng-click="onShowMove()">
<i class="fa fa-clipboard" aria-hidden="true"></i>
</button>

<button type="button" class="btn btn-default tb-elem btn-close" data-dismiss="modal">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
Expand Down

0 comments on commit bf160e4

Please sign in to comment.