Skip to content

Commit

Permalink
update FeatureController with data form Oqtane
Browse files Browse the repository at this point in the history
  • Loading branch information
tvatavuk committed Sep 15, 2021
1 parent 8237e7f commit 9cf4d8f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
30 changes: 30 additions & 0 deletions Src/Oqtane/ToSic.Sxc.Oqt.Server/Run/OqtModuleHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Oqtane.Repository;
using System.Linq;

namespace ToSic.Sxc.Oqt.Server.Run
{
public class OqtModuleHelper
{
private readonly IModuleRepository _moduleRepository;
private readonly IModuleDefinitionRepository _moduleDefinitionRepository;

public OqtModuleHelper(IModuleRepository moduleRepository, IModuleDefinitionRepository moduleDefinitionRepository)
{
_moduleRepository = moduleRepository;
_moduleDefinitionRepository = moduleDefinitionRepository;
}

/// <summary>
/// Detect is 2sxc Content app
/// </summary>
/// <param name="moduleId">module id</param>
/// <returns>bool</returns>

public bool IsContentApp(int moduleId)
{
var module = _moduleRepository.GetModule(moduleId);
var moduleDefinition = _moduleDefinitionRepository.GetModuleDefinitions(module.SiteId).ToList().Find(item => item.ModuleDefinitionName == module.ModuleDefinitionName);
return moduleDefinition?.Name == "Content";
}
}
}
2 changes: 2 additions & 0 deletions Src/Oqtane/ToSic.Sxc.Oqt.Server/StartUp/OqtaneDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public static IServiceCollection AddSxcOqtane(this IServiceCollection services)
}
catch { /* ignore */ }

services.TryAddTransient<OqtModuleHelper>();

return services;
}

Expand Down
27 changes: 14 additions & 13 deletions Src/Oqtane/ToSic.Sxc.Oqt.Server/WebApi/Admin/FeatureController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Oqtane.Infrastructure;
using Oqtane.Shared;
using System.Collections.Generic;
using ToSic.Eav.Configuration;
using ToSic.Eav.Context;
using ToSic.Eav.WebApi.PublicApi;
using ToSic.Sxc.Oqt.Server.Controllers;
using ToSic.Sxc.Oqt.Server.Run;
using ToSic.Sxc.Oqt.Shared;
using ToSic.Sxc.Run;
using ToSic.Sxc.WebApi.Features;
Expand All @@ -27,13 +27,17 @@ public class FeatureController : OqtStatefulControllerBase, IFeatureController
{
private readonly FeaturesBackend _featuresBackend;
private readonly ISite _site;
private readonly IConfigManager _configManager;
private readonly OqtModuleHelper _oqtModuleHelper;
private readonly WipRemoteRouterLink _remoteRouterLink;
protected override string HistoryLogName => "Api.Feats";

public FeatureController(FeaturesBackend featuresBackend, ISite site, WipRemoteRouterLink remoteRouterLink)
public FeatureController(FeaturesBackend featuresBackend, ISite site, IConfigManager configManager, OqtModuleHelper oqtModuleHelper, WipRemoteRouterLink remoteRouterLink)
{
_featuresBackend = featuresBackend;
_site = site;
_configManager = configManager;
_oqtModuleHelper = oqtModuleHelper;
_remoteRouterLink = remoteRouterLink;
}

Expand Down Expand Up @@ -62,20 +66,17 @@ public string RemoteManageUrl()
var ctx = GetContext();
var site = ctx.Site;
var module = ctx.Module;

//var module = Request.FindModuleInfo();

var link = _remoteRouterLink.LinkToRemoteRouter(RemoteDestinations.Features,
"Dnn",
Assembly.GetAssembly(typeof(SiteState))?.GetName().Version?.ToString(4),
Guid.Empty.ToString(),
"Oqt",
Oqtane.Shared.Constants.Version, // Assembly.GetAssembly(typeof(SiteState))?.GetName().Version?.ToString(4),
_configManager.GetInstallationId(),
site,
module.Id,
app: null,
false // TODO: NOT SURE HOW TO DETECT CONTENT-APP IN OQTANE
// (Oqtane.Models.Module)module.ModuleDefinitionName.Contains(".Content")
_oqtModuleHelper.IsContentApp(module.Id)
);
return link;

}

/// <summary>
Expand Down

0 comments on commit 9cf4d8f

Please sign in to comment.