@@ -4,6 +4,7 @@ import 'package:clipboard/clipboard.dart';
44import 'package:filesize/filesize.dart' ;
55import 'package:s5_server/store/create.dart' ;
66import 'package:selectable_autolink_text/selectable_autolink_text.dart' ;
7+ import 'package:simple_observable/simple_observable.dart' ;
78import 'package:url_launcher/url_launcher_string.dart' ;
89import 'package:vup/app.dart' ;
910import 'package:lib5/util.dart' ;
@@ -35,6 +36,14 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
3536 String ? get localStoreName =>
3637 mySky.portalAccounts['_local' ]? ['store' ]? .keys.first;
3738
39+ final hasChanges = Observable (initialValue: false );
40+
41+ void updateQuota () {
42+ quotaService.update ().then ((value) {
43+ setState (() {});
44+ });
45+ }
46+
3847 @override
3948 Widget build (BuildContext context) {
4049 return ListView (
@@ -51,6 +60,7 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
5160
5261 context.pop ();
5362 setState (() {});
63+ updateQuota ();
5464 } catch (e, st) {
5565 context.pop ();
5666 showErrorDialog (context, e, st);
@@ -72,6 +82,7 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
7282
7383 context.pop ();
7484 setState (() {});
85+ hasChanges.value = false ;
7586 } catch (e, st) {
7687 context.pop ();
7788 showErrorDialog (context, e, st);
@@ -388,11 +399,7 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
388399 }
389400 }
390401 };
391- mySky.portalAccounts['uploadPortalOrder' ]
392- .insert (0 , portalConfig.authority);
393-
394- mySky.portalAccounts['enabledPortals' ]
395- .add (portalConfig.authority);
402+ setupServiceOrder (portalConfig.authority);
396403
397404 dataBox.put (
398405 'portal_${portalConfig .authority }_auth_token' ,
@@ -404,7 +411,7 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
404411 context.pop ();
405412 setState (() {});
406413
407- quotaService. update ();
414+ updateQuota ();
408415 } catch (e, st) {
409416 context.pop ();
410417 showErrorDialog (context, e, st);
@@ -495,14 +502,7 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
495502 }
496503 };
497504
498- mySky.portalAccounts['uploadPortalOrder' ]
499- .remove ('_local' );
500- mySky.portalAccounts['enabledPortals' ].remove ('_local' );
501-
502- mySky.portalAccounts['uploadPortalOrder' ]
503- .insert (0 , '_local' );
504-
505- mySky.portalAccounts['enabledPortals' ].add ('_local' );
505+ setupServiceOrder ('_local' );
506506
507507 await mySky.savePortalAccounts ();
508508
@@ -519,7 +519,7 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
519519 context.pop ();
520520 setState (() {});
521521
522- quotaService. update ();
522+ updateQuota ();
523523 }
524524 } catch (e, st) {
525525 showErrorDialog (context, e, st);
@@ -626,14 +626,7 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
626626 }
627627 };
628628
629- mySky.portalAccounts['uploadPortalOrder' ]
630- .remove ('_local' );
631- mySky.portalAccounts['enabledPortals' ].remove ('_local' );
632-
633- mySky.portalAccounts['uploadPortalOrder' ]
634- .insert (0 , '_local' );
635-
636- mySky.portalAccounts['enabledPortals' ].add ('_local' );
629+ setupServiceOrder ('_local' );
637630
638631 await mySky.savePortalAccounts ();
639632
@@ -650,7 +643,7 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
650643 context.pop ();
651644 setState (() {});
652645
653- quotaService. update ();
646+ updateQuota ();
654647 }
655648 } catch (e, st) {
656649 showErrorDialog (context, e, st);
@@ -664,20 +657,147 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
664657 ],
665658 ),
666659 SizedBox (
667- height: 16 ,
660+ height: 12 ,
668661 ),
669-
670662 Text (
671- 'Advanced ' ,
663+ 'Uploads ' ,
672664 style: titleTextStyle,
673665 ),
674- if (s5Node.store != null )
675- Padding (
676- padding: const EdgeInsets .only (top: 6 ),
677- child: Text (
678- 'Important: If a local store is configured, all new files and metadata are uploaded to the local store.' ,
666+ SizedBox (
667+ height: 6 ,
668+ ),
669+ Text (
670+ 'Files are only uploaded to the first (1.) service, the other ones are tried if the first one fails. Metadata and thumbnails are uploaded to the services you select below.' ,
671+ ),
672+ SizedBox (
673+ height: 6 ,
674+ ),
675+ Row (
676+ children: [
677+ SizedBox (
678+ width: 80 ,
679+ child: Text (
680+ 'Files' ,
681+ style: TextStyle (fontWeight: FontWeight .bold),
682+ ),
679683 ),
680- ),
684+ for (final service in mySky.portalAccounts['enabledPortals' ])
685+ Padding (
686+ padding: const EdgeInsets .only (left: 8.0 ),
687+ child: ChoiceChip (
688+ avatar: mySky.fileUploadServiceOrder.contains (service)
689+ ? Text (
690+ '${mySky .fileUploadServiceOrder .indexOf (service ) + 1 }.' ,
691+ style: TextStyle (
692+ color: Theme .of (context).colorScheme.onPrimary,
693+ fontWeight: FontWeight .bold,
694+ ),
695+ )
696+ : null ,
697+ onSelected: (val) {
698+ if (val) {
699+ mySky.fileUploadServiceOrder.add (service);
700+ } else {
701+ mySky.fileUploadServiceOrder.remove (service);
702+ }
703+ setState (() {});
704+ hasChanges.value = true ;
705+ },
706+ label: Text (getServiceName (service)),
707+ selected: mySky.fileUploadServiceOrder.contains (service),
708+ ),
709+ ),
710+ ],
711+ ),
712+ SizedBox (height: 8 ),
713+ Row (
714+ children: [
715+ SizedBox (
716+ width: 80 ,
717+ child: Text (
718+ 'Metadata' ,
719+ style: TextStyle (fontWeight: FontWeight .bold),
720+ ),
721+ ),
722+ for (final service in mySky.portalAccounts['enabledPortals' ])
723+ Padding (
724+ padding: const EdgeInsets .only (left: 8.0 ),
725+ child: ChoiceChip (
726+ onSelected: (val) {
727+ if (val) {
728+ mySky.metadataUploadServiceOrder.add (service);
729+ } else {
730+ mySky.metadataUploadServiceOrder.remove (service);
731+ }
732+ setState (() {});
733+ hasChanges.value = true ;
734+ },
735+ label: Text (getServiceName (service)),
736+ selected: mySky.metadataUploadServiceOrder.contains (service),
737+ ),
738+ ),
739+ ],
740+ ),
741+ SizedBox (height: 8 ),
742+ Row (
743+ children: [
744+ SizedBox (
745+ width: 80 ,
746+ child: Text (
747+ 'Thumbnails' ,
748+ style: TextStyle (fontWeight: FontWeight .bold),
749+ ),
750+ ),
751+ for (final service in mySky.portalAccounts['enabledPortals' ])
752+ Padding (
753+ padding: const EdgeInsets .only (left: 8.0 ),
754+ child: ChoiceChip (
755+ onSelected: (val) {
756+ if (val) {
757+ mySky.thumbnailUploadServiceOrder.add (service);
758+ } else {
759+ mySky.thumbnailUploadServiceOrder.remove (service);
760+ }
761+ setState (() {});
762+ hasChanges.value = true ;
763+ },
764+ label: Text (getServiceName (service)),
765+ selected: mySky.thumbnailUploadServiceOrder.contains (service),
766+ ),
767+ ),
768+ ],
769+ ),
770+ StreamBuilder (
771+ stream: hasChanges.values,
772+ builder: (context, snapshot) {
773+ if (snapshot.data == true )
774+ return Padding (
775+ padding: const EdgeInsets .symmetric (vertical: 16.0 ),
776+ child: Text (
777+ 'You have unsaved changes. Remember to save!' ,
778+ style: TextStyle (
779+ color: Theme .of (context).primaryColor,
780+ fontWeight: FontWeight .bold,
781+ ),
782+ ),
783+ );
784+ return SizedBox ();
785+ },
786+ ),
787+ SizedBox (
788+ height: 12 ,
789+ ),
790+ /* Text(
791+ 'Pinning Automation',
792+ style: titleTextStyle,
793+ ),
794+ SizedBox(
795+ height: 12,
796+ ), */
797+ Text (
798+ 'Advanced' ,
799+ style: titleTextStyle,
800+ ),
681801 SizedBox (
682802 height: 6 ,
683803 ),
@@ -741,7 +861,7 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
741861 ),
742862 TextField (
743863 decoration: InputDecoration (
744- labelText: 'Upload Order' ,
864+ labelText: 'Old Upload Order' ,
745865 ),
746866 controller: TextEditingController (
747867 text: json.encode (mySky.portalAccounts['uploadPortalOrder' ])),
@@ -786,6 +906,26 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
786906 );
787907 }
788908
909+ void setupServiceOrder (String service) {
910+ mySky.fileUploadServiceOrder.remove (service);
911+ mySky.fileUploadServiceOrder.insert (0 , service);
912+
913+ mySky.metadataUploadServiceOrder.remove (service);
914+ mySky.metadataUploadServiceOrder.add (service);
915+ mySky.thumbnailUploadServiceOrder.remove (service);
916+ mySky.thumbnailUploadServiceOrder.add (service);
917+
918+ mySky.portalAccounts['enabledPortals' ].remove (service);
919+ mySky.portalAccounts['enabledPortals' ].add (service);
920+ }
921+
922+ String getServiceName (String name) {
923+ if (name == '_local' ) {
924+ return localStoreName ?? '_local' ;
925+ }
926+ return name;
927+ }
928+
789929 Card _buildLocalStoreCard (BuildContext context) {
790930 final accountInfo = quotaService.accountInfos['_local' ];
791931
@@ -809,6 +949,7 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
809949 setState (() {
810950 mySky.portalAccounts['_local' ] = null ;
811951 });
952+ hasChanges.value = true ;
812953 },
813954 child: Text (
814955 'Remove' ,
@@ -906,29 +1047,30 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
9061047 ),
9071048 if (accountInfo != null )
9081049 QuotaWidget (context: context, portal: portal),
909- Align (
910- alignment: Alignment .centerRight,
911- child: SizedBox (
912- width: 400 ,
913- child: SwitchListTile (
914- dense: true ,
915- value: mySky.portalAccounts['portals' ][portal]
916- ['autoPinEnabled' ] ??
917- false ,
918- title: Text (
919- 'Auto-Pin enabled' ,
920- ),
921- subtitle: Text (
922- 'When enabled, all data stored on one of your upload portals is replicated on this portal too' ,
1050+ if (false )
1051+ Align (
1052+ alignment: Alignment .centerRight,
1053+ child: SizedBox (
1054+ width: 400 ,
1055+ child: SwitchListTile (
1056+ dense: true ,
1057+ value: mySky.portalAccounts['portals' ][portal]
1058+ ['autoPinEnabled' ] ??
1059+ false ,
1060+ title: Text (
1061+ 'Auto-Pin enabled' ,
1062+ ),
1063+ subtitle: Text (
1064+ 'When enabled, all data stored on one of your upload portals is replicated on this portal too' ,
1065+ ),
1066+ onChanged: (val) {
1067+ mySky.portalAccounts['portals' ][portal]
1068+ ['autoPinEnabled' ] = val;
1069+ setState (() {});
1070+ },
9231071 ),
924- onChanged: (val) {
925- mySky.portalAccounts['portals' ][portal]['autoPinEnabled' ] =
926- val;
927- setState (() {});
928- },
9291072 ),
9301073 ),
931- ),
9321074 ],
9331075 ),
9341076 ),
0 commit comments