KonectarEvents/lib/viewmodel/eventsprovider.dart

355 lines
10 KiB
Dart
Raw Permalink Normal View History

2024-09-06 06:30:31 +00:00
import 'dart:async';
2024-10-07 12:45:45 +00:00
import 'dart:math';
2024-09-06 06:30:31 +00:00
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
2024-10-07 12:45:45 +00:00
import 'package:konectar_events/model/affiliationsmodel.dart';
2024-09-06 06:30:31 +00:00
import 'package:konectar_events/model/eventsdetailmodel.dart';
import 'package:konectar_events/model/eventsmodel.dart';
2024-10-07 12:45:45 +00:00
import 'package:konectar_events/model/eventsoverview.dart';
2024-09-06 06:30:31 +00:00
import 'package:konectar_events/model/keywords_model.dart';
import 'package:konectar_events/model/neweventsmodel.dart';
import 'package:konectar_events/model/scope_model.dart';
import 'package:konectar_events/model/sessionnotesmodel.dart';
2024-10-07 12:45:45 +00:00
import 'package:konectar_events/model/specialtymodel.dart';
2024-09-06 06:30:31 +00:00
import 'package:konectar_events/model/topics_cloud_model.dart';
import 'package:konectar_events/utils/apicall.dart';
import 'package:konectar_events/utils/dateformater.dart';
import 'package:konectar_events/widgets/word_cloud.dart';
class EventsProvider extends ChangeNotifier {
List<Keyword> keywordList = [];
List<Therapeutic> therapeuticList = [];
List<EventsList> eventList = [];
List<EventsList> searchList = [];
List<EventsList> myEvents = [];
List<Eventsdetail> eventdetailList = [];
List<Eventsdetail> srcheventdetailList = [];
List<String> selectedTherapeutic = [];
List<SessionNotesModel> addedSessionNotes = [];
int eventSessionCount = 0;
String message = "";
late Box<EventsList> box;
late Box<SessionNotesModel> sessionBox;
bool isAllSelected = true;
bool isFavSeleted = false;
bool isSearch = false;
bool isSearchSpeakers = false;
List<FlutterHashtag> kFlutterHashtags = [];
List<TopicsCloudData> topics = [];
2024-10-07 12:45:45 +00:00
List<Specialty> specialtyList = [];
OverviewData? overviewData;
Affiliations affiliations =
Affiliations(affiliationCount: [], affiliationNames: []);
2024-09-06 06:30:31 +00:00
onSelectAll() async {
// isFavSeleted = false;
// isAllSelected = !isAllSelected;
eventList = await getEvents();
notifyListeners();
}
onSelectMy() async {
// isFavSeleted = !isFavSeleted;
eventList = await getMyEventsData();
notifyListeners();
}
OnSearch(String searchtxt) {
// searchtxt = searchtxt.toLowerCase();
isSearch = true;
if (isFavSeleted) {
searchList = eventList
.where((element) => element.name1!.toLowerCase().contains(searchtxt))
// (element.city != "" &&
// element.city!.toLowerCase().contains(searchtxt)) ||
// (element.region != "" &&
// element.region!.toLowerCase().contains(searchtxt)) ||
// (element.country != "" &&
// element.country!.toLowerCase().contains(searchtxt)))
.toList();
} else {
searchList = eventList
.where((element) => element.name1!.toLowerCase().contains(searchtxt))
// element.city!.toLowerCase().contains(searchtxt) ||
// element.region!.toLowerCase().contains(searchtxt) ||
// element.country!.toLowerCase().contains(searchtxt))
.toList();
}
print("###$searchList@@@");
notifyListeners();
}
getSessionCount() {
List<String> sessions = [];
eventSessionCount = 0;
for (var obj in eventdetailList) {
sessions.addAll(obj.sessionName!.split(','));
eventSessionCount += int.parse(obj.numSess ?? "0");
}
print("Count ${sessions.toSet().toList().length}");
print("Count2 ${sessions.toList().length}");
print("SEE SESSIONS ${sessions.toSet().toList()}");
eventSessionCount = sessions.toSet().toList().length;
notifyListeners();
}
OnFilters() {
isSearch = true;
if (isFavSeleted) {
searchList = myEvents
.where((element) =>
selectedTherapeutic.contains(element.therapeuticArea))
.toList();
} else {
searchList = myEvents
.where((element) =>
selectedTherapeutic.contains(element.therapeuticArea))
.toList();
}
print("###$searchList@@@");
notifyListeners();
}
onFilterReset() async {
if (isFavSeleted) {
eventList = await getMyEventsData();
} else {
eventList = await getEvents();
}
isSearch = false;
searchList.clear();
notifyListeners();
}
onSearchReset() async {
if (isFavSeleted) {
eventList = await getMyEventsData();
} else {
eventList = await getEvents();
}
isSearch = false;
searchList.clear();
notifyListeners();
}
OnSearchSpeakers(String searchtxt) {
searchtxt = searchtxt.toLowerCase();
isSearchSpeakers = true;
srcheventdetailList = eventdetailList
.where((element) =>
element.kolFullName!.toLowerCase().contains(searchtxt) ||
element.eventTopics!.toLowerCase().contains(searchtxt))
.toList();
notifyListeners();
}
onSearchSpeakersReset(String eventid) async {
eventdetailList = await getEventsDetails(eventid);
isSearchSpeakers = false;
srcheventdetailList.clear();
notifyListeners();
}
initFiltersData() async {
// keywordList = await ApiCall().getkeywords('');
2024-10-07 12:45:45 +00:00
// therapeuticList = await ApiCall().getscopes();
2024-09-06 06:30:31 +00:00
notifyListeners();
}
Future<List<Keyword>> getKeywordList(String keyword) async {
keywordList = await ApiCall().getkeywords(keyword);
return keywordList;
//notifyListeners();
}
Future<List<EventsList>> getEvents() async {
eventList = await getAllEventsData();
if (eventList.isEmpty) {
eventList = (await ApiCall().getEvents())!;
2024-10-07 12:45:45 +00:00
//eventList = (await ApiCall().getStagingEvents())!;
2024-09-06 06:30:31 +00:00
for (var events in eventList) {
await saveEventsData(events);
}
}
return eventList;
//notifyListeners();
}
Future<List<SessionNotesModel>> getAddedSessionNotes() async {
addedSessionNotes = await getAllSessionNotesList();
if (addedSessionNotes.isEmpty && eventList.isNotEmpty) {
addedSessionNotes = (await ApiCall().getSessionNotes())!;
for (SessionNotesModel notes in addedSessionNotes) {
int i =
eventList.indexWhere((element) => element.name1 == notes.eventname);
if (i != -1) {
notes.eventid = eventList[i].eventId;
}
notes.addedBy = "user";
notes.addedDate = CustomDateFormatter().formatDate();
await saveSessionDataFromResp(notes);
}
}
return addedSessionNotes;
//notifyListeners();
}
Future<List<Eventsdetail>> getEventsDetails(String eventid) async {
eventdetailList = (await ApiCall().getLocalEventsDetail(eventid))!;
return eventdetailList;
//notifyListeners();
}
Future<String> addEventsToFavs(String eventid) async {
message = await ApiCall().addEventsToFav(eventid);
return message;
//notifyListeners();
}
Future<String> markAttending(String eventid) async {
message = await ApiCall().attendEvents(eventid);
return message;
//notifyListeners();
}
FutureOr saveEventsData(EventsList eventsData) async {
box = await Hive.openBox<EventsList>('EventsListBox');
box.add(eventsData);
List<EventsList> eventsData2 = await getMyEventsData();
notifyListeners();
}
FutureOr favsEventsData(EventsList eventsData) async {
box = await Hive.openBox<EventsList>('EventsListBox');
List<EventsList> data = box.values.toList();
int index = data.indexWhere(
(element) => element.eventId == eventsData.eventId,
);
box.putAt(index, eventsData);
List<EventsList> eventsData2 = await getMyEventsData();
notifyListeners();
}
Future<List<EventsList>> getMyEventsData() async {
box = await Hive.openBox<EventsList>('EventsListBox');
Iterable<EventsList> data = box.values;
myEvents = data
.where(
(element) => element.isfav == true,
)
.toList();
// EventsList eventsdata = EventsList();
// for (var obj in data) {
// eventsdata = new EventsList.fromJson(obj.toJson());
// }
return myEvents;
}
Future<List<EventsList>> getAllEventsData() async {
box = await Hive.openBox<EventsList>('EventsListBox');
Iterable<EventsList> data = box.values;
myEvents = data.toList();
// EventsList eventsdata = EventsList();
// for (var obj in data) {
// eventsdata = new EventsList.fromJson(obj.toJson());
// }
return myEvents;
}
Future<List<SessionNotesModel>> getAllSessionNotesList() async {
sessionBox = await Hive.openBox<SessionNotesModel>('SessionNotesModelBox');
Iterable<SessionNotesModel> data = sessionBox.values;
addedSessionNotes = data.toList();
// EventsList eventsdata = EventsList();
// for (var obj in data) {
// eventsdata = new EventsList.fromJson(obj.toJson());
// }
return addedSessionNotes;
}
FutureOr deleteAllEventsData() async {
box = await Hive.openBox<EventsList>('EventsListBox');
box.clear();
}
FutureOr delateEventsData(EventsList event) async {
//DELETE
// box = await Hive.openBox<EventsList>('EventsListBox');
// List<EventsList> data = box.values.toList();
// int index = data.indexWhere(
// (element) => element.eventId == eventid,
// );
// await box.deleteAt(index);
//REMOVE FROM FAVS
box = await Hive.openBox<EventsList>('EventsListBox');
List<EventsList> data = box.values.toList();
int index = data.indexWhere(
(element) => element.eventId == event.eventId,
);
event.isfav = false;
box.putAt(index, event);
eventList = await getMyEventsData();
notifyListeners();
}
FutureOr saveSessionDataFromResp(SessionNotesModel notesModel) async {
sessionBox = await Hive.openBox<SessionNotesModel>('SessionNotesModelBox');
sessionBox.add(notesModel);
notifyListeners();
}
FutureOr getTopicsCloud(String eventid) async {
List<TopicsCloudData> topics =
(await ApiCall().getTopicsCloudData(eventid))!;
// for (var events in eventList) {
// await saveEventsData(events);
// }
//notifyListeners();
kFlutterHashtags = [];
for (var topic in topics) {
kFlutterHashtags
.add(FlutterHashtag(topic.topic!, int.parse(topic.total!), false));
}
notifyListeners();
}
2024-10-07 12:45:45 +00:00
FutureOr getSpecialtyData(String eventid) async {
specialtyList = (await ApiCall().getSpecialty(eventid))!;
notifyListeners();
}
FutureOr getAffiliations(String eventid) async {
affiliations = (await ApiCall().getSpeakerCounts(eventid))!;
notifyListeners();
}
FutureOr getOverviewData(
String eventid, String startDate, String endDate) async {
overviewData =
(await ApiCall().getEventsOverview(eventid, startDate, endDate));
notifyListeners();
}
2024-09-06 06:30:31 +00:00
}