aboutsummaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
authorFurkan Sahin <furkan-dev@proton.me>2021-09-05 21:39:24 -0500
committerFurkan Sahin <furkan-dev@proton.me>2021-09-05 21:39:24 -0500
commitd0975a6e7ee57de4debda94e823011d813fbf4a1 (patch)
tree69d61bf6c29104434b9e3de4946e7d5dd549dec0 /src/models
parentffef3a6be19d1139b6378c8119d444082dd0cbac (diff)
Initial rewrite in svelte
Diffstat (limited to 'src/models')
-rw-r--r--src/models/EventInfo.ts79
-rw-r--r--src/models/Lab.ts45
-rw-r--r--src/models/PeerTeacher.ts58
3 files changed, 86 insertions, 96 deletions
diff --git a/src/models/EventInfo.ts b/src/models/EventInfo.ts
index 962ec70..d20682c 100644
--- a/src/models/EventInfo.ts
+++ b/src/models/EventInfo.ts
@@ -1,46 +1,45 @@
export default class EventInfo {
- days: string;
-
- start: number;
-
- end: number;
-
- constructor(days: string = '', start = 0, end = 0) {
- this.days = days;
- this.start = start;
- this.end = end;
- }
-
- static timeToStr(time: number) {
- let hour = Math.floor(time / 100);
- const minute = time % 100;
- const meridiem = (hour < 12) ? 'AM' : 'PM';
-
- if (hour === 0) {
- hour = 12;
- } else if (hour > 12) {
- hour -= 12;
- }
-
- if (minute < 10) {
- return `${hour}:0${minute} ${meridiem}`;
+ days: string;
+ start: number;
+ end: number;
+
+ constructor(days: string, start: number | string, end: number | string) {
+ if (typeof start === "string") {
+ start = parseInt(start, 10);
+ }
+ if (typeof end === "string") {
+ end = parseInt(end, 10);
+ }
+
+ this.days = days;
+ this.start = start;
+ this.end = end;
}
- return `${hour}:${minute} ${meridiem}`;
- }
-
- conflictsWith(event: EventInfo) {
- const daysConflict = event.days.match(new RegExp(`[${this.days}]`));
- if (daysConflict) {
- return (this.start <= event.end) && (event.start <= this.end);
+ static timeToStr(time: number) {
+ let hour = Math.floor(time / 100);
+ const minute = time % 100;
+ const meridiem = (hour < 12) ? 'AM' : 'PM';
+
+ if (hour === 0) {
+ hour = 12;
+ } else if (hour > 12) {
+ hour -= 12;
+ }
+
+ if (minute < 10) {
+ return `${hour}:0${minute} ${meridiem}`;
+ }
+ return `${hour}:${minute} ${meridiem}`;
}
- return false;
- }
- get info() {
- if (this.days === '') {
- return 'WEB';
+ get info() {
+ if(this.days === "") {
+ return `WEB`;
+ }else if(this.start === -1 || this.end === -1) {
+ return `${this.days}`;
+ } else {
+ return `${this.days} ${EventInfo.timeToStr(this.start)}-${EventInfo.timeToStr(this.end)}`;
+ }
}
- return `${this.days} ${EventInfo.timeToStr(this.start)}-${EventInfo.timeToStr(this.end)}`;
- }
-}
+} \ No newline at end of file
diff --git a/src/models/Lab.ts b/src/models/Lab.ts
index a6972ef..8636f74 100644
--- a/src/models/Lab.ts
+++ b/src/models/Lab.ts
@@ -1,23 +1,34 @@
-import EventInfo from '@/models/EventInfo';
+import type EventInfo from "./EventInfo";
export default class Lab {
- course: number;
+ id: number;
+ course: number;
+ section: number;
+ event: EventInfo;
+ building: string;
+ room: string;
- section: number;
+ constructor(course: number | string, section: number | string, event: EventInfo, building = "", room = "") {
+ if(typeof course === "string") {
+ course = parseInt(course, 10);
+ }
+ if(typeof section === "string") {
+ section = parseInt(section, 10);
+ }
- event: EventInfo;
+ this.id = parseInt(`${course}${section}`, 10);
+ this.course = course;
+ this.section = section;
+ this.event = event;
+ this.building = building;
+ this.room = room;
+ }
- constructor(course = 0, section = 0, event = new EventInfo()) {
- this.course = course;
- this.section = section;
- this.event = event;
- }
+ get time() {
+ return this.event.info;
+ }
- get id() {
- return `${this.course}-${this.section}`;
- }
-
- get fullInfo() {
- return `${this.id} ${this.event.info}`;
- }
-}
+ get location() {
+ return `${this.building}-${this.room}`;
+ }
+} \ No newline at end of file
diff --git a/src/models/PeerTeacher.ts b/src/models/PeerTeacher.ts
index f387431..6518a80 100644
--- a/src/models/PeerTeacher.ts
+++ b/src/models/PeerTeacher.ts
@@ -1,41 +1,21 @@
-import EventInfo from './EventInfo';
+import type EventInfo from "./EventInfo";
export default class PeerTeacher {
- firstname: string;
-
- lastname: string;
-
- uin: number;
-
- events: EventInfo[];
-
- assignedLabs: Set<string>;
-
- constructor(firstname = '', lastname = '', uin = 0) {
- this.firstname = firstname;
- this.lastname = lastname;
- this.uin = uin;
- this.events = [];
- this.assignedLabs = new Set();
- }
-
- conflictsWith(event: EventInfo) {
- let conflicts = false;
- this.events.every((item) => {
- if (item.conflictsWith(event)) {
- conflicts = true;
- return false;
- }
- return true;
- });
- return conflicts;
- }
-
- get name() {
- return `${this.firstname} ${this.lastname}`;
- }
-
- get id() {
- return this.uin;
- }
-}
+ id: number;
+ firstname: string;
+ lastname: string;
+ events: EventInfo[];
+ labs: Set<number>;
+
+ constructor(id: number | string, firstname: string, lastname: string) {
+ if(typeof id === "string") {
+ id = parseInt(id, 10);
+ }
+
+ this.id = id;
+ this.firstname = firstname;
+ this.lastname = lastname;
+ this.events = [];
+ this.labs = new Set();
+ }
+} \ No newline at end of file