@@ -43,8 +43,8 @@ public class DashboardController : Controller
4343 private readonly PokestopRepository _pokestopRepository ;
4444 private readonly GeofenceRepository _geofenceRepository ;
4545 private readonly WebhookRepository _webhookRepository ;
46-
4746 private readonly DeviceGroupRepository _deviceGroupRepository ;
47+ private readonly IVListRepository _ivListRepository ;
4848
4949 #endregion
5050
@@ -67,6 +67,7 @@ public DashboardController(DeviceControllerContext context, IConnectionMultiplex
6767 _geofenceRepository = new GeofenceRepository ( _context ) ;
6868 _webhookRepository = new WebhookRepository ( _context ) ;
6969 _deviceGroupRepository = new DeviceGroupRepository ( _context ) ;
70+ _ivListRepository = new IVListRepository ( _context ) ;
7071 }
7172
7273 #endregion
@@ -395,6 +396,12 @@ public async Task<IActionResult> AddInstance()
395396 } ) ;
396397 obj . circle_size = 70 ;
397398 obj . nothing_selected = true ;
399+ var ivLists = await _ivListRepository . GetAllAsync ( ) . ConfigureAwait ( false ) ;
400+ obj . iv_lists = ivLists . Select ( x => new
401+ {
402+ name = x . Name ,
403+ selected = false ,
404+ } ) ;
398405 obj . iv_queue_limit = 100 ;
399406 obj . spin_limit = 3500 ;
400407 obj . quest_retry_limit = 5 ;
@@ -424,10 +431,7 @@ public async Task<IActionResult> AddInstance()
424431 var circleSize = Request . Form . ContainsKey ( "circle_size" )
425432 ? ushort . Parse ( Request . Form [ "circle_size" ] . ToString ( ) ?? "70" )
426433 : 70 ;
427- var pokemonIdsValue = Request . Form [ "pokemon_ids" ] . ToString ( ) ;
428- var pokemonIds = pokemonIdsValue == "*"
429- ? Enumerable . Range ( 1 , 999 ) . Select ( x => ( uint ) x ) . ToList ( )
430- : pokemonIdsValue ? . Split ( new string [ ] { "\n " } , StringSplitOptions . RemoveEmptyEntries ) ? . Select ( uint . Parse ) . ToList ( ) ;
434+ var ivList = Request . Form [ "iv_list" ] . ToString ( ) ;
431435 var fastBootstrapMode = Request . Form [ "fast_bootstrap_mode" ] . ToString ( ) == "on" ;
432436 var accountGroup = Request . Form [ "account_group" ] . ToString ( ) ;
433437 var isEvent = Request . Form [ "is_event" ] . ToString ( ) == "on" ;
@@ -458,7 +462,7 @@ public async Task<IActionResult> AddInstance()
458462 }
459463 }
460464
461- if ( minLevel > maxLevel || minLevel == 0 || minLevel > 40 || maxLevel == 0 || maxLevel > 40 )
465+ if ( minLevel > maxLevel || minLevel < 0 || minLevel > 40 || maxLevel < 0 || maxLevel > 40 )
462466 {
463467 // Invalid levels
464468 return BuildErrorResponse ( "instance-add" , "Invalid minimum and maximum levels provided" ) ;
@@ -482,7 +486,7 @@ public async Task<IActionResult> AddInstance()
482486 {
483487 IVQueueLimit = ivQueueLimit ,
484488 SpinLimit = spinLimit ,
485- PokemonIds = pokemonIds ,
489+ IVList = ivList ,
486490 Timezone = timezone ,
487491 EnableDst = enableDst ,
488492 CircleRouteType = circleRouteType ,
@@ -552,7 +556,13 @@ public async Task<IActionResult> EditInstance(string name)
552556 obj . circle_route_type = instance . Data . CircleRouteType ;
553557 // break;
554558 // case InstanceType.PokemonIV:
555- obj . pokemon_ids = instance . Data . PokemonIds == null ? null : string . Join ( "\n " , instance . Data . PokemonIds ) ;
559+ //obj.pokemon_ids = instance.Data.PokemonIds == null ? null : string.Join("\n", instance.Data.PokemonIds);
560+ var ivLists = await _ivListRepository . GetAllAsync ( ) . ConfigureAwait ( false ) ;
561+ obj . iv_lists = ivLists . Select ( x => new
562+ {
563+ name = x . Name ,
564+ selected = string . Compare ( instance . Data . IVList , x . Name , true ) == 0 ,
565+ } ) ;
556566 obj . iv_queue_limit = instance . Data . IVQueueLimit > 0 ? instance . Data . IVQueueLimit : 100 ;
557567 // break;
558568 // case InstanceType.AutoQuest:
@@ -608,18 +618,15 @@ public async Task<IActionResult> EditInstance(string name)
608618 var circleRouteType = Request . Form . ContainsKey ( "circle_route_type" )
609619 ? StringToCircleRouteType ( Request . Form [ "circle_route_type" ] . ToString ( ) )
610620 : CircleRouteType . Default ;
611- var pokemonIdsValue = Request . Form [ "pokemon_ids" ] . ToString ( ) ;
612- var pokemonIds = pokemonIdsValue == "*"
613- ? Enumerable . Range ( 1 , 999 ) . Select ( x => ( uint ) x ) . ToList ( )
614- : pokemonIdsValue ? . Split ( new string [ ] { "\n " } , StringSplitOptions . RemoveEmptyEntries ) ? . Select ( uint . Parse ) . ToList ( ) ;
621+ var ivList = Request . Form [ "iv_list" ] . ToString ( ) ;
615622 var ivQueueLimit = ushort . Parse ( Request . Form [ "iv_queue_limit" ] ) ;
616623 var spinLimit = ushort . Parse ( Request . Form [ "spin_limit" ] ) ;
617624 var fastBootstrapMode = Request . Form [ "fast_bootstrap_mode" ] . ToString ( ) == "on" ;
618625 var questRetryLimit = byte . Parse ( Request . Form [ "quest_retry_limit" ] . ToString ( ) ) ;
619626 var accountGroup = Request . Form [ "account_group" ] . ToString ( ) ;
620627 var isEvent = Request . Form [ "is_event" ] . ToString ( ) == "on" ;
621628 var enableDst = Request . Form [ "enable_dst" ] . ToString ( ) == "on" ;
622- if ( minLevel > maxLevel || minLevel == 0 || minLevel > 40 || maxLevel == 0 || maxLevel > 40 )
629+ if ( minLevel > maxLevel || minLevel < 0 || minLevel > 40 || maxLevel < 0 || maxLevel > 40 )
623630 {
624631 // Invalid levels
625632 return BuildErrorResponse ( "instance-edit" , "Invalid minimum and maximum levels provided" ) ;
@@ -647,7 +654,7 @@ public async Task<IActionResult> EditInstance(string name)
647654 CircleRouteType = circleRouteType ,
648655 CircleSize = circleSize ,
649656 SpinLimit = spinLimit ,
650- PokemonIds = pokemonIds ,
657+ IVList = ivList ,
651658 Timezone = timezone ,
652659 EnableDst = enableDst ,
653660 FastBootstrapMode = fastBootstrapMode ,
@@ -1413,6 +1420,132 @@ public async Task<IActionResult> EditWebhook(string name)
14131420
14141421 #endregion
14151422
1423+ #region IV Lists
1424+
1425+ [ HttpGet ( "/dashboard/ivlists" ) ]
1426+ public IActionResult GetIVLists ( )
1427+ {
1428+ var obj = BuildDefaultData ( ) ;
1429+ var data = TemplateRenderer . ParseTemplate ( "ivlists" , obj ) ;
1430+ return new ContentResult
1431+ {
1432+ Content = data ,
1433+ ContentType = "text/html" ,
1434+ StatusCode = 200 ,
1435+ } ;
1436+ }
1437+
1438+ [
1439+ HttpGet ( "/dashboard/ivlist/add" ) ,
1440+ HttpPost ( "/dashboard/ivlist/add" ) ,
1441+ ]
1442+ public async Task < IActionResult > AddIVList ( )
1443+ {
1444+ if ( Request . Method == "GET" )
1445+ {
1446+ dynamic obj = BuildDefaultData ( ) ;
1447+ var data = TemplateRenderer . ParseTemplate ( "ivlist-add" , obj ) ;
1448+ return new ContentResult
1449+ {
1450+ Content = data ,
1451+ ContentType = "text/html" ,
1452+ StatusCode = 200 ,
1453+ } ;
1454+ }
1455+ else
1456+ {
1457+ var name = Request . Form [ "name" ] . ToString ( ) ;
1458+ var pokemonIdsValue = Request . Form [ "pokemon_ids" ] . ToString ( ) ;
1459+ var pokemonIds = pokemonIdsValue == "*"
1460+ ? Enumerable . Range ( 1 , 999 ) . Select ( x => ( uint ) x ) . ToList ( )
1461+ : pokemonIdsValue ? . Split ( new string [ ] { "\n " } , StringSplitOptions . RemoveEmptyEntries ) ?
1462+ . Select ( uint . Parse )
1463+ . ToList ( ) ;
1464+
1465+ var ivList = await _ivListRepository . GetByIdAsync ( name ) . ConfigureAwait ( false ) ;
1466+ if ( ivList != null )
1467+ {
1468+ // Already exists
1469+ return BuildErrorResponse ( "ivlist-add" , $ "IV List with name '{ name } ' already exists") ;
1470+ }
1471+ ivList = new IVList
1472+ {
1473+ Name = name ,
1474+ PokemonIDs = pokemonIds ,
1475+ } ;
1476+ await _ivListRepository . AddOrUpdateAsync ( ivList ) ;
1477+ await IVListController . Instance . Reload ( ) ;
1478+ return Redirect ( "/dashboard/ivlists" ) ;
1479+ }
1480+ }
1481+
1482+ [
1483+ HttpGet ( "/dashboard/ivlist/edit/{name}" ) ,
1484+ HttpPost ( "/dashboard/ivlist/edit/{name}" ) ,
1485+ ]
1486+ public async Task < IActionResult > EditIVList ( string name )
1487+ {
1488+ if ( Request . Method == "GET" )
1489+ {
1490+ var ivList = await _ivListRepository . GetByIdAsync ( name ) ;
1491+ if ( ivList == null )
1492+ {
1493+ // Failed to get IV list by name
1494+ return Redirect ( "/dashboard/ivlists" ) ;
1495+ }
1496+ dynamic obj = BuildDefaultData ( ) ;
1497+ obj . name = ivList . Name ;
1498+ obj . old_name = ivList . Name ;
1499+ obj . pokemon_ids = string . Join ( "\n " , ivList . PokemonIDs ) ;
1500+ var data = TemplateRenderer . ParseTemplate ( "ivlist-edit" , obj ) ;
1501+ return new ContentResult
1502+ {
1503+ Content = data ,
1504+ ContentType = "text/html" ,
1505+ StatusCode = 200 ,
1506+ } ;
1507+ }
1508+ else
1509+ {
1510+ if ( Request . Form . ContainsKey ( "delete" ) )
1511+ {
1512+ var ivListToDelete = await _ivListRepository . GetByIdAsync ( name ) . ConfigureAwait ( false ) ;
1513+ if ( ivListToDelete != null )
1514+ {
1515+ await _ivListRepository . DeleteAsync ( ivListToDelete ) . ConfigureAwait ( false ) ;
1516+ await IVListController . Instance . Reload ( ) . ConfigureAwait ( false ) ;
1517+ _logger . LogDebug ( $ "IV list { name } was deleted") ;
1518+ }
1519+ return Redirect ( "/dashboard/ivlists" ) ;
1520+ }
1521+
1522+ var newName = Request . Form [ "name" ] . ToString ( ) ;
1523+ var oldName = Request . Form [ "old_name" ] . ToString ( ) ;
1524+ var pokemonIdsValue = Request . Form [ "pokemon_ids" ] . ToString ( ) ;
1525+ var pokemonIds = pokemonIdsValue == "*"
1526+ ? Enumerable . Range ( 1 , 999 ) . Select ( x => ( uint ) x ) . ToList ( )
1527+ : pokemonIdsValue ? . Split ( new string [ ] { "\n " } , StringSplitOptions . RemoveEmptyEntries ) ?
1528+ . Select ( uint . Parse )
1529+ . ToList ( ) ;
1530+ var ivList = await _ivListRepository . GetByIdAsync ( oldName ) . ConfigureAwait ( false ) ;
1531+ if ( ivList == null )
1532+ {
1533+ // Does not exist
1534+ return BuildErrorResponse ( "ivlist-edit" , $ "IV List with name '{ name } ' does not exist") ;
1535+ }
1536+ ivList = new IVList
1537+ {
1538+ Name = oldName ,
1539+ PokemonIDs = pokemonIds ,
1540+ } ;
1541+ await _ivListRepository . AddOrUpdateAsync ( ivList ) ;
1542+ await IVListController . Instance . Reload ( ) ;
1543+ return Redirect ( "/dashboard/ivlists" ) ;
1544+ }
1545+ }
1546+
1547+ #endregion
1548+
14161549 #region Accounts
14171550
14181551 [ HttpGet ( "/dashboard/accounts" ) ]
0 commit comments