Skip to content

Commit

Permalink
Minor bugfixes and improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
JorjeRedemption committed Aug 5, 2021
1 parent 411b7ff commit 5beea1d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 40 deletions.
26 changes: 13 additions & 13 deletions projects/Hood.Admin/Controllers/MediaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MediaController()
}

[Route("admin/media/list/")]
public async Task<IActionResult> List(MediaListModel model, string viewName = "_List_Media")
public virtual async Task<IActionResult> List(MediaListModel model, string viewName = "_List_Media")
{
IQueryable<MediaObject> media = _db.Media.AsQueryable();

Expand Down Expand Up @@ -95,27 +95,27 @@ public async Task<IActionResult> List(MediaListModel model, string viewName = "_
}

[Route("admin/media/")]
public async Task<IActionResult> Index(MediaListModel model)
public virtual async Task<IActionResult> Index(MediaListModel model)
{
return await List(model, "Index");
}

[Route("admin/media/action/")]
public async Task<IActionResult> Action(MediaListModel model)
public virtual async Task<IActionResult> Action(MediaListModel model)
{
return await List(model, "Action");
}

[Route("admin/media/blade/")]
public async Task<IActionResult> Blade(int id)
public virtual async Task<IActionResult> Blade(int id)
{
MediaObject media = await _db.Media.Include(m => m.Directory).SingleOrDefaultAsync(u => u.Id == id);
return View("_Blade_Media", media);
}

[HttpPost]
[Route("admin/media/delete/")]
public async Task<Response> Delete(int id)
public virtual async Task<Response> Delete(int id)
{
try
{
Expand All @@ -134,13 +134,13 @@ public async Task<Response> Delete(int id)

#region Directories
[Route("admin/media/directories/list/")]
public IActionResult Directories(MediaListModel model)
public virtual IActionResult Directories(MediaListModel model)
{
model.TopLevelDirectories = GetDirectoriesForCurrentUser();
return View("_List_Directories", model);
}

private IEnumerable<MediaDirectory> GetDirectoriesForCurrentUser()
protected virtual IEnumerable<MediaDirectory> GetDirectoriesForCurrentUser()
{
if (User.IsAdminOrBetter())
{
Expand All @@ -157,7 +157,7 @@ private IEnumerable<MediaDirectory> GetDirectoriesForCurrentUser()
}

[Route("admin/media/directory/create/")]
public async Task<IActionResult> CreateDirectoryAsync(int id)
public virtual async Task<IActionResult> CreateDirectoryAsync(int id)
{
try
{
Expand Down Expand Up @@ -198,7 +198,7 @@ public async Task<IActionResult> CreateDirectoryAsync(int id)

[HttpPost]
[Route("admin/media/directory/create/")]
public async Task<Response> CreateDirectory(MediaDirectory model)
public virtual async Task<Response> CreateDirectory(MediaDirectory model)
{
try
{
Expand Down Expand Up @@ -242,7 +242,7 @@ public async Task<Response> CreateDirectory(MediaDirectory model)

[HttpPost]
[Route("admin/media/directory/delete/")]
public async Task<Response> DeleteDirectory(int id)
public virtual async Task<Response> DeleteDirectory(int id)
{
try
{
Expand Down Expand Up @@ -315,7 +315,7 @@ public async Task<Response> DeleteDirectory(int id)
/// </summary>
[HttpPost]
[Route("admin/media/attach/")]
public async Task<Response> Attach(MediaListModel model)
public virtual async Task<Response> Attach(MediaListModel model)
{
try
{
Expand Down Expand Up @@ -401,7 +401,7 @@ public async Task<Response> Attach(MediaListModel model)
/// </summary>
[HttpPost]
[Route("admin/media/clear/")]
public async Task<Response> Clear(MediaListModel model)
public virtual async Task<Response> Clear(MediaListModel model)
{
try
{
Expand Down Expand Up @@ -483,7 +483,7 @@ public async Task<Response> Clear(MediaListModel model)
#region Uploads
[HttpPost]
[Route("admin/media/upload/simple/")]
public async Task<Response> UploadToDirectory(IEnumerable<IFormFile> files, int? directoryId)
public virtual async Task<Response> UploadToDirectory(IEnumerable<IFormFile> files, int? directoryId)
{
try
{
Expand Down
10 changes: 0 additions & 10 deletions projects/Hood.Development/src/ts/core/DataList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ export class DataList {

}.bind(this));

// $('body').on('submit', '.hood-inline-list form', function (e) {
// e.preventDefault();
// $.hood.Loader(true);
// let $form = $(this);
// let $list = $form.parents('.hood-inline-list');
// var url = document.createElement('a');
// url.href = $list.data('url');
// url.search = "?" + $form.serialize();
// $.hood.Inline.DataList.Reload($list, url);
// });
}

reload(this: DataList, url: URL = null) {
Expand Down
8 changes: 4 additions & 4 deletions projects/Hood.Development/src/ts/core/Inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ export class Inline {

}

static handleError(xhr: { status: string | number; }) {
static handleError(xhr: { status: string | number; }, textStatus: any, errorThrown: any) {
if (xhr.status === 500) {
Alerts.error("There was an error processing the content, please contact an administrator if this continues.", "Error " + xhr.status);
Alerts.error("There was an error processing the content, please contact an administrator if this continues.", "Error " + xhr.status, 10000);
} else if (xhr.status === 404) {
Alerts.error("The content could not be found.", "Error " + xhr.status);
Alerts.error("The content could not be found.", "Error " + xhr.status, 10000);
} else if (xhr.status === 401) {
Alerts.error("You are not allowed to view this resource, are you logged in correctly?", "Error " + xhr.status);
Alerts.error("You are not allowed to view this resource, are you logged in correctly?", "Error " + xhr.status, 10000);
window.location = window.location;
}
}
Expand Down
8 changes: 7 additions & 1 deletion projects/Hood.Development/src/ts/core/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ export class ModalController {


}.bind(this))
.fail(this.options.onError ?? Inline.handleError);
.fail(function (this: ModalController, xhr: { status: string | number; }, textStatus: any, errorThrown: any) {
this.isOpen = false;
if (this.options.onError) {
this.options.onError(xhr, textStatus, errorThrown);
}
Inline.handleError(xhr, textStatus, errorThrown);
}.bind(this));
}

close() {
Expand Down
46 changes: 37 additions & 9 deletions projects/Hood.Development/src/ts/core/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ export interface ValidatorOptions {
*/
onError?: (jqXHR: any, textStatus: any, errorThrown: any) => void;

serializationFunction?: () => string;
serializationFunction?: () => string;

useAjax?: boolean;

}

export class Validator {
element: HTMLFormElement;
options: ValidatorOptions = {
errorAlert: 'There are errors, please check the form.'
errorAlert: 'There are errors, please check the form.',
useAjax: true
};

/**
Expand All @@ -52,6 +55,23 @@ export class Validator {
e.stopImmediatePropagation();
this.submitForm();
}.bind(this));
var tag = '[data-submit="#' + this.element.id + '"]';
let submitButtons = $(tag);
if (submitButtons) {
submitButtons.on('click', function (this: Validator, e: Event) {
e.preventDefault();
e.stopImmediatePropagation();
let exit = $(e.currentTarget).data('exit');
if (exit) {
$(this.element).find("input#exit").remove();
$("<input id='exit' />").attr("type", "hidden")
.attr("name", "exit")
.attr("value", "true")
.appendTo(this.element);
}
this.submitForm();
}.bind(this));
}
}

submitForm() {
Expand All @@ -74,14 +94,22 @@ export class Validator {
this.options.onSubmit(this);
}

let formData = this.options.serializationFunction();
if (this.options.useAjax) {

$.post(this.element.action, formData, function (this: Validator, data: any) {
if (this.options.onComplete) {
this.options.onComplete(data, this);
}
}.bind(this))
.fail(this.options.onError ?? Inline.handleError);
let formData = this.options.serializationFunction();

$.post(this.element.action, formData, function (this: Validator, data: any) {
if (this.options.onComplete) {
this.options.onComplete(data, this);
}
}.bind(this))
.fail(this.options.onError ?? Inline.handleError);

} else {

this.element.submit();

}

} else {

Expand Down
6 changes: 3 additions & 3 deletions projects/Hood.Development/src/ts/core/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'jquery-toast-plugin';

const BootstrapSwal = Swal.mixin({
customClass: {
confirmButton: 'btn btn-success btn-lg m-1 pl-4 pr-4',
cancelButton: 'btn btn-danger btn-lg m-1'
confirmButton: 'btn btn-success m-1 px-3',
cancelButton: 'btn btn-danger m-1 px-3'
},
buttonsStyling: false
});
Expand Down Expand Up @@ -120,7 +120,7 @@ export class Alerts {

let baseOptions: SweetAlertOptions = {
showCancelButton: true,
footer: '<span class="text-warning"><i class="fa fa-exclamation-triangle"></i> This cannot be undone.</span>',
footer: null,
title: 'Are you sure?',
html: 'Are you sure you want to do this?',
confirmButtonText: 'Ok',
Expand Down

0 comments on commit 5beea1d

Please sign in to comment.