multiples mejoras añadidas, se retiró la categoría

This commit is contained in:
Abraham
2026-01-13 14:11:03 -08:00
parent cd23fdc071
commit 8612688aa3
8 changed files with 358 additions and 776 deletions

View File

@@ -135,8 +135,6 @@ class VideosProvider extends ChangeNotifier {
'thumbnail': PlutoCell(value: media.fileUrl),
'title': PlutoCell(value: media.title ?? media.fileName),
'file_description': PlutoCell(value: media.fileDescription),
'category':
PlutoCell(value: _getCategoryName(media.mediaCategoryFk)),
'reproducciones': PlutoCell(value: media.reproducciones),
'duration': PlutoCell(
value: media.seconds != null
@@ -168,18 +166,6 @@ class VideosProvider extends ChangeNotifier {
}
}
/// Get category name by ID
String _getCategoryName(int? categoryId) {
if (categoryId == null) return 'Sin categoría';
try {
return categories
.firstWhere((cat) => cat.mediaCategoriesId == categoryId)
.categoryName;
} catch (e) {
return 'Sin categoría';
}
}
/// Format file size to human readable
String _formatFileSize(int? bytes) {
if (bytes == null) return '-';
@@ -245,7 +231,6 @@ class VideosProvider extends ChangeNotifier {
Future<bool> uploadVideo({
required String title,
String? description,
int? categoryId,
int? durationSeconds,
List<String>? tags,
}) async {
@@ -307,7 +292,6 @@ class VideosProvider extends ChangeNotifier {
'file_url': videoUrl,
'storage_path': videoStoragePath,
'organization_fk': organizationId,
'media_category_fk': categoryId,
'metadata_json': metadataJson,
'seconds': durationSeconds,
'is_public_file': true,
@@ -445,25 +429,6 @@ class VideosProvider extends ChangeNotifier {
}
}
/// Update video category
Future<bool> updateVideoCategory(int mediaFileId, int? categoryId) async {
try {
await supabaseML
.from('media_files')
.update({'media_category_fk': categoryId})
.eq('media_file_id', mediaFileId)
.eq('organization_fk', organizationId);
await loadMediaFiles();
return true;
} catch (e) {
errorMessage = 'Error actualizando categoría: $e';
notifyListeners();
print('Error en updateVideoCategory: $e');
return false;
}
}
/// Update video metadata
Future<bool> updateVideoMetadata(
int mediaFileId,
@@ -689,29 +654,10 @@ class VideosProvider extends ChangeNotifier {
curr.reproducciones > next.reproducciones ? curr : next);
}
// Videos by category
Map<String, int> videosByCategory = {};
for (var media in mediaFiles) {
final categoryName = _getCategoryName(media.mediaCategoryFk);
videosByCategory[categoryName] =
(videosByCategory[categoryName] ?? 0) + 1;
}
// Most viewed category
String? mostViewedCategory;
if (videosByCategory.isNotEmpty) {
mostViewedCategory = videosByCategory.entries
.reduce((a, b) => a.value > b.value ? a : b)
.key;
}
return {
'total_videos': totalVideos,
'total_reproducciones': totalReproducciones,
'most_viewed_video': mostViewed?.toMap(),
'videos_by_category': videosByCategory,
'most_viewed_category': mostViewedCategory,
'total_categories': categories.length,
};
} catch (e) {
print('Error en getDashboardStats: $e');
@@ -745,8 +691,6 @@ class VideosProvider extends ChangeNotifier {
'thumbnail': PlutoCell(value: media.fileUrl),
'title': PlutoCell(value: media.title ?? media.fileName),
'file_description': PlutoCell(value: media.fileDescription),
'category':
PlutoCell(value: _getCategoryName(media.mediaCategoryFk)),
'reproducciones': PlutoCell(value: media.reproducciones),
'duration': PlutoCell(
value: media.seconds != null