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 Option for Hiding Left Navigation #3686

Merged
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
1 change: 1 addition & 0 deletions src/dotnet/APIView/APIViewWeb/APIViewWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Include="CsvHelper" Version="27.2.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.12.0-beta4" />
Expand Down
1 change: 1 addition & 0 deletions src/dotnet/APIView/APIViewWeb/Client/css/site.scss
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ code {
cursor: pointer;
width: 1%;
white-space: nowrap;
padding: 0px;
}

.line-details table {
Expand Down
34 changes: 1 addition & 33 deletions src/dotnet/APIView/APIViewWeb/Client/src/navbar.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1 @@
import Split from "split.js";

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

$(() => {
/* 992px matches bootstrap col-lg min-width */
($('.namespace-view') as any).stickySidebar({ minWidth: 992 });

/* Split left and right review panes using split.js */
const rl = $('#review-left');
const rr = $('#review-right');

if (rl.length && rr.length) {
Split(['#review-left', '#review-right'], {
direction: 'horizontal',
sizes: [17, 83],
elementStyle: (dimension, size, gutterSize) => {
return {
'flex-basis': `calc(${size}% - ${gutterSize}px`
}
},
gutterStyle: (dimension, gutterSize) => {
return {
'flex-basis': `${gutterSize}px`
}
}
});
}
});

98 changes: 86 additions & 12 deletions src/dotnet/APIView/APIViewWeb/Client/src/review.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,80 @@
$(() => {
import Split from "split.js";

$(() => {
const SEL_DOC_CLASS = ".documentation";
const SHOW_DOC_CHECK_COMPONENT = "#show-documentation-component";
const SHOW_DOC_CHECKBOX = ".show-doc-checkbox";
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();

/* FUNCTIONS
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
function hideCheckboxIfNoDocs() {
if ($(SEL_DOC_CLASS).length == 0) {
$(SHOW_DOC_CHECK_COMPONENT).hide();
}
if ($(SEL_DOC_CLASS).length == 0) {
$(SHOW_DOC_CHECK_COMPONENT).hide();
}
}

function splitReviewPageContent() {
/* Split left and right review panes using split.js */
const rl = $('#review-left');
const rr = $('#review-right');

if (rl.length && rr.length) {
Split(['#review-left', '#review-right'], {
direction: 'horizontal',
sizes: [17, 83],
elementStyle: (dimension, size, gutterSize) => {
return {
'flex-basis': `calc(${size}% - ${gutterSize}px`
}
},
gutterStyle: (dimension, gutterSize) => {
return {
'flex-basis': `${gutterSize}px`
}
}
});
}
}

// 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", () => {
$(".nav-list-toggle").click(function () {
$(this).parents(".nav-list-group").first().toggleClass("nav-list-collapsed");
});
});

/* SPLIT REVIEW PAGE CONTENT
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* 992px matches bootstrap col-lg min-width */
($('.namespace-view') as any).stickySidebar({ minWidth: 992 });
if (!$("#review-left").hasClass("d-none"))
{
// Only Add Split gutter if left navigation is not hidden
splitReviewPageContent();
}

/* TOGGLE PAGE OPTIONS
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
$(SHOW_DOC_CHECKBOX).on("click", e => {
$(SHOW_DOC_HREF)[0].click();
});
Expand All @@ -24,18 +84,33 @@
});

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

/* DIFF BUTTON (UPDATES REVIEW PAGE ON CLICK)
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
$('.diff-button').each(function(index, value){
$(this).on('click', function () {
window.location.href = $(this).val() as string;
$(HIDE_LEFT_NAVIGATION).on("click", e => {
updatePageSettings(function(){
var leftContainer = $("#review-left");
var rightContainer = $("#review-right");
var gutter = $(".gutter-horizontal");

if (leftContainer.hasClass("d-none")) {
leftContainer.removeClass("d-none");
rightContainer.removeClass("col-12");
rightContainer.addClass("col-10");
splitReviewPageContent();
}
else {
leftContainer.addClass("d-none");
rightContainer.css("flex-basis", "100%");
gutter.remove();
rightContainer.removeClass("col-10");
rightContainer.addClass("col-12");
}
});
});


/* DROPDOWN FILTER FOR REVIEW, REVISIONS AND DIFF (UPDATES REVIEW PAGE ON CHANGE)
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
$('#revisions-bootstraps-select, #review-bootstraps-select, #diff-bootstraps-select').each(function(index, value) {
Expand All @@ -59,7 +134,6 @@
var caretDirection = caretClasses ? caretClasses.split(' ').filter(c => c.startsWith('fa-angle-'))[0] : "";
var foldableClassPrefix = headingRowClasses ? headingRowClasses.split(' ').filter(c => c.endsWith('-heading'))[0].replace("-heading", "") : "";


if (triggeringClass == "row-fold-caret" && caretDirection == "fa-angle-down") {
var classesOfRowsToHide = [`${foldableClassPrefix}-content`];

Expand Down
13 changes: 6 additions & 7 deletions src/dotnet/APIView/APIViewWeb/Client/src/reviews.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
$(() => {
// Search
const defaultPageSize = 50;
const reviewsFilterPartial = $( '#reviews-filter-partial' );
const languageFilter = $( '#language-filter-bootstraps-select' );
Expand Down Expand Up @@ -77,10 +76,9 @@
});
}

// Triggers partial page update to retriev properties for poulating filter dropdowns
// Fetches data for populating dropdown options
function updateFilterDropDown(filter, query)
{
// update tags dropdown select
var uri = `?handler=reviews${query}`;
var urlParams = new URLSearchParams(location.search);
if (urlParams.has(query))
Expand All @@ -97,20 +95,20 @@
});
}

// Update content of dropdown on page load
// Fetch content of dropdown on page load
$(document).ready(function() {
updateFilterDropDown(languageFilter, "languages");
updateFilterDropDown(languageFilter, "languages"); // Pulls languages data from DB
addPaginationEventHandlers();
});


// Update when any dropdown is changed
// Update list of reviews when any dropdown is changed
[languageFilter, stateFilter, statusFilter, typeFilter].forEach(function(value, index) {
value.on('hidden.bs.select', function() {
updateListedReviews();
});
});

// Update list of reviews based on search input
searchBox.on('input', _.debounce(function(e) {
updateListedReviews();
}, 600));
Expand All @@ -119,6 +117,7 @@
updateListedReviews();
});

// Reset list of reviews as well as filters
resetButton.on('click', function(e) {
(<any>languageFilter).selectpicker('deselectAll');
(<any>stateFilter).selectpicker('deselectAll').selectpicker('val', 'Open');
Expand Down
21 changes: 21 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Helpers/AutoMapperProfiles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using APIViewWeb.Models;
using AutoMapper;
using Microsoft.CodeAnalysis.Diagnostics;

namespace APIViewWeb.Helpers
{
public class AutoMapperProfiles : Profile
{
public AutoMapperProfiles()
{
CreateMap<UserPreferenceModel, UserPreferenceModel>()
.ForMember(dest => dest.UserName, opt => opt.MapFrom((src, dest) => src.UserName != null ? src.UserName : dest.UserName))
.ForMember(dest => dest.Language, opt => opt.MapFrom((src, dest) => src.Language != null ? src.Language : dest.Language))
.ForMember(dest => dest.FilterType, opt => opt.MapFrom((src, dest) => src.FilterType != null ? src.FilterType : dest.FilterType))
.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));
}
}
}
9 changes: 9 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Models/UserPreferenceModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using CsvHelper.Configuration.Attributes;

namespace APIViewWeb.Models
Expand All @@ -12,5 +13,13 @@ public class UserPreferenceModel
public IEnumerable<string> Language { get; set; }
[Name("FilterType")]
public IEnumerable<ReviewType> FilterType { get; set; }
[Name("State")]
public IEnumerable<string> State { get; set; }
[Name("Status")]
public IEnumerable<string> Status { get; set; }
[Name("HideLineNumbers")]
public bool? HideLineNumbers { get; set; }
[Name("HideLeftNavigation")]
public bool? HideLeftNavigation { get; set; }
}
}
29 changes: 26 additions & 3 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ public async Task OnGetAsync(
List<string> search = null, List<string> languages=null, List<string> state =null,
List<string> status =null, List<string> type =null, int pageNo=1, int pageSize=_defaultPageSize, string sortField=_defaultSortField)
{
if (search.Count == 0 && languages.Count == 0 && state.Count == 0 && status.Count == 0 && type.Count == 0)
chidozieononiwu marked this conversation as resolved.
Show resolved Hide resolved
{
UserPreferenceModel userPreference = _preferenceCache.GetUserPreferences(User.GetGitHubLogin());
if (userPreference != null)
{
languages = userPreference.Language.ToList();
state = userPreference.State.ToList();
status = userPreference.Status.ToList();
type = new List<string>();
if (userPreference.FilterType.Contains(ReviewType.Manual)) { type.Add("Manual"); }
if (userPreference.FilterType.Contains(ReviewType.Automatic)) { type.Add("Automatic"); }
if (userPreference.FilterType.Contains(ReviewType.PullRequest)) { type.Add("PullRequest"); }
}
}
await RunGetRequest(search, languages, state, status, type, pageNo, pageSize, sortField);
}

Expand All @@ -51,6 +65,14 @@ public async Task<PartialViewResult> OnGetReviewsPartialAsync(

public async Task<PartialViewResult> OnGetReviewsLanguagesAsync(List<string> selectedLanguages = null)
{
if (selectedLanguages.Count == 0)
{
UserPreferenceModel userPreference = _preferenceCache.GetUserPreferences(User.GetGitHubLogin());
if (userPreference != null)
{
selectedLanguages = userPreference.Language.ToList();
}
}
ReviewsProperties.Languages.All = await _manager.GetReviewPropertiesAsync("Revisions[0].Files[0].Language");
selectedLanguages = selectedLanguages.Select(x => HttpUtility.UrlDecode(x)).ToList();
ReviewsProperties.Languages.Selected = selectedLanguages;
Expand Down Expand Up @@ -128,11 +150,12 @@ private async Task RunGetRequest(List<string> search, List<string> languages,
if (type.Contains("Automatic")) { filterTypes.Add((int)ReviewType.Automatic); }
if (type.Contains("PullRequest")) { filterTypes.Add((int)ReviewType.PullRequest); }

_preferenceCache.UpdateUserPreference(new UserPreferenceModel()
{
_preferenceCache.UpdateUserPreference(new UserPreferenceModel {
UserName = User.GetGitHubLogin(),
FilterType = filterTypes.Cast<ReviewType>().ToList(),
Language = languages
Language = languages,
State = state,
Status = status
});

bool? isApproved = null;
Expand Down
Loading