Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeSimcoe committed Jul 15, 2024
1 parent 1ba1777 commit 74f9397
Show file tree
Hide file tree
Showing 18 changed files with 232 additions and 561 deletions.
File renamed without changes.
484 changes: 1 addition & 483 deletions application/angular/src/app/app.component.html

Large diffs are not rendered by default.

20 changes: 8 additions & 12 deletions application/angular/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { AppComponent } from './app.component';
import { BoardGameListComponent } from './boardgame/boardgame-list/boardgame-list.component';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [
provideAnimationsAsync()
],
bootstrap: [AppComponent]
declarations: [AppComponent, BoardGameListComponent],
imports: [BrowserModule, HttpClientModule],
providers: [provideAnimationsAsync()],
bootstrap: [AppComponent],
})
export class AppModule { }
export class AppModule {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// board-game-list.component.ts
import { Component, OnInit } from '@angular/core';
import { BoardGame, BoardGameService } from '../boardgame.service';

Expand All @@ -16,7 +15,7 @@ export class BoardGameListComponent implements OnInit {
this.loadBoardGames();
}

loadBoardGames(): void {
private loadBoardGames(): void {
this.boardGameService.getBoardGames().subscribe(
(data) => {
this.boardGames = data;
Expand Down
5 changes: 5 additions & 0 deletions application/backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-63</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ quarkus.datasource.jdbc.url=jdbc:h2:mem:backtofront

# Hibernate
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.packages=fr.sciam.backtofront.persistence.entities
quarkus.hibernate-orm.packages=fr.sciam.backtofront.persistence.entities

# HTTP / CORS
quarkus.http.cors=true
quarkus.http.cors.access-control-allow-credentials=true
quarkus.http.cors.origins=*
quarkus.http.cors.headers=Access-Control-Allow-Origin
5 changes: 4 additions & 1 deletion application/backend/src/main/resources/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ INSERT INTO BoardGameEntity (id, name, releaseYear, categories) VALUES
(8, 'Azul', 2017, JSON_ARRAY('ABSTRACT', 'TILE_PLACEMENT')),
(9, 'Codenames', 2015, JSON_ARRAY('PARTY', 'WORD_GAME')),
(10, '7 Wonders', 2010, JSON_ARRAY('CARD_DRAFTING', 'STRATEGY'))
;
;

-- Set the sequence to start from 11 for the next insertion
ALTER SEQUENCE BOARDGAMEENTITY_SEQ RESTART WITH 11;
6 changes: 5 additions & 1 deletion application/javafx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
<artifactId>quarkus-fx</artifactId>
<version>0.4.2</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>fr.sciam.backtofront</groupId>
<artifactId>backend</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,91 +1,70 @@
package fr.sciam.backtofront;

import fr.sciam.backtofront.component.BoardGameCategoriesCell;
import fr.sciam.backtofront.component.BoardGameImageCell;
import fr.sciam.backtofront.domain.Category;
import fr.sciam.backtofront.mapper.BoardGameMapper;
import fr.sciam.backtofront.persistence.entities.BoardGameEntity;
import fr.sciam.backtofront.viewmodel.BoardGameViewData;
import io.quarkiverse.fx.FxStartupEvent;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.net.URL;
import java.util.List;

@ApplicationScoped
public class FxApplication {

private Label label;
@Inject
BoardGameMapper boardGameMapper;

void onFxStartup(@Observes FxStartupEvent event) {
void onFxStartup(@Observes final FxStartupEvent event) {

// TODO
TableView<BoardGameEntity> table = new TableView<>();
TableView<BoardGameViewData> table = new TableView<>();
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY_ALL_COLUMNS);

TableColumn<BoardGameEntity, Long> idColumn = new TableColumn<>("ID");
idColumn.setCellValueFactory(new PropertyValueFactory<>("id"));
TableColumn<BoardGameViewData, Number> idColumn = new TableColumn<>("ID");
idColumn.setCellValueFactory(cellData -> cellData.getValue().getId());

TableColumn<BoardGameEntity, Long> imageColumn = new TableColumn<>("Image");
TableColumn<BoardGameViewData, Number> imageColumn = new TableColumn<>("Image");
imageColumn.setPrefWidth(150);
imageColumn.setCellValueFactory(new PropertyValueFactory<>("id"));
imageColumn.setCellFactory(_ -> new TableCell<>() {
private final ImageView imageView = new ImageView();
private final HBox hbox = new HBox(this.imageView);
{
this.imageView.setPreserveRatio(true);
// this.hbox.setAlignment(Pos.CENTER);
}

@Override
protected void updateItem(Long id, boolean empty) {
super.updateItem(id, empty);
if (empty || id == null) {
this.setGraphic(null);
} else {
URL resource = ImageResourceUtils.getImageResource(String.valueOf(id));
Image image = new Image(resource.toExternalForm(), true);
this.imageView.setImage(image);

this.setGraphic(this.imageView);
}
}
});

TableColumn<BoardGameEntity, String> nameColumn = new TableColumn<>("Name");
nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));

TableColumn<BoardGameEntity, Integer> yearColumn = new TableColumn<>("Release Year");
yearColumn.setCellValueFactory(new PropertyValueFactory<>("releaseYear"));

TableColumn<BoardGameEntity, List<Category>> categoriesColumn = new TableColumn<>("Categories");
categoriesColumn.setCellValueFactory(new PropertyValueFactory<>("categories"));

table.getColumns().addAll(
idColumn,
imageColumn,
nameColumn,
yearColumn,
categoriesColumn
);

// Sample data
List<BoardGameEntity> entities = BoardGameEntity.listAll();
ObservableList<BoardGameEntity> data = FXCollections.observableList(entities);
imageColumn.setCellValueFactory(cellData -> cellData.getValue().getId());
imageColumn.setCellFactory(_ -> BoardGameImageCell.newBoardGameImageCell());

TableColumn<BoardGameViewData, String> nameColumn = new TableColumn<>("Name");
nameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());

TableColumn<BoardGameViewData, Number> yearColumn = new TableColumn<>("Release Year");
yearColumn.setCellValueFactory(cellData -> cellData.getValue().getReleaseYear());

TableColumn<BoardGameViewData, ObservableList<Category>> categoriesColumn = new TableColumn<>("Categories");
categoriesColumn.setCellValueFactory(cellData -> new SimpleObjectProperty<>(cellData.getValue().getCategories()));
categoriesColumn.setCellFactory(_ -> BoardGameCategoriesCell.newBoardGameImageCell());


table.getColumns().addAll(idColumn, imageColumn, nameColumn, yearColumn, categoriesColumn);

// Load sample data
List<BoardGameViewData> entities = BoardGameEntity.<BoardGameEntity>listAll()
.stream()
.map(this.boardGameMapper::create)
.toList();
ObservableList<BoardGameViewData> data = FXCollections.observableList(entities);

table.setItems(data);

// Display stage
Stage stage = event.getPrimaryStage();

VBox root = new VBox(table);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fr.sciam.backtofront.component;

import fr.sciam.backtofront.domain.Category;
import fr.sciam.backtofront.viewmodel.BoardGameViewData;
import javafx.collections.ObservableList;
import javafx.scene.control.TableCell;

import java.util.stream.Collectors;

public class BoardGameCategoriesCell extends TableCell<BoardGameViewData, ObservableList<Category>> {

private BoardGameCategoriesCell() {
// Instantiated by factory
}

public static TableCell<BoardGameViewData, ObservableList<Category>> newBoardGameImageCell() {
return new BoardGameCategoriesCell();
}

@Override
protected void updateItem(final ObservableList<Category> categories, final boolean empty) {
super.updateItem(categories, empty);
if (empty || categories == null || categories.isEmpty()) {
this.setText(null);
} else {
this.setText(categories.stream().map(Category::name).collect(Collectors.joining(", ")));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package fr.sciam.backtofront.component;

import fr.sciam.backtofront.ImageResourceUtils;
import fr.sciam.backtofront.viewmodel.BoardGameViewData;
import javafx.scene.control.TableCell;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.net.URL;

public class BoardGameImageCell extends TableCell<BoardGameViewData, Number> {
private final ImageView imageView;

private BoardGameImageCell() {
this.imageView = new ImageView();
this.imageView.setPreserveRatio(true);
}

public static TableCell<BoardGameViewData, Number> newBoardGameImageCell() {
return new BoardGameImageCell();
}

@Override
protected void updateItem(final Number id, final boolean empty) {
super.updateItem(id, empty);
if (empty || id == null) {
this.setGraphic(null);
} else {
URL resource = ImageResourceUtils.getImageResource(String.valueOf(id));
Image image = new Image(resource.toExternalForm(), true);
this.imageView.setImage(image);
this.setGraphic(this.imageView);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fr.sciam.backtofront.mapper;

import fr.sciam.backtofront.persistence.entities.BoardGameEntity;
import fr.sciam.backtofront.viewmodel.BoardGameViewData;
import jakarta.inject.Singleton;

@Singleton
public class BoardGameMapper implements ViewModelMapper<BoardGameEntity, BoardGameViewData> {

@Override
public BoardGameViewData newViewModelInstance() {
return new BoardGameViewData();
}

@Override
public void update(
final BoardGameEntity domainObject,
final BoardGameViewData viewModelObject) {

viewModelObject.getId().set(domainObject.id);
viewModelObject.getName().set(domainObject.name);
viewModelObject.getReleaseYear().set(domainObject.releaseYear);
viewModelObject.getCategories().setAll(domainObject.categories);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package fr.sciam.backtofront.mapper;

/**
* Mapper used to map a domain object to a JavaFX view model object
* @param <D> domain object
* @param <V> view model object
*/
public interface ViewModelMapper<D, V> {

/**
* Create the view model object from a domain object
* @param domainObject the domain object
* @return created view model object
*/
default V create(final D domainObject) {
V viewModelObject = this.newViewModelInstance();
this.update(domainObject, viewModelObject);
return viewModelObject;
}

/**
* Factory to create a new view model object instance
* @return newly created view model object instance
*/
V newViewModelInstance();

/**
* Update a view model object with a domain object
* @param domainObject the domain object
* @param viewModelObject the view model object to be updated
*/
void update(D domainObject, V viewModelObject);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.sciam.backtofront.viewmodel;

import fr.sciam.backtofront.domain.Category;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.LongProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import lombok.Getter;

@Getter
public class BoardGameViewData {

private final LongProperty id = new SimpleLongProperty();
private final StringProperty name = new SimpleStringProperty();
private final IntegerProperty releaseYear = new SimpleIntegerProperty();
private final ObservableList<Category> categories = FXCollections.observableArrayList();

}
Loading

0 comments on commit 74f9397

Please sign in to comment.