bfg-common 1.4.310 → 1.4.311

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.
@@ -12,10 +12,11 @@
12
12
 
13
13
  <Teleport to="body">
14
14
  <common-layout-the-header-user-menu-modals-change-password
15
- :show="isChangePassword"
15
+ v-if="isShowChangePasswordModal"
16
+ v-model="isShowChangePasswordModal"
17
+ :new-view="props.newView"
16
18
  :hostname="props.hostname"
17
19
  :project="props.project"
18
- @hide="isChangePassword = false"
19
20
  />
20
21
 
21
22
  <common-layout-the-header-user-menu-modals-preferences
@@ -74,7 +75,7 @@ const emits = defineEmits<{
74
75
 
75
76
  const { $store }: any = useNuxtApp()
76
77
 
77
- const isChangePassword = ref<boolean>(false)
78
+ const isShowChangePasswordModal = ref<boolean>(false)
78
79
 
79
80
  const onLogout = async (): Promise<void> => {
80
81
  await $store.dispatch('auth/A_LOGOUT', null)
@@ -83,7 +84,7 @@ const onLogout = async (): Promise<void> => {
83
84
  const onSelectDropdown = (value: string): void => {
84
85
  switch (value) {
85
86
  case 'changePassword':
86
- isChangePassword.value = true
87
+ isShowChangePasswordModal.value = true
87
88
  break
88
89
  case 'preferences':
89
90
  emits('show-preference')
@@ -1,88 +1,20 @@
1
1
  <template>
2
- <atoms-modal
3
- width="580px"
4
- test-id="change-password"
5
- :show="props.show"
6
- :title="localization.common.changePassword"
7
- :second-title="props.hostname"
8
- :disabled-submit="buttonDisabled"
2
+ <common-layout-the-header-user-menu-modals-change-password-new
3
+ v-if="newView"
4
+ v-model="form"
5
+ :subtitle="props.hostname"
6
+ :project="props.project"
9
7
  @hide="onHideModal"
10
- @submit="onChangePassword"
11
- >
12
- <template #modalBody>
13
- <form id="change-password-form" class="compact" @submit.prevent>
14
- <section class="form-block">
15
- <div class="form-group">
16
- <label for="current-password-field"
17
- >{{ localization.common.currentPassword }}:</label
18
- >
19
- <input
20
- id="current-password-field"
21
- v-model="form.password.value"
22
- data-id="change-password-input"
23
- type="password"
24
- />
25
- </div>
26
-
27
- <div class="form-group">
28
- <label for="new-password-field"
29
- >{{ localization.common.newPassword }}:</label
30
- >
31
-
32
- <div class="form-group__input">
33
- <atoms-tooltip-error
34
- :has-error="isValid"
35
- selector="#new-password-field"
36
- >
37
- <template #elem>
38
- <input
39
- id="new-password-field"
40
- v-model="form.newPassword.value"
41
- data-id="new-password-input"
42
- type="password"
43
- />
44
- </template>
45
- <template #content>{{ errorText }}</template>
46
- </atoms-tooltip-error>
47
- <atoms-the-icon
48
- v-show="isValid"
49
- class="is-error tooltip-trigger"
50
- name="info"
51
- />
52
- </div>
53
- </div>
54
-
55
- <div class="form-group">
56
- <label for="confirm-password-field"
57
- >{{ localization.common.confirmPassword }}:</label
58
- >
59
-
60
- <div class="form-group__input">
61
- <atoms-tooltip-error
62
- :has-error="isValid"
63
- selector="#confirm-password-field"
64
- >
65
- <template #elem>
66
- <input
67
- id="confirm-password-field"
68
- v-model="form.confirmPassword.value"
69
- data-id="confirm-password-input"
70
- type="password"
71
- />
72
- </template>
73
- <template #content>{{ errorText }}</template>
74
- </atoms-tooltip-error>
75
- <atoms-the-icon
76
- v-show="isValid"
77
- class="is-error tooltip-trigger"
78
- name="info"
79
- />
80
- </div>
81
- </div>
82
- </section>
83
- </form>
84
- </template>
85
- </atoms-modal>
8
+ @apply="onChangePassword"
9
+ />
10
+
11
+ <common-layout-the-header-user-menu-modals-change-password-old
12
+ v-else
13
+ :hostname="props.hostname"
14
+ :project="props.project"
15
+ @hide="onHideModal"
16
+ @apply="onChangePassword"
17
+ />
86
18
  </template>
87
19
 
88
20
  <script setup lang="ts">
@@ -96,13 +28,11 @@ import type { UI_T_Project } from '~/lib/models/types'
96
28
  import { defaultFormFunc } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/config/form'
97
29
 
98
30
  const props = defineProps<{
99
- show: boolean
31
+ newView: boolean
100
32
  hostname: string
101
33
  project: UI_T_Project
102
34
  }>()
103
- const emits = defineEmits<{
104
- (event: 'hide'): void
105
- }>()
35
+ const isShowModalLocal = defineModel<boolean>({ required: true })
106
36
 
107
37
  const localization = computed<UI_I_Localization>(() => useLocal())
108
38
  const { $store, $validation }: any = useNuxtApp()
@@ -120,15 +50,6 @@ const setForm = (): void => {
120
50
  }
121
51
  setForm()
122
52
 
123
- const buttonDisabled = computed<boolean>(() => {
124
- const { password, confirmPassword, newPassword } = form.value
125
- return (
126
- password.value &&
127
- confirmPassword.value &&
128
- newPassword.value !== confirmPassword.value
129
- )
130
- })
131
-
132
53
  const onChangePassword = async (): Promise<void> => {
133
54
  const valid = validation.touch()
134
55
  const { newPassword, password } = form.value
@@ -184,27 +105,8 @@ const showValidationErrors = (text: string): void => {
184
105
  }
185
106
 
186
107
  const onHideModal = (): void => {
187
- emits('hide')
108
+ isShowModalLocal.value = false
188
109
  setForm()
189
110
  isValid.value = false
190
111
  }
191
112
  </script>
192
-
193
- <style lang="scss" scoped>
194
- .form-block {
195
- .form-group {
196
- &:not(:first-child) input {
197
- width: 100%;
198
- }
199
- &__input {
200
- display: flex;
201
- width: 100%;
202
- }
203
- }
204
-
205
- svg {
206
- width: 24px;
207
- height: 24px;
208
- }
209
- }
210
- </style>
@@ -0,0 +1,103 @@
1
+ <template>
2
+ <ui-modal
3
+ test-id="change-password-modal"
4
+ width="560px"
5
+ :title="localization.common.changePassword"
6
+ :subtitle="props.subtitle"
7
+ class="change-password"
8
+ @reset="emits('reset')"
9
+ @submit="onSubmit"
10
+ >
11
+ <template #content>
12
+ <ui-modal-block-standard>
13
+ <p class="change-password__description">
14
+ To keep your account secure, please make sure that your new password
15
+ is different from any of your previous passwords.
16
+ </p>
17
+
18
+ <div class="change-password__form">
19
+ <ui-input
20
+ v-model="modelLocal.current_password"
21
+ test-id="sign-in-username-field"
22
+ :label="localization.auth.password"
23
+ :error="errorText"
24
+ type="password"
25
+ ></ui-input>
26
+
27
+ <ui-input
28
+ v-model="modelLocal.new_password"
29
+ test-id="sign-in-username-field"
30
+ :label="localization.common.newPassword"
31
+ :error="errorText"
32
+ type="password"
33
+ ></ui-input>
34
+
35
+ <ui-input
36
+ v-model="modelLocal.confirm_password"
37
+ test-id="sign-in-username-field"
38
+ :label="localization.common.confirmPassword"
39
+ :error="errorText"
40
+ type="password"
41
+ ></ui-input>
42
+ </div>
43
+ </ui-modal-block-standard>
44
+ </template>
45
+
46
+ <template #footerLeftContent><span /></template>
47
+ </ui-modal>
48
+ </template>
49
+
50
+ <script setup lang="ts">
51
+ import type { UI_I_Localization } from '~//lib/models/interfaces'
52
+ import type { UI_I_FormChangePassword } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/models/interfaces'
53
+ import type { UI_T_Project } from '~/lib/models/types'
54
+
55
+ const props = defineProps<{
56
+ project: UI_T_Project
57
+ subtitle: string
58
+ }>()
59
+ const emits = defineEmits<{
60
+ (event: 'hide'): void
61
+ (event: 'reset'): void
62
+ (event: 'submit'): void
63
+ }>()
64
+ const modelLocal = defineModel<UI_I_FormChangePassword>({ required: true })
65
+
66
+ const localization = computed<UI_I_Localization>(() => useLocal())
67
+
68
+ // const isValid = ref<boolean>(false)
69
+ const errorText = ref<string>('')
70
+
71
+ // const showValidationErrors = (text: string): void => {
72
+ // isValid.value = true
73
+ // errorText.value = text
74
+ // }
75
+
76
+ // const onHideModal = (): void => {
77
+ // emits('hide')
78
+ // setForm()
79
+ // isValid.value = false
80
+ // }
81
+
82
+ const onSubmit = (): void => {
83
+ // const { } = modelLocal.value
84
+ errorText.value = 'asdaldjlkdjkadj'
85
+ }
86
+ </script>
87
+
88
+ <style lang="scss" scoped>
89
+ @import 'assets/scss/common/mixins.scss';
90
+ .change-password {
91
+ &__description {
92
+ color: #9da6ad;
93
+ font-size: 12px;
94
+ font-weight: 400;
95
+ line-height: 14.52px;
96
+ margin-bottom: 20px;
97
+ }
98
+ &__form {
99
+ @include flex($dir: column);
100
+ row-gap: 18px;
101
+ }
102
+ }
103
+ </style>
@@ -0,0 +1,209 @@
1
+ <template>
2
+ <atoms-modal
3
+ width="580px"
4
+ test-id="change-password"
5
+ show
6
+ :title="localization.common.changePassword"
7
+ :second-title="props.hostname"
8
+ :disabled-submit="buttonDisabled"
9
+ @hide="onHideModal"
10
+ @submit="onChangePassword"
11
+ >
12
+ <template #modalBody>
13
+ <form id="change-password-form" class="compact" @submit.prevent>
14
+ <section class="form-block">
15
+ <div class="form-group">
16
+ <label for="current-password-field"
17
+ >{{ localization.common.currentPassword }}:</label
18
+ >
19
+ <input
20
+ id="current-password-field"
21
+ v-model="form.password.value"
22
+ data-id="change-password-input"
23
+ type="password"
24
+ />
25
+ </div>
26
+
27
+ <div class="form-group">
28
+ <label for="new-password-field"
29
+ >{{ localization.common.newPassword }}:</label
30
+ >
31
+
32
+ <div class="form-group__input">
33
+ <atoms-tooltip-error
34
+ :has-error="isValid"
35
+ selector="#new-password-field"
36
+ >
37
+ <template #elem>
38
+ <input
39
+ id="new-password-field"
40
+ v-model="form.newPassword.value"
41
+ data-id="new-password-input"
42
+ type="password"
43
+ />
44
+ </template>
45
+ <template #content>{{ errorText }}</template>
46
+ </atoms-tooltip-error>
47
+ <atoms-the-icon
48
+ v-show="isValid"
49
+ class="is-error tooltip-trigger"
50
+ name="info"
51
+ />
52
+ </div>
53
+ </div>
54
+
55
+ <div class="form-group">
56
+ <label for="confirm-password-field"
57
+ >{{ localization.common.confirmPassword }}:</label
58
+ >
59
+
60
+ <div class="form-group__input">
61
+ <atoms-tooltip-error
62
+ :has-error="isValid"
63
+ selector="#confirm-password-field"
64
+ >
65
+ <template #elem>
66
+ <input
67
+ id="confirm-password-field"
68
+ v-model="form.confirmPassword.value"
69
+ data-id="confirm-password-input"
70
+ type="password"
71
+ />
72
+ </template>
73
+ <template #content>{{ errorText }}</template>
74
+ </atoms-tooltip-error>
75
+ <atoms-the-icon
76
+ v-show="isValid"
77
+ class="is-error tooltip-trigger"
78
+ name="info"
79
+ />
80
+ </div>
81
+ </div>
82
+ </section>
83
+ </form>
84
+ </template>
85
+ </atoms-modal>
86
+ </template>
87
+
88
+ <script setup lang="ts">
89
+ import type { UI_I_Localization } from '~/lib/models/interfaces'
90
+ import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
91
+ import type {
92
+ UI_I_ChangePasswordBodyRequest,
93
+ UI_I_FormChangePassword,
94
+ } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/models/interfaces'
95
+ import type { UI_T_Project } from '~/lib/models/types'
96
+ import { defaultFormFunc } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/config/form'
97
+
98
+ const props = defineProps<{
99
+ hostname: string
100
+ project: UI_T_Project
101
+ }>()
102
+ const emits = defineEmits<{
103
+ (event: 'hide'): void
104
+ }>()
105
+
106
+ const localization = computed<UI_I_Localization>(() => useLocal())
107
+ const { $store, $validation }: any = useNuxtApp()
108
+ const validation = $validation.call({})
109
+
110
+ const isValid = ref<boolean>(false)
111
+ const errorText = ref<string>('')
112
+ const form = ref<UI_I_FormChangePassword>(
113
+ useDeepCopy(defaultFormFunc(localization.value))
114
+ )
115
+
116
+ const setForm = (): void => {
117
+ form.value = useDeepCopy(defaultFormFunc(localization.value))
118
+ validation.setForm(form)
119
+ }
120
+ setForm()
121
+
122
+ const buttonDisabled = computed<boolean>(() => {
123
+ const { password, confirmPassword, newPassword } = form.value
124
+ return (
125
+ password.value &&
126
+ confirmPassword.value &&
127
+ newPassword.value !== confirmPassword.value
128
+ )
129
+ })
130
+
131
+ const onChangePassword = async (): Promise<void> => {
132
+ const valid = validation.touch()
133
+ const { newPassword, password } = form.value
134
+
135
+ if (newPassword.value === password.value) {
136
+ showValidationErrors(localization.value.common.newPasswordMustDifferentOld)
137
+ return
138
+ }
139
+ if (!valid.isValid) {
140
+ showValidationErrors(valid.errors.confirmPassword[0])
141
+ return
142
+ }
143
+
144
+ onHideModal()
145
+
146
+ const sendData: UI_I_ChangePasswordBodyRequest = {
147
+ current_password: password.value,
148
+ new_password: newPassword.value,
149
+ }
150
+
151
+ let url = ''
152
+ if (props.project === 'sphere') {
153
+ const { id } = useLocalStorage('userData')
154
+
155
+ url = `ui/users/${id}/passwd`
156
+ } else if (props.project === 'procurator') {
157
+ url = '/ui/passwd'
158
+ }
159
+
160
+ const { error } = await useMyFetch<never, API_UI_I_Error>(url, {
161
+ method: 'POST',
162
+ body: sendData,
163
+ key: Date.now().toString(),
164
+ })
165
+
166
+ if (error.value?.data && error.value.data.error_code !== 0) {
167
+ $store.dispatch('main/A_SHOW_NOTIFICATION', {
168
+ status: 'error',
169
+ headline: localization.value.common.operationFailed,
170
+ messages: [
171
+ {
172
+ title: 'Error',
173
+ descriptions: [error.value.data.error_message],
174
+ },
175
+ ],
176
+ })
177
+ }
178
+ }
179
+
180
+ const showValidationErrors = (text: string): void => {
181
+ isValid.value = true
182
+ errorText.value = text
183
+ }
184
+
185
+ const onHideModal = (): void => {
186
+ emits('hide')
187
+ setForm()
188
+ isValid.value = false
189
+ }
190
+ </script>
191
+
192
+ <style lang="scss" scoped>
193
+ .form-block {
194
+ .form-group {
195
+ &:not(:first-child) input {
196
+ width: 100%;
197
+ }
198
+ &__input {
199
+ display: flex;
200
+ width: 100%;
201
+ }
202
+ }
203
+
204
+ svg {
205
+ width: 24px;
206
+ height: 24px;
207
+ }
208
+ }
209
+ </style>
@@ -62,8 +62,6 @@ watch(
62
62
  ([newValue1, newValue2]: [string, 'never' | 'on']) => {
63
63
  modelFrequencyLocal.value.isValid =
64
64
  newValue2 === 'never' ? false : !!newValue1
65
-
66
- newValue2 === 'never' && (modelFrequencyLocal.value.frg_end_time = '')
67
65
  }
68
66
  )
69
67
  </script>
@@ -62,8 +62,7 @@ const getCorrectRuForm = (value: number | string, type: string): string => {
62
62
  export const validateField = (
63
63
  localization: UI_I_Localization,
64
64
  value: string,
65
- checkZero: boolean = false,
66
- checkDayRange: boolean = false // параметр для проверки диапазона дней
65
+ checkZero: boolean = false
67
66
  ): string => {
68
67
  // Если поле пустое
69
68
  if (!value) {
@@ -75,7 +74,7 @@ export const validateField = (
75
74
  return localization.common.theValueTooSmall
76
75
  }
77
76
 
78
- if (value.length > 3 ) {
77
+ if (value.length > 3) {
79
78
  return localization.common.theValueTooLarge
80
79
  }
81
80
  // Если значение не является цифрой
@@ -83,10 +82,6 @@ export const validateField = (
83
82
  return localization.common.inputContainsInvalidCharacters
84
83
  }
85
84
 
86
- if (checkDayRange && !/^([1-9]|[1-2][0-9]|3[0-1])$/.test(value)) {
87
- return localization.common.theValueTooLarge
88
- }
89
-
90
85
  return ''
91
86
  }
92
87
  export const validateDate = (
@@ -9,11 +9,11 @@
9
9
  v-model="model"
10
10
  />
11
11
 
12
- <div v-if="props.type === 'month'">
12
+ <div v-if="props.type === 'month'" class="">
13
13
  <div class="on-time__radio radio">
14
14
  <input
15
15
  id="on-time-monthly-by-day"
16
- v-model="model.frg_monthly_mode"
16
+ v-model="selectedTimeMode"
17
17
  data-id="on-time-monthly-by-day"
18
18
  type="radio"
19
19
  value="day"
@@ -49,7 +49,7 @@
49
49
  <div class="on-time__radio radio">
50
50
  <input
51
51
  id="on-time-monthly-by-week"
52
- v-model="model.frg_monthly_mode"
52
+ v-model="selectedTimeMode"
53
53
  data-id="on-time-monthly-by-week"
54
54
  type="radio"
55
55
  value="week"
@@ -115,6 +115,8 @@ const model = defineModel<UI_I_ScheduleNewTasksForm>({ required: true })
115
115
 
116
116
  const localization = computed<UI_I_Localization>(() => useLocal())
117
117
 
118
+ const selectedTimeMode = ref<'day' | 'week'>('day')
119
+
118
120
  const frequencyOnWeeksDays = computed<UI_I_SelectInputItem[]>(() => {
119
121
  return frequencyOnWeeksDaysFunc(localization.value)
120
122
  })
@@ -123,7 +125,7 @@ const frequencyOnOrdinalNumber = computed<UI_I_SelectInputItem[]>(() => {
123
125
  })
124
126
 
125
127
  const isDisabledMonthlyDayField = computed<boolean>(
126
- () => model.value.frg_monthly_mode === 'week'
128
+ () => selectedTimeMode.value === 'week'
127
129
  )
128
130
 
129
131
  const isInitTimeIntervalValidation = ref<boolean>(false)
@@ -134,12 +136,7 @@ const schedulerOnDayErrorText = computed<string>(() => {
134
136
  if (!isInitTimeIntervalValidation.value || isDisabledMonthlyDayField.value)
135
137
  return ''
136
138
 
137
- return validateField(
138
- localization.value,
139
- model.value.frg_monthly_day,
140
- true,
141
- true
142
- )
139
+ return validateField(localization.value, model.value.frg_monthly_day, true)
143
140
  })
144
141
  watch(
145
142
  schedulerOnDayErrorText,
@@ -7,31 +7,31 @@ export const frequencyOnWeeksDaysFunc = (
7
7
  return [
8
8
  {
9
9
  label: localization.common.sunday,
10
- value: 6,
10
+ value: 'sunday',
11
11
  },
12
12
  {
13
13
  label: localization.common.monday,
14
- value: 1,
14
+ value: 'monday',
15
15
  },
16
16
  {
17
17
  label: localization.common.tuesday,
18
- value: 2,
18
+ value: 'tuesday',
19
19
  },
20
20
  {
21
21
  label: localization.common.wednesday,
22
- value: 3,
22
+ value: 'wednesday',
23
23
  },
24
24
  {
25
25
  label: localization.common.thursday,
26
- value: 4,
26
+ value: 'thursday',
27
27
  },
28
28
  {
29
29
  label: localization.common.friday,
30
- value: 5,
30
+ value: 'friday',
31
31
  },
32
32
  {
33
33
  label: localization.common.saturday,
34
- value: 0,
34
+ value: 'saturday',
35
35
  },
36
36
  ]
37
37
  }
@@ -42,23 +42,23 @@ export const frequencyOnOrdinalNumberFunc = (
42
42
  return [
43
43
  {
44
44
  label: localization.scheduledTasks.first,
45
- value: 1,
45
+ value: '',
46
46
  },
47
47
  {
48
48
  label: localization.scheduledTasks.second,
49
- value: 2,
49
+ value: 'once',
50
50
  },
51
51
  {
52
52
  label: localization.scheduledTasks.third,
53
- value: 3,
53
+ value: 'after-startup',
54
54
  },
55
55
  {
56
56
  label: localization.scheduledTasks.fourth,
57
- value: 4,
57
+ value: 'hour',
58
58
  },
59
59
  {
60
60
  label: localization.common.last,
61
- value: 5,
61
+ value: 'day',
62
62
  },
63
63
  ]
64
64
  }
@@ -101,7 +101,6 @@ import type { UI_I_SelectInputItem } from '~/components/common/select/input/lib/
101
101
  import type { UI_I_ScheduleNewTasksForm } from '~/components/common/pages/scheduledTasks/modals/lib/models/interfaces'
102
102
  import type { UI_I_InitialValidationFields } from '~/components/common/pages/scheduledTasks/modals/common/newTaskForm/lib/models/interfaces'
103
103
  import type { UI_T_FrequencyType } from '~/components/common/pages/scheduledTasks/modals/common/frequency/lib/models/types'
104
- import * as cron from '~/components/common/pages/scheduledTasks/modals/common/newTaskForm/lib/utils'
105
104
  import { frequencyMethodFunc } from '~/components/common/pages/scheduledTasks/modals/common/frequency/lib/config/frequencyOptions'
106
105
 
107
106
  const props = defineProps<{
@@ -134,6 +133,57 @@ watch(
134
133
  },
135
134
  { deep: true }
136
135
  )
136
+ /* TODO рефакторинг все методы надо рефакторить */
137
+ const generateOnceCronExpression = (date: Date): any => {
138
+ if (!date) return
139
+
140
+ const minutes = date.getMinutes()
141
+ const hours = date.getHours()
142
+ const day = date.getDate()
143
+ const month = date.getMonth() + 1 // В cron месяцы начинаются с 1 (январь = 1)
144
+ const dayOfWeek = '*' // Для одноразовой задачи день недели неважен
145
+
146
+ // Генерируем cron-выражение
147
+ return `${minutes} ${hours} ${day} ${month} ${dayOfWeek} once`
148
+ }
149
+ const generateHourlyCronExpression = (delay: string, date: Date): any => {
150
+ if (!date) return
151
+
152
+ const minutes = date.getMinutes()
153
+ const hours = date.getHours()
154
+
155
+ // Генерируем cron-выражение
156
+ return `${minutes} ${hours}/${delay} * * *`
157
+ }
158
+ const generateDaylyCronExpression = (delay: string, date: Date): string => {
159
+ if (!date) return
160
+
161
+ const minutes = date.getMinutes()
162
+ const hours = date.getHours()
163
+ const day = date.getDate()
164
+
165
+ // Генерируем cron-выражение
166
+ return `${minutes} ${hours} ${day}/${delay} * *`
167
+ }
168
+ const generateWeeklyCronExpression = (
169
+ data: UI_I_ScheduleNewTasksForm
170
+ ): string => {
171
+ const { frg_on_week_days } = data
172
+
173
+ // Генерируем cron-выражение
174
+ return `* * * * ${frg_on_week_days.join(',')}`
175
+ }
176
+ const generateMonthlyCronExpression = (delay: string, date: Date): string => {
177
+ if (!date) return
178
+
179
+ const minutes = date.getMinutes()
180
+ const hours = date.getHours()
181
+ const day = date.getDate()
182
+ const month = date.getMonth() + 1
183
+
184
+ // Генерируем cron-выражение
185
+ return `${minutes} ${hours} ${day} ${month}/${delay} *`
186
+ }
137
187
 
138
188
  const generateCronExpression = (
139
189
  runType: UI_T_FrequencyType,
@@ -144,27 +194,40 @@ const generateCronExpression = (
144
194
  // Генерируем cron-выражение на основе runType
145
195
  switch (runType) {
146
196
  case 'once':
147
- const timestamp = Math.floor(
148
- new Date(interval.frg_on_time).getTime() / 1000
197
+ cronExpression = generateOnceCronExpression(
198
+ new Date(interval.frg_on_time)
149
199
  )
150
- cronExpression = `* * * * * ${timestamp}:0-0-0-0:once`
151
200
  break
152
201
  case 'after-startup':
153
- const suffixDelay =
154
- interval.frg_after_startup === 0 ? '' : `-${interval.frg_after_startup}`
155
- cronExpression = `* * * * * after_procurator_startup${suffixDelay}` // Выполняется после запуска procurator_startup с задержой N минут
202
+ const delay =
203
+ interval.frg_after_startup === 0
204
+ ? '*'
205
+ : `*/${interval.frg_after_startup}`
206
+ cronExpression = `${delay} * * * * after_procurator_startup` // Выполняется каждые N минут после запуска procurator_startup
156
207
  break
157
208
  case 'hour':
158
- cronExpression = cron.generateHourlyCronExpression(interval)
209
+ const hourlyDelay = interval.frg_interval
210
+ cronExpression = generateHourlyCronExpression(
211
+ hourlyDelay,
212
+ new Date(interval.frg_start_on_time)
213
+ )
159
214
  break
160
215
  case 'day':
161
- cronExpression = cron.generateDailyCronExpression(interval)
216
+ const dayDelay = interval.frg_interval
217
+ cronExpression = generateDaylyCronExpression(
218
+ dayDelay,
219
+ new Date(interval.frg_start_on_time)
220
+ )
162
221
  break
163
222
  case 'week':
164
- cronExpression = cron.generateWeeklyCronExpression(interval)
223
+ cronExpression = generateWeeklyCronExpression(interval)
165
224
  break
166
225
  case 'month':
167
- cronExpression = cron.generateMonthlyCronExpression(interval)
226
+ const monthDelay = interval.frg_interval
227
+ cronExpression = generateMonthlyCronExpression(
228
+ monthDelay,
229
+ new Date(interval.frg_start_on_time)
230
+ )
168
231
  break
169
232
  default:
170
233
  cronExpression = '* * * * *'
@@ -11,13 +11,12 @@ export const scheduledTaskDefaultFormFunc = (): UI_I_ScheduleNewTasksForm => {
11
11
  frequency: '',
12
12
  frg_after_startup: 0,
13
13
  frg_interval: 1,
14
- frg_end_time: '',
15
- frg_start_on_time: '',
16
- frg_monthly_mode: 'day',
17
- frg_monthly_day: 1,
14
+ frg_end_time: null,
15
+ frg_start_on_time: null,
16
+ frg_monthly_day: 0,
18
17
  frq_week_day: '',
19
18
  frq_ordinal_number: '',
20
- frg_on_time: '',
19
+ frg_on_time: null,
21
20
  frg_on_week_days: [],
22
21
  }
23
22
  }
@@ -9,13 +9,12 @@ export interface UI_I_ScheduleNewTasksForm {
9
9
  toggle: boolean
10
10
  frg_after_startup: number
11
11
  frg_interval: number
12
- frg_end_time: string
13
- frg_start_on_time: string
14
- frg_monthly_mode: 'day' | 'week'
12
+ frg_end_time: number | null
13
+ frg_start_on_time: number | null
15
14
  frg_monthly_day: number
16
15
  frq_ordinal_number: string
17
16
  frq_week_day: UI_T_FrequencyWeeksDays
18
- frg_on_time: string
17
+ frg_on_time: number | null
19
18
  frg_on_week_days: number[]
20
19
  cron: string
21
20
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.4.310",
4
+ "version": "1.4.311",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",
@@ -1,67 +0,0 @@
1
- import type { UI_I_ScheduleNewTasksForm } from '~/components/common/pages/scheduledTasks/modals/lib/models/interfaces'
2
-
3
- export const generateHourlyCronExpression = (
4
- data: UI_I_ScheduleNewTasksForm
5
- ): string => {
6
- const startTimestamp = Math.floor(
7
- new Date(data.frg_start_on_time).getTime() / 1000
8
- )
9
- const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
10
-
11
- // Генерируем cron-выражение
12
- return endTimestamp
13
- ? `* * * * * ${startTimestamp}-${endTimestamp}:${data.frg_interval}-0-0-0`
14
- : `* * * * * ${startTimestamp}:${data.frg_interval}-0-0-0`
15
- }
16
- export const generateWeeklyCronExpression = (
17
- data: UI_I_ScheduleNewTasksForm
18
- ): string => {
19
- const { frg_on_week_days } = data
20
-
21
- const startTimestamp = Math.floor(
22
- new Date(data.frg_start_on_time).getTime() / 1000
23
- )
24
- const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
25
- const daysOfWeek = frg_on_week_days.join(',')
26
-
27
- return endTimestamp
28
- ? `* * * * ${daysOfWeek} ${startTimestamp}-${endTimestamp}:0-0-0-${data.frg_interval}`
29
- : `* * * * ${daysOfWeek} ${startTimestamp}:0-0-0-${data.frg_interval}`
30
- }
31
-
32
- export const generateDailyCronExpression = (
33
- data: UI_I_ScheduleNewTasksForm
34
- ): string => {
35
- const startTimestamp = Math.floor(
36
- new Date(data.frg_start_on_time).getTime() / 1000
37
- )
38
- const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
39
-
40
- // Генерируем cron-выражение
41
- return endTimestamp
42
- ? `* * * * * ${startTimestamp}-${endTimestamp}:0-${data.frg_interval}-0-0`
43
- : `* * * * * ${startTimestamp}:0-${data.frg_interval}-0-0`
44
- }
45
-
46
- export const generateMonthlyCronExpression = (
47
- data: UI_I_ScheduleNewTasksForm
48
- ): string => {
49
- const { frg_interval, frg_monthly_day, frq_week_day, frq_ordinal_number } =
50
- data
51
-
52
- const startTimestamp = Math.floor(
53
- new Date(data.frg_start_on_time).getTime() / 1000
54
- )
55
- const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
56
-
57
- const daysOfWeek = `${frq_week_day}#${frq_ordinal_number}`
58
-
59
- const timestamp = endTimestamp
60
- ? `${startTimestamp}-${endTimestamp}`
61
- : startTimestamp
62
-
63
- // Генерируем cron-выражение
64
- return data.frg_monthly_mode === 'week'
65
- ? `* * * * * ${timestamp}:0-0-${frg_interval}-${daysOfWeek}`
66
- : `* * ${frg_monthly_day} */${frg_interval} * ${timestamp}:0-0-0-0`
67
- }