Skip to content

Commit

Permalink
redesigned AppFeatures
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Nov 16, 2024
1 parent 53fcbeb commit 3e5e879
Show file tree
Hide file tree
Showing 28 changed files with 42 additions and 944 deletions.
82 changes: 0 additions & 82 deletions lib/backend/forum/card.dart

This file was deleted.

28 changes: 0 additions & 28 deletions lib/backend/forum/page/index.dart

This file was deleted.

3 changes: 0 additions & 3 deletions lib/backend/update/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import 'package:flutter/foundation.dart';
import 'package:mimir/agreements/entity/agreements.dart';
import 'package:mimir/design/adaptive/dialog.dart';
import 'package:mimir/design/adaptive/foundation.dart';
import 'package:mimir/feature/feature.dart';
import 'package:mimir/feature/utils.dart';
import 'package:mimir/r.dart';
import 'package:mimir/settings/settings.dart';
import 'package:mimir/utils/error.dart';
Expand All @@ -22,7 +20,6 @@ Future<void> checkAppUpdate({
}) async {
if (kIsWeb) return;
if (Settings.agreements.getBasicAcceptanceOf(AgreementVersion.current) != true) return;
if (!can(AppFeature.mimirUpdate)) return;
try {
await _checkAppUpdate(
context: context,
Expand Down
85 changes: 6 additions & 79 deletions lib/credentials/entity/user_type.dart
Original file line number Diff line number Diff line change
@@ -1,95 +1,22 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:mimir/feature/feature.dart';
import 'package:mimir/storage/hive/type_id.dart';

part 'user_type.g.dart';

@HiveType(typeId: CoreHiveType.oaUserType)
enum OaUserType {
@HiveField(0)
undergraduate(allowed: {
AppFeature.mimirForum,
AppFeature.mimirBulletin,
AppFeature.timetable,
AppFeature.secondClass$,
AppFeature.examResultUg,
AppFeature.examArrangement,
AppFeature.teacherEval,
AppFeature.ywb,
AppFeature.gpaUg,
AppFeature.yellowPages,
AppFeature.expenseRecords$,
AppFeature.electricityBalance,
AppFeature.library$,
AppFeature.eduEmail$,
AppFeature.oaAnnouncement,
AppFeature.game$,
AppFeature.mimirUpdate,
}),
undergraduate(),
@HiveField(1)
postgraduate(allowed: {
AppFeature.mimirForum,
AppFeature.mimirBulletin,
AppFeature.timetable,
AppFeature.examResultPg,
AppFeature.ywb,
AppFeature.expenseRecords$,
AppFeature.electricityBalance,
AppFeature.library$,
AppFeature.yellowPages,
AppFeature.eduEmail$,
AppFeature.oaAnnouncement,
AppFeature.game$,
AppFeature.mimirUpdate,
}),
postgraduate(),
@HiveField(2)
freshman(allowed: {
AppFeature.timetable,
AppFeature.mimirForum,
AppFeature.mimirBulletin,
AppFeature.yellowPages,
AppFeature.librarySearch,
AppFeature.oaAnnouncement,
AppFeature.freshman,
AppFeature.game$,
AppFeature.mimirUpdate,
}),
freshman(),
@HiveField(3)
worker(allowed: {
AppFeature.mimirForum,
AppFeature.mimirBulletin,
AppFeature.ywb,
AppFeature.expenseRecords$,
AppFeature.electricityBalance,
AppFeature.yellowPages,
AppFeature.library$,
AppFeature.oaAnnouncement,
AppFeature.game$,
AppFeature.mimirUpdate,
}),
worker(),
@HiveField(4)
none(allowed: {
AppFeature.mimirForum,
AppFeature.mimirBulletin,
AppFeature.timetable,
AppFeature.electricityBalance,
AppFeature.librarySearch,
AppFeature.eduEmail$,
AppFeature.yellowPages,
AppFeature.mimirUpdate,
});
none();

final Set<String> allowed;

const OaUserType({
required this.allowed,
});
const OaUserType();

String l10n() => "OaUserType.$name".tr();

static final _type2Filter = Map.fromEntries(OaUserType.values.map(
(v) => MapEntry(v, AppFeatureFilter.build(allow: v.allowed, prohibit: {})),
));

AppFeatureFilter get featureFilter => _type2Filter[this]!;
}
18 changes: 3 additions & 15 deletions lib/entity/campus.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:mimir/feature/feature.dart';
import 'package:mimir/storage/hive/type_id.dart';

part 'campus.g.dart';

@HiveType(typeId: CoreHiveType.campus)
enum Campus {
@HiveField(0)
fengxian(prohibited: {}),
fengxian(),
@HiveField(1)
xuhui(prohibited: {
"school.electricityBalance",
});
xuhui();

final Set<String> prohibited;

const Campus({
required this.prohibited,
});
const Campus();

String l10n() => "campus.$name".tr();

static final _type2Filter = Map.fromEntries(Campus.values.map(
(v) => MapEntry(v, AppFeatureFilter.build(allow: {}, prohibit: v.prohibited)),
));

AppFeatureFilter get featureFilter => _type2Filter[this]!;
}
Loading

0 comments on commit 3e5e879

Please sign in to comment.