Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/library reservations #1073

Open
wants to merge 53 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6e3221e
Merge branch 'feature/library-occupation' into feature/library-rooms
jlcrodrigues Nov 13, 2022
3077511
feat: library reservations fetcher
jlcrodrigues Nov 14, 2022
c23cf3d
Display reserved library rooms
jlcrodrigues Dec 11, 2022
5ed8089
Merge branch 'feature/library-occupation' into feature/library-rooms
jlcrodrigues Dec 11, 2022
cfec53e
Merge branch 'feature/library-rooms'
jlcrodrigues Dec 11, 2022
83d9e1a
Merge branch feature/library-occupation
jlcrodrigues Jan 30, 2023
057e001
Merge branch 'feature/library-occupation' of github.com:NIAEFEUP/proj…
jlcrodrigues Jan 30, 2023
76cfe79
Added library reservations card to main page
jlcrodrigues Jan 30, 2023
36980a7
Added tabs to library page
jlcrodrigues Jan 30, 2023
fc95928
Reworked library data flow
jlcrodrigues Feb 12, 2023
6ce563e
Merge branch 'develop'
jlcrodrigues Feb 12, 2023
af78294
Fix merge conflicts
jlcrodrigues Feb 12, 2023
c2ecf16
Made changes to reserved rooms card
jlcrodrigues Feb 12, 2023
7e4b925
Reworked library reservations' view
jlcrodrigues Feb 12, 2023
53c2859
Added custom reservations route
jlcrodrigues Feb 12, 2023
1aa923b
Small changes to library reservations
jlcrodrigues Feb 12, 2023
9fa6414
Merge branch 'develop'
jlcrodrigues Feb 12, 2023
7cfd371
Merge branch 'develop' into feature/library-rooms
jlcrodrigues Feb 12, 2023
fd285b4
Merge branch develop
jlcrodrigues Mar 15, 2023
a86709b
Fixed providers issues
jlcrodrigues Mar 15, 2023
c2d0834
Refactored helper functions
jlcrodrigues Mar 15, 2023
ea8af13
Made changes according to suggestions
jlcrodrigues Apr 12, 2023
aad69ab
Finished requested changes
jlcrodrigues Apr 12, 2023
9723a9b
Fixed linter issues
jlcrodrigues Apr 12, 2023
1a553fc
Removed nullable type from RoomList
jlcrodrigues May 9, 2023
34aac72
Remove redundant reservation duration from db
jlcrodrigues Jun 21, 2023
e582cf7
Feature/library rooms (#658)
thePeras Jun 21, 2023
30ef2c0
Merge branch 'develop'
jlcrodrigues Aug 24, 2023
c2aceee
Merge branch 'develop' of github.com:NIAEFEUP/project-schrodinger int…
jlcrodrigues Aug 24, 2023
4c0f4b0
Merge branch 'develop'
jlcrodrigues Aug 26, 2023
bc185b4
Merge branch develop
jlcrodrigues Sep 26, 2023
3b10427
Merge branch 'develop' of github.com:NIAEFEUP/project-schrodinger int…
jlcrodrigues Sep 26, 2023
da5c3fe
Merge branch 'develop'
jlcrodrigues Nov 9, 2023
dc64cda
Merge branch 'develop'
jlcrodrigues Dec 11, 2023
2e61e75
Merge branch 'develop'
jlcrodrigues Dec 28, 2023
ca22148
Lint fixes
jlcrodrigues Dec 29, 2023
ee64b61
Merge branch 'develop' of github.com:NIAEFEUP/project-schrodinger int…
jlcrodrigues Jan 8, 2024
eabde47
Removed leftover ignore
jlcrodrigues Jan 8, 2024
80df1bc
Generated translation files
jlcrodrigues Jan 8, 2024
97507c7
Fixed library card page link
jlcrodrigues Jan 11, 2024
a4e7a04
Merge branch 'develop' of github.com:NIAEFEUP/project-schrodinger int…
jlcrodrigues Jan 24, 2024
eb601cd
Reverted messages_all file, fixing tests
jlcrodrigues Jan 24, 2024
65f3fe4
Fixed reservation weekday
jlcrodrigues Jan 24, 2024
7e4ca20
Merged branch 'develop'
jlcrodrigues Feb 7, 2024
629ba80
Made changes according to suggestions
jlcrodrigues Feb 7, 2024
2feccd3
Merged branch develop
jlcrodrigues Feb 7, 2024
30d2eaa
Made no reservations message appear as in the other cards
jlcrodrigues Feb 7, 2024
d2676ff
Fixed library occupation color
jlcrodrigues Feb 7, 2024
94a5b41
Merge branch 'develop'
jlcrodrigues Feb 14, 2024
91ca26f
Made changes according to suggestions
jlcrodrigues Feb 14, 2024
9f8404f
Formatted file
jlcrodrigues Feb 14, 2024
7977fdb
Merge branch 'develop'
jlcrodrigues Feb 24, 2024
9b0aa46
Removed unused imports
jlcrodrigues Feb 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion uni/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ subprojects {

tasks.register("clean", Delete) {
delete rootProject.buildDir
}
}
23 changes: 23 additions & 0 deletions uni/lib/controller/fetchers/library_reservation_fetcher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:uni/controller/fetchers/session_dependant_fetcher.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/controller/parsers/parser_library_reservation.dart';
import 'package:uni/model/entities/library_reservation.dart';
import 'package:uni/model/entities/session.dart';

/// Get the library rooms' reservations from the website
class LibraryReservationsFetcherHtml implements SessionDependantFetcher {
@override
List<String> getEndpoints(Session session) {
final url = '${NetworkRouter.getBaseUrl('feup')}res_recursos_geral'
'.pedidos_list?pct_tipo_grupo_id=3';
return [url];
}

Future<List<LibraryReservation>> getReservations(Session session) async {
final baseUrl = getEndpoints(session)[0];
final response = NetworkRouter.getWithCookies(baseUrl, {}, session);
final reservations = await response.then(getReservationsFromHtml);

return reservations;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:uni/controller/local_storage/database/app_database.dart';
import 'package:uni/model/entities/library_reservation.dart';

class LibraryReservationDatabase extends AppDatabase {
LibraryReservationDatabase()
: super('reservations.db', [
'''
CREATE TABLE RESERVATION(
id INTEGER PRIMARY KEY AUTOINCREMENT,
room TEXT,
startDate TEXT,
duration INT
)
'''
]);

Future<void> saveReservations(List<LibraryReservation> reservations) async {
final db = await getDatabase();
await db.transaction((txn) async {
await txn.delete('RESERVATION');
for (final reservation in reservations) {
await txn.insert('RESERVATION', reservation.toMap());
}
});
}

Future<List<LibraryReservation>> reservations() async {
final db = await getDatabase();

final List<Map<String, dynamic>> items = await db.query('RESERVATION');

return items.map((item) {
final minutes = item['duration'] as int;
return LibraryReservation(
item['room'] as String,
DateTime.parse(item['startDate'] as String),
Duration(hours: minutes ~/ 60, minutes: minutes % 60),
);
}).toList();
}
}
24 changes: 24 additions & 0 deletions uni/lib/controller/parsers/parser_library_reservation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:html/parser.dart';
import 'package:http/http.dart';
import 'package:uni/model/entities/library_reservation.dart';

Future<List<LibraryReservation>> getReservationsFromHtml(
Response response,
) async {
final document = parse(response.body);

final reservationHtml = document.getElementsByClassName('d interior');

return reservationHtml.map((element) {
final room = element.children[5].firstChild?.text;
final date = element.children[0].firstChild?.text;
final hour = element.children[2].firstChild?.text;
final startDate = DateTime.parse('$date $hour');
final durationHtml = element.children[4].firstChild?.text;
final duration = Duration(
hours: int.parse(durationHtml!.substring(0, 2)),
minutes: int.parse(durationHtml.substring(3, 5)),
);
return LibraryReservation(room!, startDate, duration);
}).toList();
}
20 changes: 14 additions & 6 deletions uni/lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes
// ignore_for_file:unused_import, file_names

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand All @@ -20,12 +19,12 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';

static String m0(time) => "last refresh at ${time}";
static m0(time) => "last refresh at ${time}";

static String m1(time) =>
static m1(time) =>
"${Intl.plural(time, zero: 'Refreshed ${time} minutes ago', one: 'Refreshed ${time} minute ago', other: 'Refreshed ${time} minutes ago')}";

static String m2(title) => "${Intl.select(title, {
static m2(title) => "${Intl.select(title, {
'horario': 'Schedule',
'exames': 'Exams',
'area': 'Personal Area',
Expand All @@ -42,7 +41,7 @@ class MessageLookup extends MessageLookupByLibrary {
})}";

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
static _notInlinedMessages(_) => <String, Function>{
"about": MessageLookupByLibrary.simpleMessage("About us"),
"academic_services":
MessageLookupByLibrary.simpleMessage("Academic services"),
Expand Down Expand Up @@ -152,8 +151,15 @@ class MessageLookup extends MessageLookupByLibrary {
"language": MessageLookupByLibrary.simpleMessage("Language"),
"last_refresh_time": m0,
"last_timestamp": m1,
"library": MessageLookupByLibrary.simpleMessage("Library"),
"library_occupation":
MessageLookupByLibrary.simpleMessage("Library Occupation"),
"library_reservations":
MessageLookupByLibrary.simpleMessage("Library Reservations"),
"library_tab_occupation":
MessageLookupByLibrary.simpleMessage("Occupation"),
"library_tab_reservations":
MessageLookupByLibrary.simpleMessage("Reservations"),
"load_error": MessageLookupByLibrary.simpleMessage(
"Error loading the information"),
"loading_terms": MessageLookupByLibrary.simpleMessage(
Expand Down Expand Up @@ -212,6 +218,8 @@ class MessageLookup extends MessageLookupByLibrary {
"No print balance information"),
"no_references": MessageLookupByLibrary.simpleMessage(
"There are no references to pay"),
"no_reservations": MessageLookupByLibrary.simpleMessage(
"There are no reservations to display"),
"no_results": MessageLookupByLibrary.simpleMessage("No match"),
"no_selected_courses": MessageLookupByLibrary.simpleMessage(
"There are no course units to display"),
Expand Down
18 changes: 13 additions & 5 deletions uni/lib/generated/intl/messages_pt_PT.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes
// ignore_for_file:unused_import, file_names

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand All @@ -20,12 +19,12 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'pt_PT';

static String m0(time) => "última atualização às ${time}";
static m0(time) => "última atualização às ${time}";

static String m1(time) =>
static m1(time) =>
"${Intl.plural(time, zero: 'Atualizado há ${time} minutos', one: 'Atualizado há ${time} minuto', other: 'Atualizado há ${time} minutos')}";

static String m2(title) => "${Intl.select(title, {
static m2(title) => "${Intl.select(title, {
'horario': 'Horário',
'exames': 'Exames',
'area': 'Área Pessoal',
Expand Down Expand Up @@ -152,8 +151,15 @@ class MessageLookup extends MessageLookupByLibrary {
"language": MessageLookupByLibrary.simpleMessage("Idioma"),
"last_refresh_time": m0,
"last_timestamp": m1,
"library": MessageLookupByLibrary.simpleMessage("Biblioteca"),
"library_occupation":
MessageLookupByLibrary.simpleMessage("Ocupação da Biblioteca"),
"library_reservations":
MessageLookupByLibrary.simpleMessage("Gabinetes Reservados"),
"library_tab_occupation":
MessageLookupByLibrary.simpleMessage("Ocupação"),
"library_tab_reservations":
MessageLookupByLibrary.simpleMessage("Gabinetes"),
"load_error": MessageLookupByLibrary.simpleMessage(
"Erro ao carregar a informação"),
"loading_terms": MessageLookupByLibrary.simpleMessage(
Expand Down Expand Up @@ -214,6 +220,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Sem informação de saldo"),
"no_references": MessageLookupByLibrary.simpleMessage(
"Não existem referências a pagar"),
"no_reservations": MessageLookupByLibrary.simpleMessage(
"Não existem reservas para apresentar"),
"no_results": MessageLookupByLibrary.simpleMessage("Sem resultados"),
"no_selected_courses": MessageLookupByLibrary.simpleMessage(
"Não existem cadeiras para apresentar"),
Expand Down
52 changes: 51 additions & 1 deletion uni/lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions uni/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,16 @@
"time": {}
}
},
"library": "Library",
"@library": {},
"library_occupation": "Library Occupation",
"@library_occupation": {},
"library_reservations": "Library Reservations",
"@library_reservations": {},
"library_tab_occupation": "Occupation",
"@library_tab_occupation": {},
"library_tab_reservations": "Reservations",
"@library_tab_reservations": {},
"download_error": "Error downloading the file",
"@download_error": {},
"loading_terms": "Loading Terms and Conditions...",
Expand All @@ -174,6 +182,8 @@
"@no_bus": {},
"no_bus_stops": "No configured stops",
"@no_bus_stops": {},
"no_reservations": "There are no reservations to display",
"@no_reservations": {},
"no_class": "There are no classes to display",
"@no_class": {},
"no_classes": "No classes to present",
Expand Down
14 changes: 12 additions & 2 deletions uni/lib/l10n/intl_pt_PT.arb
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,18 @@
"time": {}
}
},
"load_error": "Erro ao carregar a informação",
"@load_error": {},
"library": "Biblioteca",
"@library": {},
"library_occupation": "Ocupação da Biblioteca",
"@library_occupation": {},
"library_reservations": "Gabinetes Reservados",
"@library_reservations": {},
"library_tab_occupation": "Ocupação",
"@library_tab_occupation": {},
"library_tab_reservations": "Gabinetes",
"@library_tab_reservations": {},
"load_error": "Erro ao carregar a informação",
"@load_error": {},
"download_error": "Erro ao descarregar o ficheiro",
"@download_error": {},
"successful_open": "Ficheiro aberto com sucesso",
Expand Down Expand Up @@ -184,6 +192,8 @@
"@no_bus": {},
"no_bus_stops": "Não existe nenhuma paragem configurada",
"@no_bus_stops": {},
"no_reservations": "Não existem reservas para apresentar",
"@no_reservations": {},
"no_class": "Não existem turmas para apresentar",
"@no_class": {},
"no_classes": "Não existem aulas para apresentar",
Expand Down
14 changes: 13 additions & 1 deletion uni/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'package:uni/model/providers/lazy/exam_provider.dart';
import 'package:uni/model/providers/lazy/faculty_locations_provider.dart';
import 'package:uni/model/providers/lazy/lecture_provider.dart';
import 'package:uni/model/providers/lazy/library_occupation_provider.dart';
import 'package:uni/model/providers/lazy/library_reservations_provider.dart';
import 'package:uni/model/providers/lazy/reference_provider.dart';
import 'package:uni/model/providers/lazy/restaurant_provider.dart';
import 'package:uni/model/providers/plausible/plausible_provider.dart';
Expand Down Expand Up @@ -81,6 +82,7 @@ Future<void> main() async {
SessionProvider(),
CalendarProvider(),
LibraryOccupationProvider(),
LibraryReservationsProvider(),
FacultyLocationsProvider(),
ReferenceProvider(),
);
Expand Down Expand Up @@ -159,6 +161,9 @@ Future<void> main() async {
ChangeNotifierProvider(
create: (context) => stateProviders.libraryOccupationProvider,
),
ChangeNotifierProvider(
create: (context) => stateProviders.libraryReservationsProvider,
),
ChangeNotifierProvider(
create: (context) => stateProviders.facultyLocationsProvider,
),
Expand Down Expand Up @@ -273,11 +278,18 @@ class ApplicationState extends State<Application> {
page: const CalendarPageView(),
settings: settings,
),
'/${NavigationItem.navLibrary.route}':
'/${NavigationItem.navLibraryOccupation.route}':
PageTransition.makePageTransition(
page: const LibraryPage(),
settings: settings,
),
'/${NavigationItem.navLibraryReservations.route}':
PageTransition.makePageTransition(
page: const LibraryPage(
startTab: LibraryPageTab.reservations,
),
settings: settings,
),
'/${NavigationItem.navFaculty.route}':
PageTransition.makePageTransition(
page: const FacultyPageView(),
Expand Down
Loading
Loading