Skip to content

Commit

Permalink
Merge pull request #8 from lchsiteam/develop
Browse files Browse the repository at this point in the history
Updating
  • Loading branch information
MC-Atom committed Aug 28, 2020
2 parents d2fab0f + e0ac589 commit f060ffa
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 20 deletions.
54 changes: 45 additions & 9 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Themes } from './themes';
import { DateTime, Duration } from 'luxon';
import firebase from 'firebase';
import firebaseui from 'firebaseui';
import { printTime, getScheduleFromDay, getPeriod, getUpcomingPeriod, allGrades, plusDays } from '@/schedule';
import { printTime, getScheduleFromDay, getPeriod, getUpcomingPeriod, getPreviousPeriod, allGrades, plusDays, periodsFilter, allFilter, excludeZeroAndSix, excludeZero, excludeSix } from '@/schedule';
import { Day, Schedule, Period, getPeriodName, getScheduleName } from '@/schedule/enums';
@Component({})
Expand All @@ -31,6 +31,9 @@ export default class App extends Vue {
private grade = allGrades[2];
private currentDateTime: any;
private uniqueMinute: number = 0;
private nextPeriod = { start: 0, end: 1440, period: Period.NONE };
private previousPeriod = { start: 0, end: 1440, period: Period.NONE };
private filter = periodsFilter;
getCurrentColorScheme() {
return this.getColorSchemeFromId(this.$store.state.settings.colorTheme);
Expand Down Expand Up @@ -77,22 +80,55 @@ export default class App extends Vue {
this.uniqueMinute = currentDate.minute + (currentDate.hour * 60) + (currentDate.ordinal * 60 * 24) + (currentDate.year * 365 * 60 * 24);
this.currentDateTime = currentDate;
this.grade = this.$store.state.settings.grade;
// keep in mind, App.vue's implementation of this.currentPeriod, uses a filtered period list
this.schedule = getScheduleFromDay(currentDate.month, currentDate.day, currentDate.year, currentDate.weekday, this.grade);
this.currentPeriod = getPeriod(this.minutes, this.schedule, this.grade);
this.currentPeriod = getPeriod(this.minutes, this.schedule, this.grade, this.filter);
this.nextPeriod = getUpcomingPeriod(this.minutes, this.currentDateTime, this.schedule, this.grade, this.filter);
this.previousPeriod = getPreviousPeriod(this.minutes, this.currentDateTime, this.schedule, this.grade, this.filter);
}
updateFilter() {
if (this.$store.state.settings.sixthEnabled) {
if (this.$store.state.settings.zeroEnabled) {
this.filter = periodsFilter;
} else {
this.filter = excludeZero;
}
} else if (this.$store.state.settings.zeroEnabled) {
this.filter = excludeSix;
} else {
this.filter = excludeZeroAndSix;
}
}
sendNotifications() {
// console.log(this.uniqueMinute);
// console.log(this.minutes);
// console.log(this.currentPeriod.start);
//console.log(this.nextPeriod.start);
//console.log(this.currentPeriod.period);
//console.log(getPeriodName(this.nextPeriod.period));
// console.log(getPeriodName(this.nextPeriod.period));
// console.log(this.$store.state.settings.notificationSent);
if ((this.minutes === this.currentPeriod.start) && (!this.$store.state.settings.notificationSent)) {
//console.log(this.$store.state.settings.startTime);
//console.log(this.$store.state.settings.endTime);
if (((this.minutes === this.previousPeriod.end-this.$store.state.settings.endTime) && (!this.$store.state.settings.notificationSent) && (this.$store.state.settings.startorend != 'start')) && (this.$store.state.settings.endTime === 0)) {
this.$store.state.settings.notificationSent = true;
this.createNotification('Attention: ' + getPeriodName(this.previousPeriod.period) + ' is ending in ' + this.$store.state.settings.endTime + ' minute(s)', this.previousPeriod);
}
else if (((this.minutes === this.currentPeriod.start-this.$store.state.settings.startTime) && (!this.$store.state.settings.notificationSent) && (this.$store.state.settings.startorend != 'end')) && (this.$store.state.settings.startTime === 0)) {
this.$store.state.settings.notificationSent = true;
this.createNotification('Attention: ' + getPeriodName(this.currentPeriod.period) + ' is starting in ' + this.$store.state.settings.startTime + ' minute(s)', this.currentPeriod);
}
else if ((this.minutes === this.nextPeriod.start-this.$store.state.settings.startTime) && (!this.$store.state.settings.notificationSent) && (this.$store.state.settings.startorend != 'end')) {
this.$store.state.settings.notificationSent = true;
this.createNotification('Attention: ' + getPeriodName(this.nextPeriod.period) + ' is starting in ' + this.$store.state.settings.startTime + ' minute(s)', this.nextPeriod);
}
else if ((this.minutes === this.currentPeriod.end-this.$store.state.settings.endTime) && (!this.$store.state.settings.notificationSent) && (this.$store.state.settings.startorend != 'start')){
this.$store.state.settings.notificationSent = true;
// console.log("send");
this.createNotification('Period over, your next class will start soon!');
this.createNotification('Attention: ' + getPeriodName(this.currentPeriod.period) + ' is ending in ' + this.$store.state.settings.endTime + ' minute(s)', this.currentPeriod);
}
else {
if (this.minutes !== this.currentPeriod.start) {
if ((this.minutes !== this.nextPeriod.start-this.$store.state.settings.startTime) && (this.minutes !== this.currentPeriod.end-this.$store.state.settings.endTime) && (this.minutes !== this.previousPeriod.end-this.$store.state.settings.endTime) && (this.minutes !== this.currentPeriod.start-this.$store.state.settings.startTime)) {
this.$store.state.settings.notificationSent = false;
}
}
Expand All @@ -104,10 +140,11 @@ export default class App extends Vue {
}
}
createNotification(message: string) {
createNotification(message: string, period: any) {
// console.log(this.$store.state.settings.notificationsOn);
if ((Notification.permission === 'granted') && (this.$store.state.settings.notificationsOn)) {
// If it's okay let's create a notification
console.log('testing');
let tempNotif = new Notification('LCHS Go', {
body: String(message),
badge: 'https://go.lciteam.club/favicon.ico',
Expand Down Expand Up @@ -171,7 +208,6 @@ export default class App extends Vue {
}
mounted() {
console.log('test');
setInterval(this.updateStats, 5000);
this.updateStats();
setInterval(this.sendNotifications, 5000);
Expand Down
132 changes: 129 additions & 3 deletions src/schedule/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,13 @@ export function getFullSchedule(schedule: Schedule, grade: number): any {
}
}

export function getPeriod(time: number, schedule: Schedule, grade: number): any {
export function getPeriod(time: number, schedule: Schedule, grade: number, pAllow = allFilter): any {
const fullSchedule = getFullSchedule(schedule, grade);
return fullSchedule.find((p: any) => (p.start <= time && p.end > time));
return fullSchedule.find((p: any) => (p.start <= time && p.end > time) && pAllow.indexOf(p.period) !== -1);
}

const periodsFilter = [

export const periodsFilter = [
Period.PERIOD_0,
Period.PERIOD_1,
Period.PERIOD_2,
Expand Down Expand Up @@ -523,6 +524,120 @@ const periodsFilter = [
Period.SMALL_GROUP_WELLNESS,
];

export const excludeZero = [
Period.OFFICE,
Period.SMALL_GROUP,
Period.PERIOD_1,
Period.PERIOD_2,
Period.PERIOD_3,
Period.PERIOD_4,
Period.PERIOD_5,
Period.PERIOD_6,
Period.LUNCH,
Period.BREAK,
Period.STEP_ODD,
Period.STEP_EVEN,
Period.HOMEROOM,
Period.ASSEMBLY,
Period.TBD,
Period.ARRIVAL,
Period.GROUP_A,
Period.RECESS,
Period.RECESS_PE,
Period.PREP,
Period.GROUP_B,
];

export const excludeSix = [
Period.OFFICE,
Period.SMALL_GROUP,
Period.PERIOD_0,
Period.PERIOD_1,
Period.PERIOD_2,
Period.PERIOD_3,
Period.PERIOD_4,
Period.PERIOD_5,
Period.LUNCH,
Period.BREAK,
Period.STEP_ODD,
Period.STEP_EVEN,
Period.HOMEROOM,
Period.ASSEMBLY,
Period.TBD,
Period.ARRIVAL,
Period.GROUP_A,
Period.RECESS,
Period.RECESS_PE,
Period.PREP,
Period.GROUP_B,
];

export const excludeZeroAndSix = [
Period.OFFICE,
Period.SMALL_GROUP,
Period.PERIOD_1,
Period.PERIOD_2,
Period.PERIOD_3,
Period.PERIOD_4,
Period.PERIOD_5,
Period.LUNCH,
Period.BREAK,
Period.STEP_ODD,
Period.STEP_EVEN,
Period.HOMEROOM,
Period.ASSEMBLY,
Period.TBD,
Period.ARRIVAL,
Period.GROUP_A,
Period.RECESS,
Period.RECESS_PE,
Period.PREP,
Period.GROUP_B,
];

export const allFilter = [
Period.PERIOD_0,
Period.PERIOD_0_PASSING,
Period.PERIOD_1,
Period.PERIOD_1_PASSING,
Period.PERIOD_2,
Period.PERIOD_2_PASSING,
Period.BREAK,
Period.BREAK_PASSING,
Period.PERIOD_3,
Period.PERIOD_3_PASSING,
Period.LUNCH,
Period.LUNCH_PASSING,
Period.STEP_ODD,
Period.STEP_EVEN,
Period.STEP_PASSING,
Period.HOMEROOM,
Period.HOMEROOM_PASSING,
Period.ASSEMBLY,
Period.ASSEMBLY_PASSING,
Period.PERIOD_4,
Period.PERIOD_4_PASSING,
Period.PERIOD_5,
Period.PERIOD_5_PASSING,
Period.PERIOD_6,
Period.PERIOD_6_PASSING,
Period.TBD,
Period.NONE,
Period.EVENTNOPE,
Period.OFFICE,
Period.SMALL_GROUP,
// Elementary Periods
Period.ARRIVAL,
Period.ARRIVAL_A,
Period.ARRIVAL_B,
Period.GROUP_A,
Period.GROUP_B,
Period.RECESS,
Period.RECESS_PE,
Period.PREP,
Period.DONE,
]

export function getUpcomingPeriod(time: number, dateTime: any, schedule: Schedule, grade: number, pAllow = periodsFilter): any {
const fullSchedule = getFullSchedule(schedule, grade);
const result = fullSchedule.find((p: any) => (p.start > time && pAllow.indexOf(p.period) !== -1));
Expand All @@ -548,6 +663,17 @@ export function getUpcomingPeriod(time: number, dateTime: any, schedule: Schedul
}
}

export function getPreviousPeriod(time: number, dateTime: any, schedule: Schedule, grade: number, pAllow = periodsFilter): any {
const fullSchedule = getFullSchedule(schedule, grade);
let result = fullSchedule.find((p: any) => (p.end <= time && pAllow.indexOf(p.period) !== -1));
for (let index=0; index<fullSchedule.length; index++) {
if ((fullSchedule[index].end > result.end) && (fullSchedule[index].end <= time) && (pAllow.indexOf(fullSchedule[index].period) !== -1)) {
result = fullSchedule[index];
}
}
if (result) { return result; }
}

// This works so far, not touching.
// TODO: evaluate if needed
export function printTime(time: number) {
Expand Down
6 changes: 6 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ const defaultConfig = {
enableThemeAnimations: true,
enableRadialGradient: true,
showExtraPeriods: false,
sixthEnabled: true,
zeroEnabled: true,
colorTheme: 'theme8',
startorend: 'both',
popuporaudio: 'both',
grade: 9,
startTime: 0,
endTime: 0,
idInput: '',
gradeInput: [],
},
Expand Down
Loading

0 comments on commit f060ffa

Please sign in to comment.