Skip to content

Commit

Permalink
Add last updated label to grading (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
IoanaAlexandru authored Oct 4, 2020
1 parent e3ed109 commit 6be5097
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class MessageLookup extends MessageLookupByLibrary {
"labelEvaluation" : MessageLookupByLibrary.simpleMessage("Evaluation"),
"labelFirstName" : MessageLookupByLibrary.simpleMessage("First name"),
"labelLastName" : MessageLookupByLibrary.simpleMessage("Last name"),
"labelLastUpdated" : MessageLookupByLibrary.simpleMessage("Last updated"),
"labelLink" : MessageLookupByLibrary.simpleMessage("Link"),
"labelLocation" : MessageLookupByLibrary.simpleMessage("Location"),
"labelName" : MessageLookupByLibrary.simpleMessage("Name"),
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_ro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class MessageLookup extends MessageLookupByLibrary {
"labelEvaluation" : MessageLookupByLibrary.simpleMessage("Evaluare"),
"labelFirstName" : MessageLookupByLibrary.simpleMessage("Prenume"),
"labelLastName" : MessageLookupByLibrary.simpleMessage("Nume"),
"labelLastUpdated" : MessageLookupByLibrary.simpleMessage("Ultima modificare"),
"labelLink" : MessageLookupByLibrary.simpleMessage("Link"),
"labelLocation" : MessageLookupByLibrary.simpleMessage("Locație"),
"labelName" : MessageLookupByLibrary.simpleMessage("Nume"),
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

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

1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"labelPrivacyPolicy": "Privacy Policy",
"labelPersonalInformation": "Personal information",
"labelPermissionsConsent": "consent for editing rights",
"labelLastUpdated": "Last updated",

"sectionShortcuts": "Shortcuts",
"sectionEvents": "Events",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_ro.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"labelPrivacyPolicy": "Privacy Policy",
"labelPersonalInformation": "Informații personale",
"labelPermissionsConsent": "consimțământul pentru drepturi de editare",
"labelLastUpdated": "Ultima modificare",

"sectionShortcuts": "Scurtături",
"sectionEvents": "Evenimente",
Expand Down
8 changes: 7 additions & 1 deletion lib/pages/classes/model/class.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:acs_upb_mobile/generated/l10n.dart';
import 'package:flutter/cupertino.dart';
import 'package:meta/meta.dart';
import 'package:time_machine/time_machine.dart';

enum ShortcutType { main, classbook, resource, other }

Expand Down Expand Up @@ -38,10 +39,15 @@ class ClassHeader {
}

class Class {
Class({@required this.header, List<Shortcut> shortcuts, this.grading})
Class(
{@required this.header,
List<Shortcut> shortcuts,
this.grading,
this.gradingLastUpdated})
: shortcuts = shortcuts ?? [];

ClassHeader header;
final List<Shortcut> shortcuts;
final Map<String, double> grading;
final LocalDateTime gradingLastUpdated;
}
18 changes: 16 additions & 2 deletions lib/pages/classes/service/class_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:acs_upb_mobile/pages/filter/model/filter.dart';
import 'package:acs_upb_mobile/widgets/toast.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:time_machine/time_machine.dart';

extension UserExtension on User {
bool get canEditClassInfo => permissionLevel >= 3;
Expand Down Expand Up @@ -52,6 +53,13 @@ extension ClassHeaderExtension on ClassHeader {
}
}

extension TimestampExtension on Timestamp {
LocalDateTime toLocalDateTime() => LocalDateTime.dateTime(toDate())
.inZoneStrictly(DateTimeZone.utc)
.withZone(DateTimeZone.local)
.localDateTime;
}

extension ClassExtension on Class {
static Class fromSnap({ClassHeader header, DocumentSnapshot snap}) {
if (snap.data == null) {
Expand All @@ -75,10 +83,15 @@ extension ClassExtension on Class {
(String name, dynamic value) => MapEntry(name, value.toDouble())));
}

final gradingLastUpdated = snap.data['gradingLastUpdated'] == null
? null
: (snap.data['gradingLastUpdated'] as Timestamp).toLocalDateTime();

return Class(
header: header,
shortcuts: shortcuts,
grading: grading,
gradingLastUpdated: gradingLastUpdated,
);
}
}
Expand Down Expand Up @@ -259,13 +272,14 @@ class ClassProvider with ChangeNotifier {
try {
final DocumentReference doc = _db.collection('classes').document(classId);
final DocumentSnapshot snap = await doc.get();
final Timestamp now = Timestamp.now();

if (snap.data == null) {
// Document does not exist
await doc.setData({'grading': grading});
await doc.setData({'grading': grading, 'gradingLastUpdated': now});
} else {
// Document exists
await doc.updateData({'grading': grading});
await doc.updateData({'grading': grading, 'gradingLastUpdated': now});
}

notifyListeners();
Expand Down
1 change: 1 addition & 0 deletions lib/pages/classes/view/class_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class _ClassViewState extends State<ClassView> {
const SizedBox(height: 8),
GradingChart(
grading: classInfo.grading,
lastUpdated: classInfo.gradingLastUpdated,
onSave: (grading) => classProvider.setGrading(
classId: widget.classHeader.id, grading: grading),
),
Expand Down
24 changes: 20 additions & 4 deletions lib/pages/classes/view/grading_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ import 'package:flutter/material.dart';
import 'package:pie_chart/pie_chart.dart';
import 'package:provider/provider.dart';
import 'package:quiver/iterables.dart';
import 'package:time_machine/time_machine.dart';

class GradingChart extends StatefulWidget {
const GradingChart(
{Key key, this.grading, this.withHeader = true, this.onSave})
{Key key,
this.grading,
this.withHeader = true,
this.onSave,
this.lastUpdated})
: super(key: key);

final Map<String, double> grading;
final bool withHeader;
final void Function(Map<String, double>) onSave;
final LocalDateTime lastUpdated;

@override
_GradingChartState createState() => _GradingChartState();
Expand All @@ -40,9 +46,19 @@ class _GradingChartState extends State<GradingChart> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
S.of(context).sectionGrading,
style: Theme.of(context).textTheme.headline6,
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.of(context).sectionGrading,
style: Theme.of(context).textTheme.headline6,
),
if (widget.grading != null)
Text(
'${S.of(context).labelLastUpdated}: ${widget.lastUpdated?.toString('dd/MM/yyyy') ?? '?'}',
textAlign: TextAlign.left,
),
],
),
GestureDetector(
onTap: authProvider.currentUserFromCache.canEditClassInfo
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ packages:
source: hosted
version: "1.3.0"
time_machine:
dependency: transitive
dependency: "direct main"
description:
name: time_machine
url: "https://pub.dartlang.org"
Expand Down
5 changes: 4 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description: A mobile application for students at ACS UPB.
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
#
# ACS UPB Mobile uses semantic versioning. You can read more in the CONTRIBUTING.md file.
version: 0.10.1+1
version: 0.10.2+1

environment:
sdk: ">=2.6.0 <3.0.0"
Expand Down Expand Up @@ -77,6 +77,9 @@ dependencies:
# Timetable widget
timetable: ^0.2.0

# DateTime utilities
time_machine:

# Color picker widget
flutter_colorpicker: ^0.3.4

Expand Down

0 comments on commit 6be5097

Please sign in to comment.