WIP: apply suggestions
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
df10eba8d2
commit
e7a3cc119a
@ -1,2 +1,2 @@
|
|||||||
#VITE_API_ENDPOINT=https://iqball.maxou.dev/api/dotnet-master
|
#VITE_API_ENDPOINT=https://iqball.maxou.dev/api/dotnet-master
|
||||||
VITE_API_ENDPOINT=http://localhost:5254
|
VITE_API_ENDPOINT=http://grospc:5254
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
mkdir -p /outputs/public
|
|
||||||
# this sed command will replace the included `profile/dev-config-profile.php` to `profile/prod-config-file.php` in the config.php file.
|
|
||||||
sed -E -i 's/\/\*PROFILE_FILE\*\/\s*".*"/"profiles\/prod-config-profile.php"/' config.php
|
|
||||||
DRONE_BRANCH_ESCAPED=$(sed -E 's/\//\\\//g' <<< "$DRONE_BRANCH")
|
|
||||||
sed -E -i "s/const BASE_PATH = .*;/const BASE_PATH = \"\/IQBall\/$DRONE_BRANCH_ESCAPED\/public\";/" profiles/prod-config-profile.php
|
|
||||||
rm profiles/dev-config-profile.php
|
|
||||||
mv src config.php sql profiles vendor /outputs/
|
|
@ -0,0 +1,84 @@
|
|||||||
|
import { TacticService, ServiceError, TacticContext } from "./TacticService.ts"
|
||||||
|
import { StepContent, StepInfoNode } from "../model/tactic/Tactic.ts"
|
||||||
|
import { fetchAPI, fetchAPIGet } from "../Fetcher.ts"
|
||||||
|
|
||||||
|
export class APITacticService implements TacticService {
|
||||||
|
private readonly tacticId: number
|
||||||
|
|
||||||
|
constructor(tacticId: number) {
|
||||||
|
this.tacticId = tacticId
|
||||||
|
}
|
||||||
|
|
||||||
|
async getContext(): Promise<TacticContext | ServiceError> {
|
||||||
|
const infoResponsePromise = fetchAPIGet(`tactics/${this.tacticId}`)
|
||||||
|
const treeResponsePromise = fetchAPIGet(`tactics/${this.tacticId}/tree`)
|
||||||
|
|
||||||
|
const infoResponse = await infoResponsePromise
|
||||||
|
const treeResponse = await treeResponsePromise
|
||||||
|
|
||||||
|
if (infoResponse.status == 401 || treeResponse.status == 401) {
|
||||||
|
return ServiceError.UNAUTHORIZED
|
||||||
|
}
|
||||||
|
const { name, courtType } = await infoResponse.json()
|
||||||
|
const { root } = await treeResponse.json()
|
||||||
|
|
||||||
|
return { courtType, name, stepsTree: root }
|
||||||
|
}
|
||||||
|
|
||||||
|
async addStep(
|
||||||
|
parent: StepInfoNode,
|
||||||
|
content: StepContent,
|
||||||
|
): Promise<StepInfoNode | ServiceError> {
|
||||||
|
const response = await fetchAPI(`tactics/${this.tacticId}/steps`, {
|
||||||
|
parentId: parent.id,
|
||||||
|
content,
|
||||||
|
})
|
||||||
|
if (response.status == 404) return ServiceError.NOT_FOUND
|
||||||
|
if (response.status == 401) return ServiceError.UNAUTHORIZED
|
||||||
|
|
||||||
|
const { stepId } = await response.json()
|
||||||
|
return { id: stepId, children: [] }
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeStep(id: number): Promise<void | ServiceError> {
|
||||||
|
const response = await fetchAPI(
|
||||||
|
`tactics/${this.tacticId}/steps/${id}`,
|
||||||
|
{},
|
||||||
|
"DELETE",
|
||||||
|
)
|
||||||
|
if (response.status == 404) return ServiceError.NOT_FOUND
|
||||||
|
if (response.status == 401) return ServiceError.UNAUTHORIZED
|
||||||
|
}
|
||||||
|
|
||||||
|
async setName(name: string): Promise<void | ServiceError> {
|
||||||
|
const response = await fetchAPI(
|
||||||
|
`tactics/${this.tacticId}/name`,
|
||||||
|
{ name },
|
||||||
|
"PUT",
|
||||||
|
)
|
||||||
|
if (response.status == 404) return ServiceError.NOT_FOUND
|
||||||
|
if (response.status == 401) return ServiceError.UNAUTHORIZED
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveContent(
|
||||||
|
step: number,
|
||||||
|
content: StepContent,
|
||||||
|
): Promise<void | ServiceError> {
|
||||||
|
const response = await fetchAPI(
|
||||||
|
`tactics/${this.tacticId}/steps/${step}`,
|
||||||
|
{ content },
|
||||||
|
"PUT",
|
||||||
|
)
|
||||||
|
if (response.status == 404) return ServiceError.NOT_FOUND
|
||||||
|
if (response.status == 401) return ServiceError.UNAUTHORIZED
|
||||||
|
}
|
||||||
|
|
||||||
|
async getContent(step: number): Promise<StepContent | ServiceError> {
|
||||||
|
const response = await fetchAPIGet(
|
||||||
|
`tactics/${this.tacticId}/steps/${step}`,
|
||||||
|
)
|
||||||
|
if (response.status == 404) return ServiceError.NOT_FOUND
|
||||||
|
if (response.status == 401) return ServiceError.UNAUTHORIZED
|
||||||
|
return await response.json()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
import { TacticService, ServiceError, TacticContext } from "./TacticService.ts"
|
||||||
|
import { StepContent, StepInfoNode } from "../model/tactic/Tactic.ts"
|
||||||
|
import {
|
||||||
|
addStepNode,
|
||||||
|
getAvailableId,
|
||||||
|
removeStepNode,
|
||||||
|
} from "../editor/StepsDomain.ts"
|
||||||
|
|
||||||
|
const GUEST_MODE_STEP_CONTENT_STORAGE_KEY = "guest_mode_step"
|
||||||
|
const GUEST_MODE_STEP_ROOT_NODE_INFO_STORAGE_KEY = "guest_mode_step_tree"
|
||||||
|
const GUEST_MODE_TITLE_STORAGE_KEY = "guest_mode_title"
|
||||||
|
|
||||||
|
export class LocalStorageTacticService implements TacticService {
|
||||||
|
private constructor() {}
|
||||||
|
|
||||||
|
static init(): LocalStorageTacticService {
|
||||||
|
const root = localStorage.getItem(
|
||||||
|
GUEST_MODE_STEP_ROOT_NODE_INFO_STORAGE_KEY,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (root === null) {
|
||||||
|
localStorage.setItem(
|
||||||
|
GUEST_MODE_STEP_ROOT_NODE_INFO_STORAGE_KEY,
|
||||||
|
JSON.stringify(<StepInfoNode>{ id: 1, children: [] }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LocalStorageTacticService()
|
||||||
|
}
|
||||||
|
|
||||||
|
async getContext(): Promise<TacticContext | ServiceError> {
|
||||||
|
const stepsTree: StepInfoNode = JSON.parse(
|
||||||
|
localStorage.getItem(GUEST_MODE_STEP_ROOT_NODE_INFO_STORAGE_KEY)!,
|
||||||
|
)
|
||||||
|
const name =
|
||||||
|
localStorage.getItem(GUEST_MODE_TITLE_STORAGE_KEY) ??
|
||||||
|
"Nouvelle Tactique"
|
||||||
|
return {
|
||||||
|
stepsTree,
|
||||||
|
name,
|
||||||
|
courtType: "PLAIN",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async addStep(
|
||||||
|
parent: StepInfoNode,
|
||||||
|
content: StepContent,
|
||||||
|
): Promise<StepInfoNode | ServiceError> {
|
||||||
|
const root: StepInfoNode = JSON.parse(
|
||||||
|
localStorage.getItem(GUEST_MODE_STEP_ROOT_NODE_INFO_STORAGE_KEY)!,
|
||||||
|
)
|
||||||
|
|
||||||
|
const nodeId = getAvailableId(root)
|
||||||
|
const node = { id: nodeId, children: [] }
|
||||||
|
|
||||||
|
const resultTree = addStepNode(root, parent, node)
|
||||||
|
|
||||||
|
localStorage.setItem(
|
||||||
|
GUEST_MODE_STEP_ROOT_NODE_INFO_STORAGE_KEY,
|
||||||
|
JSON.stringify(resultTree),
|
||||||
|
)
|
||||||
|
localStorage.setItem(
|
||||||
|
GUEST_MODE_STEP_CONTENT_STORAGE_KEY + node.id,
|
||||||
|
JSON.stringify(content),
|
||||||
|
)
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
async getContent(step: number): Promise<StepContent | ServiceError> {
|
||||||
|
const content = localStorage.getItem(
|
||||||
|
GUEST_MODE_STEP_CONTENT_STORAGE_KEY + step,
|
||||||
|
)
|
||||||
|
return content ? JSON.parse(content) : null
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeStep(id: number): Promise<void | ServiceError> {
|
||||||
|
const root: StepInfoNode = JSON.parse(
|
||||||
|
localStorage.getItem(GUEST_MODE_STEP_ROOT_NODE_INFO_STORAGE_KEY)!,
|
||||||
|
)
|
||||||
|
localStorage.setItem(
|
||||||
|
GUEST_MODE_STEP_ROOT_NODE_INFO_STORAGE_KEY,
|
||||||
|
JSON.stringify(removeStepNode(root, id)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveContent(
|
||||||
|
step: number,
|
||||||
|
content: StepContent,
|
||||||
|
): Promise<void | ServiceError> {
|
||||||
|
localStorage.setItem(
|
||||||
|
GUEST_MODE_STEP_CONTENT_STORAGE_KEY + step,
|
||||||
|
JSON.stringify(content),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async setName(name: string): Promise<void | ServiceError> {
|
||||||
|
localStorage.setItem(GUEST_MODE_TITLE_STORAGE_KEY, name)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
import { CourtType, StepContent, StepInfoNode } from "../model/tactic/Tactic.ts"
|
||||||
|
|
||||||
|
export interface TacticContext {
|
||||||
|
stepsTree: StepInfoNode
|
||||||
|
name: string
|
||||||
|
courtType: CourtType
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ServiceError {
|
||||||
|
UNAUTHORIZED = "UNAUTHORIZED",
|
||||||
|
NOT_FOUND = "NOT_FOUND",
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TacticService {
|
||||||
|
getContext(): Promise<TacticContext | ServiceError>
|
||||||
|
|
||||||
|
addStep(
|
||||||
|
parent: StepInfoNode,
|
||||||
|
content: StepContent,
|
||||||
|
): Promise<StepInfoNode | ServiceError>
|
||||||
|
|
||||||
|
removeStep(id: number): Promise<void | ServiceError>
|
||||||
|
|
||||||
|
setName(name: string): Promise<void | ServiceError>
|
||||||
|
|
||||||
|
saveContent(
|
||||||
|
step: number,
|
||||||
|
content: StepContent,
|
||||||
|
): Promise<void | ServiceError>
|
||||||
|
|
||||||
|
getContent(step: number): Promise<StepContent | ServiceError>
|
||||||
|
}
|
Loading…
Reference in new issue