Skip to content

Commit

Permalink
Merge branch 'release/0.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Oct 22, 2018
2 parents 6237ffe + 8193577 commit 48d74f0
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This application enables faforever.com moderators to perform administrative acti
- For a simple setup and testing of the dependencies you should use [Docker](https://www.docker.org) and [Docker Compose](https://github.com/docker/compose/releases)

## Boot the dependencies
- Checkout the [FAF Stack](https://github.com/FAForver/faf-stack) and boot the api via `docker-compose up -d faf-java-api`. This will also boot the FAF database.
- Checkout the [FAF Stack](https://github.com/FAForever/faf-stack) and boot the api via `docker-compose up -d faf-java-api`. This will also boot the FAF database.
- Get some [test data](https://github.com/FAForever/db/blob/develop/test-data.sql) and insert it into the MySQL db (user: root & password: banana). A tool like HeidiSQL can help you with this. This also adds a moderator account with username: test & password: test_password

## Run from source
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.faforever</groupId>
<artifactId>faf-moderator-client</artifactId>
<version>0.5.0</version>
<version>0.5.1</version>
<packaging>jar</packaging>

<name>faf-moderator-client</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import com.faforever.commons.api.elide.ElideNavigator;
import com.faforever.commons.api.elide.ElideNavigatorOnCollection;
import com.faforever.moderatorclient.api.FafApiCommunicationService;
import com.faforever.moderatorclient.mapstruct.MapVersionMapper;
import com.faforever.moderatorclient.ui.domain.MapVersionFX;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -19,9 +22,11 @@
@Slf4j
public class MapService {
private final FafApiCommunicationService fafApi;
private final MapVersionMapper mapVersionMapper;

public MapService(FafApiCommunicationService fafApi) {
public MapService(FafApiCommunicationService fafApi, MapVersionMapper mapVersionMapper) {
this.fafApi = fafApi;
this.mapVersionMapper = mapVersionMapper;
}


Expand Down Expand Up @@ -121,6 +126,10 @@ public void addMapVersionToLadderPool(MapVersion mapVersion) {
new Ladder1v1Map().setMapVersion(mapVersion));
}

public void patchMapVersion(MapVersionFX mapVersionFX) {
patchMapVersion(mapVersionMapper.map(mapVersionFX));
}

public void patchMapVersion(MapVersion mapVersion) {
log.debug("Updating mapVersion id: {}", mapVersion.getId());
fafApi.patch(ElideNavigator.of(mapVersion),
Expand All @@ -138,4 +147,17 @@ public boolean doesMapVersionExist(int id) {
.addFilter(ElideNavigator.qBuilder().string("id").eq(String.valueOf(id))))
.isEmpty();
}

public List<MapVersionFX> findLatestMapVersions() {
log.debug("Searching for latest mapVersions ");
ElideNavigatorOnCollection<MapVersion> navigator = ElideNavigator.of(MapVersion.class)
.collection()
.addIncludeOnCollection("map")
.addIncludeOnCollection("map.author")
.addSortingRule("id", false);

List<MapVersion> result = fafApi.getPage(navigator, 50, 1, Collections.emptyMap());
log.trace("found {} teamkills", result.size());
return mapVersionMapper.mapToFX(result);
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/faforever/moderatorclient/ui/AvatarCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.faforever.moderatorclient.ui;

import javafx.scene.image.Image;

import java.util.HashMap;
import java.util.Map;

public class AvatarCache {

private final Map<String, Image> cache;

private static AvatarCache singleton;

private AvatarCache() {
this.cache = new HashMap<>();
}

public static synchronized AvatarCache getInstance() {
if (singleton == null) {
singleton = new AvatarCache();
}
return singleton;
}

public Image get(String key) {
return this.cache.get(key);
}

public boolean containsKey(String key) {
return this.cache.containsKey(key);
}

public void put(String cacheKey, Image img) {
this.cache.put(cacheKey, img);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void getDefaultChoices(int questionID, int count) {
private String generateMapDescriptionHTML(MapVersion mapVersion) {
String formattedHtml;
try {
URL resource = getClass().getResource("/media/map_description_template.html");
URL resource = getClass().getClassLoader().getResource("media/map_description_template.html");
String htmlTemplate = new String(Files.readAllBytes(Paths.get(resource.toURI())));

formattedHtml = htmlTemplate.replaceAll("\\{map-player-count}", String.valueOf(mapVersion.getMaxPlayers()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.faforever.moderatorclient.ui;

import com.faforever.moderatorclient.ui.domain.AvatarAssignmentFX;
import com.faforever.moderatorclient.ui.domain.AvatarFX;
import javafx.scene.control.TableCell;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.time.OffsetDateTime;
import java.util.Objects;

public class UrlImageViewTableCell<T> extends TableCell<T, String> {
Expand All @@ -17,11 +20,33 @@ protected void updateItem(String item, boolean empty) {
if (item != null) {
if (!Objects.equals(currentUrl, item)) {
currentUrl = item;
imageView.setImage(new Image(item));
Image img;
if (getTableRow() != null && getTableRow().getItem() != null) {
String cacheKey = cacheKeyFrom(item, getTableRow().getItem());
if (AvatarCache.getInstance().containsKey(cacheKey)) {
img = AvatarCache.getInstance().get(cacheKey);
} else {
img = new Image(item);
AvatarCache.getInstance().put(cacheKey, img);
}
} else {
img = new Image(item);
}
imageView.setImage(img);
}
setGraphic(imageView);
} else {
setGraphic(null);
}
}

private String cacheKeyFrom(String item, Object rawData) {
OffsetDateTime updateTime = null;
if (rawData instanceof AvatarFX) {
updateTime = ((AvatarFX)rawData).getUpdateTime();
} else if (rawData instanceof AvatarAssignmentFX) {
updateTime = ((AvatarAssignmentFX)rawData).getUpdateTime();
}
return updateTime != null ? item+updateTime.toString() : item;
}
}
151 changes: 132 additions & 19 deletions src/main/java/com/faforever/moderatorclient/ui/ViewHelper.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package com.faforever.moderatorclient.ui;

import com.faforever.commons.api.dto.BanDurationType;
import com.faforever.commons.api.dto.BanLevel;
import com.faforever.commons.api.dto.BanStatus;
import com.faforever.commons.api.dto.*;
import com.faforever.commons.api.dto.Map;
import com.faforever.commons.api.dto.VotingChoice;
import com.faforever.commons.api.dto.VotingQuestion;
import com.faforever.commons.api.dto.VotingSubject;
import com.faforever.moderatorclient.api.domain.MessagesService;
import com.faforever.moderatorclient.api.domain.TutorialService;
import com.faforever.moderatorclient.api.domain.VotingService;
Expand All @@ -26,11 +21,7 @@
import javafx.scene.control.cell.TreeItemPropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Color;
Expand All @@ -39,6 +30,8 @@
import javafx.util.StringConverter;
import javafx.util.converter.DefaultStringConverter;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;

import java.io.PrintWriter;
Expand All @@ -48,13 +41,7 @@
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.TreeSet;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -332,7 +319,7 @@ public static void buildNameHistoryTableView(TableView<NameRecordFX> tableView,
* @param showKiller whether to show the killer
* @param onAddBan if not null shows a ban button which triggers this consumer
*/
public static void buildTeamkillTableView(TableView<TeamkillFX> tableView, ObservableList<TeamkillFX> data, boolean showKiller, Consumer<PlayerFX> onAddBan) {
public static void buildTeamkillTableView(@NotNull TableView<TeamkillFX> tableView, @NotNull ObservableList<TeamkillFX> data, boolean showKiller, @Nullable Consumer<PlayerFX> onAddBan) {
tableView.setItems(data);
HashMap<TableColumn<TeamkillFX, ?>, Function<TeamkillFX, ?>> extractors = new HashMap<>();

Expand Down Expand Up @@ -674,6 +661,117 @@ public static void buildMapTreeView(TreeTableView<MapTableItemAdapter> mapTreeVi
mapTreeView.setShowRoot(false);
}

public static void buildMapFeedTableView(@NotNull TableView<MapVersionFX> tableView, @NotNull ObservableList<MapVersionFX> data, @Nullable Consumer<MapVersionFX> onToggleHide) {
tableView.setItems(data);
HashMap<TableColumn<MapVersionFX, ?>, Function<MapVersionFX, ?>> extractors = new HashMap<>();

TableColumn<MapVersionFX, String> idColumn = new TableColumn<>("Map Version ID");
idColumn.setCellValueFactory(o -> o.getValue().idProperty());
idColumn.setComparator(Comparator.comparingInt(Integer::parseInt));
idColumn.setMinWidth(100);
tableView.getColumns().add(idColumn);
extractors.put(idColumn, MapVersionFX::getId);

TableColumn<MapVersionFX, String> mapIdColumn = new TableColumn<>("Map ID");
mapIdColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(
Optional.ofNullable(param.getValue())
.map(mapVersionFX -> mapVersionFX.getMap().getId())
.orElse(""))
);
mapIdColumn.setComparator(Comparator.comparingInt(Integer::parseInt));
mapIdColumn.setMinWidth(50);
tableView.getColumns().add(mapIdColumn);
extractors.put(mapIdColumn, mapVersionFX -> mapVersionFX.getMap().getId());

TableColumn<MapVersionFX, String> mapNameColumn = new TableColumn<>("Map Name");
mapNameColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(
Optional.ofNullable(param.getValue())
.map(mapVersionFX -> mapVersionFX.getMap().getDisplayName())
.orElse(""))
);
mapNameColumn.setMinWidth(150);
tableView.getColumns().add(mapNameColumn);
extractors.put(mapNameColumn, mapVersionFX -> mapVersionFX.getMap().getDisplayName());

TableColumn<MapVersionFX, String> uploaderColumn = new TableColumn<>("Uploader");
uploaderColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(
Optional.ofNullable(param.getValue())
.map(mapVersionFX -> mapVersionFX.getMap().getAuthor().getRepresentation())
.orElse("")));
uploaderColumn.setMinWidth(150);
tableView.getColumns().add(uploaderColumn);
extractors.put(uploaderColumn, mapVersionFX -> mapVersionFX.getMap().getAuthor().getRepresentation());

TableColumn<MapVersionFX, ComparableVersion> versionColumn = new TableColumn<>("Version");
versionColumn.setCellValueFactory(o -> o.getValue().versionProperty());
versionColumn.setMinWidth(50);
tableView.getColumns().add(versionColumn);
extractors.put(versionColumn, MapVersionFX::getVersion);

TableColumn<MapVersionFX, Boolean> rankedCheckBoxColumn = new TableColumn<>("Ranked");
rankedCheckBoxColumn.setCellValueFactory(param -> param.getValue().rankedProperty());
rankedCheckBoxColumn.setCellFactory(CheckBoxTableCell.forTableColumn(rankedCheckBoxColumn));
tableView.getColumns().add(rankedCheckBoxColumn);

TableColumn<MapVersionFX, Boolean> hiddenColumn = new TableColumn<>("Hidden");
hiddenColumn.setCellValueFactory(o -> o.getValue().hiddenProperty());
hiddenColumn.setCellFactory(CheckBoxTableCell.forTableColumn(hiddenColumn));
tableView.getColumns().add(hiddenColumn);

TableColumn<MapVersionFX, Number> widthColumn = new TableColumn<>("Width");
widthColumn.setCellValueFactory(o -> o.getValue().widthProperty());
widthColumn.setMinWidth(50);
tableView.getColumns().add(widthColumn);
extractors.put(widthColumn, MapVersionFX::getWidth);

TableColumn<MapVersionFX, Number> heightColumn = new TableColumn<>("Height");
heightColumn.setCellValueFactory(o -> o.getValue().widthProperty());
heightColumn.setMinWidth(50);
tableView.getColumns().add(heightColumn);
extractors.put(heightColumn, MapVersionFX::getHeight);

TableColumn<MapVersionFX, Number> maxPlayersColumn = new TableColumn<>("Max players");
maxPlayersColumn.setCellValueFactory(o -> o.getValue().maxPlayersProperty());
maxPlayersColumn.setMinWidth(50);
tableView.getColumns().add(maxPlayersColumn);
extractors.put(maxPlayersColumn, MapVersionFX::getMaxPlayers);

TableColumn<MapVersionFX, String> versionDescriptionColumn = new TableColumn<>("Version description");
versionDescriptionColumn.setCellValueFactory(o -> o.getValue().descriptionProperty());
versionDescriptionColumn.setMinWidth(250);
tableView.getColumns().add(versionDescriptionColumn);
extractors.put(versionDescriptionColumn, MapVersionFX::getDescription);

TableColumn<MapVersionFX, URL> downloadUrlColumn = new TableColumn<>("Download URL");
downloadUrlColumn.setCellValueFactory(o -> o.getValue().downloadUrlProperty());
downloadUrlColumn.setMinWidth(400);
tableView.getColumns().add(downloadUrlColumn);
extractors.put(downloadUrlColumn, MapVersionFX::getDownloadUrl);

if (onToggleHide != null) {
TableColumn<MapVersionFX, MapVersionFX> toggleHideColumn = new TableColumn<>("Action");
toggleHideColumn.setMinWidth(50);
toggleHideColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue()));
toggleHideColumn.setCellFactory(param -> new TableCell<MapVersionFX, MapVersionFX>() {
@Override
protected void updateItem(MapVersionFX mapVersionFX, boolean empty) {
super.updateItem(mapVersionFX, empty);
if (!empty) {
Button button = new Button();
button.textProperty().bind(Bindings.createStringBinding(() -> mapVersionFX.hiddenProperty().get() ? "Unhide" : "Hide", mapVersionFX.hiddenProperty()));
button.setOnMouseClicked(event -> onToggleHide.accept(mapVersionFX));
setGraphic(button);
return;
}
setGraphic(null);
}
});
tableView.getColumns().add(toggleHideColumn);
}

applyCopyContextMenus(tableView, extractors);
}

public static void buildPlayersGamesTable(TableView<GamePlayerStatsFX> tableView, String replayDownloadFormat, PlatformService platformService) {
HashMap<TableColumn<GamePlayerStatsFX, ?>, Function<GamePlayerStatsFX, ?>> extractors = new HashMap<>();

Expand Down Expand Up @@ -1105,6 +1203,21 @@ public Number fromString(String string) {
});
extractors.put(mapColumn, tutorialFx -> tutorialFx.getMapVersion().toString());

TableColumn<TutorialFx, String> technicalNameColumn = new TableColumn<>("Technical Name ✏");
technicalNameColumn.getStyleClass().add("editable");
technicalNameColumn.setCellValueFactory(param -> param.getValue().technicalNameProperty());
technicalNameColumn.setCellFactory(TextAreaTableCell.forTableColumn());
technicalNameColumn.setEditable(true);
technicalNameColumn.setMinWidth(200);
tutorialTableView.getColumns().add(technicalNameColumn);
technicalNameColumn.setOnEditCommit(event -> {
TutorialFx rowValue = event.getRowValue();
rowValue.setTechnicalName(event.getNewValue());
tutorialService.updateTutorial(rowValue);
refresh.run();
});
extractors.put(technicalNameColumn, TutorialFx::getTechnicalName);

applyCopyContextMenus(tutorialTableView, extractors);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public StringProperty recentIpAddressProperty() {
return recentIpAddress;
}

public String getRepresentation() {
return representation.get();
}

public StringProperty representationProperty() {
return representation;
}
Expand Down
Loading

0 comments on commit 48d74f0

Please sign in to comment.