Boards: Creation and accessing.
This commit is contained in:
128
VAR.Focus.Web/Code/BusinessLogic/Boards.cs
Normal file
128
VAR.Focus.Web/Code/BusinessLogic/Boards.cs
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using VAR.Focus.Web.Code.Entities;
|
||||||
|
|
||||||
|
namespace VAR.Focus.Web.Code.BusinessLogic
|
||||||
|
{
|
||||||
|
public class Boards
|
||||||
|
{
|
||||||
|
#region Declarations
|
||||||
|
|
||||||
|
private static Boards _currentInstance = null;
|
||||||
|
|
||||||
|
private List<Board> _boards = new List<Board>();
|
||||||
|
private int _lastIDBoard=0;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
public static Boards Current
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_currentInstance == null)
|
||||||
|
{
|
||||||
|
_currentInstance = new Boards();
|
||||||
|
}
|
||||||
|
return _currentInstance;
|
||||||
|
}
|
||||||
|
set { _currentInstance = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Life cycle
|
||||||
|
|
||||||
|
public Boards()
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public methods
|
||||||
|
|
||||||
|
public List<Board> Boards_GetListForUser(string userName)
|
||||||
|
{
|
||||||
|
// FIXME: filter by permissions
|
||||||
|
return _boards;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Board Board_GetByIDBoard(int idBoard)
|
||||||
|
{
|
||||||
|
foreach (Board board in _boards)
|
||||||
|
{
|
||||||
|
if (board.IDBoard == idBoard)
|
||||||
|
{
|
||||||
|
return board;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Board Boards_SetBoard(int idBoard, string title, string description, string userName)
|
||||||
|
{
|
||||||
|
DateTime currentDate = DateTime.UtcNow;
|
||||||
|
Board board;
|
||||||
|
if (idBoard == 0)
|
||||||
|
{
|
||||||
|
lock (this)
|
||||||
|
{
|
||||||
|
_lastIDBoard++;
|
||||||
|
board = new Board();
|
||||||
|
board.IDBoard = _lastIDBoard;
|
||||||
|
board.Active = true;
|
||||||
|
board.CreatedBy = userName;
|
||||||
|
board.CreatedDate = currentDate;
|
||||||
|
_boards.Add(board);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
board = Board_GetByIDBoard(idBoard);
|
||||||
|
}
|
||||||
|
|
||||||
|
board.Title = title;
|
||||||
|
board.Description = description;
|
||||||
|
board.ModifiedBy = userName;
|
||||||
|
board.ModifiedDate = currentDate;
|
||||||
|
|
||||||
|
SaveData();
|
||||||
|
|
||||||
|
return board;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private methods
|
||||||
|
|
||||||
|
#region Persistence
|
||||||
|
|
||||||
|
private const string BoardsPersistenceFile = "priv/boards.json";
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_boards = Persistence.LoadList<Board>(BoardsPersistenceFile);
|
||||||
|
_lastIDBoard = 0;
|
||||||
|
foreach (Board board in _boards)
|
||||||
|
{
|
||||||
|
if (board.IDBoard > _lastIDBoard)
|
||||||
|
{
|
||||||
|
_lastIDBoard = board.IDBoard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveData()
|
||||||
|
{
|
||||||
|
Persistence.SaveList(BoardsPersistenceFile, _boards);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
18
VAR.Focus.Web/Code/Entities/Board.cs
Normal file
18
VAR.Focus.Web/Code/Entities/Board.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace VAR.Focus.Web.Code.Entities
|
||||||
|
{
|
||||||
|
public class Board
|
||||||
|
{
|
||||||
|
public int IDBoard { get; set; }
|
||||||
|
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
public bool Active { get; set; }
|
||||||
|
public string CreatedBy { get; set; }
|
||||||
|
public DateTime CreatedDate { get; set; }
|
||||||
|
public string ModifiedBy { get; set; }
|
||||||
|
public DateTime ModifiedDate { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,22 @@ namespace VAR.Focus.Web.Pages
|
|||||||
{
|
{
|
||||||
public class FormUtils
|
public class FormUtils
|
||||||
{
|
{
|
||||||
|
public static Control CreatePanel(Control ctrl, string cssClass)
|
||||||
|
{
|
||||||
|
Panel pnl = new Panel();
|
||||||
|
pnl.Controls.Add(ctrl);
|
||||||
|
if (string.IsNullOrEmpty(cssClass) == false)
|
||||||
|
{
|
||||||
|
pnl.CssClass = cssClass;
|
||||||
|
}
|
||||||
|
return pnl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Control CreatePanel(Control ctrl)
|
||||||
|
{
|
||||||
|
return CreatePanel(ctrl, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static Control CreateField(string label, Control fieldControl)
|
public static Control CreateField(string label, Control fieldControl)
|
||||||
{
|
{
|
||||||
Panel pnlRow = new Panel();
|
Panel pnlRow = new Panel();
|
||||||
|
|||||||
@@ -1,12 +1,26 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.UI.WebControls;
|
||||||
|
using VAR.Focus.Web.Code.BusinessLogic;
|
||||||
|
using VAR.Focus.Web.Code.Entities;
|
||||||
using VAR.Focus.Web.Controls;
|
using VAR.Focus.Web.Controls;
|
||||||
|
|
||||||
namespace VAR.Focus.Web.Pages
|
namespace VAR.Focus.Web.Pages
|
||||||
{
|
{
|
||||||
public class FrmBoard : PageCommon
|
public class FrmBoard : PageCommon
|
||||||
{
|
{
|
||||||
|
#region Declarations
|
||||||
|
|
||||||
private int _idBoard = 0;
|
private int _idBoard = 0;
|
||||||
|
|
||||||
|
private CTextBox _txtTitle = new CTextBox { ID = "txtTitle", CssClassExtra="width100pc" };
|
||||||
|
private CTextBox _txtDescription = new CTextBox { ID = "txtDescription", CssClassExtra = "width100pc" };
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Life cycle
|
||||||
|
|
||||||
public FrmBoard()
|
public FrmBoard()
|
||||||
{
|
{
|
||||||
Init += FrmBoard_Init;
|
Init += FrmBoard_Init;
|
||||||
@@ -14,19 +28,112 @@ namespace VAR.Focus.Web.Pages
|
|||||||
|
|
||||||
void FrmBoard_Init(object sender, EventArgs e)
|
void FrmBoard_Init(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Title = "Board";
|
|
||||||
|
string strIDBoard = GetRequestParm(Context, "idBoard");
|
||||||
|
if (String.IsNullOrEmpty(strIDBoard) == false)
|
||||||
|
{
|
||||||
|
_idBoard = Convert.ToInt32(strIDBoard);
|
||||||
|
}
|
||||||
|
if (_idBoard == 0)
|
||||||
|
{
|
||||||
|
FrmBoard_InitIndex();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FrmBoard_InitBoard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region UI Events
|
||||||
|
|
||||||
|
void btnAddBoard_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Board board = Boards.Current.Boards_SetBoard(0, _txtTitle.Text, _txtDescription.Text, CurrentUser.Name);
|
||||||
|
_idBoard = board.IDBoard;
|
||||||
|
|
||||||
|
Response.Redirect(string.Format("{0}?idBoard={1}", "FrmBoard", _idBoard));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private methods
|
||||||
|
|
||||||
|
private void FrmBoard_InitIndex()
|
||||||
|
{
|
||||||
|
Title = "Boards";
|
||||||
|
|
||||||
|
List<Board> boards = Boards.Current.Boards_GetListForUser(CurrentUser.Name);
|
||||||
|
|
||||||
|
foreach (Board board in boards)
|
||||||
|
{
|
||||||
|
var pnlBoardSelector = new Panel { CssClass = "boardBanner" };
|
||||||
|
var lnkTitle = new HyperLink
|
||||||
|
{
|
||||||
|
NavigateUrl = string.Format("{0}?idBoard={1}", "FrmBoard", board.IDBoard),
|
||||||
|
};
|
||||||
|
var lblTitle = new CLabel
|
||||||
|
{
|
||||||
|
Text = board.Title,
|
||||||
|
CssClass = "title",
|
||||||
|
};
|
||||||
|
lnkTitle.Controls.Add(lblTitle);
|
||||||
|
var pnlDescription = new Panel();
|
||||||
|
var lblDescription = new CLabel
|
||||||
|
{
|
||||||
|
Text = board.Description,
|
||||||
|
CssClass = "description",
|
||||||
|
};
|
||||||
|
pnlDescription.Controls.Add(lblDescription);
|
||||||
|
pnlBoardSelector.Controls.Add(lnkTitle);
|
||||||
|
pnlBoardSelector.Controls.Add(pnlDescription);
|
||||||
|
Controls.Add(pnlBoardSelector);
|
||||||
|
}
|
||||||
|
|
||||||
|
var pnlBoardAdd = new Panel { CssClass = "boardBanner" };
|
||||||
|
var btnAddBoard = new CButton { ID = "btnAddBoard", Text = "AddBoard" };
|
||||||
|
btnAddBoard.Click += btnAddBoard_Click;
|
||||||
|
pnlBoardAdd.Controls.Add(FormUtils.CreatePanel(_txtTitle, "formRow"));
|
||||||
|
_txtTitle.PlaceHolder = "Title";
|
||||||
|
pnlBoardAdd.Controls.Add(FormUtils.CreatePanel(_txtDescription, "formRow"));
|
||||||
|
_txtDescription.PlaceHolder = "Description";
|
||||||
|
pnlBoardAdd.Controls.Add(FormUtils.CreatePanel(btnAddBoard, "formRow"));
|
||||||
|
Controls.Add(pnlBoardAdd);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FrmBoard_InitBoard()
|
||||||
|
{
|
||||||
|
Board board = Boards.Current.Board_GetByIDBoard(_idBoard);
|
||||||
|
|
||||||
|
Title = board.Title;
|
||||||
|
|
||||||
CardBoardControl cardBoardControl = new CardBoardControl();
|
CardBoardControl cardBoardControl = new CardBoardControl();
|
||||||
cardBoardControl.ID = "ctrCardBoard";
|
cardBoardControl.ID = "ctrCardBoard";
|
||||||
cardBoardControl.IDBoard = _idBoard;
|
cardBoardControl.IDBoard = board.IDBoard;
|
||||||
cardBoardControl.UserName = CurrentUser.Name;
|
cardBoardControl.UserName = CurrentUser.Name;
|
||||||
Controls.Add(cardBoardControl);
|
Controls.Add(cardBoardControl);
|
||||||
|
|
||||||
ChatControl chatControl = new ChatControl();
|
ChatControl chatControl = new ChatControl();
|
||||||
chatControl.ID = "ctrChat";
|
chatControl.ID = "ctrChat";
|
||||||
chatControl.IDBoard = _idBoard;
|
chatControl.IDBoard = board.IDBoard;
|
||||||
chatControl.UserName = CurrentUser.Name;
|
chatControl.UserName = CurrentUser.Name;
|
||||||
Controls.Add(chatControl);
|
Controls.Add(chatControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetRequestParm(HttpContext context, string parm)
|
||||||
|
{
|
||||||
|
foreach (string key in context.Request.Params.AllKeys)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(key) == false && key.EndsWith(parm))
|
||||||
|
{
|
||||||
|
return context.Request.Params[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
VAR.Focus.Web/Styles/02. Boards.css
Normal file
34
VAR.Focus.Web/Styles/02. Boards.css
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
.boardBanner {
|
||||||
|
border: solid 1px rgb(32, 32, 32);
|
||||||
|
border-radius: 5px;
|
||||||
|
display: inline-block;
|
||||||
|
width: 300px;
|
||||||
|
margin: 15px;
|
||||||
|
padding: 10px;
|
||||||
|
vertical-align: top;
|
||||||
|
background-color: rgb(250,250,200);
|
||||||
|
}
|
||||||
|
|
||||||
|
.boardBanner a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.boardBanner .title {
|
||||||
|
font-size: 20px;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.boardBanner .description {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.boardBanner .formRow {
|
||||||
|
margin: 0;
|
||||||
|
margin-top: 10px;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.boardBanner .formRow:first-child {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
@@ -62,17 +62,20 @@
|
|||||||
<Content Include="Scripts\05. Cards.js" />
|
<Content Include="Scripts\05. Cards.js" />
|
||||||
<Content Include="Scripts\10. Chat.js" />
|
<Content Include="Scripts\10. Chat.js" />
|
||||||
<Content Include="Styles\01. base.css" />
|
<Content Include="Styles\01. base.css" />
|
||||||
|
<Content Include="Styles\02. Boards.css" />
|
||||||
<Content Include="Styles\05. Cards.css" />
|
<Content Include="Styles\05. Cards.css" />
|
||||||
<Content Include="Styles\10. Chat.css" />
|
<Content Include="Styles\10. Chat.css" />
|
||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Code\Bundler.cs" />
|
<Compile Include="Code\Bundler.cs" />
|
||||||
|
<Compile Include="Code\BusinessLogic\Boards.cs" />
|
||||||
<Compile Include="Code\BusinessLogic\CardBoard.cs" />
|
<Compile Include="Code\BusinessLogic\CardBoard.cs" />
|
||||||
<Compile Include="Code\BusinessLogic\MessageBoard.cs" />
|
<Compile Include="Code\BusinessLogic\MessageBoard.cs" />
|
||||||
<Compile Include="Code\BusinessLogic\Persistence.cs" />
|
<Compile Include="Code\BusinessLogic\Persistence.cs" />
|
||||||
<Compile Include="Code\BusinessLogic\Sessions.cs" />
|
<Compile Include="Code\BusinessLogic\Sessions.cs" />
|
||||||
<Compile Include="Code\BusinessLogic\Users.cs" />
|
<Compile Include="Code\BusinessLogic\Users.cs" />
|
||||||
|
<Compile Include="Code\Entities\Board.cs" />
|
||||||
<Compile Include="Code\Entities\Card.cs" />
|
<Compile Include="Code\Entities\Card.cs" />
|
||||||
<Compile Include="Code\Entities\CardEvents.cs" />
|
<Compile Include="Code\Entities\CardEvents.cs" />
|
||||||
<Compile Include="Controls\CardBoardControl.cs" />
|
<Compile Include="Controls\CardBoardControl.cs" />
|
||||||
@@ -115,7 +118,6 @@
|
|||||||
<Compile Include="Globals.cs" />
|
<Compile Include="Globals.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
|||||||
Reference in New Issue
Block a user