Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dark theme for APIView #3747

Merged
merged 6 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
330 changes: 299 additions & 31 deletions src/dotnet/APIView/APIViewWeb/Client/css/site.scss

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/dotnet/APIView/APIViewWeb/Client/src/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@
if (commentRows.length != 1)
{
if (index == 0) {
commentNavigationButtons.append(`<a class="btn btn btn-outline-secondary" href="#${nextCommentThreadAnchor}" title="Next Comment"><i class="fa fa-chevron-down" aria-hidden="true"></i></a>`)
commentNavigationButtons.append(`<a class="btn btn-outline-dark" href="#${nextCommentThreadAnchor}" title="Next Comment"><i class="fa fa-chevron-down" aria-hidden="true"></i></a>`)
}
else if (index == commentRows.length - 1) {
commentNavigationButtons.append(`<a class="btn btn btn-outline-secondary" href="#${previousCommentThreadAnchor}" title="Previous Comment"><i class="fa fa-chevron-up" aria-hidden="true"></i></a>`)
commentNavigationButtons.append(`<a class="btn btn-outline-dark" href="#${previousCommentThreadAnchor}" title="Previous Comment"><i class="fa fa-chevron-up" aria-hidden="true"></i></a>`)
}
else {
commentNavigationButtons.append(`<a class="btn btn btn-outline-secondary" href="#${previousCommentThreadAnchor}" title="Previous Comment"><i class="fa fa-chevron-up" aria-hidden="true"></i></a>`)
commentNavigationButtons.append(`<a class="btn btn btn-outline-secondary ml-1" href="#${nextCommentThreadAnchor}" title="Next Comment"><i class="fa fa-chevron-down" aria-hidden="true"></i></a>`)
commentNavigationButtons.append(`<a class="btn btn-outline-dark" href="#${previousCommentThreadAnchor}" title="Previous Comment"><i class="fa fa-chevron-up" aria-hidden="true"></i></a>`)
commentNavigationButtons.append(`<a class="btn btn-outline-dark ml-1" href="#${nextCommentThreadAnchor}" title="Next Comment"><i class="fa fa-chevron-down" aria-hidden="true"></i></a>`)
}
}
});
Expand Down
12 changes: 12 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Client/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Updated Page Setting by Updating UserPreference
export function updatePageSettings(callBack) {
var hideLineNumbers = $("#hide-line-numbers").prop("checked");
var hideLeftNavigation = $("#hide-left-navigation").prop("checked");
var selectedTheme = $("#theme-selector").children(":selected").val() as string;
var uri = location.origin + `/account/updatesettings?hideLineNumbers=${hideLineNumbers}&hideLeftNavigation=${hideLeftNavigation}&theme=${selectedTheme}`;

$.ajax({
type: "PUT",
url: uri
}).done(callBack());
}
30 changes: 29 additions & 1 deletion src/dotnet/APIView/APIViewWeb/Client/src/navbar.ts
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@

import Split from "split.js";
import { updatePageSettings } from "./helpers";

addEventListener("load", () => {
$(".nav-list-toggle").click(function () {
$(this).parents(".nav-list-group").first().toggleClass("nav-list-collapsed");
});
});

$(() => {
const themeSelector = $( '#theme-selector' );

// Add EventListener for Changing CSS Theme
themeSelector.on('change', function() {
updatePageSettings(function(){
var allThemes = themeSelector.children();
var newTheme = themeSelector.children(":selected").val() as string;
var themesToRemove = allThemes.filter(function(){
return ($(this).val() as string) != newTheme;
});
var body = $('body');

themesToRemove.each(function(){
body.removeClass(($(this).val() as string));
})
body.addClass(newTheme);
});
});
});
19 changes: 3 additions & 16 deletions src/dotnet/APIView/APIViewWeb/Client/src/review.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Split from "split.js";
import { updatePageSettings } from "./helpers";

$(() => {
const SEL_DOC_CLASS = ".documentation";
Expand All @@ -7,8 +8,6 @@ $(() => {
const SHOW_DOC_HREF = ".show-document";
const SHOW_DIFFONLY_CHECKBOX = ".show-diffonly-checkbox";
const SHOW_DIFFONLY_HREF = ".show-diffonly";
const HIDE_LINE_NUMBERS = "#hide-line-numbers";
const HIDE_LEFT_NAVIGATION = "#hide-left-navigation";

hideCheckboxIfNoDocs();

Expand Down Expand Up @@ -43,18 +42,6 @@ $(() => {
}
}

// Updated Page Setting by Updating UserPreference
function updatePageSettings(callBack) {
var hideLineNumbers = $(HIDE_LINE_NUMBERS).prop("checked");
var hideLeftNavigation = $(HIDE_LEFT_NAVIGATION).prop("checked");
var uri = `?handler=updatepagesettings&hideLineNumbers=${hideLineNumbers}&hideLeftNavigation=${hideLeftNavigation}`;

$.ajax({
type: "GET",
url: uri
}).done(callBack());
}

/* ADD EVENT LISTENER FOR TOGGLING LEFT NAVIGATION
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
addEventListener("load", () => {
Expand Down Expand Up @@ -83,13 +70,13 @@ $(() => {
$(SHOW_DIFFONLY_HREF)[0].click();
});

$(HIDE_LINE_NUMBERS).on("click", e => {
$("#hide-line-numbers").on("click", e => {
updatePageSettings(function(){
$(".line-number").toggleClass("d-none");
});
});

$(HIDE_LEFT_NAVIGATION).on("click", e => {
$("#hide-left-navigation").on("click", e => {
updatePageSettings(function(){
var leftContainer = $("#review-left");
var rightContainer = $("#review-right");
Expand Down
23 changes: 23 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using APIViewWeb.Repositories;
using APIViewWeb.Models;


namespace APIViewWeb.Controllers
{
[AllowAnonymous]
public class AccountController : Controller
{
private readonly UserPreferenceCache _preferenceCache;
public AccountController(UserPreferenceCache preferenceCache)
{
_preferenceCache = preferenceCache;
}

[HttpGet]
public async Task<IActionResult> Login(string returnUrl = "/")
{
Expand All @@ -25,5 +34,19 @@ public async Task<IActionResult> Logout()
await HttpContext.SignOutAsync();
return RedirectToPage("/Login");
}

[HttpPut]
[Authorize("RequireOrganization")]
public ActionResult UpdateSettings(bool? hideLineNumbers = null, bool? hideLeftNavigation = null, string theme = "light-theme")
{
_preferenceCache.UpdateUserPreference(new UserPreferenceModel()
{
UserName = User.GetGitHubLogin(),
HideLeftNavigation = hideLeftNavigation,
HideLineNumbers = hideLineNumbers,
Theme = theme
});
return Ok();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public AutoMapperProfiles()
.ForMember(dest => dest.State, opt => opt.MapFrom((src, dest) => src.State != null ? src.State : dest.State))
.ForMember(dest => dest.Status, opt => opt.MapFrom((src, dest) => src.Status != null ? src.Status : dest.Status))
.ForMember(dest => dest.HideLineNumbers, opt => opt.MapFrom((src, dest) => src.HideLineNumbers != null ? src.HideLineNumbers : dest.HideLineNumbers))
.ForMember(dest => dest.HideLeftNavigation, opt => opt.MapFrom((src, dest) => src.HideLeftNavigation != null ? src.HideLeftNavigation : dest.HideLeftNavigation));
.ForMember(dest => dest.HideLeftNavigation, opt => opt.MapFrom((src, dest) => src.HideLeftNavigation != null ? src.HideLeftNavigation : dest.HideLeftNavigation))
.ForMember(dest => dest.Theme, opt => opt.MapFrom((src, dest) => src.Theme != null ? src.Theme : dest.Theme));
}
}
}
13 changes: 13 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Helpers/PageModelHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using APIViewWeb.Models;
using APIViewWeb.Repositories;

namespace APIViewWeb.Helpers
{
public static class PageModelHelpers
{
public static UserPreferenceModel GetUserPreference(UserPreferenceCache preferenceCache, string userName)
{
return preferenceCache.GetUserPreferences(userName);
}
}
}
2 changes: 2 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Models/UserPreferenceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public class UserPreferenceModel
public bool? HideLineNumbers { get; set; }
[Name("HideLeftNavigation")]
public bool? HideLeftNavigation { get; set; }
[Name("Theme")]
public string Theme { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@page "{id?}"
@model APIViewWeb.Pages.Assemblies.ConversationModel
@using APIViewWeb.Helpers
@using APIViewWeb.Models
@{
Layout = "ReviewLayout";
ViewData["Title"] = "Conversation";
ViewData["UserPreference"] = PageModelHelpers.GetUserPreference(Model._preferenceCache, User.GetGitHubLogin()) ?? new UserPreferenceModel();
}
<div class="container-fluid">
<div class="mx-5 mt-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ConversationModel : PageModel
private readonly ReviewManager _reviewManager;
private const string ENDPOINT_SETTING = "Endpoint";
private readonly BlobCodeFileRepository _codeFileRepository;
public readonly UserPreferenceCache _preferenceCache;

public string Endpoint { get; }
public ReviewModel Review { get; private set; }
Expand All @@ -26,12 +27,14 @@ public ConversationModel(
IConfiguration configuration,
BlobCodeFileRepository codeFileRepository,
CommentsManager commentsManager,
ReviewManager reviewManager)
ReviewManager reviewManager,
UserPreferenceCache preferenceCache)
{
_codeFileRepository = codeFileRepository;
_commentsManager = commentsManager;
_reviewManager = reviewManager;
Endpoint = configuration.GetValue<string>(ENDPOINT_SETTING);
_preferenceCache = preferenceCache;
}

public async Task<IActionResult> OnGetAsync(string id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
@page
@model APIViewWeb.Pages.Assemblies.DeleteModel
@using APIViewWeb.Helpers
@using APIViewWeb.Models
@{
ViewData["Title"] = "Delete";
ViewData["UserPreference"] = PageModelHelpers.GetUserPreference(Model._preferenceCache, User.GetGitHubLogin()) ?? new UserPreferenceModel();
}
<div class="container-fluid">
<div class="mx-5 mt-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ namespace APIViewWeb.Pages.Assemblies
public class DeleteModel : PageModel
{
private readonly ReviewManager _manager;
public readonly UserPreferenceCache _preferenceCache;

public DeleteModel(ReviewManager manager)
public DeleteModel(ReviewManager manager, UserPreferenceCache preferenceCache)
{
_manager = manager;
_preferenceCache = preferenceCache;
}

public string AssemblyName { get; set; }
Expand Down
7 changes: 5 additions & 2 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
@using APIViewWeb
@using System
@using System.Text.RegularExpressions
@using APIViewWeb.Helpers
@using APIViewWeb.Models
@{
ViewData["Title"] = "Reviews";
ViewData["UserPreference"] = PageModelHelpers.GetUserPreference(Model._preferenceCache, User.GetGitHubLogin()) ?? new UserPreferenceModel();
}
@section Scripts
{
Expand Down Expand Up @@ -48,7 +51,7 @@
<div class="modal-header">
<h5 class="modal-title">Create Review</h5>
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">&times;</span>
<span aria-hidden="true"><i class="fa-solid fa-xmark"></i></span>
</button>
</div>
<div class="modal-body">
Expand Down Expand Up @@ -208,7 +211,7 @@
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-outline-dark" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" onclick="this.form.submit(); this.disabled = true;"><i class="fas fa-cloud-upload-alt"></i> Upload</button>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace APIViewWeb.Pages.Assemblies
public class IndexPageModel : PageModel
{
private readonly ReviewManager _manager;
private readonly UserPreferenceCache _preferenceCache;
public readonly UserPreferenceCache _preferenceCache;
public const int _defaultPageSize = 50;
public const string _defaultSortField = "LastUpdated";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@page

@model APIViewWeb.Pages.Assemblies.LegacyReview
@using APIViewWeb.Helpers
@using APIViewWeb.Models
@{
ViewData["Title"] = "Legacy Review";
ViewData["UserPreference"] = PageModelHelpers.GetUserPreference(Model._preferenceCache, User.GetGitHubLogin()) ?? new UserPreferenceModel();
}

<h2>This review can not be viewed anymore but here are the comments:</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using ApiView;
using APIViewWeb.Models;
using APIViewWeb.Repositories;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

Expand All @@ -12,10 +13,12 @@ namespace APIViewWeb.Pages.Assemblies
public class LegacyReview: PageModel
{
private CommentsManager _commentsManager;
public readonly UserPreferenceCache _preferenceCache;

public LegacyReview(CommentsManager commentsManager)
public LegacyReview(CommentsManager commentsManager, UserPreferenceCache preferenceCache)
{
_commentsManager = commentsManager;
_preferenceCache = preferenceCache;
}

public string Id { get; set; }
Expand Down
21 changes: 11 additions & 10 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
@page "{id}/{revisionId?}"
@model APIViewWeb.Pages.Assemblies.ReviewPageModel
@using APIViewWeb.Helpers
@using APIViewWeb.Models
@{
Layout = "ReviewLayout";
ViewData["Title"] = Model.Review.DisplayName;
var userPreference = PageModelHelpers.GetUserPreference(Model._preferenceCache, User.GetGitHubLogin()) ?? new UserPreferenceModel();
ViewData["UserPreference"] = userPreference;
}

<div class="container-fluid">
Expand Down Expand Up @@ -45,13 +49,13 @@
@{
var popOverContent = $"<b>{Model.ActiveConversations}</b> active revision threads.<br><b>{Model.TotalActiveConversations}</b> total active threads.<br>"
+ $"<b>Current Revision:</b> <em>{@Model.Revision.DisplayName}</em>";
@if (Model.DiffRevisionId != null)
@if (Model.DiffRevisionId != null)
{
popOverContent += $"<br><b>Current Diff:</b> <em>{@Model.DiffRevision?.DisplayName}</em>";
}
<button type="button" class="btn btn-info btn-sm shadow-sm" data-placement="bottom" data-trigger="focus" data-toggle="popover" data-html="true" data-title="Page Info" data-content="@popOverContent">
<i class="far fa-comment-alt mr-2"></i><span class="badge badge-light">@Model.ActiveConversations / @Model.TotalActiveConversations</span>
</button>
<button type="button" class="btn btn-info btn-sm shadow-sm" data-placement="bottom" data-trigger="focus" data-toggle="popover" data-html="true" data-title="Page Info" data-content="@popOverContent">
<i class="far fa-comment-alt mr-2"></i><span class="badge badge-light">@Model.ActiveConversations / @Model.TotalActiveConversations</span>
</button>
}
</div>
<div class="my-1">
Expand Down Expand Up @@ -114,7 +118,7 @@
</span>
<span class="dropdown-item checkbox">
<label>
@if (Model.GetUserPreference().HideLineNumbers == true)
@if (userPreference.HideLineNumbers == true)
{
<input type="checkbox" id="hide-line-numbers" checked>
}
Expand All @@ -127,7 +131,7 @@
</span>
<span class="dropdown-item checkbox">
<label>
@if (Model.GetUserPreference().HideLeftNavigation == true)
@if (userPreference.HideLeftNavigation == true)
{
<input type="checkbox" id="hide-left-navigation" checked>
}
Expand Down Expand Up @@ -313,7 +317,7 @@
@{
var reviewLeftDisplay = String.Empty;
var reviewRightSize = "10";
if (Model.GetUserPreference().HideLeftNavigation == true)
if (userPreference.HideLeftNavigation == true)
{
reviewLeftDisplay = "d-none";
reviewRightSize = "12";
Expand All @@ -331,9 +335,6 @@
<div id="review-right" class="col-@reviewRightSize rounded-1 border">
<table class="code-window">
<tbody>
@{
TempData["UserPreference"] = Model.GetUserPreference();
}
@foreach (var line in Model.Lines)
{
<partial name="_CodeLine" model="@line" />
Expand Down
Loading