diff --git a/src/app/(withHeader)/script/create/page.module.css b/src/app/(withHeader)/script/create/page.module.css index 48de259..89a8948 100644 --- a/src/app/(withHeader)/script/create/page.module.css +++ b/src/app/(withHeader)/script/create/page.module.css @@ -77,8 +77,88 @@ padding: 1rem 2rem; } -@media (width < 610px) { - .flex { - flex-wrap: wrap; - } +.checkboxLabel { + display: flex; + align-items: center; + gap: 1rem; + cursor: pointer; + padding: 1rem 1.25rem; + border-radius: 0.75rem; + border: 1px solid var(--color-gray-border); + background-color: var(--color-white-main); + transition: border-color 0.2s, box-shadow 0.2s; +} + +.checkboxLabel:hover { + border-color: var(--color-purple-dark); + box-shadow: 0 0 0 1px var(--color-purple-dark); +} + +.checkboxInput { + position: absolute; + opacity: 0; + width: 0; + height: 0; + pointer-events: none; +} + +.checkboxMark { + flex-shrink: 0; + width: 1.25rem; + height: 1.25rem; + border: 2px solid var(--color-gray-border); + border-radius: 0.375rem; + background-color: var(--color-white-main); + transition: all 0.2s; + position: relative; +} + +.checkboxInput:focus-visible + .checkboxMark { + outline: 2px solid var(--color-purple-dark); + outline-offset: 2px; +} + +.checkboxLabel:hover .checkboxMark { + border-color: var(--color-purple-dark); +} + +.checkboxInput:checked ~ .checkboxMark { + background-color: var(--color-purple-dark); + border-color: var(--color-purple-dark); +} + +.checkboxMark::after { + content: ''; + position: absolute; + display: none; + left: 0.25rem; + top: 0.0625rem; + width: 0.375rem; + height: 0.625rem; + border: solid var(--color-white-main); + border-width: 0 2px 2px 0; + transform: rotate(45deg); +} + +.checkboxInput:checked ~ .checkboxMark::after { + display: block; +} + +.checkboxContent { + display: flex; + flex-direction: column; + gap: 0.25rem; +} + +.checkboxText { + font-weight: 600; + font-size: var(--font-size-sm); + color: var(--color-dark-main); + user-select: none; +} + +.checkboxHint { + font-size: var(--font-size-xxs); + color: var(--color-gray-light2); + user-select: none; } diff --git a/src/app/(withHeader)/script/create/page.tsx b/src/app/(withHeader)/script/create/page.tsx index a4037ad..8687c1c 100644 --- a/src/app/(withHeader)/script/create/page.tsx +++ b/src/app/(withHeader)/script/create/page.tsx @@ -13,7 +13,7 @@ import { getSendValues } from '@/utils/send'; import { useCustomToast } from '@/hooks/other/useCustomToast'; import { notifyMutationError } from '@/utils/notifyMutationError'; import { ScriptFormInfoBlock } from '@/components/ScriptFormInfoBlock'; -import { ValueType } from '@/shared/api/generated/data-contracts'; +import { ValueType, Visibility } from '@/shared/api/generated/data-contracts'; export default function CreatePage() { const router = useRouter(); @@ -48,6 +48,7 @@ export default function CreatePage() { name: values.name.trim(), desc: values.desc?.trim() ?? '', archiveID: String(file_id), + visibility: values.visibility, in: values.inputParams.map((param) => ({ name: param.name.trim(), desc: param.desc?.trim() ?? '', diff --git a/src/app/(withHeader)/script/create/page.usecase.tsx b/src/app/(withHeader)/script/create/page.usecase.tsx index ea723b9..d85e7a9 100644 --- a/src/app/(withHeader)/script/create/page.usecase.tsx +++ b/src/app/(withHeader)/script/create/page.usecase.tsx @@ -3,6 +3,7 @@ import styles from '@/app/(withHeader)/script/create/page.module.css'; import cn from 'classnames'; import { AddParametrIcon } from '@/components/icons/AddParametricon'; import * as Yup from 'yup'; +import { Visibility } from '@/shared/api/generated/data-contracts'; const trimString = (v: unknown) => (typeof v === 'string' ? v.trim() : v); @@ -90,6 +91,7 @@ export interface ScriptFormValues { name: string; desc: string; file: File | null; + visibility: Visibility; inputParams: ParameterWithId[]; outputParams: ParameterWithId[]; } @@ -98,6 +100,7 @@ export const ScriptInitialValues: ScriptFormValues = { name: '', desc: '', file: null, + visibility: Visibility.Private, inputParams: [], outputParams: [], }; diff --git a/src/components/ScriptFormInfoBlock/index.tsx b/src/components/ScriptFormInfoBlock/index.tsx index d3ea8a8..63b515a 100644 --- a/src/components/ScriptFormInfoBlock/index.tsx +++ b/src/components/ScriptFormInfoBlock/index.tsx @@ -4,6 +4,7 @@ import { FastField, type FastFieldProps } from 'formik'; import { InfoBlockLayout } from '@/layouts/InfoBlockLayout'; import InputLayout from '@/layouts/InputLayout'; import { pageCreateUsecase } from '@/app/(withHeader)/script/create/page.usecase'; +import { Visibility } from '@/shared/api/generated/data-contracts'; import styles from '@/app/(withHeader)/script/create/page.module.css'; export const ScriptFormInfoBlock: FC = memo(() => { @@ -58,6 +59,32 @@ export const ScriptFormInfoBlock: FC = memo(() => { /> )} + + + {({ form, field }: FastFieldProps) => ( + + + form.setFieldValue( + field.name, + e.target.checked ? Visibility.Public : Visibility.Private, + ) + } + aria-label='Публичный шаблон' + /> + + + Публичный шаблон + + Шаблон будет доступен всем пользователям для просмотра и запуска + + + + )} + ); }); diff --git a/src/shared/ExtendedBlock/ExtendedBlock.module.css b/src/shared/ExtendedBlock/ExtendedBlock.module.css index 231bb0e..8114e00 100644 --- a/src/shared/ExtendedBlock/ExtendedBlock.module.css +++ b/src/shared/ExtendedBlock/ExtendedBlock.module.css @@ -82,7 +82,6 @@ padding-top: 0 !important; } - @media (width <= 1024px) { .ScriptParametrsLayout__content { grid-template-columns: repeat(1, 1fr); diff --git a/src/shared/api/generated/Auth.ts b/src/shared/api/generated/Auth.ts index 266475c..6522c81 100644 --- a/src/shared/api/generated/Auth.ts +++ b/src/shared/api/generated/Auth.ts @@ -1,35 +1,37 @@ -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck -/* - * --------------------------------------------------------------- - * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## - * ## ## - * ## AUTHOR: acacode ## - * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## - * --------------------------------------------------------------- - */ - -import { LoginRequest, LoginResponse, PlainError } from './data-contracts'; -import { ContentType, HttpClient, RequestParams } from './http-client'; - -export class Auth extends HttpClient { - /** - * No description - * - * @tags auth - * @name Login - * @request POST:/auth/login - * @secure - */ - login = (data: LoginRequest, params: RequestParams = {}) => - this.request({ - path: `/auth/login`, - method: 'POST', - body: data, - secure: true, - type: ContentType.Json, - format: 'json', - ...params, - }); -} +/* eslint-disable */ +/* tslint:disable */ +// @ts-nocheck +/* + * --------------------------------------------------------------- + * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## + * ## ## + * ## AUTHOR: acacode ## + * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## + * --------------------------------------------------------------- + */ + +import { LoginRequest, LoginResponse, PlainError } from "./data-contracts"; +import { ContentType, HttpClient, RequestParams } from "./http-client"; + +export class Auth< + SecurityDataType = unknown, +> extends HttpClient { + /** + * No description + * + * @tags auth + * @name Login + * @request POST:/auth/login + * @secure + */ + login = (data: LoginRequest, params: RequestParams = {}) => + this.request({ + path: `/auth/login`, + method: "POST", + body: data, + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }); +} diff --git a/src/shared/api/generated/Blueprints.ts b/src/shared/api/generated/Blueprints.ts index 06419c2..a9bc010 100644 --- a/src/shared/api/generated/Blueprints.ts +++ b/src/shared/api/generated/Blueprints.ts @@ -1,133 +1,138 @@ -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck -/* - * --------------------------------------------------------------- - * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## - * ## ## - * ## AUTHOR: acacode ## - * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## - * --------------------------------------------------------------- - */ - -import { - CreateBlueprintRequest, - CreateBlueprintResponse, - GetBlueprintResponse, - GetBlueprintsResponse, - InvalidInputError, - PlainError, - SearchBlueprintsResponse, - StartJobRequest, - StartJobResponse, -} from './data-contracts'; -import { ContentType, HttpClient, RequestParams } from './http-client'; - -export class Blueprints extends HttpClient { - /** - * @description Возвращает полный список доступных пользователю шаблонов (blueprints). Пользователю доступны собственные шаблоны и публичные. - * - * @tags blueprints - * @name GetBlueprints - * @request GET:/blueprints - * @secure - */ - getBlueprints = (params: RequestParams = {}) => - this.request({ - path: `/blueprints`, - method: 'GET', - secure: true, - format: 'json', - ...params, - }); - /** - * @description Создаёт пользовательский шаблон (blueprint). Если пользователь является администратором (role = UserAdmin), то такой шаблон становится доступным для всех пользователей платформы. Автоматически создаёт ID шаблона. - * - * @tags blueprints - * @name CreateBlueprint - * @request POST:/blueprints - * @secure - */ - createBlueprint = (data: CreateBlueprintRequest, params: RequestParams = {}) => - this.request({ - path: `/blueprints`, - method: 'POST', - body: data, - secure: true, - type: ContentType.Json, - format: 'json', - ...params, - }); - /** - * @description Совершает нечётки поиск по имени доступных пользователю шаблонам (blueprints). Пользователю доступны собственные шаблоны и публичные. - * - * @tags blueprints - * @name SearchBlueprints - * @request GET:/blueprints/search - * @secure - */ - searchBlueprints = ( - query: { - /** Название или часть названия шаблона (blueprint). */ - name: string; - }, - params: RequestParams = {}, - ) => - this.request({ - path: `/blueprints/search`, - method: 'GET', - query: query, - secure: true, - format: 'json', - ...params, - }); - /** - * @description Возвращает конкретный шаблон (blueprint), если он доступен пользователю. Пользователю доступны собственные шаблоны и публичные. - * - * @tags blueprints - * @name GetBlueprint - * @request GET:/blueprints/{id} - * @secure - */ - getBlueprint = (id: string, params: RequestParams = {}) => - this.request({ - path: `/blueprints/${id}`, - method: 'GET', - secure: true, - format: 'json', - ...params, - }); - /** - * @description Удаляет шаблон (blueprint) пользователя. - * - * @tags blueprints - * @name DeleteBlueprint - * @request DELETE:/blueprints/{id} - * @secure - */ - deleteBlueprint = (id: string, params: RequestParams = {}) => - this.request({ - path: `/blueprints/${id}`, - method: 'DELETE', - secure: true, - ...params, - }); - /** - * @description Запускает задачу на основании шаблона указанного ID. Задача запускается в асинхронном режиме. Возвращает ID задачи. - * - * @tags blueprints - * @name StartJob - * @request POST:/blueprints/{id}/start - * @secure - */ - startJob = (id: string, data: StartJobRequest, params: RequestParams = {}) => - this.request({ - path: `/blueprints/${id}/start`, - method: 'POST', - body: data, - secure: true, - type: ContentType.Json, - format: 'json', - ...params, - }); -} +/* eslint-disable */ +/* tslint:disable */ +// @ts-nocheck +/* + * --------------------------------------------------------------- + * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## + * ## ## + * ## AUTHOR: acacode ## + * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## + * --------------------------------------------------------------- + */ + +import { + CreateBlueprintRequest, + CreateBlueprintResponse, + GetBlueprintResponse, + GetBlueprintsResponse, + InvalidInputError, + PlainError, + SearchBlueprintsResponse, + StartJobRequest, + StartJobResponse, +} from "./data-contracts"; +import { ContentType, HttpClient, RequestParams } from "./http-client"; + +export class Blueprints< + SecurityDataType = unknown, +> extends HttpClient { + /** + * @description Возвращает полный список доступных пользователю шаблонов (blueprints). Пользователю доступны собственные шаблоны и публичные. + * + * @tags blueprints + * @name GetBlueprints + * @request GET:/blueprints + * @secure + */ + getBlueprints = (params: RequestParams = {}) => + this.request({ + path: `/blueprints`, + method: "GET", + secure: true, + format: "json", + ...params, + }); + /** + * @description Создаёт пользовательский шаблон (blueprint). Если пользователь является администратором (role = UserAdmin), то такой шаблон становится доступным для всех пользователей платформы. Автоматически создаёт ID шаблона. + * + * @tags blueprints + * @name CreateBlueprint + * @request POST:/blueprints + * @secure + */ + createBlueprint = ( + data: CreateBlueprintRequest, + params: RequestParams = {}, + ) => + this.request({ + path: `/blueprints`, + method: "POST", + body: data, + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }); + /** + * @description Совершает нечётки поиск по имени доступных пользователю шаблонам (blueprints). Пользователю доступны собственные шаблоны и публичные. + * + * @tags blueprints + * @name SearchBlueprints + * @request GET:/blueprints/search + * @secure + */ + searchBlueprints = ( + query: { + /** Название или часть названия шаблона (blueprint). */ + name: string; + }, + params: RequestParams = {}, + ) => + this.request({ + path: `/blueprints/search`, + method: "GET", + query: query, + secure: true, + format: "json", + ...params, + }); + /** + * @description Возвращает конкретный шаблон (blueprint), если он доступен пользователю. Пользователю доступны собственные шаблоны и публичные. + * + * @tags blueprints + * @name GetBlueprint + * @request GET:/blueprints/{id} + * @secure + */ + getBlueprint = (id: string, params: RequestParams = {}) => + this.request({ + path: `/blueprints/${id}`, + method: "GET", + secure: true, + format: "json", + ...params, + }); + /** + * @description Удаляет шаблон (blueprint) пользователя. + * + * @tags blueprints + * @name DeleteBlueprint + * @request DELETE:/blueprints/{id} + * @secure + */ + deleteBlueprint = (id: string, params: RequestParams = {}) => + this.request({ + path: `/blueprints/${id}`, + method: "DELETE", + secure: true, + ...params, + }); + /** + * @description Запускает задачу на основании шаблона указанного ID. Задача запускается в асинхронном режиме. Возвращает ID задачи. + * + * @tags blueprints + * @name StartJob + * @request POST:/blueprints/{id}/start + * @secure + */ + startJob = (id: string, data: StartJobRequest, params: RequestParams = {}) => + this.request({ + path: `/blueprints/${id}/start`, + method: "POST", + body: data, + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }); +} diff --git a/src/shared/api/generated/Files.ts b/src/shared/api/generated/Files.ts index 8df1b2c..ee5fcc1 100644 --- a/src/shared/api/generated/Files.ts +++ b/src/shared/api/generated/Files.ts @@ -1,44 +1,46 @@ -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck -/* - * --------------------------------------------------------------- - * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## - * ## ## - * ## AUTHOR: acacode ## - * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## - * --------------------------------------------------------------- - */ - -import { PlainError, UploadFileResponse } from './data-contracts'; -import { ContentType, HttpClient, RequestParams } from './http-client'; - -export class Files extends HttpClient { - /** - * No description - * - * @tags files - * @name UploadFile - * @request POST:/files - * @secure - */ - uploadFile = ( - data: { - /** - * Файл для загрузки на сервер. - * @format binary - */ - attachment: File; - }, - params: RequestParams = {}, - ) => - this.request({ - path: `/files`, - method: 'POST', - body: data, - secure: true, - type: ContentType.FormData, - format: 'json', - ...params, - }); -} +/* eslint-disable */ +/* tslint:disable */ +// @ts-nocheck +/* + * --------------------------------------------------------------- + * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## + * ## ## + * ## AUTHOR: acacode ## + * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## + * --------------------------------------------------------------- + */ + +import { PlainError, UploadFileResponse } from "./data-contracts"; +import { ContentType, HttpClient, RequestParams } from "./http-client"; + +export class Files< + SecurityDataType = unknown, +> extends HttpClient { + /** + * No description + * + * @tags files + * @name UploadFile + * @request POST:/files + * @secure + */ + uploadFile = ( + data: { + /** + * Файл для загрузки на сервер. + * @format binary + */ + attachment: File; + }, + params: RequestParams = {}, + ) => + this.request({ + path: `/files`, + method: "POST", + body: data, + secure: true, + type: ContentType.FormData, + format: "json", + ...params, + }); +} diff --git a/src/shared/api/generated/Jobs.ts b/src/shared/api/generated/Jobs.ts index 839ad12..1a8d7b0 100644 --- a/src/shared/api/generated/Jobs.ts +++ b/src/shared/api/generated/Jobs.ts @@ -1,55 +1,57 @@ -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck -/* - * --------------------------------------------------------------- - * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## - * ## ## - * ## AUTHOR: acacode ## - * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## - * --------------------------------------------------------------- - */ - -import { GetJobsResponse, JobState, PlainError } from './data-contracts'; -import { HttpClient, RequestParams } from './http-client'; - -export class Jobs extends HttpClient { - /** - * @description Возвращает список всех пользовательских задач (jobs). Возможна фильтрация по состоянию задачи. - * - * @tags jobs - * @name GetJobs - * @request GET:/jobs - * @secure - */ - getJobs = ( - query?: { - state?: JobState; - }, - params: RequestParams = {}, - ) => - this.request({ - path: `/jobs`, - method: 'GET', - query: query, - secure: true, - format: 'json', - ...params, - }); - /** - * @description Возвращает конкретную пользовательскую задачу (job). - * - * @tags jobs - * @name GetJob - * @request GET:/jobs/{id} - * @secure - */ - getJob = (id: string, params: RequestParams = {}) => - this.request({ - path: `/jobs/${id}`, - method: 'GET', - secure: true, - format: 'json', - ...params, - }); -} +/* eslint-disable */ +/* tslint:disable */ +// @ts-nocheck +/* + * --------------------------------------------------------------- + * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## + * ## ## + * ## AUTHOR: acacode ## + * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## + * --------------------------------------------------------------- + */ + +import { GetJobsResponse, JobState, PlainError } from "./data-contracts"; +import { HttpClient, RequestParams } from "./http-client"; + +export class Jobs< + SecurityDataType = unknown, +> extends HttpClient { + /** + * @description Возвращает список всех пользовательских задач (jobs). Возможна фильтрация по состоянию задачи. + * + * @tags jobs + * @name GetJobs + * @request GET:/jobs + * @secure + */ + getJobs = ( + query?: { + state?: JobState; + }, + params: RequestParams = {}, + ) => + this.request({ + path: `/jobs`, + method: "GET", + query: query, + secure: true, + format: "json", + ...params, + }); + /** + * @description Возвращает конкретную пользовательскую задачу (job). + * + * @tags jobs + * @name GetJob + * @request GET:/jobs/{id} + * @secure + */ + getJob = (id: string, params: RequestParams = {}) => + this.request({ + path: `/jobs/${id}`, + method: "GET", + secure: true, + format: "json", + ...params, + }); +} diff --git a/src/shared/api/generated/Users.ts b/src/shared/api/generated/Users.ts index c07d168..d6f9333 100644 --- a/src/shared/api/generated/Users.ts +++ b/src/shared/api/generated/Users.ts @@ -1,126 +1,132 @@ -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck -/* - * --------------------------------------------------------------- - * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## - * ## ## - * ## AUTHOR: acacode ## - * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## - * --------------------------------------------------------------- - */ - -import { - CreateUserRequest, - CreateUserResponse, - GetUserMeResponse, - GetUserResponse, - GetUsersResponse, - InvalidInputError, - PatchUserRequest, - PatchUserResponse, - PlainError, -} from './data-contracts'; -import { ContentType, HttpClient, RequestParams } from './http-client'; - -export class Users extends HttpClient { - /** - * @description Возвращает полный список пользователей платформы. Запрос доступен только администраторам. - * - * @tags users - * @name GetUsers - * @request GET:/users - * @secure - */ - getUsers = (params: RequestParams = {}) => - this.request({ - path: `/users`, - method: 'GET', - secure: true, - format: 'json', - ...params, - }); - /** - * @description Создаёт пользователя с заданными параметрами. Доступно только для администраторов. - * - * @tags users - * @name CreateUser - * @request POST:/users - * @secure - */ - createUser = (data: CreateUserRequest, params: RequestParams = {}) => - this.request({ - path: `/users`, - method: 'POST', - body: data, - secure: true, - type: ContentType.Json, - format: 'json', - ...params, - }); - /** - * @description Возвращает информацию о текущем пользователе. - * - * @tags users - * @name GetUserMe - * @request GET:/users/me - * @secure - */ - getUserMe = (params: RequestParams = {}) => - this.request({ - path: `/users/me`, - method: 'GET', - secure: true, - format: 'json', - ...params, - }); - /** - * @description Возвращает информацию о пользователе. Доступно только для администраторов. - * - * @tags users - * @name GetUser - * @request GET:/users/{id} - * @secure - */ - getUser = (id: string, params: RequestParams = {}) => - this.request({ - path: `/users/${id}`, - method: 'GET', - secure: true, - format: 'json', - ...params, - }); - /** - * @description Обновляет информацию о пользователе. Доступно только для администраторов. - * - * @tags users - * @name PatchUser - * @request PATCH:/users/{id} - * @secure - */ - patchUser = (id: string, data: PatchUserRequest, params: RequestParams = {}) => - this.request({ - path: `/users/${id}`, - method: 'PATCH', - body: data, - secure: true, - type: ContentType.Json, - format: 'json', - ...params, - }); - /** - * @description Удаляет пользователя по его ID. Доступно только для администраторов. - * - * @tags users - * @name DeleteUser - * @request DELETE:/users/{id} - * @secure - */ - deleteUser = (id: string, params: RequestParams = {}) => - this.request({ - path: `/users/${id}`, - method: 'DELETE', - secure: true, - ...params, - }); -} +/* eslint-disable */ +/* tslint:disable */ +// @ts-nocheck +/* + * --------------------------------------------------------------- + * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## + * ## ## + * ## AUTHOR: acacode ## + * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## + * --------------------------------------------------------------- + */ + +import { + CreateUserRequest, + CreateUserResponse, + GetUserMeResponse, + GetUserResponse, + GetUsersResponse, + InvalidInputError, + PatchUserRequest, + PatchUserResponse, + PlainError, +} from "./data-contracts"; +import { ContentType, HttpClient, RequestParams } from "./http-client"; + +export class Users< + SecurityDataType = unknown, +> extends HttpClient { + /** + * @description Возвращает полный список пользователей платформы. Запрос доступен только администраторам. + * + * @tags users + * @name GetUsers + * @request GET:/users + * @secure + */ + getUsers = (params: RequestParams = {}) => + this.request({ + path: `/users`, + method: "GET", + secure: true, + format: "json", + ...params, + }); + /** + * @description Создаёт пользователя с заданными параметрами. Доступно только для администраторов. + * + * @tags users + * @name CreateUser + * @request POST:/users + * @secure + */ + createUser = (data: CreateUserRequest, params: RequestParams = {}) => + this.request({ + path: `/users`, + method: "POST", + body: data, + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }); + /** + * @description Возвращает информацию о текущем пользователе. + * + * @tags users + * @name GetUserMe + * @request GET:/users/me + * @secure + */ + getUserMe = (params: RequestParams = {}) => + this.request({ + path: `/users/me`, + method: "GET", + secure: true, + format: "json", + ...params, + }); + /** + * @description Возвращает информацию о пользователе. Доступно только для администраторов. + * + * @tags users + * @name GetUser + * @request GET:/users/{id} + * @secure + */ + getUser = (id: string, params: RequestParams = {}) => + this.request({ + path: `/users/${id}`, + method: "GET", + secure: true, + format: "json", + ...params, + }); + /** + * @description Обновляет информацию о пользователе. Доступно только для администраторов. + * + * @tags users + * @name PatchUser + * @request PATCH:/users/{id} + * @secure + */ + patchUser = ( + id: string, + data: PatchUserRequest, + params: RequestParams = {}, + ) => + this.request({ + path: `/users/${id}`, + method: "PATCH", + body: data, + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }); + /** + * @description Удаляет пользователя по его ID. Доступно только для администраторов. + * + * @tags users + * @name DeleteUser + * @request DELETE:/users/{id} + * @secure + */ + deleteUser = (id: string, params: RequestParams = {}) => + this.request({ + path: `/users/${id}`, + method: "DELETE", + secure: true, + ...params, + }); +} diff --git a/src/shared/api/generated/data-contracts.ts b/src/shared/api/generated/data-contracts.ts index 18f3095..3c0f645 100644 --- a/src/shared/api/generated/data-contracts.ts +++ b/src/shared/api/generated/data-contracts.ts @@ -11,25 +11,25 @@ */ export enum Role { - User = 'user', - Admin = 'admin', + User = "user", + Admin = "admin", } export enum JobState { - Pending = 'pending', - Running = 'running', - Finished = 'finished', + Pending = "pending", + Running = "running", + Finished = "finished", } export enum Visibility { - Public = 'public', - Private = 'private', + Public = "public", + Private = "private", } export enum ValueType { - Integer = 'integer', - Real = 'real', - String = 'string', + Integer = "integer", + Real = "real", + String = "string", } export interface Field { @@ -106,6 +106,7 @@ export interface CreateBlueprintRequest { desc?: string; in: Field[]; out: Field[]; + visibility: Visibility; } export interface StartJobRequest { diff --git a/src/shared/api/generated/http-client.ts b/src/shared/api/generated/http-client.ts index a77de4c..24ce732 100644 --- a/src/shared/api/generated/http-client.ts +++ b/src/shared/api/generated/http-client.ts @@ -1,167 +1,186 @@ -/* eslint-disable */ -/* tslint:disable */ -// @ts-nocheck -/* - * --------------------------------------------------------------- - * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## - * ## ## - * ## AUTHOR: acacode ## - * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## - * --------------------------------------------------------------- - */ - -import type { - AxiosInstance, - AxiosRequestConfig, - AxiosResponse, - HeadersDefaults, - ResponseType, -} from 'axios'; -import axios from 'axios'; - -export type QueryParamsType = Record; - -export interface FullRequestParams - extends Omit { - /** set parameter to `true` for call `securityWorker` for this request */ - secure?: boolean; - /** request path */ - path: string; - /** content type of request body */ - type?: ContentType; - /** query params */ - query?: QueryParamsType; - /** format of response (i.e. response.json() -> format: "json") */ - format?: ResponseType; - /** request body */ - body?: unknown; -} - -export type RequestParams = Omit; - -export interface ApiConfig - extends Omit { - securityWorker?: ( - securityData: SecurityDataType | null, - ) => Promise | AxiosRequestConfig | void; - secure?: boolean; - format?: ResponseType; -} - -export enum ContentType { - Json = 'application/json', - JsonApi = 'application/vnd.api+json', - FormData = 'multipart/form-data', - UrlEncoded = 'application/x-www-form-urlencoded', - Text = 'text/plain', -} - -export class HttpClient { - public instance: AxiosInstance; - private securityData: SecurityDataType | null = null; - private securityWorker?: ApiConfig['securityWorker']; - private secure?: boolean; - private format?: ResponseType; - - constructor({ - securityWorker, - secure, - format, - ...axiosConfig - }: ApiConfig = {}) { - this.instance = axios.create({ - ...axiosConfig, - baseURL: axiosConfig.baseURL || '{url}/api/v2', - }); - this.secure = secure; - this.format = format; - this.securityWorker = securityWorker; - } - - public setSecurityData = (data: SecurityDataType | null) => { - this.securityData = data; - }; - - protected mergeRequestParams( - params1: AxiosRequestConfig, - params2?: AxiosRequestConfig, - ): AxiosRequestConfig { - const method = params1.method || (params2 && params2.method); - - return { - ...this.instance.defaults, - ...params1, - ...(params2 || {}), - headers: { - ...((method && - this.instance.defaults.headers[method.toLowerCase() as keyof HeadersDefaults]) || - {}), - ...(params1.headers || {}), - ...((params2 && params2.headers) || {}), - }, - }; - } - - protected stringifyFormItem(formItem: unknown) { - if (typeof formItem === 'object' && formItem !== null) { - return JSON.stringify(formItem); - } else { - return `${formItem}`; - } - } - - protected createFormData(input: Record): FormData { - if (input instanceof FormData) { - return input; - } - return Object.keys(input || {}).reduce((formData, key) => { - const property = input[key]; - const propertyContent: any[] = property instanceof Array ? property : [property]; - - for (const formItem of propertyContent) { - const isFileType = formItem instanceof Blob || formItem instanceof File; - formData.append(key, isFileType ? formItem : this.stringifyFormItem(formItem)); - } - - return formData; - }, new FormData()); - } - - public request = async ({ - secure, - path, - type, - query, - format, - body, - ...params - }: FullRequestParams): Promise> => { - const secureParams = - ((typeof secure === 'boolean' ? secure : this.secure) && - this.securityWorker && - (await this.securityWorker(this.securityData))) || - {}; - const requestParams = this.mergeRequestParams(params, secureParams); - const responseFormat = format || this.format || undefined; - - if (type === ContentType.FormData && body && body !== null && typeof body === 'object') { - body = this.createFormData(body as Record); - } - - if (type === ContentType.Text && body && body !== null && typeof body !== 'string') { - body = JSON.stringify(body); - } - - return this.instance.request({ - ...requestParams, - headers: { - ...(requestParams.headers || {}), - ...(type ? { 'Content-Type': type } : {}), - }, - params: query, - responseType: responseFormat, - data: body, - url: path, - }); - }; -} +/* eslint-disable */ +/* tslint:disable */ +// @ts-nocheck +/* + * --------------------------------------------------------------- + * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## + * ## ## + * ## AUTHOR: acacode ## + * ## SOURCE: https://github.com/acacode/swagger-typescript-api ## + * --------------------------------------------------------------- + */ + +import type { + AxiosInstance, + AxiosRequestConfig, + AxiosResponse, + HeadersDefaults, + ResponseType, +} from "axios"; +import axios from "axios"; + +export type QueryParamsType = Record; + +export interface FullRequestParams + extends Omit { + /** set parameter to `true` for call `securityWorker` for this request */ + secure?: boolean; + /** request path */ + path: string; + /** content type of request body */ + type?: ContentType; + /** query params */ + query?: QueryParamsType; + /** format of response (i.e. response.json() -> format: "json") */ + format?: ResponseType; + /** request body */ + body?: unknown; +} + +export type RequestParams = Omit< + FullRequestParams, + "body" | "method" | "query" | "path" +>; + +export interface ApiConfig + extends Omit { + securityWorker?: ( + securityData: SecurityDataType | null, + ) => Promise | AxiosRequestConfig | void; + secure?: boolean; + format?: ResponseType; +} + +export enum ContentType { + Json = "application/json", + JsonApi = "application/vnd.api+json", + FormData = "multipart/form-data", + UrlEncoded = "application/x-www-form-urlencoded", + Text = "text/plain", +} + +export class HttpClient { + public instance: AxiosInstance; + private securityData: SecurityDataType | null = null; + private securityWorker?: ApiConfig["securityWorker"]; + private secure?: boolean; + private format?: ResponseType; + + constructor({ + securityWorker, + secure, + format, + ...axiosConfig + }: ApiConfig = {}) { + this.instance = axios.create({ + ...axiosConfig, + baseURL: axiosConfig.baseURL || "{url}/api/v2", + }); + this.secure = secure; + this.format = format; + this.securityWorker = securityWorker; + } + + public setSecurityData = (data: SecurityDataType | null) => { + this.securityData = data; + }; + + protected mergeRequestParams( + params1: AxiosRequestConfig, + params2?: AxiosRequestConfig, + ): AxiosRequestConfig { + const method = params1.method || (params2 && params2.method); + + return { + ...this.instance.defaults, + ...params1, + ...(params2 || {}), + headers: { + ...((method && + this.instance.defaults.headers[ + method.toLowerCase() as keyof HeadersDefaults + ]) || + {}), + ...(params1.headers || {}), + ...((params2 && params2.headers) || {}), + }, + }; + } + + protected stringifyFormItem(formItem: unknown) { + if (typeof formItem === "object" && formItem !== null) { + return JSON.stringify(formItem); + } else { + return `${formItem}`; + } + } + + protected createFormData(input: Record): FormData { + if (input instanceof FormData) { + return input; + } + return Object.keys(input || {}).reduce((formData, key) => { + const property = input[key]; + const propertyContent: any[] = + property instanceof Array ? property : [property]; + + for (const formItem of propertyContent) { + const isFileType = formItem instanceof Blob || formItem instanceof File; + formData.append( + key, + isFileType ? formItem : this.stringifyFormItem(formItem), + ); + } + + return formData; + }, new FormData()); + } + + public request = async ({ + secure, + path, + type, + query, + format, + body, + ...params + }: FullRequestParams): Promise> => { + const secureParams = + ((typeof secure === "boolean" ? secure : this.secure) && + this.securityWorker && + (await this.securityWorker(this.securityData))) || + {}; + const requestParams = this.mergeRequestParams(params, secureParams); + const responseFormat = format || this.format || undefined; + + if ( + type === ContentType.FormData && + body && + body !== null && + typeof body === "object" + ) { + body = this.createFormData(body as Record); + } + + if ( + type === ContentType.Text && + body && + body !== null && + typeof body !== "string" + ) { + body = JSON.stringify(body); + } + + return this.instance.request({ + ...requestParams, + headers: { + ...(requestParams.headers || {}), + ...(type ? { "Content-Type": type } : {}), + }, + params: query, + responseType: responseFormat, + data: body, + url: path, + }); + }; +}