Skip to content

Commit

Permalink
Merge pull request #1703 from sbwalker/dev
Browse files Browse the repository at this point in the history
Allow root page paths (rather than specifying a magic "home" string). More UX improvements to FileManager and Pager.
  • Loading branch information
sbwalker committed Oct 1, 2021
2 parents a762f20 + aeb5998 commit 8e6c73d
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 59 deletions.
4 changes: 2 additions & 2 deletions Oqtane.Client/Modules/Admin/Pages/Add.razor
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="path" HelpText="Optionally enter a url path for this page (ie. home ). If you do not provide a url path, the page name will be used." ResourceKey="UrlPath">Url Path: </Label>
<Label Class="col-sm-3" For="path" HelpText="Optionally enter a url path for this page (ie. home ). If you do not provide a url path, the page name will be used. If the page is intended to be the root path specify '/'." ResourceKey="UrlPath">Url Path: </Label>
<div class="col-sm-9">
<input id="path" class="form-control" @bind="@_path" />
</div>
Expand Down Expand Up @@ -293,11 +293,11 @@
page.SiteId = PageState.Page.SiteId;
page.Name = _name;
page.Title = _title;

if (string.IsNullOrEmpty(_path))
{
_path = _name;
}

if (_path.Contains("/"))
{
_path = _path.Substring(_path.LastIndexOf("/") + 1);
Expand Down
17 changes: 13 additions & 4 deletions Oqtane.Client/Modules/Admin/Pages/Edit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="path" HelpText="Optionally enter a url path for this page (ie. home ). If you do not provide a url path, the page name will be used." ResourceKey="UrlPath">Url Path: </Label>
<Label Class="col-sm-3" For="path" HelpText="Optionally enter a url path for this page (ie. home ). If you do not provide a url path, the page name will be used. If the page is intended to be the root path specify '/'." ResourceKey="UrlPath">Url Path: </Label>
<div class="col-sm-9">
<input id="path" class="form-control" @bind="@_path" maxlength="256"/>
</div>
Expand Down Expand Up @@ -225,9 +225,16 @@
_title = page.Title;
_path = page.Path;

if (_path.Contains("/"))
if (string.IsNullOrEmpty(_path))
{
_path = _path.Substring(_path.LastIndexOf("/") + 1);
_path = "/";
}
else
{
if (_path.Contains("/"))
{
_path = _path.Substring(_path.LastIndexOf("/") + 1);
}
}

if (page.ParentId == null)
Expand Down Expand Up @@ -370,14 +377,16 @@

page.Name = _name;
page.Title = _title;
if (string.IsNullOrEmpty(_path) && _name.ToLower() != "home")

if (string.IsNullOrEmpty(_path))
{
_path = _name;
}
if (_path.Contains("/"))
{
_path = _path.Substring(_path.LastIndexOf("/") + 1);
}

if (_parentid == "-1")
{
page.ParentId = null;
Expand Down
92 changes: 48 additions & 44 deletions Oqtane.Client/Modules/Controls/FileManager.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,60 @@
<div class="container-fluid px-0">
@if (ShowFolders || FolderId <= 0)
{
<div class="row"><div class="col">
<select class="form-select" value="@FolderId" @onchange="(e => FolderChanged(e))">
@if (string.IsNullOrEmpty(Folder))
{
<option value="-1">&lt;@Localizer["Folder.Select"]&gt;</option>
}
@foreach (Folder folder in _folders)
{
<option value="@(folder.FolderId)">@(new string('-', folder.Level * 2))@(folder.Name)</option>
}
</select>
</div></div>
<div class="row">
<div class="col">
<select class="form-select" value="@FolderId" @onchange="(e => FolderChanged(e))">
@if (string.IsNullOrEmpty(Folder))
{
<option value="-1">&lt;@Localizer["Folder.Select"]&gt;</option>
}
@foreach (Folder folder in _folders)
{
<option value="@(folder.FolderId)">@(new string('-', folder.Level * 2))@(folder.Name)</option>
}
</select>
</div>
</div>
}
@if (ShowFiles)
{
<div class="row"><div class="col mt-1">
<select class="form-select" value="@FileId" @onchange="(e => FileChanged(e))">
<option value="-1">&lt;@Localizer["File.Select"]&gt;</option>
@foreach (File file in _files)
{
<option value="@(file.FileId)">@(file.Name)</option>
}
</select>
</div></div>
<div class="row mt-1">
<div class="col">
<select class="form-select" value="@FileId" @onchange="(e => FileChanged(e))">
<option value="-1">&lt;@Localizer["File.Select"]&gt;</option>
@foreach (File file in _files)
{
<option value="@(file.FileId)">@(file.Name)</option>
}
</select>
</div>
</div>
}
@if (ShowUpload && _haseditpermission)
{
<div class="row"><div class="col mt-1">
@if (UploadMultiple)
{
<input type="file" id="@_fileinputid" name="file" accept="@_filter" multiple />
}
else
{
<input type="file" id="@_fileinputid" name="file" accept="@_filter" />
}
<span class="float-end">
<div class="row">
<div class="col mt-2">
@if (UploadMultiple)
{
<input type="file" id="@_fileinputid" name="file" accept="@_filter" multiple />
}
else
{
<input type="file" id="@_fileinputid" name="file" accept="@_filter" />
}
</div>
<div class="col mt-2 text-center">
<button type="button" class="btn btn-success" @onclick="UploadFile">@SharedLocalizer["Upload"]</button>
@if (ShowFiles && GetFileId() != -1)
{
<button type="button" class="btn btn-danger" @onclick="DeleteFile">@SharedLocalizer["Delete"]</button>
<button type="button" class="btn btn-danger mx-1" @onclick="DeleteFile">@SharedLocalizer["Delete"]</button>
}
</span>
</div></div>
<div class="row"><div class="col mt-1">
<div class="container-fluid px-0">
<div class="row">
<div class="col-6"><span id="@_progressinfoid"></span></div>
<div class="col-6"><progress id="@_progressbarid" class="mt-1" style="visibility: hidden;"></progress></div>
</div>
</div>
</div></div>
</div>
<div class="row">
<div class="col mt-1"><span id="@_progressinfoid" style="display: none;"></span></div>
<div class="col text-center mt-1"><progress id="@_progressbarid" class="mt-1" style="display: none;"></progress></div>
</div>
}
</div>
</div>
Expand All @@ -77,8 +79,8 @@
</div>
@if (!string.IsNullOrEmpty(_message))
{
<div class="row">
<div class="col mt-1">
<div class="row mt-1">
<div class="col">
<ModuleMessage Message="@_message" Type="@_messagetype" />
</div>
</div>
Expand Down Expand Up @@ -151,7 +153,7 @@
{
ShowImage = false;
}

if (!string.IsNullOrEmpty(Folder))
{
_folders = new List<Folder> { new Folder { FolderId = -1, Name = Folder } };
Expand Down Expand Up @@ -369,5 +371,7 @@

public int GetFileId() => FileId;

public int GetFolderId() => FolderId;

public File GetFile() => _file;
}
2 changes: 1 addition & 1 deletion Oqtane.Client/Modules/Controls/Pager.razor
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
}
else
{
Class = "container";
Class = "container-fluid px-0";
}
}

Expand Down
2 changes: 1 addition & 1 deletion Oqtane.Client/Resources/Modules/Admin/Pages/Add.resx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
<value>Select whether the page is part of the site navigation or hidden</value>
</data>
<data name="UrlPath.HelpText" xml:space="preserve">
<value>Optionally enter a url path for this page (ie. home ). If you do not provide a url path, the page name will be used.</value>
<value>Optionally enter a url path for this page (ie. home ). If you do not provide a url path, the page name will be used. If the page is intended to be the root path specify '/'.</value>
</data>
<data name="Redirect.HelpText" xml:space="preserve">
<value>Optionally enter a url which this page should redirect to when a user navigates to it</value>
Expand Down
2 changes: 1 addition & 1 deletion Oqtane.Client/Resources/Modules/Admin/Pages/Edit.resx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
<value>Select whether the page is part of the site navigation or hidden</value>
</data>
<data name="UrlPath.HelpText" xml:space="preserve">
<value>Optionally enter a url path for this page (ie. home ). If you do not provide a url path, the page name will be used.</value>
<value>Optionally enter a url path for this page (ie. home ). If you do not provide a url path, the page name will be used. If the page is intended to be the root path specify '/'.</value>
</data>
<data name="Redirect.HelpText" xml:space="preserve">
<value>Optionally enter a url which this page should redirect to when a user navigates to it</value>
Expand Down
3 changes: 3 additions & 0 deletions Oqtane.Client/Services/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public async Task<string> UploadFilesAsync(string folder, string[] files, string
attempts += 1;
}

await interop.SetElementAttribute(id + "ProgressInfo", "style", "display: none;");
await interop.SetElementAttribute(id + "ProgressBar", "style", "display: none;");

if (!success)
{
result = result.Substring(0, result.Length - 1);
Expand Down
15 changes: 15 additions & 0 deletions Oqtane.Client/UI/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,20 @@ public ValueTask<bool> FormValid(ElementReference form)
return new ValueTask<bool>(Task.FromResult(false));
}
}

public Task SetElementAttribute(string id, string attribute, string value)
{
try
{
_jsRuntime.InvokeVoidAsync(
"Oqtane.Interop.setElementAttribute",
id, attribute, value);
return Task.CompletedTask;
}
catch
{
return Task.CompletedTask;
}
}
}
}
21 changes: 15 additions & 6 deletions Oqtane.Server/wwwroot/js/interop.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,14 @@ Oqtane.Interop = {
return files;
},
uploadFiles: function (posturl, folder, id) {
var files = document.getElementById(id + 'FileInput').files;
var fileinput = document.getElementById(id + 'FileInput');
var files = fileinput.files;
var progressinfo = document.getElementById(id + 'ProgressInfo');
var progressbar = document.getElementById(id + 'ProgressBar');

progressinfo.setAttribute("style", "display: inline;");
progressbar.setAttribute("style", "width: 200px; display: inline;");

for (var i = 0; i < files.length; i++) {
var FileChunk = [];
var file = files[i];
Expand All @@ -311,8 +315,6 @@ Oqtane.Interop = {
var EndPos = BufferChunkSize;
var Size = file.size;

progressbar.setAttribute("style", "width:100%; visibility: visible;");

while (FileStreamPos < Size) {
FileChunk.push(file.slice(FileStreamPos, EndPos));
FileStreamPos = EndPos;
Expand All @@ -332,21 +334,22 @@ Oqtane.Interop = {
var request = new XMLHttpRequest();
request.open('POST', posturl, true);
request.upload.onloadstart = function (e) {
progressbar.value = 0;
progressinfo.innerHTML = file.name + ' 0%';
progressbar.value = 0;
};
request.upload.onprogress = function (e) {
var percent = Math.ceil((e.loaded / e.total) * 100);
progressbar.value = (percent / 100);
progressinfo.innerHTML = file.name + '[' + PartCount + '] ' + percent + '%';
progressbar.value = (percent / 100);
};
request.upload.onloadend = function (e) {
progressbar.value = 1;
progressinfo.innerHTML = file.name + ' 100%';
progressbar.value = 1;
};
request.send(data);
}
}
fileinput.value = '';
},
refreshBrowser: function (reload, wait) {
setInterval(function () {
Expand All @@ -360,5 +363,11 @@ Oqtane.Interop = {
},
formValid: function (formRef) {
return formRef.checkValidity();
},
setElementAttribute: function (id, attribute, value) {
var element = document.getElementById(id);
if (element !== null) {
element.setAttribute(attribute, value);
}
}
};

0 comments on commit 8e6c73d

Please sign in to comment.