This repository has been archived by the owner on Jul 12, 2019. It is now read-only.
/
DeploymentConfigStore.js
211 lines (173 loc) · 4.83 KB
/
DeploymentConfigStore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import { observable, action, computed } from "mobx";
import { axios, store, stores } from "choerodon-front-boot";
import _ from 'lodash';
import { handleProptError } from "../../../utils/index";
const HEIGHT =
window.innerHeight ||
document.documentElement.clientHeight ||
document.body.clientHeight;
@store("DeploymentConfigStore")
class DeploymentConfigStore {
@observable configList = [];
@observable singleConfig = {};
@observable loading = false;
@observable appData = [];
@observable envData = [];
@observable value = null;
@observable valueLoading = false;
@observable pageInfo = {
current: 1,
total: 0,
pageSize: HEIGHT <= 900 ? 10 : 15,
};
@observable Info = {
filters: {},
sort: { columnKey: "id", order: "descend" },
paras: [],
};
@action setPageInfo(page) {
this.pageInfo.current = page.number + 1;
this.pageInfo.total = page.totalElements;
this.pageInfo.pageSize = page.size;
}
@computed get getPageInfo() {
return this.pageInfo;
}
@computed get getConfigList() {
return this.configList.slice();
}
@action setConfigList(data) {
this.configList = data;
}
@computed get getSingleConfig() {
return this.singleConfig;
}
@action setSingleConfig(data) {
this.singleConfig = data;
}
@action changeLoading(flag) {
this.loading = flag;
}
@computed get getLoading() {
return this.loading;
}
@action setInfo(Info) {
this.Info = Info;
}
@computed get getInfo() {
return this.Info;
}
@action setValue(data) {
this.value = data;
}
@computed get getValue() {
return this.value;
}
@action setEnvData(data) {
this.envData = data;
}
@computed get getEnvData() {
return this.envData;
}
@action setAppDate(data) {
this.appData = data;
}
@computed get getAppData() {
return this.appData;
}
@action changeValueLoading(flag) {
this.valueLoading = flag;
}
@computed get getValueLoading() {
return this.valueLoading;
}
/**
** 查询部署配置列表
*/
loadAllData = (
projectId,
page = this.pageInfo.current - 1,
size = this.pageInfo.pageSize,
sort = { field: "id", order: "desc" },
postData = {
searchParam: {},
param: "",
}
) => {
this.changeLoading(true);
return axios.post(`/devops/v1/projects/${projectId}/pipeline_value/list_by_options?page=${page}&size=${size}&sort=${sort.field || 'id'},${sort.order}`, JSON.stringify(postData))
.then(data => {
const res = handleProptError(data);
if (res) {
const {content, totalElements, number, size} = res;
this.setPageInfo({number, totalElements, size});
this.setConfigList(content);
}
this.changeLoading(false);
});
};
/**
** 查询所有应用
* @param projectId
*/
loadAppData = projectId =>
axios.post(`/devops/v1/projects/${projectId}/apps/list_by_options?active=true&type=normal&doPage=false&has_version=true`
, JSON.stringify({searchParam: {}, param: ""})
)
.then((data) => {
const res = handleProptError(data);
if (res) {
this.setAppDate(data.content);
}
return res;
});
/**
** 查询所有环境
*/
loadEnvData = projectId =>
axios.get(`/devops/v1/projects/${projectId}/envs?active=true`)
.then((data) => {
const res = handleProptError(data);
if (res) {
const newData = _.sortBy(res, item => [-item.connect, -item.permission]);
this.setEnvData(newData);
}
return res;
});
/**
** 查询配置信息
*/
loadValue = (projectId, appId) => {
this.changeValueLoading(true);
return axios.get(`/devops/v1/projects/${projectId}/app_versions/value?app_id=${appId}`)
.then(data => {
const res = handleProptError(data);
if (res) {
this.setValue(res);
}
this.changeValueLoading(false);
});
};
/**
** 查询单个部署配置
*/
loadDataById = (projectId, id) =>
axios.get(`/devops/v1/projects/${projectId}/pipeline_value?value_id=${id}`)
.then(data => {
const res = handleProptError(data);
if (res) {
this.setSingleConfig(data);
}
return res;
});
createData = (projectId, data) =>
axios.post(`/devops/v1/projects/${projectId}/pipeline_value`, JSON.stringify(data));
deleteData = (projectId, id) =>
axios.delete(`/devops/v1/projects/${projectId}/pipeline_value?value_id=${id}`);
checkName = (projectId, name) =>
axios.get(`/devops/v1/projects/${projectId}/pipeline_value/check_name?name=${name}`);
checkDelete = (projectId, id) =>
axios.get(`/devops/v1/projects/${projectId}/pipeline_value/check_delete?value_id=${id}`);
}
const deploymentConfigStore = new DeploymentConfigStore();
export default deploymentConfigStore;