Skip to content

Commit

Permalink
functionality w/ dummmy data
Browse files Browse the repository at this point in the history
  • Loading branch information
achandrabalan committed Dec 3, 2023
1 parent 5aa5c30 commit 74fdde0
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 25 deletions.
4 changes: 3 additions & 1 deletion backend/app/models/log_record_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class LogRecordTag(db.Model):
log_record_id = db.Column(
db.Integer, db.ForeignKey("log_records.log_id"), nullable=False
)
tag_id = db.Column(db.Integer, db.ForeignKey("tags.tag_id", ondelete='CASCADE'), nullable=False)
tag_id = db.Column(
db.Integer, db.ForeignKey("tags.tag_id", ondelete="CASCADE"), nullable=False
)

def to_dict(self, include_relationships=False):
# define the entities table
Expand Down
5 changes: 4 additions & 1 deletion backend/app/models/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class Tag(db.Model):
tag_id = db.Column(db.Integer, primary_key=True, nullable=False)
name = db.Column(db.String, unique=True, nullable=False)
last_modified = db.Column(
db.DateTime, server_default=db.func.now(), onupdate=db.func.now(), nullable=False
db.DateTime,
server_default=db.func.now(),
onupdate=db.func.now(),
nullable=False,
)
log_records = db.relationship(
"LogRecords", secondary="log_record_tag", back_populates="tags"
Expand Down
6 changes: 4 additions & 2 deletions backend/app/resources/auth_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def __init__(
email,
role,
user_status,
last_modified
last_modified,
):
Token.__init__(self, access_token, refresh_token)
UserDTO.__init__(self, id, first_name, last_name, email, role, user_status, last_modified)
UserDTO.__init__(
self, id, first_name, last_name, email, role, user_status, last_modified
)
6 changes: 3 additions & 3 deletions backend/app/services/implementations/tags_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def get_tags(self):
def delete_tag(self, tag_id):
tags_to_delete = Tag.query.filter_by(tag_id=tag_id).first()
if not tags_to_delete:
raise Exception(
"Log record with id {log_id} not found".format(log_id=log_id)
)
raise Exception(
"Log record with id {log_id} not found".format(log_id=log_id)
)
tags_to_delete.log_records = []
db.session.delete(tags_to_delete)
db.session.commit()
Expand Down
5 changes: 3 additions & 2 deletions backend/app/services/implementations/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from ...models import db
from ...resources.user_dto import UserDTO
from ...utilities.exceptions.auth_exceptions import (
UserNotInvitedException, EmailAlreadyInUseException
UserNotInvitedException,
EmailAlreadyInUseException,
)


Expand Down Expand Up @@ -215,7 +216,7 @@ def activate_user(self, user, auth_id=None, signup_method="PASSWORD"):

try:
cur_user_status = self.get_user_status_by_email(user.email)

if cur_user_status == "Active":
raise EmailAlreadyInUseException
if cur_user_status == "Invited":
Expand Down
7 changes: 5 additions & 2 deletions backend/app/utilities/exceptions/auth_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ def __init__(self):
self.message = "This email address has not been invited. Please try again with a different email."
super().__init__(self.message)


class EmailAlreadyInUseException(Exception):
"""
Raised when a user attempts to register with an email of a previously activated user
"""

def __init__(self):
self.message = "This email is already in use. Please try again with a different email."
super().__init__(self.message)
self.message = (
"This email is already in use. Please try again with a different email."
)
super().__init__(self.message)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("tags", schema=None) as batch_op:
batch_op.add_column(sa.Column("last_modified", sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), onupdate=sa.text('CURRENT_TIMESTAMP'), nullable=False))
batch_op.add_column(
sa.Column(
"last_modified",
sa.DateTime(),
server_default=sa.text("CURRENT_TIMESTAMP"),
onupdate=sa.text("CURRENT_TIMESTAMP"),
nullable=False,
)
)

# ### end Alembic commands ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '117790caec65'
down_revision = '0dbe140cf6f5'
revision = "117790caec65"
down_revision = "0dbe140cf6f5"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tags', schema=None) as batch_op:
batch_op.drop_column('status')
with op.batch_alter_table("tags", schema=None) as batch_op:
batch_op.drop_column("status")

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tags', schema=None) as batch_op:
batch_op.add_column(sa.Column('status', postgresql.ENUM('Deleted', 'Active', name='status'), autoincrement=False, nullable=False))
with op.batch_alter_table("tags", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"status",
postgresql.ENUM("Deleted", "Active", name="status"),
autoincrement=False,
nullable=False,
)
)

# ### end Alembic commands ###
20 changes: 17 additions & 3 deletions frontend/src/components/pages/AdminControls/SignInLogs.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React, { useEffect, useRef, useState } from "react";
import { Box, Flex } from "@chakra-ui/react";

import { PassThrough } from "stream";
import Pagination from "../../common/Pagination";
import NavigationBar from "../../common/NavigationBar";
import { User } from "../../../types/UserTypes";
import SignInLogsTable from "./SignInLogsTable";
import UserAPIClient from "../../../APIClients/UserAPIClient";



const SignInLogsPage = (): React.ReactElement => {
const [users, setUsers] = useState<User[]>([]);
const [numUsers, setNumUsers] = useState<number>(0);
Expand All @@ -18,6 +20,7 @@ const SignInLogsPage = (): React.ReactElement => {
// Table reference
const tableRef = useRef<HTMLDivElement>(null);

// Change to get filter logs !!
const getUsers = async (pageNumber: number) => {
const data = await UserAPIClient.getUsers({ pageNumber, resultsPerPage });

Expand All @@ -34,11 +37,21 @@ const SignInLogsPage = (): React.ReactElement => {
}
};

const countUsers = async () => {
const data = await UserAPIClient.countUsers();
setNumUsers(data ? data.numResults : 0);
// Dummy data
type MyDictionary = {
[key: string]: any;
};

// Create an array of dictionaries
const signInLogs: MyDictionary[] = [
{ id: 1, date: "2023-12-03T13:30:00.000Z" , name: "Aathithan Chandrabalan" },
{ id: 1, date: "2023-12-01T12:30:00.000Z" , name: "Phil Dunphry" },
{ id: 1, date: "2023-12-04T15:11:00.000Z" , name: "Connor Bechthold" },
{ id: 1, date: "2023-12-05T19:45:00.000Z" , name: "Bob Cob" },
{ id: 1, date: "2023-12-05T21:23:00.000Z" , name: "Jessica P" },

];

return (
<Box>
<NavigationBar />
Expand All @@ -55,6 +68,7 @@ const SignInLogsPage = (): React.ReactElement => {
</Flex>

<SignInLogsTable
signInLogs={signInLogs}
tableRef={tableRef}
/>
<Pagination
Expand Down
28 changes: 24 additions & 4 deletions frontend/src/components/pages/AdminControls/SignInLogsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ import React, { RefObject } from "react";
import {
Box,
Table,
Tbody,
TableContainer,
Th,
Td,
Thead,
Tr,
} from "@chakra-ui/react";
import { User } from "../../../types/UserTypes";
import { User } from "../../../types/UserTypes"; // Needs to be changed !!

import getFormattedDateAndTime from "../../../utils/DateUtils";

type Props = {
signInLogs: { id: number; date: string; name: string }[];
tableRef: RefObject<HTMLDivElement>;
};

const SignInLogsTable = ({
signInLogs,
tableRef,
}: Props): React.ReactElement => {

Expand All @@ -29,13 +35,27 @@ const SignInLogsTable = ({
<Thead>
<Tr>
<Th>Employee Name</Th>
<Th> </Th>
<Th>Date</Th>
<Th> </Th>
<Th> </Th>
<Th>Time</Th>
</Tr>
</Thead>
<Tbody>
{signInLogs.map((log) => {
const dateObj = new Date(log.date);

const { date, time } = getFormattedDateAndTime(dateObj);

return (

<Tr key={log.id} style={{ verticalAlign: "middle" }}>
<Td width="33%">{`${log.name}`}</Td>
<Td width="33%">{date}</Td>
<Td width="5%">{time}</Td>
</Tr>
);
})}

</Tbody>


</Table>
Expand Down

0 comments on commit 74fdde0

Please sign in to comment.