Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Michiii11 committed Oct 4, 2024
1 parent 6ec4137 commit 822b711
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Device> devices;
try{
return CCResponse.ok(deviceSetRepository.getAll());
return CCResponse.ok(deviceSetRepository.getAll(filters));
}catch (CCException ex){
return CCResponse.error(ex);
}
Expand Down
1 change: 0 additions & 1 deletion backend/src/main/java/at/camconnect/dtos/DeviceDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Long> deviceTypeIds, DeviceStatus status, List<Long> tagIds) {
public record DeviceSetCreateDTO (Long id, String name, String description, List<Long> deviceTypeIds, DeviceTypeStatusEnum status, List<Tag> tags) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package at.camconnect.dtos.deviceSet;

public record DeviceSetFullDTO() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public record DeviceTypeFilters(
boolean onlyAvailable,
List<DeviceTypeVariantEnum> variants,
List<Long> attributes,
List<Long> tags
List<Long> tags,
String searchTerm
) { }
12 changes: 8 additions & 4 deletions backend/src/main/java/at/camconnect/model/DeviceSet.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +24,7 @@ public class DeviceSet {
private List<DeviceType> device_types;

@Enumerated(EnumType.STRING)
private DeviceStatus status;
private DeviceTypeStatusEnum status;

@ManyToMany(fetch = FetchType.EAGER)
private List<Tag> tags;
Expand All @@ -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() {
Expand Down Expand Up @@ -94,11 +98,11 @@ public void setDevice_types(List<DeviceType> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,26 +17,36 @@ public class DeviceSetRepository {
@Inject
EntityManager em;

public List<DeviceSet> getAll(){
public List<DeviceSet> getAll(DeviceTypeFilters filters){
List<DeviceSet> 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);
deviceSet.getDevice_types().add(deviceType);
}
}

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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ public List<AutocompleteNumberOptionDTO<DeviceTypeMinimalDTO>> search(String sea
}

public List<DeviceTypeFullDTO> getAllFull(DeviceTypeFilters filters) {
List<DeviceType> deviceTypeList = em.createQuery("" +
List<DeviceType> 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<DeviceTypeFullDTO> list = new LinkedList<>();
Expand Down Expand Up @@ -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<DeviceTypeFullDTO> deviceTypeList = getAllFull(new DeviceTypeFilters(false, null, null, null));
List<DeviceTypeFullDTO> deviceTypeList = getAllFull(new DeviceTypeFilters(false, null, null, null, null));
for (DeviceTypeFullDTO deviceType : deviceTypeList) {
try {
writer.write(deviceType.deviceType().toGlobalDTO().toCsvString());
Expand All @@ -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<DeviceTypeFullDTO> deviceTypeList = getAllFull(new DeviceTypeFilters(false,null, null, null));
List<DeviceTypeFullDTO> deviceTypeList = getAllFull(new DeviceTypeFilters(false,null, null, null, null));
for (DeviceTypeFullDTO deviceType : deviceTypeList) {
writer.write(deviceType.deviceType().toGlobalDTO().toCsvString());
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion frontend/web/src/AppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class DeviceSetEditEntryComponent extends LitElement {
return html`
<style>${styles}</style>
<h3 class="children">${this.deviceSet.name}</h3>
<h3>${this.deviceSet.name}</h3>
<!-- todo für yanik <cc-line type="${Orientation.VERTICAL}"></cc-line>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppState>(this, model.appState);
Expand All @@ -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;
Expand Down Expand Up @@ -117,7 +120,6 @@ export class EditDeviceSetModalComponent extends LitElement {

getModalContent() {
this.tags = this.element.tags;
console.log(this.element)
return html`
<h1>Gerät-Set Erstellen</h1>
<div class="contentByDeviceType">
Expand Down Expand Up @@ -186,29 +188,29 @@ export class EditDeviceSetModalComponent extends LitElement {
<cc-autocomplete label="Tags" class="tagSelector" color="${ColorEnum.GRAY}"
size="${SizeEnum.MEDIUM}"
.onSelect="${(option: Tag) => {
this.tags.push(option);
if (this.isEditMode) {
DeviceSetService.toggleTag(option, this.elementId)
} else {
this.element.tags.push(option);
}
}}"
if (this.isEditMode) {
DeviceSetService.toggleTag(option, this.elementId)
this.tags.push(option);
} else {
this.element.tags.push(option);
}
}}"
.querySuggestions="${TagService.search}"
.contentProvider="${(data: Tag) => {
return `${data.name}`
}}"
return `${data.name}`
}}"
.iconProvider="${() => {
return html`${unsafeSVG(icon(faTag).html[0])}`
}}">
return html`${unsafeSVG(icon(faTag).html[0])}`
}}">
</cc-autocomplete>
<div>
${this.tags.map(elem => {
return html`
<cc-chip text="${elem.name}" color="${ColorEnum.GRAY}" type="${ChipType.REMOVABLE}"
@click="${() => {
this.tags.slice(this.tags.indexOf(elem), 1);
if (this.isEditMode) {
DeviceSetService.toggleTag(elem, this.elementId)
this.tags.slice(this.tags.indexOf(elem), 1);
} else{
this.element.tags.slice(this.element.tags.indexOf(elem), 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export class EditDeviceTypeModalComponent extends LitElement {
if (this.element == null) {
return html`
<style>${styles}</style>
<h1>Gerätetyp Erstellen</h1>
<h1>Model erstellen</h1>
<h2>Gerätetyp</h2>
<div class="selectType">
${model.deviceTypeNameFilterOptions.value.map(option => {
return html`
Expand All @@ -66,6 +69,17 @@ export class EditDeviceTypeModalComponent extends LitElement {
</div>`;
})}
</div>
<h2>Geräte-Set</h2>
<div class="selectType">
<div @click="${() => {
model.appState.value.openOverlay(html`<cc-edit-device-set-modal .isEditMode="${false}"></cc-edit-device-set-modal>`, () => {})
}}">
${DeviceTypeService.deviceTypeToIcon(DeviceTypeVariantEnum.simple)}
Geräte-Set
</div>
</div>
`;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/web/src/components/app/rentListEntry.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
}
Expand Down
1 change: 0 additions & 1 deletion frontend/web/src/components/navigation/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
17 changes: 13 additions & 4 deletions frontend/web/src/service/deviceSet.service.ts
Original file line number Diff line number Diff line change
@@ -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{
Expand All @@ -10,7 +10,7 @@ export interface DeviceSetCreateDTO{
description: string,
deviceTypeIds: number[],
tags: Tag[],
status: DeviceStatus
status: DeviceTypeVariantEnum
}

export interface DeviceSet {
Expand All @@ -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[]>("/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<DeviceFilterDTO, DeviceSet[]>("/deviceset/getall", deviceFiltersForBackend)
.then(result => {
model.loadDeviceSets(result.data)
})
Expand All @@ -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) {
Expand Down
Loading

0 comments on commit 822b711

Please sign in to comment.