diff --git a/BetterIServ.Backend/Controllers/MailController.cs b/BetterIServ.Backend/Controllers/MailController.cs index 753c8da..a54a9ec 100644 --- a/BetterIServ.Backend/Controllers/MailController.cs +++ b/BetterIServ.Backend/Controllers/MailController.cs @@ -4,6 +4,7 @@ using System.Text; using Aspose.Email.Clients.Imap; using BetterIServ.Backend.Entities; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; namespace BetterIServ.Backend.Controllers; @@ -92,8 +93,11 @@ public class MailController : ControllerBase { return new SingleResult { Value = results.ToArray() }; } - [HttpPost("download/{id}/{attachment}")] - public async Task DownloadAttachment([FromBody] Credentials credentials, [FromRoute] int id, [FromRoute] string attachment) { + [HttpGet("download/{id}/{attachment}")] + public async Task DownloadAttachment([FromQuery] string credentialString, [FromRoute] int id, [FromRoute] string attachment) { + var credentials = JsonConvert.DeserializeObject(credentialString); + if (credentials == null) return new FileStreamResult(Stream.Null, ""); + using var client = new ImapClient($"imap.{credentials.Domain}", credentials.Username, credentials.Password); var data = await client.FetchAttachmentAsync(id, attachment); diff --git a/BetterIServ.Backend/Controllers/WebDavController.cs b/BetterIServ.Backend/Controllers/WebDavController.cs index ac650f1..eff1b65 100644 --- a/BetterIServ.Backend/Controllers/WebDavController.cs +++ b/BetterIServ.Backend/Controllers/WebDavController.cs @@ -1,6 +1,7 @@ using System.Net; using BetterIServ.Backend.Entities; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; using WebDav; namespace BetterIServ.Backend.Controllers; @@ -40,8 +41,11 @@ public class WebDavController : ControllerBase { return contents.OrderBy(item => item.Type).ToArray(); } - [HttpPost("download")] - public async Task DonwloadFile([FromBody] Credentials credentials, [FromQuery] string url) { + [HttpGet("download")] + public async Task DonwloadFile([FromQuery] string url, [FromQuery] string credentialString) { + var credentials = JsonConvert.DeserializeObject(credentialString); + if (credentials == null) return new FileStreamResult(Stream.Null, ""); + var baseAddress = new Uri($"https://webdav.{credentials.Domain}"); using var client = new WebDavClient(new WebDavClientParams { BaseAddress = baseAddress, diff --git a/BetterIServ.Mobile/package-lock.json b/BetterIServ.Mobile/package-lock.json index e1defa2..dc80633 100644 --- a/BetterIServ.Mobile/package-lock.json +++ b/BetterIServ.Mobile/package-lock.json @@ -14,7 +14,6 @@ "@angular/platform-browser": "^15.0.0", "@angular/platform-browser-dynamic": "^15.0.0", "@angular/router": "^15.0.0", - "@awesome-cordova-plugins/file": "^6.3.0", "@capacitor/android": "4.7.3", "@capacitor/app": "4.1.1", "@capacitor/core": "4.7.3", @@ -22,7 +21,6 @@ "@capacitor/keyboard": "4.1.1", "@capacitor/status-bar": "4.1.1", "@ionic/angular": "^7.0.0", - "file-saver": "^2.0.5", "ionicons": "^7.0.0", "marked": "^4.3.0", "rxjs": "~7.5.0", @@ -42,7 +40,6 @@ "@angular/language-service": "^15.0.0", "@capacitor/cli": "4.7.3", "@ionic/angular-toolkit": "^9.0.0", - "@types/file-saver": "^2.0.5", "@types/jasmine": "~4.0.0", "@types/marked": "^4.0.8", "@types/node": "^12.11.1", @@ -698,30 +695,6 @@ "integrity": "sha512-H71nDOOL8Y7kWRLqf6Sums+01Q5msqBW2KhDUTemh1tvY04eSkSXrK0uj/4mmY0Xr16/3zyZmsrxN7CKuRbNRg==", "dev": true }, - "node_modules/@awesome-cordova-plugins/core": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/core/-/core-6.3.0.tgz", - "integrity": "sha512-MkcWO8akZLHa2RSJEPf76Y3P9wPqh5oXE8YCzn2vnYYeNyYWYnka2pHFsgUdbXJNiS+YeveUzvw+Isweg+wynA==", - "peer": true, - "dependencies": { - "@types/cordova": "latest" - }, - "peerDependencies": { - "rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0" - } - }, - "node_modules/@awesome-cordova-plugins/file": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/file/-/file-6.3.0.tgz", - "integrity": "sha512-w2S/X/pr0Edl8+O/ndIIlnikwkD1XEMM/8TQFp/AI1riqJFyPtYNgnU54iRjagIRJE+GRyydaUnQXp5DVn9Htg==", - "dependencies": { - "@types/cordova": "latest" - }, - "peerDependencies": { - "@awesome-cordova-plugins/core": "^6.0.1", - "rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0" - } - }, "node_modules/@babel/code-frame": { "version": "7.21.4", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.21.4.tgz", @@ -3636,11 +3609,6 @@ "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==", "dev": true }, - "node_modules/@types/cordova": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-11.0.0.tgz", - "integrity": "sha512-AtBm1IAqqXsXszJe6XxuA2iXLhraNCj25p/FHRyikPeW0Z3YfgM6qzWb+VJglJTmZc5lqRNy84cYM/sQI5v6Vw==" - }, "node_modules/@types/cors": { "version": "2.8.13", "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.13.tgz", @@ -3699,12 +3667,6 @@ "@types/range-parser": "*" } }, - "node_modules/@types/file-saver": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@types/file-saver/-/file-saver-2.0.5.tgz", - "integrity": "sha512-zv9kNf3keYegP5oThGLaPk8E081DFDuwfqjtiTzm6PoxChdJ1raSuADf2YGCVIyrSynLrgc8JWv296s7Q7pQSQ==", - "dev": true - }, "node_modules/@types/fs-extra": { "version": "8.1.2", "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-8.1.2.tgz", @@ -7361,11 +7323,6 @@ "node": "^10.12.0 || >=12.0.0" } }, - "node_modules/file-saver": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz", - "integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==" - }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", diff --git a/BetterIServ.Mobile/package.json b/BetterIServ.Mobile/package.json index 819d0e2..953fe08 100644 --- a/BetterIServ.Mobile/package.json +++ b/BetterIServ.Mobile/package.json @@ -20,7 +20,6 @@ "@angular/platform-browser": "^15.0.0", "@angular/platform-browser-dynamic": "^15.0.0", "@angular/router": "^15.0.0", - "@awesome-cordova-plugins/file": "^6.3.0", "@capacitor/android": "4.7.3", "@capacitor/app": "4.1.1", "@capacitor/core": "4.7.3", @@ -28,7 +27,6 @@ "@capacitor/keyboard": "4.1.1", "@capacitor/status-bar": "4.1.1", "@ionic/angular": "^7.0.0", - "file-saver": "^2.0.5", "ionicons": "^7.0.0", "marked": "^4.3.0", "rxjs": "~7.5.0", @@ -48,7 +46,6 @@ "@angular/language-service": "^15.0.0", "@capacitor/cli": "4.7.3", "@ionic/angular-toolkit": "^9.0.0", - "@types/file-saver": "^2.0.5", "@types/jasmine": "~4.0.0", "@types/marked": "^4.0.8", "@types/node": "^12.11.1", diff --git a/BetterIServ.Mobile/src/app/api/mail.service.ts b/BetterIServ.Mobile/src/app/api/mail.service.ts index 71ae917..ff09912 100644 --- a/BetterIServ.Mobile/src/app/api/mail.service.ts +++ b/BetterIServ.Mobile/src/app/api/mail.service.ts @@ -42,8 +42,9 @@ export class MailService { await firstValueFrom(this.client.post(this.iserv.backend + "/mail/send", data)); } - public downloadAttachment(mailId: number, attachment: string): Observable> { - return this.client.post(this.iserv.backend + `/mail/download/${mailId}/${attachment}`, this.iserv.userdata, {responseType: "blob", reportProgress: true, observe: "events"}); + public downloadAttachment(mailId: number, attachment: string): string { + //return this.client.post(this.iserv.backend + `/mail/download/${mailId}/${attachment}`, this.iserv.userdata, {responseType: "blob", reportProgress: true, observe: "events"}); + return this.iserv.backend + `/mail/download/${mailId}/${attachment}?credentialString=${JSON.stringify(this.iserv.userdata)}`; } } diff --git a/BetterIServ.Mobile/src/app/api/webdav.service.ts b/BetterIServ.Mobile/src/app/api/webdav.service.ts index 36d43f8..f4d57d5 100644 --- a/BetterIServ.Mobile/src/app/api/webdav.service.ts +++ b/BetterIServ.Mobile/src/app/api/webdav.service.ts @@ -23,8 +23,9 @@ export class WebdavService { return contents; } - public downloadFile(url: string): Observable> { - return this.client.post(this.iserv.backend + "/webdav/download?url=" + url, this.iserv.userdata, {responseType: "blob", reportProgress: true, observe: "events"}); + public downloadFile(url: string): string { + //return this.client.get(this.iserv.backend + `/webdav/download?url=${url}&credentialString=${JSON.stringify(this.iserv.userdata)}`, {responseType: "blob", reportProgress: true, observe: "events"}); + return this.iserv.backend + `/webdav/download?url=${url}&credentialString=${JSON.stringify(this.iserv.userdata)}`; } public async delete(url: string) { diff --git a/BetterIServ.Mobile/src/app/pages/files/files.page.ts b/BetterIServ.Mobile/src/app/pages/files/files.page.ts index 9e1b3e5..79c92a1 100644 --- a/BetterIServ.Mobile/src/app/pages/files/files.page.ts +++ b/BetterIServ.Mobile/src/app/pages/files/files.page.ts @@ -4,9 +4,7 @@ import {FormsModule} from '@angular/forms'; import {ActionSheetController, AlertController, IonicModule, Platform, ToastController} from '@ionic/angular'; import {WebdavService} from "../../api/webdav.service"; import {DirectoryContent} from "../../entities/directoryContent"; -import {File} from "@awesome-cordova-plugins/file/ngx"; -import {saveAs} from "file-saver"; -import {HttpDownloadProgressEvent, HttpEventType} from "@angular/common/http"; +import {HttpEventType} from "@angular/common/http"; @Component({ selector: 'app-files', @@ -47,29 +45,8 @@ export class FilesPage implements OnInit { if (item.type == "dir") { await this.switchDirectory(item.url); }else { - this.webdav.downloadFile(item.url).subscribe(async event => { - if (event.type == HttpEventType.DownloadProgress) { - const e = event as HttpDownloadProgressEvent; - this.progress = e.loaded / e.total * 100; - } - - if (event.type == HttpEventType.Response) { - const blob = event.body; - const file = new File(); - - if (this.platform.is('desktop')) { - saveAs(blob, item.name); - this.progress = -1; - return; - } - - const downloadPath = ( - this.platform.is('android') - ) ? file.externalDataDirectory : file.documentsDirectory; - await file.writeFile(downloadPath, item.name, blob, {replace: true}); - this.progress = -1; - } - }) + const download = this.webdav.downloadFile(item.url); + window.open(download, "_blank"); } } diff --git a/BetterIServ.Mobile/src/app/pages/mails/mails.page.ts b/BetterIServ.Mobile/src/app/pages/mails/mails.page.ts index e40561d..c2757a7 100644 --- a/BetterIServ.Mobile/src/app/pages/mails/mails.page.ts +++ b/BetterIServ.Mobile/src/app/pages/mails/mails.page.ts @@ -5,9 +5,6 @@ import {IonicModule, IonModal, Platform, ToastController} from '@ionic/angular'; import {MailService} from "../../api/mail.service"; import {MailContent, MailFolder} from "../../entities/mail"; import {marked} from "marked"; -import {HttpEventType} from "@angular/common/http"; -import {File} from "@awesome-cordova-plugins/file/ngx"; -import {saveAs} from "file-saver"; import {MailComponent} from "../../components/mail/mail.component"; import {ActivatedRoute} from "@angular/router"; @@ -83,25 +80,8 @@ export class MailsPage implements OnInit { } public async downloadAttachment(attachment: string, mailId: number) { - this.showLoading = true; - this.mail.downloadAttachment(mailId, attachment).subscribe(async event => { - if (event.type == HttpEventType.Response) { - const blob = event.body; - const file = new File(); - - if (this.platform.is('desktop')) { - saveAs(blob, attachment); - this.showLoading = false; - return; - } - - const downloadPath = ( - this.platform.is('android') - ) ? file.externalDataDirectory : file.documentsDirectory; - await file.writeFile(downloadPath, attachment, blob, {replace: true}); - this.showLoading = false; - } - }) + const download = this.mail.downloadAttachment(mailId, attachment); + window.open(download, "_blank"); } public async sendMail(receiver: string, subject: string, message: string, modal: IonModal) { diff --git a/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.html b/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.html index c8ff73b..42f118a 100644 --- a/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.html +++ b/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.html @@ -54,7 +54,7 @@ Abbrechen - {{currentLesson?.lesson.course || "Neue Stunde"}} + {{currentLesson?.lesson?.course || "Neue Stunde"}} Fertig @@ -63,7 +63,7 @@ Kurs - + {{course.name}} @@ -71,7 +71,7 @@ Wochentyp - + Immer Woche A Woche B @@ -79,7 +79,7 @@ Raum - + diff --git a/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.ts b/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.ts index 1e85b28..21c944e 100644 --- a/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.ts +++ b/BetterIServ.Mobile/src/app/pages/schedule/schedule.page.ts @@ -79,6 +79,10 @@ export class SchedulePage implements OnInit { } if (event.detail.role == "confirm") { + if (this.currentLesson != undefined) { + delete this.timetable[this.currentLesson.day][this.currentLesson.time]; + } + const data = event.detail.data as {lesson: Lesson, day: string, time: number}; this.timetable[data.day][data.time] = data.lesson; } @@ -87,4 +91,16 @@ export class SchedulePage implements OnInit { location.reload(); } + public getCommonCourseRoom(course: string): string { + if (course == undefined) return ""; + + const rooms: string[] = []; + for (let day of ['mon', 'tue', 'wed', 'thu', 'fri']) { + const courseTime = this.timetable[day].filter(lesson => lesson != undefined && lesson.course == course) as Lesson[]; + rooms.push(...courseTime.map(time => time.room)); + } + + return rooms[rooms.length - 1]; + } + }