Skip to content

Commit

Permalink
Got annotator of extract working.
Browse files Browse the repository at this point in the history
  • Loading branch information
JSv4 committed Jun 15, 2024
1 parent 9dbc59d commit 9c58d78
Show file tree
Hide file tree
Showing 16 changed files with 2,902 additions and 1,465 deletions.
5 changes: 5 additions & 0 deletions config/graphql/graphene_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,12 @@ def resolve_full_column_list(self, info):


class DatacellType(AnnotatePermissionsForReadMixin, DjangoObjectType):

data = GenericScalar()
full_source_list = graphene.List(AnnotationType)

def resolve_full_source_list(self, info):
return self.sources.all()

class Meta:
model = Datacell
Expand Down
14 changes: 7 additions & 7 deletions config/graphql/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,15 @@ def resolve_bulk_doc_annotations_in_corpus(self, info, corpus_id, **kwargs):
current_page=graphene.Int(required=False),
page_number_list=graphene.String(required=False),
page_containing_annotation_with_id=graphene.ID(required=False),
corpus_id=graphene.ID(required=True),
corpus_id=graphene.ID(required=False),
document_id=graphene.ID(required=True),
for_analysis_ids=graphene.String(required=False),
label_type=graphene.Argument(label_type_enum),
)

def resolve_page_annotations(self, info, document_id, corpus_id, **kwargs):
def resolve_page_annotations(self, info, document_id, corpus_id=None, **kwargs):

doc_django_pk = from_global_id(document_id)[1]
corpus_django_pk = from_global_id(corpus_id)[1]

document = Document.objects.get(id=doc_django_pk)

Expand All @@ -214,7 +213,8 @@ def resolve_page_annotations(self, info, document_id, corpus_id, **kwargs):

# Now build query to stuff they want to see
q_objects = Q(document_id=doc_django_pk)
q_objects.add(Q(corpus_id=corpus_django_pk), Q.AND)
if corpus_id is not None:
q_objects.add(Q(corpus_id=from_global_id(corpus_id)[1]), Q.AND)

# If for_analysis_ids is passed in, only show annotations from those analyses, otherwise only show human
# annotations.
Expand Down Expand Up @@ -743,13 +743,13 @@ def resolve_extract(self, info, **kwargs):
@login_required
def resolve_extracts(self, info, **kwargs):
if info.context.user.is_superuser:
return Extract.objects.all()
return Extract.objects.all().order_by("-created")
elif info.context.user.is_anonymous:
return Extract.objects.filter(Q(is_public=True))
return Extract.objects.filter(Q(is_public=True)).order_by("-created")
else:
return Extract.objects.filter(
Q(creator=info.context.user) | Q(is_public=True)
)
).order_by("-created")

corpus_query = relay.Node.Field(CorpusQueryType)

Expand Down
46 changes: 46 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import {
showExportModal,
userObj,
showCookieAcceptModal,
openedDocument,
selectedAnalysesIds,
selectedAnalyses,
onlyDisplayTheseAnnotations,
openedCorpus,
displayAnnotationOnAnnotatorLoad,
showSelectedAnnotationOnly,
showAnnotationBoundingBoxes,
} from "./graphql/cache";

import { NavMenu } from "./components/layout/NavMenu";
Expand All @@ -42,17 +50,34 @@ import { MobileNavMenu } from "./components/layout/MobileNavMenu";
import { LabelDisplayBehavior } from "./graphql/types";
import { CookieConsentDialog } from "./components/cookies/CookieConsent";
import { Extracts } from "./views/Extracts";
import { DocumentAnnotator } from "./components/annotator/DocumentAnnotator";

export const App = () => {
const { REACT_APP_USE_AUTH0 } = process.env;
const show_export_modal = useReactiveVar(showExportModal);
const show_cookie_modal = useReactiveVar(showCookieAcceptModal);
const only_display_these_annotations = useReactiveVar(
onlyDisplayTheseAnnotations
);
const selected_analyes = useReactiveVar(selectedAnalyses);
const opened_corpus = useReactiveVar(openedCorpus);
const opened_document = useReactiveVar(openedDocument);
const opened_to_annotation = useReactiveVar(displayAnnotationOnAnnotatorLoad);
const show_selected_annotation_only = useReactiveVar(
showSelectedAnnotationOnly
);
const show_annotation_bounding_boxes = useReactiveVar(
showAnnotationBoundingBoxes
);
const show_annotation_labels = useReactiveVar(showAnnotationLabels);

const { getAccessTokenSilently, user } = useAuth0();

// For now, our responsive layout is a bit hacky, but it's working well enough to
// provide a passable UI on mobile. Your results not guaranteed X-)
const { width } = useWindowDimensions();
const show_mobile_menu = width <= 1000;
const banish_sidebar = width <= 1000;

useEffect(() => {
if (width <= 800) {
Expand Down Expand Up @@ -139,6 +164,27 @@ export const App = () => {
<Dimmer active={false}>
<Loader content="Logging in..." />
</Dimmer>
{opened_document && only_display_these_annotations !== undefined ? (
<DocumentAnnotator
open={Boolean(opened_document)}
onClose={() => {
openedDocument(null);
selectedAnalysesIds([]);
selectedAnalyses([]);
onlyDisplayTheseAnnotations(undefined);
}}
display_annotations={only_display_these_annotations}
opened_document={opened_document}
read_only={selected_analyes.length > 0 || banish_sidebar}
scroll_to_annotation_on_open={opened_to_annotation}
show_selected_annotation_only={show_selected_annotation_only}
show_annotation_bounding_boxes={show_annotation_bounding_boxes}
show_annotation_labels={show_annotation_labels}
/>
) : (
<></>
)}

<Routes>
<Route path="/" element={<Corpuses />} />
{REACT_APP_USE_AUTH0 !== "true" ? (
Expand Down
Loading

0 comments on commit 9c58d78

Please sign in to comment.