Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/historical figures #158

Merged
merged 10 commits into from
Dec 18, 2024
Merged
13 changes: 12 additions & 1 deletion backend/event/types/EpisodeType.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

from event.models import Episode, EpisodeCategory
from event.types.EpisodeCategoryType import EpisodeCategoryType
from person.models import AgentDescription


class EpisodeType(EntityDescriptionType, DjangoObjectType):
categories = List(NonNull(EpisodeCategoryType), required=True)
agents = List(
NonNull("person.types.AgentDescriptionType.AgentDescriptionType"), required=True
)

class Meta:
model = Episode
Expand All @@ -17,7 +21,6 @@ class Meta:
"summary",
"categories",
"designators",
"agents",
"gifts",
"letters",
"spaces",
Expand All @@ -32,6 +35,14 @@ def get_queryset(
) -> QuerySet[Episode]:
return queryset.all()

@staticmethod
def resolve_agents(
parent: Episode, info: ResolveInfo
) -> QuerySet[AgentDescription]:
# Without distinct(), this returns one agent for every HistoricalPerson linked
# to that agent, for some reason.
return parent.agents.distinct()

@staticmethod
def resolve_categories(
parent: Episode, info: ResolveInfo
Expand Down
1 change: 1 addition & 0 deletions backend/person/mutations/UpdateAgentMutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class UpdateAgentInput(InputObjectType):
is_group = Boolean()
gender = UpdateAgentGenderInput()
location = UpdateAgentLocationInput()
describes = List(NonNull(String))


class UpdateAgentMutation(LettercraftMutation):
Expand Down
10 changes: 9 additions & 1 deletion backend/person/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from django.db.models import QuerySet, Q
from typing import Optional

from person.models import AgentDescription
from person.models import AgentDescription, HistoricalPerson
from person.types.HistoricalPersonType import HistoricalPersonType
from person.types.AgentDescriptionType import AgentDescriptionType


Expand All @@ -11,6 +12,7 @@ class PersonQueries(ObjectType):
agent_descriptions = List(
NonNull(AgentDescriptionType), required=True, episode_id=ID(), source_id=ID()
)
historical_persons = List(NonNull(HistoricalPersonType), required=True)

@staticmethod
def resolve_agent_description(
Expand Down Expand Up @@ -39,3 +41,9 @@ def resolve_agent_descriptions(
return AgentDescriptionType.get_queryset(AgentDescription.objects, info).filter(
filters
)

@staticmethod
def resolve_historical_persons(
parent: None, info: ResolveInfo
) -> QuerySet[HistoricalPerson]:
return HistoricalPersonType.get_queryset(HistoricalPerson.objects, info)
61 changes: 59 additions & 2 deletions frontend/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ export type EpisodeSpaceType = EpisodeEntityLink & {

export type EpisodeType = EntityDescription & {
__typename?: 'EpisodeType';
/** agents involved in this episode */
agents: Array<AgentDescriptionType>;
/** The book in the source */
book: Scalars['String']['output'];
Expand Down Expand Up @@ -651,6 +650,7 @@ export type Query = {
episodes: Array<EpisodeType>;
giftDescription?: Maybe<GiftDescriptionType>;
giftDescriptions: Array<GiftDescriptionType>;
historicalPersons: Array<HistoricalPersonType>;
letterCategories: Array<LetterCategoryType>;
letterDescription?: Maybe<LetterDescriptionType>;
letterDescriptions: Array<LetterDescriptionType>;
Expand Down Expand Up @@ -930,6 +930,7 @@ export type UpdateAgentGenderInput = {
};

export type UpdateAgentInput = {
describes?: InputMaybe<Array<Scalars['String']['input']>>;
description?: InputMaybe<Scalars['String']['input']>;
gender?: InputMaybe<UpdateAgentGenderInput>;
id: Scalars['ID']['input'];
Expand Down Expand Up @@ -1105,12 +1106,24 @@ export type DataEntryDeleteEpisodeEntityLinkMutationVariables = Exact<{

export type DataEntryDeleteEpisodeEntityLinkMutation = { __typename?: 'Mutation', deleteEpisodeEntityLink?: { __typename?: 'DeleteEpisodeEntityLinkMutation', ok: boolean, errors: Array<{ __typename?: 'LettercraftErrorType', field: string, messages: Array<string> }> } | null };

export type DataEntryAgentHistoricalPersonQueryVariables = Exact<{
id: Scalars['ID']['input'];
}>;


export type DataEntryAgentHistoricalPersonQuery = { __typename?: 'Query', agentDescription?: { __typename?: 'AgentDescriptionType', id: string, isGroup: boolean, describes: Array<{ __typename?: 'HistoricalPersonType', id: string }> } | null };

export type DataEntryHistoricalPersonsQueryVariables = Exact<{ [key: string]: never; }>;


export type DataEntryHistoricalPersonsQuery = { __typename?: 'Query', historicalPersons: Array<{ __typename?: 'HistoricalPersonType', id: string, name: string }> };

export type DataEntryAgentIdentificationQueryVariables = Exact<{
id: Scalars['ID']['input'];
}>;


export type DataEntryAgentIdentificationQuery = { __typename?: 'Query', agentDescription?: { __typename?: 'AgentDescriptionType', id: string, name: string, description: string, isGroup: boolean } | null };
export type DataEntryAgentIdentificationQuery = { __typename?: 'Query', agentDescription?: { __typename?: 'AgentDescriptionType', id: string, name: string, description: string, isGroup: boolean, describes: Array<{ __typename?: 'HistoricalPersonType', id: string }> } | null };

export type DataEntryAgentQueryVariables = Exact<{
id: Scalars['ID']['input'];
Expand Down Expand Up @@ -1555,6 +1568,47 @@ export const DataEntryDeleteEpisodeEntityLinkDocument = gql`
export class DataEntryDeleteEpisodeEntityLinkGQL extends Apollo.Mutation<DataEntryDeleteEpisodeEntityLinkMutation, DataEntryDeleteEpisodeEntityLinkMutationVariables> {
override document = DataEntryDeleteEpisodeEntityLinkDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const DataEntryAgentHistoricalPersonDocument = gql`
query DataEntryAgentHistoricalPerson($id: ID!) {
agentDescription(id: $id) {
id
isGroup
describes {
id
}
}
}
`;

@Injectable({
providedIn: 'root'
})
export class DataEntryAgentHistoricalPersonGQL extends Apollo.Query<DataEntryAgentHistoricalPersonQuery, DataEntryAgentHistoricalPersonQueryVariables> {
override document = DataEntryAgentHistoricalPersonDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const DataEntryHistoricalPersonsDocument = gql`
query DataEntryHistoricalPersons {
historicalPersons {
id
name
}
}
`;

@Injectable({
providedIn: 'root'
})
export class DataEntryHistoricalPersonsGQL extends Apollo.Query<DataEntryHistoricalPersonsQuery, DataEntryHistoricalPersonsQueryVariables> {
override document = DataEntryHistoricalPersonsDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
Expand All @@ -1566,6 +1620,9 @@ export const DataEntryAgentIdentificationDocument = gql`
name
description
isGroup
describes {
id
}
}
}
`;
Expand Down
3 changes: 2 additions & 1 deletion frontend/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ type EpisodeSpaceType implements EpisodeEntityLink {
}

type EpisodeType implements EntityDescription {
"""agents involved in this episode"""
agents: [AgentDescriptionType!]!

"""The book in the source"""
Expand Down Expand Up @@ -540,6 +539,7 @@ type Query {
episodes(sourceId: ID): [EpisodeType!]!
giftDescription(id: ID!): GiftDescriptionType
giftDescriptions(episodeId: ID, sourceId: ID): [GiftDescriptionType!]!
historicalPersons: [HistoricalPersonType!]!
letterCategories: [LetterCategoryType!]!
letterDescription(id: ID!): LetterDescriptionType
letterDescriptions(episodeId: ID, sourceId: ID): [LetterDescriptionType!]!
Expand Down Expand Up @@ -783,6 +783,7 @@ input UpdateAgentGenderInput {
}

input UpdateAgentInput {
describes: [String!]
description: String
gender: UpdateAgentGenderInput
id: ID!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h2>Episodes</h2>

<h2>Historical context</h2>

<p><i>Coming soon!</i></p>
<lc-agent-historical-person-form />
</ng-container>


Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/data-entry/agent-form/agent-form.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AgentDescriptionFormComponent } from './agent-description-form/agent-de
import { DataEntrySharedModule } from "../shared/data-entry-shared.module";
import { DeleteAgentComponent } from './delete-agent/delete-agent.component';
import { AgentEpisodesFormComponent } from './agent-episodes-form/agent-episodes-form.component';
import { AgentHistoricalPersonFormComponent } from './agent-historical-person-form/agent-historical-person-form.component';


@NgModule({
Expand All @@ -15,6 +16,7 @@ import { AgentEpisodesFormComponent } from './agent-episodes-form/agent-episodes
AgentDescriptionFormComponent,
DeleteAgentComponent,
AgentEpisodesFormComponent,
AgentHistoricalPersonFormComponent,
],
imports: [
SharedModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<fieldset *ngIf="isGroup$ | async as isGroup">
<ng-container >
<legend>
{{ isGroup ? "Historical persons" : "Historical person" }}
</legend>
<p class="form-text">
{{
isGroup
? "Pick one or more historical persons that are represented by this agent in this source."
: "Pick an historical person that is represented by this agent in this source."
}}
</p>
</ng-container>
<lc-historical-person-select
*ngIf="historicalPersonOptions$ | async as options"
[formControl]="form.controls.describes"
[options]="options"
[multiple]="isGroup"
/>
</fieldset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { AgentHistoricalPersonFormComponent } from "./agent-historical-person-form.component";
import { FormService } from "../../shared/form.service";
import { SharedTestingModule } from "@shared/shared-testing.module";

describe("AgentHistoricalPersonFormComponent", () => {
let component: AgentHistoricalPersonFormComponent;
let fixture: ComponentFixture<AgentHistoricalPersonFormComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AgentHistoricalPersonFormComponent],
imports: [SharedTestingModule],
providers: [FormService],
});
fixture = TestBed.createComponent(AgentHistoricalPersonFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it("should create", () => {
expect(component).toBeTruthy();
});
});
Loading