Skip to content

Commit 705ef51

Browse files
devsgaragecsharpfritz
authored andcommitted
Make Rundown Items and Title editable in Admin portal (#254)
* Made rundown title editable * Added ability to update checkbox titles and switch for editing * Add ability to add new items to the list on the admin screen when in edit mode. * Fix styling issue when dynamically adding new LI nodes. It was due to whitepsace issue with inline-block. Switched from pure JS to using jQuery * Removed commented out code * Add ability to delete items from the list * Refactored Rundown API and repositories * Update styling on title input * Added main div around elements in body. Added spacing between list items. * Styled the add button * Added delete glyphicon on newly added items * Made edit button more stylish and made add button color complement
1 parent d10914d commit 705ef51

File tree

11 files changed

+467
-115
lines changed

11 files changed

+467
-115
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Fritz.StreamTools.Interfaces;
6+
using Fritz.StreamTools.Models;
7+
using Fritz.StreamTools.Services;
8+
using Microsoft.AspNetCore.Http;
9+
using Microsoft.AspNetCore.Mvc;
10+
11+
namespace Fritz.StreamTools.Controllers
12+
{
13+
[Produces("application/json")]
14+
[Route("api/rundown")]
15+
public class RundownController : Controller
16+
{
17+
18+
private IRundownService rundownService;
19+
20+
public RundownController(IRundownService rundownService)
21+
{
22+
this.rundownService = rundownService;
23+
}
24+
25+
[HttpGet("title")]
26+
public IActionResult Get()
27+
{
28+
return Ok(rundownService.GetRundownTitle());
29+
}
30+
31+
// PUT: api/Rundown/Title/
32+
[HttpPut("title")]
33+
public IActionResult Put([FromBody]string value)
34+
{
35+
rundownService.UpdateTitle(value);
36+
return Ok(value);
37+
}
38+
}
39+
}

Fritz.StreamTools/Controllers/RundownItemController.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using System.Linq;
44
using System.Net;
55
using System.Threading.Tasks;
6+
using Fritz.StreamTools.Interfaces;
67
using Fritz.StreamTools.Models;
8+
using Fritz.StreamTools.Services;
79
using Microsoft.AspNetCore.Http;
810
using Microsoft.AspNetCore.Mvc;
911

@@ -13,49 +15,53 @@ namespace Fritz.StreamTools.Controllers
1315
[Route("api/items")]
1416
public class RundownItemController : Controller
1517
{
16-
public RundownRepository Repository { get; private set; }
1718

18-
public RundownItemController(RundownRepository repo)
19+
private IRundownService rundownService;
20+
21+
public RundownItemController(IRundownService rundownService)
1922
{
20-
this.Repository = repo;
23+
this.rundownService = rundownService;
2124
}
2225

23-
// GET: api/RundownItem
26+
// GET: api/items
2427
[HttpGet]
2528
public IActionResult Get()
2629
{
27-
return Ok(Repository.Get());
30+
return Ok(rundownService.GetAllItems());
2831
}
2932

30-
// GET: api/RundownItem/5
33+
// GET: api/items/5
3134
[HttpGet("{id}", Name = "Get")]
3235
public IActionResult Get(int id)
3336
{
34-
var outValue = Repository.Get().FirstOrDefault(i => i.ID == id);
37+
var outValue = rundownService.GetItem(id);
3538
if (outValue == null) return NotFound();
3639
return Ok(outValue);
3740
}
3841

39-
// POST: api/RundownItem
42+
// POST: api/items
4043
[HttpPost]
41-
public void Post([FromBody]RundownItem value)
44+
public IActionResult Post()
4245
{
46+
var newItem = rundownService.AddNewRundownItem();
47+
return Ok(newItem);
4348
}
4449

45-
// PUT: api/RundownItem/5
50+
// PUT: api/items/5
4651
[HttpPut("{id}")]
4752
public IActionResult Put(int id, [FromBody]RundownItem value)
4853
{
49-
Repository.Update(id, value);
54+
rundownService.UpdateRundownItem(id, value);
55+
5056
return Ok(value);
5157
}
5258

53-
// DELETE: api/ApiWithActions/5
59+
// DELETE: api/items/5
5460
[HttpDelete("{id}")]
5561
public IActionResult Delete(int id)
5662
{
57-
Repository.Delete(id);
63+
rundownService.DeleteRundownItem(id);
5864
return NoContent();
5965
}
6066
}
61-
}
67+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Fritz.StreamTools.Models;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
namespace Fritz.StreamTools.Interfaces
8+
{
9+
public interface IRundownService
10+
{
11+
string GetRundownTitle();
12+
void UpdateTitle(string title);
13+
RundownItem AddNewRundownItem();
14+
void UpdateRundownItem(int id, RundownItem item);
15+
void DeleteRundownItem(int idToDelete);
16+
List<RundownItem> GetAllItems();
17+
RundownItem GetItem(int id);
18+
}
19+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace Fritz.StreamTools.Models
5+
{
6+
public class RundownItemRepository
7+
{
8+
9+
private static readonly List<RundownItem> _Items = new List<RundownItem>()
10+
{
11+
new RundownItem {ID=10, Text="PRE-SHOW: Set stream titles"},
12+
new RundownItem {ID=20, Text="PRE-SHOW: Send 'Stream starting soon' tweet"},
13+
new RundownItem {ID=30, Text="PRE-SHOW: Set background to 'Starting shortly' and start music"},
14+
new RundownItem {ID=40, Text="Start Stream!"},
15+
new RundownItem {ID=50, Text="Introduction"},
16+
new RundownItem {ID=60, Text="Music to Code By"},
17+
new RundownItem {ID=70, Text="Today's Hat"},
18+
new RundownItem {ID=80, Text="Housekeeping"},
19+
new RundownItem {ID=90, Text="Follower Goals"},
20+
new RundownItem {ID=110, Text="Pull Requests"},
21+
new RundownItem {ID=120, Text="New Code!"},
22+
new RundownItem {ID=130, Text="Log issue with last update"},
23+
new RundownItem {ID=140, Text="Commit and push source code"},
24+
new RundownItem {ID=150, Text="Next stream..."}
25+
};
26+
27+
public IEnumerable<RundownItem> Get()
28+
{
29+
30+
return _Items.OrderBy(i => i.ID);
31+
32+
}
33+
34+
public void Add(RundownItem item)
35+
{
36+
_Items.Add(item);
37+
}
38+
39+
public void Update(int id, RundownItem item)
40+
{
41+
Delete(id);
42+
_Items.Add(item);
43+
}
44+
45+
public void Delete(int id)
46+
{
47+
48+
_Items.Remove(_Items.FirstOrDefault(i => i.ID == id));
49+
50+
}
51+
}
52+
}
Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,23 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
4+
using System.Threading.Tasks;
35

46
namespace Fritz.StreamTools.Models
57
{
6-
public class RundownRepository
7-
{
8+
public class RundownRepository
9+
{
10+
private static string _Title = "Rundown Title";
811

9-
private static readonly List<RundownItem> _Items = new List<RundownItem>()
12+
public void UpdateTitle(string title)
1013
{
11-
new RundownItem {ID=10, Text="PRE-SHOW: Set stream titles"},
12-
new RundownItem {ID=20, Text="PRE-SHOW: Send 'Stream starting soon' tweet"},
13-
new RundownItem {ID=30, Text="PRE-SHOW: Set background to 'Starting shortly' and start music"},
14-
new RundownItem {ID=40, Text="Start Stream!"},
15-
new RundownItem {ID=50, Text="Introduction"},
16-
new RundownItem {ID=60, Text="Music to Code By"},
17-
new RundownItem {ID=70, Text="Today's Hat"},
18-
new RundownItem {ID=80, Text="Housekeeping"},
19-
new RundownItem {ID=90, Text="Follower Goals"},
20-
new RundownItem {ID=110, Text="Pull Requests"},
21-
new RundownItem {ID=120, Text="New Code!"},
22-
new RundownItem {ID=130, Text="Log issue with last update"},
23-
new RundownItem {ID=140, Text="Commit and push source code"},
24-
new RundownItem {ID=150, Text="Next stream..."}
25-
};
26-
27-
public IEnumerable<RundownItem> Get()
28-
{
29-
30-
return _Items.OrderBy(i => i.ID);
31-
32-
}
33-
34-
public void Add(RundownItem item)
35-
{
36-
_Items.Add(item);
37-
}
38-
39-
public void Update(int id, RundownItem item)
40-
{
41-
Delete(id);
42-
_Items.Add(item);
14+
_Title = title;
4315
}
4416

45-
public void Delete(int id)
17+
public string GetTitle()
4618
{
47-
48-
_Items.Remove(_Items.FirstOrDefault(i => i.ID == id));
49-
19+
return _Title;
5020
}
5121

52-
}
53-
}
22+
}
23+
}

0 commit comments

Comments
 (0)