Skip to content

Commit c97c924

Browse files
authored
Create viewed slider (#7959)
* username and address passed to handler, form submission next * Viewed button added and functioning properly * Attempt to include missing files from previous push * Fixed casing on cookie naming and updated ViewedBy property name
1 parent 8b22f9d commit c97c924

4 files changed

Lines changed: 64 additions & 5 deletions

File tree

src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,18 @@ $(() => {
193193
$("#reviewSubscribeSwitch").on('change', function () {
194194
$("#reviewSubscribeForm").submit();
195195
});
196+
// Toggle Viewed Switch
197+
$("#reviewViewedSwitch").on('change', function () {
198+
$("#reviewViewedForm").submit();
199+
});
196200
// Toggle Close Switch
197201
$("#reviewCloseSwitch").on('change', function () {
198202
$("#reviewCloseForm").submit();
199203
});
200204

201205
// Manage Expand / Collapse State of options
202206
[$("#approveCollapse"), $("#requestReviewersCollapse"), $("#reviewOptionsCollapse"), $("#pageSettingsCollapse"),
203-
$("#associatedPRCollapse"), $("#associatedReviewsCollapse"), $("#generateAIReviewCollapse")].forEach(function (value, index) {
207+
$("#associatedPRCollapse"), $("#associatedReviewsCollapse"), $("#generateAIReviewCollapse"), $("#apiRevisionOptionsCollapse")].forEach(function (value, index) {
204208
const id = value.attr("id");
205209
value.on('hidden.bs.collapse', function () {
206210
document.cookie = `${id}=hidden; max-age=${7 * 24 * 60 * 60}`;

src/dotnet/APIView/APIViewWeb/LeanModels/ReviewListModels.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public class APIRevisionListItemModel : BaseListitemModel
128128
public bool IsDeleted { get; set; }
129129
public bool IsReleased { get; set; }
130130
public DateTime ReleasedOn { get; set; }
131+
public HashSet<string> ViewedBy { get; set; } = new HashSet<string>();
131132
}
132133

133134
public class SamplesRevisionModel

src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
}
332332
}
333333
<p class="h6">
334-
<a data-bs-toggle="collapse" href="#reviewOptionsCollapse" aria-expanded="true" aria-controls="approvalCollapse">Review Options&nbsp;&nbsp;<i class="fa-solid fa-ellipsis"></i></a>
334+
<a data-bs-toggle="collapse" href="#reviewOptionsCollapse" aria-expanded="true" aria-controls="reviewOptionsCollapse">Review Options&nbsp;&nbsp;<i class="fa-solid fa-ellipsis"></i></a>
335335
</p>
336336
@{
337337
var reviewOptionsCollapseState = " show";
@@ -366,7 +366,7 @@
366366
</li>
367367
</ul>
368368
<p class="h6">
369-
<a data-bs-toggle="collapse" href="#pageSettingsCollapse" aria-expanded="true" aria-controls="approvalCollapse">Page Settings&nbsp;&nbsp;<i class="fa-solid fa-ellipsis"></i></a>
369+
<a data-bs-toggle="collapse" href="#pageSettingsCollapse" aria-expanded="true" aria-controls="pageSettingsCollapse">Page Settings&nbsp;&nbsp;<i class="fa-solid fa-ellipsis"></i></a>
370370
</p>
371371
@{
372372
var pageSettingsCollapseState = String.Empty;
@@ -475,7 +475,37 @@
475475
</div>
476476
</li>
477477
}
478-
</ul>
478+
</ul>
479+
<p class="h6">
480+
<a data-bs-toggle="collapse" href="#apiRevisionOptionsCollapse" aria-expanded="true" aria-controls="apiRevisionOptionsCollapse">API Revision Options&nbsp;&nbsp;<i class="fa-solid fa-ellipsis"></i></a>
481+
</p>
482+
@{
483+
var apiRevisionOptionsCollapseState = " show";
484+
if (Request.Cookies.ContainsKey("apiRevisionOptionsCollapse"))
485+
{
486+
if (!Request.Cookies["apiRevisionOptionsCollapse"].Equals("shown"))
487+
apiRevisionOptionsCollapseState = String.Empty;
488+
}
489+
}
490+
<ul class="list-group collapse mb-3@(apiRevisionOptionsCollapseState)" id="apiRevisionOptionsCollapse">
491+
<li class="list-group-item">
492+
<div class="form-check form-switch">
493+
<form asp-resource="@Model.ReviewContent.ActiveAPIRevision" class="form-inline" id="reviewViewedForm" method="post" asp-page-handler="ToggleViewed">
494+
<input type="hidden" name="revisionId" value="@Model.ReviewContent.ActiveAPIRevision.Id" />
495+
@if (Model.ReviewContent.ActiveAPIRevision.ViewedBy.Contains(User.GetGitHubLogin()))
496+
{
497+
<input class="form-check-input" checked type="checkbox" role="switch" id="reviewViewedSwitch">
498+
}
499+
else
500+
{
501+
<input class="form-check-input" type="checkbox" role="switch" id="reviewViewedSwitch">
502+
}
503+
504+
<label class="form-check-label" for="reviewViewedSwitch">Mark as Viewed</label>
505+
</form>
506+
</div>
507+
</li>
508+
</ul>
479509
</div>
480510
</div>
481511

src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,30 @@ public async Task<ActionResult> OnPostToggleSubscribedAsync(string id)
212212
return RedirectToPage(new { id = id });
213213
}
214214

215+
/// <summary>
216+
/// Mark a Review as Viewed
217+
/// </summary>
218+
/// <param name="id"></param>
219+
/// <param name="revisionId"></param>
220+
/// <returns></returns>
221+
public async Task<ActionResult> OnPostToggleViewedAsync(string id, string revisionId)
222+
{
223+
string userName = User.GetGitHubLogin();
224+
var revision = await _apiRevisionsManager.GetAPIRevisionAsync(revisionId);
225+
226+
if (revision.ViewedBy.Contains(userName))
227+
{
228+
revision.ViewedBy.Remove(userName);
229+
}
230+
else
231+
{
232+
revision.ViewedBy.Add(userName);
233+
}
234+
235+
await _apiRevisionsManager.UpdateAPIRevisionAsync(revision);
236+
return RedirectToPage(new { id = id, revisionId = revisionId });
237+
}
238+
215239
/// <summary>
216240
/// Approve or Revert Approval for a Review
217241
/// </summary>
@@ -274,7 +298,6 @@ public async Task<IActionResult> OnPostUploadAsync(string id, [FromForm] IFormFi
274298
return RedirectToPage(new { id = id, revisionId = apiRevision.Id });
275299
}
276300

277-
278301
/// <summary>
279302
/// Get Routing Data for a Review
280303
/// </summary>
@@ -292,6 +315,7 @@ public Dictionary<string, string> GetRoutingData(string diffRevisionId = null, b
292315
routingData["diffOnly"] = (showDiffOnly ?? false).ToString();
293316
return routingData;
294317
}
318+
295319
/// <summary>
296320
/// Get Pull Requests for a Review
297321
/// </summary>

0 commit comments

Comments
 (0)