From 822b71116dd0985addea66a4cd61871ff562df74 Mon Sep 17 00:00:00 2001 From: Michael Leisch Date: Fri, 4 Oct 2024 07:38:43 +0200 Subject: [PATCH] #120 --- .../boundary/DeviceSetResource.java | 8 +++-- .../java/at/camconnect/dtos/DeviceDTO.java | 1 - .../dtos/deviceSet/DeviceSetCreateDTO.java | 4 ++- .../dtos/deviceSet/DeviceSetFullDTO.java | 4 +++ .../dtos/filters/DeviceTypeFilters.java | 3 +- .../java/at/camconnect/model/DeviceSet.java | 12 +++++--- .../repository/DeviceRepository.java | 2 -- .../repository/DeviceSetRepository.java | 19 +++++++++--- .../repository/DeviceTypeRepository.java | 10 ++++--- .../src/main/resources/application.properties | 2 +- frontend/web/src/AppState.ts | 2 +- .../app/edit/deviceSetEditEntry.component.ts | 2 +- .../app/edit/editDeviceSetModal.component.ts | 30 ++++++++++--------- .../app/edit/editDeviceTypeModal.component.ts | 16 +++++++++- .../components/app/rentListEntry.component.ts | 2 +- .../components/navigation/navbar.component.ts | 1 - frontend/web/src/service/deviceSet.service.ts | 17 ++++++++--- .../web/src/service/deviceType.service.ts | 6 ++-- .../app/edit/deviceTypeEditEntry.styles.scss | 16 ++++++++++ 19 files changed, 111 insertions(+), 46 deletions(-) create mode 100644 backend/src/main/java/at/camconnect/dtos/deviceSet/DeviceSetFullDTO.java diff --git a/backend/src/main/java/at/camconnect/boundary/DeviceSetResource.java b/backend/src/main/java/at/camconnect/boundary/DeviceSetResource.java index 2023acd2..5c8308bb 100644 --- a/backend/src/main/java/at/camconnect/boundary/DeviceSetResource.java +++ b/backend/src/main/java/at/camconnect/boundary/DeviceSetResource.java @@ -1,6 +1,7 @@ package at.camconnect.boundary; import at.camconnect.dtos.deviceSet.DeviceSetCreateDTO; +import at.camconnect.dtos.filters.DeviceTypeFilters; import at.camconnect.model.Device; import at.camconnect.model.DeviceType; import at.camconnect.repository.DeviceSetRepository; @@ -19,12 +20,13 @@ public class DeviceSetResource { @Inject DeviceSetRepository deviceSetRepository; - @GET + @POST @Path("/getall") - public Response getAll() { + @Consumes(MediaType.APPLICATION_JSON) + public Response getAll(DeviceTypeFilters filters){ List devices; try{ - return CCResponse.ok(deviceSetRepository.getAll()); + return CCResponse.ok(deviceSetRepository.getAll(filters)); }catch (CCException ex){ return CCResponse.error(ex); } diff --git a/backend/src/main/java/at/camconnect/dtos/DeviceDTO.java b/backend/src/main/java/at/camconnect/dtos/DeviceDTO.java index 6a4fa8b0..256d08e7 100644 --- a/backend/src/main/java/at/camconnect/dtos/DeviceDTO.java +++ b/backend/src/main/java/at/camconnect/dtos/DeviceDTO.java @@ -2,7 +2,6 @@ import at.camconnect.enums.DeviceStatus; -import java.time.LocalDate; import java.time.LocalDateTime; public record DeviceDTO(Long device_id, String serial, String number, String note, Long type_id, LocalDateTime creation_date, LocalDateTime change_date, DeviceStatus status) { diff --git a/backend/src/main/java/at/camconnect/dtos/deviceSet/DeviceSetCreateDTO.java b/backend/src/main/java/at/camconnect/dtos/deviceSet/DeviceSetCreateDTO.java index dfac0b70..12215741 100644 --- a/backend/src/main/java/at/camconnect/dtos/deviceSet/DeviceSetCreateDTO.java +++ b/backend/src/main/java/at/camconnect/dtos/deviceSet/DeviceSetCreateDTO.java @@ -1,8 +1,10 @@ package at.camconnect.dtos.deviceSet; import at.camconnect.enums.DeviceStatus; +import at.camconnect.enums.DeviceTypeStatusEnum; +import at.camconnect.model.Tag; import java.util.List; -public record DeviceSetCreateDTO (Long id, String name, String description, List deviceTypeIds, DeviceStatus status, List tagIds) { +public record DeviceSetCreateDTO (Long id, String name, String description, List deviceTypeIds, DeviceTypeStatusEnum status, List tags) { } diff --git a/backend/src/main/java/at/camconnect/dtos/deviceSet/DeviceSetFullDTO.java b/backend/src/main/java/at/camconnect/dtos/deviceSet/DeviceSetFullDTO.java new file mode 100644 index 00000000..bb9fe5b3 --- /dev/null +++ b/backend/src/main/java/at/camconnect/dtos/deviceSet/DeviceSetFullDTO.java @@ -0,0 +1,4 @@ +package at.camconnect.dtos.deviceSet; + +public record DeviceSetFullDTO() { +} diff --git a/backend/src/main/java/at/camconnect/dtos/filters/DeviceTypeFilters.java b/backend/src/main/java/at/camconnect/dtos/filters/DeviceTypeFilters.java index 1dfd6e48..e1d85752 100644 --- a/backend/src/main/java/at/camconnect/dtos/filters/DeviceTypeFilters.java +++ b/backend/src/main/java/at/camconnect/dtos/filters/DeviceTypeFilters.java @@ -9,5 +9,6 @@ public record DeviceTypeFilters( boolean onlyAvailable, List variants, List attributes, - List tags + List tags, + String searchTerm ) { } diff --git a/backend/src/main/java/at/camconnect/model/DeviceSet.java b/backend/src/main/java/at/camconnect/model/DeviceSet.java index be0d22d0..23991aa0 100644 --- a/backend/src/main/java/at/camconnect/model/DeviceSet.java +++ b/backend/src/main/java/at/camconnect/model/DeviceSet.java @@ -1,9 +1,11 @@ package at.camconnect.model; import at.camconnect.enums.DeviceStatus; +import at.camconnect.enums.DeviceTypeStatusEnum; import jakarta.persistence.*; import java.time.LocalDateTime; +import java.util.LinkedList; import java.util.List; @Entity @@ -22,7 +24,7 @@ public class DeviceSet { private List device_types; @Enumerated(EnumType.STRING) - private DeviceStatus status; + private DeviceTypeStatusEnum status; @ManyToMany(fetch = FetchType.EAGER) private List tags; @@ -32,10 +34,12 @@ public class DeviceSet { private LocalDateTime creation_date; private LocalDateTime change_date; - public DeviceSet(String name, String description, DeviceStatus status) { + public DeviceSet(String name, String description, DeviceTypeStatusEnum status) { this.name = name; this.description = description; this.status = status; + this.device_types = new LinkedList<>(); + this.tags = new LinkedList<>(); } public DeviceSet() { @@ -94,11 +98,11 @@ public void setDevice_types(List device_types) { this.device_types = device_types; } - public DeviceStatus getStatus() { + public DeviceTypeStatusEnum getStatus() { return status; } - public void setStatus(DeviceStatus status) { + public void setStatus(DeviceTypeStatusEnum status) { this.status = status; } diff --git a/backend/src/main/java/at/camconnect/repository/DeviceRepository.java b/backend/src/main/java/at/camconnect/repository/DeviceRepository.java index 0554bae8..1c7ebd8b 100644 --- a/backend/src/main/java/at/camconnect/repository/DeviceRepository.java +++ b/backend/src/main/java/at/camconnect/repository/DeviceRepository.java @@ -3,9 +3,7 @@ import at.camconnect.dtos.AutocompleteNumberOptionDTO; import at.camconnect.dtos.DeviceDTO; import at.camconnect.dtos.DeviceSearchDTO; -import at.camconnect.dtos.rent.RentDTO; import at.camconnect.enums.DeviceStatus; -import at.camconnect.enums.DeviceTypeStatusEnum; import at.camconnect.enums.RentStatusEnum; import at.camconnect.model.Rent; import at.camconnect.responseSystem.CCException; diff --git a/backend/src/main/java/at/camconnect/repository/DeviceSetRepository.java b/backend/src/main/java/at/camconnect/repository/DeviceSetRepository.java index 014101f0..3eb4719a 100644 --- a/backend/src/main/java/at/camconnect/repository/DeviceSetRepository.java +++ b/backend/src/main/java/at/camconnect/repository/DeviceSetRepository.java @@ -1,6 +1,7 @@ package at.camconnect.repository; import at.camconnect.dtos.deviceSet.DeviceSetCreateDTO; +import at.camconnect.dtos.filters.DeviceTypeFilters; import at.camconnect.model.DeviceSet; import at.camconnect.model.DeviceType; import at.camconnect.model.Tag; @@ -16,16 +17,27 @@ public class DeviceSetRepository { @Inject EntityManager em; - public List getAll(){ + public List getAll(DeviceTypeFilters filters){ + List deviceSetList = em.createQuery( + "select ds from DeviceSet ds " + + "where ds.status = 'active' " + + "and upper(ds.name) like :name" + , DeviceSet.class) + .setParameter("name", "%" + filters.searchTerm().toUpperCase() + "%") + .getResultList(); + return em.createQuery("SELECT d FROM DeviceSet d order by d.id", DeviceSet.class).getResultList(); } @Transactional public void create(DeviceSetCreateDTO dto){ + System.out.println(dto); DeviceSet deviceSet = new DeviceSet(dto.name(), dto.description(), dto.status()); em.persist(deviceSet); em.flush(); + System.out.println(deviceSet); + if(dto.deviceTypeIds() != null) { for (Long deviceTypeId : dto.deviceTypeIds()) { DeviceType deviceType = em.find(DeviceType.class, deviceTypeId); @@ -33,9 +45,8 @@ public void create(DeviceSetCreateDTO dto){ } } - if(dto.tagIds() != null) { - for (Long tagId : dto.tagIds()) { - Tag tag = em.find(Tag.class, tagId); + if(dto.tags() != null) { + for (Tag tag : dto.tags()) { deviceSet.getTags().add(tag); } } diff --git a/backend/src/main/java/at/camconnect/repository/DeviceTypeRepository.java b/backend/src/main/java/at/camconnect/repository/DeviceTypeRepository.java index af40d9f4..cf3f24c7 100644 --- a/backend/src/main/java/at/camconnect/repository/DeviceTypeRepository.java +++ b/backend/src/main/java/at/camconnect/repository/DeviceTypeRepository.java @@ -103,13 +103,15 @@ public List> search(String sea } public List getAllFull(DeviceTypeFilters filters) { - List deviceTypeList = em.createQuery("" + + List deviceTypeList = em.createQuery( "select dt from DeviceType dt " + "where dt.status = 'active' " + - "and (dt.variant in :variants OR :variantsEmpty = true)" + "and (dt.variant in :variants OR :variantsEmpty = true) " + + "and upper(dt.name) like :name" , DeviceType.class) .setParameter("variants", filters.variants()) .setParameter("variantsEmpty", filters.variants().isEmpty()) + .setParameter("name", "%" + filters.searchTerm().toUpperCase() + "%") .getResultList(); List list = new LinkedList<>(); @@ -212,7 +214,7 @@ public Response exportAllDeviceTypeVariants() { try (Writer writer = new BufferedWriter(new OutputStreamWriter(os))) { writer.write("type_id; name; image; autofocus; f_stop; focal_length; height_centimeters; max_range; max_weight_kilograms; needs_recorder; number_of_axis; rgb; variable_temperature; watts; needs_power; wireless; head_id; mount_id; resolution_id; sensor_id; system; flight_time_minutes; description\n"); - List deviceTypeList = getAllFull(new DeviceTypeFilters(false, null, null, null)); + List deviceTypeList = getAllFull(new DeviceTypeFilters(false, null, null, null, null)); for (DeviceTypeFullDTO deviceType : deviceTypeList) { try { writer.write(deviceType.deviceType().toGlobalDTO().toCsvString()); @@ -238,7 +240,7 @@ public Response exportDeviceTypeVariant(DeviceTypeVariantEnum variant) { try (Writer writer = new BufferedWriter(new OutputStreamWriter(os))) { writer.write("type_id; name; image; autofocus; f_stop; focal_length; height_centimeters; max_range; max_weight_kilograms; needs_recorder; number_of_axis; rgb; variable_temperature; watts; needs_power; wireless; head_id; mount_id; resolution_id; sensor_id; system; flight_time_minutes; description"); - List deviceTypeList = getAllFull(new DeviceTypeFilters(false,null, null, null)); + List deviceTypeList = getAllFull(new DeviceTypeFilters(false,null, null, null, null)); for (DeviceTypeFullDTO deviceType : deviceTypeList) { writer.write(deviceType.deviceType().toGlobalDTO().toCsvString()); } diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index a9deab25..a3d033ba 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -4,7 +4,7 @@ quarkus.http.cors.methods=GET, POST, PUT, DELETE quarkus.http.cors.headers=Content-Type, Authorization quarkus.hibernate-orm.database.generation=drop-and-create -quarkus.hibernate-orm.log.sql=true +quarkus.hibernate-orm.log.sql=false #added dont-import.qsl because quarkus will crash wehen fed a completly commented out sql script.. or maybe just our sql script quarkus.hibernate-orm.sql-load-script=import.sql diff --git a/frontend/web/src/AppState.ts b/frontend/web/src/AppState.ts index ab063acd..2cda12e2 100644 --- a/frontend/web/src/AppState.ts +++ b/frontend/web/src/AppState.ts @@ -443,7 +443,7 @@ export class AppState{ UrlHandler.setParam("searchTerm", value) this.update() if(this._page == PageEnum.RENTS) RentService.fetchAll() - if(this._page == PageEnum.EQUIPMENT) DeviceService.fetchAll() + if(this._page == PageEnum.EQUIPMENT) DeviceTypeService.fetchAllFull() } diff --git a/frontend/web/src/components/app/edit/deviceSetEditEntry.component.ts b/frontend/web/src/components/app/edit/deviceSetEditEntry.component.ts index 026e6afb..da47e66c 100644 --- a/frontend/web/src/components/app/edit/deviceSetEditEntry.component.ts +++ b/frontend/web/src/components/app/edit/deviceSetEditEntry.component.ts @@ -27,7 +27,7 @@ export class DeviceSetEditEntryComponent extends LitElement { return html` -

${this.deviceSet.name}

+

${this.deviceSet.name}

diff --git a/frontend/web/src/components/app/edit/editDeviceSetModal.component.ts b/frontend/web/src/components/app/edit/editDeviceSetModal.component.ts index 7b5d126c..0f97c6d2 100644 --- a/frontend/web/src/components/app/edit/editDeviceSetModal.component.ts +++ b/frontend/web/src/components/app/edit/editDeviceSetModal.component.ts @@ -41,6 +41,8 @@ export class EditDeviceSetModalComponent extends LitElement { startElement: DeviceSetCreateDTO | null = null; tags: Tag[] = []; + // todo if the device is in create mode it should get a warning before tabing out of the model + constructor() { super(); this.appState = new ObservedProperty(this, model.appState); @@ -55,7 +57,8 @@ export class EditDeviceSetModalComponent extends LitElement { name: "", description: "", deviceTypeIds: [], - status: DeviceStatus.ACTIVE + status: DeviceStatus.ACTIVE, + tags: [] } as DeviceSetCreateDTO; this.startElement = this.element; @@ -117,7 +120,6 @@ export class EditDeviceSetModalComponent extends LitElement { getModalContent() { this.tags = this.element.tags; - console.log(this.element) return html`

Gerät-Set Erstellen

@@ -186,29 +188,29 @@ export class EditDeviceSetModalComponent extends LitElement { + return html`${unsafeSVG(icon(faTag).html[0])}` + }}">
${this.tags.map(elem => { return html` ${model.deviceTypeNameFilterOptions.value.map(option => { return html` @@ -66,6 +69,17 @@ export class EditDeviceTypeModalComponent extends LitElement {
`; })}
+ + +

Geräte-Set

+
+
`, () => {}) + }}"> + ${DeviceTypeService.deviceTypeToIcon(DeviceTypeVariantEnum.simple)} + Geräte-Set +
+
`; } diff --git a/frontend/web/src/components/app/rentListEntry.component.ts b/frontend/web/src/components/app/rentListEntry.component.ts index bc6a9043..a5dace13 100644 --- a/frontend/web/src/components/app/rentListEntry.component.ts +++ b/frontend/web/src/components/app/rentListEntry.component.ts @@ -59,7 +59,7 @@ export class RentListEntryComponent extends LitElement { if(!this.datePicker || this.lastStatus != this.rent.status) { this.lastStatus = this.rent.status this.datePicker = new DatePickerWrapper(input, [new Date(startDate), new Date(endDate)], - async (dates) => { + async (dates) => { await RentService.updateProperty(this.rent.rent_id, 'rent_start', Util.formatDateForDb(dates[0])) RentService.updateProperty(this.rent.rent_id, 'rent_end_planned', Util.formatDateForDb(dates[1])) } diff --git a/frontend/web/src/components/navigation/navbar.component.ts b/frontend/web/src/components/navigation/navbar.component.ts index 037c3df5..8cc9b3af 100644 --- a/frontend/web/src/components/navigation/navbar.component.ts +++ b/frontend/web/src/components/navigation/navbar.component.ts @@ -162,7 +162,6 @@ export class NavbarComponent extends LitElement { handleSearchInput = Util.debounce(() => { let input = this.shadowRoot.querySelector(".search input") as HTMLInputElement model.appState.value.searchTerm = input.value - console.log("adsfaf") }) closeSearch(){ diff --git a/frontend/web/src/service/deviceSet.service.ts b/frontend/web/src/service/deviceSet.service.ts index c1296ea8..ed8f5484 100644 --- a/frontend/web/src/service/deviceSet.service.ts +++ b/frontend/web/src/service/deviceSet.service.ts @@ -1,7 +1,7 @@ import {DeviceStatus} from "./device.service" import {Api} from "../util/Api" import {model} from "../index" -import {DeviceType} from "./deviceType.service" +import {DeviceFilterDTO, DeviceType, DeviceTypeFullDTO, DeviceTypeVariantEnum} from "./deviceType.service" import {Tag} from "./tag.service" export interface DeviceSetCreateDTO{ @@ -10,7 +10,7 @@ export interface DeviceSetCreateDTO{ description: string, deviceTypeIds: number[], tags: Tag[], - status: DeviceStatus + status: DeviceTypeVariantEnum } export interface DeviceSet { @@ -19,12 +19,20 @@ export interface DeviceSet { description: string, device_types: DeviceType[], tags: Tag[], - status: DeviceStatus + status: DeviceTypeVariantEnum } export default class DeviceSetService{ static fetchAll(){ - Api.getData("/deviceset/getall") + let deviceFiltersForBackend: DeviceFilterDTO = { + onlyAvailable: model.appState.value.deviceFilters.onlyAvailable, + variants: Array.from(model.appState.value.deviceFilters.variants), + attributes: Array.from(model.appState.value.deviceFilters.attributes), + tags: Array.from(model.appState.value.deviceFilters.tags), + searchTerm: model.appState.value.searchTerm + } + + Api.postData("/deviceset/getall", deviceFiltersForBackend) .then(result => { model.loadDeviceSets(result.data) }) @@ -47,6 +55,7 @@ export default class DeviceSetService{ } static create(element: DeviceSetCreateDTO) { + console.log(element) return Api.postData("/deviceset/create", element) .then(result => { if (result.ccStatus.statusCode == 1000) { diff --git a/frontend/web/src/service/deviceType.service.ts b/frontend/web/src/service/deviceType.service.ts index f685c43b..dbb75bec 100644 --- a/frontend/web/src/service/deviceType.service.ts +++ b/frontend/web/src/service/deviceType.service.ts @@ -99,11 +99,11 @@ export interface DeviceFilterDTO{ variants: string[] attributes: number[] tags: number[] + searchTerm: string } export default class DeviceTypeService { static fetchAll(){ - Api.getData("/devicetype/getall") .then(result => { model.loadDeviceTypes(result.data) @@ -118,9 +118,11 @@ export default class DeviceTypeService { onlyAvailable: model.appState.value.deviceFilters.onlyAvailable, variants: Array.from(model.appState.value.deviceFilters.variants), attributes: Array.from(model.appState.value.deviceFilters.attributes), - tags: Array.from(model.appState.value.deviceFilters.tags) + tags: Array.from(model.appState.value.deviceFilters.tags), + searchTerm: model.appState.value.searchTerm } + Api.postData("/devicetype/getallfull", deviceFiltersForBackend) .then(result => { model.loadDeviceTypesFull(result.data) diff --git a/frontend/web/styles/components/app/edit/deviceTypeEditEntry.styles.scss b/frontend/web/styles/components/app/edit/deviceTypeEditEntry.styles.scss index 7abc7d67..2c8e3a98 100644 --- a/frontend/web/styles/components/app/edit/deviceTypeEditEntry.styles.scss +++ b/frontend/web/styles/components/app/edit/deviceTypeEditEntry.styles.scss @@ -36,6 +36,10 @@ div.edit{ div.edit{ opacity: 1 } + + div.deviceTypes{ + background-color: $gray300; + } } h3{ @@ -58,6 +62,17 @@ div{ margin-left: 1rem; width: 9vw; gap: .5rem; + + &:hover{ + z-index: 3; + } + } + + &.deviceTypes{ + transition: all $transitionTimeShort; + z-index: 2; + padding-block: .1rem; + background-color: $gray200; } cc-property-value{ @@ -72,6 +87,7 @@ cc-circle-select{ .deviceSetInfo{ gap: .5rem; + flex-wrap: wrap; span{ color: $gray800;