Skip to content

Commit

Permalink
Feature/1031 add alias-input field when adding new env (#801)
Browse files Browse the repository at this point in the history
* feat: add name alias input field to adding envs

* feat: add validation to add-environments-form

* feat: add validation to endpoint

* chore: remove console log, change form to div

* chore: improve getTitle in env edit modal

* feat: context name should not be blank

* fix: fix rebase error
  • Loading branch information
BeriBoss authored Nov 20, 2024
1 parent 108d4fa commit 38f8694
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
<div class="container">
<app-modal-header [title]="getTitle() + ' ' + environment.name" (cancel)="cancel()"></app-modal-header>
<app-modal-header [title]="getTitle()" (cancel)="cancel()"></app-modal-header>
<div class="modal-body">
<div class="mb-3">
<div class="needs-validation mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" [(ngModel)]="environment.name" />
</div>
@if (isEdit() && !isDomain()){
<div class="mb-3">
<label for="nameAlias" class="form-label">Alias</label>
<input type="text" class="form-control" id="nameAlias" [(ngModel)]="environment.nameAlias" />
<input type="text" class="form-control" id="name" [(ngModel)]="environment.name" required pattern=".*\S+.*">
<div class="invalid-feedback">
Please enter a name
</div>
</div>
@if (!isDomain()) {
<div class="mb-3">
<label for="nameAlias" class="form-label">Alias</label>
<input type="text" class="form-control" id="nameAlias" [(ngModel)]="environment.nameAlias"/>
</div>
}
</div>
<div class="modal-footer">
<app-button [variant]="'light'" (click)="cancel()">Cancel</app-button>
@if(permissions().canSave){
<app-button [variant]="'primary'" (click)="save()">Save</app-button>
@if (permissions().canSave) {
<app-button [variant]="'primary'"
[disabled]="!isValidForm()"
(click)="save()">Save
</app-button>
}
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class EnvironmentEditComponent {
getTitle(): string {
if (!this.environment) return;
return this.environment.id
? `Edit ${this.isDomain() ? 'domain' : 'environment'}`
? `Edit ${this.isDomain() ? 'domain' : 'environment'} ${this.environment.name}`
: `Add ${this.isDomain() ? 'domain' : 'environment'}`;
}

Expand All @@ -41,17 +41,21 @@ export class EnvironmentEditComponent {
return this.environment.parentName === this.globalName;
}

isEdit(): boolean {
if (!this.environment) return;
return !!this.environment.id;
}

cancel() {
this.activeModal.close();
}

save() {
this.saveEnvironment.emit(this.environment);
this.activeModal.close();
let forms: NodeListOf<Element> = document.querySelectorAll('.needs-validation');
if (this.isValidForm()) {
this.saveEnvironment.emit(this.environment);
this.activeModal.close();
} else {
forms[0].classList.add('was-validated');
}
}

isValidForm() {
return this.environment.name.trim().length !== 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void saveEnvironment(Integer contextId, String newContextName, String con
* Erstellt einen neuen Context anhand den Name und den superContext. Der Kontext ist an einen Benutzer zugewisen
*/
@HasPermission(permission = Permission.ADD_NEW_ENV_OR_DOM)
public ContextEntity createContextByName(String newName, Integer superContextId) throws ResourceNotFoundException, ElementAlreadyExistsException {
public ContextEntity createContextByName(String newName, String newAliasName, Integer superContextId) throws ResourceNotFoundException, ElementAlreadyExistsException {
try {
if (getContextByName(newName) != null) {
String message = "Der Kontext mit dem Namen " + newName + " ist bereits vorhanden und kann nicht erstellen werden";
Expand All @@ -113,6 +113,8 @@ public ContextEntity createContextByName(String newName, Integer superContextId)
throw new ResourceNotFoundException("Der Superkontext mit der Id " + superContextId + " konnte nicht gefunden werden");
}
entity.setName(newName);
if(newAliasName != null)
entity.setNameAlias(newAliasName);
entity.setContextType(resourceTypeProvider.getOrCreateContextType(contextName));
entityManager.persist(entity);
return entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ch.puzzle.itc.mobiliar.common.exception.AMWException;
import ch.puzzle.itc.mobiliar.common.exception.ElementAlreadyExistsException;
import ch.puzzle.itc.mobiliar.common.exception.ResourceNotFoundException;
import ch.puzzle.itc.mobiliar.common.exception.ValidationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
Expand Down Expand Up @@ -60,8 +61,9 @@ public List<EnvironmentDTO> getContexts() {
@POST
@Path("/contexts")
@ApiOperation(value = "Add new context")
public Response addContext(@ApiParam() EnvironmentDTO request) throws ElementAlreadyExistsException, ResourceNotFoundException {
environmentsScreenDomainService.createContextByName(request.getName(), request.getParentId());
public Response addContext(@ApiParam() EnvironmentDTO request) throws ElementAlreadyExistsException, ResourceNotFoundException, ValidationException {
if(request.getName() == null || request.getName().trim().isEmpty()) throw new ValidationException("Context name must not be null or blank");
environmentsScreenDomainService.createContextByName(request.getName(), request.getNameAlias(), request.getParentId());
return Response.status(Response.Status.OK).build();
}

Expand Down

0 comments on commit 38f8694

Please sign in to comment.