Skip to content

Commit

Permalink
Oracle tools (#161)
Browse files Browse the repository at this point in the history
* init sniper locator controller

* fix

* fix type

* delete dependency

* change name

* fix bugs

* fix auth problem

* fix eslint

* added default username and password

* mini refactored

* fix mustExist flag + deleted useless get requests

* fixed linter

* create shared code

* fix locator in overlay

* rename to oracle-tools

* fix package name

* move abstractWidget.js to common folder

* make abstractWidgetImpl for admin

* added LOCATOR_MAGICAL_CONSTANT

* fixed bugs + move BasicAuthKey to object

* rename all parts of code from sniper to oracle

---------

Co-authored-by: Mihail Kornilovich <[email protected]>
  • Loading branch information
Mond1c and Mihail Kornilovich authored Apr 3, 2024
1 parent d90f702 commit c5ff3a3
Show file tree
Hide file tree
Showing 81 changed files with 1,750 additions and 635 deletions.
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ val simpleProjects = listOf(
"frontend",
"reactions-bot",
"schema-generator",
"sniper-tools",
"oracle-tools",
"faker",
"user-archive",
)
Expand Down Expand Up @@ -69,4 +69,4 @@ for (projectName in cdsPlugins) {
gradleEnterprise.buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
}
3 changes: 2 additions & 1 deletion src/frontend/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"react-drag-drop-files": "^2.3.4",
"react-rnd": "^10.3.7",
"react-router-dom": "^6.2.2",
"react-scripts": "^5.0.1"
"react-scripts": "^5.0.1",
"shared-code": "file:../common"
},
"scripts": {
"start": "react-scripts start",
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/admin/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import BackendLog from "./components/BackendLog";
import Dashboard from "./components/Dashboard";
import Analytics from "./components/Analytics";
import TeamSpotlight from "./components/TeamSpotlight";
import { createApiGet, setFavicon, isShouldUseDarkColor, useLocalStorageState } from "./utils";
import { createApiGet } from "shared-code/utils";
import { setFavicon, isShouldUseDarkColor, useLocalStorageState } from "./utils";
import FullScreenClockManager from "./components/FullScreenClockManager";
import AdvancedJson from "./components/AdvancedJson";
import MediaFiles from "./components/MediaFiles";
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/admin/src/components/AdvancedJson.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState, useEffect } from "react";
import { Button, Container } from "@mui/material";
import { errorHandlerWithSnackbar } from "../errors";
import { errorHandlerWithSnackbar } from "shared-code/errors";
import { useSnackbar } from "notistack";
import { BASE_URL_BACKEND, SCHEMAS_LOCATION } from "../config";
import Typography from "@mui/material/Typography";
import { createApiGet, createApiPost } from "../utils";
import { createApiGet, createApiPost } from "shared-code/utils";
import JsonEditor from "./atoms/JsonEditor";
import Box from "@mui/material/Box";

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/admin/src/components/Advertisement.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import Container from "@mui/material/Container";
import { useSnackbar } from "notistack";
import { errorHandlerWithSnackbar } from "../errors";
import { errorHandlerWithSnackbar } from "shared-code/errors";
import { PresetsManager } from "./PresetsManager";
import { usePresetWidgetService } from "../services/presetWidget";

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/admin/src/components/Controls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import Container from "@mui/material/Container";
import { errorHandlerWithSnackbar } from "../errors";
import { errorHandlerWithSnackbar } from "shared-code/errors";
import { useSnackbar } from "notistack";
import { useControlsWidgetService } from "../services/controlsWidget";
import { PresetsManager } from "./PresetsManager";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SlimTableCell } from "./atoms/Table";
import { Button, ButtonGroup, Container, Switch, Table, TableBody, TableRow } from "@mui/material";
import { useSnackbar } from "notistack";
import React, { useEffect, useState } from "react";
import { errorHandlerWithSnackbar } from "../errors";
import { errorHandlerWithSnackbar } from "shared-code/errors";
import { useFullScreenClockWidget } from "../services/fullScreenClockWidget";


Expand Down
2 changes: 1 addition & 1 deletion src/frontend/admin/src/components/MediaFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { styled } from "@mui/material/styles";
import { FileUploader } from "react-drag-drop-files";
import { Container, Link, Paper } from "@mui/material";
import { useErrorHandlerWithSnackbar } from "../errors";
import { createApiGet } from "../utils";
import { createApiGet } from "shared-code/utils";
import AttachFileIcon from "@mui/icons-material/AttachFile";
import Box from "@mui/material/Box";
import { BASE_URL_BACKEND, MEDIAS_LOCATION } from "../config";
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/admin/src/components/Picture.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import Container from "@mui/material/Container";
import { PictureTableRow } from "./PictureTableRow";
import { useSnackbar } from "notistack";
import { errorHandlerWithSnackbar } from "../errors";
import { errorHandlerWithSnackbar } from "shared-code/errors";
import { PresetsManager } from "./PresetsManager";
import { usePresetWidgetService } from "../services/presetWidget";

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/admin/src/components/PresetsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Table, TableBody, TableCell, TableHead, TableRow } from "@mui/material"
import AddIcon from "@mui/icons-material/Add";
import IconButton from "@mui/material/IconButton";
import { PresetsTableRow } from "./PresetsTableRow";
import { AbstractWidgetService } from "../services/abstractWidget";
import { AbstractWidgetImpl } from "../services/abstractWidgetImpl";

export function DefaultAddPresetButton({ onCreate }) {
return (<IconButton color="primary" size="large" onClick={() => onCreate()}><AddIcon/></IconButton>);
Expand Down Expand Up @@ -56,7 +56,7 @@ export function PresetsManager({ service, RowComponent, defaultRowData, tableKey
}

PresetsManager.propTypes = {
service: PropTypes.instanceOf(AbstractWidgetService).isRequired,
service: PropTypes.instanceOf(AbstractWidgetImpl).isRequired,
RowComponent: PropTypes.elementType,
defaultRowData: PropTypes.object,
tableKeys: PropTypes.arrayOf(PropTypes.string).isRequired,
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/admin/src/components/ScoreboardManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { useSnackbar } from "notistack";
import PropTypes from "prop-types";
import React, { useCallback, useEffect, useRef, useState } from "react";
import { BASE_URL_BACKEND } from "../config";
import { errorHandlerWithSnackbar } from "../errors";
import { createApiGet, createApiPost } from "../utils";
import { errorHandlerWithSnackbar } from "shared-code/errors";
import { createApiGet, createApiPost } from "shared-code/utils";
import { SlimTableCell } from "./atoms/Table";

function NumericField({ onChange : _onChange, value, minValue, arrowsDelta }) {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/admin/src/components/TeamView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
createTheme,
} from "@mui/material";
import { useSnackbar } from "notistack";
import { errorHandlerWithSnackbar } from "../errors";
import { errorHandlerWithSnackbar } from "shared-code/errors";
import { TeamViewService, useTeamViewService } from "../services/teamViewWidget";
import SingleTeamViewIcon from "@mui/icons-material/WebAsset";
import PVPTeamViewIcon from "@mui/icons-material/Splitscreen";
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/admin/src/components/TickerMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Container from "@mui/material/Container";
import PropTypes from "prop-types";
import { IconButton, ButtonGroup } from "@mui/material";
import { useSnackbar } from "notistack";
import { errorHandlerWithSnackbar } from "../errors";
import { errorHandlerWithSnackbar } from "shared-code/errors";
import AddIcon from "@mui/icons-material/Add";
import ClockIcon from "@mui/icons-material/AccessTime";
import ScoreboardIcon from "@mui/icons-material/EmojiEvents";
Expand All @@ -13,7 +13,7 @@ import { TickerTableRow } from "./TickerTableRow";
import Dashboard from "./Dashboard";
import { usePresetWidgetService } from "../services/presetWidget";
import { PresetsManager } from "./PresetsManager";
import { AbstractWidgetService } from "../services/abstractWidget";
import { AbstractWidgetImpl } from "../services/abstractWidgetImpl";

const addPresetButtons = [
{
Expand Down Expand Up @@ -61,7 +61,7 @@ const TickerPart = ({ service, part }) =>
AddButtons={makeAddButtons(part)}
/>);
TickerPart.propTypes = {
service: PropTypes.instanceOf(AbstractWidgetService).isRequired,
service: PropTypes.instanceOf(AbstractWidgetImpl).isRequired,
part: PropTypes.string.isRequired,
};

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/admin/src/components/Title.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";
import Container from "@mui/material/Container";
import { useSnackbar } from "notistack";
import { errorHandlerWithSnackbar } from "../errors";
import { errorHandlerWithSnackbar } from "shared-code/errors";
import { Autocomplete, TextField, Button,
TableCell, TableRow,
Dialog, DialogTitle, DialogContent, DialogActions,
Expand Down
9 changes: 1 addition & 8 deletions src/frontend/admin/src/errors.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { useSnackbar } from "notistack";

export const errorHandlerWithSnackbar = (snackBarEnqueue) =>
(cause) => {
return (error) => {
console.error(cause + ": " + error);
snackBarEnqueue(cause, { variant: "error" });
};
};
import { errorHandlerWithSnackbar } from "shared-code/errors";

export const useErrorHandlerWithSnackbar = () => {
const { enqueueSnackbar } = useSnackbar();
Expand Down
9 changes: 9 additions & 0 deletions src/frontend/admin/src/services/abstractWidgetImpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AbstractWidgetService } from "shared-code/abstractWidget";
import { BASE_URL_BACKEND, ADMIN_ACTIONS_WS_URL } from "../config";

export class AbstractWidgetImpl extends AbstractWidgetService {
constructor(apiPath, errorHandler, listenWS) {
super(BASE_URL_BACKEND, ADMIN_ACTIONS_WS_URL, apiPath, errorHandler, listenWS);

}
}
3 changes: 2 additions & 1 deletion src/frontend/admin/src/services/analytics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createApiPost, useWebsocket } from "../utils";
import { createApiPost } from "shared-code/utils";
import { useWebsocket } from "../utils";
import { BASE_URL_BACKEND, BASE_URL_WS } from "../config";
import { useMemo, useState } from "react";

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/admin/src/services/controlsWidget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractWidgetService } from "./abstractWidget";
import { AbstractWidgetImpl } from "../services/abstractWidgetImpl";
import { useMemo } from "react";

const controlElements = [
Expand All @@ -10,7 +10,7 @@ const controlElements = [
{ text: "Full screen clock", id: "fullScreenClock" },
];

export class ControlsWidgetService extends AbstractWidgetService {
export class ControlsWidgetService extends AbstractWidgetImpl {
constructor(errorHandler, listenWS = true) {
super("", errorHandler, listenWS);
}
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/admin/src/services/fullScreenClockWidget.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AbstractWidgetService } from "./abstractWidget";
import { AbstractWidgetImpl } from "../services/abstractWidgetImpl";
import { useMemo } from "react";

export class FullScreenClockService extends AbstractWidgetService {
export class FullScreenClockService extends AbstractWidgetImpl {
constructor(errorHandler, listenWS = true) {
super("/fullScreenClock", errorHandler, listenWS);
}
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/admin/src/services/presetWidget.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AbstractWidgetService } from "./abstractWidget";
import { AbstractWidgetImpl } from "../services/abstractWidgetImpl";
import { useMemo } from "react";

export class PresetWidgetService extends AbstractWidgetService {
export class PresetWidgetService extends AbstractWidgetImpl {
constructor(apiPath, errorHandler, listenWS = true) {
super(apiPath, errorHandler, listenWS);
}
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/admin/src/services/teamSpotlight.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createApiPost, useWebsocket } from "../utils";
import { createApiPost } from "shared-code/utils";
import { useWebsocket } from "../utils";
import { BASE_URL_BACKEND, BASE_URL_WS } from "../config";
import { useMemo, useState } from "react";

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/admin/src/services/teamViewWidget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractWidgetService } from "./abstractWidget";
import { AbstractWidgetImpl } from "../services/abstractWidgetImpl";
import { useMemo } from "react";

const getTeamViewVariantParams = (variant) => {
Expand All @@ -12,7 +12,7 @@ const getTeamViewVariantParams = (variant) => {
}
};

export class TeamViewService extends AbstractWidgetService {
export class TeamViewService extends AbstractWidgetImpl {
constructor(variant, errorHandler, listenWS = true) {
const [instances, apiPath] = getTeamViewVariantParams(variant);
super("/" + apiPath, errorHandler, listenWS);
Expand Down
26 changes: 0 additions & 26 deletions src/frontend/admin/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,6 @@ export const useLocalStorageState = (key, defaultValue) => {
return [state, saveState];
};

export const createApiPost = (apiUrl) =>
function (path, body = {}, method = "POST", sendRaw = false) {
const requestOptions = {
method: method,
headers: { "Content-Type": sendRaw ? "text/plain" : "application/json" },
body: method === "GET" ? undefined : (sendRaw ? body : JSON.stringify(body)),
};
return fetch(apiUrl + path, requestOptions)
.then(response => response.json())
.then(response => {
if (response.status !== "ok") {
throw new Error("Server return not ok status: " + response);
}
return response;
});
};
export const createApiGet = (apiUrl) =>
function (path, body = undefined, rawText = false) {
const requestOptions = {
headers: { "Content-Type": "application/json" },
body: body !== undefined ? JSON.stringify(body) : undefined,
};
return fetch(apiUrl + path, requestOptions)
.then(response => rawText ? response.text() : response.json());
};

export const timeMsToDuration = (timeMs) => DateTime.fromMillis(timeMs, { zone: "utc" }).toFormat("H:mm:ss");
export const unixTimeMsToLocalTime = (timeMs) => DateTime.fromMillis(timeMs, { zone: "local" }).toFormat("HH:mm:ss");

Expand Down
13 changes: 12 additions & 1 deletion src/frontend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ tasks {
inputs.file("admin/package.json")
outputs.dir("admin/build")
}
val buildLocatorAdmin = named<NpmTask>("npm_run_buildLocatorAdmin") {
outputs.cacheIf { true }
environment.set(mapOf("PUBLIC_URL" to "/locator"))
inputs.dir("locator/src")
inputs.dir("locator/public")
inputs.dir("common")
inputs.file("package.json")
inputs.file("package-lock.json")
inputs.file("locator/package.json")
outputs.dir("locator/build")
}
//val installBrowsers = named<NpmTask>("npm_run_install-browsers") // probably want to cache it somehow
val runTests = named<NpmTask>("npm_run_test") {
//dependsOn(installBrowsers)
Expand All @@ -48,7 +59,7 @@ tasks {
dependsOn(runTests)
}
val assemble = register<Task>("assemble") {
dependsOn(buildOverlay, buildAdmin)
dependsOn(buildOverlay, buildAdmin, buildLocatorAdmin)
}
register<Task>("build") {
dependsOn(assemble, test)
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/clean.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rm -rf node_modules overlay/node_modules admin/node_modules
rm -rf node_modules overlay/node_modules admin/node_modules locator/node_modules
9 changes: 9 additions & 0 deletions src/frontend/common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "shared-code",
"exports": {
"./utils": "./src/utils.js",
"./errors": "./src/errors.js",
"./abstractWidget": "./src/abstractWidget.js",
"./package.json": "./package.json"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ADMIN_ACTIONS_WS_URL, BASE_URL_BACKEND } from "../config";
import { createApiGet, createApiPost } from "../utils";
import { createApiGet, createApiPost } from "./utils.js";

const WEBSOCKET_RECONNECT_TIME = 3000;

export class AbstractWidgetService {
constructor(apiPath, errorHandler, listenWS) {
constructor(BASE_URL_BACKEND, ADMIN_ACTIONS_WS_URL, apiPath, errorHandler, listenWS) {
this.ADMIN_ACTIONS_WS_URL = ADMIN_ACTIONS_WS_URL;
this.apiPath = apiPath;
this.apiUrl = BASE_URL_BACKEND + apiPath;
this.apiGet = createApiGet(this.apiUrl);
Expand All @@ -21,7 +21,7 @@ export class AbstractWidgetService {
}

openWS() {
this.ws = new WebSocket(ADMIN_ACTIONS_WS_URL);
this.ws = new WebSocket(this.ADMIN_ACTIONS_WS_URL);
this.ws.onmessage = ({ data }) => this.isMessageRequireReload(data) && this.reloadDataHandlers.forEach(h => h(data));
this.ws.onclose = (function () {
this.ws = null;
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/common/src/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const errorHandlerWithSnackbar = (snackBarEnqueue) =>
(cause) => {
return (error) => {
console.error(cause + ": " + error);
snackBarEnqueue(cause, { variant: "error" });
};
};
25 changes: 25 additions & 0 deletions src/frontend/common/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const createApiPost = (apiUrl) =>
function (path, body = {}, method = "POST") {
const requestOptions = {
method: method,
headers: { "Content-Type": "application/json" },
body: method === "GET" ? undefined : JSON.stringify(body),
};
return fetch(apiUrl + path, requestOptions)
.then(response => response.json())
.then(response => {
if (response.status !== "ok") {
throw new Error("Server return not ok status: " + response);
}
return response;
});
};
export const createApiGet = (apiUrl) =>
function (path, body = undefined) {
const requestOptions = {
headers: { "Content-Type": "application/json" },
body: body !== undefined ? JSON.stringify(body) : undefined,
};
return fetch(apiUrl + path, requestOptions)
.then(response => response.json());
};
Loading

0 comments on commit c5ff3a3

Please sign in to comment.