Skip to content

Commit

Permalink
Интерфейс зачётной книжки (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
KriseevM authored May 5, 2024
1 parent e93a324 commit f67a9a7
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 269 deletions.
2 changes: 1 addition & 1 deletion lib/core/models/mark_by_subject.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MarkBySubject {
_KeysForMarkBySubjectJsonConverter.date: date.toIso8601String(),
_KeysForMarkBySubjectJsonConverter.hours: hours.toString(),
_KeysForMarkBySubjectJsonConverter.lecturers: lecturers,
_KeysForMarkBySubjectJsonConverter.mark: markType.convertToString(),
_KeysForMarkBySubjectJsonConverter.mark: markType.convertToDouble(),
_KeysForMarkBySubjectJsonConverter.subject: subject,
};
}
Expand Down
26 changes: 26 additions & 0 deletions lib/core/viewmodels/grades_screen_view_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:injector/injector.dart';
import 'package:unn_mobile/core/misc/try_login_and_retrieve_data.dart';
import 'package:unn_mobile/core/models/mark_by_subject.dart';
import 'package:unn_mobile/core/services/interfaces/getting_grade_book.dart';
import 'package:unn_mobile/core/services/interfaces/mark_by_subject_provider.dart';
import 'package:unn_mobile/core/viewmodels/base_view_model.dart';

class GradesScreenViewModel extends BaseViewModel {
final GettingGradeBook _gradeBookService =
Injector.appInstance.get<GettingGradeBook>();
final MarkBySubjectProvider _markBySubjectProvider =
Injector.appInstance.get<MarkBySubjectProvider>();

Future<Map<int, List<MarkBySubject>>?> getGradeBook() async {
return await tryLoginAndRetrieveData(
() async {
final gradeBook = await _gradeBookService.getGradeBook();
if (gradeBook != null) {
_markBySubjectProvider.saveData(gradeBook);
}
return gradeBook;
},
() async => _markBySubjectProvider.getData(),
);
}
}
8 changes: 1 addition & 7 deletions lib/core/viewmodels/main_page_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ class MainPageViewModel extends BaseViewModel {
'Материалы',
];
final List<String> _drawerScreenNames = [
'Чаты',
'Справки',
'Сотрудники',
'Календарь',
'Подразделения',
'Библиотечные ресурсы',
'Сайт оплаты',
'Зачётная книжка',
'Настройки',
'О нас',
];
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import 'package:unn_mobile/core/services/interfaces/user_data_provider.dart';
import 'package:unn_mobile/core/viewmodels/auth_page_view_model.dart';
import 'package:unn_mobile/core/viewmodels/comments_page_view_model.dart';
import 'package:unn_mobile/core/viewmodels/feed_screen_view_model.dart';
import 'package:unn_mobile/core/viewmodels/grades_screen_view_model.dart';
import 'package:unn_mobile/core/viewmodels/loading_page_view_model.dart';
import 'package:unn_mobile/core/viewmodels/main_page_view_model.dart';
import 'package:unn_mobile/core/viewmodels/schedule_screen_view_model.dart';
Expand Down Expand Up @@ -150,4 +151,5 @@ void registerDependencies() {
injector.registerDependency(() => ScheduleScreenViewModel());
injector.registerDependency(() => FeedScreenViewModel());
injector.registerDependency(() => CommentsPageViewModel());
injector.registerDependency(() => GradesScreenViewModel());
}
3 changes: 0 additions & 3 deletions lib/ui/views/main_page/about/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ class AboutScreenView extends StatelessWidget {
fontSize: 13,
),
),
const Image(
image: AssetImage('assets/images/quest/3.png'),
),
],
),
),
Expand Down
10 changes: 0 additions & 10 deletions lib/ui/views/main_page/chat/chat.dart

This file was deleted.

20 changes: 0 additions & 20 deletions lib/ui/views/main_page/employees/employees.dart

This file was deleted.

175 changes: 173 additions & 2 deletions lib/ui/views/main_page/grades/grades.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,181 @@
import 'package:flutter/material.dart';
import 'package:unn_mobile/core/models/mark_by_subject.dart';
import 'package:unn_mobile/core/viewmodels/grades_screen_view_model.dart';
import 'package:unn_mobile/ui/views/base_view.dart';

class GradesScreenView extends StatelessWidget {
class GradesScreenView extends StatefulWidget {
const GradesScreenView({super.key});

@override
State<GradesScreenView> createState() => _GradesScreenViewState();
}

class _GradesScreenViewState extends State<GradesScreenView> {
@override
Widget build(BuildContext context) {
return const Placeholder();
return BaseView<GradesScreenViewModel>(
builder: (context, value, child) {
return _getGradesBook(context: context, model: value);
},
);
}

Widget _getGradesBook({
required GradesScreenViewModel model,
required BuildContext context,
}) {
final theme = Theme.of(context);
return FutureBuilder(
future: model.getGradeBook(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return const Center(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text('Произошла ошибка :('),
),
);
}
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData) {
final tabs = snapshot.data!.keys.toList();
tabs.sort();
return DefaultTabController(
initialIndex: tabs.length - 1,
length: tabs.length,
child: Column(
children: [
Container(
color: theme.colorScheme.background,
child: TabBar.secondary(
tabAlignment: TabAlignment.start,
enableFeedback: false,
isScrollable: true,
tabs: [
for (final tab in tabs)
Tab(
child: Text('Семестр $tab'),
),
],
),
),
Expanded(
child: TabBarView(
children: [
for (final tab in tabs)
SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Table(
border: TableBorder.all(
borderRadius: const BorderRadius.all(
Radius.circular(4.0),
),
),
children: [
TableRow(
decoration: BoxDecoration(
color: theme.highlightColor,
),
children: const [
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Дисциплина',
textAlign: TextAlign.center,
),
),
),
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Вид контроля',
textAlign: TextAlign.center,
),
),
),
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Оценка',
textAlign: TextAlign.center,
),
),
),
],
),
for (final row in snapshot.data![tab]!)
TableRow(
children: [
TableCell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
row.subject,
textAlign: TextAlign.center,
),
),
),
TableCell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
row.controlType,
textAlign: TextAlign.center,
),
),
),
TableCell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
row.markType.convertToString(),
textAlign: TextAlign.center,
),
),
),
],
),
],
),
),
),
],
),
),
],
),
);
} else {
return Center(
child: Column(
children: [
const Text('Ещё нет загруженной версии зачётной книжки'),
TextButton(
onPressed: () {
// Force redraw
setState(() {});
},
child: const Text('Обновить'),
),
],
),
);
}
}

return const Center(
child: SizedBox(
height: 100.0,
width: 100.0,
child: CircularProgressIndicator(),
),
);
},
);
}
}
37 changes: 7 additions & 30 deletions lib/ui/views/main_page/main_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'package:unn_mobile/ui/views/main_page/employees/employees.dart';
import 'package:unn_mobile/ui/views/main_page/feed/feed.dart';
import 'package:unn_mobile/ui/views/main_page/grades/grades.dart';
import 'package:unn_mobile/ui/views/main_page/main_page_tab_state.dart';
import 'package:unn_mobile/ui/views/main_page/map/map.dart';
import 'package:unn_mobile/ui/views/main_page/materials/materials.dart';
import 'package:unn_mobile/ui/views/main_page/payment_site/payment_site.dart';
import 'package:unn_mobile/ui/views/main_page/settings/settings.dart';
import 'package:unn_mobile/ui/widgets/placeholder.dart' as placeholder;
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -32,22 +29,14 @@ class _MainPageState extends State<MainPage> {
};

final List<String> drawerRoutes = [
'placeholder',
'placeholder',
'employees',
'placeholder',
'placeholder',
'placeholder',
'payment_site',
'grades',
'settings',
'about',
'exit',
];
final List<String> navbarRoutes = [
'feed',
'schedule',
'map',
'materials',
'placeholder',
'placeholder',
];

Expand All @@ -74,28 +63,16 @@ class _MainPageState extends State<MainPage> {
return local_router.Router.createCustomRoute(
const FeedScreenView(),
);
case 'grades':
return local_router.Router.createCustomRoute(
const GradesScreenView(),
);
case '':
case 'schedule':
tabKeys[1] = GlobalKey<State<ScheduleScreenView>>();
return local_router.Router.createCustomRoute(
ScheduleScreenView(key: tabKeys[1]),
);
case 'map':
return local_router.Router.createCustomRoute(
const MapScreenView(),
);
case 'materials':
return local_router.Router.createCustomRoute(
const MaterialsScreenView(),
);
case 'employees':
return local_router.Router.createCustomRoute(
const EmployeesScreenView(),
);
case 'payment_site':
return local_router.Router.createCustomRoute(
const PaymentSiteScreenView(),
);
case 'settings':
return local_router.Router.createCustomRoute(
const SettingsScreenView(),
Expand Down
8 changes: 1 addition & 7 deletions lib/ui/views/main_page/main_page_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ class MainPageDrawer extends StatelessWidget {
this.onDestinationSelected,
});
final List<IconData> drawerIcons = [
Icons.chat,
Icons.document_scanner,
Icons.people,
Icons.calendar_month,
Icons.account_tree,
Icons.shelves,
Icons.credit_card,
Icons.book,
Icons.settings,
Icons.info,
];
Expand Down
Loading

0 comments on commit f67a9a7

Please sign in to comment.