mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 21:10:38 +03:00
Refactoring: split backendAPI into modules
This commit is contained in:
parent
4c413ca0f4
commit
f36924d0e9
|
@ -1,577 +0,0 @@
|
||||||
/**
|
|
||||||
* Module: API for backend communications.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
|
|
||||||
import { toast } from 'react-toastify';
|
|
||||||
|
|
||||||
import { type ErrorData } from '@/components/info/InfoError';
|
|
||||||
import { ILexemeData, ITextRequest, ITextResult, IWordFormPlain } from '@/models/language';
|
|
||||||
import { ILibraryItem, ILibraryUpdateData, ITargetAccessPolicy, ITargetLocation, IVersionData } from '@/models/library';
|
|
||||||
import { ILibraryCreateData } from '@/models/library';
|
|
||||||
import {
|
|
||||||
ICstSubstituteData,
|
|
||||||
IOperationCreateData,
|
|
||||||
IOperationCreatedResponse,
|
|
||||||
IOperationSchemaData,
|
|
||||||
IPositionsData,
|
|
||||||
ITargetOperation
|
|
||||||
} from '@/models/oss';
|
|
||||||
import {
|
|
||||||
IConstituentaList,
|
|
||||||
IConstituentaMeta,
|
|
||||||
ICstCreateData,
|
|
||||||
ICstCreatedResponse,
|
|
||||||
ICstMovetoData,
|
|
||||||
ICstRenameData,
|
|
||||||
ICstUpdateData,
|
|
||||||
IInlineSynthesisData,
|
|
||||||
IProduceStructureResponse,
|
|
||||||
IRSFormCloneData,
|
|
||||||
IRSFormData,
|
|
||||||
IRSFormUploadData,
|
|
||||||
ITargetCst,
|
|
||||||
IVersionCreatedResponse
|
|
||||||
} from '@/models/rsform';
|
|
||||||
import { IExpressionParse, IRSExpression } from '@/models/rslang';
|
|
||||||
import {
|
|
||||||
ICurrentUser,
|
|
||||||
IPasswordTokenData,
|
|
||||||
IRequestPasswordData,
|
|
||||||
IResetPasswordData,
|
|
||||||
ITargetUser,
|
|
||||||
ITargetUsers,
|
|
||||||
IUserInfo,
|
|
||||||
IUserLoginData,
|
|
||||||
IUserProfile,
|
|
||||||
IUserSignupData,
|
|
||||||
IUserUpdateData,
|
|
||||||
IUserUpdatePassword
|
|
||||||
} from '@/models/user';
|
|
||||||
import { buildConstants } from '@/utils/buildConstants';
|
|
||||||
|
|
||||||
const defaultOptions = {
|
|
||||||
xsrfCookieName: 'csrftoken',
|
|
||||||
xsrfHeaderName: 'x-csrftoken',
|
|
||||||
baseURL: `${buildConstants.backend}`,
|
|
||||||
withCredentials: true
|
|
||||||
};
|
|
||||||
|
|
||||||
const axiosInstance = axios.create(defaultOptions);
|
|
||||||
axiosInstance.interceptors.request.use(config => {
|
|
||||||
const token = document.cookie
|
|
||||||
.split('; ')
|
|
||||||
.find(row => row.startsWith('csrftoken='))
|
|
||||||
?.split('=')[1];
|
|
||||||
if (token) {
|
|
||||||
config.headers['x-csrftoken'] = token;
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
});
|
|
||||||
|
|
||||||
// ================ Data transfer types ================
|
|
||||||
export type DataCallback<ResponseData = undefined> = (data: ResponseData) => void;
|
|
||||||
|
|
||||||
interface IFrontRequest<RequestData, ResponseData> {
|
|
||||||
data?: RequestData;
|
|
||||||
onSuccess?: DataCallback<ResponseData>;
|
|
||||||
onError?: (error: ErrorData) => void;
|
|
||||||
setLoading?: (loading: boolean) => void;
|
|
||||||
showError?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FrontPush<DataType> extends IFrontRequest<DataType, undefined> {
|
|
||||||
data: DataType;
|
|
||||||
}
|
|
||||||
export interface FrontPull<DataType> extends IFrontRequest<undefined, DataType> {
|
|
||||||
onSuccess: DataCallback<DataType>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FrontExchange<RequestData, ResponseData> extends IFrontRequest<RequestData, ResponseData> {
|
|
||||||
data: RequestData;
|
|
||||||
onSuccess: DataCallback<ResponseData>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FrontAction extends IFrontRequest<undefined, undefined> {}
|
|
||||||
|
|
||||||
interface IAxiosRequest<RequestData, ResponseData> {
|
|
||||||
endpoint: string;
|
|
||||||
request: IFrontRequest<RequestData, ResponseData>;
|
|
||||||
options?: AxiosRequestConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== API ====================
|
|
||||||
export function getAuth(request: FrontPull<ICurrentUser>) {
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: `/users/api/auth`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postLogin(request: FrontPush<IUserLoginData>) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: '/users/api/login',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postLogout(request: FrontAction) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: '/users/api/logout',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postSignup(request: FrontExchange<IUserSignupData, IUserProfile>) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: '/users/api/signup',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getProfile(request: FrontPull<IUserProfile>) {
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: '/users/api/profile',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchProfile(request: FrontExchange<IUserUpdateData, IUserProfile>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: '/users/api/profile',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchPassword(request: FrontPush<IUserUpdatePassword>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: '/users/api/change-password',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postRequestPasswordReset(request: FrontPush<IRequestPasswordData>) {
|
|
||||||
// title: 'Request password reset',
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: '/users/api/password-reset',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postValidatePasswordToken(request: FrontPush<IPasswordTokenData>) {
|
|
||||||
// title: 'Validate password token',
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: '/users/api/password-reset/validate',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postResetPassword(request: FrontPush<IResetPasswordData>) {
|
|
||||||
// title: 'Reset password',
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: '/users/api/password-reset/confirm',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getActiveUsers(request: FrontPull<IUserInfo[]>) {
|
|
||||||
// title: 'Active users list',
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: '/users/api/active-users',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getLibrary(request: FrontPull<ILibraryItem[]>) {
|
|
||||||
// title: 'Available LibraryItems list',
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: '/api/library/active',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getAdminLibrary(request: FrontPull<ILibraryItem[]>) {
|
|
||||||
// title: 'All LibraryItems list',
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: '/api/library/all',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getTemplates(request: FrontPull<ILibraryItem[]>) {
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: '/api/library/templates',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postRSFormFromFile(request: FrontExchange<ILibraryCreateData, ILibraryItem>) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: '/api/rsforms/create-detailed',
|
|
||||||
request: request,
|
|
||||||
options: {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postCreateLibraryItem(request: FrontExchange<ILibraryCreateData, ILibraryItem>) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: '/api/library',
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postCloneLibraryItem(target: string, request: FrontExchange<IRSFormCloneData, IRSFormData>) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: `/api/library/${target}/clone`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getRSFormDetails(target: string, version: string, request: FrontPull<IRSFormData>) {
|
|
||||||
if (!version) {
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: `/api/rsforms/${target}/details`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: `/api/rsforms/${target}/versions/${version}`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchLibraryItem(target: string, request: FrontExchange<ILibraryUpdateData, ILibraryItem>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/library/${target}`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function deleteLibraryItem(target: string, request: FrontAction) {
|
|
||||||
AxiosDelete({
|
|
||||||
endpoint: `/api/library/${target}`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchSetOwner(target: string, request: FrontPush<ITargetUser>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/library/${target}/set-owner`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchSetAccessPolicy(target: string, request: FrontPush<ITargetAccessPolicy>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/library/${target}/set-access-policy`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchSetLocation(target: string, request: FrontPush<ITargetLocation>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/library/${target}/set-location`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchEditorsAdd(target: string, request: FrontPush<ITargetUser>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/library/${target}/editors-add`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchEditorsRemove(target: string, request: FrontPush<ITargetUser>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/library/${target}/editors-remove`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchEditorsSet(target: string, request: FrontPush<ITargetUsers>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/library/${target}/editors-set`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postSubscribe(target: string, request: FrontAction) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: `/api/library/${target}/subscribe`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function deleteUnsubscribe(target: string, request: FrontAction) {
|
|
||||||
AxiosDelete({
|
|
||||||
endpoint: `/api/library/${target}/unsubscribe`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getTRSFile(target: string, version: string, request: FrontPull<Blob>) {
|
|
||||||
if (!version) {
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: `/api/rsforms/${target}/export-trs`,
|
|
||||||
request: request,
|
|
||||||
options: { responseType: 'blob' }
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: `/api/versions/${version}/export-file`,
|
|
||||||
request: request,
|
|
||||||
options: { responseType: 'blob' }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postCreateConstituenta(schema: string, request: FrontExchange<ICstCreateData, ICstCreatedResponse>) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: `/api/rsforms/${schema}/cst-create`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchDeleteConstituenta(schema: string, request: FrontExchange<IConstituentaList, IRSFormData>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/rsforms/${schema}/cst-delete-multiple`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchConstituenta(target: string, request: FrontExchange<ICstUpdateData, IConstituentaMeta>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/constituents/${target}`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchRenameConstituenta(schema: string, request: FrontExchange<ICstRenameData, ICstCreatedResponse>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/rsforms/${schema}/cst-rename`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchProduceStructure(schema: string, request: FrontExchange<ITargetCst, IProduceStructureResponse>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/rsforms/${schema}/cst-produce-structure`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchSubstituteConstituents(schema: string, request: FrontExchange<ICstSubstituteData, IRSFormData>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/rsforms/${schema}/cst-substitute`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchMoveConstituenta(schema: string, request: FrontExchange<ICstMovetoData, IRSFormData>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/rsforms/${schema}/cst-moveto`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postCheckExpression(schema: string, request: FrontExchange<IRSExpression, IExpressionParse>) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: `/api/rsforms/${schema}/check`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchResetAliases(target: string, request: FrontPull<IRSFormData>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/rsforms/${target}/reset-aliases`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchRestoreOrder(target: string, request: FrontPull<IRSFormData>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/rsforms/${target}/restore-order`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchUploadTRS(target: string, request: FrontExchange<IRSFormUploadData, IRSFormData>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/rsforms/${target}/load-trs`,
|
|
||||||
request: request,
|
|
||||||
options: {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
export function patchInlineSynthesis(request: FrontExchange<IInlineSynthesisData, IRSFormData>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/operations/inline-synthesis`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getOssDetails(target: string, request: FrontPull<IOperationSchemaData>) {
|
|
||||||
AxiosGet({
|
|
||||||
endpoint: `/api/oss/${target}/details`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchUpdatePositions(schema: string, request: FrontPush<IPositionsData>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/oss/${schema}/update-positions`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postCreateOperation(
|
|
||||||
schema: string,
|
|
||||||
request: FrontExchange<IOperationCreateData, IOperationCreatedResponse>
|
|
||||||
) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: `/api/oss/${schema}/create-operation`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchDeleteOperation(schema: string, request: FrontExchange<ITargetOperation, IOperationSchemaData>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/oss/${schema}/delete-operation`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postInflectText(request: FrontExchange<IWordFormPlain, ITextResult>) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: `/api/cctext/inflect`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postParseText(request: FrontExchange<ITextRequest, ITextResult>) {
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: `/api/cctext/parse`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postGenerateLexeme(request: FrontExchange<ITextRequest, ILexemeData>) {
|
|
||||||
// title: `Parse text ${request.data.text}`,
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: `/api/cctext/generate-lexeme`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postCreateVersion(target: string, request: FrontExchange<IVersionData, IVersionCreatedResponse>) {
|
|
||||||
// title: `Create version for RSForm id=${target}`,
|
|
||||||
AxiosPost({
|
|
||||||
endpoint: `/api/rsforms/${target}/versions/create`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchVersion(target: string, request: FrontPush<IVersionData>) {
|
|
||||||
// title: `Version id=${target}`,
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/versions/${target}`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function patchRestoreVersion(target: string, request: FrontPull<IRSFormData>) {
|
|
||||||
AxiosPatch({
|
|
||||||
endpoint: `/api/versions/${target}/restore`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function deleteVersion(target: string, request: FrontAction) {
|
|
||||||
AxiosDelete({
|
|
||||||
endpoint: `/api/versions/${target}`,
|
|
||||||
request: request
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============ Helper functions =============
|
|
||||||
function AxiosGet<ResponseData>({ endpoint, request, options }: IAxiosRequest<undefined, ResponseData>) {
|
|
||||||
if (request.setLoading) request.setLoading(true);
|
|
||||||
axiosInstance
|
|
||||||
.get<ResponseData>(endpoint, options)
|
|
||||||
.then(response => {
|
|
||||||
if (request.setLoading) request.setLoading(false);
|
|
||||||
if (request.onSuccess) request.onSuccess(response.data);
|
|
||||||
})
|
|
||||||
.catch((error: Error | AxiosError) => {
|
|
||||||
if (request.setLoading) request.setLoading(false);
|
|
||||||
if (request.showError) toast.error(error.message);
|
|
||||||
if (request.onError) request.onError(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function AxiosPost<RequestData, ResponseData>({
|
|
||||||
endpoint,
|
|
||||||
request,
|
|
||||||
options
|
|
||||||
}: IAxiosRequest<RequestData, ResponseData>) {
|
|
||||||
if (request.setLoading) request.setLoading(true);
|
|
||||||
axiosInstance
|
|
||||||
.post<ResponseData>(endpoint, request.data, options)
|
|
||||||
.then(response => {
|
|
||||||
if (request.setLoading) request.setLoading(false);
|
|
||||||
if (request.onSuccess) request.onSuccess(response.data);
|
|
||||||
})
|
|
||||||
.catch((error: Error | AxiosError) => {
|
|
||||||
if (request.setLoading) request.setLoading(false);
|
|
||||||
if (request.showError) toast.error(error.message);
|
|
||||||
if (request.onError) request.onError(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function AxiosDelete<RequestData, ResponseData>({
|
|
||||||
endpoint,
|
|
||||||
request,
|
|
||||||
options
|
|
||||||
}: IAxiosRequest<RequestData, ResponseData>) {
|
|
||||||
if (request.setLoading) request.setLoading(true);
|
|
||||||
axiosInstance
|
|
||||||
.delete<ResponseData>(endpoint, options)
|
|
||||||
.then(response => {
|
|
||||||
if (request.setLoading) request.setLoading(false);
|
|
||||||
if (request.onSuccess) request.onSuccess(response.data);
|
|
||||||
})
|
|
||||||
.catch((error: Error | AxiosError) => {
|
|
||||||
if (request.setLoading) request.setLoading(false);
|
|
||||||
if (request.showError) toast.error(error.message);
|
|
||||||
if (request.onError) request.onError(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function AxiosPatch<RequestData, ResponseData>({
|
|
||||||
endpoint,
|
|
||||||
request,
|
|
||||||
options
|
|
||||||
}: IAxiosRequest<RequestData, ResponseData>) {
|
|
||||||
if (request.setLoading) request.setLoading(true);
|
|
||||||
axiosInstance
|
|
||||||
.patch<ResponseData>(endpoint, request.data, options)
|
|
||||||
.then(response => {
|
|
||||||
if (request.setLoading) request.setLoading(false);
|
|
||||||
if (request.onSuccess) request.onSuccess(response.data);
|
|
||||||
return response.data;
|
|
||||||
})
|
|
||||||
.catch((error: Error | AxiosError) => {
|
|
||||||
if (request.setLoading) request.setLoading(false);
|
|
||||||
if (request.showError) toast.error(error.message);
|
|
||||||
if (request.onError) request.onError(error);
|
|
||||||
});
|
|
||||||
}
|
|
25
rsconcept/frontend/src/backend/apiConfiguration.ts
Normal file
25
rsconcept/frontend/src/backend/apiConfiguration.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
* Module: communication setup.
|
||||||
|
*/
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import { buildConstants } from '@/utils/buildConstants';
|
||||||
|
|
||||||
|
const defaultOptions = {
|
||||||
|
xsrfCookieName: 'csrftoken',
|
||||||
|
xsrfHeaderName: 'x-csrftoken',
|
||||||
|
baseURL: `${buildConstants.backend}`,
|
||||||
|
withCredentials: true
|
||||||
|
};
|
||||||
|
|
||||||
|
export const axiosInstance = axios.create(defaultOptions);
|
||||||
|
axiosInstance.interceptors.request.use(config => {
|
||||||
|
const token = document.cookie
|
||||||
|
.split('; ')
|
||||||
|
.find(row => row.startsWith('csrftoken='))
|
||||||
|
?.split('=')[1];
|
||||||
|
if (token) {
|
||||||
|
config.headers['x-csrftoken'] = token;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
});
|
114
rsconcept/frontend/src/backend/apiTransport.ts
Normal file
114
rsconcept/frontend/src/backend/apiTransport.ts
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
/**
|
||||||
|
* Module: generic API for backend REST communications.
|
||||||
|
*/
|
||||||
|
import { AxiosError, AxiosRequestConfig } from 'axios';
|
||||||
|
import { toast } from 'react-toastify';
|
||||||
|
|
||||||
|
import { ErrorData } from '@/components/info/InfoError';
|
||||||
|
|
||||||
|
import { axiosInstance } from './apiConfiguration';
|
||||||
|
|
||||||
|
// ================ Data transfer types ================
|
||||||
|
export type DataCallback<ResponseData = undefined> = (data: ResponseData) => void;
|
||||||
|
|
||||||
|
export interface IFrontRequest<RequestData, ResponseData> {
|
||||||
|
data?: RequestData;
|
||||||
|
onSuccess?: DataCallback<ResponseData>;
|
||||||
|
onError?: (error: ErrorData) => void;
|
||||||
|
setLoading?: (loading: boolean) => void;
|
||||||
|
showError?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FrontPush<DataType> extends IFrontRequest<DataType, undefined> {
|
||||||
|
data: DataType;
|
||||||
|
}
|
||||||
|
export interface FrontPull<DataType> extends IFrontRequest<undefined, DataType> {
|
||||||
|
onSuccess: DataCallback<DataType>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FrontExchange<RequestData, ResponseData> extends IFrontRequest<RequestData, ResponseData> {
|
||||||
|
data: RequestData;
|
||||||
|
onSuccess: DataCallback<ResponseData>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FrontAction extends IFrontRequest<undefined, undefined> {}
|
||||||
|
|
||||||
|
export interface IAxiosRequest<RequestData, ResponseData> {
|
||||||
|
endpoint: string;
|
||||||
|
request: IFrontRequest<RequestData, ResponseData>;
|
||||||
|
options?: AxiosRequestConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================ Transport API calls ================
|
||||||
|
export function AxiosGet<ResponseData>({ endpoint, request, options }: IAxiosRequest<undefined, ResponseData>) {
|
||||||
|
if (request.setLoading) request.setLoading(true);
|
||||||
|
axiosInstance
|
||||||
|
.get<ResponseData>(endpoint, options)
|
||||||
|
.then(response => {
|
||||||
|
if (request.setLoading) request.setLoading(false);
|
||||||
|
if (request.onSuccess) request.onSuccess(response.data);
|
||||||
|
})
|
||||||
|
.catch((error: Error | AxiosError) => {
|
||||||
|
if (request.setLoading) request.setLoading(false);
|
||||||
|
if (request.showError) toast.error(error.message);
|
||||||
|
if (request.onError) request.onError(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AxiosPost<RequestData, ResponseData>({
|
||||||
|
endpoint,
|
||||||
|
request,
|
||||||
|
options
|
||||||
|
}: IAxiosRequest<RequestData, ResponseData>) {
|
||||||
|
if (request.setLoading) request.setLoading(true);
|
||||||
|
axiosInstance
|
||||||
|
.post<ResponseData>(endpoint, request.data, options)
|
||||||
|
.then(response => {
|
||||||
|
if (request.setLoading) request.setLoading(false);
|
||||||
|
if (request.onSuccess) request.onSuccess(response.data);
|
||||||
|
})
|
||||||
|
.catch((error: Error | AxiosError) => {
|
||||||
|
if (request.setLoading) request.setLoading(false);
|
||||||
|
if (request.showError) toast.error(error.message);
|
||||||
|
if (request.onError) request.onError(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AxiosDelete<RequestData, ResponseData>({
|
||||||
|
endpoint,
|
||||||
|
request,
|
||||||
|
options
|
||||||
|
}: IAxiosRequest<RequestData, ResponseData>) {
|
||||||
|
if (request.setLoading) request.setLoading(true);
|
||||||
|
axiosInstance
|
||||||
|
.delete<ResponseData>(endpoint, options)
|
||||||
|
.then(response => {
|
||||||
|
if (request.setLoading) request.setLoading(false);
|
||||||
|
if (request.onSuccess) request.onSuccess(response.data);
|
||||||
|
})
|
||||||
|
.catch((error: Error | AxiosError) => {
|
||||||
|
if (request.setLoading) request.setLoading(false);
|
||||||
|
if (request.showError) toast.error(error.message);
|
||||||
|
if (request.onError) request.onError(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AxiosPatch<RequestData, ResponseData>({
|
||||||
|
endpoint,
|
||||||
|
request,
|
||||||
|
options
|
||||||
|
}: IAxiosRequest<RequestData, ResponseData>) {
|
||||||
|
if (request.setLoading) request.setLoading(true);
|
||||||
|
axiosInstance
|
||||||
|
.patch<ResponseData>(endpoint, request.data, options)
|
||||||
|
.then(response => {
|
||||||
|
if (request.setLoading) request.setLoading(false);
|
||||||
|
if (request.onSuccess) request.onSuccess(response.data);
|
||||||
|
return response.data;
|
||||||
|
})
|
||||||
|
.catch((error: Error | AxiosError) => {
|
||||||
|
if (request.setLoading) request.setLoading(false);
|
||||||
|
if (request.showError) toast.error(error.message);
|
||||||
|
if (request.onError) request.onError(error);
|
||||||
|
});
|
||||||
|
}
|
28
rsconcept/frontend/src/backend/cctext.ts
Normal file
28
rsconcept/frontend/src/backend/cctext.ts
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
* Endpoints: cctext.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ILexemeData, ITextRequest, ITextResult, IWordFormPlain } from '@/models/language';
|
||||||
|
|
||||||
|
import { AxiosPost, FrontExchange } from './apiTransport';
|
||||||
|
|
||||||
|
export function postInflectText(request: FrontExchange<IWordFormPlain, ITextResult>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: `/api/cctext/inflect`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postParseText(request: FrontExchange<ITextRequest, ITextResult>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: `/api/cctext/parse`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postGenerateLexeme(request: FrontExchange<ITextRequest, ILexemeData>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: `/api/cctext/generate-lexeme`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
14
rsconcept/frontend/src/backend/constituents.ts
Normal file
14
rsconcept/frontend/src/backend/constituents.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/**
|
||||||
|
* Endpoints: constituents.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { IConstituentaMeta, ICstUpdateData } from '@/models/rsform';
|
||||||
|
|
||||||
|
import { AxiosPatch, FrontExchange } from './apiTransport';
|
||||||
|
|
||||||
|
export function patchConstituenta(target: string, request: FrontExchange<ICstUpdateData, IConstituentaMeta>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/constituents/${target}`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
131
rsconcept/frontend/src/backend/library.ts
Normal file
131
rsconcept/frontend/src/backend/library.ts
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
/**
|
||||||
|
* Endpoints: library.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
ILibraryCreateData,
|
||||||
|
ILibraryItem,
|
||||||
|
ILibraryUpdateData,
|
||||||
|
ITargetAccessPolicy,
|
||||||
|
ITargetLocation
|
||||||
|
} from '@/models/library';
|
||||||
|
import { IRSFormCloneData, IRSFormData } from '@/models/rsform';
|
||||||
|
import { ITargetUser, ITargetUsers } from '@/models/user';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AxiosDelete,
|
||||||
|
AxiosGet,
|
||||||
|
AxiosPatch,
|
||||||
|
AxiosPost,
|
||||||
|
FrontAction,
|
||||||
|
FrontExchange,
|
||||||
|
FrontPull,
|
||||||
|
FrontPush
|
||||||
|
} from './apiTransport';
|
||||||
|
|
||||||
|
export function getLibrary(request: FrontPull<ILibraryItem[]>) {
|
||||||
|
// title: 'Available LibraryItems list',
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: '/api/library/active',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAdminLibrary(request: FrontPull<ILibraryItem[]>) {
|
||||||
|
// title: 'All LibraryItems list',
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: '/api/library/all',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTemplates(request: FrontPull<ILibraryItem[]>) {
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: '/api/library/templates',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postCreateLibraryItem(request: FrontExchange<ILibraryCreateData, ILibraryItem>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: '/api/library',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postCloneLibraryItem(target: string, request: FrontExchange<IRSFormCloneData, IRSFormData>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: `/api/library/${target}/clone`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchLibraryItem(target: string, request: FrontExchange<ILibraryUpdateData, ILibraryItem>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/library/${target}`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteLibraryItem(target: string, request: FrontAction) {
|
||||||
|
AxiosDelete({
|
||||||
|
endpoint: `/api/library/${target}`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchSetOwner(target: string, request: FrontPush<ITargetUser>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/library/${target}/set-owner`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchSetAccessPolicy(target: string, request: FrontPush<ITargetAccessPolicy>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/library/${target}/set-access-policy`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchSetLocation(target: string, request: FrontPush<ITargetLocation>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/library/${target}/set-location`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchEditorsAdd(target: string, request: FrontPush<ITargetUser>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/library/${target}/editors-add`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchEditorsRemove(target: string, request: FrontPush<ITargetUser>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/library/${target}/editors-remove`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchEditorsSet(target: string, request: FrontPush<ITargetUsers>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/library/${target}/editors-set`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postSubscribe(target: string, request: FrontAction) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: `/api/library/${target}/subscribe`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteUnsubscribe(target: string, request: FrontAction) {
|
||||||
|
AxiosDelete({
|
||||||
|
endpoint: `/api/library/${target}/unsubscribe`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
14
rsconcept/frontend/src/backend/operations.ts
Normal file
14
rsconcept/frontend/src/backend/operations.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/**
|
||||||
|
* Endpoints: operations.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { IInlineSynthesisData, IRSFormData } from '@/models/rsform';
|
||||||
|
|
||||||
|
import { AxiosPatch, FrontExchange } from './apiTransport';
|
||||||
|
|
||||||
|
export function patchInlineSynthesis(request: FrontExchange<IInlineSynthesisData, IRSFormData>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/operations/inline-synthesis`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
44
rsconcept/frontend/src/backend/oss.ts
Normal file
44
rsconcept/frontend/src/backend/oss.ts
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
* Endpoints: oss.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
IOperationCreateData,
|
||||||
|
IOperationCreatedResponse,
|
||||||
|
IOperationSchemaData,
|
||||||
|
IPositionsData,
|
||||||
|
ITargetOperation
|
||||||
|
} from '@/models/oss';
|
||||||
|
|
||||||
|
import { AxiosGet, AxiosPatch, AxiosPost, FrontExchange, FrontPull, FrontPush } from './apiTransport';
|
||||||
|
|
||||||
|
export function getOssDetails(target: string, request: FrontPull<IOperationSchemaData>) {
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: `/api/oss/${target}/details`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchUpdatePositions(schema: string, request: FrontPush<IPositionsData>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/oss/${schema}/update-positions`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postCreateOperation(
|
||||||
|
schema: string,
|
||||||
|
request: FrontExchange<IOperationCreateData, IOperationCreatedResponse>
|
||||||
|
) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: `/api/oss/${schema}/create-operation`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchDeleteOperation(schema: string, request: FrontExchange<ITargetOperation, IOperationSchemaData>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/oss/${schema}/delete-operation`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
145
rsconcept/frontend/src/backend/rsforms.ts
Normal file
145
rsconcept/frontend/src/backend/rsforms.ts
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
/**
|
||||||
|
* Endpoints: rsforms.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ILibraryCreateData, ILibraryItem, IVersionData } from '@/models/library';
|
||||||
|
import { ICstSubstituteData } from '@/models/oss';
|
||||||
|
import {
|
||||||
|
IConstituentaList,
|
||||||
|
ICstCreateData,
|
||||||
|
ICstCreatedResponse,
|
||||||
|
ICstMovetoData,
|
||||||
|
ICstRenameData,
|
||||||
|
IProduceStructureResponse,
|
||||||
|
IRSFormData,
|
||||||
|
IRSFormUploadData,
|
||||||
|
ITargetCst,
|
||||||
|
IVersionCreatedResponse
|
||||||
|
} from '@/models/rsform';
|
||||||
|
import { IExpressionParse, IRSExpression } from '@/models/rslang';
|
||||||
|
|
||||||
|
import { AxiosGet, AxiosPatch, AxiosPost, FrontExchange, FrontPull } from './apiTransport';
|
||||||
|
|
||||||
|
export function postRSFormFromFile(request: FrontExchange<ILibraryCreateData, ILibraryItem>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: '/api/rsforms/create-detailed',
|
||||||
|
request: request,
|
||||||
|
options: {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRSFormDetails(target: string, version: string, request: FrontPull<IRSFormData>) {
|
||||||
|
if (!version) {
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: `/api/rsforms/${target}/details`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: `/api/rsforms/${target}/versions/${version}`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTRSFile(target: string, version: string, request: FrontPull<Blob>) {
|
||||||
|
if (!version) {
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: `/api/rsforms/${target}/export-trs`,
|
||||||
|
request: request,
|
||||||
|
options: { responseType: 'blob' }
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: `/api/versions/${version}/export-file`,
|
||||||
|
request: request,
|
||||||
|
options: { responseType: 'blob' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postCreateConstituenta(schema: string, request: FrontExchange<ICstCreateData, ICstCreatedResponse>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: `/api/rsforms/${schema}/cst-create`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchDeleteConstituenta(schema: string, request: FrontExchange<IConstituentaList, IRSFormData>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/rsforms/${schema}/cst-delete-multiple`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchRenameConstituenta(schema: string, request: FrontExchange<ICstRenameData, ICstCreatedResponse>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/rsforms/${schema}/cst-rename`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchProduceStructure(schema: string, request: FrontExchange<ITargetCst, IProduceStructureResponse>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/rsforms/${schema}/cst-produce-structure`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchSubstituteConstituents(schema: string, request: FrontExchange<ICstSubstituteData, IRSFormData>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/rsforms/${schema}/cst-substitute`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchMoveConstituenta(schema: string, request: FrontExchange<ICstMovetoData, IRSFormData>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/rsforms/${schema}/cst-moveto`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postCheckExpression(schema: string, request: FrontExchange<IRSExpression, IExpressionParse>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: `/api/rsforms/${schema}/check`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchResetAliases(target: string, request: FrontPull<IRSFormData>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/rsforms/${target}/reset-aliases`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchRestoreOrder(target: string, request: FrontPull<IRSFormData>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/rsforms/${target}/restore-order`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchUploadTRS(target: string, request: FrontExchange<IRSFormUploadData, IRSFormData>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/rsforms/${target}/load-trs`,
|
||||||
|
request: request,
|
||||||
|
options: {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postCreateVersion(target: string, request: FrontExchange<IVersionData, IVersionCreatedResponse>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: `/api/rsforms/${target}/versions/create`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
99
rsconcept/frontend/src/backend/users.ts
Normal file
99
rsconcept/frontend/src/backend/users.ts
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
/**
|
||||||
|
* Endpoints: users.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
ICurrentUser,
|
||||||
|
IPasswordTokenData,
|
||||||
|
IRequestPasswordData,
|
||||||
|
IResetPasswordData,
|
||||||
|
IUserInfo,
|
||||||
|
IUserLoginData,
|
||||||
|
IUserProfile,
|
||||||
|
IUserSignupData,
|
||||||
|
IUserUpdateData,
|
||||||
|
IUserUpdatePassword
|
||||||
|
} from '@/models/user';
|
||||||
|
|
||||||
|
import { AxiosGet, AxiosPatch, AxiosPost, FrontAction, FrontExchange, FrontPull, FrontPush } from './apiTransport';
|
||||||
|
|
||||||
|
export function getAuth(request: FrontPull<ICurrentUser>) {
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: `/users/api/auth`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postLogin(request: FrontPush<IUserLoginData>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: '/users/api/login',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postLogout(request: FrontAction) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: '/users/api/logout',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postSignup(request: FrontExchange<IUserSignupData, IUserProfile>) {
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: '/users/api/signup',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getProfile(request: FrontPull<IUserProfile>) {
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: '/users/api/profile',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchProfile(request: FrontExchange<IUserUpdateData, IUserProfile>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: '/users/api/profile',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchPassword(request: FrontPush<IUserUpdatePassword>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: '/users/api/change-password',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postRequestPasswordReset(request: FrontPush<IRequestPasswordData>) {
|
||||||
|
// title: 'Request password reset',
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: '/users/api/password-reset',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postValidatePasswordToken(request: FrontPush<IPasswordTokenData>) {
|
||||||
|
// title: 'Validate password token',
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: '/users/api/password-reset/validate',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postResetPassword(request: FrontPush<IResetPasswordData>) {
|
||||||
|
// title: 'Reset password',
|
||||||
|
AxiosPost({
|
||||||
|
endpoint: '/users/api/password-reset/confirm',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getActiveUsers(request: FrontPull<IUserInfo[]>) {
|
||||||
|
// title: 'Active users list',
|
||||||
|
AxiosGet({
|
||||||
|
endpoint: '/users/api/active-users',
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
30
rsconcept/frontend/src/backend/versions.ts
Normal file
30
rsconcept/frontend/src/backend/versions.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
* Endpoints: versions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { IVersionData } from '@/models/library';
|
||||||
|
import { IRSFormData } from '@/models/rsform';
|
||||||
|
|
||||||
|
import { AxiosDelete, AxiosPatch, FrontAction, FrontPull, FrontPush } from './apiTransport';
|
||||||
|
|
||||||
|
export function patchVersion(target: string, request: FrontPush<IVersionData>) {
|
||||||
|
// title: `Version id=${target}`,
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/versions/${target}`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchRestoreVersion(target: string, request: FrontPull<IRSFormData>) {
|
||||||
|
AxiosPatch({
|
||||||
|
endpoint: `/api/versions/${target}/restore`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteVersion(target: string, request: FrontAction) {
|
||||||
|
AxiosDelete({
|
||||||
|
endpoint: `/api/versions/${target}`,
|
||||||
|
request: request
|
||||||
|
});
|
||||||
|
}
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
import { createContext, useCallback, useContext, useLayoutEffect, useState } from 'react';
|
import { createContext, useCallback, useContext, useLayoutEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import { DataCallback } from '@/backend/apiTransport';
|
||||||
import {
|
import {
|
||||||
type DataCallback,
|
|
||||||
getAuth,
|
getAuth,
|
||||||
patchPassword,
|
patchPassword,
|
||||||
postLogin,
|
postLogin,
|
||||||
|
@ -12,7 +12,7 @@ import {
|
||||||
postResetPassword,
|
postResetPassword,
|
||||||
postSignup,
|
postSignup,
|
||||||
postValidatePasswordToken
|
postValidatePasswordToken
|
||||||
} from '@/app/backendAPI';
|
} from '@/backend/users';
|
||||||
import { type ErrorData } from '@/components/info/InfoError';
|
import { type ErrorData } from '@/components/info/InfoError';
|
||||||
import {
|
import {
|
||||||
ICurrentUser,
|
ICurrentUser,
|
||||||
|
|
|
@ -2,17 +2,16 @@
|
||||||
|
|
||||||
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
|
import { DataCallback } from '@/backend/apiTransport';
|
||||||
import {
|
import {
|
||||||
DataCallback,
|
|
||||||
deleteLibraryItem,
|
deleteLibraryItem,
|
||||||
getAdminLibrary,
|
getAdminLibrary,
|
||||||
getLibrary,
|
getLibrary,
|
||||||
getRSFormDetails,
|
|
||||||
getTemplates,
|
getTemplates,
|
||||||
postCloneLibraryItem,
|
postCloneLibraryItem,
|
||||||
postCreateLibraryItem,
|
postCreateLibraryItem
|
||||||
postRSFormFromFile
|
} from '@/backend/library';
|
||||||
} from '@/app/backendAPI';
|
import { getRSFormDetails, postRSFormFromFile } from '@/backend/rsforms';
|
||||||
import { ErrorData } from '@/components/info/InfoError';
|
import { ErrorData } from '@/components/info/InfoError';
|
||||||
import { FolderTree } from '@/models/FolderTree';
|
import { FolderTree } from '@/models/FolderTree';
|
||||||
import { ILibraryItem, LibraryItemID, LocationHead } from '@/models/library';
|
import { ILibraryItem, LibraryItemID, LocationHead } from '@/models/library';
|
||||||
|
|
|
@ -2,19 +2,17 @@
|
||||||
|
|
||||||
import { createContext, useCallback, useContext, useMemo, useState } from 'react';
|
import { createContext, useCallback, useContext, useMemo, useState } from 'react';
|
||||||
|
|
||||||
|
import { DataCallback } from '@/backend/apiTransport';
|
||||||
import {
|
import {
|
||||||
type DataCallback,
|
|
||||||
deleteUnsubscribe,
|
deleteUnsubscribe,
|
||||||
patchDeleteOperation,
|
patchEditorsSet,
|
||||||
patchEditorsSet as patchSetEditors,
|
|
||||||
patchLibraryItem,
|
patchLibraryItem,
|
||||||
patchSetAccessPolicy,
|
patchSetAccessPolicy,
|
||||||
patchSetLocation,
|
patchSetLocation,
|
||||||
patchSetOwner,
|
patchSetOwner,
|
||||||
patchUpdatePositions,
|
|
||||||
postCreateOperation,
|
|
||||||
postSubscribe
|
postSubscribe
|
||||||
} from '@/app/backendAPI';
|
} from '@/backend/library';
|
||||||
|
import { patchDeleteOperation, patchUpdatePositions, postCreateOperation } from '@/backend/oss';
|
||||||
import { type ErrorData } from '@/components/info/InfoError';
|
import { type ErrorData } from '@/components/info/InfoError';
|
||||||
import useOssDetails from '@/hooks/useOssDetails';
|
import useOssDetails from '@/hooks/useOssDetails';
|
||||||
import { AccessPolicy, ILibraryItem } from '@/models/library';
|
import { AccessPolicy, ILibraryItem } from '@/models/library';
|
||||||
|
@ -238,7 +236,7 @@ export const OssState = ({ itemID, children }: OssStateProps) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setProcessingError(undefined);
|
setProcessingError(undefined);
|
||||||
patchSetEditors(itemID, {
|
patchEditorsSet(itemID, {
|
||||||
data: {
|
data: {
|
||||||
users: newEditors
|
users: newEditors
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,32 +2,32 @@
|
||||||
|
|
||||||
import { createContext, useCallback, useContext, useMemo, useState } from 'react';
|
import { createContext, useCallback, useContext, useMemo, useState } from 'react';
|
||||||
|
|
||||||
|
import { DataCallback } from '@/backend/apiTransport';
|
||||||
|
import { patchConstituenta } from '@/backend/constituents';
|
||||||
import {
|
import {
|
||||||
type DataCallback,
|
|
||||||
deleteUnsubscribe,
|
deleteUnsubscribe,
|
||||||
deleteVersion,
|
patchEditorsSet,
|
||||||
getTRSFile,
|
|
||||||
patchConstituenta,
|
|
||||||
patchDeleteConstituenta,
|
|
||||||
patchEditorsSet as patchSetEditors,
|
|
||||||
patchInlineSynthesis,
|
|
||||||
patchLibraryItem,
|
patchLibraryItem,
|
||||||
|
patchSetAccessPolicy,
|
||||||
|
patchSetLocation,
|
||||||
|
patchSetOwner,
|
||||||
|
postSubscribe
|
||||||
|
} from '@/backend/library';
|
||||||
|
import { patchInlineSynthesis } from '@/backend/operations';
|
||||||
|
import {
|
||||||
|
getTRSFile,
|
||||||
|
patchDeleteConstituenta,
|
||||||
patchMoveConstituenta,
|
patchMoveConstituenta,
|
||||||
patchProduceStructure,
|
patchProduceStructure,
|
||||||
patchRenameConstituenta,
|
patchRenameConstituenta,
|
||||||
patchResetAliases,
|
patchResetAliases,
|
||||||
patchRestoreOrder,
|
patchRestoreOrder,
|
||||||
patchRestoreVersion,
|
|
||||||
patchSetAccessPolicy,
|
|
||||||
patchSetLocation,
|
|
||||||
patchSetOwner,
|
|
||||||
patchSubstituteConstituents,
|
patchSubstituteConstituents,
|
||||||
patchUploadTRS,
|
patchUploadTRS,
|
||||||
patchVersion,
|
|
||||||
postCreateConstituenta,
|
postCreateConstituenta,
|
||||||
postCreateVersion,
|
postCreateVersion
|
||||||
postSubscribe
|
} from '@/backend/rsforms';
|
||||||
} from '@/app/backendAPI';
|
import { deleteVersion, patchRestoreVersion, patchVersion } from '@/backend/versions';
|
||||||
import { type ErrorData } from '@/components/info/InfoError';
|
import { type ErrorData } from '@/components/info/InfoError';
|
||||||
import useRSFormDetails from '@/hooks/useRSFormDetails';
|
import useRSFormDetails from '@/hooks/useRSFormDetails';
|
||||||
import { AccessPolicy, ILibraryItem, IVersionData, VersionID } from '@/models/library';
|
import { AccessPolicy, ILibraryItem, IVersionData, VersionID } from '@/models/library';
|
||||||
|
@ -309,7 +309,7 @@ export const RSFormState = ({ itemID, versionID, children }: RSFormStateProps) =
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setProcessingError(undefined);
|
setProcessingError(undefined);
|
||||||
patchSetEditors(itemID, {
|
patchEditorsSet(itemID, {
|
||||||
data: {
|
data: {
|
||||||
users: newEditors
|
users: newEditors
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { DataCallback, getProfile, patchProfile } from '@/app/backendAPI';
|
import { DataCallback } from '@/backend/apiTransport';
|
||||||
|
import { getProfile, patchProfile } from '@/backend/users';
|
||||||
import { ErrorData } from '@/components/info/InfoError';
|
import { ErrorData } from '@/components/info/InfoError';
|
||||||
import { IUserProfile, IUserUpdateData } from '@/models/user';
|
import { IUserProfile, IUserUpdateData } from '@/models/user';
|
||||||
import { contextOutsideScope } from '@/utils/labels';
|
import { contextOutsideScope } from '@/utils/labels';
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { getActiveUsers } from '@/app/backendAPI';
|
import { getActiveUsers } from '@/backend/users';
|
||||||
import { IUserInfo } from '@/models/user';
|
import { IUserInfo } from '@/models/user';
|
||||||
import { contextOutsideScope } from '@/utils/labels';
|
import { contextOutsideScope } from '@/utils/labels';
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
|
||||||
import { DataCallback, postCheckExpression } from '@/app/backendAPI';
|
import { DataCallback } from '@/backend/apiTransport';
|
||||||
|
import { postCheckExpression } from '@/backend/rsforms';
|
||||||
import { type ErrorData } from '@/components/info/InfoError';
|
import { type ErrorData } from '@/components/info/InfoError';
|
||||||
import { CstType, IConstituenta, type IRSForm } from '@/models/rsform';
|
import { CstType, IConstituenta, type IRSForm } from '@/models/rsform';
|
||||||
import { getDefinitionPrefix } from '@/models/rsformAPI';
|
import { getDefinitionPrefix } from '@/models/rsformAPI';
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
|
||||||
import { DataCallback, postGenerateLexeme, postInflectText, postParseText } from '@/app/backendAPI';
|
import { DataCallback } from '@/backend/apiTransport';
|
||||||
|
import { postGenerateLexeme, postInflectText, postParseText } from '@/backend/cctext';
|
||||||
import { ErrorData } from '@/components/info/InfoError';
|
import { ErrorData } from '@/components/info/InfoError';
|
||||||
import { ILexemeData, ITextRequest, ITextResult, IWordFormPlain } from '@/models/language';
|
import { ILexemeData, ITextRequest, ITextResult, IWordFormPlain } from '@/models/language';
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { getOssDetails } from '@/app/backendAPI';
|
import { getOssDetails } from '@/backend/oss';
|
||||||
import { type ErrorData } from '@/components/info/InfoError';
|
import { type ErrorData } from '@/components/info/InfoError';
|
||||||
import { useAuth } from '@/context/AuthContext';
|
import { useAuth } from '@/context/AuthContext';
|
||||||
import { IOperationSchema, IOperationSchemaData } from '@/models/oss';
|
import { IOperationSchema, IOperationSchemaData } from '@/models/oss';
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { getRSFormDetails } from '@/app/backendAPI';
|
import { getRSFormDetails } from '@/backend/rsforms';
|
||||||
import { type ErrorData } from '@/components/info/InfoError';
|
import { type ErrorData } from '@/components/info/InfoError';
|
||||||
import { useAuth } from '@/context/AuthContext';
|
import { useAuth } from '@/context/AuthContext';
|
||||||
import { IRSForm, IRSFormData } from '@/models/rsform';
|
import { IRSForm, IRSFormData } from '@/models/rsform';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user