From 4fc4aa7bcb403e5d33a641955ad26ecfa096ef7f Mon Sep 17 00:00:00 2001 From: Mahmoud Emad Date: Sun, 29 Oct 2023 19:23:33 +0200 Subject: [PATCH] Fix profile improments. --- .../src/componants/profile/UserProfile.svelte | 12 +++--- .../componants/profile/VacationBalance.svelte | 28 ++++++++++--- server/cshr/serializers/vacations.py | 40 +++++++++++++++---- 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/client/src/componants/profile/UserProfile.svelte b/client/src/componants/profile/UserProfile.svelte index e7cfdb06b..329006ded 100644 --- a/client/src/componants/profile/UserProfile.svelte +++ b/client/src/componants/profile/UserProfile.svelte @@ -64,28 +64,28 @@ - {#if $UserStore.user_type === 'Admin' || $UserStore.user_type === 'Supervisor' || $UserStore.id === id} +
-
+ {#if $UserStore.user_type === 'Admin' || $UserStore.user_type === 'Supervisor' || $UserStore.id === id}
{/if} - {#if $UserStore.user_type === 'Admin' || $UserStore.id === id} +
diff --git a/client/src/componants/profile/VacationBalance.svelte b/client/src/componants/profile/VacationBalance.svelte index 2ce786919..cd9f9b515 100644 --- a/client/src/componants/profile/VacationBalance.svelte +++ b/client/src/componants/profile/VacationBalance.svelte @@ -4,13 +4,29 @@ export let user: any; - let vacationBalance: any = null; + type BalanceValue = { + reserved: number; + all: number; + } + + interface VacationBalance { + annual_leaves: BalanceValue; + compensation: BalanceValue; + emergency_leaves: BalanceValue; + leave_excuses: BalanceValue; + sick_leaves: BalanceValue; + unpaid: BalanceValue; + }; + + let balance: VacationBalance; + onMount(async () => { - vacationBalance = await Vacation.balance(user.id); + balance = await Vacation.balance(user.id); }); + -{#if vacationBalance != null} +{#if balance != null}
Vacation Balance
@@ -20,9 +36,9 @@
Excuses
-
{vacationBalance.annual_leaves[0]} / {vacationBalance.annual_leaves[1]}
-
{vacationBalance.emergency_leaves[0]} / {vacationBalance.emergency_leaves[1]}
-
{vacationBalance.leave_excuses[0]} / {vacationBalance.leave_excuses[1]}
+
{balance.annual_leaves.reserved} / {balance.annual_leaves.all}
+
{balance.emergency_leaves.reserved} / {balance.emergency_leaves.all}
+
{balance.leave_excuses.reserved} / {balance.leave_excuses.all}
diff --git a/server/cshr/serializers/vacations.py b/server/cshr/serializers/vacations.py index ff972772d..952eb470a 100644 --- a/server/cshr/serializers/vacations.py +++ b/server/cshr/serializers/vacations.py @@ -8,7 +8,6 @@ from server.cshr.serializers.users import BaseUserSerializer, TeamSerializer from rest_framework import serializers - class VacationsSerializer(ModelSerializer): class Meta: model = Vacation @@ -120,6 +119,9 @@ def get_user(self, obj: User): """This method to return user data instead of his id""" return TeamSerializer(obj.user).data +class UserBalanceVlaueSerializer(serializers.Serializer): + reserved = serializers.IntegerField() + all = serializers.IntegerField() class CalculateBalanceSerializer(serializers.Serializer): user = serializers.SerializerMethodField() @@ -147,24 +149,48 @@ def get_user(self, obj: VacationBalance): def get_sick_leaves(self, obj: VacationBalance): """This method returns the actual user balance values.""" - return [obj.sick_leaves, obj.actual_balance.get("sick_leaves")] + value = { + "reserved": obj.actual_balance.get("sick_leaves") - obj.sick_leaves, + "all": obj.actual_balance.get("sick_leaves") + } + return UserBalanceVlaueSerializer(value).data def get_compensation(self, obj: VacationBalance): """This method returns the actual user balance values.""" - return [obj.compensation, obj.actual_balance.get("compensation")] + value = { + "reserved": obj.actual_balance.get("compensation") - obj.compensation, + "all": obj.actual_balance.get("compensation") + } + return UserBalanceVlaueSerializer(value).data def get_unpaid(self, obj: VacationBalance): """This method returns the actual user balance values.""" - return [obj.unpaid, obj.actual_balance.get("unpaid")] + value = { + "reserved": obj.actual_balance.get("unpaid") - obj.unpaid, + "all": obj.actual_balance.get("unpaid") + } + return UserBalanceVlaueSerializer(value).data def get_annual_leaves(self, obj: VacationBalance): """This method returns the actual user balance values.""" - return [obj.annual_leaves, obj.actual_balance.get("annual_leaves")] + value = { + "reserved": obj.actual_balance.get("annual_leaves") - obj.annual_leaves, + "all": obj.actual_balance.get("annual_leaves") + } + return UserBalanceVlaueSerializer(value).data def get_emergency_leaves(self, obj: VacationBalance): """This method returns the actual user balance values.""" - return [obj.emergency_leaves, obj.actual_balance.get("emergency_leaves")] + value = { + "reserved": obj.actual_balance.get("emergency_leaves") - obj.emergency_leaves, + "all": obj.actual_balance.get("emergency_leaves") + } + return UserBalanceVlaueSerializer(value).data def get_leave_excuses(self, obj: VacationBalance): """This method returns the actual user balance values.""" - return [obj.leave_excuses, obj.actual_balance.get("leave_excuses")] + value = { + "reserved": obj.actual_balance.get("leave_excuses") - obj.leave_excuses, + "all": obj.actual_balance.get("leave_excuses") + } + return UserBalanceVlaueSerializer(value).data