LCOV - code coverage report
Current view: top level - lib/crud - abstract_consumer.dart (source / functions) Hit Total Coverage
Test: Folly Fields Lines: 2 25 8.0 %
Date: 2023-05-11 23:59:26 Functions: 0 0 -

          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           2 :   @mustCallSuper
      21             :   const AbstractConsumer(
      22             :     this.routeName, {
      23             :     this.offlineTableName,
      24             :     this.offlineWhere,
      25             :     this.offlineWhereArgs,
      26             :     this.offlineOrderBy = 'id',
      27             :     this.offlineTerms,
      28             :     this.returnLog = false,
      29             :   });
      30             : 
      31             :   ///
      32             :   ///
      33             :   ///
      34             :   T fromJson(Map<String, dynamic> map);
      35             : 
      36             :   ///
      37             :   ///
      38             :   ///
      39             :   Future<ConsumerPermission> checkPermission(
      40             :     BuildContext context,
      41             :     List<String> paths,
      42             :   );
      43             : 
      44             :   ///
      45             :   ///
      46             :   ///
      47             :   Future<List<T>> list(
      48             :     BuildContext context,
      49             :     Map<String, String> qsParam, {
      50             :     required bool forceOffline,
      51             :   });
      52             : 
      53             :   ///
      54             :   ///
      55             :   ///
      56           0 :   Future<Map<T, String>> dropdownMap(
      57             :     BuildContext context, {
      58             :     Map<String, String> qsParam = const <String, String>{},
      59             :     bool forceOffline = false,
      60             :   }) async =>
      61           0 :       (await list(context, qsParam, forceOffline: forceOffline))
      62           0 :           .asMap()
      63           0 :           .map((_, T item) => MapEntry<T, String>(item, item.dropdownText));
      64             : 
      65             :   ///
      66             :   ///
      67             :   ///
      68             :   Future<T?> getById(
      69             :     BuildContext context,
      70             :     T model,
      71             :   );
      72             : 
      73             :   ///
      74             :   ///
      75             :   ///
      76           0 :   Future<bool> beforeDelete(BuildContext context, T model) async => true;
      77             : 
      78             :   ///
      79             :   ///
      80             :   ///
      81             :   Future<bool> delete(
      82             :     BuildContext context,
      83             :     T model,
      84             :   );
      85             : 
      86             :   ///
      87             :   ///
      88             :   ///
      89           0 :   Future<bool> beforeSaveOrUpdate(BuildContext context, T model) async => true;
      90             : 
      91             :   ///
      92             :   ///
      93             :   ///
      94             :   Future<bool> saveOrUpdate(
      95             :     BuildContext context,
      96             :     T model,
      97             :   );
      98             : }
      99             : 
     100             : ///
     101             : ///
     102             : ///
     103             : @immutable
     104             : class ConsumerPermission {
     105             :   final bool menu;
     106             :   final bool view;
     107             :   final bool insert;
     108             :   final bool update;
     109             :   final bool delete;
     110             :   final String iconName;
     111             :   final String name;
     112             : 
     113             :   ///
     114             :   ///
     115             :   ///
     116           2 :   const ConsumerPermission({
     117             :     this.menu = false,
     118             :     this.view = false,
     119             :     this.insert = false,
     120             :     this.update = false,
     121             :     this.delete = false,
     122             :     this.iconName = 'solidCircle',
     123             :     this.name = '',
     124             :   });
     125             : 
     126             :   ///
     127             :   ///
     128             :   ///
     129           0 :   ConsumerPermission.fromJson(Map<String, dynamic> map)
     130           0 :       : menu = map['menu'] ?? false,
     131           0 :         view = map['view'] ?? false,
     132           0 :         insert = map['insert'] ?? false,
     133           0 :         update = map['update'] ?? false,
     134           0 :         delete = map['delete'] ?? false,
     135           0 :         iconName = map['iconName'] ?? 'solidCircle',
     136           0 :         name = map['name'] ?? '';
     137             : 
     138             :   ///
     139             :   ///
     140             :   ///
     141           0 :   Map<String, dynamic> toMap() {
     142           0 :     return <String, dynamic>{
     143           0 :       'menu': menu,
     144           0 :       'view': view,
     145           0 :       'insert': insert,
     146           0 :       'update': update,
     147           0 :       'delete': delete,
     148           0 :       'iconName': iconName,
     149           0 :       'name': name,
     150             :     };
     151             :   }
     152             : }

Generated by: LCOV version 1.14