Lab 4 - доп.задание
This commit is contained in:
parent
f024215f82
commit
f9c5202f6b
@ -17,6 +17,11 @@ export default function Catalog(props) {
|
|||||||
handleShow();
|
handleShow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleChoose(itemId) {
|
||||||
|
setModalTitle("Выбрать");
|
||||||
|
props.onChoose(itemId);
|
||||||
|
handleShow();
|
||||||
|
}
|
||||||
function handleEdit(itemId) {
|
function handleEdit(itemId) {
|
||||||
setModalTitle("Редактирование");
|
setModalTitle("Редактирование");
|
||||||
props.onEdit(itemId);
|
props.onEdit(itemId);
|
||||||
@ -35,6 +40,7 @@ export default function Catalog(props) {
|
|||||||
<Table
|
<Table
|
||||||
headers={props.headers}
|
headers={props.headers}
|
||||||
items={props.items}
|
items={props.items}
|
||||||
|
onChoose={handleChoose}
|
||||||
onEdit={handleEdit}
|
onEdit={handleEdit}
|
||||||
onDelete={handleRemove}
|
onDelete={handleRemove}
|
||||||
/>
|
/>
|
||||||
|
@ -27,6 +27,8 @@ export default function DrivingSchools(props) {
|
|||||||
loadItems();
|
loadItems();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const [selectedId, setSelectedId] = useState(null);
|
||||||
|
|
||||||
function loadItems() {
|
function loadItems() {
|
||||||
DataService.readAll(url, (data) => new DrivingSchool(data))
|
DataService.readAll(url, (data) => new DrivingSchool(data))
|
||||||
.then(data => setItems(data));
|
.then(data => setItems(data));
|
||||||
@ -127,15 +129,13 @@ export default function DrivingSchools(props) {
|
|||||||
}
|
}
|
||||||
const [chosenDrivingSchool, setChosenDrivingSchool] = useState(0);
|
const [chosenDrivingSchool, setChosenDrivingSchool] = useState(0);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
function redirectToDrivingSchool() {
|
|
||||||
|
|
||||||
if (chosenDrivingSchool !== 0) {
|
function redirectToDrivingSchool(item) {
|
||||||
navigate(`/drivingSchool/${chosenDrivingSchool}`);
|
setSelectedId(item);
|
||||||
}
|
navigate(`/drivingSchool/${item}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div className="container-lg pt-5 min-vh-100">
|
return <div className="container-lg pt-5 min-vh-100">
|
||||||
<Button onClick={showModalFormChoosing} variant="info">Перейти к автошколе</Button>
|
|
||||||
<ModalForm show={showModalForm} onClose={unshowModalFormChoosing} modalTitle={"Выбор автошколы"} form={formChooseDrivingSchool}></ModalForm>
|
<ModalForm show={showModalForm} onClose={unshowModalFormChoosing} modalTitle={"Выбор автошколы"} form={formChooseDrivingSchool}></ModalForm>
|
||||||
<Catalog name={nameCatalog}
|
<Catalog name={nameCatalog}
|
||||||
headers={headers}
|
headers={headers}
|
||||||
@ -143,6 +143,7 @@ export default function DrivingSchools(props) {
|
|||||||
onAdd={handleAdd}
|
onAdd={handleAdd}
|
||||||
onEdit={handleEdit}
|
onEdit={handleEdit}
|
||||||
onDelete={handleDelete}
|
onDelete={handleDelete}
|
||||||
|
onChoose={redirectToDrivingSchool}
|
||||||
onClose={reset}
|
onClose={reset}
|
||||||
onBtnAdd={reset}
|
onBtnAdd={reset}
|
||||||
form={form}>
|
form={form}>
|
||||||
|
@ -6,12 +6,16 @@ export default function ItemTable(props) {
|
|||||||
function remove() {
|
function remove() {
|
||||||
props.onDelete(props.item.id);
|
props.onDelete(props.item.id);
|
||||||
}
|
}
|
||||||
|
function chooseDrivingSchool() {
|
||||||
|
props.onChoose(props.item.id);
|
||||||
|
}
|
||||||
|
|
||||||
return <tr key={props.item.id}>
|
return <tr key={props.item.id}>
|
||||||
{
|
{
|
||||||
props.headers.map((header) => <td key={`${header.name}_${props.item.id}`}>{props.item[header.name]}</td>)
|
props.headers.map((header) => <td key={`${header.name}_${props.item.id}`}>{props.item[header.name]}</td>)
|
||||||
}
|
}
|
||||||
{props.isOnlyView || <td key={`controls_${props.item.id}`}>
|
{props.isOnlyView || <td key={`controls_${props.item.id}`}>
|
||||||
|
<Button variant="btn btn-outline-warning" onClick={chooseDrivingSchool}>Выбрать</Button>
|
||||||
<Button variant="btn btn-outline-primary" onClick={edit}>Редактировать</Button>
|
<Button variant="btn btn-outline-primary" onClick={edit}>Редактировать</Button>
|
||||||
<Button variant="btn btn-outline-danger" onClick={remove}>Удалить</Button></td>}
|
<Button variant="btn btn-outline-danger" onClick={remove}>Удалить</Button></td>}
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -6,6 +6,10 @@ export default function Table(props) {
|
|||||||
function remove(itemId) {
|
function remove(itemId) {
|
||||||
props.onDelete(itemId);
|
props.onDelete(itemId);
|
||||||
}
|
}
|
||||||
|
function chooseDrivingSchool(itemId) {
|
||||||
|
props.onChoose(itemId);
|
||||||
|
}
|
||||||
|
|
||||||
return <div >
|
return <div >
|
||||||
<table className={`table table-hover`}>
|
<table className={`table table-hover`}>
|
||||||
<thead>
|
<thead>
|
||||||
@ -26,6 +30,7 @@ export default function Table(props) {
|
|||||||
item={item}
|
item={item}
|
||||||
onDelete={remove}
|
onDelete={remove}
|
||||||
onEdit={edit}
|
onEdit={edit}
|
||||||
|
onChoose={chooseDrivingSchool}
|
||||||
isOnlyView={props.isOnlyView}/>)
|
isOnlyView={props.isOnlyView}/>)
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
Reference in New Issue
Block a user