Skip to content

Commit

Permalink
refactor: merge main, clean up open content frontend, add routes
Browse files Browse the repository at this point in the history
  • Loading branch information
calisio committed Nov 25, 2024
1 parent ffd5cca commit 662098c
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 129 deletions.
6 changes: 4 additions & 2 deletions backend/src/database/open_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,14 @@ func (db *DB) GetTopUserOpenContent(id int) ([]models.OpenContentItem, error) {
Table("open_content_activities oca").
Joins("LEFT JOIN videos v ON v.id = oca.content_id AND v.open_content_provider_id = oca.open_content_provider_id AND v.visibility_status = TRUE").
Where("oca.user_id = ?", id).
Group("v.title, v.url, v.thumbnail_url, v.open_content_provider_id, v.id"),
Group("v.title, v.url, v.thumbnail_url, v.open_content_provider_id, v.id").
Having("count(v.id) > 0"),
db.Select("l.name, l.path as url, l.image_url as thumbnail_url, l.open_content_provider_id, l.id as content_id, 'library' as type, count(l.id) as visits").
Table("open_content_activities oca").
Joins("LEFT JOIN libraries l on l.id = oca.content_id AND l.open_content_provider_id = oca.open_content_provider_id AND l.visibility_status = TRUE").
Where("oca.user_id = ?", id).
Group("l.name, l.path, l.image_url, l.open_content_provider_id, l.id"),
Group("l.name, l.path, l.image_url, l.open_content_provider_id, l.id").
Having("count(l.id) > 0"),
).Find(&content).Error; err != nil {
return nil, newGetRecordsDBError(err, "open_content_items")
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/open_content_activity_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func (srv *Server) registerOpenContentActivityRoutes() []routeDef {
axx := models.Feature(models.OpenContentAccess)
return []routeDef{
{"GET /api/open-content/activity", srv.handleGetTopFacilityOpenContent, false, axx},
{"PUT /api/open-content/activity/{id}", srv.handleGetTopUserOpenContent, false, axx},
{"GET /api/open-content/activity/{id}", srv.handleGetTopUserOpenContent, false, axx},
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (srv *Server) RegisterRoutes() {
srv.registerOryRoutes,
srv.registerFacilitiesRoutes,
srv.registerOpenContentRoutes,
srv.registerOpenContentActivityRoutes,
srv.registerLibraryRoutes,
srv.registerProgramsRoutes,
srv.registerSectionsRoutes,
Expand All @@ -88,6 +87,7 @@ func (srv *Server) RegisterRoutes() {
srv.registerAttendanceRoutes,
srv.registerVideoRoutes,
srv.registerFeatureFlagRoutes,
srv.registerOpenContentActivityRoutes,
} {
srv.register(route)
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/Components/LibraryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function LibraryCard({
<div className="flex p-4 gap-2 border-b-2">
<figure className="w-[48px] h-[48px] bg-cover">
<img
src={library.thumbnail_url ?? ''}
src={library.image_url ?? ''}
alt={`${library.name} thumbnail`}
/>
</figure>
Expand All @@ -89,7 +89,7 @@ export default function LibraryCard({
<div onClick={(e: MouseEvent) => void toggleFavorite(e)}>
<ULIComponent
tooltipClassName={'absolute right-2 top-2 z-100'}
iconClassName={`w-6 h-6 ${library.is_favorited ? 'text-primary-yellow' : ''}`}
iconClassName={`w-5 h-5 ${library.is_favorited ? 'text-primary-yellow' : ''}`}
icon={library.is_favorited ? StarIcon : StarIconOutline}
dataTip="Favorite Library"
/>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/Components/LibraryLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function LibaryLayout({
}, [filterLibrariesAdmin, filterLibraries, searchTerm]);

return (
<div className="px-8">
<div className="flex flex-col gap-8">
<div className="flex flex-row gap-4">
<SearchBar
searchTerm={searchTerm}
Expand All @@ -97,7 +97,7 @@ export default function LibaryLayout({
/>
)}
</div>
<div className="grid grid-cols-4 pb-8 pt-8 gap-6">
<div className="grid grid-cols-4 gap-6">
{libraries?.data.map((library) => (
<LibraryCard
key={library.id}
Expand Down
85 changes: 54 additions & 31 deletions frontend/src/Components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ export default function Navbar({
{user && isAdministrator(user) ? (
<>
{/* admin view */}
<li className="mt-16">
<Link to="/admin-dashboard">
<ULIComponent icon={HomeIcon} />
Dashboard
</Link>
</li>
<li>
<Link to="/student-management">
<ULIComponent icon={AcademicCapIcon} />
Students
</Link>
</li>
<li>
<Link to="/admin-management">
<ULIComponent icon={UsersIcon} />
Admins
</Link>
</li>
{hasFeature(
user,
FeatureAccess.OpenContentAccess
) && user.feature_access.length === 1 ? (
<li className="mt-16">
<Link to="/open-content-dashboard">
<ULIComponent icon={HomeIcon} />
Dashboard
</Link>
</li>
) : (
<li className="mt-16">
<Link to="/admin-dashboard">
<ULIComponent icon={HomeIcon} />
Dashboard
</Link>
</li>
)}
{hasFeature(
user,
FeatureAccess.OpenContentAccess
Expand All @@ -105,12 +105,6 @@ export default function Navbar({
</li>
</>
)}
<li>
<Link to="/resources-management">
<ULIComponent icon={ArchiveBoxIcon} />
Resources
</Link>
</li>
{hasFeature(
user,
FeatureAccess.ProviderAccess
Expand Down Expand Up @@ -147,6 +141,24 @@ export default function Navbar({
</Link>
</li>
)}
<li>
<Link to="/student-management">
<ULIComponent icon={AcademicCapIcon} />
Students
</Link>
</li>
<li>
<Link to="/admin-management">
<ULIComponent icon={UsersIcon} />
Admins
</Link>
</li>
<li>
<Link to="/resources-management">
<ULIComponent icon={ArchiveBoxIcon} />
Resources
</Link>
</li>
<li>
<Link to="/facilities-management">
<ULIComponent
Expand All @@ -158,13 +170,24 @@ export default function Navbar({
</>
) : (
<>
{/* student view */}
<li className="mt-16">
<Link to="/student-dashboard">
<ULIComponent icon={HomeIcon} />
Dashboard
</Link>
</li>
{hasFeature(
user,
FeatureAccess.OpenContentAccess
) && user.feature_access.length === 1 ? (
<li className="mt-16">
<Link to="/open-content-dashboard">
<ULIComponent icon={HomeIcon} />
Dashboard
</Link>
</li>
) : (
<li className="mt-16">
<Link to="/student-dashboard">
<ULIComponent icon={HomeIcon} />
Dashboard
</Link>
</li>
)}
{hasFeature(
user,
FeatureAccess.ProviderAccess
Expand Down
93 changes: 44 additions & 49 deletions frontend/src/Components/VideoContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,56 +53,51 @@ export default function VideoContent() {
};

return (
<div>
<div className="flex flex-col space-y-6 overflow-x-auto rounded-lg p-4 px-8">
<h1>Videos</h1>
<div className="flex justify-between">
<div className="flex flex-row gap-x-2">
<SearchBar
searchTerm={searchTerm}
changeCallback={handleChange}
/>
<DropdownControl
label="Order by"
setState={setSortQuery}
enumType={{
'Title (A-Z)': 'title ASC',
'Title (Z-A)': 'title DESC',
'Date Added ↓': 'created_at DESC',
'Date Added ↑': 'created_at ASC',
Favorited: 'favorited'
}}
/>
</div>
</div>
<div className="grid grid-cols-4 gap-6">
{videoData.map((video) => (
<VideoCard
key={video.id}
video={video}
mutate={mutate}
role={UserRole.Student}
/>
))}
</div>
{!isLoading && !error && meta && (
<div className="flex justify-center">
<Pagination
meta={meta}
setPage={setPageQuery}
setPerPage={handleSetPerPage}
/>
</div>
)}
{error && (
<span className="text-center text-error">
Failed to load videos.
</span>
)}
{!isLoading && !error && videoData.length === 0 && (
<span className="text-center text-warning">No results</span>
)}
<div className="flex flex-col gap-8">
<div className="flex flex-row gap-4">
<SearchBar
searchTerm={searchTerm}
changeCallback={handleChange}
/>
<DropdownControl
label="Order by"
setState={setSortQuery}
enumType={{
'Title (A-Z)': 'title ASC',
'Title (Z-A)': 'title DESC',
'Date Added ↓': 'created_at DESC',
'Date Added ↑': 'created_at ASC',
Favorited: 'favorited'
}}
/>
</div>
<div className="grid grid-cols-4 gap-6">
{videoData.map((video) => (
<VideoCard
key={video.id}
video={video}
mutate={mutate}
role={UserRole.Student}
/>
))}
</div>
{!isLoading && !error && meta && (
<div className="flex justify-center">
<Pagination
meta={meta}
setPage={setPageQuery}
setPerPage={handleSetPerPage}
/>
</div>
)}
{error && (
<span className="text-center text-error">
Failed to load videos.
</span>
)}
{!isLoading && !error && videoData.length === 0 && (
<span className="text-center text-warning">No results</span>
)}
</div>
);
}
15 changes: 8 additions & 7 deletions frontend/src/Components/cards/OpenContentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export default function OpenContentCardRow({
}) {
const navigate = useNavigate();
function redirectToViewer() {
if ('url' in content) {
if (content.type === 'video') {
navigate(`/viewer/videos/${content.content_id}`);
} else if (content.type === 'library') {
navigate(`/viewer/libraries/${content.content_id}`);
}
}
const isFavorite = !('url' in content);
const type = isFavorite ? content.content_type : content.type;
const basePath =
type === 'video'
? `/viewer/videos/${content.content_id}`
: `/viewer/libraries/${content.content_id}`;

navigate(basePath);
}

return (
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/Pages/Favorites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export default function FavoritesPage() {
};

return (
<div className="w-full p-8 ">
My Favorites
<div className="flex flex-col gap-8">
<div className="grid grid-cols-4 gap-6">
{favorites.map((favorite) => (
<FavoriteCard
Expand All @@ -53,7 +52,7 @@ export default function FavoritesPage() {
<p>No favorites found.</p>
)}
{!isLoading && !error && meta && (
<div className="flex justify-center mt-4">
<div className="flex justify-center">
<Pagination
meta={meta}
setPage={setPageQuery}
Expand Down
29 changes: 27 additions & 2 deletions frontend/src/Pages/OpenContentLevelDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import {
OpenContentFavorite,
OpenContentItem,
ResourceCategory
ResourceCategory,
UserRole
} from '@/common';
import OpenContentCard from '@/Components/cards/OpenContentCard';
import ResourcesCategoryCard from '@/Components/ResourcesCategoryCard';
import ULIComponent from '@/Components/ULIComponent';
import { useAuth } from '@/useAuth';
import { useLoaderData } from 'react-router-dom';
import { ArrowTopRightOnSquareIcon } from '@heroicons/react/24/outline';
import { useLoaderData, useNavigate } from 'react-router-dom';

export default function OpenContentLevelDashboard() {
const { user } = useAuth();
const navigate = useNavigate();
const { resources, topUserContent, topFacilityContent, favorites } =
useLoaderData() as {
resources: ResourceCategory[];
Expand All @@ -18,6 +22,14 @@ export default function OpenContentLevelDashboard() {
favorites: OpenContentFavorite[];
};

function navigateToOpenContent() {
if (user?.role == UserRole.Student) {
navigate(`/open-content/libraries`);
} else {
navigate(`/open-content-management/libraries`);
}
}

return (
<div className="flex flex-row h-full">
{/* main section */}
Expand All @@ -37,6 +49,19 @@ export default function OpenContentLevelDashboard() {
/>
);
})}
{topUserContent.length < 5 && (
<div
className="card px-4 py-2 flex flex-row gap-2 items-center"
onClick={navigateToOpenContent}
>
<ULIComponent
tooltipClassName="h-12 flex items-center"
iconClassName="w-5 h-5"
icon={ArrowTopRightOnSquareIcon}
/>
<h3>Explore open content offered</h3>
</div>
)}
</div>
<div className="card card-row-padding flex flex-col gap-3">
<h2>Popular Open Content</h2>
Expand Down
Loading

0 comments on commit 662098c

Please sign in to comment.