sprof 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/package.json +101 -0
- package/src/Hooks/Hooks.ts +75 -0
- package/src/assets/img/avatar.webp +0 -0
- package/src/assets/styles/borders.scss +11 -0
- package/src/assets/styles/brandbook.css +227 -0
- package/src/assets/styles/colors.scss +42 -0
- package/src/assets/styles/fonts.scss +15 -0
- package/src/assets/styles/index.css +15 -0
- package/src/assets/styles/index.scss +45 -0
- package/src/assets/styles/platform/android.css +53 -0
- package/src/assets/styles/platform/ios.css +53 -0
- package/src/assets/styles/platform/webdesktop.css +72 -0
- package/src/assets/styles/platform/webdesktop_old.css +65 -0
- package/src/assets/styles/platform/webmobile.css +53 -0
- package/src/assets/styles/platform/webtablet.css +53 -0
- package/src/assets/styles/reset.scss +28 -0
- package/src/assets/styles/shadow.scss +6 -0
- package/src/assets/styles/theme/aquaBlueLight.css +162 -0
- package/src/assets/styles/theme/blueLight.css +187 -0
- package/src/assets/styles/theme/blueLight_test.css +162 -0
- package/src/assets/styles/theme/dark.css +286 -0
- package/src/assets/styles/theme/light.css +151 -0
- package/src/assets/svg/ArrowLeft.svg +5 -0
- package/src/assets/svg/ArrowRight.svg +5 -0
- package/src/assets/svg/Close.svg +7 -0
- package/src/assets/svg/DoubleArrowLeft.svg +5 -0
- package/src/assets/svg/DoubleArrowRight.svg +5 -0
- package/src/assets/svg/Ellipsis.svg +7 -0
- package/src/assets/svg/Filter.svg +10 -0
- package/src/assets/svg/Menu.svg +5 -0
- package/src/assets/svg/Move.svg +5 -0
- package/src/assets/svg/Password.svg +5 -0
- package/src/assets/svg/RightMenu.svg +5 -0
- package/src/assets/svg/Settings.svg +6 -0
- package/src/assets/svg/User.svg +6 -0
- package/src/buildLibrary.ts +59 -0
- package/src/classes/Auth.ts +63 -0
- package/src/classes/AuthButton.ts +64 -0
- package/src/classes/AuthForm.ts +114 -0
- package/src/classes/AuthModal.ts +32 -0
- package/src/classes/AuthStatusesObjects.ts +37 -0
- package/src/classes/AuthTokens.ts +43 -0
- package/src/classes/AuthUser.ts +53 -0
- package/src/classes/CallbackRequest.ts +12 -0
- package/src/classes/Chat.ts +18 -0
- package/src/classes/ChatMessage.ts +48 -0
- package/src/classes/Contact.ts +96 -0
- package/src/classes/Cropper.ts +22 -0
- package/src/classes/DateHelper.ts +29 -0
- package/src/classes/Email.ts +18 -0
- package/src/classes/EmailField.ts +42 -0
- package/src/classes/EmailRules.ts +4 -0
- package/src/classes/FTSPPreset.ts +16 -0
- package/src/classes/FileInfo.ts +86 -0
- package/src/classes/HttpResponse.ts +22 -0
- package/src/classes/Human.ts +106 -0
- package/src/classes/LabelValue.ts +11 -0
- package/src/classes/LocalStore.ts +22 -0
- package/src/classes/M2M.ts +25 -0
- package/src/classes/Menu.ts +102 -0
- package/src/classes/PageSectionImage.ts +19 -0
- package/src/classes/PasswordField.ts +39 -0
- package/src/classes/PasswordRepeatField.ts +37 -0
- package/src/classes/Phone.ts +17 -0
- package/src/classes/PostAddress.ts +11 -0
- package/src/classes/PostAddressRules.ts +1 -0
- package/src/classes/Role.ts +13 -0
- package/src/classes/Schema.ts +13 -0
- package/src/classes/SchemaField.ts +10 -0
- package/src/classes/SearchElement.ts +18 -0
- package/src/classes/SearchElementMeta.ts +10 -0
- package/src/classes/SearchGroup.ts +25 -0
- package/src/classes/SearchGroupMetaColumn.ts +11 -0
- package/src/classes/SearchModel.ts +61 -0
- package/src/classes/SortModel.ts +57 -0
- package/src/classes/SubMenu.ts +56 -0
- package/src/classes/TelephoneNumberRules.ts +9 -0
- package/src/classes/User.ts +17 -0
- package/src/classes/UserAccount.ts +17 -0
- package/src/classes/UserService.ts +20 -0
- package/src/classes/ValidationRules.ts +15 -0
- package/src/classes/ValueType.ts +69 -0
- package/src/classes/Website.ts +11 -0
- package/src/classes/WebsiteRules.ts +4 -0
- package/src/classes/admin/AdminButtonParams.ts +27 -0
- package/src/classes/admin/AdminHeaderParams.ts +34 -0
- package/src/classes/calendar/Calendar.ts +168 -0
- package/src/classes/calendar/Day.ts +15 -0
- package/src/classes/calendar/Month.ts +144 -0
- package/src/classes/calendar/Week.ts +44 -0
- package/src/classes/calendar/Year.ts +130 -0
- package/src/classes/filters/Cursor.ts +43 -0
- package/src/classes/filters/FTSP.ts +99 -0
- package/src/classes/filters/FilterModel.ts +263 -0
- package/src/classes/filters/FilterQuery.ts +187 -0
- package/src/classes/filters/OperatorsOptions.ts +8 -0
- package/src/classes/filters/OperatorsTextOptions.ts +3 -0
- package/src/classes/filters/Pagination.ts +78 -0
- package/src/classes/filters/SelectFilter.ts +15 -0
- package/src/classes/filters/TreeModel.ts +14 -0
- package/src/classes/page/CustomSection.ts +24 -0
- package/src/classes/page/Page.ts +160 -0
- package/src/classes/page/PageDocument.ts +27 -0
- package/src/classes/page/PageImage.ts +15 -0
- package/src/classes/page/PageSection.ts +82 -0
- package/src/classes/page/PageSectionDocument.ts +56 -0
- package/src/classes/page/PageSideMenu.ts +74 -0
- package/src/components/AdaptiveContainer.vue +154 -0
- package/src/components/AdaptiveContainerHorizontal.vue +173 -0
- package/src/components/AdminGallery.vue +238 -0
- package/src/components/AuthModal.vue +16 -0
- package/src/components/CarouselImages.vue +434 -0
- package/src/components/ContactForm.vue +219 -0
- package/src/components/ContextWindow.vue +48 -0
- package/src/components/DateInputRange.vue +66 -0
- package/src/components/DateInputRange_v2.vue +25 -0
- package/src/components/DropList.vue +55 -0
- package/src/components/Edit.svg +10 -0
- package/src/components/EmailForm.vue +180 -0
- package/src/components/FTSPPanel.vue +379 -0
- package/src/components/FilterCheckbox.vue +73 -0
- package/src/components/FilterSelect.vue +104 -0
- package/src/components/FiltersButtonsSelect.vue +126 -0
- package/src/components/GeneralItem.vue +172 -0
- package/src/components/GridContainer.vue +66 -0
- package/src/components/Icons/Filter/IconDownload.vue +55 -0
- package/src/components/Icons/Filter/IconFilter.vue +55 -0
- package/src/components/Icons/IconArrowLeft.vue +36 -0
- package/src/components/Icons/IconCheckDefault.vue +41 -0
- package/src/components/Icons/IconClose.vue +37 -0
- package/src/components/Icons/IconEdit.vue +40 -0
- package/src/components/Icons/IconEmail.vue +36 -0
- package/src/components/Icons/IconMove.vue +53 -0
- package/src/components/Icons/IconPhone.vue +36 -0
- package/src/components/Icons/IconSearch.vue +47 -0
- package/src/components/Icons/IconSelectArrow.vue +41 -0
- package/src/components/Icons/Pagination/ArrowLeft.vue +52 -0
- package/src/components/Icons/Pagination/ArrowRight.vue +52 -0
- package/src/components/Icons/Pagination/DoubleArrowLeft.vue +52 -0
- package/src/components/Icons/Pagination/DoubleArrowRight.vue +52 -0
- package/src/components/Icons/Pagination/EllipsisSvg.vue +58 -0
- package/src/components/ImageCropper.vue +203 -0
- package/src/components/InfoItem.vue +294 -0
- package/src/components/InfoItemSelectButtons.vue +43 -0
- package/src/components/LeftRightContainer.vue +93 -0
- package/src/components/MessageBody.vue +45 -0
- package/src/components/PAutocomplete.vue +93 -0
- package/src/components/PDialog.vue +77 -0
- package/src/components/PLoader.vue +68 -0
- package/src/components/PNotification.vue +79 -0
- package/src/components/PPagination.vue +174 -0
- package/src/components/PhoneForm.vue +180 -0
- package/src/components/RSContainer.vue +262 -0
- package/src/components/RemoteSearch.vue +156 -0
- package/src/components/ResearcheContainer.vue +71 -0
- package/src/components/RightSliderContainer.vue +181 -0
- package/src/components/RightTabsContainer.vue +210 -0
- package/src/components/SelectValueType.vue +39 -0
- package/src/components/SingleNameToggleForm.vue +399 -0
- package/src/components/SortList.vue +101 -0
- package/src/components/SortSelect.vue +93 -0
- package/src/components/SvgIcon.vue +25 -0
- package/src/components/Switch3Pos.vue +173 -0
- package/src/components/ThemeWrapper.vue +19 -0
- package/src/components/ToggleInfoItem.vue +296 -0
- package/src/components/TopSliderContainer.vue +166 -0
- package/src/components/UploaderImage.vue +268 -0
- package/src/components/atoms/PButton/PButton.stories.ts +44 -0
- package/src/components/atoms/PButton/PButton.test.ts +66 -0
- package/src/components/atoms/PButton/PButton.vue +54 -0
- package/src/components/atoms/PButton/skins/p-button_base.css +131 -0
- package/src/components/atoms/PButton/skins/p-button_filter.scss +83 -0
- package/src/components/atoms/PButton/skins/p-button_icon.scss +78 -0
- package/src/components/atoms/PButton/skins/p-button_pag.css +44 -0
- package/src/components/atoms/PButton/skins/p-button_text.css +88 -0
- package/src/components/atoms/PButton/skins/p-button_text_ano.css +88 -0
- package/src/components/atoms/PCheckbox/PCheckBox.test.ts +107 -0
- package/src/components/atoms/PCheckbox/PCheckBox.vue +92 -0
- package/src/components/atoms/PDatePicker/PDatePicker.test.ts +63 -0
- package/src/components/atoms/PDatePicker/PDatePicker.vue +141 -0
- package/src/components/atoms/PFlex/PFlex.test.ts +41 -0
- package/src/components/atoms/PFlex/PFlex.vue +46 -0
- package/src/components/atoms/PInput/PInput.stories.ts +40 -0
- package/src/components/atoms/PInput/PInput.test.ts +92 -0
- package/src/components/atoms/PInput/PInput.vue +133 -0
- package/src/components/atoms/PInputDate/PInputDate.test.ts +55 -0
- package/src/components/atoms/PInputDate/PInputDate.vue +79 -0
- package/src/components/atoms/PInputNumber/PInputNumber.vue +175 -0
- package/src/components/atoms/PLeftSlider/PLeftSlider.test.ts +121 -0
- package/src/components/atoms/PLeftSlider/PLeftSlider.vue +139 -0
- package/src/components/atoms/PList/PList.test.ts +32 -0
- package/src/components/atoms/PList/PList.vue +27 -0
- package/src/components/atoms/PListItem/PListItem.test.ts +61 -0
- package/src/components/atoms/PListItem/PListItem.vue +51 -0
- package/src/components/atoms/PRadio/PRadio.test.ts +110 -0
- package/src/components/atoms/PRadio/PRadio.vue +97 -0
- package/src/components/atoms/PRightSlider/PRightSlider.test.ts +123 -0
- package/src/components/atoms/PRightSlider/PRightSlider.vue +149 -0
- package/src/components/atoms/PSelect/PSelect.test.ts +74 -0
- package/src/components/atoms/PSelect/PSelect.vue +192 -0
- package/src/components/atoms/PSelect/select-arrow-down.svg +4 -0
- package/src/components/atoms/PSticky/PSticky.test.ts +70 -0
- package/src/components/atoms/PSticky/PSticky.vue +37 -0
- package/src/components/atoms/PString/PString.test.ts +58 -0
- package/src/components/atoms/PString/PString.vue +58 -0
- package/src/components/atoms/PTextarea/PTextarea.stories.ts +40 -0
- package/src/components/atoms/PTextarea/PTextarea.test.ts +22 -0
- package/src/components/atoms/PTextarea/PTextarea.vue +123 -0
- package/src/components/atoms/PTopSlider/PTopSlider.test.ts +95 -0
- package/src/components/atoms/PTopSlider/PTopSlider.vue +164 -0
- package/src/components/molecules/Collapse/CollapseContainer.vue +36 -0
- package/src/components/molecules/Collapse/CollapseItem.vue +295 -0
- package/src/components/molecules/Collapse/VerticalCollapseContainer.vue +102 -0
- package/src/components/molecules/PAdd/PAdd.vue +65 -0
- package/src/components/molecules/PAdd/PContainer.vue +65 -0
- package/src/components/molecules/PAdd/PContainerStickyHead.vue +51 -0
- package/src/components/molecules/PDel/PDel.vue +74 -0
- package/src/components/organisms/AuthForm.vue +219 -0
- package/src/components/organisms/PModal.vue +113 -0
- package/src/components/organisms/PTabs/ITab.ts +5 -0
- package/src/components/organisms/PTabs/PTabs.vue +190 -0
- package/src/components/organisms/UploaderFile/UploaderFile.test.ts +23 -0
- package/src/components/organisms/UploaderFile/UploaderFile.vue +202 -0
- package/src/components/pages/AuthPage.vue +22 -0
- package/src/components/pages/PageNotFound.vue +7 -0
- package/src/index.ts +206 -0
- package/src/interfaces/AdminLayout.ts +4 -0
- package/src/interfaces/Animations.ts +5 -0
- package/src/interfaces/AuthStatuses.ts +8 -0
- package/src/interfaces/CalendarScale.ts +6 -0
- package/src/interfaces/Callback.ts +2 -0
- package/src/interfaces/Class.ts +3 -0
- package/src/interfaces/DataTypes.ts +8 -0
- package/src/interfaces/Filter.ts +3 -0
- package/src/interfaces/IAdminMenu.ts +9 -0
- package/src/interfaces/IAuthInfo.ts +0 -0
- package/src/interfaces/ICursor.ts +14 -0
- package/src/interfaces/IEmailPassword.ts +4 -0
- package/src/interfaces/IFIlesList.ts +4 -0
- package/src/interfaces/IFile.ts +7 -0
- package/src/interfaces/IFileAnchor.ts +4 -0
- package/src/interfaces/IFileInfo.ts +22 -0
- package/src/interfaces/IFileInfosGetter.ts +5 -0
- package/src/interfaces/IFiler.ts +7 -0
- package/src/interfaces/IFilter.ts +4 -0
- package/src/interfaces/IFilterQuery.ts +24 -0
- package/src/interfaces/IForm.ts +5 -0
- package/src/interfaces/IHTTPTypes.ts +19 -0
- package/src/interfaces/IMessage.ts +5 -0
- package/src/interfaces/IOption.ts +4 -0
- package/src/interfaces/IOrdered.ts +4 -0
- package/src/interfaces/IPagination.ts +15 -0
- package/src/interfaces/ISearchElement.ts +6 -0
- package/src/interfaces/ISearchObject.ts +6 -0
- package/src/interfaces/ISearchQuery.ts +4 -0
- package/src/interfaces/ISelectFilter.ts +6 -0
- package/src/interfaces/ISortModel.ts +18 -0
- package/src/interfaces/IStorePaginator.ts +4 -0
- package/src/interfaces/ISupposedTimePeriod.ts +4 -0
- package/src/interfaces/ITimePeriod.ts +4 -0
- package/src/interfaces/ITokens.ts +4 -0
- package/src/interfaces/IWithId.ts +3 -0
- package/src/interfaces/IWithImage.ts +9 -0
- package/src/interfaces/IWithName.ts +4 -0
- package/src/interfaces/IWithSupposedTimePeriod.ts +4 -0
- package/src/interfaces/ItemsWithCount.ts +4 -0
- package/src/interfaces/LocalStoreKeys.ts +7 -0
- package/src/interfaces/Operators.ts +11 -0
- package/src/interfaces/Orders.ts +4 -0
- package/src/interfaces/RoleName.ts +4 -0
- package/src/interfaces/SocialTypes.ts +6 -0
- package/src/interfaces/Sort.ts +9 -0
- package/src/interfaces/ValueRelation.ts +7 -0
- package/src/interfaces/canvas/ICanvas.ts +3 -0
- package/src/interfaces/canvas/ICanvasResult.ts +7 -0
- package/src/interfaces/canvas/ICoordinates.ts +6 -0
- package/src/interfaces/types.ts +3 -0
- package/src/services/AdminHead.ts +32 -0
- package/src/services/AdminSideMenu.ts +52 -0
- package/src/services/AdminUI.ts +9 -0
- package/src/services/Arrays.ts +65 -0
- package/src/services/Axios.ts +64 -0
- package/src/services/BaseRoutes.ts +21 -0
- package/src/services/BaseStore.ts +220 -0
- package/src/services/Button.ts +42 -0
- package/src/services/Cache.ts +44 -0
- package/src/services/CacheS.ts +44 -0
- package/src/services/CarouselSwipe.ts +14 -0
- package/src/services/ClassHelper.ts +101 -0
- package/src/services/Color.ts +8 -0
- package/src/services/CreateSortModels.ts +26 -0
- package/src/services/Cursor.ts +51 -0
- package/src/services/DateFormat.ts +102 -0
- package/src/services/DateMask.ts +69 -0
- package/src/services/Dates.ts +41 -0
- package/src/services/DatesFormatter.ts +45 -0
- package/src/services/Dialog.ts +70 -0
- package/src/services/Dragger.ts +22 -0
- package/src/services/Extension.ts +6 -0
- package/src/services/Favourite.ts +62 -0
- package/src/services/HttpClient.ts +199 -0
- package/src/services/HttpClientS.ts +188 -0
- package/src/services/HttpError.ts +58 -0
- package/src/services/Loading.ts +14 -0
- package/src/services/MakeCarousel.ts +10 -0
- package/src/services/Menu.ts +102 -0
- package/src/services/Message.ts +66 -0
- package/src/services/Notification.ts +37 -0
- package/src/services/PHelp.ts +20 -0
- package/src/services/Paginator.ts +22 -0
- package/src/services/Period.ts +29 -0
- package/src/services/PhoneService.ts +46 -0
- package/src/services/Router.ts +85 -0
- package/src/services/RouterGuard.ts +15 -0
- package/src/services/Scheduler.ts +66 -0
- package/src/services/Scroll.ts +19 -0
- package/src/services/SortList.ts +44 -0
- package/src/services/Sorter.ts +6 -0
- package/src/services/Strings.test.ts +30 -0
- package/src/services/Strings.ts +138 -0
- package/src/services/Time.ts +124 -0
- package/src/services/Timer.ts +13 -0
- package/src/services/Token.ts +71 -0
- package/src/services/Visible.ts +16 -0
- package/src/services/WaitElement.ts +19 -0
- package/src/services/WebSocketClient.ts +62 -0
- package/src/services/brandColors.ts +5 -0
- package/src/services/buildNameNumbers.ts +8 -0
- package/src/services/countRating.ts +12 -0
- package/src/services/index.ts +105 -0
- package/src/services/indexNames.ts +55 -0
- package/src/services/moves.ts +17 -0
- package/src/services/useConfirmLeavePage.ts +52 -0
- package/src/services/validate.ts +22 -0
- package/src/store/AuthStore.ts +58 -0
- package/src/store/ContactsStore.ts +11 -0
- package/src/store/CropperStore.ts +20 -0
- package/src/store/EmailsStore.ts +11 -0
- package/src/store/FTSPPresetsStore.ts +11 -0
- package/src/store/FileInfosStore.ts +11 -0
- package/src/store/HumansStore.ts +11 -0
- package/src/store/MenusStore.ts +11 -0
- package/src/store/PhonesStore.ts +11 -0
- package/src/store/SchemasStore.ts +11 -0
- package/src/store/SearchStore.ts +65 -0
- package/src/store/ServicesStores.ts +29 -0
- package/src/store/ServicesStoresNames.ts +17 -0
- package/src/store/UserAccountsStore.ts +11 -0
- package/src/store/ValueTypesStore.ts +11 -0
- package/src/tsconfig.build-lib.json +30 -0
- package/src/types/AuthInfo.ts +6 -0
- package/src/types/HttpHeaders.ts +12 -0
- package/src/types/HttpMethods.ts +6 -0
- package/src/types/Sizes.ts +7 -0
- package/src/types/Statuses.ts +9 -0
- package/src/types/ValueTypes.ts +16 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import Cache from '@/services/CacheS';
|
|
2
|
+
import FileInfo from '@/services/classes/FileInfo';
|
|
3
|
+
import FTSP from '@/services/classes/filters/FTSP';
|
|
4
|
+
import HttpResponse from '@/services/classes/HttpResponse';
|
|
5
|
+
import { Constructable } from '@/services/ClassHelper';
|
|
6
|
+
import HttpClient from '@/services/HttpClientS';
|
|
7
|
+
import IFileInfosGetter from '@/services/interfaces/IFileInfosGetter';
|
|
8
|
+
import { IBodyfulParams } from '@/services/interfaces/IHTTPTypes';
|
|
9
|
+
import ItemsWithCount from '@/services/interfaces/ItemsWithCount';
|
|
10
|
+
import IWithId from '@/services/interfaces/IWithId';
|
|
11
|
+
|
|
12
|
+
interface GetAllOptions {
|
|
13
|
+
withCache?: boolean;
|
|
14
|
+
ftsp: FTSP;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default class BaseStore<T extends IWithId & IFileInfosGetter> {
|
|
18
|
+
protected readonly items: T[] = reactive([]);
|
|
19
|
+
protected readonly item: T;
|
|
20
|
+
protected count = ref(0);
|
|
21
|
+
protected classConstructor: Constructable<T>;
|
|
22
|
+
protected url = '';
|
|
23
|
+
|
|
24
|
+
constructor(i: Constructable<T>, url: string) {
|
|
25
|
+
this.classConstructor = i;
|
|
26
|
+
this.item = reactive(new this.classConstructor());
|
|
27
|
+
this.url = url;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Set(item: T | void) {
|
|
31
|
+
Object.assign(this.item, new this.classConstructor(item));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Item(): T {
|
|
35
|
+
return this.item;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ======= //
|
|
39
|
+
// ACTIONS //
|
|
40
|
+
// ======= //
|
|
41
|
+
protected getUrl(query?: string): string {
|
|
42
|
+
if (!query) {
|
|
43
|
+
return this.url;
|
|
44
|
+
}
|
|
45
|
+
return `${this.url}/${query}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async GetAll(options?: GetAllOptions): Promise<void> {
|
|
49
|
+
let res;
|
|
50
|
+
const get = HttpClient.Get<T[] | ItemsWithCount<T>>;
|
|
51
|
+
if (options && options.withCache) {
|
|
52
|
+
res = await Cache.TryGet<T[] | ItemsWithCount<T>>(this.getUrl(), get);
|
|
53
|
+
} else {
|
|
54
|
+
res = await get({ query: this.getUrl() });
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(res)) {
|
|
57
|
+
this.SetAll(res);
|
|
58
|
+
} else {
|
|
59
|
+
this.SetAllWithCount(res as ItemsWithCount<T>);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async Get(id?: string) {
|
|
63
|
+
if (!id) {
|
|
64
|
+
id = Router.Id();
|
|
65
|
+
}
|
|
66
|
+
this.Set(await HttpClient.Get<T>({ query: this.getUrl(id) }));
|
|
67
|
+
}
|
|
68
|
+
async FTSP(options?: GetAllOptions) {
|
|
69
|
+
const ftsp: FTSP = options?.ftsp ?? FTSP.Get();
|
|
70
|
+
const f = ftsp.clearForHTTP();
|
|
71
|
+
const p: IBodyfulParams<unknown> = {
|
|
72
|
+
payload: { ftsp: f },
|
|
73
|
+
query: this.getUrl('ftsp'),
|
|
74
|
+
};
|
|
75
|
+
const res = await HttpClient.Post<unknown, HttpResponse<T[] | ItemsWithCount<T>>>(p);
|
|
76
|
+
if (!res || !res.ftsp) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (Array.isArray(res.data)) {
|
|
80
|
+
this.SetAll(res.data);
|
|
81
|
+
} else {
|
|
82
|
+
if (f.p.append) {
|
|
83
|
+
this.AppendToAll(res.data?.items);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.SetAllWithCount(res.data);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async Create(item?: T): Promise<T | void> {
|
|
91
|
+
console.log(item);
|
|
92
|
+
const param = item ?? this.item;
|
|
93
|
+
const opts: IBodyfulParams<T> = { payload: param, query: this.getUrl() };
|
|
94
|
+
if (param.getFileInfos) {
|
|
95
|
+
opts.fileInfos = param.getFileInfos();
|
|
96
|
+
opts.fileInfos.forEach((f: FileInfo) => (f.url = ''));
|
|
97
|
+
}
|
|
98
|
+
return await HttpClient.Post<T, T>(opts);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async CreateAndSet(item: T): Promise<void> {
|
|
102
|
+
const result = await this.Create(item);
|
|
103
|
+
this.Set(result);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// bun не поддерживает множественное создание с uuid. Пока отправляем несколько запросов
|
|
107
|
+
async CreateMany(items?: T[]): Promise<void> {
|
|
108
|
+
if (!items) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const promises: Promise<T | void>[] = [];
|
|
112
|
+
items.forEach((i) => {
|
|
113
|
+
promises.push(new Promise(() => this.Create(i)));
|
|
114
|
+
});
|
|
115
|
+
Promise.all(promises);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async Update(item?: T): Promise<T | void> {
|
|
119
|
+
const param = item ?? this.item;
|
|
120
|
+
const opts: IBodyfulParams<T> = { query: this.getUrl(`${param.id}`), payload: param };
|
|
121
|
+
if (param.getFileInfos) {
|
|
122
|
+
opts.fileInfos = param.getFileInfos();
|
|
123
|
+
opts.fileInfos.forEach((f: FileInfo) => (f.url = ''));
|
|
124
|
+
}
|
|
125
|
+
return await HttpClient.Put<T, T>(opts);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async UpdateAndSet(item: T): Promise<void> {
|
|
129
|
+
const result = await this.Update(item);
|
|
130
|
+
this.Set(result);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async UpdateAndReset(item?: T): Promise<void> {
|
|
134
|
+
await this.Update(item ?? this.item);
|
|
135
|
+
this.Set();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async Remove(id: string | undefined): Promise<void> {
|
|
139
|
+
if (!id) {
|
|
140
|
+
console.warn('BaseStore/Remove. id is undefined');
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
await HttpClient.Delete({ query: this.getUrl(`${id}`) });
|
|
144
|
+
this.RemoveItem(id);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// bun не поддерживает множественное обновление с uuid. Пока отправляем несколько запросов
|
|
148
|
+
async UpdateMany(items?: T[]): Promise<void> {
|
|
149
|
+
if (!items) {
|
|
150
|
+
items = this.items;
|
|
151
|
+
}
|
|
152
|
+
if (!items) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const promises: Promise<T | void>[] = [];
|
|
156
|
+
items.forEach((i) => {
|
|
157
|
+
promises.push(new Promise(() => this.Update(i)));
|
|
158
|
+
});
|
|
159
|
+
Promise.all(promises);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ======= //
|
|
163
|
+
// COMMITS //
|
|
164
|
+
// ======= //
|
|
165
|
+
SetAll(items: T[] | undefined) {
|
|
166
|
+
if (!items) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.items.splice(0, this.items.length);
|
|
170
|
+
this.items.push(...items.map((a: T) => new this.classConstructor(a)));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
SetAllWithCount(items?: ItemsWithCount<T>) {
|
|
174
|
+
if (!items) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.SetAll(items.items);
|
|
178
|
+
this.count.value = items.count;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
RemoveItem(id: string) {
|
|
182
|
+
const index = this.items.findIndex((i: T) => i.id === id);
|
|
183
|
+
this.items.splice(index, 1);
|
|
184
|
+
}
|
|
185
|
+
AppendToAll(items?: T[] | undefined) {
|
|
186
|
+
if (!items) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const resultItems = items.map((i: T) => new this.classConstructor(i));
|
|
190
|
+
this.items.push(...resultItems);
|
|
191
|
+
}
|
|
192
|
+
ResetState() {
|
|
193
|
+
this.ResetItem();
|
|
194
|
+
this.ClearItems();
|
|
195
|
+
this.count.value = 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
ResetItem() {
|
|
199
|
+
ClassHelper.BuildClass(this.item, new this.classConstructor());
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
ClearItems() {
|
|
203
|
+
this.items.splice(0, this.items.length);
|
|
204
|
+
}
|
|
205
|
+
UnshiftToAll(item: T) {
|
|
206
|
+
this.items.unshift(new this.classConstructor(item));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ======= //
|
|
210
|
+
// GETTERS //
|
|
211
|
+
// ======= //
|
|
212
|
+
|
|
213
|
+
Items(): T[] {
|
|
214
|
+
return this.items;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
Count(): Ref<number> {
|
|
218
|
+
return this.count;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from "vue";
|
|
2
|
+
import { NavigationGuardNext } from "vue-router";
|
|
3
|
+
|
|
4
|
+
import Statuses from "../types/Statuses";
|
|
5
|
+
|
|
6
|
+
type actionFunction =
|
|
7
|
+
| ((next?: NavigationGuardNext | undefined) => Promise<void>)
|
|
8
|
+
| (() => Promise<void>)
|
|
9
|
+
| (() => void);
|
|
10
|
+
|
|
11
|
+
type Text = string | ComputedRef<string> | Ref<string>;
|
|
12
|
+
type Condition = boolean | ComputedRef<boolean> | Ref<boolean>;
|
|
13
|
+
type Action = undefined | actionFunction | ComputedRef<actionFunction>;
|
|
14
|
+
|
|
15
|
+
export default class Button {
|
|
16
|
+
text?: Text = "Сохранить";
|
|
17
|
+
type?: Statuses = Statuses.Success;
|
|
18
|
+
condition?: Condition = true;
|
|
19
|
+
action?: Action;
|
|
20
|
+
|
|
21
|
+
constructor(text: Text, action: Action, t: Statuses, condition?: Condition) {
|
|
22
|
+
this.text = text;
|
|
23
|
+
this.type = t;
|
|
24
|
+
this.action = action;
|
|
25
|
+
if (condition !== undefined) {
|
|
26
|
+
this.condition = condition;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static Primary(text: Text, action: Action, condition?: Condition): Button {
|
|
31
|
+
return new Button(text, action, Statuses.Primary, condition);
|
|
32
|
+
}
|
|
33
|
+
static Success(text: Text, action: Action, condition?: Condition): Button {
|
|
34
|
+
return new Button(text, action, Statuses.Success, condition);
|
|
35
|
+
}
|
|
36
|
+
static Warning(text: Text, action: Action, condition?: Condition): Button {
|
|
37
|
+
return new Button(text, action, Statuses.Warning, condition);
|
|
38
|
+
}
|
|
39
|
+
static Error(text: Text, action: Action, condition?: Condition): Button {
|
|
40
|
+
return new Button(text, action, Statuses.Error, condition);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import ClassHelper from '@/services/ClassHelper';
|
|
2
|
+
|
|
3
|
+
export default class Cache {
|
|
4
|
+
name = '';
|
|
5
|
+
|
|
6
|
+
constructor(i?: Cache) {
|
|
7
|
+
ClassHelper.BuildClass(this, i);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public cache(): void {
|
|
11
|
+
// const res = { data, time: new Date() };
|
|
12
|
+
// sessionStorage.setItem(this.name, JSON.stringify(res));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getFromCache<DataType>(min?: number): DataType | null {
|
|
16
|
+
const res = sessionStorage.getItem(this.name);
|
|
17
|
+
if (res) {
|
|
18
|
+
const storeData = JSON.parse(res);
|
|
19
|
+
const now = new Date();
|
|
20
|
+
const timestamp = new Date(storeData.time);
|
|
21
|
+
const difference = now.getTime() - timestamp.getTime(); // difference in milliseconds
|
|
22
|
+
const resultInMinutes = Math.round(difference / 60000);
|
|
23
|
+
const defaultMin = 10; // min by default
|
|
24
|
+
if (resultInMinutes > (min ? min : defaultMin)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return storeData.data;
|
|
28
|
+
} else {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async storeGetWithCache<DataType>(get: () => Promise<DataType | void>, min?: number): Promise<DataType | void | null> {
|
|
34
|
+
let res;
|
|
35
|
+
res = this.getFromCache<DataType>(min);
|
|
36
|
+
if (!res) {
|
|
37
|
+
res = await get();
|
|
38
|
+
if (res) {
|
|
39
|
+
this.cache();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return res;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import ClassHelper from '@/services/ClassHelper';
|
|
2
|
+
|
|
3
|
+
export default class Cache {
|
|
4
|
+
name = '';
|
|
5
|
+
|
|
6
|
+
constructor(i?: Cache) {
|
|
7
|
+
ClassHelper.BuildClass(this, i);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public static Set(): void {
|
|
11
|
+
// const res = { data, time: new Date() };
|
|
12
|
+
// sessionStorage.setItem(this.name, JSON.stringify(res));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public static Get<DataType>(name: string, min?: number): DataType | null {
|
|
16
|
+
const res = sessionStorage.getItem(name);
|
|
17
|
+
if (res) {
|
|
18
|
+
const storeData = JSON.parse(res);
|
|
19
|
+
const now = new Date();
|
|
20
|
+
const timestamp = new Date(storeData.time);
|
|
21
|
+
const difference = now.getTime() - timestamp.getTime(); // difference in milliseconds
|
|
22
|
+
const resultInMinutes = Math.round(difference / 60000);
|
|
23
|
+
const defaultMin = 10; // min by default
|
|
24
|
+
if (resultInMinutes > (min ? min : defaultMin)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return storeData.data;
|
|
28
|
+
} else {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async TryGet<DataType>(name: string, get: () => Promise<DataType | void>, min?: number): Promise<DataType | void | null> {
|
|
34
|
+
let res;
|
|
35
|
+
res = Cache.Get<DataType>(name, min);
|
|
36
|
+
if (!res) {
|
|
37
|
+
res = await get();
|
|
38
|
+
if (res) {
|
|
39
|
+
// Cache.Set<DataType>(name, res);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return res;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
|
|
5
|
+
import IWithId from '@/services/interfaces/IWithId';
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line
|
|
8
|
+
export type ClassType = { [key: string]: any };
|
|
9
|
+
// eslint-disable-next-line
|
|
10
|
+
export type Constructable<T> = { new (...args: any[]): T };
|
|
11
|
+
|
|
12
|
+
export default class ClassHelper {
|
|
13
|
+
static BuildClass(passedClass: ClassType, arg?: ClassType): void {
|
|
14
|
+
if (!arg) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
Object.keys(arg).forEach((key) => {
|
|
18
|
+
const prop = arg[key];
|
|
19
|
+
if (this.isPrimitive(prop)) {
|
|
20
|
+
if (passedClass[key] instanceof Date) {
|
|
21
|
+
passedClass[key] = new Date(prop);
|
|
22
|
+
} else {
|
|
23
|
+
passedClass[key] = prop;
|
|
24
|
+
}
|
|
25
|
+
} else if (prop !== null && prop !== undefined && !Array.isArray(prop)) {
|
|
26
|
+
if (passedClass[key] && passedClass[key].constructor) {
|
|
27
|
+
passedClass[key] = new passedClass[key].constructor(prop);
|
|
28
|
+
} else {
|
|
29
|
+
const constructor = Reflect.getMetadata(key, passedClass);
|
|
30
|
+
if (constructor) {
|
|
31
|
+
passedClass[key] = new constructor[key](prop);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(prop)) {
|
|
36
|
+
const constructor = Reflect.getMetadata(key, passedClass);
|
|
37
|
+
if (constructor) {
|
|
38
|
+
passedClass[key] = prop.map((t) => new constructor[key](t));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static GetClassConstructor = <T>(construct: Constructable<T>): PropertyDecorator => {
|
|
45
|
+
return (targetClass, propertyName) => {
|
|
46
|
+
const metadataSingleton = Reflect.getMetadata(`property:${propertyName as string}`, targetClass) || {};
|
|
47
|
+
metadataSingleton[propertyName] = construct;
|
|
48
|
+
Reflect.defineMetadata(propertyName, metadataSingleton, targetClass);
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
private static isPrimitive(prop: unknown): boolean {
|
|
53
|
+
return prop !== null && typeof prop !== 'undefined' && prop !== Object(prop);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static RemoveFromClassByIndex(index: number, arrayFromDelete: IWithId[], arrayForDelete?: string[]): void {
|
|
57
|
+
ClassHelper.RemoveFromClass(index, arrayFromDelete, arrayForDelete);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static RemoveFromClassById(id: string | undefined, arrayFromDelete: IWithId[], arrayForDelete?: string[]): string | undefined {
|
|
61
|
+
if (!id) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const index = arrayFromDelete.findIndex((i: IWithId) => i.id === id);
|
|
65
|
+
ClassHelper.RemoveFromClass(index, arrayFromDelete, arrayForDelete);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private static RemoveFromClass(index: number, arrayFromDelete: IWithId[], arrayForDelete?: string[]): void {
|
|
69
|
+
if (index < 0) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const idForDelete = arrayFromDelete[index].id;
|
|
73
|
+
if (idForDelete && arrayForDelete) {
|
|
74
|
+
arrayForDelete.push(idForDelete);
|
|
75
|
+
}
|
|
76
|
+
arrayFromDelete.splice(index, 1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static GetPropertyName<T extends ClassType>(obj: Constructable<T>): T {
|
|
80
|
+
const o = new obj();
|
|
81
|
+
return new Proxy(o, {
|
|
82
|
+
get(t, key) {
|
|
83
|
+
return key;
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static CreateUUID(): string {
|
|
89
|
+
return uuidv4();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static InitClassInstance(passedClass: ClassType, arg?: ClassType): ClassType {
|
|
93
|
+
const item = passedClass.constructor(arg);
|
|
94
|
+
ClassHelper.BuildClass(item);
|
|
95
|
+
item.id = ClassHelper.CreateUUID();
|
|
96
|
+
return item;
|
|
97
|
+
}
|
|
98
|
+
static ExistsWithId(arr: IWithId[], id?: string): boolean {
|
|
99
|
+
return arr.some((a: IWithId) => a.id === id);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import SortModel from '@/services/classes/SortModel';
|
|
2
|
+
import { Orders } from '@/services/interfaces/Orders';
|
|
3
|
+
import { SortModelBuilder, SortModelBuildersLib } from '@/services/interfaces/Sort';
|
|
4
|
+
|
|
5
|
+
export default function createSortModels(lib: SortModelBuildersLib, mainOrder?: Orders): SortModel[] {
|
|
6
|
+
const sortModels: SortModel[] = [];
|
|
7
|
+
const firstOrder = mainOrder ? mainOrder : Orders.Asc;
|
|
8
|
+
const secondOrder = firstOrder === Orders.Asc ? Orders.Desc : Orders.Asc;
|
|
9
|
+
|
|
10
|
+
Object.values(lib).forEach((el: SortModelBuilder) => {
|
|
11
|
+
sortModels.push(el(firstOrder));
|
|
12
|
+
sortModels.push(el(secondOrder));
|
|
13
|
+
});
|
|
14
|
+
if (sortModels.length > 0 && !sortModels.some((s: SortModel) => s.default)) {
|
|
15
|
+
sortModels[0].default = true;
|
|
16
|
+
}
|
|
17
|
+
if (!mainOrder) {
|
|
18
|
+
return sortModels;
|
|
19
|
+
}
|
|
20
|
+
sortModels.forEach((sortModel: SortModel) => {
|
|
21
|
+
if (sortModel.default) {
|
|
22
|
+
sortModel.default = sortModel.order === mainOrder;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return sortModels;
|
|
26
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TimelineMinutes, TimelineSteps } from '@/services/Time';
|
|
2
|
+
|
|
3
|
+
import Arrays from './Arrays';
|
|
4
|
+
|
|
5
|
+
export default class Scheduler {
|
|
6
|
+
startHour = 9;
|
|
7
|
+
endHour = 19;
|
|
8
|
+
timelinePxHeight = 50;
|
|
9
|
+
|
|
10
|
+
timelineStep: TimelineSteps = TimelineSteps.FiveMinutes;
|
|
11
|
+
|
|
12
|
+
activeTime = '';
|
|
13
|
+
activeObjectId = '';
|
|
14
|
+
|
|
15
|
+
dragged = false;
|
|
16
|
+
draggedStartTime = '';
|
|
17
|
+
draggedEndTime = '';
|
|
18
|
+
|
|
19
|
+
timelines: string[] = TimelineMinutes[TimelineSteps.FiveMinutes];
|
|
20
|
+
|
|
21
|
+
startDrag(t1: string, t2: string): void {
|
|
22
|
+
this.draggedStartTime = t1;
|
|
23
|
+
this.draggedEndTime = t2;
|
|
24
|
+
this.dragged = true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
endDrag(): void {
|
|
28
|
+
this.activeTime = '';
|
|
29
|
+
this.dragged = false;
|
|
30
|
+
}
|
|
31
|
+
setTimelineStep(step: TimelineSteps): void {
|
|
32
|
+
this.timelineStep = step;
|
|
33
|
+
this.setTimelines();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setTimelines(): void {
|
|
37
|
+
this.timelines = TimelineMinutes[this.timelineStep];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getScheduleHeight() {
|
|
41
|
+
return this.getHourHeight() * this.getHoursArr().length;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getHourHeight() {
|
|
45
|
+
return this.timelinePxHeight * this.timelines.length;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getHoursArr(): number[] {
|
|
49
|
+
return Arrays.GenerateNumsRange(this.startHour, this.endHour);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export const SetDays = ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье'];
|
|
2
|
+
export const SetDaysMobile = ['ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ', 'ВС'];
|
|
3
|
+
const SetShortDays = ['ВС', 'ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ'];
|
|
4
|
+
|
|
5
|
+
interface CustomDateTimeFormatOptions {
|
|
6
|
+
localeMatcher?: string;
|
|
7
|
+
weekday?: 'narrow' | 'short' | 'long';
|
|
8
|
+
era?: string;
|
|
9
|
+
year?: 'numeric' | '2-digit' | undefined;
|
|
10
|
+
month?: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long';
|
|
11
|
+
day?: 'numeric' | '2-digit' | undefined;
|
|
12
|
+
hour?: 'numeric' | '2-digit';
|
|
13
|
+
minute?: 'numeric' | '2-digit';
|
|
14
|
+
second?: string;
|
|
15
|
+
timeZoneName?: string;
|
|
16
|
+
formatMatcher?: string;
|
|
17
|
+
hour12?: boolean;
|
|
18
|
+
timeZone?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default class DateTimeFormat {
|
|
22
|
+
locale = 'ru-RU';
|
|
23
|
+
|
|
24
|
+
constructor(locale?: string) {
|
|
25
|
+
this.locale = locale ?? this.locale;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
format(date?: Date, options?: CustomDateTimeFormatOptions): string {
|
|
29
|
+
if (!date) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
const opt: Intl.DateTimeFormatOptions = { year: 'numeric', month: '2-digit', day: '2-digit', hour: undefined, minute: undefined };
|
|
33
|
+
if (options) {
|
|
34
|
+
opt.year = options.year || options.year === undefined ? options.year : opt.year;
|
|
35
|
+
opt.month = options.month || options.month === undefined ? options.month : opt.month;
|
|
36
|
+
opt.day = options.day || options.day === undefined ? options.day : opt.day;
|
|
37
|
+
opt.hour = options.hour ?? opt.hour;
|
|
38
|
+
opt.minute = options.minute ?? opt.minute;
|
|
39
|
+
}
|
|
40
|
+
return Intl.DateTimeFormat(this.locale, opt).format(new Date(date));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getPeriod(start: Date, end: Date, options?: CustomDateTimeFormatOptions): string {
|
|
44
|
+
return `${this.format(start, options)}-${this.format(end, options)}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getShortDayName(date?: Date): string {
|
|
48
|
+
if (!date) {
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
return SetShortDays[date.getDay()];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getCurrentWeekPeriod(options?: CustomDateTimeFormatOptions): string {
|
|
55
|
+
const now = new Date();
|
|
56
|
+
const startOfWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - now.getDay() + 1);
|
|
57
|
+
const endOfWeek = new Date(now.getFullYear(), now.getMonth(), startOfWeek.getDate() + 7);
|
|
58
|
+
return this.getPeriod(startOfWeek, endOfWeek, options ? options : { month: '2-digit', day: 'numeric', year: undefined });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getDurationInDay(time1: string, time2: string): number {
|
|
62
|
+
const timeStart = new Date();
|
|
63
|
+
const timeEnd = new Date();
|
|
64
|
+
const valueStart = DateTimeFormat.SplitHourTime(time1);
|
|
65
|
+
const valueEnd = DateTimeFormat.SplitHourTime(time2);
|
|
66
|
+
|
|
67
|
+
timeStart.setHours(valueStart[0], valueStart[1], 0, 0);
|
|
68
|
+
timeEnd.setHours(valueEnd[0], valueEnd[1], 0, 0);
|
|
69
|
+
|
|
70
|
+
const diff = timeEnd.getTime() - timeStart.getTime();
|
|
71
|
+
|
|
72
|
+
return diff / 1000 / 60; // millisecond
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static HourTimeinMunutes(time: string): number {
|
|
76
|
+
const parts = DateTimeFormat.SplitHourTime(time);
|
|
77
|
+
return parts[0] * 60 + parts[1];
|
|
78
|
+
}
|
|
79
|
+
static SplitHourTime(time: string): number[] {
|
|
80
|
+
const parts = time.split(':');
|
|
81
|
+
return [Number(parts[0]), Number(parts[1])];
|
|
82
|
+
}
|
|
83
|
+
static AddMinutesToHM(hm: string, minutes: number): string {
|
|
84
|
+
const d = new Date();
|
|
85
|
+
const hmArr = DateTimeFormat.SplitHourTime(hm);
|
|
86
|
+
d.setHours(hmArr[0], hmArr[1], 0, 0);
|
|
87
|
+
const newD = new Date(d.getTime() + minutes * 60000);
|
|
88
|
+
const h = newD.getHours();
|
|
89
|
+
const m = newD.getMinutes();
|
|
90
|
+
return `${h}:${m}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getMonthsDiff(dateFrom: Date, dateTo: Date): number {
|
|
94
|
+
return dateTo.getMonth() - dateFrom.getMonth() + 12 * (dateTo.getFullYear() - dateFrom.getFullYear());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
stringToDate(value: string): Date {
|
|
98
|
+
const parts = value.split('.');
|
|
99
|
+
const date = new Date(`${parts[2]}-${parts[1]}-${parts[0]}`);
|
|
100
|
+
return date;
|
|
101
|
+
}
|
|
102
|
+
}
|