notes
This commit is contained in:
@@ -1,36 +1,34 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
|
||||
class NoteModel extends Equatable {
|
||||
final String? id;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
final String companyId;
|
||||
final String createdBy;
|
||||
final String? title;
|
||||
final String? content;
|
||||
final String color; // Stringa Hex es. '#FFF59D'
|
||||
final String color;
|
||||
final bool isPinned;
|
||||
final bool isSharedAll;
|
||||
final String companyId;
|
||||
final List<String> collaboratorIds;
|
||||
|
||||
// Campi di utilità per la UI e le relazioni
|
||||
final List<String> collaboratorIds;
|
||||
final List<StaffMemberModel> collaborators;
|
||||
//final List<StaffMemberModel> collaborators;
|
||||
|
||||
const NoteModel({
|
||||
this.id,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
required this.companyId,
|
||||
required this.createdBy,
|
||||
this.title,
|
||||
this.content,
|
||||
this.color = '#FFF59D', // Giallo Post-it di default
|
||||
this.color = '#FFF59D',
|
||||
this.isPinned = false,
|
||||
this.isSharedAll = false,
|
||||
required this.companyId,
|
||||
this.collaboratorIds = const [],
|
||||
this.collaborators = const [],
|
||||
required this.collaboratorIds,
|
||||
});
|
||||
|
||||
/// Trasforma il colore Hex String in un oggetto Color di Flutter
|
||||
@@ -43,29 +41,27 @@ class NoteModel extends Equatable {
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
String? companyId,
|
||||
String? createdBy,
|
||||
String? title,
|
||||
String? content,
|
||||
String? color,
|
||||
bool? isPinned,
|
||||
bool? isSharedAll,
|
||||
String? companyId,
|
||||
List<String>? collaboratorIds,
|
||||
List<StaffMemberModel>? collaborators,
|
||||
}) {
|
||||
return NoteModel(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
companyId: companyId ?? this.companyId,
|
||||
createdBy: createdBy ?? this.createdBy,
|
||||
title: title ?? this.title,
|
||||
content: content ?? this.content,
|
||||
color: color ?? this.color,
|
||||
isPinned: isPinned ?? this.isPinned,
|
||||
isSharedAll: isSharedAll ?? this.isSharedAll,
|
||||
companyId: companyId ?? this.companyId,
|
||||
collaboratorIds: collaboratorIds ?? this.collaboratorIds,
|
||||
collaborators: collaborators ?? this.collaborators,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -73,7 +69,11 @@ class NoteModel extends Equatable {
|
||||
required String createdBy,
|
||||
required String companyId,
|
||||
}) {
|
||||
return NoteModel(createdBy: createdBy, companyId: companyId);
|
||||
return NoteModel(
|
||||
createdBy: createdBy,
|
||||
companyId: companyId,
|
||||
collaboratorIds: [],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
@@ -91,27 +91,6 @@ class NoteModel extends Equatable {
|
||||
}
|
||||
|
||||
factory NoteModel.fromMap(Map<String, dynamic> map) {
|
||||
// Estraiamo gli ID dei collaboratori se presenti dalla join nativa di Supabase
|
||||
List<String> collIds = [];
|
||||
List<StaffMemberModel> collModels = [];
|
||||
|
||||
if (map['note_collaborators'] != null) {
|
||||
final List jsonList = map['note_collaborators'] as List;
|
||||
for (var item in jsonList) {
|
||||
if (item['staff_id'] != null) {
|
||||
collIds.add(item['staff_id'].toString());
|
||||
}
|
||||
// Se abbiamo fatto la join profonda per avere anche i dettagli dello staff member
|
||||
if (item['staff_members'] != null) {
|
||||
collModels.add(
|
||||
StaffMemberModel.fromMap(
|
||||
item['staff_members'] as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NoteModel(
|
||||
id: map['id'] as String?,
|
||||
createdAt: map['created_at'] != null
|
||||
@@ -120,15 +99,17 @@ class NoteModel extends Equatable {
|
||||
updatedAt: map['updated_at'] != null
|
||||
? DateTime.parse(map['updated_at'] as String)
|
||||
: null,
|
||||
companyId: map['company_id'] as String,
|
||||
createdBy: map['created_by'] as String,
|
||||
title: map['title'] as String?,
|
||||
content: map['content'] as String?,
|
||||
color: map['color'] as String? ?? '#FFF59D',
|
||||
isPinned: map['is_pinned'] as bool? ?? false,
|
||||
isSharedAll: map['is_shared_all'] as bool? ?? false,
|
||||
companyId: map['company_id'] as String,
|
||||
collaboratorIds: collIds,
|
||||
collaborators: collModels,
|
||||
// TRUCCO NINJA: Castiamo l'array di Postgres in una List<String> pulita
|
||||
collaboratorIds: map['collaborator_ids'] != null
|
||||
? List<String>.from(map['collaborator_ids'] as List)
|
||||
: [],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -145,6 +126,6 @@ class NoteModel extends Equatable {
|
||||
isSharedAll,
|
||||
companyId,
|
||||
collaboratorIds,
|
||||
collaborators,
|
||||
//collaborators,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user