fixes #126: progress bar and ability to not deduplicate entries
This commit is contained in:
parent
f338da9078
commit
09035932ad
3 changed files with 32 additions and 10 deletions
|
@ -19,8 +19,16 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="submit" value="{{'Import' | translate}}" ng-click="upload(file, '/ebcsvpersons')" />
|
<input type="checkbox" ng-model="deduplicate"> {{'deduplicate entries' | translate}}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<br />
|
||||||
|
<input type="submit" value="{{'Import' | translate}}" ng-click="upload(file, '/ebcsvpersons')" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group top5">
|
||||||
|
<uib-progressbar class="progress-striped" ng-class="{active: progressbarType == 'warning'}" max="100" value="progress" type="progressbarType">{{progress}}%</uib-progressbar>
|
||||||
|
</div>
|
||||||
<div class="form-group top5">
|
<div class="form-group top5">
|
||||||
Result: total: <span>{{reply.total}}</span> valid: <span>{{reply.valid}}</span> new: <span>{{reply.new_in_event}}</span>
|
Result: total: <span>{{reply.total}}</span> valid: <span>{{reply.valid}}</span> new: <span>{{reply.new_in_event}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
13
angular_app/js/controllers.js
vendored
13
angular_app/js/controllers.js
vendored
|
@ -771,19 +771,26 @@ eventManControllers.controller('UsersCtrl', ['$scope', '$rootScope', '$state', '
|
||||||
eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'Event',
|
eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'Event',
|
||||||
function ($scope, $log, $upload, Event) {
|
function ($scope, $log, $upload, Event) {
|
||||||
$scope.file = null;
|
$scope.file = null;
|
||||||
|
$scope.progress = 0;
|
||||||
|
$scope.progressbarType = 'warning';
|
||||||
|
$scope.deduplicate = false;
|
||||||
$scope.reply = {};
|
$scope.reply = {};
|
||||||
$scope.events = Event.all();
|
$scope.events = Event.all();
|
||||||
$scope.upload = function(file, url) {
|
$scope.upload = function(file, url) {
|
||||||
$log.debug("FileUploadCtrl.upload");
|
$log.debug("FileUploadCtrl.upload");
|
||||||
|
$scope.progress = 0;
|
||||||
|
$scope.progressbarType = 'warning';
|
||||||
$upload.upload({
|
$upload.upload({
|
||||||
url: url,
|
url: url,
|
||||||
file: file,
|
file: file,
|
||||||
fields: {targetEvent: $scope.targetEvent}
|
fields: {targetEvent: $scope.targetEvent, deduplicate: $scope.deduplicate}
|
||||||
}).progress(function(evt) {
|
}).progress(function(evt) {
|
||||||
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
|
$scope.progress = parseInt(100.0 * evt.loaded / evt.total);
|
||||||
$log.debug('progress: ' + progressPercentage + '%');
|
$log.debug('progress: ' + $scope.progress + '%');
|
||||||
}).success(function(data, status, headers, config) {
|
}).success(function(data, status, headers, config) {
|
||||||
$scope.file = null;
|
$scope.file = null;
|
||||||
|
$scope.progress = 100;
|
||||||
|
$scope.progressbarType = 'success';
|
||||||
$scope.reply = angular.fromJson(data);
|
$scope.reply = angular.fromJson(data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1034,20 +1034,25 @@ class EbCSVImportPersonsHandler(BaseHandler):
|
||||||
event_handler.db = self.db
|
event_handler.db = self.db
|
||||||
event_handler.logger = self.logger
|
event_handler.logger = self.logger
|
||||||
event_id = None
|
event_id = None
|
||||||
|
deduplicate = False
|
||||||
try:
|
try:
|
||||||
event_id = self.get_body_argument('targetEvent')
|
event_id = self.get_body_argument('targetEvent')
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
deduplicate = self.tobool(self.get_body_argument('deduplicate'))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
if event_id is None:
|
if event_id is None:
|
||||||
return self.build_error('invalid event')
|
return self.build_error('invalid event')
|
||||||
reply = dict(total=0, valid=0, merged=0, new_in_event=0)
|
reply = dict(total=0, valid=0, merged=0, new_in_event=0)
|
||||||
event_details = event_handler.db.query('events', {'_id': event_id})
|
event_details = event_handler.db.query('events', {'_id': event_id})
|
||||||
if not event_details:
|
if not event_details:
|
||||||
return self.build_error('invalid event')
|
return self.build_error('invalid event')
|
||||||
all_emails = set()
|
all_persons = set()
|
||||||
#[x.get('email') for x in (event_details[0].get('tickets') or []) if x.get('email')])
|
#[x.get('email') for x in (event_details[0].get('tickets') or []) if x.get('email')])
|
||||||
for ticket in (event_details[0].get('tickets') or []):
|
for ticket in (event_details[0].get('tickets') or []):
|
||||||
all_emails.add('%s_%s_%s' % (ticket.get('name'), ticket.get('surname'), ticket.get('email')))
|
all_persons.add('%s_%s_%s' % (ticket.get('name'), ticket.get('surname'), ticket.get('email')))
|
||||||
for fieldname, contents in self.request.files.items():
|
for fieldname, contents in self.request.files.items():
|
||||||
for content in contents:
|
for content in contents:
|
||||||
filename = content['filename']
|
filename = content['filename']
|
||||||
|
@ -1060,10 +1065,12 @@ class EbCSVImportPersonsHandler(BaseHandler):
|
||||||
person['attended'] = False
|
person['attended'] = False
|
||||||
person['from_file'] = filename
|
person['from_file'] = filename
|
||||||
self.add_access_info(person)
|
self.add_access_info(person)
|
||||||
duplicate_check = '%s_%s_%s' % (person.get('name'), person.get('surname'), person.get('email'))
|
if deduplicate:
|
||||||
if duplicate_check in all_emails:
|
duplicate_check = '%s_%s_%s_%s' % (person.get('name'), person.get('surname'),
|
||||||
|
person.get('email'), person.get('order_nr'))
|
||||||
|
if duplicate_check in all_persons:
|
||||||
continue
|
continue
|
||||||
all_emails.add(duplicate_check)
|
all_persons.add(duplicate_check)
|
||||||
event_handler.handle_post_tickets(event_id, None, person)
|
event_handler.handle_post_tickets(event_id, None, person)
|
||||||
reply['new_in_event'] += 1
|
reply['new_in_event'] += 1
|
||||||
self.write(reply)
|
self.write(reply)
|
||||||
|
|
Loading…
Reference in a new issue