diff --git a/backend/__pycache__/seed.cpython-312.pyc b/backend/__pycache__/seed.cpython-312.pyc index 1c25c33..a59b338 100644 Binary files a/backend/__pycache__/seed.cpython-312.pyc and b/backend/__pycache__/seed.cpython-312.pyc differ diff --git a/backend/app/__pycache__/main.cpython-312.pyc b/backend/app/__pycache__/main.cpython-312.pyc index 3ee04a6..070a407 100644 Binary files a/backend/app/__pycache__/main.cpython-312.pyc and b/backend/app/__pycache__/main.cpython-312.pyc differ diff --git a/backend/app/__pycache__/models.cpython-312.pyc b/backend/app/__pycache__/models.cpython-312.pyc index 026edc8..49ca2e0 100644 Binary files a/backend/app/__pycache__/models.cpython-312.pyc and b/backend/app/__pycache__/models.cpython-312.pyc differ diff --git a/backend/app/__pycache__/schemas.cpython-312.pyc b/backend/app/__pycache__/schemas.cpython-312.pyc index c9e4a75..085474c 100644 Binary files a/backend/app/__pycache__/schemas.cpython-312.pyc and b/backend/app/__pycache__/schemas.cpython-312.pyc differ diff --git a/backend/app/api/__pycache__/community.cpython-312.pyc b/backend/app/api/__pycache__/community.cpython-312.pyc new file mode 100644 index 0000000..bd3c7d0 Binary files /dev/null and b/backend/app/api/__pycache__/community.cpython-312.pyc differ diff --git a/backend/app/api/__pycache__/history.cpython-312.pyc b/backend/app/api/__pycache__/history.cpython-312.pyc new file mode 100644 index 0000000..d6255b0 Binary files /dev/null and b/backend/app/api/__pycache__/history.cpython-312.pyc differ diff --git a/backend/app/api/__pycache__/team.cpython-312.pyc b/backend/app/api/__pycache__/team.cpython-312.pyc new file mode 100644 index 0000000..d832322 Binary files /dev/null and b/backend/app/api/__pycache__/team.cpython-312.pyc differ diff --git a/backend/app/api/community.py b/backend/app/api/community.py new file mode 100644 index 0000000..2ab7611 --- /dev/null +++ b/backend/app/api/community.py @@ -0,0 +1,79 @@ +from typing import Optional + +from fastapi import APIRouter, Depends, Query +from sqlalchemy import select +from sqlalchemy.ext.asyncio import AsyncSession + +from app.auth import get_current_admin_user +from app.database import get_session +from app.models import CommunityHighlight +from app.schemas import CommunityHighlightCreate, CommunityHighlightUpdate, CommunityHighlightResponse +from app.user_models import User + +router = APIRouter() + + +@router.get("/", response_model=list[CommunityHighlightResponse]) +async def list_community_highlights( + active: Optional[bool] = Query(None, description="Filter by active status"), + session: AsyncSession = Depends(get_session), +): + query = select(CommunityHighlight).order_by(CommunityHighlight.display_order) + if active is not None: + query = query.where(CommunityHighlight.active == active) + result = await session.execute(query) + return list(result.scalars().all()) + + +@router.get("/{highlight_id}", response_model=CommunityHighlightResponse) +async def get_community_highlight(highlight_id: int, session: AsyncSession = Depends(get_session)): + result = await session.execute(select(CommunityHighlight).where(CommunityHighlight.id == highlight_id)) + highlight = result.scalar_one_or_none() + if not highlight: + return {"error": "Community highlight not found"} + return highlight + + +@router.post("/", response_model=CommunityHighlightResponse, status_code=201) +async def create_community_highlight( + payload: CommunityHighlightCreate, + session: AsyncSession = Depends(get_session), + _: User = Depends(get_current_admin_user), +): + highlight = CommunityHighlight(**payload.model_dump(), active=True) + session.add(highlight) + await session.commit() + await session.refresh(highlight) + return highlight + + +@router.put("/{highlight_id}", response_model=CommunityHighlightResponse) +async def update_community_highlight( + highlight_id: int, + payload: CommunityHighlightUpdate, + session: AsyncSession = Depends(get_session), + _: User = Depends(get_current_admin_user), +): + result = await session.execute(select(CommunityHighlight).where(CommunityHighlight.id == highlight_id)) + highlight = result.scalar_one_or_none() + if not highlight: + return {"error": "Community highlight not found"} + for key, value in payload.model_dump(exclude_unset=True).items(): + setattr(highlight, key, value) + await session.commit() + await session.refresh(highlight) + return highlight + + +@router.delete("/{highlight_id}", status_code=204) +async def delete_community_highlight( + highlight_id: int, + session: AsyncSession = Depends(get_session), + _: User = Depends(get_current_admin_user), +): + result = await session.execute(select(CommunityHighlight).where(CommunityHighlight.id == highlight_id)) + highlight = result.scalar_one_or_none() + if not highlight: + return {"error": "Community highlight not found"} + await session.delete(highlight) + await session.commit() diff --git a/backend/app/api/history.py b/backend/app/api/history.py new file mode 100644 index 0000000..d791741 --- /dev/null +++ b/backend/app/api/history.py @@ -0,0 +1,79 @@ +from typing import Optional + +from fastapi import APIRouter, Depends, Query +from sqlalchemy import select +from sqlalchemy.ext.asyncio import AsyncSession + +from app.auth import get_current_admin_user +from app.database import get_session +from app.models import HistoryEntry +from app.schemas import HistoryEntryCreate, HistoryEntryUpdate, HistoryEntryResponse +from app.user_models import User + +router = APIRouter() + + +@router.get("/", response_model=list[HistoryEntryResponse]) +async def list_history_entries( + active: Optional[bool] = Query(None, description="Filter by active status"), + session: AsyncSession = Depends(get_session), +): + query = select(HistoryEntry).order_by(HistoryEntry.display_order) + if active is not None: + query = query.where(HistoryEntry.active == active) + result = await session.execute(query) + return list(result.scalars().all()) + + +@router.get("/{entry_id}", response_model=HistoryEntryResponse) +async def get_history_entry(entry_id: int, session: AsyncSession = Depends(get_session)): + result = await session.execute(select(HistoryEntry).where(HistoryEntry.id == entry_id)) + entry = result.scalar_one_or_none() + if not entry: + return {"error": "History entry not found"} + return entry + + +@router.post("/", response_model=HistoryEntryResponse, status_code=201) +async def create_history_entry( + payload: HistoryEntryCreate, + session: AsyncSession = Depends(get_session), + _: User = Depends(get_current_admin_user), +): + entry = HistoryEntry(**payload.model_dump(), active=True) + session.add(entry) + await session.commit() + await session.refresh(entry) + return entry + + +@router.put("/{entry_id}", response_model=HistoryEntryResponse) +async def update_history_entry( + entry_id: int, + payload: HistoryEntryUpdate, + session: AsyncSession = Depends(get_session), + _: User = Depends(get_current_admin_user), +): + result = await session.execute(select(HistoryEntry).where(HistoryEntry.id == entry_id)) + entry = result.scalar_one_or_none() + if not entry: + return {"error": "History entry not found"} + for key, value in payload.model_dump(exclude_unset=True).items(): + setattr(entry, key, value) + await session.commit() + await session.refresh(entry) + return entry + + +@router.delete("/{entry_id}", status_code=204) +async def delete_history_entry( + entry_id: int, + session: AsyncSession = Depends(get_session), + _: User = Depends(get_current_admin_user), +): + result = await session.execute(select(HistoryEntry).where(HistoryEntry.id == entry_id)) + entry = result.scalar_one_or_none() + if not entry: + return {"error": "History entry not found"} + await session.delete(entry) + await session.commit() diff --git a/backend/app/api/team.py b/backend/app/api/team.py new file mode 100644 index 0000000..f28ac56 --- /dev/null +++ b/backend/app/api/team.py @@ -0,0 +1,79 @@ +from typing import Optional + +from fastapi import APIRouter, Depends, Query +from sqlalchemy import select +from sqlalchemy.ext.asyncio import AsyncSession + +from app.auth import get_current_admin_user +from app.database import get_session +from app.models import TeamMember +from app.schemas import TeamMemberCreate, TeamMemberUpdate, TeamMemberResponse +from app.user_models import User + +router = APIRouter() + + +@router.get("/", response_model=list[TeamMemberResponse]) +async def list_team_members( + active: Optional[bool] = Query(None, description="Filter by active status"), + session: AsyncSession = Depends(get_session), +): + query = select(TeamMember).order_by(TeamMember.display_order) + if active is not None: + query = query.where(TeamMember.active == active) + result = await session.execute(query) + return list(result.scalars().all()) + + +@router.get("/{member_id}", response_model=TeamMemberResponse) +async def get_team_member(member_id: int, session: AsyncSession = Depends(get_session)): + result = await session.execute(select(TeamMember).where(TeamMember.id == member_id)) + member = result.scalar_one_or_none() + if not member: + return {"error": "Team member not found"} + return member + + +@router.post("/", response_model=TeamMemberResponse, status_code=201) +async def create_team_member( + payload: TeamMemberCreate, + session: AsyncSession = Depends(get_session), + _: User = Depends(get_current_admin_user), +): + member = TeamMember(**payload.model_dump(), active=True) + session.add(member) + await session.commit() + await session.refresh(member) + return member + + +@router.put("/{member_id}", response_model=TeamMemberResponse) +async def update_team_member( + member_id: int, + payload: TeamMemberUpdate, + session: AsyncSession = Depends(get_session), + _: User = Depends(get_current_admin_user), +): + result = await session.execute(select(TeamMember).where(TeamMember.id == member_id)) + member = result.scalar_one_or_none() + if not member: + return {"error": "Team member not found"} + for key, value in payload.model_dump(exclude_unset=True).items(): + setattr(member, key, value) + await session.commit() + await session.refresh(member) + return member + + +@router.delete("/{member_id}", status_code=204) +async def delete_team_member( + member_id: int, + session: AsyncSession = Depends(get_session), + _: User = Depends(get_current_admin_user), +): + result = await session.execute(select(TeamMember).where(TeamMember.id == member_id)) + member = result.scalar_one_or_none() + if not member: + return {"error": "Team member not found"} + await session.delete(member) + await session.commit() diff --git a/backend/app/main.py b/backend/app/main.py index 4dc0a10..fabf42b 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -8,9 +8,9 @@ from sqlalchemy import func, select from app.config import settings from app.database import async_session, engine -from app.models import Base, Program, StationConfig +from app.models import Base, Program, StationConfig, HistoryEntry, TeamMember, CommunityHighlight from app.user_models import User -from app.api import programs, events, tiers, auth, station_config +from app.api import programs, events, tiers, auth, station_config, history, team, community async def _ensure_station_config(session): @@ -96,6 +96,9 @@ app.include_router(programs.router, prefix="/api/programs", tags=["programs"]) app.include_router(events.router, prefix="/api/events", tags=["events"]) app.include_router(tiers.router, prefix="/api/tiers", tags=["tiers"]) app.include_router(station_config.router, prefix="/api/station-config", tags=["station-config"]) +app.include_router(history.router, prefix="/api/history", tags=["history"]) +app.include_router(team.router, prefix="/api/team", tags=["team"]) +app.include_router(community.router, prefix="/api/community", tags=["community"]) # Serve uploaded files (dev only — Nginx handles this in production) if settings.ENV != "production": diff --git a/backend/app/models.py b/backend/app/models.py index 7b93e09..00199b4 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -80,3 +80,37 @@ class StationConfig(Base): phone = Column(String(30), nullable=False, default="(970) 555-0198") email = Column(String(100), nullable=False, default="hello@kmountainflower.org") website = Column(String(200), nullable=False, default="kmountainflower.org") + + +class HistoryEntry(Base): + __tablename__ = "history_entries" + + id = Column(Integer, primary_key=True, autoincrement=True) + year = Column(Integer, nullable=False) + title = Column(String(200), nullable=False) + body = Column(Text, nullable=False) + display_order = Column(Integer, nullable=False) + active = Column(Boolean, default=True) + + +class TeamMember(Base): + __tablename__ = "team_members" + + id = Column(Integer, primary_key=True, autoincrement=True) + name = Column(String(100), nullable=False) + title = Column(String(150), nullable=False) + bio = Column(Text, nullable=True) + photo_url = Column(String(500), nullable=True) + display_order = Column(Integer, nullable=False) + active = Column(Boolean, default=True) + + +class CommunityHighlight(Base): + __tablename__ = "community_highlights" + + id = Column(Integer, primary_key=True, autoincrement=True) + icon = Column(String(10), nullable=False) + title = Column(String(200), nullable=False) + description = Column(Text, nullable=False) + display_order = Column(Integer, nullable=False) + active = Column(Boolean, default=True) diff --git a/backend/app/schemas.py b/backend/app/schemas.py index 68ea471..41e107d 100644 --- a/backend/app/schemas.py +++ b/backend/app/schemas.py @@ -156,3 +156,90 @@ class StationConfigUpdate(BaseModel): phone: Optional[str] = None email: Optional[str] = None website: Optional[str] = None + + +# ── HistoryEntry ────────────────────────────────────────── + +class HistoryEntryCreate(BaseModel): + year: int + title: str + body: str + display_order: int + + +class HistoryEntryUpdate(BaseModel): + year: Optional[int] = None + title: Optional[str] = None + body: Optional[str] = None + display_order: Optional[int] = None + active: Optional[bool] = None + + +class HistoryEntryResponse(BaseModel): + id: int + year: int + title: str + body: str + display_order: int + active: bool + + model_config = {"from_attributes": True} + + +# ── TeamMember ───────────────────────────────────────────── + +class TeamMemberCreate(BaseModel): + name: str + title: str + bio: Optional[str] = None + photo_url: Optional[str] = None + display_order: int + + +class TeamMemberUpdate(BaseModel): + name: Optional[str] = None + title: Optional[str] = None + bio: Optional[str] = None + photo_url: Optional[str] = None + display_order: Optional[int] = None + active: Optional[bool] = None + + +class TeamMemberResponse(BaseModel): + id: int + name: str + title: str + bio: Optional[str] + photo_url: Optional[str] + display_order: int + active: bool + + model_config = {"from_attributes": True} + + +# ── CommunityHighlight ───────────────────────────────────── + +class CommunityHighlightCreate(BaseModel): + icon: str + title: str + description: str + display_order: int + + +class CommunityHighlightUpdate(BaseModel): + icon: Optional[str] = None + title: Optional[str] = None + description: Optional[str] = None + display_order: Optional[int] = None + active: Optional[bool] = None + + +class CommunityHighlightResponse(BaseModel): + id: int + icon: str + title: str + description: str + display_order: int + active: bool + + model_config = {"from_attributes": True} diff --git a/backend/seed.py b/backend/seed.py index ab2f416..6ea4fcb 100644 --- a/backend/seed.py +++ b/backend/seed.py @@ -15,6 +15,7 @@ from sqlalchemy import select from app.database import async_session from app.models import Program, Event, DonationTier, StationConfig +from app.models import HistoryEntry, TeamMember, CommunityHighlight # ── Seed data ────────────────────────────────────────────── @@ -113,6 +114,91 @@ STATION_CONFIG: dict = { "website": "kmountainflower.org", } +HISTORY_ENTRIES: list[dict] = [ + { + "year": 1987, + "title": "The Idea Takes Root", + "body": "A small group of mountain residents gathered around a kitchen table with a shared dream: a radio station owned by the community, for the community. With nothing but conviction and a stack of handwritten letters to the FCC, they began the long road toward bringing independent radio to the high country.", + "display_order": 1, + }, + { + "year": 1991, + "title": "FCC License Granted", + "body": "After years of paperwork, public hearings, and grassroots fundraising, the Federal Communications Commission approved the construction permit. The call sign KMTN was chosen — a nod to the mountain terrain that defines the region and the people who call it home.", + "display_order": 2, + }, + { + "year": 1995, + "title": "First Broadcast", + "body": "On a crisp September morning, KMTN signed on the air for the first time. The opening broadcast featured a live bluegrass set from the studio, followed by interviews with local farmers, teachers, and business owners. The signal reached every valley and ridge within a 40-mile radius.", + "display_order": 3, + }, + { + "year": 2008, + "title": "Studio Expansion", + "body": "A generous community-driven capital campaign funded the construction of a new broadcast studio — doubling production space and adding a dedicated live-performance room. The expansion also brought upgraded transmission equipment, extending the station's reach to surrounding counties.", + "display_order": 4, + }, +] + +TEAM_MEMBERS: list[dict] = [ + { + "name": "Margaret Ellis", + "title": "Board Chair", + "bio": "Margaret has served on the KMTN board for over fifteen years. A retired schoolteacher, she believes community radio is the backbone of civic engagement.", + "photo_url": None, + "display_order": 1, + }, + { + "name": "James Whitfield", + "title": "General Manager", + "bio": "James joined KMTN as a volunteer DJ in 2002 and has been steering the station's operations ever since. He oversees programming, finance, and community outreach.", + "photo_url": None, + "display_order": 2, + }, + { + "name": "Dr. Priya Nair", + "title": "Program Director", + "bio": "Dr. Nair brings two decades of media experience to KMTN. She curates the station's diverse lineup and mentors the next generation of local broadcasters.", + "photo_url": None, + "display_order": 3, + }, + { + "name": "Carlos Mendez", + "title": "Community Outreach Coordinator", + "bio": "Carlos organizes station events, volunteer drives, and school partnerships. His Evening Echoes show is one of the station's most-listened-to programs.", + "photo_url": None, + "display_order": 4, + }, +] + +COMMUNITY_HIGHLIGHTS: list[dict] = [ + { + "icon": "🎵", + "title": "Our Music", + "description": "From bluegrass and folk to jazz and classical, our playlists reflect the rich cultural tapestry of the high country and its neighbors. We feature local artists alongside the world's best voices.", + "display_order": 1, + }, + { + "icon": "🤝", + "title": "Our Community", + "description": "Every show is staffed by volunteers who live and work in these mountains. From high school DJs to retired teachers, our team is your community — passionate about sharing what they love.", + "display_order": 2, + }, + { + "icon": "📡", + "title": "Our Reach", + "description": "Over the air on 98.7 FM and streaming live worldwide. Whether you're hiking the ridgeline or on the other side of the planet, our signal — and our welcome — goes everywhere.", + "display_order": 3, + }, + { + "icon": "🌱", + "title": "Our Mission", + "description": "To keep public radio free, independent, and deeply rooted in place. No corporate advertising, no spin — just music, conversation, and community served with care.", + "display_order": 4, + }, +] + # ── Helpers ──────────────────────────────────────────────── @@ -174,6 +260,51 @@ async def _upsert_station_config(session, data: dict) -> None: session.add(StationConfig(**data)) +async def _upsert_history_entry(session, data: dict) -> None: + """Get-or-create a history entry matched on (year, title).""" + existing = await session.execute( + select(HistoryEntry).where( + HistoryEntry.year == data["year"], + HistoryEntry.title == data["title"], + ) + ) + entry = existing.scalar_one_or_none() + if entry: + for key, value in data.items(): + setattr(entry, key, value) + else: + session.add(HistoryEntry(**data, active=True)) + + +async def _upsert_team_member(session, data: dict) -> None: + """Get-or-create a team member matched on name.""" + existing = await session.execute( + select(TeamMember).where(TeamMember.name == data["name"]) + ) + member = existing.scalar_one_or_none() + if member: + for key, value in data.items(): + setattr(member, key, value) + else: + session.add(TeamMember(**data, active=True)) + + +async def _upsert_community_highlight(session, data: dict) -> None: + """Get-or-create a community highlight matched on (icon, title).""" + existing = await session.execute( + select(CommunityHighlight).where( + CommunityHighlight.icon == data["icon"], + CommunityHighlight.title == data["title"], + ) + ) + highlight = existing.scalar_one_or_none() + if highlight: + for key, value in data.items(): + setattr(highlight, key, value) + else: + session.add(CommunityHighlight(**data, active=True)) + + # ── Main ────────────────────────────────────────────────── async def seed() -> None: @@ -198,6 +329,21 @@ async def seed() -> None: await session.commit() print(" ✓ Seeded station config") + for data in HISTORY_ENTRIES: + await _upsert_history_entry(session, data) + await session.commit() + print(f" ✓ Seeded {len(HISTORY_ENTRIES)} history entries") + + for data in TEAM_MEMBERS: + await _upsert_team_member(session, data) + await session.commit() + print(f" ✓ Seeded {len(TEAM_MEMBERS)} team members") + + for data in COMMUNITY_HIGHLIGHTS: + await _upsert_community_highlight(session, data) + await session.commit() + print(f" ✓ Seeded {len(COMMUNITY_HIGHLIGHTS)} community highlights") + async def truncate_all() -> None: """Remove all seed data from the database.""" @@ -206,6 +352,9 @@ async def truncate_all() -> None: await session.execute(Event.__table__.delete()) await session.execute(DonationTier.__table__.delete()) await session.execute(StationConfig.__table__.delete()) + await session.execute(HistoryEntry.__table__.delete()) + await session.execute(TeamMember.__table__.delete()) + await session.execute(CommunityHighlight.__table__.delete()) await session.commit() print(" ✓ Truncated all tables") diff --git a/src/app/about/about.component.html b/src/app/about/about.component.html index eaa1add..f9a35c1 100644 --- a/src/app/about/about.component.html +++ b/src/app/about/about.component.html @@ -1,5 +1,6 @@
+

About {{ config().name_primary }} {{ config().name_secondary }}

@@ -10,45 +11,69 @@

-
-
-
🎵
-

Our Music

-

- From bluegrass and folk to jazz and classical, our playlists reflect - the rich cultural tapestry of the high country and its neighbors. We - feature local artists alongside the world's best voices. -

-
-
-
🤝
-

Our Community

-

- Every show is staffed by volunteers who live and work in these - mountains. From high school DJs to retired teachers, our team is your - community — passionate about sharing what they love. -

-
-
-
📡
-

Our Reach

-

- Over the air on {{ config().frequency }} and streaming live worldwide. Whether you're - hiking the ridgeline or on the other side of the planet, our signal - — and our welcome — goes everywhere. -

-
-
-
🌱
-

Our Mission

-

- To keep public radio free, independent, and deeply rooted in place. - No corporate advertising, no spin — just music, conversation, and - community served with care. -

-
-
+ + @if (communityHighlights$ | async; as highlights) { + @if (highlights.length) { +
+ @for (highlight of highlights; track highlight.id) { +
+
{{ highlight.icon }}
+

{{ highlight.title }}

+

{{ highlight.description }}

+
+ } +
+ } + } + + @if (historyEntries$ | async; as entries) { + @if (entries.length) { +
+

Our History

+
+ @for (entry of entries; track entry.id; let index = $index) { +
+
+ {{ entry.year }} +

{{ entry.title }}

+

{{ entry.body }}

+
+
+ } +
+
+ } + } + + + @if (teamMembers$ | async; as members) { + @if (members.length) { +
+

Our Team

+
+ @for (member of members; track member.id) { +
+
+ @if (member.photo_url) { + + } @else { + {{ member.name.charAt(0) }} + } +
+

{{ member.name }}

+

{{ member.title }}

+ @if (member.bio) { +

{{ member.bio }}

+ } +
+ } +
+
+ } + } + +
+ } + } + + + @if (activeTab() === 'team') { + @if (teamMembers$ | async; as members) { +
+
+

Team Members ({{ members.length }})

+ +
+ + + + + + + + + + + + + @for (member of members; track member.id) { + + + + + + + + } @empty { + + } + +
NameTitleOrderActiveActions
{{ member.name }}{{ member.title }}{{ member.display_order }}{{ member.active ? 'Yes' : 'No' }} + + +
No team members yet. Click "Add Member" to create one.
+
+ } + } + + + @if (activeTab() === 'community') { + @if (communityHighlights$ | async; as highlights) { +
+
+

Community Highlights ({{ highlights.length }})

+ +
+ + + + + + + + + + + + + @for (highlight of highlights; track highlight.id) { + + + + + + + + } @empty { + + } + +
IconTitleOrderActiveActions
{{ highlight.icon }}{{ highlight.title }}{{ highlight.display_order }}{{ highlight.active ? 'Yes' : 'No' }} + + +
No highlights yet. Click "Add Highlight" to create one.
+
+ } + } + @if (activeTab() === 'station') { @if (stationConfig$ | async; as config) { @@ -215,4 +351,13 @@ @if (showStationForm) { } + @if (showHistoryForm) { + + } + @if (showTeamForm) { + + } + @if (showCommunityForm) { + + }
diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index 18efcd0..0d2442b 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -7,16 +7,25 @@ import { Program } from '../interfaces/program'; import { Event } from '../interfaces/event'; import { Tier } from '../interfaces/tier'; import { StationConfig } from '../interfaces/station-config'; +import { HistoryEntry } from '../interfaces/history-entry'; +import { TeamMember } from '../interfaces/team-member'; +import { CommunityHighlight } from '../interfaces/community-highlight'; import { ProgramService } from '../services/program.service'; import { EventService } from '../services/event.service'; import { TierService } from '../services/tier.service'; import { StationConfigService } from '../services/station-config.service'; +import { HistoryEntryService } from '../services/history-entry.service'; +import { TeamMemberService } from '../services/team-member.service'; +import { CommunityHighlightService } from '../services/community-highlight.service'; import { AdminProgramFormComponent } from './admin-program-form.component'; import { AdminEventFormComponent } from './admin-event-form.component'; import { AdminTierFormComponent } from './admin-tier-form.component'; import { AdminStationFormComponent } from './admin-station-form.component'; +import { AdminHistoryFormComponent } from './admin-history-form.component'; +import { AdminTeamFormComponent } from './admin-team-form.component'; +import { AdminCommunityFormComponent } from './admin-community-form.component'; -type TabKey = 'programs' | 'events' | 'tiers' | 'station'; +type TabKey = 'programs' | 'events' | 'tiers' | 'station' | 'history' | 'team' | 'community'; @Component({ selector: 'app-admin', @@ -29,6 +38,9 @@ type TabKey = 'programs' | 'events' | 'tiers' | 'station'; AdminEventFormComponent, AdminTierFormComponent, AdminStationFormComponent, + AdminHistoryFormComponent, + AdminTeamFormComponent, + AdminCommunityFormComponent, ], templateUrl: './admin.component.html', styleUrl: './admin.component.scss', @@ -38,6 +50,9 @@ export class AdminComponent implements OnInit { private eventService = inject(EventService); private tierService = inject(TierService); private stationConfigService = inject(StationConfigService); + private historyEntryService = inject(HistoryEntryService); + private teamMemberService = inject(TeamMemberService); + private communityHighlightService = inject(CommunityHighlightService); activeTab = signal('programs'); @@ -45,17 +60,26 @@ export class AdminComponent implements OnInit { editingProgram: Program | null = null; editingEvent: Event | null = null; editingTier: Tier | null = null; + editingHistory: HistoryEntry | null = null; + editingTeam: TeamMember | null = null; + editingCommunity: CommunityHighlight | null = null; /** BehaviorSubjects guarantee change detection via the async pipe — start empty, populated on load. */ readonly programs$ = new BehaviorSubject([]); readonly events$ = new BehaviorSubject([]); readonly tiers$ = new BehaviorSubject([]); readonly stationConfig$ = new BehaviorSubject(null); + readonly historyEntries$ = new BehaviorSubject([]); + readonly teamMembers$ = new BehaviorSubject([]); + readonly communityHighlights$ = new BehaviorSubject([]); showProgramForm = false; showEventForm = false; showTierForm = false; showStationForm = false; + showHistoryForm = false; + showTeamForm = false; + showCommunityForm = false; ngOnInit(): void { this.loadAll(); @@ -81,12 +105,30 @@ export class AdminComponent implements OnInit { this.stationConfig$.next(this.stationConfigService.config()); } + async reloadHistoryEntries(): Promise { + const data = await firstValueFrom(this.historyEntryService.getHistoryEntries()); + this.historyEntries$.next(data); + } + + async reloadTeamMembers(): Promise { + const data = await firstValueFrom(this.teamMemberService.getTeamMembers()); + this.teamMembers$.next(data); + } + + async reloadCommunityHighlights(): Promise { + const data = await firstValueFrom(this.communityHighlightService.getCommunityHighlights()); + this.communityHighlights$.next(data); + } + async loadAll(): Promise { await Promise.all([ this.reloadPrograms(), this.reloadEvents(), this.reloadTiers(), this.reloadStationConfig(), + this.reloadHistoryEntries(), + this.reloadTeamMembers(), + this.reloadCommunityHighlights(), ]); } @@ -191,4 +233,91 @@ export class AdminComponent implements OnInit { onStationClosed(): void { this.showStationForm = false; } + + // ── History CRUD ──────────────────────────────────────── + + openHistoryForm(): void { + this.editingHistory = null; + this.showHistoryForm = true; + } + + editHistory(entry: HistoryEntry): void { + this.editingHistory = entry; + this.showHistoryForm = true; + } + + onHistorySaved(): void { + this.reloadHistoryEntries(); + this.showHistoryForm = false; + this.editingHistory = null; + } + + onHistoryClosed(): void { + this.showHistoryForm = false; + this.editingHistory = null; + } + + async deleteHistory(id: number): Promise { + if (!confirm('Delete this history entry?')) return; + await firstValueFrom(this.historyEntryService.deleteHistoryEntry(id)); + await this.reloadHistoryEntries(); + } + + // ── Team CRUD ─────────────────────────────────────────── + + openTeamForm(): void { + this.editingTeam = null; + this.showTeamForm = true; + } + + editTeam(member: TeamMember): void { + this.editingTeam = member; + this.showTeamForm = true; + } + + onTeamSaved(): void { + this.reloadTeamMembers(); + this.showTeamForm = false; + this.editingTeam = null; + } + + onTeamClosed(): void { + this.showTeamForm = false; + this.editingTeam = null; + } + + async deleteTeam(id: number): Promise { + if (!confirm('Delete this team member?')) return; + await firstValueFrom(this.teamMemberService.deleteTeamMember(id)); + await this.reloadTeamMembers(); + } + + // ── Community CRUD ────────────────────────────────────── + + openCommunityForm(): void { + this.editingCommunity = null; + this.showCommunityForm = true; + } + + editCommunity(highlight: CommunityHighlight): void { + this.editingCommunity = highlight; + this.showCommunityForm = true; + } + + onCommunitySaved(): void { + this.reloadCommunityHighlights(); + this.showCommunityForm = false; + this.editingCommunity = null; + } + + onCommunityClosed(): void { + this.showCommunityForm = false; + this.editingCommunity = null; + } + + async deleteCommunity(id: number): Promise { + if (!confirm('Delete this community highlight?')) return; + await firstValueFrom(this.communityHighlightService.deleteCommunityHighlight(id)); + await this.reloadCommunityHighlights(); + } } diff --git a/src/app/interfaces/community-highlight.ts b/src/app/interfaces/community-highlight.ts new file mode 100644 index 0000000..85675f7 --- /dev/null +++ b/src/app/interfaces/community-highlight.ts @@ -0,0 +1,8 @@ +export interface CommunityHighlight { + id: number; + icon: string; + title: string; + description: string; + display_order: number; + active: boolean; +} diff --git a/src/app/interfaces/history-entry.ts b/src/app/interfaces/history-entry.ts new file mode 100644 index 0000000..6d5a6a2 --- /dev/null +++ b/src/app/interfaces/history-entry.ts @@ -0,0 +1,8 @@ +export interface HistoryEntry { + id: number; + year: number; + title: string; + body: string; + display_order: number; + active: boolean; +} diff --git a/src/app/interfaces/team-member.ts b/src/app/interfaces/team-member.ts new file mode 100644 index 0000000..ef347ad --- /dev/null +++ b/src/app/interfaces/team-member.ts @@ -0,0 +1,9 @@ +export interface TeamMember { + id: number; + name: string; + title: string; + bio: string | null; + photo_url: string | null; + display_order: number; + active: boolean; +} diff --git a/src/app/services/community-highlight.service.ts b/src/app/services/community-highlight.service.ts new file mode 100644 index 0000000..de8a36a --- /dev/null +++ b/src/app/services/community-highlight.service.ts @@ -0,0 +1,37 @@ +import { Injectable, inject } from '@angular/core'; +import { HttpClient, HttpParams } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +import { CommunityHighlight } from '../interfaces/community-highlight'; +import { getAppConfig } from './app-config.service'; + +@Injectable({ + providedIn: 'root', +}) +export class CommunityHighlightService { + private http = inject(HttpClient); + private baseUrl = `${getAppConfig().apiBaseUrl}/api/community`; + + /** Fetch community highlights, optionally filtered by active status. */ + getCommunityHighlights(active?: boolean): Observable { + let params = new HttpParams(); + if (active !== undefined) params = params.set('active', String(active)); + return this.http.get(this.baseUrl, { params }); + } + + getCommunityHighlight(id: number): Observable { + return this.http.get(`${this.baseUrl}/${id}`); + } + + createCommunityHighlight(payload: Omit): Observable { + return this.http.post(this.baseUrl, payload); + } + + updateCommunityHighlight(id: number, payload: Partial): Observable { + return this.http.put(`${this.baseUrl}/${id}`, payload); + } + + deleteCommunityHighlight(id: number): Observable { + return this.http.delete(`${this.baseUrl}/${id}`); + } +} diff --git a/src/app/services/history-entry.service.ts b/src/app/services/history-entry.service.ts new file mode 100644 index 0000000..73ffb97 --- /dev/null +++ b/src/app/services/history-entry.service.ts @@ -0,0 +1,37 @@ +import { Injectable, inject } from '@angular/core'; +import { HttpClient, HttpParams } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +import { HistoryEntry } from '../interfaces/history-entry'; +import { getAppConfig } from './app-config.service'; + +@Injectable({ + providedIn: 'root', +}) +export class HistoryEntryService { + private http = inject(HttpClient); + private baseUrl = `${getAppConfig().apiBaseUrl}/api/history`; + + /** Fetch history entries, optionally filtered by active status. */ + getHistoryEntries(active?: boolean): Observable { + let params = new HttpParams(); + if (active !== undefined) params = params.set('active', String(active)); + return this.http.get(this.baseUrl, { params }); + } + + getHistoryEntry(id: number): Observable { + return this.http.get(`${this.baseUrl}/${id}`); + } + + createHistoryEntry(payload: Omit): Observable { + return this.http.post(this.baseUrl, payload); + } + + updateHistoryEntry(id: number, payload: Partial): Observable { + return this.http.put(`${this.baseUrl}/${id}`, payload); + } + + deleteHistoryEntry(id: number): Observable { + return this.http.delete(`${this.baseUrl}/${id}`); + } +} diff --git a/src/app/services/team-member.service.ts b/src/app/services/team-member.service.ts new file mode 100644 index 0000000..0c5bddf --- /dev/null +++ b/src/app/services/team-member.service.ts @@ -0,0 +1,37 @@ +import { Injectable, inject } from '@angular/core'; +import { HttpClient, HttpParams } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +import { TeamMember } from '../interfaces/team-member'; +import { getAppConfig } from './app-config.service'; + +@Injectable({ + providedIn: 'root', +}) +export class TeamMemberService { + private http = inject(HttpClient); + private baseUrl = `${getAppConfig().apiBaseUrl}/api/team`; + + /** Fetch team members, optionally filtered by active status. */ + getTeamMembers(active?: boolean): Observable { + let params = new HttpParams(); + if (active !== undefined) params = params.set('active', String(active)); + return this.http.get(this.baseUrl, { params }); + } + + getTeamMember(id: number): Observable { + return this.http.get(`${this.baseUrl}/${id}`); + } + + createTeamMember(payload: Omit): Observable { + return this.http.post(this.baseUrl, payload); + } + + updateTeamMember(id: number, payload: Partial): Observable { + return this.http.put(`${this.baseUrl}/${id}`, payload); + } + + deleteTeamMember(id: number): Observable { + return this.http.delete(`${this.baseUrl}/${id}`); + } +}