From fd1865da2dfb964d5c7b27ee1a35eacbebc45714 Mon Sep 17 00:00:00 2001 From: "leon.hoppe" Date: Mon, 4 Sep 2023 15:03:20 +0200 Subject: [PATCH] Added some qol improvements --- .../Controllers/UnitsController.cs | 4 +- .../src/app/api/storage.service.ts | 46 ++++++++++++++++--- BetterIServ.Mobile/src/app/app.component.ts | 2 +- .../src/app/pages/home/home.page.ts | 5 +- .../src/app/pages/login/login.page.html | 1 + .../src/app/pages/login/login.page.ts | 6 +++ .../src/app/pages/schedule/schedule.page.html | 2 +- .../src/app/pages/schedule/schedule.page.scss | 6 ++- .../src/app/pages/schedule/schedule.page.ts | 7 ++- .../pages/substitution/substitution.page.html | 2 +- BetterIServ.Mobile/src/app/pipes/week.pipe.ts | 37 --------------- 11 files changed, 63 insertions(+), 55 deletions(-) delete mode 100644 BetterIServ.Mobile/src/app/pipes/week.pipe.ts diff --git a/BetterIServ.Backend/Controllers/UnitsController.cs b/BetterIServ.Backend/Controllers/UnitsController.cs index 8ce7710..b23483b 100644 --- a/BetterIServ.Backend/Controllers/UnitsController.cs +++ b/BetterIServ.Backend/Controllers/UnitsController.cs @@ -49,10 +49,10 @@ public class UnitsController : ControllerBase { Desc = 7 }; - for (int i = 1; i < substitutions.ChildNodes.Count; i++) { + for (int i = 2; i < substitutions.ChildNodes.Count; i++) { var node = substitutions.ChildNodes[i]; if (node.ChildNodes.Count < 8) continue; - if (!node.ChildNodes[cols.Times].InnerText.Contains("-")) continue; + if (node.ChildNodes[cols.Times].InnerText.Contains("//")) continue; var substitution = new Substitution { Times = node.ChildNodes[cols.Times].InnerText.Split(" - ").Select(int.Parse).ToArray(), diff --git a/BetterIServ.Mobile/src/app/api/storage.service.ts b/BetterIServ.Mobile/src/app/api/storage.service.ts index 0034df1..745cd7d 100644 --- a/BetterIServ.Mobile/src/app/api/storage.service.ts +++ b/BetterIServ.Mobile/src/app/api/storage.service.ts @@ -1,8 +1,9 @@ import { Injectable } from '@angular/core'; import {HttpClient} from "@angular/common/http"; -import {firstValueFrom} from "rxjs"; +import {firstValueFrom, Observable} from "rxjs"; import {environment} from "../../environments/environment"; import {IServService} from "./iserv.service"; +import {Lesson} from "../entities/course"; @Injectable({ providedIn: 'root' @@ -11,23 +12,56 @@ export class StorageService { constructor(private client: HttpClient) {} - public async getItem(item: string, isJson: boolean = true): Promise { + public async getItem(item: string, isJson: boolean = true, defaultValue: T = undefined): Promise { try { const data = await firstValueFrom(this.client.get<{value: string}>(environment.backend + `/storage?user=${IServService.userdata.username}&item=${item}`)); if (isJson) return JSON.parse(data.value) as T; - return data.value as T; + else return data.value as T; }catch { - return undefined; + return defaultValue; } } + public getItemLocal(item: string, isJson: boolean = true, defaultValue: T = undefined): Observable { + return new Observable((result) => { + const local = localStorage.getItem(item); + + if (local != undefined) { + if (isJson) result.next(JSON.parse(local) as T); + else result.next(local as T); + } + + setTimeout(async () => { + const response = await this.getItem(item, isJson, defaultValue); + localStorage.setItem(item, isJson ? JSON.stringify(response) : response as string); + result.next(response); + result.complete(); + }, 0); + }) + } + public async setItem(item: string, value: any) { + localStorage.setItem(item, value); await firstValueFrom(this.client.post(environment.backend + `/storage?user=${IServService.userdata.username}&item=${item}`, value)); } - public async clear() { - await firstValueFrom(this.client.delete(environment.backend + `/storage?user=${IServService.userdata.username}`)); + public isLessonThisWeek(lesson: Lesson): boolean { + const week = this.getWeek(new Date()) % 2; + const label = week == 0 ? "a" : "b"; + return (lesson != undefined && (lesson.week == "all" || lesson.week == label)); + } + + private getWeek(orig: Date): number { + const date = new Date(orig.getTime()); + date.setHours(0, 0, 0, 0); + // Thursday in current week decides the year. + date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); + // January 4 is always in week 1. + const week1 = new Date(date.getFullYear(), 0, 4); + // Adjust to Thursday in week 1 and count number of weeks from date to week1. + return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 + - 3 + (week1.getDay() + 6) % 7) / 7); } } diff --git a/BetterIServ.Mobile/src/app/app.component.ts b/BetterIServ.Mobile/src/app/app.component.ts index 3592e5b..59341bd 100644 --- a/BetterIServ.Mobile/src/app/app.component.ts +++ b/BetterIServ.Mobile/src/app/app.component.ts @@ -28,7 +28,7 @@ export class AppComponent { } public async logout() { - await this.storage.clear(); + localStorage.clear(); this.iserv.logout(); await this.router.navigate(["login"]); } diff --git a/BetterIServ.Mobile/src/app/pages/home/home.page.ts b/BetterIServ.Mobile/src/app/pages/home/home.page.ts index 70199f3..28a7e71 100644 --- a/BetterIServ.Mobile/src/app/pages/home/home.page.ts +++ b/BetterIServ.Mobile/src/app/pages/home/home.page.ts @@ -42,14 +42,15 @@ export class HomePage implements OnInit { const classPromise = this.iserv.getCoursesAndClass(); const subsPromise = this.units.getSubstitutionPlan("today"); const timetablePromise = this.storage.getItem("timetable"); - await Promise.all([classPromise, subsPromise, timetablePromise]); + await Promise.all([classPromise, subsPromise]); this.classData = await classPromise; let unitsData = await subsPromise; + const timetable = await timetablePromise; if (scheduleDay != undefined && timetable != undefined) { - this.lessons = timetable[scheduleDay].filter(lesson => lesson != undefined); + this.lessons = timetable[scheduleDay].filter(lesson => lesson != undefined && this.storage.isLessonThisWeek(lesson)); } if (this.dateIsPast(unitsData.date, this.today)) { diff --git a/BetterIServ.Mobile/src/app/pages/login/login.page.html b/BetterIServ.Mobile/src/app/pages/login/login.page.html index a0c023f..1c2a988 100644 --- a/BetterIServ.Mobile/src/app/pages/login/login.page.html +++ b/BetterIServ.Mobile/src/app/pages/login/login.page.html @@ -2,6 +2,7 @@ BetterIServ + diff --git a/BetterIServ.Mobile/src/app/pages/login/login.page.ts b/BetterIServ.Mobile/src/app/pages/login/login.page.ts index 3108fb6..509ad68 100644 --- a/BetterIServ.Mobile/src/app/pages/login/login.page.ts +++ b/BetterIServ.Mobile/src/app/pages/login/login.page.ts @@ -14,6 +14,8 @@ import {Router} from "@angular/router"; }) export class LoginPage implements OnInit { + public showLoading: boolean = false; + constructor(private iservApi: IServService, private router: Router, private alerts: AlertController) { } ngOnInit() { @@ -21,12 +23,16 @@ export class LoginPage implements OnInit { public async onLogin(email?: string, password?: string) { if (email == undefined || password == undefined) return; + if (this.showLoading) return; + this.showLoading = true; if (await this.iservApi.login(email, password)) { setTimeout(async () => { + this.showLoading = false; await this.router.navigate(['home']); }, 500); }else { + this.showLoading = false; const alert = await this.alerts.create({ header: "Fehler", message: "Die angegebenen Logindaten sind nicht korrekt!", diff --git a/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.html b/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.html index 634f86a..5eba99a 100644 --- a/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.html +++ b/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.html @@ -191,7 +191,7 @@ Do Fr - + diff --git a/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.scss b/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.scss index 38429d5..05575a3 100644 --- a/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.scss +++ b/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.scss @@ -38,5 +38,9 @@ } .hide { - opacity: 0; + opacity: 0 !important; +} + +.off-week { + opacity: 0.5; } diff --git a/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.ts b/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.ts index 247a578..59a6619 100644 --- a/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.ts +++ b/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.ts @@ -1,10 +1,9 @@ -import {Component, ElementRef, NgZone, OnInit, ViewChild} from '@angular/core'; +import {Component, OnInit, ViewChild} from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import {IonicModule, IonModal} from '@ionic/angular'; import {IServService} from "../../api/iserv.service"; import {Course, Lesson, Timetable} from "../../entities/course"; -import {WeekPipe} from "../../pipes/week.pipe"; import {LessonComponent} from "../../components/lesson/lesson.component"; import {StorageService} from "../../api/storage.service"; @@ -13,7 +12,7 @@ import {StorageService} from "../../api/storage.service"; templateUrl: './schedule.page.html', styleUrls: ['./schedule.page.scss'], standalone: true, - imports: [IonicModule, CommonModule, FormsModule, WeekPipe, LessonComponent] + imports: [IonicModule, CommonModule, FormsModule, LessonComponent] }) export class SchedulePage implements OnInit { @@ -27,7 +26,7 @@ export class SchedulePage implements OnInit { @ViewChild('courseModal') courseModal: IonModal; @ViewChild('tableModal') tableModal: IonModal; - constructor(public iserv: IServService, private storage: StorageService) { } + constructor(public iserv: IServService, public storage: StorageService) { } async ngOnInit() { this.courses = (await this.iserv.getCoursesAndClass()).courses; diff --git a/BetterIServ.Mobile/src/app/pages/substitution/substitution.page.html b/BetterIServ.Mobile/src/app/pages/substitution/substitution.page.html index b90d894..525747f 100644 --- a/BetterIServ.Mobile/src/app/pages/substitution/substitution.page.html +++ b/BetterIServ.Mobile/src/app/pages/substitution/substitution.page.html @@ -67,7 +67,7 @@
- +
diff --git a/BetterIServ.Mobile/src/app/pipes/week.pipe.ts b/BetterIServ.Mobile/src/app/pipes/week.pipe.ts deleted file mode 100644 index 25ee661..0000000 --- a/BetterIServ.Mobile/src/app/pipes/week.pipe.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; -import {Lesson} from "../entities/course"; - -@Pipe({ - name: 'week', - standalone: true -}) -export class WeekPipe implements PipeTransform { - - transform(objects: Lesson[]): Lesson[] { - if (objects == undefined) return []; - - const week = this.getWeek(new Date()) % 2; - const label = week == 0 ? "a" : "b"; - const result = []; - for (let lesson of objects) { - if (lesson != undefined && (lesson.week == "all" || lesson.week == label)) - result.push(lesson); - else result.push(undefined); - } - - return result; - } - - private getWeek(orig: Date): number { - const date = new Date(orig.getTime()); - date.setHours(0, 0, 0, 0); - // Thursday in current week decides the year. - date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); - // January 4 is always in week 1. - const week1 = new Date(date.getFullYear(), 0, 4); - // Adjust to Thursday in week 1 and count number of weeks from date to week1. - return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - - 3 + (week1.getDay() + 6) % 7) / 7); - } - -}