upload roomplan
This commit is contained in:
13
src/main/java/de/mbremer/room/RoomFileForm.java
Normal file
13
src/main/java/de/mbremer/room/RoomFileForm.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package de.mbremer.room;
|
||||
|
||||
import org.jboss.resteasy.annotations.providers.multipart.PartType;
|
||||
|
||||
import javax.ws.rs.FormParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class RoomFileForm {
|
||||
@FormParam("file")
|
||||
@PartType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public InputStream file;
|
||||
}
|
||||
67
src/main/java/de/mbremer/room/RoomResource.java
Normal file
67
src/main/java/de/mbremer/room/RoomResource.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package de.mbremer.room;
|
||||
|
||||
import io.quarkus.qute.Template;
|
||||
import io.quarkus.qute.TemplateInstance;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
|
||||
@Path("/room")
|
||||
@ApplicationScoped
|
||||
public class RoomResource {
|
||||
|
||||
public static final int MAX_PLANSIZE_IN_BYTES = 1000 * 1024;
|
||||
@Inject
|
||||
Logger log;
|
||||
@Inject
|
||||
SecurityIdentity identity;
|
||||
@Inject
|
||||
Template room;
|
||||
|
||||
private byte[] roomPlan = new byte[0];
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
@RolesAllowed({"USER", "ADMIN"})
|
||||
public TemplateInstance getRoom() {
|
||||
return room
|
||||
.data("is_admin", identity.hasRole("ADMIN"));
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/plan")
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
@RolesAllowed({"ADMIN"})
|
||||
public TemplateInstance uploadRoomplan(@MultipartForm RoomFileForm roomFileForm) throws IOException {
|
||||
byte[] newRoomPlan = roomFileForm.file.readAllBytes();
|
||||
int newPlanSize = newRoomPlan.length;
|
||||
|
||||
TemplateInstance room = getRoom();
|
||||
// validate
|
||||
log.info("Uploaded " + newPlanSize + " Bytes Roomplan" );
|
||||
if (newPlanSize > MAX_PLANSIZE_IN_BYTES) {
|
||||
room.data("error", "Raumplan ist zu groß: " + newPlanSize + " Bytes. Maximal " + MAX_PLANSIZE_IN_BYTES + " Bytes erlaubt.");
|
||||
} else {
|
||||
roomPlan = newRoomPlan;
|
||||
}
|
||||
return room;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/plan")
|
||||
@Produces("image/*")
|
||||
@RolesAllowed({"USER", "ADMIN"})
|
||||
public Response getImage(@PathParam("image") String image) {
|
||||
|
||||
return roomPlan.length < 1 ? Response.noContent().build() : Response.ok(roomPlan).build();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<div class="navbar-nav mr-auto">
|
||||
<a class="nav-item nav-link {#insert kalender_active}{/}" href="/kalender">Kalender</a>
|
||||
<a class="nav-item nav-link {#insert room_active}{/}" href="/room">Raum</a>
|
||||
<a class="nav-item nav-link {#insert user_active}{/}" href="/user">Benutzer</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
19
src/main/resources/templates/room.html
Normal file
19
src/main/resources/templates/room.html
Normal file
@@ -0,0 +1,19 @@
|
||||
{#include base.html}
|
||||
{#room_active}active{/}
|
||||
{#contents}
|
||||
|
||||
{#if is_admin}
|
||||
<div class="mt-2">
|
||||
<form action="/room/plan" method="POST" enctype="multipart/form-data">
|
||||
<label id="filelabel" class="btn btn-secondary" for="fileinput">
|
||||
Raumplan auswählen...
|
||||
</label>
|
||||
<input id="fileinput" type="file" name="file" accept="image/*" hidden
|
||||
onchange="document.getElementById('filelabel').innerHTML = 'Datei: ' + this.files[0].name;" />
|
||||
<input class="btn btn-primary" type="submit" value="Upload" />
|
||||
</form>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{/contents}
|
||||
{/include}
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
<div class="mt-2" >
|
||||
{#if is_admin}
|
||||
<a class="btn btn-primary btn" data-bs-toggle="modal" data-bs-target="#userModal" role="button">neuer Benutzer</a>
|
||||
<a class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#userModal" role="button">neuer Benutzer</a>
|
||||
{/if}
|
||||
<a class="btn btn-primary btn" data-bs-toggle="modal" data-bs-target="#passwordModal" role="button">Passwort ändern</a>
|
||||
<a class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#passwordModal" role="button">Passwort ändern</a>
|
||||
{#if is_admin}
|
||||
{#include user-modal.html}{/include}
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user