2024-11-07 05:52:03 +01:00
|
|
|
import 'package:ambito/src/entity/_general/filter/item_filter_repository.dart';
|
2024-10-29 16:15:11 +01:00
|
|
|
import 'package:ambito/src/entity/entities.dart';
|
2024-11-07 05:52:03 +01:00
|
|
|
import 'package:ambito/src/extensions/extensions.dart';
|
2024-10-21 15:01:20 +02:00
|
|
|
import 'package:ambito/src/packages/ambito_db/base_db.dart';
|
|
|
|
import 'package:isar/isar.dart';
|
|
|
|
|
|
|
|
import '../../../../main.dart';
|
|
|
|
|
2024-10-28 16:17:09 +01:00
|
|
|
class MeasureRepository extends BaseDB {
|
2024-10-29 16:15:11 +01:00
|
|
|
@override
|
2024-10-28 16:17:09 +01:00
|
|
|
IsarCollection collection = isar.measures;
|
2024-11-07 05:52:03 +01:00
|
|
|
|
|
|
|
Future<bool> buildMeasureFilters() async {
|
|
|
|
Map<String, List<int>> filtersAreaType = {};
|
|
|
|
Map<String, List<int>> filtersMeasureGroup = {};
|
|
|
|
Map<String, List<int>> filterMonths = {};
|
|
|
|
Map<String, List<int>> filterFundingPrograms = {};
|
|
|
|
Map<String, String> colors = {};
|
|
|
|
|
|
|
|
var measures = getAll();
|
|
|
|
|
|
|
|
for (Measure measure in measures) {
|
|
|
|
measure.factsheetAreaType?.forEach((ivc) {
|
|
|
|
filtersAreaType.putIfAbsent(ivc.value!, () => []).add(measure.id);
|
|
|
|
colors[ivc.value!] = ivc.color!;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (measure.actionGroup != null) {
|
|
|
|
filtersMeasureGroup
|
|
|
|
.putIfAbsent(measure.actionGroup!.value!, () => [])
|
|
|
|
.add(measure.id);
|
|
|
|
colors[measure.actionGroup!.value!] = measure.actionGroup!.color!;
|
|
|
|
}
|
|
|
|
|
|
|
|
measure.timeFrame?.forEach((ivc) {
|
|
|
|
filterMonths.putIfAbsent(ivc.value!, () => []).add(measure.id);
|
|
|
|
colors[ivc.value!] = ivc.color!;
|
|
|
|
});
|
|
|
|
|
|
|
|
measure.fundingPrograms?.forEach((ivc) {
|
|
|
|
filterFundingPrograms.putIfAbsent(ivc.value!, () => []).add(measure.id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final itemFilterRepo = ItemFilterRepository();
|
|
|
|
final autoIncrement = isar.itemFilters.autoIncrement;
|
|
|
|
|
|
|
|
itemFilterRepo.putAll(filtersAreaType.entries
|
|
|
|
.map((entry) => ItemFilter()
|
|
|
|
..id = autoIncrement()
|
|
|
|
..name = entry.key
|
|
|
|
..type = 'areaType'
|
|
|
|
..description =
|
2024-11-09 22:03:03 +01:00
|
|
|
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy.'
|
2024-11-07 05:52:03 +01:00
|
|
|
..image =
|
|
|
|
'images/actions/areatype/${entry.key.toLowerCase().replaceUmlauts()}.jpg'
|
|
|
|
..color = colors[entry.key]
|
|
|
|
..ids = entry.value)
|
|
|
|
.toList());
|
|
|
|
|
|
|
|
itemFilterRepo.putAll(filtersMeasureGroup.entries
|
|
|
|
.map((entry) => ItemFilter()
|
|
|
|
..id = autoIncrement()
|
|
|
|
..name = entry.key
|
|
|
|
..type = 'group'
|
2024-11-09 22:03:03 +01:00
|
|
|
..description = 'Lorem ipsum dolor sit amet, consetetur sadipscing.'
|
2024-11-07 05:52:03 +01:00
|
|
|
..image =
|
|
|
|
'images/actions/areatype/${entry.key.toLowerCase().replaceUmlauts()}.jpg'
|
|
|
|
..color = colors[entry.key]
|
|
|
|
..ids = entry.value)
|
|
|
|
.toList());
|
|
|
|
|
|
|
|
itemFilterRepo.putAll(filterMonths.entries
|
|
|
|
.map((entry) => ItemFilter()
|
|
|
|
..id = autoIncrement()
|
|
|
|
..name = entry.key
|
|
|
|
..type = 'month'
|
|
|
|
..ids = entry.value)
|
|
|
|
.toList());
|
|
|
|
|
|
|
|
itemFilterRepo.putAll(filterFundingPrograms.entries
|
|
|
|
.map((entry) => ItemFilter()
|
|
|
|
..id = autoIncrement()
|
|
|
|
..name = entry.key
|
|
|
|
..type = 'fundingProgram'
|
|
|
|
..ids = entry.value)
|
|
|
|
.toList());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getMeasureCount() {
|
|
|
|
return isar.measures.where().count();
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Measure?> getByIds(List<int> ids) {
|
|
|
|
return isar.measures.getAll(ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Measure> getAllOrdered() {
|
|
|
|
return isar.measures.where().sortByName().findAll();
|
|
|
|
}
|
2024-11-09 22:03:03 +01:00
|
|
|
|
|
|
|
Future<bool> downloadImages() async {
|
|
|
|
List<Measure> measures = isar.measures.where().findAll();
|
|
|
|
List<String> files = [];
|
|
|
|
for (Measure measure in measures) {
|
|
|
|
if (measure.files != null) {
|
|
|
|
for (FilePart file in measure.files!) {
|
|
|
|
files.add(file.url!);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.d(files);
|
|
|
|
return true;
|
|
|
|
}
|
2024-10-21 15:01:20 +02:00
|
|
|
}
|