Merge branch 'main' of https://git.azuze.fr/kawa/SharepointToolbox-Web
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
@inject ILibraryDiscoveryService LibraryDiscovery
|
||||
|
||||
@* Library name field with a picker: type a title, or click Browse to load and
|
||||
choose from the libraries on the selected site. *@
|
||||
<div class="form-group library-picker">
|
||||
<label class="form-label">@Label</label>
|
||||
<div class="flex-row" style="gap:8px;align-items:stretch">
|
||||
<input class="form-input" style="flex:1"
|
||||
placeholder="@Placeholder"
|
||||
value="@Library"
|
||||
@oninput="OnTextInput"
|
||||
disabled="@Disabled" />
|
||||
<button type="button" class="btn btn-secondary"
|
||||
@onclick="Browse"
|
||||
disabled="@(Disabled || _loading)">
|
||||
@(_loading ? "Loading…" : "Browse")
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_error))
|
||||
{
|
||||
<div class="alert alert-error mt-8">@_error</div>
|
||||
}
|
||||
|
||||
@if (_open)
|
||||
{
|
||||
<div class="library-picker-list" style="max-height:200px;overflow:auto;border:1px solid var(--border);border-radius:4px;padding:4px;margin-top:6px">
|
||||
@foreach (var lib in _libraries)
|
||||
{
|
||||
<button type="button"
|
||||
class="library-picker-item @(string.Equals(lib, Library, StringComparison.OrdinalIgnoreCase) ? "active" : "")"
|
||||
style="display:block;width:100%;text-align:left;padding:4px 8px;border:none;background:none;cursor:pointer;border-radius:3px"
|
||||
@onclick="() => Pick(lib)">
|
||||
@lib
|
||||
</button>
|
||||
}
|
||||
@if (_libraries.Count == 0)
|
||||
{
|
||||
<div class="text-muted" style="padding:6px">No document libraries found on this site.</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public TenantProfile Profile { get; set; } = default!;
|
||||
[Parameter] public string? SiteUrl { get; set; }
|
||||
[Parameter] public string Library { get; set; } = string.Empty;
|
||||
[Parameter] public EventCallback<string> LibraryChanged { get; set; }
|
||||
[Parameter] public string Label { get; set; } = "Library";
|
||||
[Parameter] public string Placeholder { get; set; } = "Shared Documents";
|
||||
[Parameter] public bool Disabled { get; set; }
|
||||
|
||||
private List<string> _libraries = new();
|
||||
private bool _loading, _open;
|
||||
private string _error = string.Empty;
|
||||
private string? _loadedForSite;
|
||||
|
||||
private async Task OnTextInput(ChangeEventArgs e)
|
||||
{
|
||||
Library = e.Value?.ToString() ?? string.Empty;
|
||||
await LibraryChanged.InvokeAsync(Library);
|
||||
}
|
||||
|
||||
private async Task Browse()
|
||||
{
|
||||
_error = string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(SiteUrl)) { _error = "Select a site first."; return; }
|
||||
|
||||
// Toggle closed if already showing the list for this site.
|
||||
if (_open && _loadedForSite == SiteUrl) { _open = false; return; }
|
||||
|
||||
// Reload when the site changed since the last load.
|
||||
if (_libraries.Count == 0 || _loadedForSite != SiteUrl)
|
||||
{
|
||||
_loading = true;
|
||||
try
|
||||
{
|
||||
_libraries = (await LibraryDiscovery.ListLibrariesAsync(Profile, SiteUrl!)).ToList();
|
||||
_loadedForSite = SiteUrl;
|
||||
}
|
||||
catch (Exception ex) { _error = ex.Message; return; }
|
||||
finally { _loading = false; }
|
||||
}
|
||||
_open = true;
|
||||
}
|
||||
|
||||
private async Task Pick(string lib)
|
||||
{
|
||||
Library = lib;
|
||||
_open = false;
|
||||
await LibraryChanged.InvokeAsync(Library);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user