Skip to content

Commit

Permalink
Fix profile improments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud-Emad committed Oct 29, 2023
1 parent d7d0c90 commit 4fc4aa7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
12 changes: 6 additions & 6 deletions client/src/componants/profile/UserProfile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,28 @@
</div>

<ReportTo users={user.reporting_to}/>
{#if $UserStore.user_type === 'Admin' || $UserStore.user_type === 'Supervisor' || $UserStore.id === id}
<!-- RFV0.1 {#if $UserStore.user_type === 'Admin' || $UserStore.user_type === 'Supervisor' || $UserStore.id === id}
<Evaluation {user}/>
<UserDocuments user={user} />
{/if}
{/if} -->
</div>
<div class="col-lg-8">
<UserData bind:user />
<div class="row">
<!-- RFV0.1 <div class="row">
<Skills bind:skills={user.skills} />
<Certificates bind:certificates={user.user_certificates} />
</div>
</div> -->
{#if $UserStore.user_type === 'Admin' || $UserStore.user_type === 'Supervisor' || $UserStore.id === id}
<div class="row">
<Company bind:companies={user.user_company_properties} />
</div>
<VacationBalance user={user}/>
{/if}
{#if $UserStore.user_type === 'Admin' || $UserStore.id === id}
<!-- RFV0.1 {#if $UserStore.user_type === 'Admin' || $UserStore.id === id}
<div class="row">
<Salary salaries={user.salary} />
</div>
{/if}
{/if} -->
</div>
</div>
</div>
Expand Down
28 changes: 22 additions & 6 deletions client/src/componants/profile/VacationBalance.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
</script>

{#if vacationBalance != null}
{#if balance != null}
<div class="card">
<div class="card-header">Vacation Balance</div>
<div class="card-body">
Expand All @@ -20,9 +36,9 @@
<div class="col-4 text-muted d-flex justify-content-center">Excuses</div>
</div>
<div class="row">
<div class="col-4 text-muted d-flex justify-content-center">{vacationBalance.annual_leaves[0]} / {vacationBalance.annual_leaves[1]}</div>
<div class="col-4 text-muted d-flex justify-content-center">{vacationBalance.emergency_leaves[0]} / {vacationBalance.emergency_leaves[1]}</div>
<div class="col-4 text-muted d-flex justify-content-center">{vacationBalance.leave_excuses[0]} / {vacationBalance.leave_excuses[1]}</div>
<div class="col-4 text-muted d-flex justify-content-center">{balance.annual_leaves.reserved} / {balance.annual_leaves.all}</div>
<div class="col-4 text-muted d-flex justify-content-center">{balance.emergency_leaves.reserved} / {balance.emergency_leaves.all}</div>
<div class="col-4 text-muted d-flex justify-content-center">{balance.leave_excuses.reserved} / {balance.leave_excuses.all}</div>
</div>
</div>
</div>
Expand Down
40 changes: 33 additions & 7 deletions server/cshr/serializers/vacations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from server.cshr.serializers.users import BaseUserSerializer, TeamSerializer
from rest_framework import serializers


class VacationsSerializer(ModelSerializer):

Check failure on line 11 in server/cshr/serializers/vacations.py

View workflow job for this annotation

GitHub Actions / Flake8

server/cshr/serializers/vacations.py#L11

Expected 2 blank lines, found 1 (E302)
class Meta:
model = Vacation
Expand Down Expand Up @@ -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):

Check failure on line 122 in server/cshr/serializers/vacations.py

View workflow job for this annotation

GitHub Actions / Flake8

server/cshr/serializers/vacations.py#L122

Expected 2 blank lines, found 1 (E302)
reserved = serializers.IntegerField()
all = serializers.IntegerField()

class CalculateBalanceSerializer(serializers.Serializer):

Check failure on line 126 in server/cshr/serializers/vacations.py

View workflow job for this annotation

GitHub Actions / Flake8

server/cshr/serializers/vacations.py#L126

Expected 2 blank lines, found 1 (E302)
user = serializers.SerializerMethodField()
Expand Down Expand Up @@ -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

0 comments on commit 4fc4aa7

Please sign in to comment.