history ing

This commit is contained in:
insanity 2017-08-25 19:38:50 +09:00
parent c1d084314b
commit d2d35b91ea
4 changed files with 61 additions and 29 deletions

View File

@ -0,0 +1,8 @@
interface PageParams {
pageNo: string;
countPerPage: string;
sortCol: string;
sortDirection: string;
}
export default PageParams;

View File

@ -17,8 +17,6 @@ export interface State {
export class Pager extends React.Component<Props, State> { export class Pager extends React.Component<Props, State> {
private countPerPage: number = 10;
constructor(props: Props, context: State) { constructor(props: Props, context: State) {
super(props, context); super(props, context);
this.state = { this.state = {

View File

@ -14,6 +14,8 @@ import * as readAllByProbeActions from '../redux/action/read_all_by_probe';
import * as readAllByProbeAndTypeActions from '../redux/action/read_all_by_probe_and_type'; import * as readAllByProbeAndTypeActions from '../redux/action/read_all_by_probe_and_type';
import * as probeListActions from '@overflow/probe/redux/action/read_all_by_domain'; import * as probeListActions from '@overflow/probe/redux/action/read_all_by_domain';
import * as historyTypeListActions from '@overflow/meta/redux/action/history_type_read_all'; import * as historyTypeListActions from '@overflow/meta/redux/action/history_type_read_all';
import PageParams from '@overflow/commons/api/model/PageParams';
export function mapStateToProps(state: any, ownProps?: any): HistoryStateProps { export function mapStateToProps(state: any, ownProps?: any): HistoryStateProps {
return { return {
@ -26,21 +28,21 @@ export function mapStateToProps(state: any, ownProps?: any): HistoryStateProps {
export function mapDispatchToProps(dispatch: Dispatch<HistoryDispatchProps>, ownProps?: HistoryDispatchProps): HistoryDispatchProps { export function mapDispatchToProps(dispatch: Dispatch<HistoryDispatchProps>, ownProps?: HistoryDispatchProps): HistoryDispatchProps {
return { return {
onReadAllByDomain: (domain: Domain, pageNo: string, countPerPage: string) => { onReadAllByDomain: (domain: Domain, pageParams: PageParams) => {
dispatch(asyncRequestActions.request('HistoryService', 'readAllByDomain', readAllByProbeActions.REQUEST, dispatch(asyncRequestActions.request('HistoryService', 'readAllByDomain', readAllByProbeActions.REQUEST,
JSON.stringify(domain), pageNo, countPerPage)); JSON.stringify(domain), JSON.stringify(pageParams)));
}, },
onReadAllByProbe: (probe: Probe, pageNo: string, countPerPage: string) => { onReadAllByProbe: (probe: Probe, pageParams: PageParams) => {
dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbe', readAllByProbeActions.REQUEST, dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbe', readAllByProbeActions.REQUEST,
JSON.stringify(probe), pageNo, countPerPage)); JSON.stringify(probe), JSON.stringify(pageParams)));
}, },
onReadAllByProbeAndType: (probe: Probe, type: MetaHistoryType, pageNo: string, countPerPage: string) => { onReadAllByProbeAndType: (probe: Probe, type: MetaHistoryType, pageParams: PageParams) => {
dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbeAndType', readAllByProbeAndTypeActions.REQUEST, dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbeAndType', readAllByProbeAndTypeActions.REQUEST,
JSON.stringify(probe), JSON.stringify(type), pageNo, countPerPage)); JSON.stringify(probe), JSON.stringify(type), JSON.stringify(pageParams)));
}, },
onReadAllByDomainAndType: (domain: Domain, type: MetaHistoryType, pageNo: string, countPerPage: string) => { onReadAllByDomainAndType: (domain: Domain, type: MetaHistoryType, pageParams: PageParams) => {
dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbeAndType', readAllByProbeAndTypeActions.REQUEST, dispatch(asyncRequestActions.request('HistoryService', 'readAllByProbeAndType', readAllByProbeAndTypeActions.REQUEST,
JSON.stringify(domain), JSON.stringify(type), pageNo, countPerPage)); JSON.stringify(domain), JSON.stringify(type), JSON.stringify(pageParams)));
}, },
onReadAllProbeByDomain: (domain: Domain) => { onReadAllProbeByDomain: (domain: Domain) => {
dispatch(asyncRequestActions.request('ProbeService', 'readAllByDomain', probeListActions.REQUEST, JSON.stringify(domain))); dispatch(asyncRequestActions.request('ProbeService', 'readAllByDomain', probeListActions.REQUEST, JSON.stringify(domain)));

View File

@ -8,6 +8,7 @@ import Page from '@overflow/commons/api/model/Page';
import MetaHistoryType from '@overflow/meta/api/model/MetaHistoryType'; import MetaHistoryType from '@overflow/meta/api/model/MetaHistoryType';
import { Pager } from '@overflow/commons/react/component/Pager'; import { Pager } from '@overflow/commons/react/component/Pager';
import { SortTableHeaderRow } from '@overflow/commons/react/component/SortTableHeaderRow'; import { SortTableHeaderRow } from '@overflow/commons/react/component/SortTableHeaderRow';
import PageParams from '@overflow/commons/api/model/PageParams';
export interface StateProps { export interface StateProps {
probes: Probe[]; probes: Probe[];
@ -20,10 +21,10 @@ export interface DispatchProps {
onReadAllProbeByDomain?(domain: Domain): void; onReadAllProbeByDomain?(domain: Domain): void;
onReadAllMetaHistoryType?(): void; onReadAllMetaHistoryType?(): void;
onReadAllByDomain?(domain: Domain, pageNo: string, countPerPage: string): void; onReadAllByDomain?(domain: Domain, pageParams: PageParams): void;
onReadAllByProbe?(probe: Probe, pageNo: string, countPerPage: string): void; onReadAllByProbe?(probe: Probe, pageParams: PageParams): void;
onReadAllByProbeAndType?(probe: Probe, type: MetaHistoryType, pageNo: string, countPerPage: string): void; onReadAllByProbeAndType?(probe: Probe, type: MetaHistoryType, pageParams: PageParams): void;
onReadAllByDomainAndType?(domain: Domain, type: MetaHistoryType, pageNo: string, countPerPage: string): void; onReadAllByDomainAndType?(domain: Domain, type: MetaHistoryType, pageParams: PageParams): void;
} }
export type Props = StateProps & DispatchProps; export type Props = StateProps & DispatchProps;
@ -66,16 +67,23 @@ export class HistoryList extends React.Component<Props, State> {
} }
public getAllHistory(pageNo: number): void { public getAllHistory(pageNo: number): void {
const pageParams: PageParams = {
pageNo: String(pageNo),
countPerPage: String(10),
sortCol: 'id',
sortDirection: 'descending',
};
if (this.selectedProbeId === 0) { if (this.selectedProbeId === 0) {
let domain: Domain = { let domain: Domain = {
id: 1, id: 1,
}; };
this.props.onReadAllByDomain(domain, String(pageNo), String(this.countPerPage)); this.props.onReadAllByDomain(domain, pageParams);
} else { } else {
let probe: Probe = { let probe: Probe = {
id: this.selectedProbeId, id: this.selectedProbeId,
}; };
this.props.onReadAllByProbe(probe, String(pageNo), String(this.countPerPage)); this.props.onReadAllByProbe(probe, pageParams);
} }
} }
@ -84,7 +92,13 @@ export class HistoryList extends React.Component<Props, State> {
let probe: Probe = { let probe: Probe = {
id: url[2], id: url[2],
}; };
this.props.onReadAllByProbeAndType(probe, this.getMetaType(url[1]), String(pageNo), String(this.countPerPage)); const pageParams: PageParams = {
pageNo: String(pageNo),
countPerPage: String(10),
sortCol: 'id',
sortDirection: 'descending',
};
this.props.onReadAllByProbeAndType(probe, this.getMetaType(url[1]), pageParams);
} }
public getMetaType(typeStr: string): MetaHistoryType { public getMetaType(typeStr: string): MetaHistoryType {
@ -117,19 +131,29 @@ export class HistoryList extends React.Component<Props, State> {
} }
} }
private handleSort = (col:string, direction:string):void => { private handleSort = (col: string, direction: string): void => {
console.log(col + ' || direction:' + direction); console.log(col + ' || direction:' + direction);
const pageParams: PageParams = {
pageNo: String(0),
countPerPage: String(10),
sortCol: col,
sortDirection: direction,
};
let domain: Domain = {
id: 1,
};
this.props.onReadAllByDomain(domain, pageParams);
} }
public render(): JSX.Element { public render(): JSX.Element {
// let cols:string[] = ['No.', 'Probe', 'Type', 'Message', 'Created At', 'Created By']; // let cols:string[] = ['No.', 'Probe', 'Type', 'Message', 'Created At', 'Created By'];
let colsmap:Map<string, string> = new Map(); let colsmap: Map<string, string> = new Map();
colsmap.set('No.', 'id'); colsmap.set('No.', 'id');
colsmap.set('Probe', 'probe.id'); colsmap.set('Probe', 'probe.displayName');
colsmap.set('Type', ' type.id'); colsmap.set('Type', 'type.name');
colsmap.set('Message', 'message'); colsmap.set('Message', 'message');
colsmap.set('Created At', 'createDate'); colsmap.set('Created At', 'createDate');
colsmap.set('Created By', 'member.id'); colsmap.set('Created By', 'member.name');
let historyList: JSX.Element = ( let historyList: JSX.Element = (
<Container fluid> <Container fluid>
@ -171,7 +195,7 @@ export class HistoryList extends React.Component<Props, State> {
</Table.Body> </Table.Body>
<Table.Footer> <Table.Footer>
<Table.Row> <Table.Row>
<Table.HeaderCell colSpan='3'> <Table.HeaderCell colSpan='6' textAlign='center'>
<Pager page={this.props.histories} onPageChange={this.handlePaging} /> <Pager page={this.props.histories} onPageChange={this.handlePaging} />
</Table.HeaderCell> </Table.HeaderCell>
</Table.Row> </Table.Row>