Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/public/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.env = {
// SERVER_DOMAIN_NAME_API: 'https://cshrserver.gent01.qa.grid.tf/api', // Added for testing, this is a staging API
// SERVER_DOMAIN_NAME_WS: 'wss://cshrserver.gent01.qa.grid.tf/ws/notification', // Added for testing, this is a staging API
// SERVER_DOMAIN_NAME_API: 'https://bknd2.hr.threefold.tech/api', // Added for testing, this is a staging API
// SERVER_DOMAIN_NAME_WS: 'wss://bknd2.hr.threefold.tech/ws/notification', // Added for testing, this is a staging API
SERVER_DOMAIN_NAME_API: 'http://127.0.0.1:8000/api', // Added for testing, this is the local server API
SERVER_DOMAIN_NAME_WS: 'ws://127.0.0.1:8000/ws/notification', // Added for testing, this is the local server API
};
55 changes: 29 additions & 26 deletions client/src/components/CalenderComponent.vue
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
<template>
<v-row class="justify-center py-4">
<v-col cols="2">
<v-checkbox v-model="filters.vacation" color="#fcd091" label="Vacations" />
</v-col>
<v-col cols="2">
<v-checkbox v-model="filters.meeting" color="#efeaea" label="Meetings" />
</v-col>
<v-col cols="2">
<v-checkbox v-model="filters.event" color="#47a2ff" label="Events" />
</v-col>
<v-col cols="2">
<v-checkbox v-model="filters.holiday" color="#5effb4" label="Holidays" />
</v-col>
<v-col cols="2">
<v-checkbox v-model="filters.birthday" color="#e0adf0" label="Birthdays" />
</v-col>
</v-row>
<v-divider class="d-flex mx-auto" style="width: 90%"></v-divider>
<div v-if="!isLoading">
<v-row class="justify-center py-4">
<v-col cols="2">
<v-checkbox v-model="filters.vacation" color="#fcd091" label="Vacations" />
</v-col>
<v-col cols="2">
<v-checkbox v-model="filters.meeting" color="#efeaea" label="Meetings" />
</v-col>
<v-col cols="2">
<v-checkbox v-model="filters.event" color="#47a2ff" label="Events" />
</v-col>
<v-col cols="2">
<v-checkbox v-model="filters.holiday" color="#5effb4" label="Holidays" />
</v-col>
<v-col cols="2">
<v-checkbox v-model="filters.birthday" color="#e0adf0" label="Birthdays" />
</v-col>
</v-row>
<v-divider class="d-flex mx-auto" style="width: 90%"></v-divider>
</div>
<div class="ma-7 px-7">
<div class="loading-container d-flex align-center justify-center my-5" v-if="isLoading">
<v-alert density="compact" class="pa-5" type="info" text="Events are loading..."></v-alert>
</div>

<FullCalendar
class="fc"
:options="{
...options,
events: filteredEvents as any
}"
>
</FullCalendar>
<FullCalendar
class="fc"
:options="{
...options,
events: filteredEvents as any
}"
>
</FullCalendar>

</div>

<!-- Dialogs -->
Expand Down
7 changes: 4 additions & 3 deletions client/src/components/CshrToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
</template>

<script lang="ts">
import { computed, ref, type Ref } from 'vue'
import { computed, onMounted, ref, type Ref } from 'vue'
import { useAsyncState } from '@vueuse/core'
import { useApi } from '@/hooks'
import { formatDate, getStatusColor } from '@/utils'
Expand All @@ -135,11 +135,12 @@ export default {

const notifications = computed(() => notificationStore.notifications)

setTimeout(() => {
onMounted(async () => {
await user.execute();
if (!user.state.value) {
window.location.href = '/login'
}
}, 1000)
})

const loadNotifications = async () => {
const notificationData = await $api.notifications.list()
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/SideDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ export default {
const filteredItems = computed(() =>
navItems.filter((item: any) => {
return (
user.value?.fullUser.user_type.toLowerCase() === 'admin' || item.path !== '/dashboard'
user.value?.fullUser && user.value?.fullUser.user_type.toLowerCase() === 'admin' || item.path !== '/dashboard'
)
})
)

function logout() {
console.log("Logged out..")
$api.auth.logout()
$router.push('/login')
}
Expand Down
70 changes: 35 additions & 35 deletions server/cshr/services/landing_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@
wrap_vacation_request,
)

from concurrent.futures import ThreadPoolExecutor


def landing_page_calendar_functionality(user: User, month: str, year: str) -> List[Any]:
response: List[Any] = []

# Fetch vacations
vacations = filter_vacations_by_month_and_year(month, year).order_by("-created_at")
for vacation in vacations:
vacation_data = wrap_vacation_request(vacation)
response.append(vacation_data)

# Fetch meetings
meetings = filter_meetings_by_month_and_year(user, month, year).order_by(
"-created_at"
)
for meeting in meetings:
meeting_data = wrap_meeting_request(meeting)
response.append(meeting_data)

# Fetch events
events = filter_events_by_month_and_year(user, month, year).order_by("-created_at")
for event in events:
event_data = wrap_event_request(event)
response.append(event_data)

# Fetch users' birthdays
users_birthdates = filter_users_by_birth_month(month).order_by("-created_at")
for birthday_user in users_birthdates:
birthday_data = wrap_birthday_event(birthday_user)
response.append(birthday_data)

# Fetch public holidays
public_holidays = filter_public_holidays_by_month_and_year(year, month).order_by(
"-created_at"
)
for holiday in public_holidays:
holiday_data = wrap_holiday_request(holiday)
response.append(holiday_data)

return response
with ThreadPoolExecutor() as executor:
future_vacations = executor.submit(filter_vacations_by_month_and_year, month, year)
future_meetings = executor.submit(filter_meetings_by_month_and_year, user, month, year)
future_events = executor.submit(filter_events_by_month_and_year, user, month, year)
future_birthdays = executor.submit(filter_users_by_birth_month, month)
future_holidays = executor.submit(filter_public_holidays_by_month_and_year, year, month)

# Add vacations to response
for vacation in future_vacations.result():
vacation_data = wrap_vacation_request(vacation)
response.append(vacation_data)

# Add meetings to response
for meeting in future_meetings.result():
meeting_data = wrap_meeting_request(meeting)
response.append(meeting_data)

# Add events to response
for event in future_events.result():
event_data = wrap_event_request(event)
response.append(event_data)

# Add birthdays to response
for birthday_user in future_birthdays.result():
birthday_data = wrap_birthday_event(birthday_user)
response.append(birthday_data)

# Add public holidays to response
for holiday in future_holidays.result():
holiday_data = wrap_holiday_request(holiday)
response.append(holiday_data)

return response
8 changes: 4 additions & 4 deletions server/cshr/services/meetings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import List

from cshr.models.users import User
from django.db.models import Prefetch



def get_meeting_by_id(id: str) -> Meetings:
Expand All @@ -20,15 +22,13 @@ def get_all_meetings() -> Meetings:


def filter_meetings_by_month_and_year(user: User, month: str, year: str) -> Meetings:
"""
This function will filter all of meetings based on its yesr, month.
"""
meetings: List[Meetings] = Meetings.objects.filter(
date__month=month, date__year=year
).prefetch_related(
Prefetch('event_participants', queryset=User.objects.only('id', 'full_name'))
)
return meetings


def filter_meetings_by_day(year: int, month: int, day: int) -> List[Meetings]:
"""Filter all users by birthdates"""
return Meetings.objects.filter(date__year=year, date__month=month, date__day=day)
18 changes: 3 additions & 15 deletions server/cshr/services/vacations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,10 @@


def filter_vacations_by_month_and_year(month: str, year: str) -> Vacation:
"""
This function will filter all of vacations based on its yesr, month.
"""
vacations: QuerySet[Vacation] = Vacation.objects.filter(
Q(
from_date__month=month,
from_date__year=year,
)
| Q(
end_date__month=month,
end_date__year=year,
)
)
vacations = vacations.exclude(status=STATUS_CHOICES.REJECTED).exclude(
status=STATUS_CHOICES.CANCELED
)
Q(from_date__month=month, from_date__year=year) |
Q(end_date__month=month, end_date__year=year)
).exclude(status__in=[STATUS_CHOICES.REJECTED, STATUS_CHOICES.CANCELED]).select_related('applying_user')
return vacations


Expand Down
6 changes: 3 additions & 3 deletions server/cshr/utils/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def wrap_vacation_request(vacation: Vacation) -> LandingPageVacationsSerializer:
vacation_data["type"] = LandingPageTypeEnum.VACATION.value
vacation_data["applying_user_full_name"] = vacation.applying_user.full_name
vacation_data["actual_days"] = vacation.actual_days
vacation_data["approvals"] = build_user_reporting_to_hierarchy(
vacation.applying_user
)
# vacation_data["approvals"] = build_user_reporting_to_hierarchy(
# vacation.applying_user
# )
return vacation_data


Expand Down
13 changes: 11 additions & 2 deletions server/cshr/views/landing_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any

from cshr.services.landing_page import landing_page_calendar_functionality
from django.core.cache import cache


class LandingPageApiView(GenericAPIView):
Expand All @@ -14,5 +15,13 @@ class LandingPageApiView(GenericAPIView):
def get(self, request):
month: str = request.query_params.get("month")
year: str = request.query_params.get("year")
events: Any = landing_page_calendar_functionality(request.user, month, year)
return CustomResponse.success(data=events)

# Use cache to store results if the same request is made frequently
cache_key = f"landing_page_{request.user.id}_{month}_{year}"
events = cache.get(cache_key)

if not events:
events: Any = landing_page_calendar_functionality(request.user, month, year)
cache.set(cache_key, events, timeout=60*10) # Cache for 10 minutes

return CustomResponse.success(data=events)