namespace Khaemhat.Web.Shell;
///
/// The wiki page of each part of the application (SPEC ยง17: F1 and "?" open the page of the screen). The address is
/// the deepest prefix that matches; anything unknown opens the wiki home.
///
public static class HelpLinks
{
/// The wiki of the project, used when no other address is configured.
public const string DefaultBaseUrl = "https://gitea.encke-hake.ts.net/BalboSoft/Khaemhat/wiki/";
private static readonly (string Prefix, string Page)[] Pages =
[
("/anagrafiche/articoli", "Articoli-e-listini"),
("/anagrafiche/listini", "Articoli-e-listini"),
("/anagrafiche", "Anagrafiche"),
("/crm", "CRM"),
("/vendite", "Vendite"),
("/acquisti", "Acquisti"),
("/magazzino", "Magazzino"),
("/contabilita/liquidazione-iva", "IVA"),
("/contabilita/registri-iva", "IVA"),
("/contabilita", "Contabilita"),
("/scadenzario", "Scadenzario"),
("/fatturazione-elettronica", "Fatturazione-elettronica"),
("/cespiti", "Cespiti"),
("/servizi", "Servizi"),
("/canali", "Canali-e-commerce"),
("/report", "Report"),
("/tabelle", "Tabelle-azienda"),
("/automazioni", "Automazioni"),
("/amministrazione/import-export", "Import-Export"),
("/amministrazione/licenze", "Licenze-e-moduli"),
("/amministrazione/log", "Log"),
("/amministrazione/attivita", "Attivita-programmate"),
("/amministrazione/stato", "Stato-sistema"),
("/amministrazione/utenti", "Utenti-e-permessi"),
("/amministrazione/ruoli", "Utenti-e-permessi"),
("/amministrazione", "Istanza-e-database"),
("/profilo", "Preferenze-utente"),
("/", "Dashboard"),
];
/// The wiki page of a path.
/// The path, without query.
/// The page name, for example Anagrafiche.
public static string PageFor(string path)
{
var p = TabService.PathOf(path);
foreach (var (prefix, page) in Pages)
{
if (prefix == "/" ? p == "/" : p.Equals(prefix, StringComparison.OrdinalIgnoreCase) || p.StartsWith(prefix + "/", StringComparison.OrdinalIgnoreCase))
{
return page;
}
}
return "Home";
}
/// The address of the help of a path.
/// The wiki address, ending with a slash.
/// The path.
/// The address.
public static string UrlFor(string baseUrl, string path) => baseUrl + PageFor(path);
/// The help page of a path inside the application (F1, mockup 011).
/// The path.
/// The relative address, such as aiuto/Anagrafiche.
public static string LocalFor(string path) => Khaemhat.Web.Help.WikiLibrary.Href(PageFor(path));
/// The online wiki: KHAEMHAT_HELP_URL or the project wiki, always ending with a slash.
/// The configured address, if any.
/// The address.
public static string BaseUrl(string? configured) =>
string.IsNullOrWhiteSpace(configured) ? DefaultBaseUrl : configured.EndsWith('/') ? configured : configured + "/";
/// Where to report a problem: the issues of the repository whose wiki it is (Gitea and GitHub alike).
/// The wiki address.
/// The address of a new issue, or when the wiki is not a repository wiki.
public static string? IssuesUrl(string baseUrl)
{
ArgumentNullException.ThrowIfNull(baseUrl);
return baseUrl.EndsWith("/wiki/", StringComparison.OrdinalIgnoreCase) ? baseUrl[..^"wiki/".Length] + "issues/new" : null;
}
}