ConceptPortal-public/rsconcept/frontend/src/models/library.ts

138 lines
2.8 KiB
TypeScript
Raw Normal View History

/**
* Module: Models for LibraryItem.
*/
2023-09-11 20:31:54 +03:00
2024-05-27 20:42:34 +03:00
import { UserID } from './user';
/**
* Represents type of library items.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export enum LibraryItemType {
RSFORM = 'rsform',
OSS = 'oss'
2023-09-11 20:31:54 +03:00
}
/**
* Represents Access policy for library items.
*/
export enum AccessPolicy {
PUBLIC = 'public',
PROTECTED = 'protected',
PRIVATE = 'private'
}
/**
* Represents valid location headers.
*/
export enum LocationHead {
USER = '/U',
2024-06-04 11:19:21 +03:00
COMMON = '/S',
2024-06-19 22:10:15 +03:00
PROJECTS = '/P',
LIBRARY = '/L'
}
2024-05-27 20:42:34 +03:00
/**
* Represents {@link LibraryItem} identifier type.
*/
export type LibraryItemID = number;
/**
* Represents {@link Version} identifier type.
*/
export type VersionID = number;
/**
* Represents library item version information.
*/
export interface IVersionInfo {
2024-05-27 20:42:34 +03:00
id: VersionID;
version: string;
description: string;
time_create: string;
}
2024-03-04 19:22:22 +03:00
/**
* Represents user data, intended to create or update version metadata in persistent storage.
*/
export interface IVersionData extends Omit<IVersionInfo, 'id' | 'time_create'> {}
/**
* Represents library item common data typical for all item types.
2023-12-28 14:04:44 +03:00
*/
2023-09-11 20:31:54 +03:00
export interface ILibraryItem {
2024-03-17 19:24:12 +03:00
id: LibraryItemID;
2023-12-28 14:04:44 +03:00
item_type: LibraryItemType;
title: string;
alias: string;
comment: string;
visible: boolean;
read_only: boolean;
location: string;
access_policy: AccessPolicy;
2023-12-28 14:04:44 +03:00
time_create: string;
time_update: string;
2024-05-27 20:42:34 +03:00
owner: UserID | null;
2023-09-11 20:31:54 +03:00
}
2023-11-30 02:14:24 +03:00
/**
2024-06-04 23:00:22 +03:00
* Represents library item constant data loaded for both OSS and RSForm.
2023-12-28 14:04:44 +03:00
*/
2024-06-04 23:00:22 +03:00
export interface ILibraryItemData extends ILibraryItem {
2024-05-27 20:42:34 +03:00
subscribers: UserID[];
editors: UserID[];
2024-06-04 23:00:22 +03:00
}
/**
* Represents library item extended data with versions.
*/
export interface ILibraryItemVersioned extends ILibraryItemData {
2024-05-27 20:42:34 +03:00
version?: VersionID;
versions: IVersionInfo[];
2023-11-30 02:14:24 +03:00
}
2024-06-04 23:00:22 +03:00
/**
* Represents common library item editor controller.
*/
export interface ILibraryItemEditor {
schema?: ILibraryItemData;
isMutable: boolean;
isProcessing: boolean;
setOwner: (newOwner: UserID) => void;
setAccessPolicy: (newPolicy: AccessPolicy) => void;
promptEditors: () => void;
promptLocation: () => void;
toggleSubscribe: () => void;
share: () => void;
}
/**
* Represents update data for editing {@link ILibraryItem}.
2023-12-28 14:04:44 +03:00
*/
export interface ILibraryUpdateData
extends Omit<ILibraryItem, 'time_create' | 'time_update' | 'access_policy' | 'location' | 'id' | 'owner'> {}
/**
* Represents update data for editing {@link AccessPolicy} of a {@link ILibraryItem}.
*/
export interface ITargetAccessPolicy {
access_policy: AccessPolicy;
}
/**
* Represents update data for editing Location of a {@link ILibraryItem}.
*/
export interface ITargetLocation {
location: string;
}
/**
* Represents data, used for creating {@link IRSForm}.
*/
export interface ILibraryCreateData extends Omit<ILibraryItem, 'time_create' | 'time_update' | 'id' | 'owner'> {
file?: File;
fileName?: string;
}