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/location form expansion #159

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions backend/event/types/EpisodeType.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from event.models import Episode, EpisodeCategory
from event.types.EpisodeCategoryType import EpisodeCategoryType
from person.models import AgentDescription
from space.models import SpaceDescription


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

class Meta:
model = Episode
Expand Down Expand Up @@ -43,6 +45,12 @@ def resolve_agents(
# to that agent, for some reason.
return parent.agents.distinct()

@staticmethod
def resolve_spaces(
parent: Episode, info: ResolveInfo
) -> QuerySet[SpaceDescription]:
return parent.spaces.distinct()

@staticmethod
def resolve_categories(
parent: Episode, info: ResolveInfo
Expand Down
5 changes: 3 additions & 2 deletions backend/space/mutations/UpdateSpaceMutation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from graphene import ID, Boolean, InputObjectType, List, NonNull, ResolveInfo
from django.core.exceptions import ObjectDoesNotExist
from core.types.input.DescriptionFieldInputType import DescriptionFieldInputType
from core.types.input.EntityDescriptionInputType import EntityDescriptionInputType
from letter.models import LetterDescription
from graphql_app.LettercraftMutation import LettercraftMutation

from graphql_app.types.LettercraftErrorType import LettercraftErrorType
Expand All @@ -11,6 +9,9 @@

class UpdateSpaceInput(EntityDescriptionInputType, InputObjectType):
id = ID(required=True)
regions = List(NonNull(ID))
settlements = List(NonNull(ID))
structures = List(NonNull(ID))


class UpdateSpaceMutation(LettercraftMutation):
Expand Down
170 changes: 169 additions & 1 deletion frontend/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ export type EpisodeType = EntityDescription & {
source: SourceType;
/** How is this entity presented in the text? */
sourceMention?: Maybe<EventEpisodeSourceMentionChoices>;
/** locations involved in this episode */
spaces: Array<SpaceDescriptionType>;
/** full description of the events in the passage */
summary: Scalars['String']['output'];
Expand Down Expand Up @@ -1060,6 +1059,9 @@ export type UpdateSpaceInput = {
id: Scalars['ID']['input'];
name?: InputMaybe<Scalars['String']['input']>;
page?: InputMaybe<Scalars['String']['input']>;
regions?: InputMaybe<Array<Scalars['ID']['input']>>;
settlements?: InputMaybe<Array<Scalars['ID']['input']>>;
structures?: InputMaybe<Array<Scalars['ID']['input']>>;
};

export type UpdateSpaceMutation = {
Expand Down Expand Up @@ -1350,13 +1352,49 @@ export type DataEntryLocationIdentificationQueryVariables = Exact<{

export type DataEntryLocationIdentificationQuery = { __typename?: 'Query', spaceDescription?: { __typename?: 'SpaceDescriptionType', id: string, name: string, description: string } | null };

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


export type DataEntryLocationRegionsQuery = { __typename?: 'Query', spaceDescription?: { __typename?: 'SpaceDescriptionType', id: string, regions: Array<{ __typename?: 'RegionType', id: string }> } | null };

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


export type DataEntryRegionsQuery = { __typename?: 'Query', regions: Array<{ __typename?: 'RegionType', id: string, name: string, type: SpaceRegionTypeChoices }> };

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


export type DataEntryLocationSettlementsQuery = { __typename?: 'Query', spaceDescription?: { __typename?: 'SpaceDescriptionType', id: string, settlements: Array<{ __typename?: 'SettlementType', id: string }> } | null };

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


export type DataEntrySettlementsQuery = { __typename?: 'Query', settlements: Array<{ __typename?: 'SettlementType', id: string, name: string, regions: Array<{ __typename?: 'RegionType', id: string, name: string }> }> };

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


export type DataEntryLocationSourceTextQuery = { __typename?: 'Query', spaceDescription?: { __typename?: 'SpaceDescriptionType', id: string, book: string, chapter: string, page: string } | null };

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


export type DataEntryLocationStructuresQuery = { __typename?: 'Query', spaceDescription?: { __typename?: 'SpaceDescriptionType', id: string, structures: Array<{ __typename?: 'StructureType', id: string }> } | null };

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


export type DataEntryStructuresQuery = { __typename?: 'Query', structures: Array<{ __typename?: 'StructureType', id: string, name: string, level: SpaceStructureLevelChoices, settlement?: { __typename?: 'SettlementType', id: string, name: string } | null }> };

export type DataEntryLocationQueryVariables = Exact<{
id: Scalars['ID']['input'];
}>;
Expand Down Expand Up @@ -2427,6 +2465,91 @@ export const DataEntryLocationIdentificationDocument = gql`
export class DataEntryLocationIdentificationGQL extends Apollo.Query<DataEntryLocationIdentificationQuery, DataEntryLocationIdentificationQueryVariables> {
override document = DataEntryLocationIdentificationDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const DataEntryLocationRegionsDocument = gql`
query DataEntryLocationRegions($id: ID!) {
spaceDescription(id: $id) {
id
regions {
id
}
}
}
`;

@Injectable({
providedIn: 'root'
})
export class DataEntryLocationRegionsGQL extends Apollo.Query<DataEntryLocationRegionsQuery, DataEntryLocationRegionsQueryVariables> {
override document = DataEntryLocationRegionsDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const DataEntryRegionsDocument = gql`
query DataEntryRegions {
regions {
id
name
type
}
}
`;

@Injectable({
providedIn: 'root'
})
export class DataEntryRegionsGQL extends Apollo.Query<DataEntryRegionsQuery, DataEntryRegionsQueryVariables> {
override document = DataEntryRegionsDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const DataEntryLocationSettlementsDocument = gql`
query DataEntryLocationSettlements($id: ID!) {
spaceDescription(id: $id) {
id
settlements {
id
}
}
}
`;

@Injectable({
providedIn: 'root'
})
export class DataEntryLocationSettlementsGQL extends Apollo.Query<DataEntryLocationSettlementsQuery, DataEntryLocationSettlementsQueryVariables> {
override document = DataEntryLocationSettlementsDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const DataEntrySettlementsDocument = gql`
query DataEntrySettlements {
settlements {
id
name
regions {
id
name
}
}
}
`;

@Injectable({
providedIn: 'root'
})
export class DataEntrySettlementsGQL extends Apollo.Query<DataEntrySettlementsQuery, DataEntrySettlementsQueryVariables> {
override document = DataEntrySettlementsDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
Expand All @@ -2448,6 +2571,51 @@ export const DataEntryLocationSourceTextDocument = gql`
export class DataEntryLocationSourceTextGQL extends Apollo.Query<DataEntryLocationSourceTextQuery, DataEntryLocationSourceTextQueryVariables> {
override document = DataEntryLocationSourceTextDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const DataEntryLocationStructuresDocument = gql`
query DataEntryLocationStructures($id: ID!) {
spaceDescription(id: $id) {
id
structures {
id
}
}
}
`;

@Injectable({
providedIn: 'root'
})
export class DataEntryLocationStructuresGQL extends Apollo.Query<DataEntryLocationStructuresQuery, DataEntryLocationStructuresQueryVariables> {
override document = DataEntryLocationStructuresDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const DataEntryStructuresDocument = gql`
query DataEntryStructures {
structures {
id
name
level
settlement {
id
name
}
}
}
`;

@Injectable({
providedIn: 'root'
})
export class DataEntryStructuresGQL extends Apollo.Query<DataEntryStructuresQuery, DataEntryStructuresQueryVariables> {
override document = DataEntryStructuresDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ type EpisodeType implements EntityDescription {

"""How is this entity presented in the text?"""
sourceMention: EventEpisodeSourceMentionChoices

"""locations involved in this episode"""
spaces: [SpaceDescriptionType!]!

"""full description of the events in the passage"""
Expand Down Expand Up @@ -905,6 +903,9 @@ input UpdateSpaceInput {
id: ID!
name: String
page: String
regions: [ID!]
settlements: [ID!]
structures: [ID!]
}

type UpdateSpaceMutation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
DataEntryUpdateAgentMutation,
} from "generated/graphql";
import {
combineLatest,
debounceTime,
filter,
map,
Expand Down Expand Up @@ -45,12 +44,9 @@ export class AgentHistoricalPersonFormComponent implements OnInit, OnDestroy {
share()
);

private allHistoricalPersons$ = this.historicalPersonsQuery
.fetch()
.pipe(map((result) => result.data.historicalPersons));

public historicalPersonOptions$: Observable<MultiselectOption[]> =
this.allHistoricalPersons$.pipe(
this.historicalPersonsQuery.fetch().pipe(
map((result) => result.data.historicalPersons),
map((persons) =>
persons.map(({ id, name }) => ({
value: id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ <h2 class="subform-header">Source text</h2>
<lc-location-source-text-form />

<h2 class="subform-header">Regions</h2>
<p><i>Coming soon!</i></p>
<lc-location-regions-form />

<h2 class="subform-header">Settlements</h2>
<p><i>Coming soon!</i></p>
<lc-location-settlements-form />

<h2 class="subform-header">Structures</h2>
<p><i>Coming soon!</i></p>
<lc-location-structures-form />

<h2 class="subform-header">Episodes</h2>
<lc-location-episodes-form />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { SharedModule } from "@shared/shared.module";
import { LocationIdentificationFormComponent } from "./location-identification-form/location-identification-form.component";
import { LocationSourceTextFormComponent } from "./location-source-text-form/location-source-text-form.component";
import { LocationEpisodesFormComponent } from './location-episodes-form/location-episodes-form.component';
import { LocationRegionsFormComponent } from './location-regions-form/location-regions-form.component';
import { LocationSettlementsFormComponent } from './location-settlements-form/location-settlements-form.component';
import { LocationStructuresFormComponent } from './location-structures-form/location-structures-form.component';



Expand All @@ -14,6 +17,9 @@ import { LocationEpisodesFormComponent } from './location-episodes-form/location
LocationIdentificationFormComponent,
LocationEpisodesFormComponent,
LocationSourceTextFormComponent,
LocationRegionsFormComponent,
LocationSettlementsFormComponent,
LocationStructuresFormComponent,
],
imports: [SharedModule, DataEntrySharedModule],
exports: [LocationFormComponent],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<form>
<p class="form-text">
Pick one or more regions that contain the location represented here.
</p>

<lc-subspace-select
*ngIf="regionOptions$ | async as options"
[formControl]="form.controls.regions"
[options]="options"
subspaceType="region"
/>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { LocationRegionsFormComponent } from "./location-regions-form.component";
import { SharedTestingModule } from "@shared/shared-testing.module";
import { FormService } from "../../shared/form.service";

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

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

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