Skip to content

Commit

Permalink
#117 device set overview
Browse files Browse the repository at this point in the history
  • Loading branch information
Michiii11 committed Oct 1, 2024
1 parent 33ca916 commit 79bc2d7
Show file tree
Hide file tree
Showing 16 changed files with 598 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
package at.camconnect.boundary;

import at.camconnect.model.Device;
import at.camconnect.repository.DeviceSetRepository;
import at.camconnect.responseSystem.CCException;
import at.camconnect.responseSystem.CCResponse;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;

import java.util.List;

@Path("deviceset")
public class DeviceSetResource {
//TODO this and the repo

@Inject
DeviceSetRepository deviceSetRepository;

@GET
@Path("/getall")
public Response getAll() {
List<Device> devices;
try{
return CCResponse.ok(deviceSetRepository.getAll());
}catch (CCException ex){
return CCResponse.error(ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package at.camconnect.dtos.deviceSet;

import at.camconnect.enums.DeviceStatus;

import java.util.List;

public record DeviceSetCreateDTO (Long id, String name, String description, List<Long> deviceTypeIds, DeviceStatus status) {
}
70 changes: 67 additions & 3 deletions backend/src/main/java/at/camconnect/model/DeviceSet.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
package at.camconnect.model;

import at.camconnect.enums.DeviceStatus;
import jakarta.persistence.*;

import java.time.LocalDateTime;
import java.util.List;

@Entity
public class DeviceSet {
@Column(length = 20)
private String name;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(length = 4)
private Long id;

@OneToMany(fetch = FetchType.EAGER)
private String description;

@ManyToMany(fetch = FetchType.EAGER)
private List<DeviceType> device_types;

public DeviceSet(String name) {
@Enumerated(EnumType.STRING)
private DeviceStatus status;

private String image_blob;

private LocalDateTime creation_date;
private LocalDateTime change_date;

public DeviceSet(String name, String description, DeviceStatus status) {
this.name = name;
this.description = description;
this.status = status;
}

public DeviceSet() {
}

//region Getter and Setter

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getName() {
return name;
}
Expand All @@ -47,5 +71,45 @@ public List<DeviceType> getDevice_types() {
public void addDevice_type(DeviceType device_type) {
this.device_types.add(device_type);
}

public void removeDevice_type(DeviceType device_type) {
this.device_types.remove(device_type);
}

public void setDevice_types(List<DeviceType> device_types) {
this.device_types = device_types;
}

public DeviceStatus getStatus() {
return status;
}

public void setStatus(DeviceStatus status) {
this.status = status;
}

public String getImage_blob() {
return image_blob;
}

public void setImage_blob(String image_blob) {
this.image_blob = image_blob;
}

public LocalDateTime getCreation_date() {
return creation_date;
}

public void setCreation_date(LocalDateTime creation_date) {
this.creation_date = creation_date;
}

public LocalDateTime getChange_date() {
return change_date;
}

public void setChange_date(LocalDateTime change_date) {
this.change_date = change_date;
}
//endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package at.camconnect.repository;

import at.camconnect.model.DeviceSet;
import at.camconnect.model.DeviceType;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;

import java.util.List;

@ApplicationScoped
public class DeviceSetRepository {
@Inject
EntityManager em;

public List<DeviceSet> getAll(){
return em.createQuery("SELECT d FROM DeviceSet d order by d.id", DeviceSet.class).getResultList();
}
}
25 changes: 24 additions & 1 deletion backend/src/main/resources/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,30 @@ VALUES
('DJI Phantom 4', 'url4', 'drone', 'DroneType', 5, 28, true, 'active'),
('Yuneec Typhoon H Pro', 'url5', 'drone', 'DroneType', 1, 25, false, 'active');

-- assigning tags to devicetypes
-- Device Set
INSERT INTO deviceset (name, description, status)
VALUES
('Foto Set', 'Ein Set für Fotografen', 'ACTIVE'),
('Video Set', 'Ein Set für Videografen', 'ACTIVE'),
('Audio Set', 'Ein Set für Tontechniker', 'ACTIVE'),
('Light Set', 'Ein Set für Beleuchter', 'ACTIVE'),
('Simple Set', 'Ein Set für einfache Geräte', 'ACTIVE'),
('Stabilizer Set', 'Ein Set für Stabilizer', 'ACTIVE'),
('Tripod Set', 'Ein Set für Stative', 'ACTIVE'),
('Drone Set', 'Ein Set für Drohnen', 'ACTIVE');

-- Assigning devices to device sets
INSERT INTO deviceset_devicetype (deviceset_id, device_types_type_id)
VALUES
(1, 1), -- Foto Set with Canon EOS 5D Mark IV
(1, 2), -- Foto Set with Nikon D850
(1, 3), -- Foto Set with Sony Alpha a7 III
(1, 4), -- Foto Set with Fujifilm X-T3
(1, 5), -- Foto Set with Olympus OM-D E-M10 Mark III
(2, 1), -- Video Set with Canon EOS 5D Mark IV
(2, 2), -- Video Set with Nikon D850
(3, 3); -- Audio Set with Sony Alpha a7 III

-- assigning tags to devicetypes
INSERT INTO tag_devicetype (tag_tag_id, types_type_id)
VALUES
Expand Down
27 changes: 24 additions & 3 deletions frontend/web/src/AppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {KeyBoardShortCut} from "./util/KeyboardShortcut"
import {DeviceTypeEditEntryComponent} from "./components/app/edit/deviceTypeEditEntry.component"
import {DeviceEditEntryComponent} from "./components/app/edit/deviceEditEntry"
import {SidebarComponent} from "./components/navigation/sidebar.component"
import {EditType} from "./components/app/edit/edit.component"
import {DeviceSetEditEntryComponent} from "./components/app/edit/deviceSetEditEntry.component"

interface ActionCancellation {
identifier: string,
Expand Down Expand Up @@ -59,13 +61,14 @@ export interface DeviceFilters {
export class AppState{
private _page: PageEnum = PageEnum.RENTS
private _editPage: EditPageEnum = EditPageEnum.OVERVIEW;
private _editPageType: DeviceTypeVariantEnum = DeviceTypeVariantEnum.camera;
private _editPageType: EditType = DeviceTypeVariantEnum.camera;
private _createRentModalOpen: boolean = false
private _createMultiRentModalOpen: boolean = false
private _selectedRentEntries: Set<RentListEntryComponent> = new Set<RentListEntryComponent>()
private _selectedDeviceEntries: Set<DeviceListEntryComponent> = new Set<DeviceListEntryComponent>()
private _selectedDeviceTypeEditEntries: Set<DeviceTypeEditEntryComponent> = new Set<DeviceTypeEditEntryComponent>()
private _selectedDeviceEditEntries: Set<DeviceEditEntryComponent> = new Set<DeviceEditEntryComponent>()
private _selectedDeviceSetEditEntries: Set<DeviceSetEditEntryComponent> = new Set<DeviceSetEditEntryComponent>()
private _cancelCurrentAction: ActionCancellation[] = []
private _createRentElement: CreateRentComponent
private _appElement: HTMLElement
Expand Down Expand Up @@ -125,11 +128,11 @@ export class AppState{
this.update()
}

get editPageType(): DeviceTypeVariantEnum {
get editPageType(): EditType {
return this._editPageType
}

set editPageType(value: DeviceTypeVariantEnum) {
set editPageType(value: EditType) {
this._editPageType = value
this.update()
}
Expand Down Expand Up @@ -235,6 +238,10 @@ export class AppState{
return this._selectedDeviceEditEntries
}

get selectedDeviceSetEditEntries(): Set<DeviceSetEditEntryComponent> {
return this._selectedDeviceSetEditEntries
}

addSelectedRentEntry(rentEntry: RentListEntryComponent){
this.selectedRentEntries.add(rentEntry)
this.update()
Expand Down Expand Up @@ -284,6 +291,20 @@ export class AppState{
this.update()
}

toggleSelectedDeviceSetEditEntry(deviceSetEditEntry: DeviceSetEditEntryComponent){
if(this.selectedDeviceSetEditEntries.has(deviceSetEditEntry)){
this.selectedDeviceSetEditEntries.delete(deviceSetEditEntry)
}else{
this.selectedDeviceSetEditEntries.add(deviceSetEditEntry)
}
this.update()
}

clearSelectedDeviceSetEditEntries(){
this.selectedDeviceSetEditEntries.clear()
this.update()
}

get cancelCurrentAction(): () => void {
if(this._cancelCurrentAction.length <= 0) return () => {}
if(typeof this._cancelCurrentAction.at(-1).action != "function") return () => {}
Expand Down
68 changes: 68 additions & 0 deletions frontend/web/src/components/app/edit/deviceSetEdit.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {html, LitElement, PropertyValues} from 'lit'
import {customElement, property} from 'lit/decorators.js'
import styles from '../../../../styles/components/app/edit/deviceTypeEdit.styles.scss'
import {
DeviceTypeFullDTO, DeviceTypeVariantEnum,
} from "../../../service/deviceType.service"
import {EditPageEnum, ObservedProperty} from "../../../model"
import UrlHandler from "../../../util/UrlHandler"
import {model} from "../../../index"
import {AppState} from "../../../AppState"
import {InputType} from "../../basic/input.component"
import {ColorEnum, SizeEnum} from "../../../base"
import TagService, {Tag} from "../../../service/tag.service"
import {ChipType} from "../../basic/chip.component"
import {DeviceSetCreateDTO, DeviceSet} from "../../../service/deviceSet.service"

@customElement('cc-device-set-edit')
export class DeviceSetEditComponent extends LitElement {
@property() private deviceSets: ObservedProperty<DeviceSet[]>

@property() private appState: ObservedProperty<AppState>

constructor() {
super()
this.deviceSets = new ObservedProperty<DeviceSet[]>(this, model.deviceSets)
this.appState = new ObservedProperty<AppState>(this, model.appState)

console.log(this.deviceSets.value)
}

render() {
return html`
<style>${styles}</style>
<div class="toolbar-container">
<cc-toolbar type="edit"></cc-toolbar>
<main>
<div class="header">
<h1>
Geräte-Sets
</h1>
</div>
${Object.values(this.deviceSets.value)?.flat().map(deviceSet => {
return html`<cc-device-set-edit-entry .deviceSet="${deviceSet}" @click="${() => {
let convertedDeviceSet : DeviceSetCreateDTO = {
id: deviceSet.id,
name: deviceSet.name,
description: deviceSet.description,
deviceTypeIds: deviceSet.device_types.map(deviceType => deviceType.type_id) || [],
status: deviceSet.status
} as DeviceSetCreateDTO
model.appState.value.openOverlay(html`<cc-edit-device-set-modal .element="${deviceSet}" .isEditMode="${true}"></cc-edit-device-set-modal>`, () => {})}}">
}}"></cc-device-set-edit-entry>`
})}
</main>
</div>
`
}
}

declare global {
interface HTMLElementTagNameMap {
"cc-device-set-edit": DeviceSetEditComponent
}
}
Loading

0 comments on commit 79bc2d7

Please sign in to comment.