This commit is contained in:
赵禹光 2019-07-12 23:38:35 +08:00
parent 1915e9c087
commit 7d0aebccbc
7 changed files with 64 additions and 40 deletions

View File

@ -82,6 +82,7 @@ const I18N_CONF = {
pubNoData: 'No results found.',
columnServiceName: 'Service Name',
groupName: 'Group Name',
groupNamePlaceholder: 'Enter Group Name',
columnClusterCount: 'Cluster Count',
columnIpCount: 'Instance Count',
columnHealthyInstanceCount: 'Healthy Instance Count',

View File

@ -81,7 +81,8 @@ const I18N_CONF = {
query: '查询',
pubNoData: '没有数据',
columnServiceName: '服务名',
groupName: '分组',
groupName: '分组名称',
groupNamePlaceholder: '请输入分组名称',
columnClusterCount: '集群数目',
columnIpCount: '实例数',
columnHealthyInstanceCount: '健康实例数',

View File

@ -55,8 +55,11 @@ class ServiceList extends React.Component {
total: 0,
pageSize: 10,
currentPage: 1,
keyword: '',
dataSource: [],
search: {
serviceName: '',
groupName: '',
},
};
this.field = new Field(this);
}
@ -71,19 +74,18 @@ class ServiceList extends React.Component {
openEditServiceDialog() {
try {
this.editServiceDialog.current.getInstance()
.show(this.state.service);
} catch (error) {
}
this.editServiceDialog.current.getInstance().show(this.state.service);
} catch (error) {}
}
queryServiceList() {
const { currentPage, pageSize, keyword, withInstances = false } = this.state;
const { currentPage, pageSize, search, withInstances = false } = this.state;
const parameter = [
`withInstances=${withInstances}`,
`pageNo=${currentPage}`,
`pageSize=${pageSize}`,
`keyword=${keyword}`,
`serviceName=${search.serviceName}`,
`groupName=${search.groupName}`,
];
request({
url: `v1/ns/catalog/services?${parameter.join('&')}`,
@ -119,8 +121,7 @@ class ServiceList extends React.Component {
*
*/
showSampleCode(record) {
this.showcode.current.getInstance()
.openDialog(record);
this.showcode.current.getInstance().openDialog(record);
}
deleteService(service) {
@ -157,7 +158,6 @@ class ServiceList extends React.Component {
rowColor = row => ({ className: !row.healthyInstanceCount ? 'row-bg-red' : '' });
render() {
const { locale = {} } = this.props;
const {
@ -165,6 +165,8 @@ class ServiceList extends React.Component {
serviceList,
serviceName,
serviceNamePlaceholder,
groupName,
groupNamePlaceholder,
query,
create,
operation,
@ -172,7 +174,7 @@ class ServiceList extends React.Component {
sampleCode,
deleteAction,
} = locale;
const { keyword, nowNamespaceName, nowNamespaceId } = this.state;
const { search, nowNamespaceName, nowNamespaceId } = this.state;
const { init, getValue } = this.field;
this.init = init;
this.getValue = getValue;
@ -214,8 +216,19 @@ class ServiceList extends React.Component {
<Input
placeholder={serviceNamePlaceholder}
style={{ width: 200 }}
value={keyword}
onChange={keyword => this.setState({ keyword })}
value={search.serviceName}
onChange={serviceName => this.setState({ search: { ...search, serviceName } })}
onPressEnter={() =>
this.setState({ currentPage: 1 }, () => this.queryServiceList())
}
/>
</FormItem>
<FormItem label={groupName}>
<Input
placeholder={groupNamePlaceholder}
style={{ width: 200 }}
value={search.groupName}
onChange={groupName => this.setState({ search: { ...search, groupName } })}
onPressEnter={() =>
this.setState({ currentPage: 1 }, () => this.queryServiceList())
}
@ -266,8 +279,9 @@ class ServiceList extends React.Component {
<a
onClick={() =>
this.props.history.push(
`/serviceDetail?name=${record.name}&groupName=${record.groupName}`,
)}
`/serviceDetail?name=${record.name}&groupName=${record.groupName}`
)
}
style={{ marginRight: 5 }}
>
{detail}
@ -277,10 +291,7 @@ class ServiceList extends React.Component {
{sampleCode}
</a>
<span style={{ marginRight: 5 }}>|</span>
<a
onClick={() => this.deleteService(record)}
style={{ marginRight: 5 }}
>
<a onClick={() => this.deleteService(record)} style={{ marginRight: 5 }}>
{deleteAction}
</a>
</div>
@ -290,10 +301,11 @@ class ServiceList extends React.Component {
</Col>
</Row>
{this.state.total > this.state.pageSize && (
<div style={{
marginTop: 10,
textAlign: 'right',
}}
<div
style={{
marginTop: 10,
textAlign: 'right',
}}
>
<Pagination
current={this.state.currentPage}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -150,10 +150,11 @@ public class CatalogController {
List<ServiceDetailInfo> serviceDetailInfoList = new ArrayList<>();
int pageNo = Integer.parseInt(WebUtils.required(request, "pageNo"));
int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize"));
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
String serviceName = WebUtils.optional(request, "serviceName", StringUtils.EMPTY);
String groupName = WebUtils.optional(request, "groupName", StringUtils.EMPTY);
List<Service> serviceList = new ArrayList<>(8);
serviceManager.getPagedService(namespaceId, pageNo, pageSize, keyword, StringUtils.EMPTY, serviceList);
serviceManager.getPagedService(namespaceId, pageNo, pageSize, serviceName, groupName, StringUtils.EMPTY, serviceList);
for (Service service : serviceList) {
ServiceDetailInfo serviceDetailInfo = new ServiceDetailInfo();
@ -257,11 +258,12 @@ public class CatalogController {
int page = Integer.parseInt(WebUtils.required(request, "pageNo"));
int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize"));
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
String serviceName = WebUtils.optional(request, "serviceName", StringUtils.EMPTY);
String groupName = WebUtils.optional(request, "groupName", StringUtils.EMPTY);
String containedInstance = WebUtils.optional(request, "instance", StringUtils.EMPTY);
List<Service> services = new ArrayList<>();
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, keyword, containedInstance, services);
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, serviceName, groupName, containedInstance, services);
if (CollectionUtils.isEmpty(services)) {
result.put("serviceList", Collections.emptyList());

View File

@ -599,13 +599,21 @@ public class ServiceManager implements RecordListener<Service> {
}
public List<Service> searchServices(String namespaceId, String regex) {
return searchServices(namespaceId, regex, null);
}
public List<Service> searchServices(String namespaceId, String regex, String groupName) {
List<Service> result = new ArrayList<>();
for (Map.Entry<String, Service> entry : chooseServiceMap(namespaceId).entrySet()) {
Service service = entry.getValue();
String key = service.getName() + ":" + ArrayUtils.toString(service.getOwners());
if (key.matches(regex)) {
result.add(service);
if(StringUtils.isNotEmpty(groupName)&&!groupName.equals(service.getGroupName())){
continue;
}
String key = service.getName() + ":" + ArrayUtils.toString(service.getOwners());
if(StringUtils.isNotEmpty(regex)&&!key.matches(regex)){
continue;
}
result.add(service);
}
return result;
@ -633,7 +641,7 @@ public class ServiceManager implements RecordListener<Service> {
return serviceMap.get(namespaceId);
}
public int getPagedService(String namespaceId, int startPage, int pageSize, String keyword, String containedInstance, List<Service> serviceList) {
public int getPagedService(String namespaceId, int startPage, int pageSize, String serviceName, String groupName, String containedInstance, List<Service> serviceList) {
List<Service> matchList;
@ -641,8 +649,8 @@ public class ServiceManager implements RecordListener<Service> {
return 0;
}
if (StringUtils.isNotBlank(keyword)) {
matchList = searchServices(namespaceId, ".*" + keyword + ".*");
if (StringUtils.isNotBlank(serviceName) || StringUtils.isNotBlank(groupName)) {
matchList = searchServices(namespaceId, StringUtils.isNotBlank(serviceName) ? ".*" + serviceName + ".*" : null, groupName);
} else {
matchList = new ArrayList<>(chooseServiceMap(namespaceId).values());
}