process
This commit is contained in:
parent
7ff6165882
commit
ae9842d5e1
61 changed files with 929 additions and 433 deletions
|
@ -4,7 +4,7 @@
|
|||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"pretest": "tsc",
|
||||
"test:dev": "NODE_ENV=test_dev tsc-watch --onSuccess 'ts-node ./build/test/test.js'",
|
||||
"test:unit": "NODE_ENV=unit tsc-watch --onSuccess 'ts-node ./build/test/test.js'",
|
||||
"test:e2e": "NODE_ENV=e2e tsc-watch --onSuccess 'ts-node ./build/test/test.js'",
|
||||
"dev": "NODE_ENV=dev tsc-watch --onSuccess 'ts-node ./build/src/main.js'"
|
||||
|
|
|
@ -85,7 +85,7 @@ export class App extends TypedEvent<ServerStatus> {
|
|||
this.app.use(cors());
|
||||
this.app.use(express.json());
|
||||
this.app.use(express.urlencoded({ extended: true }));
|
||||
this.app.use(express.static("public"));
|
||||
this.app.use(express.static(App.staticFilesStoreDir()));
|
||||
|
||||
this.app.use(
|
||||
fileUpload({
|
||||
|
@ -118,6 +118,7 @@ export class App extends TypedEvent<ServerStatus> {
|
|||
static staticFilesStoreDir = () => {
|
||||
const dir = dirname(__filename);
|
||||
const rootDir = dir.slice(0, dir.length - 20);
|
||||
|
||||
return rootDir + "public/";
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ import { validationModelMiddleware } from "../middlewares/validation_model";
|
|||
import { Result } from "../helpers/result";
|
||||
import { Router, Request, Response } from "express";
|
||||
import { IRouteModel, Routes } from "../interfaces/router";
|
||||
import { CoreValidation } from "../validations/core_validation";
|
||||
|
||||
export type HttpMethodType = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "PATCH" | "HEAD";
|
||||
|
||||
export type ResponseBase = Promise<Result<any, any>>;
|
||||
|
||||
export abstract class CallbackStrategyWithEmpty {
|
||||
abstract call(): ResponseBase;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ export abstract class CallbackStrategyWithValidationModel<V> {
|
|||
abstract call(a: V): ResponseBase;
|
||||
}
|
||||
export abstract class CallbackStrategyWithIdQuery {
|
||||
abstract idValidationExpression: RegExp | null;
|
||||
abstract idValidationExpression: CoreValidation;
|
||||
abstract call(id: string): ResponseBase;
|
||||
}
|
||||
export abstract class CallBackStrategyWithQueryPage {
|
||||
|
@ -84,7 +84,24 @@ export class CoreHttpController<V> implements ICoreHttpController {
|
|||
throw Error("needs to be implimed");
|
||||
}
|
||||
if (el.fn instanceof CallbackStrategyWithIdQuery) {
|
||||
throw Error("needs to be implimed");
|
||||
if (req.query.id === undefined) {
|
||||
res.status(400).json("request query id is null, need query id ?id={id:String}");
|
||||
return;
|
||||
}
|
||||
if (el.fn.idValidationExpression !== undefined) {
|
||||
if (!el.fn.idValidationExpression.regExp.test(req.query.id)) {
|
||||
res
|
||||
.status(400)
|
||||
.json(
|
||||
`request query id must fall under the pattern: ${el.fn.idValidationExpression.regExp} message: ${el.fn.idValidationExpression.message} `
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
await this.responseHelper(res, el.fn.call(req.query.id));
|
||||
}
|
||||
} else {
|
||||
await this.responseHelper(res, el.fn.call(req["files"]["file"]));
|
||||
}
|
||||
}
|
||||
if (el.fn instanceof CallBackStrategyWithQueryPage) {
|
||||
throw Error("needs to be implimed");
|
||||
|
|
|
@ -20,6 +20,7 @@ declare global {
|
|||
lastElement(): string;
|
||||
hasPattern(pattern: string): boolean;
|
||||
hasNoPattern(pattern: string): boolean;
|
||||
pathNormalize(): string;
|
||||
}
|
||||
}
|
||||
export const extensions = () => {
|
||||
|
|
|
@ -5,6 +5,11 @@ export const StringExtensions = () => {
|
|||
return this.length === 0;
|
||||
};
|
||||
}
|
||||
if ("".pathNormalize === undefined) {
|
||||
String.prototype.pathNormalize = function () {
|
||||
return this.replace("//", "/");
|
||||
};
|
||||
}
|
||||
if ("".isNotEmpty === undefined) {
|
||||
// eslint-disable-next-line no-extend-native
|
||||
String.prototype.isNotEmpty = function () {
|
||||
|
@ -27,3 +32,6 @@ export const StringExtensions = () => {
|
|||
};
|
||||
}
|
||||
};
|
||||
// python3 /Users/idontsudo/framework/path.py --path /Users/idontsudo/webservice/server/build/public/0a3422cc-f2e3-4abc-87d8-ae13b8b6d26d/ --env /Users/idontsudo/framework/cad_generation/env.json
|
||||
// python3 /Users/idontsudo/framework/path.py --path /Users/idontsudo/webservice/server/build/public/0a3422cc-f2e3-4abc-87d8-ae13b8b6d26d/ --env /Users/idontsudo/framework/cad_generation/env.json
|
||||
// /Users/idontsudo/Desktop/FreeCAD.app/Contents/MacOS/FreeCAD /Users/idontsudo/framework/cad_generation/main.py
|
||||
|
|
|
@ -17,7 +17,9 @@ export interface WorkerDataExec {
|
|||
process.on("message", async (message) => {
|
||||
const workerData = message as WorkerDataExec;
|
||||
if (workerData.type == WorkerType.SPAWN) {
|
||||
const subprocess = cp.spawn(workerData.command, workerData.cliArgs, {
|
||||
// Maybe error
|
||||
// const subprocess = cp.spawn(workerData.command, workerData.cliArgs, {
|
||||
const subprocess = cp.spawn(workerData.command, {
|
||||
cwd: workerData.execPath,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
import { RequestHandler } from "express";
|
||||
|
||||
export const validationMiddleware = (
|
||||
type: any,
|
||||
value = "body",
|
||||
skipMissingProperties = false,
|
||||
whitelist = true,
|
||||
forbidNonWhitelisted = true
|
||||
): RequestHandler => {
|
||||
export const validationMiddleware = (): RequestHandler => {
|
||||
// TODO:(IDONTSUDO) need TOKEN
|
||||
// return nextTick
|
||||
return (req, res, next) => {};
|
||||
|
|
|
@ -4,10 +4,15 @@ extensions();
|
|||
|
||||
export class ExecError extends Error {
|
||||
static isExecError(e: any): ExecError | void {
|
||||
if ("type" in e && "script" in e && "unixTime" in e && "error" in e) {
|
||||
return new ExecError(e.type, e.event, e.data);
|
||||
try {
|
||||
if (e) {
|
||||
if ("type" in e && "script" in e && "unixTime" in e && "error" in e) {
|
||||
return new ExecError(e.type, e.event, e.data);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
script: string;
|
||||
unixTime: number;
|
||||
|
@ -34,10 +39,15 @@ export class SpawnError extends Error {
|
|||
this.unixTime = Date.now();
|
||||
}
|
||||
static isError(errorType: any): SpawnError | void {
|
||||
if ("command" in errorType && "error" in errorType && "execPath" in errorType) {
|
||||
return new SpawnError(errorType.command, errorType.execPath, errorType.error);
|
||||
try {
|
||||
if (errorType) {
|
||||
if ("command" in errorType && "error" in errorType && "execPath" in errorType) {
|
||||
return new SpawnError(errorType.command, errorType.execPath, errorType.error);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,14 @@ export class ExecutorResult {
|
|||
this.data = data;
|
||||
}
|
||||
static isExecutorResult(value: any): void | ExecutorResult {
|
||||
if ("type" in value && "event" in value && "data" in value) {
|
||||
return new ExecutorResult(value.type, value.event, value.data);
|
||||
try {
|
||||
if (value) {
|
||||
if ("type" in value && "event" in value && "data" in value) {
|
||||
return new ExecutorResult(value.type, value.event, value.data);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
131
server/src/core/models/robossembler_assets.ts
Normal file
131
server/src/core/models/robossembler_assets.ts
Normal file
|
@ -0,0 +1,131 @@
|
|||
import { IsEnum, IsNumber, IsOptional, IsString, ValidateNested } from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
|
||||
export enum AssetsType {
|
||||
Asset = "asset",
|
||||
Light = "light",
|
||||
}
|
||||
|
||||
export class Gravity {
|
||||
@IsNumber()
|
||||
x: number;
|
||||
@IsNumber()
|
||||
y: number;
|
||||
@IsNumber()
|
||||
z: number;
|
||||
}
|
||||
export class Pose {
|
||||
@IsNumber()
|
||||
x: number;
|
||||
@IsNumber()
|
||||
y: number;
|
||||
@IsNumber()
|
||||
z: number;
|
||||
@IsNumber()
|
||||
roll: number;
|
||||
@IsNumber()
|
||||
pitch: number;
|
||||
@IsNumber()
|
||||
yaw: number;
|
||||
}
|
||||
|
||||
export class Instance {
|
||||
@IsString()
|
||||
model_name: string;
|
||||
@IsString()
|
||||
model_id: string;
|
||||
@IsString()
|
||||
id: string;
|
||||
@ValidateNested()
|
||||
@Type(() => Pose)
|
||||
pose: Pose;
|
||||
@IsNumber()
|
||||
scale: number;
|
||||
@IsEnum(AssetsType)
|
||||
type: AssetsType;
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
parent?: string;
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
light_type?: string;
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
intencity?: number;
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
diffuse?: number[];
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
spot_angle?: number;
|
||||
}
|
||||
|
||||
export class Asset {
|
||||
@IsString()
|
||||
name: string;
|
||||
@IsString()
|
||||
ixx: string;
|
||||
@IsString()
|
||||
ixy: string;
|
||||
@IsString()
|
||||
ixz: string;
|
||||
@IsString()
|
||||
iyy: string;
|
||||
@IsString()
|
||||
izz: string;
|
||||
@IsString()
|
||||
mass: string;
|
||||
@IsString()
|
||||
posX: string;
|
||||
@IsString()
|
||||
posY: string;
|
||||
@IsString()
|
||||
posZ: string;
|
||||
@IsString()
|
||||
eulerX: string;
|
||||
@IsString()
|
||||
eulerY: string;
|
||||
@IsString()
|
||||
eulerZ: string;
|
||||
@IsString()
|
||||
iyz: string;
|
||||
@IsString()
|
||||
meshPath: string;
|
||||
@IsString()
|
||||
friction: string;
|
||||
@IsString()
|
||||
centerMassX: string;
|
||||
@IsString()
|
||||
centerMassY: string;
|
||||
@IsString()
|
||||
centerMassZ: string;
|
||||
}
|
||||
|
||||
export class Physics {
|
||||
@IsString()
|
||||
engine_name: string;
|
||||
@Type(() => Gravity)
|
||||
gravity: Gravity;
|
||||
}
|
||||
|
||||
export class RobossemblerAssets {
|
||||
@ValidateNested()
|
||||
@Type(() => Asset)
|
||||
assets: Asset[];
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => Instance)
|
||||
instances: Instance[];
|
||||
|
||||
@IsOptional()
|
||||
@ValidateNested()
|
||||
@Type(() => Physics)
|
||||
physics: Physics;
|
||||
convertLocalPathsToServerPaths(server_address: string): RobossemblerAssets {
|
||||
this.assets = this.assets.map((el) => {
|
||||
el.meshPath = server_address + el.meshPath;
|
||||
return el;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
3
server/src/core/models/static_files.ts
Normal file
3
server/src/core/models/static_files.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export enum StaticFiles {
|
||||
robossembler_assets = "robossembler_assets.json",
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
import { ClassConstructor, plainToInstance } from "class-transformer";
|
||||
import { ReadFileAndParseJsonUseCase } from "../usecases/read_file_and_parse_json";
|
||||
import { Result } from "../helpers/result";
|
||||
import { validate, ValidationError } from "class-validator";
|
||||
const skipMissingProperties = false,
|
||||
whitelist = true,
|
||||
forbidNonWhitelisted = true;
|
||||
|
||||
export class ReadingJsonFileAndConvertingToInstanceClass<T> {
|
||||
model: ClassConstructor<T>;
|
||||
constructor(cls: ClassConstructor<T>) {
|
||||
this.model = cls;
|
||||
}
|
||||
call = async (path: string): Promise<Result<string, T>> => {
|
||||
const result = await new ReadFileAndParseJsonUseCase().call(path);
|
||||
if (result.isFailure()) {
|
||||
return result.forward();
|
||||
}
|
||||
const json = result.value;
|
||||
const model = plainToInstance(this.model, json);
|
||||
const errors = await validate(model as object, { skipMissingProperties, whitelist, forbidNonWhitelisted });
|
||||
if (errors.length > 0) {
|
||||
const message = errors.map((error: ValidationError) => Object.values(error.constraints)).join(", ");
|
||||
return Result.error(message);
|
||||
} else {
|
||||
return Result.ok(model as T);
|
||||
}
|
||||
};
|
||||
}
|
|
@ -4,7 +4,7 @@ import {
|
|||
} from "../../features/project_instance/models/project_instance_database_model";
|
||||
import { pipelineRealTimeService } from "../../features/realtime/realtime_presentation";
|
||||
import { App } from "../controllers/app";
|
||||
import { CreateFolderUseCase } from "../usecases/crete_folder_usecase";
|
||||
import { CreateFolderUseCase } from "../usecases/create_folder_usecase";
|
||||
import { SearchDataBaseModelUseCase } from "../usecases/search_database_model_usecase";
|
||||
|
||||
export class SetLastActivePipelineToRealTimeServiceScenario {
|
||||
|
@ -12,12 +12,11 @@ export class SetLastActivePipelineToRealTimeServiceScenario {
|
|||
const result = await new SearchDataBaseModelUseCase<IProjectInstanceModel>(ProjectInstanceDbModel).call({
|
||||
isActive: true,
|
||||
});
|
||||
|
||||
if (result.isSuccess()) {
|
||||
const projectModel = result.value;
|
||||
const projectPath = App.staticFilesStoreDir() + result.value.rootDir + "/";
|
||||
await result.map(async (el) => {
|
||||
const projectModel = el;
|
||||
const projectPath = App.staticFilesStoreDir() + projectModel.rootDir + "/";
|
||||
await new CreateFolderUseCase().call(projectPath);
|
||||
pipelineRealTimeService.setPipelineDependency(projectModel.project.pipelines, projectPath, projectModel._id);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -21,57 +21,61 @@ export class ExecutorProgramService
|
|||
|
||||
constructor(execPath: string, maxTime: number | null = null) {
|
||||
super();
|
||||
this.execPath = execPath;
|
||||
this.execPath = execPath.pathNormalize();
|
||||
this.maxTime = maxTime;
|
||||
}
|
||||
|
||||
private async workerExecuted(command: string, workerType: WorkerType, args: Array<string> | undefined = undefined) {
|
||||
cluster.setupPrimary({
|
||||
exec: __dirname + "/../helpers/worker_computed.js",
|
||||
});
|
||||
try {
|
||||
cluster.setupPrimary({
|
||||
exec: __dirname + "/../helpers/worker_computed.js",
|
||||
});
|
||||
|
||||
const worker = cluster.fork();
|
||||
const worker = cluster.fork();
|
||||
|
||||
await delay(300);
|
||||
await delay(300);
|
||||
|
||||
this.worker = worker;
|
||||
this.worker = worker;
|
||||
|
||||
const workerDataExec: WorkerDataExec = {
|
||||
command: command,
|
||||
execPath: this.execPath,
|
||||
type: workerType,
|
||||
cliArgs: args,
|
||||
};
|
||||
worker.send(workerDataExec);
|
||||
worker.on("message", (e) => {
|
||||
const spawnError = SpawnError.isError(e);
|
||||
const workerDataExec: WorkerDataExec = {
|
||||
command: command,
|
||||
execPath: this.execPath,
|
||||
type: workerType,
|
||||
cliArgs: args,
|
||||
};
|
||||
worker.send(workerDataExec);
|
||||
worker.on("message", (e) => {
|
||||
const spawnError = SpawnError.isError(e);
|
||||
|
||||
if (spawnError instanceof SpawnError) {
|
||||
this.emit(Result.error(spawnError));
|
||||
return;
|
||||
if (spawnError instanceof SpawnError) {
|
||||
this.emit(Result.error(spawnError));
|
||||
return;
|
||||
}
|
||||
const execError = ExecError.isExecError(e);
|
||||
|
||||
if (execError instanceof ExecError) {
|
||||
this.emit(Result.error(execError));
|
||||
return;
|
||||
}
|
||||
|
||||
const executorResult = ExecutorResult.isExecutorResult(e);
|
||||
if (executorResult instanceof ExecutorResult) {
|
||||
this.emit(Result.ok(executorResult));
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (this.maxTime != null) {
|
||||
setTimeout(() => {
|
||||
this.worker.kill();
|
||||
this.emit(
|
||||
Result.error(
|
||||
WorkerType.EXEC ? new ExecError(command, "timeout err") : new SpawnError(command, "timeout err")
|
||||
)
|
||||
);
|
||||
}, this.maxTime!);
|
||||
}
|
||||
|
||||
const executorResult = ExecutorResult.isExecutorResult(e);
|
||||
|
||||
if (executorResult instanceof ExecutorResult) {
|
||||
this.emit(Result.ok(executorResult));
|
||||
return;
|
||||
}
|
||||
|
||||
const execError = ExecError.isExecError(e);
|
||||
|
||||
if (execError instanceof ExecError) {
|
||||
this.emit(Result.error(execError));
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (this.maxTime != null) {
|
||||
setTimeout(() => {
|
||||
this.worker.kill();
|
||||
this.emit(
|
||||
Result.error(WorkerType.EXEC ? new ExecError(command, "timeout err") : new SpawnError(command, "timeout err"))
|
||||
);
|
||||
}, this.maxTime!);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { ExecError } from "../models/exec_error_model";
|
|||
import { ExecutorResult } from "../models/executor_result";
|
||||
import { ActivePipeline } from "../models/active_pipeline_model";
|
||||
import { IPipeline } from "../models/process_model";
|
||||
import { Iteration } from "./stack_service";
|
||||
import { Iteration, StackService } from "./stack_service";
|
||||
|
||||
export class PipelineRealTimeService extends TypedEvent<ActivePipeline> {
|
||||
status: ActivePipeline;
|
||||
|
@ -65,9 +65,10 @@ export class PipelineRealTimeService extends TypedEvent<ActivePipeline> {
|
|||
this.status["path"] = path;
|
||||
}
|
||||
runPipeline(): void {
|
||||
// const stack = new StackService(this.pipelineModels, this.path);
|
||||
// this.status["pipelineIsRunning"] = true;
|
||||
// stack.on(this.pipelineSubscriber);
|
||||
// stack.call();
|
||||
const stack = new StackService(this.pipelineModels, this.status.path);
|
||||
|
||||
this.status["pipelineIsRunning"] = true;
|
||||
stack.on(this.pipelineSubscriber);
|
||||
stack.call();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import { Trigger } from "../../features/triggers/models/trigger_database_model";
|
|||
|
||||
export interface Iteration {
|
||||
hashes: IHashesCache | null;
|
||||
process: IPipeline;
|
||||
pipeline: IPipeline;
|
||||
result?: ExecError | SpawnError | ExecutorResult;
|
||||
}
|
||||
|
||||
|
@ -36,12 +36,12 @@ export class StackService extends TypedEvent<Iteration[]> implements IStackServi
|
|||
el = this.commandHandler(el);
|
||||
this.callStack.push({
|
||||
hashes: null,
|
||||
process: el,
|
||||
pipeline: el,
|
||||
});
|
||||
}
|
||||
}
|
||||
private commandHandler(processMetaData: IPipeline) {
|
||||
processMetaData.process.command = processMetaData.process.command.replace("$PATH", this.path);
|
||||
processMetaData.process.command = processMetaData.process.command.replace("$PATH", this.path).pathNormalize();
|
||||
return processMetaData;
|
||||
}
|
||||
public async call() {
|
||||
|
@ -52,10 +52,7 @@ export class StackService extends TypedEvent<Iteration[]> implements IStackServi
|
|||
}
|
||||
async execStack(stackNumber: number, stackLayer: Iteration): Promise<void | boolean> {
|
||||
const executorService = new ExecutorProgramService(this.path);
|
||||
executorService.call(stackLayer.process.process.type, stackLayer.process.process.command);
|
||||
executorService.on((e) => {
|
||||
console.log(e);
|
||||
});
|
||||
executorService.call(stackLayer.pipeline.process.type, stackLayer.pipeline.process.command);
|
||||
const filesChangeNotifierService = new FilesChangeNotifierService(this.path);
|
||||
|
||||
filesChangeNotifierService.call();
|
||||
|
@ -73,7 +70,7 @@ export class StackService extends TypedEvent<Iteration[]> implements IStackServi
|
|||
result.map(async (el) => {
|
||||
this.callStack.at(stackNumber).result = el;
|
||||
this.callStack.at(stackNumber).hashes = filesChangeNotifierService.hashes;
|
||||
(await this.triggerExec(stackLayer.process.trigger, stackNumber)).map(() => {
|
||||
(await this.triggerExec(stackLayer.pipeline.trigger, stackNumber)).map(() => {
|
||||
filesChangeNotifierService.cancel();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { App } from "../controllers/app";
|
||||
import { FileSystemRepository } from "../repository/file_system_repository";
|
||||
import { CreateFolderUseCase } from "./crete_folder_usecase";
|
||||
import { CreateFolderUseCase } from "./create_folder_usecase";
|
||||
|
||||
export class CheckAndCreateStaticFilesFolderUseCase {
|
||||
fileSystemRepository: FileSystemRepository;
|
||||
|
|
|
@ -9,7 +9,7 @@ export class CreateFolderUseCase {
|
|||
call = async (path: string): Promise<Result<Error, string>> => {
|
||||
try {
|
||||
if (await this.fileSystemRepository.dirIsExists(path)) {
|
||||
return Result.error(new Error("createFolderUseCase create dir "));
|
||||
return Result.ok("ok");
|
||||
}
|
||||
await this.fileSystemRepository.createDir(path);
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
export class FindPredicateModelAndUpdateDatabaseModelUseCase<D> {
|
||||
databaseModel: D;
|
||||
|
||||
constructor(model) {
|
||||
this.databaseModel = model;
|
||||
}
|
||||
async call(conditions: Partial<D>, update: Partial<D>) {
|
||||
const dbModel = this.databaseModel as any;
|
||||
dbModel.findOneAndUpdate(conditions, update);
|
||||
}
|
||||
}
|
7
server/src/core/usecases/get_server_address_usecase.ts
Normal file
7
server/src/core/usecases/get_server_address_usecase.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { Result } from "../helpers/result";
|
||||
|
||||
export class GetServerAddressUseCase {
|
||||
call = (): Result<string, string> => {
|
||||
return Result.ok("http://localhost:4001");
|
||||
};
|
||||
}
|
21
server/src/core/usecases/read_file_and_parse_json.ts
Normal file
21
server/src/core/usecases/read_file_and_parse_json.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { Result } from "../helpers/result";
|
||||
import { FileSystemRepository } from "../repository/file_system_repository";
|
||||
|
||||
export class ReadFileAndParseJsonUseCase {
|
||||
fileSystemRepository: FileSystemRepository;
|
||||
|
||||
constructor() {
|
||||
this.fileSystemRepository = new FileSystemRepository();
|
||||
}
|
||||
async call<T>(path: string): Promise<Result<string, T>> {
|
||||
try {
|
||||
if (RegExp(path).test("^(.+)/([^/]+)$")) {
|
||||
return Result.error(`ReadFileAndParseJsonUseCase got the bad way: ${path}`);
|
||||
}
|
||||
const file = await this.fileSystemRepository.readFileAsync(path);
|
||||
return Result.ok(JSON.parse(file.toString()));
|
||||
} catch (error) {
|
||||
return Result.error(`ReadFileAndParseJsonUseCase is not json type file parse path:${path}`);
|
||||
}
|
||||
}
|
||||
}
|
4
server/src/core/validations/core_validation.ts
Normal file
4
server/src/core/validations/core_validation.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export abstract class CoreValidation {
|
||||
abstract regExp: RegExp;
|
||||
abstract message: string;
|
||||
}
|
6
server/src/core/validations/mongo_id_validation.ts
Normal file
6
server/src/core/validations/mongo_id_validation.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { CoreValidation } from "./core_validation";
|
||||
|
||||
export class MongoIdValidation extends CoreValidation {
|
||||
regExp = RegExp("^[0-9a-fA-F]{24}$");
|
||||
message = "is do not mongo db object uuid";
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import { App } from "../../../core/controllers/app";
|
||||
import { Result } from "../../../core/helpers/result";
|
||||
import { CreateDataBaseModelUseCase } from "../../../core/usecases/create_database_model_usecase";
|
||||
import { CreateFolderUseCase } from "../../../core/usecases/crete_folder_usecase";
|
||||
import { CreateFolderUseCase } from "../../../core/usecases/create_folder_usecase";
|
||||
import { ProjectInstanceDbModel } from "../models/project_instance_database_model";
|
||||
import { ProjectInstanceValidationModel } from "../models/project_instance_validation_model";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import { CallbackStrategyWithEmpty, ResponseBase } from "../../../core/controllers/http_controller";
|
||||
import { Result } from "../../../core/helpers/result";
|
||||
import { RobossemblerAssets } from "../../../core/models/robossembler_assets";
|
||||
import { StaticFiles } from "../../../core/models/static_files";
|
||||
import { ReadingJsonFileAndConvertingToInstanceClass } from "../../../core/scenarios/read_file_and_json_to_plain_instance_class_scenario";
|
||||
import { GetServerAddressUseCase } from "../../../core/usecases/get_server_address_usecase";
|
||||
import { PipelineStatusUseCase } from "../../realtime/domain/pipeline_status_usecase";
|
||||
|
||||
export class RobossemblerAssetsNetworkMapperScenario extends CallbackStrategyWithEmpty {
|
||||
async call(): ResponseBase {
|
||||
try {
|
||||
const result = await new PipelineStatusUseCase().call();
|
||||
|
||||
return await result.map(async (activeInstanceModel) => {
|
||||
return (
|
||||
await new ReadingJsonFileAndConvertingToInstanceClass(RobossemblerAssets).call(
|
||||
`${activeInstanceModel.path}${StaticFiles.robossembler_assets}`
|
||||
)
|
||||
).map((robossemblerAssets) => {
|
||||
return new GetServerAddressUseCase().call().map((address) => {
|
||||
return Result.ok(
|
||||
robossemblerAssets.convertLocalPathsToServerPaths(`${address}/${activeInstanceModel.projectUUID}`)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
return Result.error(error);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
import { App } from "../../../core/controllers/app";
|
||||
import { CallbackStrategyWithIdQuery, ResponseBase } from "../../../core/controllers/http_controller";
|
||||
import { Result } from "../../../core/helpers/result";
|
||||
import { CreateFolderUseCase } from "../../../core/usecases/create_folder_usecase";
|
||||
import { FindPredicateModelAndUpdateDatabaseModelUseCase } from "../../../core/usecases/find_and_update_database_model_usecase";
|
||||
import { ReadByIdDataBaseModelUseCase } from "../../../core/usecases/read_by_id_database_model_usecase";
|
||||
import { UpdateDataBaseModelUseCase } from "../../../core/usecases/update_database_model_usecase";
|
||||
import { MongoIdValidation } from "../../../core/validations/mongo_id_validation";
|
||||
import { IProjectInstanceModel, ProjectInstanceDbModel } from "../models/project_instance_database_model";
|
||||
|
||||
export class SetActiveProjectScenario extends CallbackStrategyWithIdQuery {
|
||||
idValidationExpression = new MongoIdValidation();
|
||||
|
||||
async call(id: string): ResponseBase {
|
||||
const result = await new ReadByIdDataBaseModelUseCase<IProjectInstanceModel>(ProjectInstanceDbModel).call(id);
|
||||
|
||||
if (result.isFailure()) {
|
||||
return result.forward();
|
||||
}
|
||||
|
||||
const model = result.value;
|
||||
return (await new CreateFolderUseCase().call(App.staticFilesStoreDir() + model.rootDir)).map(async () => {
|
||||
model.isActive = true;
|
||||
new FindPredicateModelAndUpdateDatabaseModelUseCase(ProjectInstanceDbModel).call({}, {});
|
||||
return (await new UpdateDataBaseModelUseCase(ProjectInstanceDbModel).call(model)).map(() => {
|
||||
return Result.ok(`project ${id} is active`);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
import { CrudController } from "../../core/controllers/crud_controller";
|
||||
|
||||
import { CreateNewProjectInstanceScenario } from "./domain/create_new_project_scenario";
|
||||
import { RobossemblerAssetsNetworkMapperScenario } from "./domain/robossembler_assets_network_mapper_scenario";
|
||||
import { SetActiveProjectScenario } from "./domain/set_active_project_use_scenario";
|
||||
import { UploadCadFileToProjectScenario } from "./domain/upload_file_to_to_project_scenario";
|
||||
import { ProjectInstanceDbModel } from "./models/project_instance_database_model";
|
||||
import { ProjectInstanceValidationModel } from "./models/project_instance_validation_model";
|
||||
|
@ -14,12 +17,25 @@ export class ProjectInstancePresentation extends CrudController<
|
|||
url: "project_instance",
|
||||
databaseModel: ProjectInstanceDbModel,
|
||||
});
|
||||
|
||||
super.post(new CreateNewProjectInstanceScenario().call);
|
||||
|
||||
this.subRoutes.push({
|
||||
method: "POST",
|
||||
subUrl: "set/active/project",
|
||||
fn: new SetActiveProjectScenario(),
|
||||
});
|
||||
|
||||
this.subRoutes.push({
|
||||
method: "POST",
|
||||
subUrl: "upload",
|
||||
fn: new UploadCadFileToProjectScenario(),
|
||||
});
|
||||
|
||||
this.subRoutes.push({
|
||||
method: "GET",
|
||||
subUrl: "assets",
|
||||
fn: new RobossemblerAssetsNetworkMapperScenario(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ export class PipelineStatusUseCase {
|
|||
if (status.projectUUID !== null) {
|
||||
return Result.ok(status);
|
||||
}
|
||||
|
||||
if (status.projectUUID === null) {
|
||||
return Result.error(new Error("pipelineRealTimeService does not have an active project instance"));
|
||||
}
|
||||
|
|
|
@ -1,39 +1,55 @@
|
|||
import { App } from "../../../core/controllers/app";
|
||||
import { Result } from "../../../core/helpers/result";
|
||||
import { IPipeline } from "../../../core/models/process_model";
|
||||
import { ReadByIdDataBaseModelUseCase } from "../../../core/usecases/read_by_id_database_model_usecase";
|
||||
import { UpdateDataBaseModelUseCase } from "../../../core/usecases/update_database_model_usecase";
|
||||
import { PipelineValidationModel } from "../../pipelines/models/pipeline_validation_model";
|
||||
import {
|
||||
IProjectInstanceModel,
|
||||
ProjectInstanceDbModel,
|
||||
} from "../../project_instance/models/project_instance_database_model";
|
||||
import { RealTimeValidationModel, pipelineRealTimeService } from "../realtime_presentation";
|
||||
import { pipelineRealTimeService } from "../realtime_presentation";
|
||||
import { PipelineStatusUseCase } from "./pipeline_status_usecase";
|
||||
|
||||
const mongoPipelineModelMapper = (el: PipelineValidationModel): IPipeline => {
|
||||
const mapObj: IPipeline = {
|
||||
process: {
|
||||
type: el.process.type,
|
||||
command: el.process.command,
|
||||
isGenerating: Boolean(el.process.isGenerating),
|
||||
isLocaleCode: Boolean(el.process.isLocaleCode),
|
||||
issueType: el.process.issueType,
|
||||
},
|
||||
trigger: {
|
||||
type: el.trigger.type,
|
||||
value: el.trigger.value.map((el) => String(el)),
|
||||
},
|
||||
env: null,
|
||||
stackGenerateType: el.stackGenerateType,
|
||||
};
|
||||
return mapObj;
|
||||
};
|
||||
export class RunInstancePipelineUseCase {
|
||||
async call(model: RealTimeValidationModel): Promise<Result<Error, any>> {
|
||||
const { id } = model;
|
||||
async call(): Promise<Result<Error, any>> {
|
||||
const r = await new PipelineStatusUseCase().call();
|
||||
if (r.isFailure()) {
|
||||
return r;
|
||||
}
|
||||
const readByIdDataBaseModelUseCase = await new ReadByIdDataBaseModelUseCase<IProjectInstanceModel>(
|
||||
ProjectInstanceDbModel
|
||||
).call(id);
|
||||
).call(r.value.projectUUID);
|
||||
|
||||
if (readByIdDataBaseModelUseCase.isFailure()) {
|
||||
return readByIdDataBaseModelUseCase.forward();
|
||||
}
|
||||
|
||||
const projectModel = readByIdDataBaseModelUseCase.value;
|
||||
projectModel.isActive = true;
|
||||
const resultMapper = projectModel.project.pipelines.map((el) => mongoPipelineModelMapper(el));
|
||||
|
||||
const updateDataBaseModelUseCase = await new UpdateDataBaseModelUseCase<IProjectInstanceModel, any>(
|
||||
ProjectInstanceDbModel
|
||||
).call(projectModel);
|
||||
|
||||
if (updateDataBaseModelUseCase.isFailure()) {
|
||||
return updateDataBaseModelUseCase.forward();
|
||||
}
|
||||
pipelineRealTimeService.setPipelineDependency(
|
||||
projectModel.project.pipelines,
|
||||
resultMapper,
|
||||
App.staticFilesStoreDir() + projectModel.rootDir + "/",
|
||||
projectModel._id
|
||||
);
|
||||
|
||||
pipelineRealTimeService.runPipeline();
|
||||
|
||||
return Result.ok({ status: "ok" });
|
||||
|
|
|
@ -4,7 +4,7 @@ import { delay } from "../../src/core/helpers/delay";
|
|||
import { assert, dirname__ } from "../test";
|
||||
import { mockSimplePipeline } from "../model/mock_pipelines";
|
||||
import { FileSystemRepository } from "../../src/core/repository/file_system_repository";
|
||||
import { CreateFolderUseCase } from "../../src/core/usecases/crete_folder_usecase";
|
||||
import { CreateFolderUseCase } from "../../src/core/usecases/create_folder_usecase";
|
||||
|
||||
abstract class IStackServiceTest {
|
||||
abstract test(): Promise<boolean>;
|
||||
|
|
|
@ -37,19 +37,19 @@ const init = async () => {
|
|||
|
||||
const unitTest = async () => {
|
||||
await init();
|
||||
// await new ExecutorProgramServiceTest(dirname__).test();
|
||||
// await new FilesChangerTest(dirname__).test();
|
||||
await new ExecutorProgramServiceTest(dirname__).test();
|
||||
await new FilesChangerTest(dirname__).test();
|
||||
await new StackServiceTest(dirname__).test();
|
||||
// await new TriggerServiceTest().test();
|
||||
// await new CreateDataBaseModelUseCaseTest().test();
|
||||
// await new CreateDataBaseModelUseCaseTest().test();
|
||||
// await new DeleteDataBaseModelUseCaseTest().test();
|
||||
// await new ReadDataBaseModelUseCaseTest().test();
|
||||
// await new UpdateDataBaseModelUseCaseTest().test();
|
||||
await new TriggerServiceTest().test();
|
||||
await new CreateDataBaseModelUseCaseTest().test();
|
||||
await new CreateDataBaseModelUseCaseTest().test();
|
||||
await new DeleteDataBaseModelUseCaseTest().test();
|
||||
await new ReadDataBaseModelUseCaseTest().test();
|
||||
await new UpdateDataBaseModelUseCaseTest().test();
|
||||
|
||||
// for await (const usecase of tests) {
|
||||
// testCore.assert(await new usecase().test(), usecase.name);
|
||||
// }
|
||||
for await (const usecase of tests) {
|
||||
testCore.assert(await new usecase().test(), usecase.name);
|
||||
}
|
||||
};
|
||||
const presentationCrudControllers = [new TriggerPresentation()];
|
||||
const e2eTest = async () => {
|
||||
|
|
|
@ -2,7 +2,8 @@ import { ArrayExtensions } from "./array";
|
|||
import { MapExtensions } from "./map";
|
||||
import { StringExtensions } from "./string";
|
||||
|
||||
export type CallBackFunction = <T>(value: T) => void;
|
||||
export type CallBackVoidFunction = <T>(value: T) => void;
|
||||
export type CallBackStringVoidFunction = (value: string) => void;
|
||||
|
||||
declare global {
|
||||
interface Array<T> {
|
||||
|
@ -17,7 +18,7 @@ declare global {
|
|||
isEmpty(): boolean;
|
||||
}
|
||||
interface Map<K, V> {
|
||||
addValueOrMakeCallback(key: K, value: V, callBack: CallBackFunction): void;
|
||||
addValueOrMakeCallback(key: K, value: V, callBack: CallBackVoidFunction): void;
|
||||
}
|
||||
}
|
||||
export const extensions = () => {
|
||||
|
|
6
ui/src/core/model/ui_base_error.ts
Normal file
6
ui/src/core/model/ui_base_error.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export class UiBaseError {
|
||||
text: string;
|
||||
constructor(text: string) {
|
||||
this.text = text;
|
||||
}
|
||||
}
|
|
@ -16,18 +16,32 @@ export class HttpError extends Error {
|
|||
|
||||
export class HttpRepository {
|
||||
private server = "http://localhost:4001";
|
||||
public async formDataRequest<T>(method: HttpMethod, url: string, data?: any): Promise<Result<HttpError, T>> {
|
||||
let formData = new FormData();
|
||||
formData.append("file", data);
|
||||
|
||||
public async jsonRequest<T>(
|
||||
method: HttpMethod,
|
||||
url: string,
|
||||
data?: any
|
||||
): Promise<Result<HttpError, T>> {
|
||||
const reqInit = {
|
||||
body: formData,
|
||||
method: method,
|
||||
};
|
||||
|
||||
if (data !== undefined) {
|
||||
reqInit["body"] = data;
|
||||
}
|
||||
const response = await fetch(this.server + url, reqInit);
|
||||
if (response.status !== 200) {
|
||||
throw Result.error(new Error(await response.json()));
|
||||
}
|
||||
return Result.ok(response.text as T);
|
||||
}
|
||||
public async jsonRequest<T>(method: HttpMethod, url: string, data?: any): Promise<Result<HttpError, T>> {
|
||||
try {
|
||||
const reqInit = {
|
||||
body: data,
|
||||
method: method,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
};
|
||||
console.log(reqInit);
|
||||
if (data !== undefined) {
|
||||
reqInit["body"] = JSON.stringify(data);
|
||||
}
|
||||
|
@ -37,28 +51,25 @@ export class HttpRepository {
|
|||
return Result.error(new HttpError(this.server + url, response.status));
|
||||
}
|
||||
|
||||
return Result.ok(await response.json());
|
||||
return Result.ok(await response.json());
|
||||
} catch (error) {
|
||||
return Result.error(new HttpError(error, 0));
|
||||
}
|
||||
}
|
||||
|
||||
public async request<T>(
|
||||
method: HttpMethod,
|
||||
url: string,
|
||||
data?: any
|
||||
): Promise<T> {
|
||||
public async request<T>(method: HttpMethod, url: string, data?: any): Promise<Result<HttpError, T>> {
|
||||
const reqInit = {
|
||||
body: data,
|
||||
method: method,
|
||||
};
|
||||
|
||||
if (data !== undefined) {
|
||||
reqInit["body"] = data;
|
||||
}
|
||||
const response = await fetch(this.server + url, reqInit);
|
||||
if (response.status !== 200) {
|
||||
throw new Error(await response.json());
|
||||
throw Result.error(new Error(await response.json()));
|
||||
}
|
||||
return response.json();
|
||||
return Result.ok(response.text as T);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,18 +21,17 @@ import {
|
|||
CreateProcessScreen,
|
||||
CreateProcessScreenPath,
|
||||
} from "../../features/create_process/presentation/create_process_screen";
|
||||
import { ProjectRepository } from "../../features/all_projects/data/project_repository";
|
||||
import {
|
||||
CreateProjectInstancePath,
|
||||
CreateProjectInstanceScreen,
|
||||
} from "../../features/create_project_instance/create_project_instance";
|
||||
import { SceneManger, SceneManagerPath } from "../../features/scene_manager/scene_manager";
|
||||
|
||||
const idURL = ":id";
|
||||
|
||||
export const router = createBrowserRouter([
|
||||
{
|
||||
path: AllProjectScreenPath,
|
||||
loader: new ProjectRepository().loader,
|
||||
element: <AllProjectScreen />,
|
||||
},
|
||||
{
|
||||
|
@ -63,4 +62,8 @@ export const router = createBrowserRouter([
|
|||
path: CreateProjectInstancePath + idURL,
|
||||
element: <CreateProjectInstanceScreen />,
|
||||
},
|
||||
{
|
||||
path: SceneManagerPath + idURL,
|
||||
element: <SceneManger />,
|
||||
},
|
||||
]);
|
||||
|
|
|
@ -1,22 +1,49 @@
|
|||
// TODO(IDONTSUDO): нужно переписать все запросы под BaseStore
|
||||
|
||||
import { Result } from "../helper/result";
|
||||
import { UiBaseError } from "../model/ui_base_error";
|
||||
import { HttpError } from "../repository/http_repository";
|
||||
|
||||
export class BaseStore {
|
||||
export type CoreError = HttpError | Error;
|
||||
|
||||
export abstract class UiLoader {
|
||||
isLoading = false;
|
||||
isError = false;
|
||||
|
||||
async loadingHelper<T>(callBack: Promise<Result<any, T>>) {
|
||||
this.isLoading = true;
|
||||
|
||||
const result = await callBack;
|
||||
if (result.isFailure()) {
|
||||
this.isError = true;
|
||||
this.isLoading = false;
|
||||
this.errorHandingStrategy(result.error);
|
||||
return result.forward();
|
||||
}
|
||||
|
||||
this.isLoading = false;
|
||||
return result;
|
||||
}
|
||||
abstract errorHandingStrategy: (error?: any) => void;
|
||||
|
||||
mapOk = async <T>(property: string, callBack: Promise<Result<CoreError, T>>) => {
|
||||
return (
|
||||
(await this.loadingHelper(callBack))
|
||||
// eslint-disable-next-line array-callback-return
|
||||
.map((el) => {
|
||||
// @ts-ignore
|
||||
this[property] = el;
|
||||
})
|
||||
);
|
||||
};
|
||||
}
|
||||
export class SimpleErrorState extends UiLoader {
|
||||
errorHandingStrategy = () => {
|
||||
this.isError = true;
|
||||
};
|
||||
isError = false;
|
||||
}
|
||||
|
||||
export abstract class UiErrorState<T> extends UiLoader {
|
||||
abstract errorHandingStrategy: (error: T) => void;
|
||||
abstract init(): Promise<any>;
|
||||
dispose() {}
|
||||
errors: UiBaseError[] = [];
|
||||
}
|
||||
|
|
|
@ -1,27 +1,16 @@
|
|||
import { redirect } from "react-router-dom";
|
||||
import { ActivePipeline } from "../../../core/model/active_pipiline";
|
||||
import {
|
||||
HttpMethod,
|
||||
HttpRepository,
|
||||
} from "../../../core/repository/http_repository";
|
||||
import { PipelineInstanceScreenPath } from "../../pipeline_instance_main_screen/pipeline_instance_screen";
|
||||
import { ActivePipeline } from "../../../core/model/active_pipeline";
|
||||
import { HttpMethod, HttpRepository } from "../../../core/repository/http_repository";
|
||||
import { IProjectModel } from "../model/project_model";
|
||||
|
||||
export class ProjectRepository extends HttpRepository {
|
||||
async getAllProject() {
|
||||
return this.jsonRequest<IProjectModel[]>(HttpMethod.GET, "/project");
|
||||
return this.jsonRequest<IProjectModel[]>(HttpMethod.GET, "/project_instance");
|
||||
}
|
||||
|
||||
|
||||
async getActivePipeline() {
|
||||
return this.jsonRequest<ActivePipeline>(HttpMethod.GET, "/realtime");
|
||||
}
|
||||
loader = async () => {
|
||||
const result = await this.getActivePipeline();
|
||||
|
||||
// if (result.isSuccess() && result.value.projectUUID !== null) {
|
||||
// return redirect(PipelineInstanceScreenPath + result.value.projectUUID);
|
||||
// }
|
||||
|
||||
return null;
|
||||
};
|
||||
async setActivePipeline(id: string) {
|
||||
return this.jsonRequest(HttpMethod.POST, `/project_instance/set/active/project?id=${id}`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,18 @@ import { ProjectRepository } from "../data/project_repository";
|
|||
import { LoadPage } from "../../../core/ui/pages/load_page";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { SelectProjectScreenPath } from "../../select_project/presentation/select_project";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Button } from "antd";
|
||||
import { PipelineInstanceScreenPath } from "../../pipeline_instance_main_screen/pipeline_instance_screen";
|
||||
|
||||
export const AllProjectScreenPath = "/";
|
||||
|
||||
export const AllProjectScreen: React.FunctionComponent = observer(() => {
|
||||
const [allProjectStore] = React.useState(
|
||||
() => new AllProjectStore(new ProjectRepository())
|
||||
);
|
||||
const [allProjectStore] = React.useState(() => new AllProjectStore(new ProjectRepository()));
|
||||
const navigate = useNavigate();
|
||||
|
||||
React.useEffect(() => {
|
||||
allProjectStore.init();
|
||||
}, [allProjectStore]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -23,8 +28,33 @@ export const AllProjectScreen: React.FunctionComponent = observer(() => {
|
|||
isLoading={allProjectStore.isLoading}
|
||||
children={
|
||||
<div>
|
||||
<h1>Projects</h1>
|
||||
<h5 style={{ backgroundColor: "ButtonShadow" }}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
navigate(PipelineInstanceScreenPath + allProjectStore.activePipeline?.projectUUID ?? "");
|
||||
}}
|
||||
>
|
||||
Project main panel
|
||||
</Button>
|
||||
{allProjectStore.activePipeline?.projectUUID ?? "loading"}
|
||||
</h5>
|
||||
{allProjectStore.projectsModels?.map((el) => {
|
||||
return <div>{el.description}</div>;
|
||||
return (
|
||||
<div style={{ margin: "10px", backgroundColor: "Highlight" }}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
allProjectStore.setPipelineActive(el._id ?? "").then(() => {
|
||||
allProjectStore.init();
|
||||
navigate(PipelineInstanceScreenPath + el._id ?? "");
|
||||
});
|
||||
}}
|
||||
>
|
||||
set active project
|
||||
</Button>
|
||||
<div style={{ margin: "10px", display: "contents" }}> {el.description}</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
}
|
||||
|
|
|
@ -1,24 +1,62 @@
|
|||
import makeAutoObservable from "mobx-store-inheritance";
|
||||
import { ProjectRepository } from "../data/project_repository";
|
||||
import { IProjectModel } from "../model/project_model";
|
||||
import { BaseStore } from "../../../core/store/base_store";
|
||||
import { SimpleErrorState } from "../../../core/store/base_store";
|
||||
import { ActivePipeline } from "../../../core/model/active_pipeline";
|
||||
|
||||
export class AllProjectStore extends BaseStore {
|
||||
interface IProjectView {
|
||||
isActive: boolean;
|
||||
description: string;
|
||||
id: string;
|
||||
}
|
||||
export class ProjectView {
|
||||
isActive: boolean;
|
||||
description: string;
|
||||
id: string;
|
||||
constructor(view: IProjectView) {
|
||||
this.isActive = view.isActive;
|
||||
this.description = view.description;
|
||||
this.id = view.id;
|
||||
}
|
||||
}
|
||||
export class AllProjectStore extends SimpleErrorState {
|
||||
projectsModels?: IProjectModel[];
|
||||
repository: ProjectRepository;
|
||||
redirect = false;
|
||||
activePipeline?: ActivePipeline;
|
||||
constructor(repository: ProjectRepository) {
|
||||
super();
|
||||
this.repository = repository;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
async getProjects() {
|
||||
const result = await this.loadingHelper(this.repository.getAllProject());
|
||||
if (result.isSuccess()) {
|
||||
this.projectsModels = result.value;
|
||||
}
|
||||
async getProjects(): Promise<void> {
|
||||
await this.mapOk<IProjectModel[]>("projectsModels", this.repository.getAllProject());
|
||||
}
|
||||
|
||||
|
||||
async getActiveProject(): Promise<void> {
|
||||
await this.mapOk<ActivePipeline>("activePipeline", this.repository.getActivePipeline());
|
||||
}
|
||||
async foo(): Promise<void> {
|
||||
this.isLoading = true;
|
||||
const result = await this.repository.getActivePipeline();
|
||||
result.fold(
|
||||
(success) => {
|
||||
this.activePipeline = success;
|
||||
this.isLoading = false;
|
||||
},
|
||||
(_error) => {
|
||||
this.isError = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async init() {
|
||||
await Promise.all([this.getProjects(), this.getActiveProject()]);
|
||||
await this.projectViewGenerate();
|
||||
}
|
||||
projectViewGenerate() {
|
||||
this.projectsModels = this.projectsModels?.filter((el) => el._id === this.activePipeline?.projectUUID);
|
||||
}
|
||||
async setPipelineActive(id: string) {
|
||||
await this.loadingHelper(this.repository.setActivePipeline(id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,7 @@ export const CreatePipelineScreen: React.FunctionComponent = observer(() => {
|
|||
icon={Icon.add}
|
||||
/>
|
||||
<div style={{ flexGrow: "1" }}>
|
||||
<Button onClick={() => createPipelineStore.createPipeline()}>
|
||||
Save result
|
||||
</Button>
|
||||
<Button onClick={() => createPipelineStore.createPipeline()}>Save result</Button>
|
||||
<List
|
||||
headers="new pipeline"
|
||||
values={createPipelineStore.pipelineViewModels}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { CreatePipelineRepository } from "../data/create_pipeline_repository";
|
|||
import { ITriggerModel } from "../../../core/model/trigger_model";
|
||||
import { IProcess } from "../../create_process/model/process_model";
|
||||
import { message } from "antd";
|
||||
import { BaseStore } from "../../../core/store/base_store";
|
||||
import { SimpleErrorState } from "../../../core/store/base_store";
|
||||
|
||||
enum Type {
|
||||
PROCESS,
|
||||
|
@ -16,7 +16,7 @@ export interface UnionView {
|
|||
uuid?: string;
|
||||
}
|
||||
|
||||
export class CreatePipelineStore extends BaseStore {
|
||||
export class CreatePipelineStore extends SimpleErrorState {
|
||||
repository: CreatePipelineRepository;
|
||||
triggersModels: ITriggerModel[] = [];
|
||||
processModels: IProcess[] = [];
|
||||
|
@ -34,9 +34,7 @@ export class CreatePipelineStore extends BaseStore {
|
|||
}
|
||||
|
||||
filterPipelineViewModel(index: number): void {
|
||||
this.pipelineViewModels = this.pipelineViewModels.filter(
|
||||
(_el, i) => i !== index
|
||||
);
|
||||
this.pipelineViewModels = this.pipelineViewModels.filter((_el, i) => i !== index);
|
||||
}
|
||||
addTrigger(e: string, id: string): void {
|
||||
const lastElement = this.pipelineViewModels.lastElement();
|
||||
|
@ -82,12 +80,8 @@ export class CreatePipelineStore extends BaseStore {
|
|||
message.error("not found pipelines process");
|
||||
return;
|
||||
}
|
||||
const triggerId = this.pipelineViewModels.find(
|
||||
(el) => el.type === Type.TRIGGER
|
||||
)!.uuid as string;
|
||||
const processId = this.pipelineViewModels.find(
|
||||
(el) => el.type === Type.PROCESS
|
||||
)!.uuid as string;
|
||||
const triggerId = this.pipelineViewModels.find((el) => el.type === Type.TRIGGER)!.uuid as string;
|
||||
const processId = this.pipelineViewModels.find((el) => el.type === Type.PROCESS)!.uuid as string;
|
||||
|
||||
this.repository.savePipeline({
|
||||
process: processId,
|
||||
|
@ -96,33 +90,11 @@ export class CreatePipelineStore extends BaseStore {
|
|||
}
|
||||
|
||||
async loadProcess() {
|
||||
this.isLoading = true;
|
||||
const result = await this.repository.getProcessed();
|
||||
result.fold(
|
||||
(s) => {
|
||||
this.processModels = s;
|
||||
},
|
||||
(_e) => {
|
||||
this.isError = true;
|
||||
}
|
||||
);
|
||||
this.isLoading = false;
|
||||
this.mapOk("processModels", this.repository.getProcessed());
|
||||
}
|
||||
|
||||
async loadTriggers() {
|
||||
this.isLoading = true;
|
||||
const result = await this.repository.getTriggers(1);
|
||||
result.fold(
|
||||
(s) => {
|
||||
this.triggersModels = s;
|
||||
},
|
||||
(_e) => {
|
||||
this.isError = true;
|
||||
}
|
||||
);
|
||||
this.isLoading = false;
|
||||
this.mapOk("triggersModels", this.repository.getTriggers());
|
||||
}
|
||||
}
|
||||
export const createPipelineStore = new CreatePipelineStore(
|
||||
new CreatePipelineRepository()
|
||||
);
|
||||
export const createPipelineStore = new CreatePipelineStore(new CreatePipelineRepository());
|
||||
|
|
|
@ -8,8 +8,8 @@ class ProcessStore {
|
|||
this.repository = repository;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
async saveResult(model:IProcess) {
|
||||
await this.repository.save(model)
|
||||
async saveResult(model: IProcess) {
|
||||
await this.repository.save(model);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
import * as React from "react";
|
||||
import { LoadPage } from "../../core/ui/pages/load_page";
|
||||
import { createProjectStore } from "./create_project_store";
|
||||
import { LoadPage as MainPage } from "../../core/ui/pages/load_page";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { Col, Row, Input, Button } from "antd";
|
||||
import { ReactComponent as AddIcon } from "../../core/assets/icons/add.svg";
|
||||
import { CreatePipelineScreenPath } from "../create_pipeline/presentation/create_pipeline_screen";
|
||||
import { CreateProjectStore } from "./create_project_store";
|
||||
import { CreateProjectRepository } from "./create_project_repository";
|
||||
|
||||
export const CreateProjectScreenPath = "/create_project";
|
||||
|
||||
export const CreateProjectScreen: React.FunctionComponent = observer(() => {
|
||||
const [createProjectStore] = React.useState(() => new CreateProjectStore(new CreateProjectRepository()));
|
||||
|
||||
React.useEffect(() => {
|
||||
createProjectStore.init();
|
||||
}, [createProjectStore]);
|
||||
return (
|
||||
<>
|
||||
<LoadPage
|
||||
<MainPage
|
||||
path={CreatePipelineScreenPath}
|
||||
largeText={"Create project"}
|
||||
minText={"add new pipelines?"}
|
||||
|
@ -48,21 +54,14 @@ export const CreateProjectScreen: React.FunctionComponent = observer(() => {
|
|||
})}
|
||||
</Col>
|
||||
<Col>
|
||||
|
||||
<Row>
|
||||
<Input
|
||||
style={{ width: "250px" }}
|
||||
onChange={(e) =>
|
||||
createProjectStore.setDescriptionToNewProject(
|
||||
e.target.value
|
||||
)
|
||||
}
|
||||
onChange={(e) => createProjectStore.setDescriptionToNewProject(e.target.value)}
|
||||
placeholder="project description"
|
||||
/>
|
||||
|
||||
<Button onClick={() => createProjectStore.saveProject()}>
|
||||
save
|
||||
</Button>
|
||||
<Button onClick={() => createProjectStore.saveProject()}>save</Button>
|
||||
</Row>
|
||||
|
||||
{createProjectStore.newProjectViews.map((el, index) => {
|
||||
|
@ -87,4 +86,3 @@ export const CreateProjectScreen: React.FunctionComponent = observer(() => {
|
|||
</>
|
||||
);
|
||||
});
|
||||
|
|
@ -1,12 +1,9 @@
|
|||
import makeAutoObservable from "mobx-store-inheritance";
|
||||
import {
|
||||
CreateProjectRepository,
|
||||
PipelineModel,
|
||||
} from "./create_project_repository";
|
||||
import { CreateProjectRepository, PipelineModel } from "./create_project_repository";
|
||||
import { message } from "antd";
|
||||
import { BaseStore } from "../../core/store/base_store";
|
||||
import { SimpleErrorState } from "../../core/store/base_store";
|
||||
|
||||
class CreateProjectStore extends BaseStore {
|
||||
export class CreateProjectStore extends SimpleErrorState {
|
||||
repository: CreateProjectRepository;
|
||||
|
||||
pipelineModels?: PipelineModel[];
|
||||
|
@ -17,25 +14,16 @@ class CreateProjectStore extends BaseStore {
|
|||
super();
|
||||
this.repository = repository;
|
||||
makeAutoObservable(this);
|
||||
this.loadPipelines();
|
||||
}
|
||||
|
||||
async init() {
|
||||
await this.loadPipelines();
|
||||
}
|
||||
async addPipeline(model: PipelineModel) {
|
||||
this.newProjectViews.push(model);
|
||||
}
|
||||
|
||||
async loadPipelines() {
|
||||
this.isLoading = true;
|
||||
const result = await this.repository.getAllPipelines();
|
||||
result.fold(
|
||||
(s) => {
|
||||
this.pipelineModels = s;
|
||||
},
|
||||
(_e) => {
|
||||
this.isError = true;
|
||||
}
|
||||
);
|
||||
this.isLoading = false;
|
||||
this.mapOk("pipelineModels", this.repository.getAllPipelines());
|
||||
}
|
||||
|
||||
setDescriptionToNewProject(value: string): void {
|
||||
|
@ -71,7 +59,3 @@ class CreateProjectStore extends BaseStore {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const createProjectStore = new CreateProjectStore(
|
||||
new CreateProjectRepository()
|
||||
);
|
||||
|
|
|
@ -12,16 +12,17 @@ export const CreateProjectInstanceScreen = observer(() => {
|
|||
() => new CreateProjectInstanceStore(new CreateProjectInstanceRepository())
|
||||
);
|
||||
const id = useParams().id;
|
||||
createProjectInstanceStore.getProjectById(id as string)
|
||||
React.useEffect(() => {}, [id, createProjectInstanceStore]);
|
||||
return (
|
||||
<>
|
||||
<Upload
|
||||
onChange={(e) => {
|
||||
console.log(e);
|
||||
createProjectInstanceStore.file = e.file.originFileObj;
|
||||
}}
|
||||
>
|
||||
<Button>Upload root entity</Button>
|
||||
</Upload>
|
||||
<Button onClick={() => createProjectInstanceStore.saveInstance()}>Save</Button>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import {
|
||||
HttpMethod,
|
||||
HttpRepository,
|
||||
} from "../../core/repository/http_repository";
|
||||
import { HttpMethod, HttpRepository } from "../../core/repository/http_repository";
|
||||
|
||||
// this.subRoutes.push({
|
||||
// method: "POST",
|
||||
// subUrl: "upload
|
||||
export class CreateProjectInstanceRepository extends HttpRepository {
|
||||
async getProjectInstance(id: string) {
|
||||
return await this.jsonRequest(HttpMethod.GET, "");
|
||||
async setProjectRootFile() {
|
||||
return await this.formDataRequest(HttpMethod.POST, "/project_instance/upload/");
|
||||
}
|
||||
// async getProjectInstance(id: string) {
|
||||
// return await this.jsonRequest(HttpMethod.GET, "");
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
import makeAutoObservable from "mobx-store-inheritance";
|
||||
import { BaseStore } from "../../core/store/base_store";
|
||||
import { SimpleErrorState } from "../../core/store/base_store";
|
||||
import { CreateProjectInstanceRepository } from "./create_project_instance_repository";
|
||||
import { message } from "antd";
|
||||
import { HttpMethod } from "../../core/repository/http_repository";
|
||||
|
||||
export class CreateProjectInstanceStore extends BaseStore {
|
||||
export class CreateProjectInstanceStore extends SimpleErrorState {
|
||||
file?: File;
|
||||
|
||||
saveInstance(): void {
|
||||
if (this.file === undefined) {
|
||||
message.error("Need upload file");
|
||||
} else {
|
||||
// this.repository.formDataRequest(HttpMethod.POST, "", this.file);
|
||||
}
|
||||
}
|
||||
constructor(repository: CreateProjectInstanceRepository) {
|
||||
super();
|
||||
this.repository = repository;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
repository: CreateProjectInstanceRepository;
|
||||
async getProjectById(id: string) {
|
||||
const result = await this.loadingHelper(this.repository.getProjectInstance(id))
|
||||
if(result.isSuccess()){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,36 +2,40 @@ import * as React from "react";
|
|||
import Editor from "@monaco-editor/react";
|
||||
import { Button } from "antd";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { triggerStore } from "../trigger_store";
|
||||
import { CallBackStringVoidFunction } from "../../../../core/extensions/extensions";
|
||||
|
||||
export const CodeTriggerForm: React.FunctionComponent = observer(() => {
|
||||
return (
|
||||
<>
|
||||
<div style={{ width: "100%", backgroundColor: "black", height: "1px" }} />
|
||||
interface ICodeTriggerFormProps {
|
||||
codeTriggerValue: string;
|
||||
clearTriggerCode: VoidFunction;
|
||||
saveCode: VoidFunction;
|
||||
writeNewTrigger: CallBackStringVoidFunction;
|
||||
}
|
||||
|
||||
<Editor
|
||||
height="40vh"
|
||||
defaultLanguage="javascript"
|
||||
value={triggerStore.codeTriggerValue}
|
||||
onChange={(v) => {
|
||||
triggerStore.writeNewTrigger(v);
|
||||
}}
|
||||
onValidate={(_m) => {}}
|
||||
/>
|
||||
export const CodeTriggerForm: React.FunctionComponent<ICodeTriggerFormProps> = observer(
|
||||
(props: ICodeTriggerFormProps) => {
|
||||
return (
|
||||
<>
|
||||
<div style={{ width: "100%", backgroundColor: "black", height: "1px" }} />
|
||||
|
||||
<div style={{ width: "100%", backgroundColor: "black", height: "1px" }} />
|
||||
<div style={{ height: "10px" }} />
|
||||
<Editor
|
||||
height="40vh"
|
||||
defaultLanguage="javascript"
|
||||
value={props.codeTriggerValue}
|
||||
onChange={(v) => {
|
||||
props.writeNewTrigger(v ?? "");
|
||||
}}
|
||||
onValidate={(_m) => {}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
onClick={() => triggerStore.saveCode()}
|
||||
style={{ marginLeft: "10px", marginRight: "10px" }}
|
||||
>
|
||||
Save code
|
||||
</Button>
|
||||
<div style={{ width: "100%", backgroundColor: "black", height: "1px" }} />
|
||||
<div style={{ height: "10px" }} />
|
||||
|
||||
<Button onClick={() => triggerStore.clearTriggerCode()}>
|
||||
Reset code
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
});
|
||||
<Button onClick={() => props.saveCode()} style={{ marginLeft: "10px", marginRight: "10px" }}>
|
||||
Save code
|
||||
</Button>
|
||||
|
||||
<Button onClick={() => props.clearTriggerCode()}>Reset code</Button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -3,50 +3,49 @@ import { Formik } from "formik";
|
|||
import { SubmitButton, Input, ResetButton, Form, FormItem } from "formik-antd";
|
||||
import { Row, Col } from "antd";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { triggerStore } from "../trigger_store";
|
||||
import { TriggerType } from "../../../../core/model/trigger_model";
|
||||
import { validateRequired } from "../../../../core/helper/validate";
|
||||
|
||||
export const FileTriggerForm: React.FunctionComponent = observer(() => {
|
||||
return (
|
||||
<>
|
||||
<div style={{ marginTop: 80 }}>
|
||||
<Formik
|
||||
initialValues={{
|
||||
value: "",
|
||||
}}
|
||||
onSubmit={(values, actions) => {
|
||||
triggerStore.pushTrigger(values.value, TriggerType.FILE);
|
||||
actions.setSubmitting(false);
|
||||
actions.resetForm();
|
||||
}}
|
||||
validate={(values) => {
|
||||
if (values.value.length === 0) {
|
||||
return false;
|
||||
}
|
||||
return {};
|
||||
}}
|
||||
render={() => (
|
||||
<Form>
|
||||
<div style={{ background: "white", flex: 1, padding: 40 }}>
|
||||
<FormItem
|
||||
name="value"
|
||||
required={true}
|
||||
validate={validateRequired}
|
||||
>
|
||||
<Input name="value" placeholder="regExp file" />
|
||||
</FormItem>
|
||||
<Row style={{ marginTop: 60 }}>
|
||||
<Col offset={8}>
|
||||
<ResetButton>Reset</ResetButton>
|
||||
<SubmitButton>Submit</SubmitButton>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Form>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
});
|
||||
export interface IFileTriggerFormProps {
|
||||
pushTrigger: (value: string, type: TriggerType) => void;
|
||||
}
|
||||
export const FileTriggerForm: React.FunctionComponent<IFileTriggerFormProps> = observer(
|
||||
(props: IFileTriggerFormProps) => {
|
||||
return (
|
||||
<>
|
||||
<div style={{ marginTop: 80 }}>
|
||||
<Formik
|
||||
initialValues={{
|
||||
value: "",
|
||||
}}
|
||||
onSubmit={(values, actions) => {
|
||||
props.pushTrigger(values.value, TriggerType.FILE);
|
||||
actions.setSubmitting(false);
|
||||
actions.resetForm();
|
||||
}}
|
||||
validate={(values) => {
|
||||
if (values.value.length === 0) {
|
||||
return false;
|
||||
}
|
||||
return {};
|
||||
}}
|
||||
render={() => (
|
||||
<Form>
|
||||
<div style={{ background: "white", flex: 1, padding: 40 }}>
|
||||
<FormItem name="value" required={true} validate={validateRequired}>
|
||||
<Input name="value" placeholder="regExp file" />
|
||||
</FormItem>
|
||||
<Row style={{ marginTop: 60 }}>
|
||||
<Col offset={8}>
|
||||
<ResetButton>Reset</ResetButton>
|
||||
<SubmitButton>Submit</SubmitButton>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Form>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -2,35 +2,20 @@ import * as React from "react";
|
|||
import { Button, Col, Row, Switch, Typography, Input } from "antd";
|
||||
import { CodeTriggerForm } from "./components/code_trigger_form";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { triggerStore } from "./trigger_store";
|
||||
import { FileTriggerForm } from "./components/file_trigger_form";
|
||||
import { ReactComponent as DeleteIcon } from "../../../core/assets/icons/delete.svg";
|
||||
import { Loader } from "../../../core/ui/loader/loader";
|
||||
import { TriggerRepository } from "../data/trigger_repository";
|
||||
import { TriggerStore } from "./trigger_store";
|
||||
import { TriggerViewModel } from "../model/trigger_form_view_model";
|
||||
import { CallBackStringVoidFunction } from "../../../core/extensions/extensions";
|
||||
|
||||
const { Title } = Typography;
|
||||
|
||||
const Header = observer(() => {
|
||||
return (
|
||||
<Row style={{ justifyItems: "center", alignItems: "center" }}>
|
||||
<div style={{ height: "37px" }}>
|
||||
<Switch
|
||||
checked={triggerStore.getTriggerType()}
|
||||
onChange={() => triggerStore.setTriggerType()}
|
||||
/>
|
||||
</div>
|
||||
<Title level={2}>
|
||||
Trigger editor: {triggerStore.getTriggerDescription()}
|
||||
</Title>
|
||||
<div style={{ width: "10px" }}></div>
|
||||
<Button onClick={() => triggerStore.saveResult()}>Save result</Button>
|
||||
</Row>
|
||||
);
|
||||
});
|
||||
|
||||
const Bottom = observer(() => {
|
||||
const Bottom = observer((props: { triggers: TriggerViewModel[]; callBack: CallBackStringVoidFunction }) => {
|
||||
return (
|
||||
<Col>
|
||||
{triggerStore.triggers.map((el) => {
|
||||
{props.triggers.map((el) => {
|
||||
return (
|
||||
<Row
|
||||
style={{
|
||||
|
@ -38,40 +23,50 @@ const Bottom = observer(() => {
|
|||
}}
|
||||
>
|
||||
{el.value}
|
||||
<DeleteIcon onClick={() => triggerStore.deleteItem(el.id)} />
|
||||
<DeleteIcon onClick={() => props.callBack(el.id)} />
|
||||
</Row>
|
||||
);
|
||||
})}
|
||||
</Col>
|
||||
);
|
||||
});
|
||||
export const CreateTriggerScreenPath = '/create/trigger'
|
||||
export const CreateTriggerScreenPath = "/create/trigger";
|
||||
|
||||
export const TriggerScreen: React.FunctionComponent = observer(() => {
|
||||
const [triggerStore] = React.useState(() => new TriggerStore(new TriggerRepository()));
|
||||
return (
|
||||
<>
|
||||
<main>
|
||||
{!triggerStore.isLoading ? (
|
||||
<>
|
||||
<Header />,
|
||||
<Input
|
||||
placeholder="trigger description"
|
||||
onChange={() => triggerStore.changeTriggerDescription}
|
||||
/>
|
||||
<Row style={{ justifyItems: "center", alignItems: "center" }}>
|
||||
<div style={{ height: "37px" }}>
|
||||
<Switch checked={triggerStore.getTriggerType()} onChange={() => triggerStore.setTriggerType()} />
|
||||
</div>
|
||||
<Title level={2}>Trigger editor: {triggerStore.getTriggerDescription()}</Title>
|
||||
<div style={{ width: "10px" }}></div>
|
||||
<Button onClick={() => triggerStore.saveResult()}>Save result</Button>
|
||||
</Row>
|
||||
<Input placeholder="trigger description" onChange={() => triggerStore.changeTriggerDescription} />
|
||||
{triggerStore.getTriggerType() ? (
|
||||
<>
|
||||
<FileTriggerForm />
|
||||
<FileTriggerForm pushTrigger={triggerStore.pushTrigger} />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<CodeTriggerForm />
|
||||
<CodeTriggerForm
|
||||
codeTriggerValue={triggerStore.codeTriggerValue}
|
||||
clearTriggerCode={triggerStore.clearTriggerCode}
|
||||
saveCode={triggerStore.saveCode}
|
||||
writeNewTrigger={triggerStore.writeNewTrigger}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<Bottom />
|
||||
<Bottom triggers={triggerStore.triggers} callBack={triggerStore.deleteItem} />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
|
||||
<Loader/>
|
||||
<Loader />
|
||||
</>
|
||||
)}
|
||||
</main>
|
||||
|
|
|
@ -3,9 +3,9 @@ import { v4 as uuidv4 } from "uuid";
|
|||
import { TriggerType } from "../../../core/model/trigger_model";
|
||||
import { TriggerRepository } from "../data/trigger_repository";
|
||||
import { TriggerViewModel } from "../model/trigger_form_view_model";
|
||||
import { BaseStore } from "../../../core/store/base_store";
|
||||
import { SimpleErrorState } from "../../../core/store/base_store";
|
||||
|
||||
class TriggerStore extends BaseStore {
|
||||
export class TriggerStore extends SimpleErrorState {
|
||||
constructor(repository: TriggerRepository) {
|
||||
super();
|
||||
this.triggerType = TriggerType.FILE;
|
||||
|
@ -39,9 +39,7 @@ class TriggerStore extends BaseStore {
|
|||
this.triggerType = TriggerType.FILE;
|
||||
};
|
||||
getTriggerDescription = (): string => {
|
||||
return this.triggerType === TriggerType.FILE
|
||||
? TriggerType.FILE
|
||||
: TriggerType.PROCESS;
|
||||
return this.triggerType === TriggerType.FILE ? TriggerType.FILE : TriggerType.PROCESS;
|
||||
};
|
||||
pushTrigger = (value: string, type: TriggerType): void => {
|
||||
this.triggers.push({
|
||||
|
@ -72,16 +70,15 @@ class TriggerStore extends BaseStore {
|
|||
}
|
||||
}
|
||||
async saveResult(): Promise<void> {
|
||||
this.isLoading = true;
|
||||
await this.repository.save({
|
||||
type: this.getTriggerDescription(),
|
||||
description: this.triggerDescription,
|
||||
value: this.triggers.map((el) => {
|
||||
return el.value;
|
||||
}),
|
||||
});
|
||||
this.isLoading = false;
|
||||
await this.loadingHelper(
|
||||
this.repository.save({
|
||||
type: this.getTriggerDescription(),
|
||||
description: this.triggerDescription,
|
||||
value: this.triggers.map((el) => {
|
||||
return el.value;
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const triggerStore = new TriggerStore(new TriggerRepository());
|
||||
|
|
68
ui/src/features/p.tsx
Normal file
68
ui/src/features/p.tsx
Normal file
|
@ -0,0 +1,68 @@
|
|||
export {};
|
||||
// import React from "react";
|
||||
// import { CoreError, UiErrorState } from "../core/store/base_store";
|
||||
// import { SelectProjectStore } from "./select_project/presentation/select_project_store";
|
||||
|
||||
// export declare type ClassConstructor<T> = {
|
||||
// new (...args: any[]): T;
|
||||
// };
|
||||
// interface MobxReactComponentProps<T extends UiErrorState<CoreError>, ClassConstructor> {
|
||||
// store: ClassConstructor;
|
||||
// children: (element: T) => React.ReactElement;
|
||||
// }
|
||||
|
||||
// class UiStateErrorComponent<T extends UiErrorState<CoreError>, K> extends React.Component<
|
||||
// MobxReactComponentProps<T, K>,
|
||||
// { store: T | undefined }
|
||||
// > {
|
||||
// async componentDidMount(): Promise<void> {
|
||||
// const store = this.props.store as ClassConstructor<T>;
|
||||
// console.log(store);
|
||||
// const s = new store();
|
||||
// this.setState({ store: s });
|
||||
// if (this.state !== null) {
|
||||
// await this.state.store?.init();
|
||||
// }
|
||||
// }
|
||||
// componentWillUnmount(): void {
|
||||
// if (this.state.store !== undefined) {
|
||||
// this.state.store.dispose();
|
||||
// }
|
||||
// }
|
||||
|
||||
// render() {
|
||||
// if (this.state !== null) {
|
||||
// if (this.state.store?.isLoading) {
|
||||
// return <>Loading</>;
|
||||
// }
|
||||
// if (this.state.store !== undefined) {
|
||||
// return this.props.children(this.state.store);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return (
|
||||
// <div>
|
||||
// <>{this.props.children}</>
|
||||
// </div>
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// export const ExampleScreen: React.FC = () => {
|
||||
// return (
|
||||
// <div>
|
||||
// <UiStateErrorComponent<SelectProjectStore, {}> store={SelectProjectStore}>
|
||||
// {(store) => {
|
||||
// console.log(store);
|
||||
// return (
|
||||
// <div>
|
||||
// {store.projects.map((el) => {
|
||||
// return <>{el}</>;
|
||||
// })}
|
||||
// </div>
|
||||
// );
|
||||
// }}
|
||||
// </UiStateErrorComponent>
|
||||
// </div>
|
||||
// );
|
||||
// };
|
|
@ -4,13 +4,12 @@ import { PipelineInstanceStore } from "./pipeline_instance_store";
|
|||
|
||||
export const PipelineInstanceScreenPath = "/pipeline_instance/";
|
||||
export const PipelineInstanceScreen: React.FunctionComponent = () => {
|
||||
const [pipelineInstanceStore] = React.useState(
|
||||
() => new PipelineInstanceStore()
|
||||
);
|
||||
|
||||
const [pipelineInstanceStore] = React.useState(() => new PipelineInstanceStore());
|
||||
React.useEffect(() => {}, [pipelineInstanceStore]);
|
||||
return (
|
||||
<LoadPage
|
||||
needBackButton={false}
|
||||
needBackButton={true}
|
||||
largeText={"Project instance active"}
|
||||
isError={pipelineInstanceStore.isError}
|
||||
isLoading={pipelineInstanceStore.isLoading}
|
||||
children={<div></div>}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import makeAutoObservable from "mobx-store-inheritance";
|
||||
import { BaseStore } from "../../core/store/base_store";
|
||||
import { SimpleErrorState } from "../../core/store/base_store";
|
||||
|
||||
export class PipelineInstanceStore extends BaseStore {
|
||||
export class PipelineInstanceStore extends SimpleErrorState {
|
||||
constructor() {
|
||||
super();
|
||||
makeAutoObservable(this);
|
||||
|
|
|
@ -2,6 +2,7 @@ import * as React from "react";
|
|||
import { SceneMangerStore, StaticAssetItemModel } from "./scene_manager_store";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { StaticAssetModelView } from "./components/static_asset_item_view";
|
||||
import { useParams } from "react-router-dom";
|
||||
|
||||
// const useKeyLister = (fn: Function) => {
|
||||
// const pressed = new Map();
|
||||
|
@ -26,21 +27,25 @@ import { StaticAssetModelView } from "./components/static_asset_item_view";
|
|||
|
||||
// return [];
|
||||
// };
|
||||
|
||||
export const SceneManagerPath = "/scene/manager/";
|
||||
export const SceneManger = observer(() => {
|
||||
const canvasRef = React.useRef<HTMLCanvasElement>(null);
|
||||
|
||||
const [sceneMangerStore] = React.useState(() => new SceneMangerStore());
|
||||
const id = useParams().id as string;
|
||||
|
||||
React.useEffect(() => {
|
||||
sceneMangerStore.loadGl(canvasRef.current!);
|
||||
if (id) {
|
||||
sceneMangerStore.loadScene(id, canvasRef.current!);
|
||||
}
|
||||
return () => {
|
||||
sceneMangerStore.dispose();
|
||||
};
|
||||
});
|
||||
}, [id, sceneMangerStore]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>{sceneMangerStore.errors.isNotEmpty() ? <>{sceneMangerStore.errors[0].text}</> : <></>}</div>
|
||||
<div style={{ position: "absolute" }}>
|
||||
{sceneMangerStore.sceneItems.map((el) => {
|
||||
if (el instanceof StaticAssetItemModel) {
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
/* eslint-disable array-callback-return */
|
||||
import { makeAutoObservable } from "mobx";
|
||||
import makeAutoObservable from "mobx-store-inheritance";
|
||||
import { CoreThereRepository } from "../../core/repository/core_there_repository";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { Vector2 } from "three";
|
||||
import { HttpError, HttpMethod, HttpRepository } from "../../core/repository/http_repository";
|
||||
import { UiErrorState } from "../../core/store/base_store";
|
||||
import { UiBaseError } from "../../core/model/ui_base_error";
|
||||
|
||||
export class BaseSceneItemModel {
|
||||
id: string;
|
||||
|
@ -24,12 +27,35 @@ export class StaticAssetItemModel extends BaseSceneItemModel {
|
|||
}
|
||||
}
|
||||
|
||||
export class SceneMangerStore {
|
||||
export enum RobossemblerFiles {
|
||||
robossemblerAssets = "robossembler_assets.json",
|
||||
}
|
||||
|
||||
export class SceneMangerStore extends UiErrorState<HttpError> {
|
||||
async init(): Promise<any> {}
|
||||
errorHandingStrategy = (error: HttpError) => {
|
||||
if (error.status === 404) {
|
||||
this.errors.push(new UiBaseError(`${RobossemblerFiles.robossemblerAssets} not found to project`));
|
||||
}
|
||||
};
|
||||
|
||||
async loadScene(sceneId: string, canvasRef: HTMLCanvasElement) {
|
||||
(
|
||||
await this.loadingHelper(
|
||||
this.httpRepository.jsonRequest(HttpMethod.GET, "/" + sceneId + "/" + RobossemblerFiles.robossemblerAssets)
|
||||
)
|
||||
).map((el) => {
|
||||
this.loadGl(canvasRef);
|
||||
});
|
||||
}
|
||||
coreThereRepository: null | CoreThereRepository = null;
|
||||
httpRepository: HttpRepository;
|
||||
sceneItems: BaseSceneItemModel[] = [];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
makeAutoObservable(this);
|
||||
this.httpRepository = new HttpRepository();
|
||||
}
|
||||
|
||||
loadGl(canvasRef: HTMLCanvasElement): void {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Result } from "../../../core/helper/result";
|
||||
import {
|
||||
HttpMethod,
|
||||
HttpRepository,
|
||||
} from "../../../core/repository/http_repository";
|
||||
import { HttpMethod, HttpRepository } from "../../../core/repository/http_repository";
|
||||
import { IProjectModel } from "../model/project_model";
|
||||
|
||||
export class SelectProjectRepository extends HttpRepository {
|
||||
async setActiveProject(id: string) {
|
||||
return await this.jsonRequest(HttpMethod.POST, `/project?${id}`);
|
||||
}
|
||||
async getAllProjects(page = 1): Promise<Result<Error, IProjectModel[]>> {
|
||||
return await this.jsonRequest(HttpMethod.GET, `/project?${page}`);
|
||||
}
|
||||
|
|
|
@ -3,16 +3,16 @@ import { observer } from "mobx-react-lite";
|
|||
import { LoadPage } from "../../../core/ui/pages/load_page";
|
||||
import { CreateProjectScreenPath } from "../../create_project/create_project_screen";
|
||||
import { SelectProjectStore } from "./select_project_store";
|
||||
import { SelectProjectRepository } from "../data/select_project_repository";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { CreateProjectInstancePath } from "../../create_project_instance/create_project_instance";
|
||||
import { Button } from "antd";
|
||||
export const SelectProjectScreenPath = "/select_project";
|
||||
|
||||
export const SelectProjectScreen: React.FunctionComponent = observer(() => {
|
||||
const [selectProjectStore] = React.useState(
|
||||
() => new SelectProjectStore(new SelectProjectRepository())
|
||||
);
|
||||
const [selectProjectStore] = React.useState(() => new SelectProjectStore());
|
||||
React.useEffect(() => {
|
||||
selectProjectStore.init();
|
||||
}, [selectProjectStore]);
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
|
@ -22,17 +22,13 @@ export const SelectProjectScreen: React.FunctionComponent = observer(() => {
|
|||
largeText={"Select project"}
|
||||
minText={"add new project?"}
|
||||
isLoading={selectProjectStore.isLoading}
|
||||
isError={selectProjectStore.isError}
|
||||
isError={selectProjectStore.errors.isNotEmpty()}
|
||||
children={selectProjectStore.projects.map((el) => {
|
||||
return (
|
||||
<>
|
||||
<div>{el.description}</div>
|
||||
<div>
|
||||
<Button
|
||||
onClick={() => navigate(CreateProjectInstancePath + el._id)}
|
||||
>
|
||||
create instance
|
||||
</Button>
|
||||
<Button onClick={() => navigate(CreateProjectInstancePath + el._id)}>create instance</Button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -1,33 +1,31 @@
|
|||
import makeAutoObservable from "mobx-store-inheritance";
|
||||
import { SelectProjectRepository } from "../data/select_project_repository";
|
||||
import { IProjectModel } from "../model/project_model";
|
||||
import { BaseStore } from "../../../core/store/base_store";
|
||||
import { CoreError, UiErrorState } from "../../../core/store/base_store";
|
||||
|
||||
export class SelectProjectStore extends UiErrorState<CoreError> {
|
||||
errorHandingStrategy = (error: CoreError) => {
|
||||
console.log(error);
|
||||
};
|
||||
|
||||
export class SelectProjectStore extends BaseStore {
|
||||
repository: SelectProjectRepository;
|
||||
|
||||
errors = [];
|
||||
page = 1;
|
||||
projects: IProjectModel[] = [];
|
||||
|
||||
constructor(repository: SelectProjectRepository) {
|
||||
super()
|
||||
this.repository = repository;
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.repository = new SelectProjectRepository();
|
||||
makeAutoObservable(this);
|
||||
this.getPipelines();
|
||||
}
|
||||
|
||||
async setActiveProject(id: string): Promise<void> {
|
||||
this.loadingHelper(this.repository.setActiveProject(id));
|
||||
}
|
||||
async getPipelines(): Promise<void> {
|
||||
this.isLoading = true;
|
||||
const result = await this.repository.getAllProjects(this.page);
|
||||
result.fold(
|
||||
(s) => {
|
||||
this.projects = s;
|
||||
},
|
||||
(_e) => {
|
||||
this.isError = true;
|
||||
}
|
||||
);
|
||||
this.isLoading = false;
|
||||
await this.mapOk("projects", this.repository.getAllProjects(this.page));
|
||||
}
|
||||
async init() {
|
||||
await this.getPipelines();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,21 +2,19 @@ import React from "react";
|
|||
import ReactDOM from "react-dom/client";
|
||||
|
||||
import "antd/dist/antd.min.css";
|
||||
import { RouterProvider } from "react-router-dom";
|
||||
|
||||
import { router } from "./core/routers/routers";
|
||||
import { SocketLister } from "./features/socket_lister/socket_lister";
|
||||
import { extensions } from "./core/extensions/extensions";
|
||||
import { SceneManger } from "./features/scene_manager/scene_manager";
|
||||
import { SocketLister } from "./features/socket_lister/socket_lister";
|
||||
import { RouterProvider } from "react-router-dom";
|
||||
import { router } from "./core/routers/routers";
|
||||
|
||||
extensions();
|
||||
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
|
||||
|
||||
root.render(
|
||||
<>
|
||||
{/* <SocketLister>
|
||||
<SocketLister>
|
||||
<RouterProvider router={router} />
|
||||
</SocketLister> */}
|
||||
<SceneManger />
|
||||
</SocketLister>
|
||||
</>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue