Skip to content

Commit

Permalink
Preferred tree state persisted in localstorage. Fixes for the tree di…
Browse files Browse the repository at this point in the history
…splay and config.
  • Loading branch information
impworks committed Jan 12, 2024
1 parent f1c8299 commit e664524
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Bonsai.Areas.Admin.Logic;
using Bonsai.Areas.Admin.Logic.Tree;
using Bonsai.Areas.Admin.ViewModels.DynamicConfig;
using Bonsai.Areas.Front.ViewModels.Page;
using Bonsai.Code.Services;
using Bonsai.Code.Services.Config;
using Bonsai.Code.Services.Jobs;
using Bonsai.Data;
Expand All @@ -16,18 +18,20 @@ namespace Bonsai.Areas.Admin.Controllers
[Route("admin/config")]
public class DynamicConfigController: AdminControllerBase
{
public DynamicConfigController(DynamicConfigManagerService configMgr, BonsaiConfigService config, IBackgroundJobService jobs, AppDbContext db)
public DynamicConfigController(DynamicConfigManagerService configMgr, BonsaiConfigService config, IBackgroundJobService jobs, AppDbContext db, CacheService cache)
{
_configMgr = configMgr;
_config = config;
_jobs = jobs;
_db = db;
_cache = cache;
}

private readonly DynamicConfigManagerService _configMgr;
private readonly BonsaiConfigService _config;
private readonly IBackgroundJobService _jobs;
private readonly AppDbContext _db;
private readonly CacheService _cache;

/// <summary>
/// Displays the form and edits the config.
Expand All @@ -54,7 +58,10 @@ public async Task<ActionResult> Update(UpdateDynamicConfigVM vm)
_config.ResetCache();

if (IsTreeConfigChanged())
{
_cache.Remove<PageTreeVM>();
await _jobs.RunAsync(JobBuilder.For<TreeLayoutJob>().SupersedeAll());
}

return RedirectToSuccess("Настройки сохранены");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private TreeLayoutVM GetCloseFamilyTree(RelationContext ctx, Guid pageId)
fc =>
{
// explicitly avoid e.g. other husbands of a man's wife
if (fc is {Distance: 1, RelationType: RelationType.Spouse, LastRelationType: RelationType.Spouse})
if (fc is {Distance: 2, RelationType: RelationType.Spouse, LastRelationType: RelationType.Spouse})
return null;
return fc.Distance switch
Expand Down
2 changes: 1 addition & 1 deletion src/Bonsai/Areas/Admin/Views/DynamicConfig/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
@{ TreeKindOption(TreeKind.FullTree, "Полное дерево", "весь связанный граф родственников"); }
@{ TreeKindOption(TreeKind.CloseFamily, "Близкие родственники", "на два уровня вокруг, от бабушек до внуков"); }
@{ TreeKindOption(TreeKind.Ancestors, "Предки", "все кровные родственники вверх"); }
@{ TreeKindOption(TreeKind.Descendants, "Потомки", "все кровные родственники вниз, включая супругов"); }
@{ TreeKindOption(TreeKind.Descendants, "Потомки", "все кровные родственники вниз и их родители"); }
</div>
</div>
<div class="form-group row">
Expand Down
20 changes: 10 additions & 10 deletions src/Bonsai/Areas/Front/Scripts/tree-view.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
$(function () {
var key = 'bonsai.preferences.view-tree-kind';

var $view = $('.tree-view'),
$iframe = $view.find('iframe'),
$toggles = $view.find('.cmd-switch-tree'),
$newWin = $view.find('.cmd-new-window');

if($view.length === 0)
return;

// $iframe.on('load', function () {
// setTimeout(
// function() {
// var size = $iframe[0].contentWindow.document.documentElement.scrollHeight;
// $iframe.css('height', Math.min(size + 2, 1000) + 'px');
// },
// 200
// );
// });

$view.find('.cmd-fullscreen').click(function () {
$iframe.fullScreen(true);
Expand All @@ -32,5 +24,13 @@ $(function () {
var url = $this.attr('href');
$newWin.attr('href', url);
$iframe.attr('src', url);

window.localStorage.setItem(key, $this.data('kind'));
});

var state = window.localStorage.getItem(key);
if (state) {
$toggles.filter('[data-kind="' + state + '"]')
.trigger('click');
}
});
2 changes: 1 addition & 1 deletion src/Bonsai/Areas/Front/Views/Page/Tree.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="float-left btn-group btn-group-toggle">
@foreach (var kind in Model.Body.SupportedKinds)
{
<a href="@GetTreeUrl(kind)" class="btn btn-sm btn-outline-primary cmd-switch-tree @(kind == Model.Body.TreeKind ? "active" : "")">@kind.GetEnumDescription()</a>
<a href="@GetTreeUrl(kind)" class="btn btn-sm btn-outline-primary cmd-switch-tree @(kind == Model.Body.TreeKind ? "active" : "")" data-kind="@kind">@kind.GetEnumDescription()</a>
}
</div>
<div class="float-right btn-group">
Expand Down

0 comments on commit e664524

Please sign in to comment.