Line data Source code
1 : part of apptive_grid_model; 2 : 3 : /// A Uri representing a GridView 4 : class GridViewUri extends GridUri { 5 : /// Creates a new [GridViewUri] based on known ids for [user], [space], [grid] and [view] 6 4 : GridViewUri({ 7 : required String user, 8 : required String space, 9 : required String grid, 10 : required this.view, 11 4 : }) : super(user: user, space: space, grid: grid); 12 : 13 : /// Creates a new [GridViewUri] based on a string [uri] 14 : /// Main usage of this is for [GridViewUri] retrieved through other Api Calls 15 6 : factory GridViewUri.fromUri(String uri) { 16 : const regex = r'/api/users/(\w+)/spaces/(\w+)/grids/(\w+)/views/(\w+)\b'; 17 12 : final matches = RegExp(regex).allMatches(uri); 18 18 : if (matches.isEmpty || matches.elementAt(0).groupCount != 4) { 19 8 : throw ArgumentError('Could not parse GridViewUri $uri'); 20 : } 21 4 : final match = matches.elementAt(0); 22 4 : return GridViewUri( 23 4 : user: match.group(1)!, 24 4 : space: match.group(2)!, 25 4 : grid: match.group(3)!, 26 4 : view: match.group(4)!, 27 : ); 28 : } 29 : 30 : /// Id of the View this [GridViewUri] is representing 31 : final String view; 32 : 33 2 : @override 34 : String toString() { 35 10 : return 'GridViewUri(user: $user, space: $space grid: $grid, view: $view)'; 36 : } 37 : 38 : /// Generates the uriString used for ApiCalls referencing this 39 2 : @override 40 : String get uriString => 41 10 : '/api/users/$user/spaces/$space/grids/$grid/views/$view'; 42 : 43 3 : @override 44 : bool operator ==(Object other) { 45 3 : return other is GridViewUri && 46 9 : view == other.view && 47 9 : grid == other.grid && 48 9 : user == other.user && 49 9 : space == other.space; 50 : } 51 : 52 1 : @override 53 2 : int get hashCode => toString().hashCode; 54 : }