Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/apocas/restai
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Nov 16, 2023
2 parents e9bcc6f + e7c3a02 commit e2b5887
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 17 deletions.
Binary file added frontend/public/apple-touch-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/apple-touch-icon.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
Binary file added frontend/src/assets/img/restai-logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 18 additions & 4 deletions frontend/src/components/common/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useContext } from 'react';
import { Container, Navbar, Button, Nav } from 'react-bootstrap';
import { NavLink } from "react-router-dom";
import { AuthContext } from './AuthProvider.js';
import restaiLogo from '../../assets/img/restai-logo.png';

function Navigation() {
const { logout, getBasicAuth } = useContext(AuthContext);
Expand All @@ -10,6 +11,13 @@ function Navigation() {
<Navbar expand="lg" className="bg-body-tertiary">
<Container>
<Navbar.Brand href="/admin">
<img
alt=""
src={restaiLogo}
width="30"
height="30"
className="d-inline-block align-top"
/>{' '}
RestAI
</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
Expand Down Expand Up @@ -42,13 +50,19 @@ function Navigation() {
{user.username && (
<Nav>
<Navbar.Text>
Signed in as: <NavLink
Signed in as: {' '}
<NavLink
to={"/users/" + user.username}
>
{user.username}{' '}
👤{user.username}{' | '}
</NavLink>
<NavLink
to={"/users/" + user.username + "/edit"}
>
⚙️Edit{' |'}
</NavLink>
<Button variant="link" onClick={logout}>
Logout
<Button style={{ textDecoration: "none", color: "black", padding: "0px", verticalAlign: "0px" }} variant="link" onClick={logout}>
🚪Logout
</Button>
</Navbar.Text>
</Nav>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/pages/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Form, Button, Alert } from "react-bootstrap";
import React, { useState, useContext } from "react";
import { Navigate } from 'react-router-dom';
import "./login.css";
import restaiLogo from '../../../assets/img/restai-logo.png';
import { AuthContext } from '../../common/AuthProvider.js';

function Login() {
Expand Down Expand Up @@ -34,7 +35,7 @@ function Login() {
<Form className="shadow p-4 bg-white rounded" onSubmit={handleSubmit}>
<img
className="img-thumbnail mx-auto d-block mb-2"
src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/React-icon.svg/1150px-React-icon.svg.png"
src={restaiLogo}
alt="logo"
/>
<div className="h4 mb-2 text-center">LOGIN</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/Login/login.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

.sign-in__wrapper form img {
width: 4rem;
width: 60%;
}

@keyframes showSignInForm {
Expand Down
44 changes: 43 additions & 1 deletion frontend/src/components/pages/Projects/Projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function Projects() {

const url = process.env.REACT_APP_RESTAI_API_URL || "";
const [data, setData] = useState([]);
const [users, setUsers] = useState({ "teste": [] });
const [info, setInfo] = useState({ "version": "", "embeddings": [], "llms": [], "loaders": [] });
const [error, setError] = useState([]);
const projectNameForm = useRef(null)
Expand All @@ -28,7 +29,11 @@ function Projects() {
const fetchProjects = () => {
return fetch(url + "/projects", { headers: new Headers({ 'Authorization': 'Basic ' + user.basicAuth }) })
.then((res) => res.json())
.then((d) => setData(d)
.then((d) => {
setData(d)
if (user.admin)
fetchUsers(d);
}
).catch(err => {
setError([...error, { "functionName": "fetchProjects", "error": err.toString() }]);
});
Expand All @@ -43,6 +48,27 @@ function Projects() {
});
}

const fetchUsers = (data) => {
return fetch(url + "/users", { headers: new Headers({ 'Authorization': 'Basic ' + user.basicAuth }) })
.then((res) => res.json())
.then((d) => {
var arr = {};
for (let i = 0; i < data.length; i++) {
arr[data[i].name] = []
for (let j = 0; j < d.length; j++) {
for (let z = 0; z < d[j].projects.length; z++) {
if (data[i].name === d[j].projects[z].name)
arr[data[i].name].push(d[j].username);
}
}
}
setUsers(arr)
}
).catch(err => {
setError([...error, { "functionName": "fetchUsers", "error": err.toString() }]);
});
}

// TODO: response handling
const onSubmitHandler = (event) => {
event.preventDefault();
Expand Down Expand Up @@ -86,6 +112,9 @@ function Projects() {
<th>#</th>
<th>Project Name</th>
<th>Actions</th>
{user.admin &&
<th>Used by</th>
}
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -124,6 +153,19 @@ function Projects() {
</NavLink>
<Button onClick={() => handleDeleteClick(project.name)} variant="danger">Delete</Button>
</td>
{
user.admin &&
<td>
{typeof users[project.name] !== "undefined" && (
users[project.name].map((user, index) => {
if (users[project.name].length - 1 === index)
return <NavLink key={index} to={"/users/" + user}>{user}</NavLink>
return <NavLink key={index} to={"/users/" + user}>{user + ", "}</NavLink>
})
)
}
</td>
}
</tr>
)
})
Expand Down
18 changes: 12 additions & 6 deletions frontend/src/components/pages/Users/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ function Edit() {
const onSubmitHandler = (event) => {
event.preventDefault();
var body = "";
if (passwordForm.current.value === "") {
if (passwordForm.current.value === "" && user.admin) {
body = JSON.stringify({
"is_admin": isadminForm.current.checked
})
} else {
} else if (passwordForm.current.value !== "" && user.admin) {
body = JSON.stringify({
"password": passwordForm.current.value,
"is_admin": isadminForm.current.checked
})
} else {
body = JSON.stringify({
"password": passwordForm.current.value
})
}

fetch(url + "/users/" + username, {
Expand Down Expand Up @@ -60,10 +64,12 @@ function Edit() {
<Form.Label>Password</Form.Label>
<Form.Control ref={passwordForm} />
</Form.Group>
<Form.Group as={Col} controlId="formGridAdmin">
<Form.Label>Admin</Form.Label>
<Form.Check ref={isadminForm} type="checkbox" label="Check me" />
</Form.Group>
{user.admin &&
<Form.Group as={Col} controlId="formGridAdmin">
<Form.Label>Admin</Form.Label>
<Form.Check ref={isadminForm} type="checkbox" label="Check me" />
</Form.Group>
}
</Row>
<Button variant="dark" type="submit" className="mb-2">
Submit
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/pages/Users/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function User() {

var projectsi = [];
for (var i = 0; i < data.projects.length; i++) {
projectsi.push(data.projects[i].name);
projectsi.push(data.projects[i].name);
}

projectsi.push(projectForm.current.value)
Expand Down Expand Up @@ -97,10 +97,11 @@ function User() {
<ListGroup.Item>Id: {data.id}</ListGroup.Item>
<ListGroup.Item>Username: {data.username}</ListGroup.Item>
<ListGroup.Item>Projects Count: {data.projects.length}</ListGroup.Item>
<ListGroup.Item>Admin: {data.is_admin ? (<span></span>) : (<span></span>)}</ListGroup.Item>
</ListGroup>
</Col>
</Row>
<Row>
<Row style={{ marginTop: "20px" }}>
<h1>Projects</h1>
{user.admin && (
<Form onSubmit={onSubmitHandler}>
Expand Down Expand Up @@ -155,7 +156,7 @@ function User() {
</tbody>
</Table>
</Row>
</Container>
</Container >
</>
);
}
Expand Down

0 comments on commit e2b5887

Please sign in to comment.