Skip to content

Commit

Permalink
Merge pull request #127 from tremors0/report-find-agent-in-message
Browse files Browse the repository at this point in the history
Report find agent in report
  • Loading branch information
tremors0 authored Dec 17, 2018
2 parents 07d2c52 + 809ea60 commit cd88fe6
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Secret-agency-web/src/main/react/secret-agency/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as secretAgencyRepository from "./repository/secretAgecyRepository";
import {IAgent} from "./types/Agent";
import {TopBar} from "./components/top-bar/TopBar"
import {AgentsPage} from "./components/agents-page/AgentsPage";
import {BrowserRouter, Route} from "react-router-dom";
import {BrowserRouter, Redirect, Route} from "react-router-dom";
import {DepartmentsPage} from "./components/departments-page/DepartmentsPage";
import {ROUTING_URL_BASE} from "./utils/requestUtils";
import {ReportsPage} from "./components/reports-page/ReportsPage";
Expand Down Expand Up @@ -152,6 +152,7 @@ class App extends React.Component<{}, IState> {
)} />
<Route path={`${ROUTING_URL_BASE}/reports/report/:reportId`} component={ReportDetail}/>
</div>
<Redirect to={`${ROUTING_URL_BASE}/reports`}/>
</div>
</BrowserRouter>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@

.ReportDetail__img {
margin-right: 100px;
}

.ReportDetail__textWrapper {
margin-bottom: 10px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Alert, Button, FormControl, FormGroup} from "react-bootstrap";
import {Link} from "react-router-dom";
import {ROUTING_URL_BASE} from "../../utils/requestUtils";
import {AlertCloseable} from "../alert-closeable/AlertCloseable";
import {IAgent} from "../../types/Agent";

// easiest way, how to add image to page
const topSecretImgSrc = "https://vignette.wikia.nocookie.net/uncyclopedia/images/2/25/Top_Secret_Stamp.png" +
Expand All @@ -20,6 +21,7 @@ interface IReportDetailState {
readonly submitError: string;
readonly serverError: string;
readonly wasSaved: boolean;
readonly mentionedAgentsInReport: IAgent[] | null;
}

type IProps = RouteComponentProps<{reportId: string}>;
Expand All @@ -42,6 +44,19 @@ export class ReportDetail extends React.PureComponent<IProps, IState> {
this.setState(prevState => ({...prevState, text , submitError: ""}));
};

private onFindMentionedAgents = async () => {
// already run
if (this.state.mentionedAgentsInReport != null) {
return;
}
const response = await reportService.getAgentsMentionedInReport(this.displayedReport.id);
if (typeof response === "string") {
this.setState(prevState => ({...prevState, serverError: response}));
return;
}

this.setState(prevState => ({...prevState, mentionedAgentsInReport: response}));
};

private onSaveClicked = async (): Promise<void> => {
if (this.state.text.trim().length < 10) {
Expand Down Expand Up @@ -87,6 +102,7 @@ export class ReportDetail extends React.PureComponent<IProps, IState> {
submitError: "",
serverError: "",
wasSaved: false,
mentionedAgentsInReport: null,
}
}

Expand All @@ -104,6 +120,20 @@ export class ReportDetail extends React.PureComponent<IProps, IState> {
this.setState(prevState => ({...prevState, text: response.text, isLoading: false}));
}

private getFindAgentsResult(): null | JSX.Element |JSX.Element[] {
if (this.state.mentionedAgentsInReport == null) {
return null;
}

if (this.state.mentionedAgentsInReport.length === 0) {
return <Alert bsStyle={"info"}>No agents found</Alert>;
}

return this.state.mentionedAgentsInReport.map((agent) => (
<div className={"ReportDetail__findAgentsResult"} key={agent.id}>{agent.codeName}</div>
));
}

/********************************************************
* RENDERING
*******************************************************/
Expand Down Expand Up @@ -151,9 +181,16 @@ export class ReportDetail extends React.PureComponent<IProps, IState> {
</div>
<img title={'Top-secret'} src={topSecretImgSrc} alt={'Top secret logo'} className={"ReportDetail__img"}/>
</div>
<div>Text: {textComponent}</div>
<div className={"ReportDetail__textWrapper"}>Text: {textComponent}</div>
{this.state.wasSaved && <p className={"text-success"}>Report was successfully updated</p>}
{this.isEditingMode() && <Button bsStyle={"primary"} onClick={this.onSaveClicked}>Save</Button>}
{this.getFindAgentsResult()}
{!this.isEditingMode() && (
<Button className={"ReportDetail__findAgentsButton"}
bsStyle={"warning"} onClick={this.onFindMentionedAgents}>
Find mentioned agents
</Button>
)}
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class ReportFilter extends React.PureComponent<IProps, IState> {
result = await reportService.getAllReports();
break;
case SEARCH_BY_STATUS:
result = await reportService.getreportsWithStatus(this.state.reportStatus);
result = await reportService.getReportsWithStatus(this.state.reportStatus);
break;
case SEARCH_BY_RESULT:
result = await reportService.getReportsWithResult(this.state.reportResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ export class ReportsPage extends React.PureComponent<IProps, IState> {
// authenticated agent is not admin or Report author
return (
<div className={'ReportsPage__actions'}>
<Button bsStyle={'info'}>View</Button>
<span className={"icon-operation"} onClick={() => this.onShowDetail(report.id)}>
<FontAwesomeIcon icon={faSearch} size={"2x"} />
</span>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {IReport, IReportCreate, IReportUpdate} from "../types/Report";
import {DELETE, GET, POST, PUT, REST_URL_BASE} from "../utils/requestUtils";
import {AxiosError} from "axios";
import {IAgent} from "../types/Agent";


export function getAllReports(): Promise<IReport[]> {
Expand Down Expand Up @@ -101,10 +102,19 @@ export function getReportsWithResult(result: string): Promise<IReport[] | string
}

// /reportStatus/{reportStatus}
export function getreportsWithStatus(status: string,): Promise<IReport[] | string> {
export function getReportsWithStatus(status: string,): Promise<IReport[] | string> {
return GET<IReport[]>(`${REST_URL_BASE}/reports/reportStatus/${status}`).then((response) => {
return response.data;
}).catch((error: AxiosError) => {
return error.response ? error.response.data.message : error.message;
});
}

// /report/{reportId}/mentionedAgents
export function getAgentsMentionedInReport(reportId: number): Promise<IAgent[] | string> {
return GET<IReport[]>(`${REST_URL_BASE}/reports/report/${reportId}/mentionedAgents`).then((response) => {
return response.data;
}).catch((error: AxiosError) => {
return error.response ? error.response.data.message : error.message;
});
}
4 changes: 2 additions & 2 deletions Secret-agency-web/src/main/resources/static/css/frontend.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Secret-agency-web/src/main/resources/static/js/frontend.js

Large diffs are not rendered by default.

0 comments on commit cd88fe6

Please sign in to comment.