diff --git a/backend/flask_session/2029240f6d1128be89ddc32729463129 b/backend/flask_session/2029240f6d1128be89ddc32729463129 index 7f5741f1..ffb2cd9b 100644 Binary files a/backend/flask_session/2029240f6d1128be89ddc32729463129 and b/backend/flask_session/2029240f6d1128be89ddc32729463129 differ diff --git a/backend/flask_session/679eaac484e8efec851e5d02a21b12ac b/backend/flask_session/679eaac484e8efec851e5d02a21b12ac index 6b00d6ac..cf3196bc 100644 Binary files a/backend/flask_session/679eaac484e8efec851e5d02a21b12ac and b/backend/flask_session/679eaac484e8efec851e5d02a21b12ac differ diff --git a/backend/flask_session/7a973a1ecebb180f9fe7c30101047a60 b/backend/flask_session/7a973a1ecebb180f9fe7c30101047a60 new file mode 100644 index 00000000..f1074ec4 Binary files /dev/null and b/backend/flask_session/7a973a1ecebb180f9fe7c30101047a60 differ diff --git a/backend/flask_session/d809bf2dcbe2110e634be9cd9bce2102 b/backend/flask_session/d809bf2dcbe2110e634be9cd9bce2102 index 3ab4dca6..25891979 100644 Binary files a/backend/flask_session/d809bf2dcbe2110e634be9cd9bce2102 and b/backend/flask_session/d809bf2dcbe2110e634be9cd9bce2102 differ diff --git a/backend/timesheets/routes.py b/backend/timesheets/routes.py index 348e9b5f..4eff8972 100644 --- a/backend/timesheets/routes.py +++ b/backend/timesheets/routes.py @@ -23,6 +23,22 @@ class HomeView(MethodView): def get(self): return "Done", 200 +class ListConsultantsView(MethodView): + def get(self): + user_id = session.get("user_id") + line_manager = LineManager.query.filter_by(id=user_id) + + if line_manager != None: + consultants = Consultant.query.filter_by(line_manager_id=user_id) + else: + return jsonify({"Error": "Unauthorized"}), 400 + + json_dict = {} + for consultant in consultants: + json_dict[consultant.username] = {"username": consultant.username, "consultant_id": consultant.id} + + return jsonify(json_dict), 200 + class CurrentUserView(MethodView): def get(self): @@ -139,13 +155,14 @@ def get(self): json_dict = {} timesheet_ids = [timesheet.id for timesheet in timesheets] for timesheet in timesheets: - json_dict[timesheet.id] = {"name": timesheet.consultant_name, "status": timesheet.status} + json_dict[timesheet.id] = {"id": timesheet.id, "name": timesheet.consultant_name, "status": timesheet.status} return jsonify(json_dict), 200 class ListWeeklyTimesheetsView(MethodView): def get(self): user_id = session.get("user_id") consultant = Consultant.query.filter_by(id=user_id).first() + # line_manager = LineManager.query.filter_by(username=consultant.line_manager.username).first() print(consultant) if consultant == None: @@ -160,18 +177,34 @@ def get(self): for timesheet in timesheets: hours_worked = str(timedelta(seconds=timesheet.hours_worked)) day = f"{timesheet.day.day}/{timesheet.day.month}/{timesheet.day.year}" - json_dict[timesheet.id] = {"start_work": timesheet.start_work_time, "end_work": timesheet.end_work_time, "week_start": week_start, "hours_worked": hours_worked, "day": day} + json_dict[timesheet.id] = {"start_work": timesheet.start_work_time, "end_work": timesheet.end_work_time, + "week_start": week_start, "hours_worked": hours_worked, "day": day, + "consultant_name": f"{consultant.firstname} {consultant.lastname}", + "line_manager_name": f"{consultant.line_manager.firstname} {consultant.line_manager.lastname}"} return jsonify(json_dict), 200 -class ListConsultantsView(MethodView): - def get(self): +class WeeklyTimesheetsApprovalView(MethodView): + def post(self, consultant_username, flag): user_id = session.get("user_id") - consultants = Consultant.query.filter_by(line_manager_id=user_id) - json_dict = {} - for consultant in consultants: - json_dict[consultant.id] = consultant.username - return jsonify(json_dict), 200 + line_manager = LineManager.query.filter_by(id=user_id) + consultant = Consultant.query.filter_by(username=consultant_username) + + week_start = datetime.today() - timedelta(days=datetime.today().weekday() % 7) + week_start = datetime(week_start.year, week_start.month, week_start.day) + week_start = f"{week_start.day}/{week_start.month}/{week_start.year}" + timesheets = Timesheet.query.filter_by(week_start_date=week_start, username=consultant_username).all() + + for timesheet in timesheets : + if flag == "approve": + timesheet.status = "approved" + db.session.commit() + elif flag == "disapprove": + timesheet.status = "disapproved" + else: + return jsonify({"Error": "Invalid flag"}), 400 + + return jsonify("Success"), 200 class ListConsultantTimesheetsView(MethodView): def get(self, consultant_id): @@ -369,7 +402,8 @@ def post(self, consultant_username,): app.add_url_rule("/delete_timesheet/", view_func=timesheets_view, methods=["DELETE"]) app.add_url_rule("/list_timesheets", view_func=ListTimesheetsView.as_view("list_timesheets_view"), methods=["GET"]) app.add_url_rule("/list_weekly_timesheets", view_func=ListWeeklyTimesheetsView.as_view("list_weekly_timesheets_view"), methods=["GET"]) -app.add_url_rule("/list_timesheets/", view_func=ListConsultantTimesheetsView.as_view("list_consultant_timesheets_view"), methods=["GET"]) +app.add_url_rule("/list_weekly_timesheets//", view_func=WeeklyTimesheetsApprovalView.as_view("list_weekly_timesheets_approval"), methods=["POST"]) +app.add_url_rule("/list_timesheets/", view_func=ListConsultantTimesheetsView.as_view("list_consultant_timesheets_viewpost"), methods=["GET"]) app.add_url_rule("/approve_timesheet/", view_func=TimesheetApprovalView.as_view("timesheet_approval_view"), methods=["POST"]) app.add_url_rule("/disapprove_timesheet/", view_func=TimesheetDisapprovalView.as_view("timesheet_disapproval_view"), methods=["POST"]) diff --git a/frontend/public/Home_Page_Icons/Consultant/record_timesheet.svg b/frontend/public/Home_Page_Icons/Consultant/record_timesheet.svg new file mode 100644 index 00000000..2df374ff --- /dev/null +++ b/frontend/public/Home_Page_Icons/Consultant/record_timesheet.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/Home_Page_Icons/Consultant/view_saved_timesheets.svg b/frontend/public/Home_Page_Icons/Consultant/view_saved_timesheets.svg new file mode 100644 index 00000000..ea97d652 --- /dev/null +++ b/frontend/public/Home_Page_Icons/Consultant/view_saved_timesheets.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/Home_Page_Icons/Consultant/view_timesheet.svg b/frontend/public/Home_Page_Icons/Consultant/view_timesheet.svg new file mode 100644 index 00000000..7d0b03ac --- /dev/null +++ b/frontend/public/Home_Page_Icons/Consultant/view_timesheet.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/Home_Page_Icons/house-solid.svg b/frontend/public/Home_Page_Icons/house-solid.svg new file mode 100644 index 00000000..c6bbed4b --- /dev/null +++ b/frontend/public/Home_Page_Icons/house-solid.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/Home_Page_Icons/logout.svg b/frontend/public/Home_Page_Icons/logout.svg new file mode 100644 index 00000000..1b6b9710 --- /dev/null +++ b/frontend/public/Home_Page_Icons/logout.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/index.html b/frontend/public/index.html index 4f8a892b..5350f792 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -15,9 +15,12 @@ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ --> - - - + + +