bfg-common 1.3.33 → 1.3.34
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/lib/models/interfaces.ts +7 -18
- package/lib/models/table/interfaces.ts +28 -0
- package/lib/models/table/types.ts +1 -0
- package/lib/models/types.ts +0 -2
- package/package.json +1 -1
- package/store/main/lib/interfaces.ts +9 -0
- package/store/tasks/actions.ts +133 -0
- package/store/tasks/getters.ts +25 -0
- package/store/tasks/lib/models/interfaces.ts +18 -0
- package/store/tasks/mappers/recentTasks.ts +43 -0
- package/store/tasks/mappers/tasks.ts +45 -0
- package/store/tasks/mutations.ts +58 -0
- package/store/tasks/state.ts +16 -0
- package/store/tasks/store.ts +12 -0
package/lib/models/interfaces.ts
CHANGED
|
@@ -8,28 +8,11 @@ export interface UI_I_HTMLSelectElement extends Event {
|
|
|
8
8
|
target: HTMLInputElement
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export interface UI_I_Localization {
|
|
12
|
-
[key: string]: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
11
|
export interface UI_I_ArbitraryObject<T> {
|
|
16
12
|
[key: string]: T
|
|
17
13
|
}
|
|
18
14
|
|
|
19
|
-
export interface
|
|
20
|
-
total_items: number
|
|
21
|
-
total_pages: number
|
|
22
|
-
items: T
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface UI_I_Pagination {
|
|
26
|
-
page: number
|
|
27
|
-
pageSize: number
|
|
28
|
-
}
|
|
29
|
-
export interface UI_I_DataTableQuery extends UI_I_Pagination {
|
|
30
|
-
sortBy?: string
|
|
31
|
-
filter?: string
|
|
32
|
-
}
|
|
15
|
+
export interface UI_I_Localization extends UI_I_ArbitraryObject<string> {}
|
|
33
16
|
|
|
34
17
|
export interface UI_I_SendTaskParams {
|
|
35
18
|
method: string
|
|
@@ -41,6 +24,12 @@ export interface UI_I_NotifyBodyMessage {
|
|
|
41
24
|
title: string
|
|
42
25
|
desc: string
|
|
43
26
|
}
|
|
27
|
+
|
|
28
|
+
export interface API_UI_I_Response<T> {
|
|
29
|
+
response: {
|
|
30
|
+
_data: T
|
|
31
|
+
}
|
|
32
|
+
}
|
|
44
33
|
export interface UI_I_RequestBody {
|
|
45
34
|
method: string
|
|
46
35
|
params: {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { UI_T_Schema } from '~/lib/models/table/types'
|
|
2
|
+
|
|
3
|
+
export interface API_UI_I_DataTable<T> {
|
|
4
|
+
total_items: number
|
|
5
|
+
total_pages: number
|
|
6
|
+
items: T
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface UI_I_TableQuery {
|
|
10
|
+
page: number
|
|
11
|
+
page_size: number
|
|
12
|
+
sortBy?: string
|
|
13
|
+
filter?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface UI_I_TableQueryWidthSchema extends UI_I_TableQuery {
|
|
17
|
+
schema: UI_T_Schema
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface UI_I_Pagination {
|
|
21
|
+
page: number
|
|
22
|
+
pageSize: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface UI_I_DataTableQuery extends UI_I_Pagination {
|
|
26
|
+
sortBy?: string
|
|
27
|
+
filter?: string
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type UI_T_Schema = 'short' | 'ui' | 'full'
|
package/lib/models/types.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export type UI_T_Project = 'sphere' | 'procurator'
|
|
2
2
|
|
|
3
|
-
export type UI_T_Schema = 'short' | 'ui' | 'full'
|
|
4
|
-
|
|
5
3
|
export type UI_T_Binary = 'KB' | 'MB' | 'GB' | 'TB' | 'PB' | 'EB' | 'ZB' | 'YB'
|
|
6
4
|
export type UI_T_BinaryLower = 'kb' | 'mb' | 'gb' | 'tb' | 'pb' | 'eb' | 'zb' | 'yb'
|
|
7
5
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
API_UI_I_Error,
|
|
3
|
+
UI_I_CommitOptions,
|
|
4
|
+
} from '~/lib/models/store/interfaces'
|
|
5
|
+
import type {
|
|
6
|
+
UI_I_DataTableQuery,
|
|
7
|
+
UI_I_TableQuery,
|
|
8
|
+
} from '~/lib/models/table/interfaces'
|
|
9
|
+
import type { UI_I_Options } from '~/lib/models/composables/useMyFetch/interfaces'
|
|
10
|
+
import type {
|
|
11
|
+
API_UI_I_RecentTask,
|
|
12
|
+
UI_I_RTaskQuery,
|
|
13
|
+
UI_I_TasksLoadingPayload,
|
|
14
|
+
UI_I_RawRecentTask,
|
|
15
|
+
UI_I_RecentTask,
|
|
16
|
+
API_UI_I_Task,
|
|
17
|
+
} from '~/lib/models/store/tasks/interfaces'
|
|
18
|
+
import type { UI_I_TasksState } from '~/store/tasks/lib/models/interfaces'
|
|
19
|
+
import type { API_UI_I_Response } from '~/lib/models/interfaces'
|
|
20
|
+
import type { UI_I_RefreshStack } from '~/store/main/lib/interfaces'
|
|
21
|
+
import { tasksConstructor } from '~/store/tasks/mappers/tasks'
|
|
22
|
+
import { recentTasks } from '~/store/tasks/mappers/recentTasks'
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
async A_GET_TASKS(
|
|
26
|
+
context: {
|
|
27
|
+
commit: <T>(arg0: string, arg1: T) => void
|
|
28
|
+
state: UI_I_TasksState
|
|
29
|
+
dispatch: <T>(arg0: string, arg1: T, arg2: UI_I_CommitOptions) => void
|
|
30
|
+
},
|
|
31
|
+
payload: UI_I_DataTableQuery
|
|
32
|
+
): Promise<API_UI_I_Error | void> {
|
|
33
|
+
const { page, pageSize, sortBy } = payload
|
|
34
|
+
|
|
35
|
+
const query: UI_I_TableQuery = {
|
|
36
|
+
page_size: pageSize,
|
|
37
|
+
page,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (sortBy) query.sortBy = sortBy
|
|
41
|
+
|
|
42
|
+
const queryJson: string = JSON.stringify({ type: 'tasks', ...query })
|
|
43
|
+
const lastQuery: string = context.state.taskQuery || ''
|
|
44
|
+
|
|
45
|
+
if (queryJson === lastQuery) {
|
|
46
|
+
// Снимаем с паузы сам запрос, для глобального обновления
|
|
47
|
+
context.dispatch<string>('main/A_CONTINUE_GLOBAL_REFRESH', queryJson, {
|
|
48
|
+
root: true,
|
|
49
|
+
})
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
context.commit('M_SET_TASKS_LAST_QUERY', queryJson)
|
|
53
|
+
|
|
54
|
+
const url = '/ui/tasks'
|
|
55
|
+
const options: UI_I_Options = {
|
|
56
|
+
query,
|
|
57
|
+
method: 'GET',
|
|
58
|
+
key: Date.now().toString(),
|
|
59
|
+
onRequest() {
|
|
60
|
+
context.commit<UI_I_TasksLoadingPayload>('M_SET_LOADING', {
|
|
61
|
+
prop: 'tasks',
|
|
62
|
+
value: true,
|
|
63
|
+
})
|
|
64
|
+
},
|
|
65
|
+
onResponse({ response }: API_UI_I_Response<API_UI_I_Task<string>>) {
|
|
66
|
+
const tasks = tasksConstructor(response._data)
|
|
67
|
+
|
|
68
|
+
context.commit('M_SET_TASKS_LIST', tasks)
|
|
69
|
+
context.commit<UI_I_TasksLoadingPayload>('M_SET_LOADING', {
|
|
70
|
+
prop: 'tasks',
|
|
71
|
+
value: false,
|
|
72
|
+
})
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
const { error } = await useMyFetch<API_UI_I_Task<string>, API_UI_I_Error>(
|
|
76
|
+
url,
|
|
77
|
+
options
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
if (error.value?.data?.error_code)
|
|
81
|
+
throw new Error(error.value.data.error_message)
|
|
82
|
+
|
|
83
|
+
context.dispatch<UI_I_RefreshStack>(
|
|
84
|
+
'main/A_ADD_IN_GLOBAL_REFRESH',
|
|
85
|
+
{ key: queryJson, url, options },
|
|
86
|
+
{ root: true }
|
|
87
|
+
)
|
|
88
|
+
},
|
|
89
|
+
async A_GET_RECENT_TASKS(
|
|
90
|
+
context: {
|
|
91
|
+
commit: <T>(arg0: string, arg1: T) => void
|
|
92
|
+
state: UI_I_TasksState
|
|
93
|
+
},
|
|
94
|
+
payload: string
|
|
95
|
+
): Promise<void> {
|
|
96
|
+
const query: UI_I_RTaskQuery = {
|
|
97
|
+
last: context.state.recentTaskList?.last || 0,
|
|
98
|
+
}
|
|
99
|
+
if (payload) query.sortBy = payload
|
|
100
|
+
|
|
101
|
+
const { data, error } = await useMyFetch<
|
|
102
|
+
API_UI_I_RecentTask<string>,
|
|
103
|
+
API_UI_I_Error
|
|
104
|
+
>('/ui/rtasks', {
|
|
105
|
+
query,
|
|
106
|
+
method: 'GET',
|
|
107
|
+
initialCache: false,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
if (error.value?.data?.error_code)
|
|
111
|
+
throw new Error(error.value.data.error_message)
|
|
112
|
+
|
|
113
|
+
context.commit<UI_I_RecentTask<string>>(
|
|
114
|
+
'M_SET_RECENT_TASKS_LIST',
|
|
115
|
+
recentTasks(data.value)
|
|
116
|
+
)
|
|
117
|
+
context.commit<UI_I_RawRecentTask<string>>(
|
|
118
|
+
'M_SET_UPDATED_RECENT_TASKS_LIST',
|
|
119
|
+
data.value
|
|
120
|
+
)
|
|
121
|
+
// context.commit<I_TasksLoadingPayload>('M_SET_LOADING', {
|
|
122
|
+
// prop: 'recentTasks',
|
|
123
|
+
// value: false,
|
|
124
|
+
// })
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
// Вызывается в useMyFetch когда получаем первый ответ от запроса с url tasks
|
|
128
|
+
// и default.vue когда срабатывает watch на recentTasks
|
|
129
|
+
// Нужно для того чтобы не обрабатывали те таски которые были сделаны перед загрузкой страницы
|
|
130
|
+
A_SET_FIRST_TASK(context: { commit: (arg0: string) => void }): void {
|
|
131
|
+
context.commit('M_SET_FIRST_TASK')
|
|
132
|
+
},
|
|
133
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { UI_T_TasksStateLoading } from '~/lib/models/store/tasks/types'
|
|
2
|
+
import type {
|
|
3
|
+
UI_I_RawRecentTaskItem,
|
|
4
|
+
UI_I_RecentTask,
|
|
5
|
+
UI_I_Task,
|
|
6
|
+
} from '~/lib/models/store/tasks/interfaces'
|
|
7
|
+
import type { UI_I_TasksState } from '~/store/tasks/lib/models/interfaces'
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
getFirstTask: (state: UI_I_TasksState): boolean => state.hasFirstTask,
|
|
11
|
+
getTaskList: (state: UI_I_TasksState): UI_I_Task<string> | null =>
|
|
12
|
+
state.taskList,
|
|
13
|
+
getTasksLastRequestType: (state: UI_I_TasksState): string | null =>
|
|
14
|
+
state.taskLastRequestType,
|
|
15
|
+
getRecentTaskList: (
|
|
16
|
+
state: UI_I_TasksState
|
|
17
|
+
): UI_I_RecentTask<string> | null => state.recentTaskList,
|
|
18
|
+
getUpdatedRecentTasks: (
|
|
19
|
+
state: UI_I_TasksState
|
|
20
|
+
): UI_I_RawRecentTaskItem<string>[] | null => state.updatedTaskList,
|
|
21
|
+
getLoading:
|
|
22
|
+
(state: UI_I_TasksState) =>
|
|
23
|
+
(type: UI_T_TasksStateLoading): boolean =>
|
|
24
|
+
state.loading[type],
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
UI_I_Task,
|
|
3
|
+
UI_I_RecentTask,
|
|
4
|
+
UI_I_RawRecentTaskItem,
|
|
5
|
+
} from '~/lib/models/store/tasks/interfaces'
|
|
6
|
+
|
|
7
|
+
export interface UI_I_TasksState {
|
|
8
|
+
hasFirstTask: boolean
|
|
9
|
+
taskList: UI_I_Task<string> | null
|
|
10
|
+
taskLastRequestType: string
|
|
11
|
+
taskQuery: string
|
|
12
|
+
recentTaskList: UI_I_RecentTask<string> | null
|
|
13
|
+
updatedTaskList: UI_I_RawRecentTaskItem<string>[] | null
|
|
14
|
+
loading: {
|
|
15
|
+
tasks: boolean
|
|
16
|
+
recentTasks: boolean
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UI_E_RecentTaskStatus,
|
|
3
|
+
UI_E_IconNameByRecentTaskStatus,
|
|
4
|
+
} from '~/lib/models/store/tasks/enums'
|
|
5
|
+
import type {
|
|
6
|
+
API_UI_I_RecentTask,
|
|
7
|
+
UI_I_RecentTask,
|
|
8
|
+
} from '~/lib/models/store/tasks/interfaces'
|
|
9
|
+
|
|
10
|
+
export const recentTasks = (
|
|
11
|
+
data: API_UI_I_RecentTask<string>
|
|
12
|
+
): UI_I_RecentTask<string> => {
|
|
13
|
+
const items =
|
|
14
|
+
data.items
|
|
15
|
+
?.sort((a, b) => {
|
|
16
|
+
return b.start_time - a.start_time
|
|
17
|
+
})
|
|
18
|
+
.map((task) => {
|
|
19
|
+
return {
|
|
20
|
+
completion: task.completion + '' || '-',
|
|
21
|
+
queuedFor: task.creation_time - task.start_time,
|
|
22
|
+
execution: Math.abs(task.start_time - task.completion),
|
|
23
|
+
details: task.details,
|
|
24
|
+
error: task.error,
|
|
25
|
+
initiator: task.initiator,
|
|
26
|
+
server: task.server,
|
|
27
|
+
startTime: task.start_time + '' || '-',
|
|
28
|
+
statusIcon: UI_E_IconNameByRecentTaskStatus[task.status],
|
|
29
|
+
statusText: task.error || UI_E_RecentTaskStatus[task.status],
|
|
30
|
+
status: task.status,
|
|
31
|
+
target: task.target,
|
|
32
|
+
targetType: task.target_type,
|
|
33
|
+
taskName: task.task_name,
|
|
34
|
+
id: task.id,
|
|
35
|
+
zone: task.zone,
|
|
36
|
+
extra: task.extra,
|
|
37
|
+
}
|
|
38
|
+
}) || []
|
|
39
|
+
return {
|
|
40
|
+
items,
|
|
41
|
+
last: data.last,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { UI_I_Localization } from '~/lib/models/interfaces'
|
|
2
|
+
import type {
|
|
3
|
+
API_UI_I_Task,
|
|
4
|
+
UI_I_TaskItem,
|
|
5
|
+
UI_I_Task,
|
|
6
|
+
API_UI_I_TaskItem,
|
|
7
|
+
} from '~/lib/models/store/tasks/interfaces'
|
|
8
|
+
import {
|
|
9
|
+
UI_E_TaskStatus,
|
|
10
|
+
UI_E_IconNameByTaskStatus,
|
|
11
|
+
} from '~/lib/models/store/tasks/enums'
|
|
12
|
+
|
|
13
|
+
export const tasksConstructor = (
|
|
14
|
+
data: API_UI_I_Task<string>
|
|
15
|
+
): UI_I_Task<string> => {
|
|
16
|
+
const localization: UI_I_Localization = useLocal()
|
|
17
|
+
|
|
18
|
+
const items: UI_I_TaskItem<string>[] =
|
|
19
|
+
data.items?.map((task: API_UI_I_TaskItem<string>) => {
|
|
20
|
+
return {
|
|
21
|
+
// relatedEvents: task?.RelatedEvents || '',
|
|
22
|
+
relatedEvents: '',
|
|
23
|
+
completion: task.completion || '-',
|
|
24
|
+
queuedFor: task.creation_time - task.start_time,
|
|
25
|
+
execution: Math.abs(task.start_time - task.completion),
|
|
26
|
+
details: task.details,
|
|
27
|
+
error: task.error,
|
|
28
|
+
initiator: task.initiator,
|
|
29
|
+
server: task.server,
|
|
30
|
+
startTime: task.start_time || '-',
|
|
31
|
+
statusIcon: UI_E_IconNameByTaskStatus[task.status],
|
|
32
|
+
statusText: task.error || localization[UI_E_TaskStatus[task.status]],
|
|
33
|
+
status: task.status,
|
|
34
|
+
target: task.target,
|
|
35
|
+
targetType: task.target_type,
|
|
36
|
+
taskName: task.task_name,
|
|
37
|
+
id: task.id,
|
|
38
|
+
zone: task.zone,
|
|
39
|
+
}
|
|
40
|
+
}) || []
|
|
41
|
+
return {
|
|
42
|
+
...data,
|
|
43
|
+
items,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
UI_I_RawRecentTask,
|
|
3
|
+
UI_I_TasksLoadingPayload,
|
|
4
|
+
UI_I_RecentTask,
|
|
5
|
+
UI_I_Task,
|
|
6
|
+
} from '~/lib/models/store/tasks/interfaces'
|
|
7
|
+
import type { UI_I_TasksState } from '~/store/tasks/lib/models/interfaces'
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
M_SET_RECENT_TASKS_LIST(
|
|
11
|
+
state: UI_I_TasksState,
|
|
12
|
+
payload: UI_I_RecentTask<string>
|
|
13
|
+
): void {
|
|
14
|
+
if (state.recentTaskList) {
|
|
15
|
+
state.recentTaskList.last = payload.last
|
|
16
|
+
|
|
17
|
+
// Заменяем которые уже имеются и удаляем их из payload.items
|
|
18
|
+
state.recentTaskList.items = state.recentTaskList.items.map((task) => {
|
|
19
|
+
let changedTask = null
|
|
20
|
+
payload.items = payload.items.filter((task2) => {
|
|
21
|
+
if (task2.id === task.id) changedTask = task2
|
|
22
|
+
return task2.id !== task.id
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return changedTask || task
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// Делаем слияние новых и старых tasks
|
|
29
|
+
state.recentTaskList.items = [
|
|
30
|
+
...payload.items,
|
|
31
|
+
...state.recentTaskList.items,
|
|
32
|
+
]
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
state.recentTaskList = payload
|
|
37
|
+
},
|
|
38
|
+
M_SET_TASKS_LAST_QUERY(state: UI_I_TasksState, payload: string): void {
|
|
39
|
+
state.taskLastRequestType = payload
|
|
40
|
+
},
|
|
41
|
+
M_SET_TASKS_LIST(state: UI_I_TasksState, payload: UI_I_Task<string>): void {
|
|
42
|
+
state.taskList = payload
|
|
43
|
+
},
|
|
44
|
+
M_SET_UPDATED_RECENT_TASKS_LIST(
|
|
45
|
+
state: UI_I_TasksState,
|
|
46
|
+
payload: UI_I_RawRecentTask<string>
|
|
47
|
+
): void {
|
|
48
|
+
state.updatedTaskList = payload.items
|
|
49
|
+
},
|
|
50
|
+
M_SET_FIRST_TASK(state: UI_I_TasksState): void {
|
|
51
|
+
state.hasFirstTask = true
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
M_SET_LOADING(state: UI_I_TasksState, payload: UI_I_TasksLoadingPayload): void {
|
|
55
|
+
const { prop, value } = payload
|
|
56
|
+
state.loading[prop] = value
|
|
57
|
+
},
|
|
58
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { UI_I_TasksState } from '~/store/tasks/lib/models/interfaces'
|
|
2
|
+
|
|
3
|
+
const state: UI_I_TasksState = {
|
|
4
|
+
hasFirstTask: false,
|
|
5
|
+
recentTaskList: null,
|
|
6
|
+
updatedTaskList: null,
|
|
7
|
+
taskLastRequestType: '',
|
|
8
|
+
taskQuery: '',
|
|
9
|
+
taskList: null,
|
|
10
|
+
loading: {
|
|
11
|
+
tasks: false,
|
|
12
|
+
recentTasks: false,
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default state
|