Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
work for issue #62
Browse files Browse the repository at this point in the history
  • Loading branch information
ontehfritz committed Jul 11, 2014
1 parent e288963 commit 32506dc
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/www.mtgdb.info/Test_MtgDb.Info/DeckTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Init()
});

deck.Cards = cards;
deck.SideBar = sideBoard;
deck.SideBoard = sideBoard;
deck.Description = "This is a test deck.";
deck.IsPublic = true;
deck.Name = "Test Deck";
Expand Down Expand Up @@ -63,7 +63,7 @@ public void Add_deck()
});

deck.Cards = cards;
deck.SideBar = sideBoard;
deck.SideBoard = sideBoard;
deck.Description = "This is a test deck 2";
deck.IsPublic = true;
deck.Name = "Test Deck 2";
Expand Down
28 changes: 16 additions & 12 deletions src/www.mtgdb.info/www.mtgdb.info.userprefs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="www.mtgdb.info/Models/Deck.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="www.mtgdb.info/Views/Logon/Settings.cshtml">
<Files>
<File FileName="www.mtgdb.info/Modules/DeckViewerModule.cs" Line="77" Column="18" />
<File FileName="www.mtgdb.info/Views/Deck/Deck.cshtml" Line="32" Column="10" />
<File FileName="www.mtgdb.info/Helpers/Email.cs" Line="17" Column="29" />
<File FileName="www.mtgdb.info/Modules/LogonModule.cs" Line="236" Column="49" />
<File FileName="www.mtgdb.info/web.config" Line="15" Column="30" />
<File FileName="www.mtgdb.info/Modules/DeckModule.cs" Line="189" Column="33" />
<File FileName="www.mtgdb.info/Views/Deck/MyDecks.cshtml" Line="23" Column="11" />
<File FileName="www.mtgdb.info/Views/MyCards.cshtml" Line="81" Column="61" />
<File FileName="www.mtgdb.info/Views/Index.cshtml" Line="1" Column="1" />
<File FileName="www.mtgdb.info/Content/css/mtgdb.css" Line="384" Column="40" />
<File FileName="www.mtgdb.info/Models/Deck.cs" Line="20" Column="1" />
<File FileName="www.mtgdb.info/Models/Views/DeckModel.cs" Line="20" Column="22" />
<File FileName="www.mtgdb.info/Views/Deck/Deck.cshtml" Line="13" Column="38" />
<File FileName="www.mtgdb.info/Modules/DeckViewerModule.cs" Line="77" Column="22" />
<File FileName="www.mtgdb.info/Views/About.cshtml" Line="7" Column="21" />
<File FileName="www.mtgdb.info/Views/Book.cshtml" Line="1" Column="1" />
<File FileName="www.mtgdb.info/Views/Card.cshtml" Line="18" Column="27" />
<File FileName="www.mtgdb.info/Views/Sets.cshtml" Line="10" Column="2" />
<File FileName="www.mtgdb.info/Views/FAQ.cshtml" Line="10" Column="5" />
<File FileName="www.mtgdb.info/Views/MyCards.cshtml" Line="15" Column="5" />
<File FileName="www.mtgdb.info/Views/Planeswalker.cshtml" Line="15" Column="2" />
<File FileName="www.mtgdb.info/Views/Search.cshtml" Line="16" Column="24" />
<File FileName="www.mtgdb.info/Views/Logon/Forgot.cshtml" Line="1" Column="1" />
<File FileName="www.mtgdb.info/Views/Logon/Loggedin.cshtml" Line="1" Column="1" />
<File FileName="www.mtgdb.info/Views/Logon/Logon.cshtml" Line="1" Column="1" />
<File FileName="www.mtgdb.info/Views/Logon/Settings.cshtml" Line="16" Column="45" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
Expand Down
24 changes: 15 additions & 9 deletions src/www.mtgdb.info/www.mtgdb.info/Helpers/MtgFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public static string ExportDec(Deck deck)
}

//sidebar
foreach(var card in deck.GetSideBarCards())
foreach(var card in deck.GetSideBoardCards())
{
dec.AppendFormat("SB: {0} {1}\n",deck.SideBarCardCount(card.Id),
dec.AppendFormat("SB: {0} {1}\n",deck.SideBoardCardCount(card.Id),
card.Name.Replace("//", "/"));
}

Expand Down Expand Up @@ -68,7 +68,7 @@ public static Deck ImportDec(Stream stream)
.OrderByDescending(x => x.Id)
.FirstOrDefault();

deck.SideBar.Add(new DeckCard(){
deck.SideBoard.Add(new DeckCard(){
Amount = amount,
MultiverseId = card.Id
});
Expand All @@ -89,12 +89,18 @@ public static Deck ImportDec(Stream stream)


int amount = int.Parse(number.Trim());
Card card = magicdb.GetCards(cardName.Trim()).FirstOrDefault();

deck.Cards.Add(new DeckCard(){
Amount = amount,
MultiverseId = card.Id
});

Card card = magicdb.GetCards(cardName.Trim())
.OrderByDescending(x => x.Id).FirstOrDefault();


if(amount > 0)
{
deck.Cards.Add(new DeckCard(){
Amount = amount,
MultiverseId = card.Id
});
}

}
catch(Exception exc)
Expand Down
18 changes: 9 additions & 9 deletions src/www.mtgdb.info/www.mtgdb.info/Models/Deck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Deck
[BsonElement]
public List<DeckCard> Cards { get; set; }
[BsonElement]
public List<DeckCard> SideBar { get; set; }
public List<DeckCard> SideBoard { get; set; }
[BsonElement]
public DateTime CreatedAt { get; set; }
[BsonElement]
Expand All @@ -48,7 +48,7 @@ public Deck ()
{
mtgDb = new Db (ConfigurationManager.AppSettings.Get("api"));
Cards = new List<DeckCard>();
SideBar = new List<DeckCard>();
SideBoard = new List<DeckCard>();
Types = new Dictionary<string, List<string>>();
Types.Add("creature", new List<string>(){
"Creature",
Expand Down Expand Up @@ -133,7 +133,7 @@ public void SetCards(int [] mvids)
}


public void SetSideBar(int [] mvids)
public void SetSideBoard(int [] mvids)
{
Dictionary<int, int> deckCard = new Dictionary<int, int>();

Expand All @@ -149,7 +149,7 @@ public void SetSideBar(int [] mvids)
}
}

SideBar = deckCard.Select(c => new DeckCard {
SideBoard = deckCard.Select(c => new DeckCard {
MultiverseId = c.Key, Amount = c.Value
}).ToList();
}
Expand Down Expand Up @@ -193,11 +193,11 @@ public Card[] GetCards(string type)
return cards.OrderBy(x => x.Name).ToArray();
}

public Card[] GetSideBarCards()
public Card[] GetSideBoardCards()
{
if(SideBar != null)
if(SideBoard != null)
{
int [] multiverseIds = SideBar
int [] multiverseIds = SideBoard
.Select(x => x.MultiverseId)
.ToArray();

Expand Down Expand Up @@ -251,10 +251,10 @@ public int CardCount(string type)
return amount;
}

public int SideBarCardCount(int multiverseId)
public int SideBoardCardCount(int multiverseId)
{
DeckCard card =
this.SideBar.Find(x => x.MultiverseId == multiverseId);
this.SideBoard.Find(x => x.MultiverseId == multiverseId);

if(card != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Deck UpdateDeck(Deck deck)
.Set(d => d.Cards, deck.Cards)
.Set(d => d.Description, deck.Description)
.Set(d => d.IsPublic, deck.IsPublic)
.Set(d => d.SideBar, deck.SideBar)
.Set(d => d.SideBoard, deck.SideBoard)
.Set(d => d.ModifiedAt, deck.ModifiedAt),
new MongoUpdateOptions
{
Expand Down
8 changes: 7 additions & 1 deletion src/www.mtgdb.info/www.mtgdb.info/Models/Views/DeckModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public DeckModelValidator()
{
RuleFor(deck => deck.DeckFile).NotEmpty()
.WithMessage("No .dec file to render or save.");

RuleFor(deck => deck.Name).NotEmpty()
.WithMessage("Name cannot be blank. Yes, even for rendering.");
}
}

Expand All @@ -20,7 +23,10 @@ public class DeckModel : PageModel
public string Name { get; set; }
public string Email { get; set; }

public DeckModel () : base(){}
public DeckModel () : base()
{
Deck = new Deck();
}
}
}

18 changes: 18 additions & 0 deletions src/www.mtgdb.info/www.mtgdb.info/Modules/DeckModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ public DeckModule ()
return View["Deck/MyDecks", model];
};

Post["/decks/delete/{id}"] = parameters => {
Planeswalker planeswalker = (Planeswalker)this.Context.CurrentUser;
Guid id = Guid.Empty;
Deck deck = new Deck();
if(Guid.TryParse((string)parameters.id, out id))
{
deck = deckbuilder.GetDeck(id);
if(deck != null && deck.IsOwner(planeswalker))
{
deckbuilder.DeleteDeck(deck.Id);
}
}
return Response.AsRedirect("/mydecks");
};


// //for deck link sharing and viewing single deck
// Get["/pw/{planeswalker}/decks/{name}"] = parameters => {
// DeckModel model = new DeckModel();
Expand Down
16 changes: 15 additions & 1 deletion src/www.mtgdb.info/www.mtgdb.info/Modules/DeckViewerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,21 @@ public DeckViewerModule ()
byte[] byteArray = Encoding.ASCII.GetBytes(model.DeckFile);
MemoryStream stream = new MemoryStream(byteArray);
model.Deck = MtgFile.ImportDec(stream);
try
{
model.Deck = MtgFile.ImportDec(stream);
if(model.Deck.Cards.Count == 0)
{
model.Errors.Add("Deck file contains no valid cards.");
return View["Deck/Deck", model];
}
}
catch(Exception exc)
{
model.Errors.Add(exc.Message);
return View["Deck/Deck", model];
}
if(parameters.deckId != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/www.mtgdb.info/www.mtgdb.info/Views/About.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}
@section Top
{
<h1>About Us</h1>
<h4>About Us</h4>
}
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
Expand Down
2 changes: 1 addition & 1 deletion src/www.mtgdb.info/www.mtgdb.info/Views/Card.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}
@section Top{
<div class="t_section">
<h1>@Html.Raw(RenderHtml.Name(@Model.Card.Name))</h1>
<h4>@Html.Raw(RenderHtml.Name(@Model.Card.Name))</h4>
@if(Model.Card.Flavor != null && Model.Card.Flavor != "")
{
<blockquote><em>@Model.Card.Flavor</em></blockquote>
Expand Down
39 changes: 24 additions & 15 deletions src/www.mtgdb.info/www.mtgdb.info/Views/Deck/Deck.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

@section Top
{
<h1>Simple Deck Viewer <span class="label label-warning">In-Development</span></h1>
<h4>Deck: @Model.Name</h4>
Deck viewer status: <span class="label label-warning">In-Development</span>
}

<div style="width:1200px;">
Expand All @@ -19,7 +20,7 @@
</div>
}

@if(@Model.Deck == null || (@Model.Planeswalker != null && @Model.Deck.UserId == @Model.Planeswalker.Id))
@if(@Model.Deck.Id == Guid.Empty || (@Model.Planeswalker != null && @Model.Deck.UserId == @Model.Planeswalker.Id))
{
<div id="edit">
<form action="@path" method="post" >
Expand All @@ -32,8 +33,8 @@
}
<br />
<br />
<button type="submit" class="btn btn-primary btn-lg" name="Render">Render</button>
<button type="submit" class="btn btn-primary btn-lg" name="Save">Save</button>
<button type="submit" class="btn btn-primary" name="Render">Render</button>
<button type="submit" class="btn btn-primary" name="Save">Save</button>

@if(@Model.Planeswalker == null)
{
Expand All @@ -50,10 +51,6 @@
}
</div>
<div class="well" style="float:left;margin-left: 20px;width:800px;" id="deck">
@if(@Model.Deck != null)
{
<h2 style="padding:0px;margin: 0px;">Deck: @Model.Deck.Name</h2>
}
@if(@Model.Deck == null || Model.Deck.Cards == null || Model.Deck.Cards.Count == 0)
{
<h3>No cards to render. Paste .dec file and render.</h3>
Expand Down Expand Up @@ -96,19 +93,21 @@
}
}
<div id="sidebar">
@if(@Model.Deck != null && @Model.Deck.SideBar.Count > 0)
@if(@Model.Deck != null && @Model.Deck.SideBoard.Count > 0)
{
<h2>Side Bar</h2>
foreach(var card in Model.Deck.GetSideBarCards())
<h4>Side Bar</h4>
foreach(var card in Model.Deck.GetSideBoardCards())
{
int repeat = (int)System.Math.Ceiling(@Model.Deck.SideBarCardCount(card.Id) / 4.0);
int repeat = (int)System.Math.Ceiling(@Model.Deck.SideBoardCardCount(card.Id) / 4.0);
for(int times = 0; times < repeat; times++)
{
int top = 0;
string topStyle = string.Format("{0}px;", top);
int max = @Model.Deck.SideBarCardCount(card.Id) - (times * 4);
int max = @Model.Deck.SideBoardCardCount(card.Id) - (times * 4);
<div style="float:left;margin-left:10px;">
<div style="position:relative;height:140px;">
<div style="position:relative;height:140px;" class="deck-card" data-container="body"
data-toggle="popover" data-placement="right"
data-content="<image src='@card.CardImage' />" data-title="@card.Name">
<image src="@card.CardImage" style="position:relative;width:65px;height:87px; z-index: 0;display:block;"/>
@for(int i = 1; (i < max && i < 4); i++ )
{
Expand All @@ -125,13 +124,23 @@
<br style="clear:both;" />
</div>
<div>
@if(@Model.Deck != null)
@if(@Model.Deck.Description != null)
{
<h4>Description:</h4>
<p>@Model.Deck.Description</p>
}
</div>
<br />
<div style="clear:left;">
@if(@Model.Planeswalker != null && @Model.Deck.UserId == @Model.Planeswalker.Id)
{
<form action="/decks/delete/@Model.Deck.Id" method="post" >
<button type="submit" class="btn btn-danger" name="Delete">Delete</button>
</form>
}
</div>
</div>
</div>
<br style="clear:both;" />


4 changes: 2 additions & 2 deletions src/www.mtgdb.info/www.mtgdb.info/Views/Deck/MyDecks.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@section Top
{
<h1>My Decks <span class="label label-warning">In-Development</span></h1>
<h4>My Decks <span class="label label-warning">In-Development</span></h4>
}
<a href="/decks/viewer" class="btn btn-primary">Create Deck</a>
<div>
Expand All @@ -18,7 +18,7 @@
<b>@deck.Name</b>
<div>@deck.Description</div>
<div>Cards: @deck.Cards.Count</div>
<div>Side Bar: @deck.SideBar.Count</div>
<div>Side Board: @deck.SideBoard.Count</div>
</div>
</div>
</a>
Expand Down
5 changes: 2 additions & 3 deletions src/www.mtgdb.info/www.mtgdb.info/Views/Deck/_Cards.cshtml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<MtgDb.Info.Deck>
<div>
<h4>@Model.Name</h4>
<ul style="list-style-type: none;margin-left:0px;padding: 0">
@foreach(var card in @Model.GetCards())
{
<li>
@Model.CardCount(card.Id) <a href='@string.Format("https://www.mtgdb.info/cards/{0}", @card.Id)'>@card.Name</a>
</li>
}
@foreach(var card in @Model.GetSideBarCards())
@foreach(var card in @Model.GetSideBoardCards())
{
<li>
SB: @Model.SideBarCardCount(card.Id) <a href='@string.Format("https://www.mtgdb.info/cards/{0}", @card.Id)'>@card.Name</a>
SB: @Model.SideBoardCardCount(card.Id) <a href='@string.Format("https://www.mtgdb.info/cards/{0}", @card.Id)'>@card.Name</a>
</li>
}
</ul>
Expand Down
Loading

0 comments on commit 32506dc

Please sign in to comment.