Compare commits

7 Commits

Author SHA1 Message Date
c31b5c5b14 Refactor relationship types to single class and add more
Took 38 minutes
2025-04-16 15:39:13 +02:00
0333d37aae Refactor to interfaces and type classes
Took 5 minutes
2025-04-16 13:59:15 +02:00
3da29516ec Refactor friendship types to one type
Took 10 minutes
2025-04-16 13:49:58 +02:00
00e7294f41 Set name to firstname and first letter of lastname and increase node size
Took 3 hours 34 minutes
2025-04-16 13:25:47 +02:00
b054d55018 add autofocus for modals 2025-04-16 11:27:39 +02:00
bbb3645d99 Fix birthdate input 2025-04-16 11:17:50 +02:00
9ce80b4c59 Fix Dockerfile healthcheck, add curl 2025-04-16 10:53:55 +02:00
11 changed files with 214 additions and 447 deletions

View File

@ -44,6 +44,12 @@ LABEL "org.opencontainers.image.version"="1.0.0"
LABEL "VERSION"="1.0.0"
LABEL maintainer="Tobias Hopp and Philip Rothstein"
# Install curl for healthcheck
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get -qq -y install curl && \
rm -rf /var/cache/apt/archives /var/lib/apt/lists/*
WORKDIR /app

View File

@ -1,4 +1,6 @@
import axios from 'axios';
import { RELATIONSHIP_TYPES } from '../types/RelationShipTypes';
import { Relationship } from '../interfaces/IRelationship';
const protocol = window.location.protocol;
const hostname = window.location.hostname;
@ -6,27 +8,15 @@ const port = window.location.port;
const API_URL = protocol + '//' + hostname + (port ? ':' + port : '') + '/api';
// Types
export interface Relationship {
_id: string;
source: string;
target: string;
type: 'freund' | 'partner' | 'familie' | 'arbeitskolleg' | 'custom';
customType?: string;
network: string;
createdAt: string;
updatedAt: string;
}
export interface CreateRelationshipData {
source: string;
target: string;
type: 'freund' | 'partner' | 'familie' | 'arbeitskolleg' | 'custom';
type: RELATIONSHIP_TYPES;
customType?: string;
}
export interface UpdateRelationshipData {
type?: 'freund' | 'partner' | 'familie' | 'arbeitskolleg' | 'custom';
type?: RELATIONSHIP_TYPES;
customType?: string;
}

View File

@ -35,9 +35,9 @@ interface CanvasGraphProps {
}
// Physics constants
const NODE_RADIUS = 30; // Node radius in pixels
const MIN_DISTANCE = 100; // Minimum distance between any two nodes
const MAX_DISTANCE = 300; // Maximum distance between connected nodes
const NODE_RADIUS = 45; // Node radius in pixels
const MIN_DISTANCE = 110; // Minimum distance between any two nodes
const MAX_DISTANCE = 500; // Maximum distance between connected nodes
const REPULSION_STRENGTH = 500; // How strongly nodes repel each other when too close
const ATTRACTION_STRENGTH = 0.1; // Default attraction between connected nodes
const CONSTRAINT_STRENGTH = 0.2; // Strength of distance constraints
@ -573,9 +573,9 @@ const CanvasGraph: React.FC<CanvasGraphProps> = ({ data, width, height, zoomLeve
ctx.stroke();
// Draw initials
const initials = `${node.firstName.charAt(0)}${node.lastName.charAt(0)}`;
const initials = `${node.firstName} ${node.lastName.charAt(0)}.`;
ctx.fillStyle = 'white';
ctx.font = 'bold 16px sans-serif';
ctx.font = 'bold 13px sans-serif';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(initials, pos.x, pos.y);

File diff suppressed because it is too large Load Diff

View File

@ -3,10 +3,11 @@ import { addPerson, getPeople, Person, removePerson, updatePerson } from '../api
import {
addRelationship,
getRelationships,
Relationship,
removeRelationship,
updateRelationship,
} from '../api/relationships';
import { Relationship } from '../interfaces/IRelationship';
import { RELATIONSHIP_TYPES } from '../types/RelationShipTypes';
interface PersonNode extends Person {
// Additional properties needed for the visualization
@ -314,7 +315,7 @@ export const useFriendshipNetwork = (
const createRelationship = async (relationshipData: {
source: string;
target: string;
type: 'freund' | 'partner' | 'familie' | 'arbeitskolleg' | 'custom';
type: RELATIONSHIP_TYPES;
customType?: string;
}): Promise<RelationshipEdge> => {
if (!networkId) throw new Error('No network selected');
@ -342,7 +343,7 @@ export const useFriendshipNetwork = (
const updateRelationshipData = async (
relationshipId: string,
relationshipData: {
type?: 'freund' | 'partner' | 'familie' | 'arbeitskolleg' | 'custom';
type?: RELATIONSHIP_TYPES;
customType?: string;
},
): Promise<RelationshipEdge> => {

View File

@ -0,0 +1,15 @@
export interface PersonNode {
_id: string;
firstName: string;
lastName: string;
birthday?: Date | string | null;
notes?: string;
position?: {
x: number; y: number;
};
}
// Type for form errors
export interface FormErrors {
[key: string]: string;
}

View File

@ -0,0 +1,13 @@
// Types
import { RELATIONSHIP_TYPES } from '../types/RelationShipTypes';
export interface Relationship {
_id: string;
source: string;
target: string;
type: RELATIONSHIP_TYPES;
customType?: string;
network: string;
createdAt: string;
updatedAt: string;
}

View File

@ -0,0 +1,15 @@
export type RELATIONSHIP_TYPES = 'acquaintance' | 'friend' | 'partner' | 'family' | 'secondDegree' | 'colleague' | 'teacher' | 'exPartner' | 'custom';
export const RELATIONSHIPS: Record<RELATIONSHIP_TYPES, { label: string; color: string }> = {
acquaintance: { label: 'Bekannter', color: '#60A5FA' }, // Light blue
friend: { label: 'Freund', color: '#60A5FA' }, // Light blue
partner: { label: 'Partner', color: '#F472B6' }, // Pink
family: { label: 'Familie', color: '#34D399' }, // Green
secondDegree: { label: 'Verwandter', color: '#34D399' }, // Green
colleague: { label: 'Kollege/Klassenkamerad', color: '#FBBF24' }, // Yellow
teacher: { label: 'Lehrer', color: '#FBBF24' }, // Yellow
exPartner: { label: 'Ex-Partner', color: '#ce8c13' }, // Orange
custom: { label: 'Benutzerdefiniert', color: '#9CA3AF' }, // Gray
};
export const getRelationshipLabel = (type: RELATIONSHIP_TYPES): string => RELATIONSHIPS[type].label;
export const getRelationshipColor = (type: RELATIONSHIP_TYPES): string => RELATIONSHIPS[type].color;

View File

@ -217,12 +217,12 @@ const createSampleDemoNetwork = async (userId: mongoose.Types.ObjectId | string)
// Create relationships between people
const relationships = [
{ source: 'JohnSmith', target: 'EmmaJohnson', type: 'freund' },
{ source: 'EmmaJohnson', target: 'MichaelWilliams', type: 'familie' },
{ source: 'MichaelWilliams', target: 'SarahBrown', type: 'arbeitskolleg' },
{ source: 'SarahBrown', target: 'DavidJones', type: 'freund' },
{ source: 'JohnSmith', target: 'EmmaJohnson', type: 'friend' },
{ source: 'EmmaJohnson', target: 'MichaelWilliams', type: 'family' },
{ source: 'MichaelWilliams', target: 'SarahBrown', type: 'colleague' },
{ source: 'SarahBrown', target: 'DavidJones', type: 'friend' },
{ source: 'DavidJones', target: 'LisaGarcia', type: 'partner' },
{ source: 'JohnSmith', target: 'DavidJones', type: 'arbeitskolleg' },
{ source: 'JohnSmith', target: 'DavidJones', type: 'colleague' },
];
// Create each relationship

View File

@ -1,5 +1,10 @@
import mongoose, { Document, Schema } from 'mongoose';
export const RELATIONSHIP_TYPES = [
'acquaintance', 'friend', 'partner', 'family', 'secondDegree', 'colleague', 'teacher', 'exPartner', 'custom',
];
export interface IRelationship extends Document {
_id: string;
source: mongoose.Types.ObjectId;
@ -24,7 +29,7 @@ const RelationshipSchema = new Schema(
type: {
type: String,
required: [true, 'Relationship type is required'],
enum: ['freund', 'partner', 'familie', 'arbeitskolleg', 'custom'],
enum: RELATIONSHIP_TYPES,
},
customType: {
type: String,
@ -36,7 +41,7 @@ const RelationshipSchema = new Schema(
required: true,
},
},
{ timestamps: true }
{ timestamps: true },
);
// Create compound index to ensure unique relationships in a network

View File

@ -3,6 +3,8 @@ import { check } from 'express-validator';
import * as relationshipController from '../controllers/relationship.controller';
import { auth } from '../middleware/auth.middleware';
import { checkNetworkAccess } from '../middleware/network-access.middleware';
import { RELATIONSHIP_TYPES } from '../models/relationship.model';
const router = express.Router();
@ -22,13 +24,7 @@ router.post(
[
check('source', 'Source person ID is required').not().isEmpty().isMongoId(),
check('target', 'Target person ID is required').not().isEmpty().isMongoId(),
check('type', 'Relationship type is required').isIn([
'freund',
'partner',
'familie',
'arbeitskolleg',
'custom',
]),
check('type', 'Relationship type is required').isIn(RELATIONSHIP_TYPES),
check('customType', 'Custom type is required when type is custom')
.if(check('type').equals('custom'))
.not()
@ -45,7 +41,7 @@ router.put(
[
check('type', 'Relationship type must be valid if provided')
.optional()
.isIn(['freund', 'partner', 'familie', 'arbeitskolleg', 'custom']),
.isIn(RELATIONSHIP_TYPES),
check('customType', 'Custom type is required when type is custom')
.if(check('type').equals('custom'))
.not()