Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #44 from haevg-rz/drap-and-drop
Browse files Browse the repository at this point in the history
Drap and drop
  • Loading branch information
dhcgn authored Apr 7, 2020
2 parents 42e4621 + aceb76f commit 371db4b
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 23 deletions.
20 changes: 20 additions & 0 deletions Planungsboard.Presentation/DesignData/DesignDataCard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Planungsboard.Presentation.ViewModels;

namespace Planungsboard.Presentation.DesignData
{
public class DesignDataCard : Card
{
public DesignDataCard()
{
var rnd = new Random();
var alpha = "qwertzuioplkjhgfdsayxcvbnm";
this.Effort = rnd.Next(1, 10) ^ 2;
this.Id = rnd.Next(10000, 99999).ToString();
this.Title = alpha.OrderBy(c => Guid.NewGuid()).Take(rnd.Next(3, 5)).Select(c => c.ToString()).Aggregate((s, s1) => s + s1).ToUpper();
}
}
}
10 changes: 10 additions & 0 deletions Planungsboard.Presentation/DesignData/DesignDataListCards.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Planungsboard.Presentation.DesignData
{
public class DesignDataListCards : List<ViewModels.Card>
{
}
}
34 changes: 33 additions & 1 deletion Planungsboard.Presentation/DesignData/ResourceDictionary.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewModels="clr-namespace:Planungsboard.Presentation.ViewModels">
xmlns:viewModels="clr-namespace:Planungsboard.Presentation.ViewModels"
xmlns:userControls="clr-namespace:Planungsboard.Presentation.UserControls"
xmlns:designData="clr-namespace:Planungsboard.Presentation.DesignData">

<viewModels:Card x:Key="DesignDataCard" Id="23422" Title="BER" Color="#003087" Effort="16" />

<userControls:CardsWarpPanel x:Key="DesignDataCardsWarpPanel">
<userControls:CardsWarpPanel.Quarter1Cards>
<designData:DesignDataListCards>
<designData:DesignDataCard />
<designData:DesignDataCard />
<designData:DesignDataCard />
</designData:DesignDataListCards>
</userControls:CardsWarpPanel.Quarter1Cards>
<userControls:CardsWarpPanel.Quarter2Cards>
<designData:DesignDataListCards>
<designData:DesignDataCard />
<designData:DesignDataCard />
<designData:DesignDataCard />
</designData:DesignDataListCards>
</userControls:CardsWarpPanel.Quarter2Cards>
<userControls:CardsWarpPanel.Quarter3Cards>
<designData:DesignDataListCards>
<designData:DesignDataCard />
<designData:DesignDataCard />
<designData:DesignDataCard />
</designData:DesignDataListCards>
</userControls:CardsWarpPanel.Quarter3Cards>
<userControls:CardsWarpPanel.Quarter4Cards>
<designData:DesignDataListCards>
<designData:DesignDataCard />
<designData:DesignDataCard />
<designData:DesignDataCard />
</designData:DesignDataListCards>
</userControls:CardsWarpPanel.Quarter4Cards>
</userControls:CardsWarpPanel>
</ResourceDictionary>
16 changes: 16 additions & 0 deletions Planungsboard.Presentation/Message/DropMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using Planungsboard.Presentation.ViewModels;

namespace Planungsboard.Presentation.Message
{
public class DropMessage
{
public Card Card { get; set; }
public ItemsControl DropTarget { get; set; }
public int DisplayQuarterIndex { get; set; }
public Team Team { get; set; }
}
}
6 changes: 4 additions & 2 deletions Planungsboard.Presentation/UserControls/Card.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Planungsboard.Presentation.UserControls"
mc:Ignorable="d"
d:DesignWidth="200"

d:DesignWidth="200">
MouseMove="Card_OnMouseMove"
>

<Border BorderBrush="{Binding Color}" BorderThickness="5,2,2,2" CornerRadius="2"
Background="White"
Expand Down
13 changes: 13 additions & 0 deletions Planungsboard.Presentation/UserControls/Card.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Planungsboard.Presentation.UserControls
{
Expand All @@ -21,5 +22,17 @@ public ViewModels.Card Item
get => (ViewModels.Card) this.GetValue(ItemProperty);
set => this.SetValue(ItemProperty, value);
}

private void Card_OnMouseMove(object sender, MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.LeftButton == MouseButtonState.Pressed)
{
DataObject data = new DataObject();
data.SetData("Object", this.Item);

DragDrop.DoDragDrop(this, data, DragDropEffects.Copy | DragDropEffects.Move);
}
}
}
}
29 changes: 18 additions & 11 deletions Planungsboard.Presentation/UserControls/CardsWarpPanel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Planungsboard.Presentation.UserControls"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:CardsWarpPanel}"
d:DesignHeight="450" d:DesignWidth="800">

d:DesignHeight="100" d:DesignWidth="800">
<UserControl.Resources>
<Style x:Key="ItemsControlStyle" TargetType="ItemsControl">
<Setter Property="ItemsPanel">
Expand All @@ -23,28 +23,35 @@
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="AllowDrop" Value="True" />
<Setter Property="Background" Value="Transparent" />
</Style>
</UserControl.Resources>
<Border>
<Grid DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
d:DataContext="{StaticResource DesignDataCardsWarpPanel}">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ItemsControl Grid.Column="0"
ItemsSource="{Binding Quarter1Cards, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
Style="{StaticResource ItemsControlStyle}" />
ItemsSource="{Binding Quarter1Cards}"
Style="{StaticResource ItemsControlStyle}"
Drop="Quarter1Cards_OnDrop"/>
<ItemsControl Grid.Column="1"
ItemsSource="{Binding Quarter2Cards, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
Style="{StaticResource ItemsControlStyle}" />
ItemsSource="{Binding Quarter2Cards}"
Style="{StaticResource ItemsControlStyle}"
Drop="Quarter2Cards_OnDrop"/>
<ItemsControl Grid.Column="2"
ItemsSource="{Binding Quarter3Cards, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
Style="{StaticResource ItemsControlStyle}" />
ItemsSource="{Binding Quarter3Cards}"
Style="{StaticResource ItemsControlStyle}"
Drop="Quarter3Cards_OnDrop"/>
<ItemsControl Grid.Column="3"
ItemsSource="{Binding Quarter4Cards, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
Style="{StaticResource ItemsControlStyle}" />
ItemsSource="{Binding Quarter4Cards}"
Style="{StaticResource ItemsControlStyle}"
Drop="Quarter4Cards_OnDrop"/>
</Grid>
</Border>
</UserControl>
54 changes: 54 additions & 0 deletions Planungsboard.Presentation/UserControls/CardsWarpPanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using GalaSoft.MvvmLight.Messaging;
using Planungsboard.Presentation.Message;
using Planungsboard.Presentation.ViewModels;

namespace Planungsboard.Presentation.UserControls
{
Expand Down Expand Up @@ -49,5 +52,56 @@ public List<ViewModels.Card> Quarter4Cards
get => (List<ViewModels.Card>) this.GetValue(Quarter4CardsProperty);
set => this.SetValue(Quarter4CardsProperty, value);
}

public static readonly DependencyProperty TeamProperty = DependencyProperty.Register(
"Team", typeof(Team), typeof(CardsWarpPanel), new PropertyMetadata(default(Team)));

public Team Team
{
get { return (Team) GetValue(TeamProperty); }
set { SetValue(TeamProperty, value); }
}

private void Quarter1Cards_OnDrop(object sender, DragEventArgs e)
{
var displayQuarterIndex = 0;

this.SendDropMessage(sender, e, displayQuarterIndex);
}

private void Quarter2Cards_OnDrop(object sender, DragEventArgs e)
{
var displayQuarterIndex = 1;

this.SendDropMessage(sender, e, displayQuarterIndex);
}

private void Quarter3Cards_OnDrop(object sender, DragEventArgs e)
{
var displayQuarterIndex = 2;

this.SendDropMessage(sender, e, displayQuarterIndex);
}

private void Quarter4Cards_OnDrop(object sender, DragEventArgs e)
{
var displayQuarterIndex = 3;

this.SendDropMessage(sender, e, displayQuarterIndex);
}

private void SendDropMessage(object sender, DragEventArgs e, int displayQuarterIndex)
{
var card = e.Data.GetData("Object") as ViewModels.Card;
var senderControl = sender as ItemsControl;

Messenger.Default.Send<DropMessage>(new DropMessage()
{
Card = card,
DropTarget = senderControl,
Team = this.Team,
DisplayQuarterIndex = displayQuarterIndex,
});
}
}
}
38 changes: 32 additions & 6 deletions Planungsboard.Presentation/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using Planungsboard.Presentation.Message;
using Planungsboard.Presentation.Views;

namespace Planungsboard.Presentation.ViewModels
Expand Down Expand Up @@ -59,7 +60,7 @@ public MainViewModel()
c.Title = alpha.OrderBy(c => Guid.NewGuid()).Take(rnd.Next(3, 5)).Select(c => c.ToString()).Aggregate((s, s1) => s + s1).ToUpper();
}

this.BacklogCards = backlogCards;
this.BacklogCards = new ObservableCollection<Card>(backlogCards);

var futureCards = Enumerable.Range(0, 21).Select(_ => new Card()).ToList();
foreach (var c in futureCards)
Expand All @@ -68,12 +69,35 @@ public MainViewModel()
c.Title = alpha.OrderBy(c => Guid.NewGuid()).Take(rnd.Next(3, 5)).Select(c => c.ToString()).Aggregate((s, s1) => s + s1).ToUpper();
}

this.FutureCards = futureCards;
this.FutureCards = new ObservableCollection<Card>(futureCards);

MessengerInstance.Register<DropMessage>(this,this.DropMessageHandling );
}

private void DropMessageHandling(DropMessage dropMessage)
{
if (dropMessage.Card.AssignedQuarter == null || !dropMessage.Card.AssignedQuarter.Any())
{
dropMessage.Card.AssignedQuarter = new List<string> {this.DisplayQuarters[dropMessage.DisplayQuarterIndex]};
}

dropMessage.Team.Cards.Add(dropMessage.Card);
dropMessage.Team.SetColor();

if (this.FutureCards.Contains(dropMessage.Card))
this.FutureCards.Remove(dropMessage.Card);

if (this.BacklogCards.Contains(dropMessage.Card))
this.BacklogCards.Remove(dropMessage.Card);

// TODO
this.Teams = new ObservableCollection<Team>(this.Teams);
base.RaisePropertyChanged(() => this.Teams);
}

public List<Card> FutureCards { get; set; }
public ObservableCollection<Card> FutureCards { get; set; }

public List<Card> BacklogCards { get; set; }
public ObservableCollection<Card> BacklogCards { get; set; }

private (int quarter, int year) ConvertFromQuater(string input)
{
Expand Down Expand Up @@ -204,7 +228,6 @@ public double TeamLabelWidth
public RelayCommand LoadedCommand { get; set; }
public RelayCommand QuarterNextCommand { get; set; }
public RelayCommand QuarterBackCommand { get; set; }

public RelayCommand NewTeamCommand { get; set; }

#endregion
Expand Down Expand Up @@ -296,7 +319,10 @@ public Team()

public void SetColor()
{
foreach (var card in this.Cards) card.Color = this.Color;
foreach (var card in this.Cards)
{
card.Color = this.Color;
}
}
}
}
3 changes: 2 additions & 1 deletion Planungsboard.Presentation/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
</userControls:CardsTimeLine.Cards>
</userControls:CardsTimeLine>

<userControls:CardsWarpPanel Grid.Column="1" Grid.Row="1" Margin="0,0,0,5">
<userControls:CardsWarpPanel Grid.Column="1" Grid.Row="1" Margin="0,0,0,5" Team="{Binding}">
<userControls:CardsWarpPanel.Quarter1Cards>
<MultiBinding Converter="{StaticResource CardsQuarterFilterForSingles}">
<Binding Path="Cards" />
Expand Down Expand Up @@ -186,6 +186,7 @@
<Setter Property="MaxWidth" Value="200" />
<Setter Property="Margin" Value="10" />
<Setter Property="Padding" Value="10" />
<Setter Property="AllowDrop" Value="True" />
</Style>
<Style x:Key="BacklogHeaderStyle" TargetType="TextBlock">
<Setter Property="Foreground" Value="White"></Setter>
Expand Down
4 changes: 2 additions & 2 deletions Planungsboard.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Planungsboard.Presentation"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Planungsboard.Presentation.Test", "Planungsboard.Presentation.Test\Planungsboard.Presentation.Test.csproj", "{A4B63583-9D4C-4794-974B-E14597BFFF71}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{15BE0D3D-D0AD-419D-888E-B36E5C7C3035}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CA44D2E3-421D-4EFE-8893-799B5079DB7F}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
Expand Down Expand Up @@ -51,6 +51,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FB1E1656-C1D1-4E6C-AA2A-6710A77EA8D2}
SolutionGuid = {04E9940F-3281-4E71-A54D-D2F7579D7517}
EndGlobalSection
EndGlobal

0 comments on commit 371db4b

Please sign in to comment.