Skip to content

Commit

Permalink
Merge branch 'disable_filter'
Browse files Browse the repository at this point in the history
  • Loading branch information
IoanaAlexandru committed Apr 4, 2020
2 parents 02c8352 + 281844e commit 5da28a7
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 53 deletions.
4 changes: 4 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MessageLookup extends MessageLookupByLibrary {

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"actionApply" : MessageLookupByLibrary.simpleMessage("Apply"),
"actionDeleteAccount" : MessageLookupByLibrary.simpleMessage("Delete account"),
"actionLogIn" : MessageLookupByLibrary.simpleMessage("Log in"),
"actionLogInAnonymously" : MessageLookupByLibrary.simpleMessage("Log in anonymously"),
Expand Down Expand Up @@ -58,6 +59,8 @@ class MessageLookup extends MessageLookupByLibrary {
"errorSomethingWentWrong" : MessageLookupByLibrary.simpleMessage("Something went wrong."),
"errorTooManyRequests" : MessageLookupByLibrary.simpleMessage("There have been too many requests from this device."),
"fileAcsBanner" : MessageLookupByLibrary.simpleMessage("assets/images/acs_banner_en.png"),
"filterMenuRelevance" : MessageLookupByLibrary.simpleMessage("Filter by relevance"),
"filterMenuShowAll" : MessageLookupByLibrary.simpleMessage("Show all"),
"hintEmail" : MessageLookupByLibrary.simpleMessage("john.doe"),
"hintFirstName" : MessageLookupByLibrary.simpleMessage("John"),
"hintGroup" : MessageLookupByLibrary.simpleMessage("314CB"),
Expand Down Expand Up @@ -93,6 +96,7 @@ class MessageLookup extends MessageLookupByLibrary {
"settingsItemLanguageAuto" : MessageLookupByLibrary.simpleMessage("Auto"),
"settingsItemLanguageEnglish" : MessageLookupByLibrary.simpleMessage("English"),
"settingsItemLanguageRomanian" : MessageLookupByLibrary.simpleMessage("Romanian"),
"settingsRelevanceFilter" : MessageLookupByLibrary.simpleMessage("Relevance filter"),
"settingsTitleLocalization" : MessageLookupByLibrary.simpleMessage("Localization"),
"settingsTitlePersonalization" : MessageLookupByLibrary.simpleMessage("Personalization"),
"stringAnonymous" : MessageLookupByLibrary.simpleMessage("Anonymous"),
Expand Down
4 changes: 4 additions & 0 deletions lib/generated/intl/messages_ro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MessageLookup extends MessageLookupByLibrary {

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"actionApply" : MessageLookupByLibrary.simpleMessage("Aplică"),
"actionDeleteAccount" : MessageLookupByLibrary.simpleMessage("Ștergere cont"),
"actionLogIn" : MessageLookupByLibrary.simpleMessage("Conectare"),
"actionLogInAnonymously" : MessageLookupByLibrary.simpleMessage("Conectare anonimă"),
Expand Down Expand Up @@ -58,6 +59,8 @@ class MessageLookup extends MessageLookupByLibrary {
"errorSomethingWentWrong" : MessageLookupByLibrary.simpleMessage("A apărut o problemă."),
"errorTooManyRequests" : MessageLookupByLibrary.simpleMessage("Au fost trimise prea multe cereri de pe acest dispozitiv."),
"fileAcsBanner" : MessageLookupByLibrary.simpleMessage("assets/images/acs_banner_ro.png"),
"filterMenuRelevance" : MessageLookupByLibrary.simpleMessage("Filtrează după relevanță"),
"filterMenuShowAll" : MessageLookupByLibrary.simpleMessage("Arată tot"),
"hintEmail" : MessageLookupByLibrary.simpleMessage("john.doe"),
"hintFirstName" : MessageLookupByLibrary.simpleMessage("John"),
"hintGroup" : MessageLookupByLibrary.simpleMessage("314CB"),
Expand Down Expand Up @@ -93,6 +96,7 @@ class MessageLookup extends MessageLookupByLibrary {
"settingsItemLanguageAuto" : MessageLookupByLibrary.simpleMessage("Auto"),
"settingsItemLanguageEnglish" : MessageLookupByLibrary.simpleMessage("Engleză"),
"settingsItemLanguageRomanian" : MessageLookupByLibrary.simpleMessage("Română"),
"settingsRelevanceFilter" : MessageLookupByLibrary.simpleMessage("Filtru de relevanță"),
"settingsTitleLocalization" : MessageLookupByLibrary.simpleMessage("Localizare"),
"settingsTitlePersonalization" : MessageLookupByLibrary.simpleMessage("Personalizare"),
"stringAnonymous" : MessageLookupByLibrary.simpleMessage("Anonim"),
Expand Down
37 changes: 37 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"actionSendEmail": "Send e-mail",
"actionSendVerificationAgain": "Send e-mail again?",
"actionDeleteAccount": "Delete account",
"actionApply": "Apply",

"errorSomethingWentWrong": "Something went wrong.",
"errorPasswordsDiffer": "The two passwords differ.",
Expand Down Expand Up @@ -56,13 +57,17 @@
"navigationSettings": "Settings",
"navigationFilter": "Filter",

"filterMenuShowAll": "Show all",
"filterMenuRelevance": "Filter by relevance",

"settingsTitlePersonalization": "Personalization",
"settingsItemDarkMode": "Dark mode",
"settingsTitleLocalization": "Localization",
"settingsItemLanguage": "Language",
"settingsItemLanguageEnglish": "English",
"settingsItemLanguageRomanian": "Romanian",
"settingsItemLanguageAuto": "Auto",
"settingsRelevanceFilter": "Relevance filter",

"websiteCategoryLearning": "Learning",
"websiteCategoryAdministrative": "Administrative",
Expand Down
5 changes: 5 additions & 0 deletions lib/l10n/intl_ro.arb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"actionSendEmail": "Trimite e-mail",
"actionSendVerificationAgain": "Trimite mail din nou?",
"actionDeleteAccount": "Ștergere cont",
"actionApply": "Aplică",

"errorSomethingWentWrong": "A apărut o problemă.",
"errorPasswordsDiffer": "Cele două parole diferă.",
Expand Down Expand Up @@ -56,13 +57,17 @@
"navigationSettings": "Setări",
"navigationFilter": "Filtru",

"filterMenuShowAll": "Arată tot",
"filterMenuRelevance": "Filtrează după relevanță",

"settingsTitlePersonalization": "Personalizare",
"settingsItemDarkMode": "Dark mode",
"settingsTitleLocalization": "Localizare",
"settingsItemLanguage": "Limbă",
"settingsItemLanguageEnglish": "Engleză",
"settingsItemLanguageRomanian": "Română",
"settingsItemLanguageAuto": "Auto",
"settingsRelevanceFilter": "Filtru de relevanță",

"websiteCategoryLearning": "Cursuri",
"websiteCategoryAdministrative": "Administrativ",
Expand Down
16 changes: 15 additions & 1 deletion lib/pages/filter/service/filter_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension FilterNodeExtension on FilterNode {

class FilterProvider with ChangeNotifier {
final Firestore _db = Firestore.instance;
Filter _relevanceFilter;
Filter _relevanceFilter; // filter cache

void resetFilter() {
_relevanceFilter = null;
Expand All @@ -29,6 +29,20 @@ class FilterProvider with ChangeNotifier {
PrefService.setStringList('relevant_nodes', null);
}

void enable() {
_relevanceFilter = null;
PrefService.setBool('relevance_filter', true);
notifyListeners();
}

void disable() {
_relevanceFilter = null;
PrefService.setBool('relevance_filter', false);
notifyListeners();
}

bool get filterEnabled => PrefService.get('relevance_filter');

Future<Filter> getRelevanceFilter(BuildContext context) async {
if (_relevanceFilter != null) {
return _relevanceFilter;
Expand Down
32 changes: 22 additions & 10 deletions lib/pages/filter/view/filter_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,44 @@ class FilterPageState extends State<FilterPage> {

@override
Widget build(BuildContext context) {
var filterProvider = Provider.of<FilterProvider>(context);

List<Widget> widgets = [SizedBox(height: 10.0)];

// Only fetch the filter once.
// This is a tradeoff, since it makes the UI a bit buggy in some cases (for
// instance if a row shows up before a row that has an option selected, it
// will have that option selected as well). However, it avoids the page
// being rebuilt completely every single time something is pressed (which
// looks really bad and scrolls all the rows back to the beginning).
if (filterFuture == null) {
// Only fetch filter once
filterFuture =
Provider.of<FilterProvider>(context).getRelevanceFilter(context);
filterFuture = filterProvider.getRelevanceFilter(context);
}

return AppScaffold(
title: S.of(context).navigationFilter,
enableMenu: false,
enableMenu: true,
menuText: S.of(context).actionApply,
menuAction: () {
filterProvider.enable();
Navigator.of(context).pop();
},
body: FutureBuilder(
future: filterFuture,
builder: (BuildContext context, AsyncSnapshot snap) {
if (snap.hasData) {
if (snap.connectionState == ConnectionState.done && snap.hasData) {
Filter filter = snap.data;

Map<int, List<Widget>> optionsByLevel = {};
_buildTree(node: filter.root, optionsByLevel: optionsByLevel);
List<Widget> widgets = [];
for (var i = 0; i < filter.localizedLevelNames.length; i++) {
if (optionsByLevel[i] == null || optionsByLevel.isEmpty) {
break;
}

// Level name
widgets.add(Padding(
padding: const EdgeInsets.all(10.0),
padding: const EdgeInsets.only(left: 10.0, bottom: 8.0),
child: Text(
filter.localizedLevelNames[i][Utils.getLocaleString()],
style: Theme.of(context).textTheme.headline6),
Expand All @@ -133,15 +145,15 @@ class FilterPageState extends State<FilterPage> {
// Level options
widgets.addAll(optionsByLevel[i]);
}

return ListView(children: widgets);
} else if (snap.hasError) {
print(snap.error);
// TODO: Show error toast
return Container();
} else {
} else if (snap.connectionState != ConnectionState.done) {
return Center(child: CircularProgressIndicator());
}

return ListView(children: widgets);
}),
);
}
Expand Down
31 changes: 19 additions & 12 deletions lib/pages/portal/service/website_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,29 @@ class WebsiteProvider with ChangeNotifier {
Future<List<Website>> getWebsites(Filter filter) async {
try {
List<DocumentSnapshot> documents = [];

// Documents without a 'relevance' field are relevant for everyone
Query query = _db.collection('websites').where('relevance', isNull: true);
QuerySnapshot qSnapshot = await query.getDocuments();
documents.addAll(qSnapshot.documents);

for (String string in filter.relevantNodes) {
// selected nodes
Query query = _db
.collection('websites')
.where('degree', isEqualTo: filter.baseNode)
.where('relevance', arrayContains: string);

if (filter == null) {
QuerySnapshot qSnapshot = await _db.collection('websites').getDocuments();
documents.addAll(qSnapshot.documents);
} else {
// Documents without a 'relevance' field are relevant for everyone
Query query = _db.collection('websites').where('relevance', isNull: true);
QuerySnapshot qSnapshot = await query.getDocuments();
documents.addAll(qSnapshot.documents);

for (String string in filter.relevantNodes) {
// selected nodes
Query query = _db
.collection('websites')
.where('degree', isEqualTo: filter.baseNode)
.where('relevance', arrayContains: string);
QuerySnapshot qSnapshot = await query.getDocuments();
documents.addAll(qSnapshot.documents);
}
}



// Remove duplicates
// (a document may result out of more than one query)
final seenDocumentIds = Set<String>();
Expand Down
23 changes: 13 additions & 10 deletions lib/pages/portal/view/portal_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class _PortalPageState extends State<PortalPage> {
}
return CircleImage(
label: website.label,
tooltip:
website.infoByLocale[Utils.getLocaleString()],
tooltip: website
.infoByLocale[Utils.getLocaleString()],
image: image,
onTap: () => _launchURL(website.link),
);
Expand Down Expand Up @@ -136,11 +136,9 @@ class _PortalPageState extends State<PortalPage> {
Widget build(BuildContext context) {
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
WebsiteProvider websiteProvider = Provider.of<WebsiteProvider>(context);
FilterProvider filterProvider = Provider.of<FilterProvider>(context);

if (filterFuture == null) {
filterFuture =
Provider.of<FilterProvider>(context).getRelevanceFilter(context);
}
filterFuture = filterProvider.getRelevanceFilter(context);

List<Website> websites = [];

Expand All @@ -150,14 +148,19 @@ class _PortalPageState extends State<PortalPage> {
title: S.of(context).navigationPortal,
enableMenu: true,
menuIcon: CustomIcons.filter,
menuRoute: Routes.filter,
menuName: S.of(context).navigationFilter,
menuTooltip: S.of(context).navigationFilter,
menuItems: {
S.of(context).filterMenuShowAll: () => filterProvider.disable(),
S.of(context).filterMenuRelevance: () =>
Navigator.pushNamed(context, Routes.filter)
},
body: FutureBuilder(
future: filterFuture,
builder: (BuildContext context, AsyncSnapshot<Filter> filterSnap) {
if (filterSnap.hasData) {
if (filterSnap.connectionState == ConnectionState.done) {
return FutureBuilder<List<Website>>(
future: websiteProvider.getWebsites(filterSnap.data),
future: websiteProvider.getWebsites(
filterProvider.filterEnabled ? filterSnap.data : null),
builder: (context, AsyncSnapshot<List<Website>> websiteSnap) {
if (websiteSnap.hasData) {
websites = websiteSnap.data;
Expand Down
Loading

0 comments on commit 5da28a7

Please sign in to comment.