Line data Source code
1 : import 'package:flutter/cupertino.dart';
2 : import 'package:folly_fields/crud/abstract_model.dart';
3 :
4 : ///
5 : ///
6 : ///
7 : @immutable
8 : abstract class AbstractConsumer<T extends AbstractModel<Object>> {
9 : final List<String> routeName;
10 : final String? offlineTableName;
11 : final String? offlineWhere;
12 : final List<dynamic>? offlineWhereArgs;
13 : final String offlineOrderBy;
14 : final String? offlineTerms;
15 : final bool returnLog;
16 :
17 : ///
18 : ///
19 : ///
20 5 : const AbstractConsumer(
21 : this.routeName, {
22 : this.offlineTableName,
23 : this.offlineWhere,
24 : this.offlineWhereArgs,
25 : this.offlineOrderBy = 'id',
26 : this.offlineTerms,
27 : this.returnLog = false,
28 : });
29 :
30 : ///
31 : ///
32 : ///
33 : T fromJson(Map<String, dynamic> map);
34 :
35 : ///
36 : ///
37 : ///
38 : Future<ConsumerPermission> checkPermission(
39 : BuildContext context,
40 : List<String> paths,
41 : );
42 :
43 : ///
44 : ///
45 : ///
46 : Future<List<T>> list(
47 : BuildContext context, {
48 : // TODO(edufolly): @QueryParam("sort") List<String> sortQuery
49 : int page = 0,
50 : int size = 20,
51 : Map<String, String> extraParams = const <String, String>{},
52 : bool forceOffline = false,
53 : });
54 :
55 : ///
56 : ///
57 : ///
58 0 : Future<Map<T, String>> dropdownMap(
59 : BuildContext context, {
60 : int page = 0,
61 : int size = 20,
62 : Map<String, String> extraParams = const <String, String>{},
63 : bool forceOffline = false,
64 : }) async =>
65 0 : (await list(
66 : context,
67 : page: page,
68 : size: size,
69 : extraParams: extraParams,
70 : forceOffline: forceOffline,
71 : ))
72 0 : .asMap()
73 0 : .map((_, T item) => MapEntry<T, String>(item, item.dropdownText));
74 :
75 : ///
76 : ///
77 : ///
78 : Future<T?> getById(
79 : BuildContext context,
80 : T model, {
81 : Map<String, String> extraParams = const <String, String>{},
82 : });
83 :
84 : ///
85 : ///
86 : ///
87 0 : Future<bool> beforeDelete(
88 : BuildContext context,
89 : T model, {
90 : Map<String, String> extraParams = const <String, String>{},
91 : }) async =>
92 : true;
93 :
94 : ///
95 : ///
96 : ///
97 : Future<bool> delete(
98 : BuildContext context,
99 : T model, {
100 : Map<String, String> extraParams = const <String, String>{},
101 : });
102 :
103 : ///
104 : ///
105 : ///
106 0 : Future<bool> beforeSaveOrUpdate(
107 : BuildContext context,
108 : T model, {
109 : Map<String, String> extraParams = const <String, String>{},
110 : }) async =>
111 : true;
112 :
113 : ///
114 : ///
115 : ///
116 : Future<bool> saveOrUpdate(
117 : BuildContext context,
118 : T model, {
119 : Map<String, String> extraParams = const <String, String>{},
120 : });
121 : }
122 :
123 : ///
124 : ///
125 : ///
126 : @immutable
127 : class ConsumerPermission {
128 : final bool menu;
129 : final bool view;
130 : final bool insert;
131 : final bool update;
132 : final bool delete;
133 : final String iconName;
134 : final String name;
135 :
136 : ///
137 : ///
138 : ///
139 5 : const ConsumerPermission({
140 : this.menu = false,
141 : this.view = false,
142 : this.insert = false,
143 : this.update = false,
144 : this.delete = false,
145 : this.iconName = 'solidCircle',
146 : this.name = '',
147 : });
148 :
149 : ///
150 : ///
151 : ///
152 0 : ConsumerPermission.fromJson(Map<String, dynamic> map)
153 0 : : menu = map['menu'] ?? false,
154 0 : view = map['view'] ?? false,
155 0 : insert = map['insert'] ?? false,
156 0 : update = map['update'] ?? false,
157 0 : delete = map['delete'] ?? false,
158 0 : iconName = map['iconName'] ?? 'solidCircle',
159 0 : name = map['name'] ?? '';
160 :
161 : ///
162 : ///
163 : ///
164 0 : Map<String, dynamic> toMap() {
165 0 : return <String, dynamic>{
166 0 : 'menu': menu,
167 0 : 'view': view,
168 0 : 'insert': insert,
169 0 : 'update': update,
170 0 : 'delete': delete,
171 0 : 'iconName': iconName,
172 0 : 'name': name,
173 : };
174 : }
175 : }
|