Skip to content

Commit

Permalink
🚧 Some works on #66. Pre-release 2
Browse files Browse the repository at this point in the history
  • Loading branch information
iqfareez committed Apr 17, 2023
1 parent e44cec6 commit 2193c4e
Show file tree
Hide file tree
Showing 10 changed files with 600 additions and 186 deletions.
10 changes: 10 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"image": "cirrusci/flutter:stable",
"forwardPorts": [
3000
],
"extensions": [
"Dart-Code.dart-code",
"Dart-Code.flutter"
]
}
128 changes: 64 additions & 64 deletions lib/calTec.dart
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
import 'dart:io';
import 'dart:convert';
import 'package:albiruni/albiruni.dart';
import 'package:ical/serializer.dart';
// import 'dart:io';
// import 'dart:convert';
// import 'package:albiruni/albiruni.dart';
// import 'package:ical/serializer.dart';

void main(List<String> args) async {
print("hello world");
var arr = ['AERO1121', 'AERO1322', 'AERO2128'];
Albiruni albiruni = Albiruni(semester: 2, session: "2022/2023");
var mappedArr = arr
.map((e) => albiruni.fetch("ENGIN", course: e.toAlbiruniFormat()))
.toList();
var result = await Future.wait(mappedArr);
result.map((e) => print(e)).toList();
if(result.isNotEmpty){
var class_appointments = result.map((e) => GenerateCalData(e)).toList();
var serialized_calendar_data = class_appointments.map((e) => e.serialize()).toList();
var file = new File('test.ics');
var _ = serialized_calendar_data.map((e) => file.writeAsStringSync(e, mode: FileMode.append)).toList();
}
// void main(List<String> args) async {
// print("hello world");
// var arr = ['AERO1121', 'AERO1322', 'AERO2128'];
// Albiruni albiruni = Albiruni(semester: 2, session: "2022/2023");
// var mappedArr = arr
// .map((e) => albiruni.fetch("ENGIN", course: e.toAlbiruniFormat()))
// .toList();
// var result = await Future.wait(mappedArr);
// result.map((e) => print(e)).toList();
// if(result.isNotEmpty){
// var class_appointments = result.map((e) => GenerateCalData(e)).toList();
// var serialized_calendar_data = class_appointments.map((e) => e.serialize()).toList();
// var file = new File('test.ics');
// var _ = serialized_calendar_data.map((e) => file.writeAsStringSync(e, mode: FileMode.append)).toList();
// }

}
// }

ICalendar GenerateCalData(List<Subject> item) {
ICalendar cal = ICalendar();
//IF SUBJECT HAS MORE THAN TWO DATES
if (item.single.dayTime.length > 1) {
for (var element in item.single.dayTime) {
cal.addElement(
IEvent(
uid: 'test@example.com',
start: DateTime(2023,3,6,),
url: 'https://pub.dartlang.org/packages/srt_parser',
status: IEventStatus.CONFIRMED,
location: 'IIUM',
description:
'COURSE TITLE:${item.single.title}\nCREDIT HOUR:${item.single.chr}\nVENUE:${item.single.venue}\nLECTURERS:\n${item.single.lect.map((e) => print(e+"\n"))}',
summary: item.single.code,
//FOR RECURRENCE UNTIL DATE, ASK INPUT FROM USER
rrule: IRecurrenceRule(
frequency: IRecurrenceFrequency.WEEKLY,
untilDate: DateTime(2023, 6, 6)),
),
);
}
return cal;}
// ICalendar GenerateCalData(List<Subject> item) {
// ICalendar cal = ICalendar();
// //IF SUBJECT HAS MORE THAN TWO DATES
// if (item.single.dayTime.length > 1) {
// for (var element in item.single.dayTime) {
// cal.addElement(
// IEvent(
// uid: 'test@example.com',
// start: DateTime(2023,3,6,),
// url: 'https://pub.dartlang.org/packages/srt_parser',
// status: IEventStatus.CONFIRMED,
// location: 'IIUM',
// description:
// 'COURSE TITLE:${item.single.title}\nCREDIT HOUR:${item.single.chr}\nVENUE:${item.single.venue}\nLECTURERS:\n${item.single.lect.map((e) => print(e+"\n"))}',
// summary: item.single.code,
// //FOR RECURRENCE UNTIL DATE, ASK INPUT FROM USER
// rrule: IRecurrenceRule(
// frequency: IRecurrenceFrequency.WEEKLY,
// untilDate: DateTime(2023, 6, 6)),
// ),
// );
// }
// return cal;}

cal.addElement(
IEvent(
uid: 'test@example.com',
start: DateTime(
2023,
3,
6,
),
url: 'https://pub.dartlang.org/packages/srt_parser',
status: IEventStatus.CONFIRMED,
location: 'IIUM',
description:
'COURSE TITLE:${item.single.title}\nCREDIT HOUR:${item.single.chr}\nVENUE:${item.single.venue}',
summary: item.single.code,
rrule: IRecurrenceRule(
frequency: IRecurrenceFrequency.WEEKLY,
untilDate: DateTime(2023, 6, 6)),
),
);
return cal;
}
// cal.addElement(
// IEvent(
// uid: 'test@example.com',
// start: DateTime(
// 2023,
// 3,
// 6,
// ),
// url: 'https://pub.dartlang.org/packages/srt_parser',
// status: IEventStatus.CONFIRMED,
// location: 'IIUM',
// description:
// 'COURSE TITLE:${item.single.title}\nCREDIT HOUR:${item.single.chr}\nVENUE:${item.single.venue}',
// summary: item.single.code,
// rrule: IRecurrenceRule(
// frequency: IRecurrenceFrequency.WEEKLY,
// untilDate: DateTime(2023, 6, 6)),
// ),
// );
// return cal;
// }
60 changes: 60 additions & 0 deletions lib/model/imaluum_exam.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:intl/intl.dart';

enum ExamTime { am, pm }

/// Parse data from I-Ma'Luum importer for final exam
class ImaluumExam {
late String courseCode;
late String title;
late int section;
late DateTime date;
late ExamTime time;
late String venue;
late int seat;

ImaluumExam(
{required this.courseCode,
required this.title,
required this.section,
required this.date,
required this.time,
required this.venue,
required this.seat});

ImaluumExam.fromJson(Map<String, dynamic> json) {
var format = DateFormat('dd/MM/yyyy');
courseCode = json["courseCode"];
title = json["title"];
section = json["section"];
time = json["time"] == 'AM' ? ExamTime.am : ExamTime.pm;
// If the exam is in evening, just set the time to 2pm
// this is useful when we want to sort these subjects
// based on their priority
date = format
.parse(json["date"])
.add(time == ExamTime.pm ? const Duration(hours: 14) : Duration.zero);
venue = json["venue"];
seat = json["seat"];
}

static List<ImaluumExam> fromList(List<dynamic> list) {
return list.map((map) => ImaluumExam.fromJson(map)).toList();
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data["courseCode"] = courseCode;
data["title"] = title;
data["section"] = section;
data["date"] = date;
data["time"] = time;
data["venue"] = venue;
data["seat"] = seat;
return data;
}

@override
String toString() {
return "ImaluumExam{courseCode: $courseCode, title: $title, section: $section, date: $date, time: $time, venue: $venue, seat: $seat}";
}
}
20 changes: 20 additions & 0 deletions lib/util/relative_date.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:intl/intl.dart';

class RelativeDate {
/// Returns the upcoming date in the format of "in 2 days" or "in this week"
/// If the upcoming date is more than a week, return the formatted date
static String fromDate(DateTime dateTime) {
final now = DateTime.now();
final diff = dateTime.difference(now);

if (diff.inDays == 0) {
return "today";
} else if (diff.inDays == 1) {
return "tomorrow";
} else if (diff.inDays < 7) {
return "in ${diff.inDays} days";
} else {
return DateFormat('E, d MMM yyyy').format(dateTime);
}
}
}
78 changes: 78 additions & 0 deletions lib/views/final_exam/exam_detail_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

import '../../model/imaluum_exam.dart';
import 'seat_number_card.dart';

class ExamDetailPage extends StatelessWidget {
const ExamDetailPage({super.key, required this.exam});

final ImaluumExam exam;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Exam ${exam.courseCode}"),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
const SizedBox(height: 12),
ListTile(
title: Text(exam.title, style: const TextStyle(fontSize: 24)),
leading: Icon(
Icons.book,
size: 38,
color: Theme.of(context).colorScheme.surfaceTint,
),
),
const SizedBox(height: 4),
ListTile(
subtitle: const Text("Date & Time"),
title: Row(
children: [
Text(DateFormat('d MMM yy').format(exam.date),
style: const TextStyle(fontSize: 24)),
const SizedBox(width: 8),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondary,
borderRadius: BorderRadius.circular(8),
),
child: Text(
exam.time.name.toUpperCase(),
style: TextStyle(
color: Theme.of(context).colorScheme.onSecondary),
),
),
],
),
leading: Icon(
Icons.today_outlined,
size: 38,
color: Theme.of(context).colorScheme.surfaceTint,
),
),
const SizedBox(height: 4),
ListTile(
subtitle: const Text("Venue"),
title: Text(exam.venue, style: const TextStyle(fontSize: 24)),
leading: Icon(
Icons.meeting_room,
size: 38,
color: Theme.of(context).colorScheme.surfaceTint,
),
),
const Spacer(),
SeatNumberCard(exam.seat.toString()),
const Spacer(flex: 2),
],
),
),
);
}
}
Loading

0 comments on commit 2193c4e

Please # to comment.