Skip to content

Commit

Permalink
Support voor 'projecten' in studiewijzers (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryDeKat authored Oct 12, 2023
1 parent e81649e commit 15fa874
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 50 deletions.
81 changes: 44 additions & 37 deletions lib/src/ui/components/Bijlage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'package:filesize/filesize.dart';
import 'package:url_launcher/url_launcher.dart';

enum DownloadState { done, loading, none }

Expand All @@ -28,48 +29,54 @@ class BijlageItem extends StatelessWidget {
message: bijlage.naam,
child: ListTile(
onTap: () {
if (onTap != null) onTap();
if (download != null) {
downloadState.value = DownloadState.loading;
if (bijlage.contentType == "application/octet-stream") {
launch(bijlage.downloadUrl);
} else {
if (onTap != null) onTap();
if (download != null) {
downloadState.value = DownloadState.loading;

download(
bijlage,
(count, total) {
bijlage.downloadCount = count;
downloadCount.value = count;
if (count >= total) {
downloadState.value = DownloadState.done;
}
},
);
download(
bijlage,
(count, total) {
bijlage.downloadCount = count;
downloadCount.value = count;
if (count >= total) {
downloadState.value = DownloadState.done;
}
},
);
}
}
},
leading: bijlage.isFolder
? Icon(Icons.folder_outlined)
: Column(
children: [
Padding(
padding: EdgeInsets.only(
top: 5,
),
child: Icon(
Icons.insert_drive_file_outlined,
),
),
Padding(
padding: EdgeInsets.only(
top: 7.5,
),
child: Text(
splittedNaam.length > 1 ? splittedNaam.last.toUpperCase() : bijlage.naam,
style: TextStyle(
fontSize: 12.5,
: bijlage.contentType == "application/octet-stream"
? Icon(Icons.link)
: Column(
children: [
Padding(
padding: EdgeInsets.only(
top: 5,
),
child: Icon(
Icons.insert_drive_file_outlined,
),
),
),
)
],
),
subtitle: bijlage.isFolder
Padding(
padding: EdgeInsets.only(
top: 7.5,
),
child: Text(
splittedNaam.length > 1 ? splittedNaam.last.toUpperCase() : bijlage.naam,
style: TextStyle(
fontSize: 12.5,
),
),
)
],
),
subtitle: bijlage.isFolder || bijlage.contentType == "application/octet-stream"
? null
: Padding(
child: ValueListenableBuilder(
Expand All @@ -93,7 +100,7 @@ class BijlageItem extends StatelessWidget {
vertical: 10,
),
),
trailing: bijlage.isFolder
trailing: bijlage.isFolder || bijlage.contentType == "application/octet-stream"
? Icon(
Icons.arrow_forward_ios,
size: 14,
Expand Down
10 changes: 3 additions & 7 deletions lib/src/ui/tabs/Studiewijzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class _StudiewijzerTab extends State<StudiewijzerTab> {
if (wijstab.bronnen.isNotEmpty)
MaterialCard(
children: divideListTiles([
for (var bron in wijstab.bronnen)
for (var bron in wijstab.bronnen.where((b) => !b.isFolder)) //Folders are not yet supported
BijlageItem(
bron,
download: account().magister.bronnen.downloadFile,
Expand All @@ -248,14 +248,10 @@ class _StudiewijzerTab extends State<StudiewijzerTab> {
onRefresh: () async => retry(),
child: EmptyPage(
icon: Icons.wifi_off_outlined,
text: error?.error ?? error?.toString(),
text: error?.toString(),
),
),
futureBuilder: () async {
await account().magister.studiewijzers.loadTab(
wijstab,
);
},
futureBuilder: () async => await account().magister.studiewijzers.loadTab(wijstab),
busyBuilder: (BuildContext context) => Center(
child: CircularProgressIndicator(),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/hive/adapters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ class Wijzer {
if (pinned == null) {
pinned = false;
}
if (wijzer["Links"] != null) {
if (wijzer["Links"] != null && wijzer["Links"].isNotEmpty) {
this.tabUrl = wijzer["Links"].where((a) => a["Rel"] == "Self").first["Href"];
}
if (wijzer["Bronnen"] != null) {
Expand Down
6 changes: 4 additions & 2 deletions lib/src/utils/magister/Bronnen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:dio/dio.dart';

import 'magister.dart';
import 'package:argo/src/utils/hive/adapters.dart';

Expand Down Expand Up @@ -35,8 +37,8 @@ class Bronnen extends MagisterApi {
onReceiveProgress(bron.size, 0);
return;
}
await api.dio.download(
bron.downloadUrl,
await Dio().download(
(await api.dio.get(bron.downloadUrl + "?redirect_type=body")).data["location"],
savePath,
onReceiveProgress: onReceiveProgress,
);
Expand Down
7 changes: 4 additions & 3 deletions lib/src/utils/magister/Studiewijzers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ class Studiewijzers extends MagisterApi {
.cast<Wijzer>();
}

Future<Map> loadWijzer([id = ""]) async {
return (await api.dio.get("api/leerlingen/${account.id}/studiewijzers/$id?peildatum=${dateFormatter.format(DateTime.now())}")).data;
Future<Map> loadWijzer() async {
var wijzers = await Future.wait([api.dio.get("api/leerlingen/${account.id}/studiewijzers/?peildatum=${dateFormatter.format(DateTime.now())}"), api.dio.get("api/leerlingen/${account.id}/projecten/?peildatum=${dateFormatter.format(DateTime.now())}")]);
return {...wijzers.first.data}..["Items"].addAll(wijzers.last.data["Items"]);
}

Future loadChildren(Wijzer wijs) async {
Map wijzer = (await loadWijzer(wijs.id));
Map wijzer = (await api.dio.get(wijs.tabUrl)).data;
wijs.children = wijzer["Onderdelen"]["Items"]
.map(
(wijs) => Wijzer(wijs),
Expand Down

0 comments on commit 15fa874

Please sign in to comment.