mirror of
https://github.com/nextcloud/passman.git
synced 2025-01-26 17:30:19 +08:00
Importers now have to return a object
This commit is contained in:
parent
1a86c1b664
commit
0a39cdc582
7 changed files with 78 additions and 39 deletions
15
css/app.css
15
css/app.css
|
@ -282,13 +282,6 @@
|
|||
#app-content #app-content-wrapper .edit_credential .custom_fields table tr td, #app-content #app-content-wrapper .edit_credential .files table tr td {
|
||||
height: 50px;
|
||||
vertical-align: middle; }
|
||||
#app-content #app-content-wrapper .edit_credential .file_tab .progress {
|
||||
margin-top: 10px;
|
||||
height: 10px; }
|
||||
#app-content #app-content-wrapper .edit_credential .file_tab .progress .progress-bar {
|
||||
height: 10px;
|
||||
background-image: none;
|
||||
background-color: #0082c9; }
|
||||
#app-content #app-content-wrapper .app_sidebar {
|
||||
padding: 10px;
|
||||
overflow-y: auto; }
|
||||
|
@ -331,6 +324,14 @@
|
|||
cursor: pointer;
|
||||
margin-right: 4px; }
|
||||
|
||||
.progress {
|
||||
margin-top: 10px;
|
||||
height: 10px; }
|
||||
.progress .progress-bar {
|
||||
height: 10px;
|
||||
background-image: none;
|
||||
background-color: #0082c9; }
|
||||
|
||||
.settings-container div {
|
||||
padding-left: 15px; }
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -51,8 +51,12 @@ angular.module('passmanApp')
|
|||
};
|
||||
|
||||
var parsed_data;
|
||||
$scope.current_import_index = 0;
|
||||
$scope.current_import_length = 0;
|
||||
|
||||
$scope.import_progress = {
|
||||
progress: 0,
|
||||
loaded: 0,
|
||||
total: 0
|
||||
};
|
||||
var addCredential = function(parsed_data_index){
|
||||
if(!parsed_data[parsed_data_index]){
|
||||
return;
|
||||
|
@ -66,36 +70,54 @@ angular.module('passmanApp')
|
|||
return
|
||||
}
|
||||
_log('Adding '+ _credential.label);
|
||||
$scope.current_import_index = parsed_data_index;
|
||||
_credential.vault_id = $scope.active_vault.vault_id;
|
||||
CredentialService.createCredential(_credential).then(function (result) {
|
||||
if(result.credential_id){
|
||||
_log('Added '+ _credential.label);
|
||||
if(parsed_data[ parsed_data_index +1]) {
|
||||
$scope.import_progress = {
|
||||
progress: parsed_data_index / parsed_data.length * 100,
|
||||
loaded: parsed_data_index,
|
||||
total: parsed_data.length
|
||||
};
|
||||
|
||||
addCredential(parsed_data_index +1)
|
||||
} else {
|
||||
$scope.import_progress = {
|
||||
progress: 100,
|
||||
loaded: parsed_data.length-1,
|
||||
total: parsed_data.length-1
|
||||
};
|
||||
_log('DONE!');
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
$scope.file_read_progress = {
|
||||
percent: 0,
|
||||
loaded: 0,
|
||||
total: 0
|
||||
};
|
||||
$scope.startImport = function(){
|
||||
$scope.import_progress = 0;
|
||||
$scope.file_read_percent = 0;
|
||||
if(file_data){
|
||||
$window.PassmanImporter[$scope.selectedImporter.id]
|
||||
.readFile(file_data)
|
||||
.then(function(parseddata){
|
||||
console.log("woof!");
|
||||
$scope.file_read_percent = 100;
|
||||
parsed_data = parseddata;
|
||||
_log('Parsed '+ parsed_data.length + ' credentials, starting to import');
|
||||
$scope.current_import_length = parsed_data.length;
|
||||
if( parsed_data.length > 0){
|
||||
addCredential(0);
|
||||
} else {
|
||||
// @TODO Show message no data found
|
||||
}
|
||||
}).progress(function(percentage){
|
||||
console.log(percentage + '%');
|
||||
}).progress(function(progress){
|
||||
$scope.file_read_progress = progress;
|
||||
$scope.$apply();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ PassmanImporter.randomData = {
|
|||
}
|
||||
};
|
||||
|
||||
PassmanImporter.randomData.readFile = function (file_data,callback) {
|
||||
return new C_Promise(function(){
|
||||
PassmanImporter.randomData.readFile = function (file_data, callback) {
|
||||
return new C_Promise(function () {
|
||||
var tags =
|
||||
['Social media',
|
||||
'Hosting',
|
||||
|
@ -33,32 +33,37 @@ PassmanImporter.randomData.readFile = function (file_data,callback) {
|
|||
var credential_list = [];
|
||||
var _this = this;
|
||||
var generateCredential = function (max, i, callback) {
|
||||
if(jQuery){
|
||||
if (jQuery) {
|
||||
var url = OC.generateUrl('apps/passman/api/internal/generate_person');
|
||||
$.ajax({
|
||||
url: url,
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
success: function (data) {
|
||||
var _credential = PassmanImporter.newCredential();
|
||||
label = (Math.random() >= 0.5) ? data.domain : data.email_d +' - ' + data.email_u;
|
||||
label = (Math.random() >= 0.5) ? data.domain : data.email_d + ' - ' + data.email_u;
|
||||
_credential.label = label;
|
||||
_credential.username = data.username;
|
||||
_credential.password = data.password;
|
||||
_credential.url = data.url;
|
||||
|
||||
var tag_amount = Math.floor(Math.random()*5);
|
||||
for(var ta = 0; ta < tag_amount; ta++){
|
||||
var item = tags[Math.floor(Math.random()*tags.length)];
|
||||
var tag_amount = Math.floor(Math.random() * 5);
|
||||
for (var ta = 0; ta < tag_amount; ta++) {
|
||||
var item = tags[Math.floor(Math.random() * tags.length)];
|
||||
var tag = {
|
||||
text: item
|
||||
};
|
||||
if(_credential.tags.indexOf(tag) === -1){
|
||||
if (_credential.tags.indexOf(tag) === -1) {
|
||||
_credential.tags.push(tag);
|
||||
}
|
||||
}
|
||||
credential_list.push(_credential);
|
||||
if(i <= max){
|
||||
_this.call_progress(i/max*100);
|
||||
if (i <= max) {
|
||||
var values = {
|
||||
percent: i / max * 100,
|
||||
loaded: i,
|
||||
total: max
|
||||
};
|
||||
_this.call_progress(values);
|
||||
generateCredential(max, i + 1, callback)
|
||||
} else {
|
||||
callback(credential_list)
|
||||
|
@ -69,7 +74,7 @@ PassmanImporter.randomData.readFile = function (file_data,callback) {
|
|||
};
|
||||
|
||||
|
||||
generateCredential(9, 0,function(credential_list){
|
||||
generateCredential(10, 1, function (credential_list) {
|
||||
_this.call_then(credential_list);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -57,7 +57,7 @@ angular.module('views/partials/forms/settings/general_settings.html', []).run(['
|
|||
angular.module('views/partials/forms/settings/import.html', []).run(['$templateCache', function($templateCache) {
|
||||
'use strict';
|
||||
$templateCache.put('views/partials/forms/settings/import.html',
|
||||
'<div ng-controller="ImportCtrl"><div class="row"><div class="col-xs-6"><label>Import type<select ng-init="importerType" ng-model="importerType" ng-change="setImporter(importerType)"><option ng-repeat="importer in available_importers" value="{{importer}}">{{importer.name}}</option></select></label><div><b>{{selectedImporter.description}}</b></div><input ng-if="selectedImporter" type="file" file-select success="fileLoaded" error="fileLoadError" progress="fileSelectProgress"><br><button class="button" ng-click="startImport()" ng-if="selectedImporter">Import</button><div ng-if="current_import_length">{{ current_import_index }} / {{ current_import_length - 1}}</div></div><div class="col-xs-6"><div ng-if="log" class="import_log"><textarea id="import_log" auto-scroll="log">{{log.join(\'\\n\')}}</textarea></div></div></div></div>');
|
||||
'<div ng-controller="ImportCtrl"><div class="row"><div class="col-xs-6"><label>Import type<select ng-init="importerType" ng-model="importerType" ng-change="setImporter(importerType)"><option ng-repeat="importer in available_importers" value="{{importer}}">{{importer.name}}</option></select></label><div><b>{{selectedImporter.description}}</b></div><input ng-if="selectedImporter" type="file" file-select success="fileLoaded" error="fileLoadError" progress="fileSelectProgress"><br><button class="button" ng-click="startImport()" ng-if="selectedImporter">Import</button><div ng-if="file_read_progress.percent > 0">Read progress<div progress-bar="file_read_progress.percent"></div><br>{{ file_read_progress.loaded }} / {{ file_read_progress.total }}</div><div ng-if="import_progress.progress > 0">Upload progress<div progress-bar="import_progress.progress"></div><br>{{ import_progress.loaded }} / {{ import_progress.total }}</div></div><div class="col-xs-6"><div ng-if="log" class="import_log"><textarea id="import_log" auto-scroll="log">{{log.join(\'\\n\')}}</textarea></div></div></div></div>');
|
||||
}]);
|
||||
|
||||
angular.module('views/partials/forms/settings/sharing.html', []).run(['$templateCache', function($templateCache) {
|
||||
|
|
|
@ -197,15 +197,7 @@
|
|||
}
|
||||
}
|
||||
.file_tab {
|
||||
.progress {
|
||||
margin-top: 10px;
|
||||
height: 10px;
|
||||
.progress-bar {
|
||||
height: 10px;
|
||||
background-image: none;
|
||||
background-color: #0082c9;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
.app_sidebar {
|
||||
|
@ -269,4 +261,13 @@
|
|||
margin-right: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.progress {
|
||||
margin-top: 10px;
|
||||
height: 10px;
|
||||
.progress-bar {
|
||||
height: 10px;
|
||||
background-image: none;
|
||||
background-color: #0082c9;
|
||||
}
|
||||
}
|
|
@ -16,8 +16,18 @@
|
|||
<button class="button" ng-click="startImport()"
|
||||
ng-if="selectedImporter">Import
|
||||
</button>
|
||||
<div ng-if="current_import_length">
|
||||
{{ current_import_index }} / {{ current_import_length - 1}}
|
||||
|
||||
<div ng-if="file_read_progress.percent > 0">
|
||||
Read progress
|
||||
<div progress-bar="file_read_progress.percent"></div>
|
||||
<br />
|
||||
{{ file_read_progress.loaded }} / {{ file_read_progress.total }}
|
||||
</div>
|
||||
<div ng-if="import_progress.progress > 0">
|
||||
Upload progress
|
||||
<div progress-bar="import_progress.progress"></div>
|
||||
<br />
|
||||
{{ import_progress.loaded }} / {{ import_progress.total }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-6">
|
||||
|
|
Loading…
Reference in a new issue