Skip to content

Commit

Permalink
alfio-event#91 add additional field
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed May 6, 2016
1 parent 37bc58c commit d2b140f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ dependencies {
compileOnly "javax.servlet:javax.servlet-api:3.1.0"
testCompile "javax.servlet:javax.servlet-api:3.1.0"
testRuntime "org.springframework.boot:spring-boot-starter-test"
testCompile "net.sourceforge.htmlunit:htmlunit:2.21"
runtime "org.hsqldb:hsqldb:2.3.3"
runtime "commons-fileupload:commons-fileupload:1.3.1"
providedCompile "org.springframework.boot:spring-boot-starter-web@jar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public ValidationResult updateExistingCategory(@PathVariable("eventId") int even
public ValidationResult createCategory(@PathVariable("eventId") int eventId, @RequestBody TicketCategoryModification category, Errors errors, Principal principal) {
return validateCategory(category, errors).ifSuccess(() -> eventManager.insertCategory(eventId, category, principal.getName()));
}

@RequestMapping(value = "/events/reallocate", method = PUT)
public String reallocateTickets(@RequestBody TicketAllocationModification form) {
eventManager.reallocateTickets(form.getSrcCategoryId(), form.getTargetCategoryId(), form.getEventId());
Expand Down Expand Up @@ -351,6 +351,12 @@ public List<DynamicFieldTemplate> loadTemplates() {
public void saveAdditionalFieldDescriptions(@RequestBody Map<String, TicketFieldDescriptionModification> descriptions) {
eventManager.updateTicketFieldDescriptions(descriptions);
}

@RequestMapping(value = "/events/{eventName}/additional-field/new", method = POST)
public void addAdditionalField(@PathVariable("eventName") String eventName, @RequestBody EventModification.AdditionalField field, Principal principal) {
Event event = eventManager.getSingleEvent(eventName, principal.getName());
eventManager.addAdditionalField(event.getId(), field);
}

@RequestMapping(value = "/events/{eventName}/pending-payments")
public List<SerializablePair<TicketReservation, OrderSummary>> getPendingPayments(@PathVariable("eventName") String eventName, Principal principal) {
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/alfio/manager/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import alfio.model.PromoCodeDiscount.DiscountType;
import alfio.model.Ticket.TicketStatus;
import alfio.model.modification.*;
import alfio.model.modification.EventModification.AdditionalField;
import alfio.model.system.Configuration;
import alfio.model.system.ConfigurationKeys;
import alfio.model.transaction.PaymentProxy;
Expand Down Expand Up @@ -187,16 +188,20 @@ private void createOrUpdateEventDescription(int eventId, EventModification em) {
private void createAdditionalFields(int eventId, EventModification em) {
if (!CollectionUtils.isEmpty(em.getTicketFields())) {
em.getTicketFields().forEach(f -> {
List<String> restrictedValues = Optional.ofNullable(f.getRestrictedValues()).orElseGet(Collections::emptyList).stream().map(EventModification.RestrictedValue::getValue).collect(Collectors.toList());
String serializedRestrictedValues = "select".equals(f.getType()) ? Json.GSON.toJson(restrictedValues) : null;
int configurationId = ticketFieldRepository.insertConfiguration(eventId, f.getName(), f.getOrder(), f.getType(), serializedRestrictedValues, f.getMaxLength(), f.getMinLength(), f.isRequired()).getKey();
f.getDescription().forEach((locale, value) -> {
ticketFieldRepository.insertDescription(configurationId, locale, Json.GSON.toJson(value));
});
insertAdditionalField(eventId, f, f.getOrder());
});
}
}

private void insertAdditionalField(int eventId, AdditionalField f, int order) {
List<String> restrictedValues = Optional.ofNullable(f.getRestrictedValues()).orElseGet(Collections::emptyList).stream().map(EventModification.RestrictedValue::getValue).collect(Collectors.toList());
String serializedRestrictedValues = "select".equals(f.getType()) ? Json.GSON.toJson(restrictedValues) : null;
int configurationId = ticketFieldRepository.insertConfiguration(eventId, f.getName(), order, f.getType(), serializedRestrictedValues, f.getMaxLength(), f.getMinLength(), f.isRequired()).getKey();
f.getDescription().forEach((locale, value) -> {
ticketFieldRepository.insertDescription(configurationId, locale, Json.GSON.toJson(value));
});
}

public void updateEventHeader(Event original, EventModification em, String username) {
checkOwnership(original, username, em.getOrganizationId());
int eventId = original.getId();
Expand Down Expand Up @@ -619,6 +624,11 @@ public void updateTicketFieldDescriptions(Map<String, TicketFieldDescriptionModi
}
});
}

public void addAdditionalField(int eventId, AdditionalField field) {
int order = ticketFieldRepository.countAdditionalFieldsForEvent(eventId);
insertAdditionalField(eventId, field, order);
}

@Data
private static final class GeolocationResult {
Expand All @@ -641,4 +651,6 @@ public ZoneId getZoneId() {
return tz.toZoneId();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h3>Add field</h3>
</div>
<div class="modal-body">

<form name="addField" ng-submit="addField(field)">
<form name="addFieldForm" ng-submit="addField(addFieldForm, field)">

<div class="row">
<div class="col-md-4">
Expand All @@ -13,7 +13,9 @@ <h3>Add field</h3>
</div>
<div class="form-group">
<label>Type</label>
<select ng-model="field.type" ng-options="option for option in fieldTypes" class="form-control" required></select>
<select ng-model="field.type" ng-options="option for option in fieldTypes" class="form-control" required>
<option></option>
</select>
</div>
</div>
<div class="col-md-4" ng-if="field.type != 'country'">
Expand Down
10 changes: 6 additions & 4 deletions src/main/webapp/resources/js/admin/ng-app/admin-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,11 +839,13 @@
return (selectedLanguages & lang) > 0;
};

$scope.addField = function(field) {
//FIXME;
$scope.addField = function(form, field) {
EventService.addField($stateParams.eventName, field).then(function(result) {
return loadData();
}).then(function() {
$scope.$close(true);
});
};


}});
};

Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/resources/js/admin/service/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
saveFieldDescription: function(eventName, fieldDescription) {
return $http.post('/admin/api/events/'+eventName+'/additional-field/descriptions', fieldDescription)
},
addField: function(eventName, field) {
return $http.post('/admin/api/events/'+eventName+'/additional-field/new', field);
}
};
});

Expand Down

0 comments on commit d2b140f

Please sign in to comment.