Skip to content

Commit

Permalink
simplify icon decision for locations and agents
Browse files Browse the repository at this point in the history
  • Loading branch information
lukavdplas committed Sep 27, 2024
1 parent b1152cc commit 8a06af6
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 27 deletions.
3 changes: 3 additions & 0 deletions backend/person/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def clean(self):
"Only groups can describe multiple historical figures"
)

def identified(self):
return self.describes.filter(identifiable=True).exists()


class Gender(models.TextChoices):
FEMALE = "FEMALE", "Female"
Expand Down
7 changes: 6 additions & 1 deletion backend/person/types/AgentDescriptionType.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from graphene import Field, List, ResolveInfo, NonNull
from graphene import Field, List, ResolveInfo, NonNull, Boolean
from graphene_django import DjangoObjectType

from django.db.models import QuerySet
Expand All @@ -18,6 +18,7 @@ class AgentDescriptionType(EntityDescriptionType, DjangoObjectType):
gender = Field(AgentDescriptionGenderType)
location = Field(AgentDescriptionLocationType)
episodes = List(NonNull(EpisodeAgentType), required=True)
identified = Boolean(required=True)

class Meta:
model = AgentDescription
Expand Down Expand Up @@ -55,3 +56,7 @@ def resolve_episodes(
parent: AgentDescription, info: ResolveInfo
) -> QuerySet[EpisodeAgent]:
return EpisodeAgent.objects.filter(agent=parent)

@staticmethod
def resolve_identified(parent: AgentDescription, info: ResolveInfo) -> bool:
return parent.identified()
11 changes: 5 additions & 6 deletions frontend/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type AgentDescriptionType = EntityDescription & {
episodes: Array<EpisodeAgentType>;
gender?: Maybe<AgentDescriptionGenderType>;
id: Scalars['ID']['output'];
identified: Scalars['Boolean']['output'];
/** Whether this agent is a group of people (e.g. 'the nuns of Poitiers'). */
isGroup: Scalars['Boolean']['output'];
location?: Maybe<AgentDescriptionLocationType>;
Expand Down Expand Up @@ -1062,7 +1063,7 @@ export type DataEntryAgentQueryVariables = Exact<{
}>;


export type DataEntryAgentQuery = { __typename?: 'Query', agentDescription?: { __typename?: 'AgentDescriptionType', id: string, name: string, description: string, isGroup: boolean, source: { __typename?: 'SourceType', id: string, name: string } } | null };
export type DataEntryAgentQuery = { __typename?: 'Query', agentDescription?: { __typename?: 'AgentDescriptionType', id: string, name: string, description: string, isGroup: boolean, identified: boolean, source: { __typename?: 'SourceType', id: string, name: string } } | null };

export type DataEntryUpdateAgentMutationVariables = Exact<{
input: UpdateAgentInput;
Expand Down Expand Up @@ -1247,7 +1248,7 @@ export type DataEntrySourceDetailQueryVariables = Exact<{
}>;


export type DataEntrySourceDetailQuery = { __typename?: 'Query', source: { __typename?: 'SourceType', id: string, name: string, episodes: Array<{ __typename?: 'EpisodeType', id: string, name: string, description: string, summary: string, book: string, chapter: string, page: string, contributors: Array<{ __typename?: 'UserType', id: string, fullName: string }>, agents: Array<{ __typename?: 'AgentDescriptionType', id: string, name: string, isGroup: boolean, describes: Array<{ __typename?: 'HistoricalPersonType', id: string, identifiable: boolean }> }>, gifts: Array<{ __typename?: 'GiftDescriptionType', id: string, name: string }>, letters: Array<{ __typename?: 'LetterDescriptionType', id: string, name: string }>, spaces: Array<{ __typename?: 'SpaceDescriptionType', id: string, name: string, hasIdentifiableFeatures: boolean }> }> } };
export type DataEntrySourceDetailQuery = { __typename?: 'Query', source: { __typename?: 'SourceType', id: string, name: string, episodes: Array<{ __typename?: 'EpisodeType', id: string, name: string, description: string, summary: string, book: string, chapter: string, page: string, contributors: Array<{ __typename?: 'UserType', id: string, fullName: string }>, agents: Array<{ __typename?: 'AgentDescriptionType', id: string, name: string, isGroup: boolean, identified: boolean }>, gifts: Array<{ __typename?: 'GiftDescriptionType', id: string, name: string }>, letters: Array<{ __typename?: 'LetterDescriptionType', id: string, name: string }>, spaces: Array<{ __typename?: 'SpaceDescriptionType', id: string, name: string, hasIdentifiableFeatures: boolean }> }> } };

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

Expand Down Expand Up @@ -1443,6 +1444,7 @@ export const DataEntryAgentDocument = gql`
name
description
isGroup
identified
source {
id
name
Expand Down Expand Up @@ -2101,10 +2103,7 @@ export const DataEntrySourceDetailDocument = gql`
id
name
isGroup
describes {
id
identifiable
}
identified
}
gifts {
id
Expand Down
1 change: 1 addition & 0 deletions frontend/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type AgentDescriptionType implements EntityDescription {
episodes: [EpisodeAgentType!]!
gender: AgentDescriptionGenderType
id: ID!
identified: Boolean!

"""Whether this agent is a group of people (e.g. 'the nuns of Poitiers')."""
isGroup: Boolean!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<ng-container *ngIf="data.agentDescription as agentDescription; else noAgent">
<h1 class="mb-4">
<lc-icon [icon]="agentDescription.isGroup ? dataIcons.group : dataIcons.person" />
<lc-icon [icon]="agentIcon(agentDescription)" />
{{agentDescription.name}}
<span class="text-secondary">
({{agentDescription.source.name}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { dataIcons } from '@shared/icons';
import { DataEntryAgentGQL, DataEntryAgentQuery } from 'generated/graphql';
import { map, Observable, switchMap } from 'rxjs';
import { FormService } from '../shared/form.service';
import { agentIcon } from '@shared/icons-utils';

@Component({
selector: 'lc-agent-form',
Expand All @@ -16,6 +17,7 @@ export class AgentFormComponent {
data$: Observable<DataEntryAgentQuery>;

dataIcons = dataIcons;
agentIcon = agentIcon;

status$ = this.formService.status$;

Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/data-entry/agent-form/agent.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ query DataEntryAgent($id: ID!) {
name
description
isGroup
identified
source {
id
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<ng-container *ngIf="data.spaceDescription as spaceDescription">
<h1 class="mb-4">
<lc-icon [icon]="spaceDescription.hasIdentifiableFeatures ? dataIcons.locationIdentified : dataIcons.location" />
<lc-icon [icon]="locationIcon(spaceDescription)" />
{{spaceDescription.name}}
<span class="text-secondary">
({{spaceDescription.source.name}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Breadcrumb } from '@shared/breadcrumb/breadcrumb.component';
import { dataIcons } from '@shared/icons';
import { locationIcon } from '@shared/icons-utils';
import { DataEntrySpaceDescriptionGQL, DataEntrySpaceDescriptionQuery } from 'generated/graphql';
import { map, Observable, switchMap } from 'rxjs';

Expand All @@ -15,6 +16,7 @@ export class LocationFormComponent {
data$: Observable<DataEntrySpaceDescriptionQuery>;

dataIcons = dataIcons;
locationIcon = locationIcon;

constructor(
private route: ActivatedRoute, private spaceQuery: DataEntrySpaceDescriptionGQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
[routerLink]="['/data-entry', 'locations', space.id]"
class="icon-link"
>
<lc-icon [icon]="space.hasIdentifiableFeatures ?
dataIcons.locationIdentified : dataIcons.location" />
<lc-icon [icon]="locationIcon(space)" />
{{ space.name }}
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { ModalService } from "@services/modal.service";
import { ToastService } from "@services/toast.service";
import { dataIcons } from "@shared/icons";
import { agentIcon, locationIcon } from "@shared/icons-utils";
import {
DataEntryDeleteEpisodeGQL,
DataEntrySourceDetailQuery,
Expand All @@ -21,6 +22,8 @@ export class EpisodePreviewComponent {
@Input({ required: true })
public episode!: QueriedEpisode;
public dataIcons = dataIcons;
agentIcon = agentIcon;
locationIcon = locationIcon;

constructor(
private destroyRef: DestroyRef,
Expand All @@ -42,16 +45,6 @@ export class EpisodePreviewComponent {
});
}

public agentIcon(agent: QueriedEpisode["agents"][0]): string {
if (agent.isGroup) {
return dataIcons.group;
}
if (agent.describes?.some((person) => person?.identifiable)) {
return dataIcons.person;
}
return dataIcons.personUnknown;
}

private performDelete(episodeId: string): void {
this.deleteEpisode
.mutate(
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/app/data-entry/source/source.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ query DataEntrySourceDetail($id: ID!) {
id
name
isGroup
describes {
id
identifiable
}
identified
}
gifts {
id
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/app/shared/icons-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { dataIcons } from "./icons";

export const agentIcon = (agent: { isGroup: boolean, identified: boolean }): string => {
if (agent.isGroup) {
return dataIcons.group;
}
if (agent.identified) {
return dataIcons.personIdentified;
}
return dataIcons.person;
}

export const locationIcon = (location: { hasIdentifiableFeatures: boolean }): string =>
location.hasIdentifiableFeatures ? dataIcons.locationIdentified : dataIcons.location;
4 changes: 2 additions & 2 deletions frontend/src/app/shared/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const authIcons = {
export const dataIcons = {
source: 'book',
episode: 'bookmark',
person: 'person-fill',
personUnknown: 'person',
person: 'person',
personIdentified: 'person-fill',
group: 'people',
location: 'geo-alt',
locationIdentified: 'geo-alt-fill',
Expand Down

0 comments on commit 8a06af6

Please sign in to comment.