From 2e345c1ebd498e3f7e088e6fc3e1ca17082b23c1 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 26 Aug 2024 13:53:26 -0400
Subject: converted unique faces to be a Doc type similar to a collection.

---
 src/client/views/search/FaceRecognitionHandler.tsx | 34 +++++++++++++++-------
 1 file changed, 23 insertions(+), 11 deletions(-)

(limited to 'src/client/views/search/FaceRecognitionHandler.tsx')

diff --git a/src/client/views/search/FaceRecognitionHandler.tsx b/src/client/views/search/FaceRecognitionHandler.tsx
index a17e4c54a..1ab084eaa 100644
--- a/src/client/views/search/FaceRecognitionHandler.tsx
+++ b/src/client/views/search/FaceRecognitionHandler.tsx
@@ -8,6 +8,8 @@ import { Cast, ImageCast, NumCast, StrCast } from '../../../fields/Types';
 import { DocumentType } from '../../documents/DocumentTypes';
 import { DocumentManager } from '../../util/DocumentManager';
 import { ImageField } from '../../../fields/URLField';
+import { UniqueFaceBox } from '../collections/collectionFreeForm/FaceCollectionBox';
+import { Docs } from '../../documents/Documents';
 
 /**
  * A singleton class that handles face recognition and manages face Doc collections for each face found.
@@ -169,15 +171,25 @@ export class FaceRecognitionHandler {
      * @returns a unique face Doc
      */
     private createUniqueFaceDoc = (dashboard: Doc) => {
-        const faceDocNum = NumCast(dashboard.myUniqueFaces_count) + 1;
-        dashboard.myUniqueFaces_count = faceDocNum; // TODO: improve to a better name
-
-        const uniqueFaceDoc = new Doc();
-        uniqueFaceDoc.title = `Face ${faceDocNum}`;
-        uniqueFaceDoc.face = ''; // just to make prettyprinting look better
-        uniqueFaceDoc.face_label = `Face${faceDocNum}`;
-        uniqueFaceDoc.face_images = new List<Doc>();
-        uniqueFaceDoc.face_descriptors = new List<List<number>>();
+        const faceDocNum = NumCast(dashboard[DocData].myUniqueFaces_count) + 1;
+        dashboard[DocData].myUniqueFaces_count = faceDocNum; // TODO: improve to a better name
+
+        const uniqueFaceDoc = Docs.Create.UniqeFaceDocument({
+            title: `Face ${faceDocNum}`,
+            _layout_reflowHorizontal: true,
+            _layout_reflowVertical: true,
+            _layout_nativeDimEditable: true,
+            _layout_borderRounding: '20px',
+            backgroundColor: '#555555',
+            _width: 400,
+            _height: 400,
+        });
+        const uface = uniqueFaceDoc[DocData];
+        uface.face = ''; // just to make prettyprinting look better
+        uface.face_label = `Face${faceDocNum}`;
+        uface.face_images = new List<Doc>();
+        uface.face_descriptors = new List<List<number>>();
+        Doc.SetContainer(uniqueFaceDoc, Doc.MyFaceCollection);
 
         Doc.ActiveDashboard && Doc.AddDocToList(Doc.ActiveDashboard[DocData], 'myUniqueFaces', uniqueFaceDoc);
         return uniqueFaceDoc;
@@ -222,8 +234,8 @@ export class FaceRecognitionHandler {
             setTimeout(() => this.classifyFacesInImage(imgDoc), 1000);
         } else {
             const imgUrl = ImageCast(imgDoc[Doc.LayoutFieldKey(imgDoc)]);
-            if (imgUrl && !DocListCast(Doc.MyFaceCollection.examinedFaceDocs).includes(imgDoc)) { // only examine Docs that have an image and that haven't already been examined.
-                Doc.AddDocToList(Doc.MyFaceCollection, 'examinedFaceDocs', imgDoc);
+            if (imgUrl && !DocListCast(Doc.MyFaceCollection.examinedFaceDocs).includes(imgDoc[DocData])) { // only examine Docs that have an image and that haven't already been examined.
+                Doc.AddDocToList(Doc.MyFaceCollection, 'examinedFaceDocs', imgDoc[DocData]);
                 FaceRecognitionHandler.initImageDocFaceDescriptors(imgDoc);
                 FaceRecognitionHandler.loadImage(imgUrl).then( // load image and analyze faces
                 img => faceapi.detectAllFaces(img).withFaceLandmarks().withFaceDescriptors()
-- 
cgit v1.2.3-70-g09d2

