forked from firka/firka
Összes tantárgy megjelenítése
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:firka/helpers/api/model/all_lessons.dart';
|
||||
import 'package:firka/helpers/api/model/class_group.dart';
|
||||
import 'package:firka/helpers/api/model/homework.dart';
|
||||
import 'package:firka/helpers/api/model/timetable.dart';
|
||||
@@ -624,6 +625,41 @@ class KretaClient {
|
||||
return ApiResponse(lessons, 200, err, cached);
|
||||
}
|
||||
|
||||
Future<ApiResponse<List<AllLessons>>> getLessons({bool forceCache = true}) async {
|
||||
var (resp, status, ex, cached) = await _cachingGet(
|
||||
CacheId.getLessons,
|
||||
KretaEndpoints.getLessons(model.iss!),
|
||||
forceCache,
|
||||
0,
|
||||
);
|
||||
|
||||
var items = <AllLessons>[];
|
||||
String? err;
|
||||
|
||||
try {
|
||||
if (resp is List) {
|
||||
for (var item in resp) {
|
||||
if (item != null && item is Map<String, dynamic>) {
|
||||
items.add(AllLessons.fromJson(item));
|
||||
} else {
|
||||
logger.warning("$item");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = "${resp.runtimeType}";
|
||||
}
|
||||
} catch (e, stack) {
|
||||
err = e.toString();
|
||||
logger.warning(e, stack);
|
||||
}
|
||||
|
||||
if (ex != null) {
|
||||
err = ex.toString();
|
||||
}
|
||||
|
||||
return ApiResponse(items, status, err, cached);
|
||||
}
|
||||
|
||||
Future<ApiResponse<List<Test>>> getTests({bool forceCache = true}) async {
|
||||
var (resp, status, ex, cached) = await _cachingGet(
|
||||
CacheId.getTests, KretaEndpoints.getTests(model.iss!), forceCache, 0);
|
||||
|
||||
@@ -117,4 +117,7 @@ class KretaEndpoints {
|
||||
|
||||
static String getTests(String iss) =>
|
||||
"${kreta(iss)}/ellenorzo/v3/sajat/BejelentettSzamonkeresek";
|
||||
}
|
||||
|
||||
static String getLessons(String iss) =>
|
||||
"${kreta(iss)}/dktapi/intezmenyek/munkaterek/tanulok";
|
||||
}
|
||||
|
||||
132
firka/lib/helpers/api/model/all_lessons.dart
Normal file
132
firka/lib/helpers/api/model/all_lessons.dart
Normal file
@@ -0,0 +1,132 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class AllLessons {
|
||||
final String intezmenyId;
|
||||
final String tanevId;
|
||||
final dynamic osztalyId;
|
||||
final String? osztalyNev;
|
||||
final bool osztalyMunkaTer;
|
||||
final dynamic csoportId;
|
||||
final String? csoportNev;
|
||||
final bool csoportMunkaTer;
|
||||
final String osztalyCsoportNev;
|
||||
final dynamic tantargyId;
|
||||
final String tantargyNev;
|
||||
final dynamic alkalmazottId;
|
||||
final String alkalmazottGuid;
|
||||
final String alkalmazottNev;
|
||||
final dynamic alkalmazottUzenoFalId;
|
||||
final dynamic uzenoFalId;
|
||||
final String? nyelvId;
|
||||
final dynamic tantargyKategoriaId;
|
||||
final String tantargyKategoriaNev;
|
||||
final dynamic tipusId;
|
||||
final String tipusNev;
|
||||
final dynamic evfolyamTipusId;
|
||||
final String evfolyamTipusNev;
|
||||
final dynamic feladatEllatasiHelyId;
|
||||
final String feladatEllatasiHelyNev;
|
||||
final dynamic alkalmazottAvatarTipusId;
|
||||
final String alkalmazottAvatarEleres;
|
||||
final dynamic oraiFeladatGroupId;
|
||||
|
||||
AllLessons({
|
||||
required this.intezmenyId,
|
||||
required this.tanevId,
|
||||
this.osztalyId,
|
||||
this.osztalyNev,
|
||||
required this.osztalyMunkaTer,
|
||||
this.csoportId,
|
||||
this.csoportNev,
|
||||
required this.csoportMunkaTer,
|
||||
required this.osztalyCsoportNev,
|
||||
required this.tantargyId,
|
||||
required this.tantargyNev,
|
||||
required this.alkalmazottId,
|
||||
required this.alkalmazottGuid,
|
||||
required this.alkalmazottNev,
|
||||
this.alkalmazottUzenoFalId,
|
||||
this.uzenoFalId,
|
||||
this.nyelvId,
|
||||
required this.tantargyKategoriaId,
|
||||
required this.tantargyKategoriaNev,
|
||||
required this.tipusId,
|
||||
required this.tipusNev,
|
||||
required this.evfolyamTipusId,
|
||||
required this.evfolyamTipusNev,
|
||||
required this.feladatEllatasiHelyId,
|
||||
required this.feladatEllatasiHelyNev,
|
||||
required this.alkalmazottAvatarTipusId,
|
||||
required this.alkalmazottAvatarEleres,
|
||||
this.oraiFeladatGroupId,
|
||||
});
|
||||
|
||||
factory AllLessons.fromJson(Map<String, dynamic> json) => AllLessons(
|
||||
intezmenyId: json['intezmenyId']?.toString() ?? '',
|
||||
tanevId: json['tanevId']?.toString() ?? '',
|
||||
osztalyId: json['osztalyId'],
|
||||
osztalyNev: json['osztalyNev']?.toString(),
|
||||
osztalyMunkaTer: json['osztalyMunkaTer'] == true,
|
||||
csoportId: json['csoportId'],
|
||||
csoportNev: json['csoportNev']?.toString(),
|
||||
csoportMunkaTer: json['csoportMunkaTer'] == true,
|
||||
osztalyCsoportNev: json['osztalyCsoportNev']?.toString() ?? '',
|
||||
tantargyId: json['tantargyId'],
|
||||
tantargyNev: json['tantargyNev']?.toString() ?? '',
|
||||
alkalmazottId: json['alkalmazottId'],
|
||||
alkalmazottGuid: json['alkalmazottGuid']?.toString() ?? '',
|
||||
alkalmazottNev: json['alkalmazottNev']?.toString() ?? '',
|
||||
alkalmazottUzenoFalId: json['alkalmazottUzenoFalId'],
|
||||
uzenoFalId: json['uzenoFalId'],
|
||||
nyelvId: json['nyelvId']?.toString(),
|
||||
tantargyKategoriaId: json['tantargyKategoriaId'],
|
||||
tantargyKategoriaNev: json['tantargyKategoriaNev']?.toString() ?? '',
|
||||
tipusId: json['tipusId'],
|
||||
tipusNev: json['tipusNev']?.toString() ?? '',
|
||||
evfolyamTipusId: json['evfolyamTipusId'],
|
||||
evfolyamTipusNev: json['evfolyamTipusNev']?.toString() ?? '',
|
||||
feladatEllatasiHelyId: json['feladatEllatasiHelyId'],
|
||||
feladatEllatasiHelyNev: json['feladatEllatasiHelyNev']?.toString() ?? '',
|
||||
alkalmazottAvatarTipusId: json['alkalmazottAvatarTipusId'],
|
||||
alkalmazottAvatarEleres: json['alkalmazottAvatarEleres']?.toString() ?? '',
|
||||
oraiFeladatGroupId: json['oraiFeladatGroupId'],
|
||||
);
|
||||
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'intezmenyId': intezmenyId,
|
||||
'tanevId': tanevId,
|
||||
'osztalyId': osztalyId,
|
||||
'osztalyNev': osztalyNev,
|
||||
'osztalyMunkaTer': osztalyMunkaTer,
|
||||
'csoportId': csoportId,
|
||||
'csoportNev': csoportNev,
|
||||
'csoportMunkaTer': csoportMunkaTer,
|
||||
'osztalyCsoportNev': osztalyCsoportNev,
|
||||
'tantargyId': tantargyId,
|
||||
'tantargyNev': tantargyNev,
|
||||
'alkalmazottId': alkalmazottId,
|
||||
'alkalmazottGuid': alkalmazottGuid,
|
||||
'alkalmazottNev': alkalmazottNev,
|
||||
'alkalmazottUzenoFalId': alkalmazottUzenoFalId,
|
||||
'uzenoFalId': uzenoFalId,
|
||||
'nyelvId': nyelvId,
|
||||
'tantargyKategoriaId': tantargyKategoriaId,
|
||||
'tantargyKategoriaNev': tantargyKategoriaNev,
|
||||
'tipusId': tipusId,
|
||||
'tipusNev': tipusNev,
|
||||
'evfolyamTipusId': evfolyamTipusId,
|
||||
'evfolyamTipusNev': evfolyamTipusNev,
|
||||
'feladatEllatasiHelyId': feladatEllatasiHelyId,
|
||||
'feladatEllatasiHelyNev': feladatEllatasiHelyNev,
|
||||
'alkalmazottAvatarTipusId': alkalmazottAvatarTipusId,
|
||||
'alkalmazottAvatarEleres': alkalmazottAvatarEleres,
|
||||
'oraiFeladatGroupId': oraiFeladatGroupId,
|
||||
};
|
||||
}
|
||||
|
||||
List<AllLessons> lessonsFromJson(String str) =>
|
||||
List<AllLessons>.from(json.decode(str).map((x) => AllLessons.fromJson(x)));
|
||||
|
||||
String lessonsToJson(List<AllLessons> data) =>
|
||||
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
|
||||
@@ -5,19 +5,24 @@ class Subject {
|
||||
final String name;
|
||||
final NameUidDesc category;
|
||||
final int sortIndex;
|
||||
final String? alkalmazottNev;
|
||||
|
||||
Subject(
|
||||
{required this.uid,
|
||||
required this.name,
|
||||
required this.category,
|
||||
required this.sortIndex});
|
||||
Subject({
|
||||
required this.uid,
|
||||
required this.name,
|
||||
required this.category,
|
||||
required this.sortIndex,
|
||||
this.alkalmazottNev,
|
||||
});
|
||||
|
||||
factory Subject.fromJson(Map<String, dynamic> json) {
|
||||
return Subject(
|
||||
uid: json['Uid'],
|
||||
name: json['Nev'],
|
||||
category: NameUidDesc.fromJson(json['Kategoria']),
|
||||
sortIndex: json['SortIndex']);
|
||||
uid: json['Uid'],
|
||||
name: json['Nev'],
|
||||
category: NameUidDesc.fromJson(json['Kategoria']),
|
||||
sortIndex: json['SortIndex'],
|
||||
alkalmazottNev: json['alkalmazottNev'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
@@ -26,6 +31,7 @@ class Subject {
|
||||
'Nev': name,
|
||||
'Kategoria': category.toJson(),
|
||||
'SortIndex': sortIndex,
|
||||
'alkalmazottNev': alkalmazottNev,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -35,7 +41,8 @@ class Subject {
|
||||
'uid: "$uid", '
|
||||
'name: "$name", '
|
||||
'category: $category, '
|
||||
'sortIndex: $sortIndex'
|
||||
'sortIndex: $sortIndex, '
|
||||
'alkalmazottNev: $alkalmazottNev'
|
||||
')';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ enum CacheId {
|
||||
getOmissions,
|
||||
getTests,
|
||||
getClassGroup,
|
||||
getSubjectAvg
|
||||
getSubjectAvg,
|
||||
getLessons
|
||||
}
|
||||
|
||||
@collection
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:firka/helpers/api/client/kreta_client.dart';
|
||||
import 'package:firka/helpers/api/model/all_lessons.dart';
|
||||
import 'package:firka/helpers/api/model/generic.dart';
|
||||
import 'package:firka/helpers/ui/firka_card.dart';
|
||||
import 'package:firka/helpers/ui/grade_helpers.dart';
|
||||
@@ -32,9 +33,12 @@ class HomeGradesScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
String activeSubjectUid = "";
|
||||
String alkalmazottNev = "";
|
||||
String tantargyNev = "";
|
||||
|
||||
class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
|
||||
ApiResponse<List<Grade>>? grades;
|
||||
ApiResponse<List<AllLessons>>? lessons;
|
||||
ApiResponse<List<Lesson>>? week;
|
||||
ApiResponse<List<ClassGroup>>? classGroups;
|
||||
List<ApiResponse<List<SubjectAverage>>>? subjectAvgs;
|
||||
@@ -53,6 +57,7 @@ class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
|
||||
var end = start.add(Duration(days: 6));
|
||||
|
||||
grades = await widget.data.client.getGrades(forceCache: false);
|
||||
lessons = await widget.data.client.getLessons(forceCache: false);
|
||||
week = await widget.data.client.getTimeTable(start, end, forceCache: false);
|
||||
classGroups = await widget.data.client.getClassGroups(forceCache: false);
|
||||
|
||||
@@ -81,6 +86,7 @@ class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
|
||||
var end = start.add(Duration(days: 6));
|
||||
|
||||
grades = await widget.data.client.getGrades();
|
||||
lessons = await widget.data.client.getLessons();
|
||||
week = await widget.data.client.getTimeTable(start, end);
|
||||
|
||||
if (mounted) setState(() {});
|
||||
@@ -120,30 +126,60 @@ class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
for (var lesson in lessons!.response!) {
|
||||
if (subjects.where((s) => s.uid == lesson.tantargyId?.toString()).isEmpty) {
|
||||
subjects.add(Subject(
|
||||
uid: lesson.tantargyId?.toString() ?? '',
|
||||
name: lesson.tantargyNev,
|
||||
alkalmazottNev: lesson.alkalmazottNev,
|
||||
|
||||
category: NameUidDesc(
|
||||
uid: lesson.tantargyKategoriaId?.toString() ?? '',
|
||||
name: lesson.tantargyKategoriaNev,
|
||||
description: "",
|
||||
),
|
||||
sortIndex: 0,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
subjects.sort((s1, s2) => s1.name.compareTo(s2.name));
|
||||
|
||||
for (var subject in subjects) {
|
||||
for (var grade in grades!.response!) {
|
||||
if (grade.subject.uid != subject.uid) continue;
|
||||
final subjectGrades =
|
||||
grades!.response!.where((g) => g.subject.uid == subject.uid).toList();
|
||||
|
||||
if (grade.valueType.name == "Szazalekos") {
|
||||
grade.valueType = NameUidDesc(
|
||||
uid: "1,Osztalyzat", name: "Osztalyzat", description: "");
|
||||
if (grade.numericValue != null) {
|
||||
grade.numericValue = percentageToGrade(grade.numericValue!);
|
||||
double avg = double.nan;
|
||||
if (subjectGrades.isNotEmpty) {
|
||||
for (var grade in subjectGrades) {
|
||||
if (grade.valueType.name == "Szazalekos") {
|
||||
grade.valueType = NameUidDesc(
|
||||
uid: "1,Osztalyzat", name: "Osztalyzat", description: "");
|
||||
if (grade.numericValue != null) {
|
||||
grade.numericValue = percentageToGrade(grade.numericValue!);
|
||||
}
|
||||
}
|
||||
}
|
||||
avg = grades!.response!.getAverageBySubject(subject);
|
||||
}
|
||||
var avg = grades!.response!.getAverageBySubject(subject);
|
||||
|
||||
if (avg.isNaN) {
|
||||
gradeCards.add(GradeSmallCard(grades!.response!, subject));
|
||||
gradeCards.add(GestureDetector(
|
||||
child: GradeSmallCard(grades!.response!, subject),
|
||||
onTap: () {
|
||||
activeSubjectUid = subject.uid;
|
||||
alkalmazottNev = subject.alkalmazottNev ?? '';
|
||||
tantargyNev = subject.name;
|
||||
widget.pageController(1);
|
||||
},
|
||||
));
|
||||
} else {
|
||||
gradeCards.add(GestureDetector(
|
||||
child: GradeSmallCard(grades!.response!, subject),
|
||||
onTap: () {
|
||||
activeSubjectUid = subject.uid;
|
||||
|
||||
alkalmazottNev = subject.alkalmazottNev ?? '';
|
||||
tantargyNev = subject.name;
|
||||
widget.pageController(1);
|
||||
},
|
||||
));
|
||||
|
||||
@@ -71,7 +71,7 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (grades != null && activeSubjectUid != "") {
|
||||
if (grades != null && grades!.isNotEmpty && activeSubjectUid != "") {
|
||||
var aGrade = grades!.first;
|
||||
var groups = grades!.groupList((grade) => grade.recordDate);
|
||||
|
||||
@@ -197,13 +197,34 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
||||
);
|
||||
} else {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [DelayedSpinnerWidget()],
|
||||
)
|
||||
],
|
||||
FirkaCard(
|
||||
left: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 1.45,
|
||||
child: Text(
|
||||
tantargyNev,
|
||||
style: appStyle.fonts.H_H2
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
alkalmazottNev,
|
||||
style: appStyle.fonts.B_16R
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user