Skip to content

Commit

Permalink
Added message on category delete if records linked to it.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Doolaeghe committed Aug 26, 2023
1 parent 705e014 commit d1f85d1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
14 changes: 9 additions & 5 deletions webapp/Pages/Categories/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
<e-grid-loadingIndicator indicatorType="Shimmer"></e-grid-loadingIndicator>
<e-grid-columns>
<e-grid-column field="Id" headerText="@Localizer["Id"].Value" isPrimaryKey="true" visible="false"></e-grid-column>
<e-grid-column field="Icon" headerText="@Localizer["Icon"].Value" editType="dropdownedit" edit="new { @@params = iconParams }" validationRules="validationRules" allowFiltering="false" width="50"></e-grid-column>
<e-grid-column field="Icon" headerText="@Localizer["Icon"].Value" editType="dropdownedit" edit="new { @@params = iconEdit }" validationRules="validationRules" allowFiltering="false" width="50"></e-grid-column>
<e-grid-column field="Name" headerText="@Localizer["Name"].Value" editType="textboxedit" validationRules="validationRules" minWidth="120" width="140"></e-grid-column>
<e-grid-column headerText="@Localizer["Commands"].Value" commands="commands" textAlign="Right" width="120"></e-grid-column>
</e-grid-columns>
Expand All @@ -213,18 +213,22 @@
function actionComplete(args) {
console.log(args);
if (args.requestType === "beginEdit" || args.requestType === "add") {
var dialog = args.dialog;
let dialog = args.dialog;
dialog.element.style.maxHeight = "1000px";
dialog.header = args.requestType === "beginEdit" ? "@Localizer["Edit category"].Value" + args.rowData["Name"] : "@Localizer["Add category"].Value";
}
if (args.requestType === "delete") {
// todo: Show dialog when delete operation is canceled.
var canceled = args.cancel;
if (args.data != null && args.data.length > 0) {
let selectedCategory = args.data[0];
fetch("/Categories/NumberOfTransactionsAssociated?id=" + selectedCategory.Id).then(function (result) { return result.json() }).then(function (data) {
if (data > 0) alert("@Localizer["Cancel message"].Value");
});
}
}
}
function toolbarClick(args) {
var gridObj = document.getElementById("grid").ej2_instances[0];
let gridObj = document.getElementById("grid").ej2_instances[0];
if (args.item.id === "grid_excelexport") {
gridObj.showSpinner();
gridObj.excelExport();
Expand Down
15 changes: 15 additions & 0 deletions webapp/Pages/Categories/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ public async Task<IActionResult> OnGetAsync() {
return Page();
}

public async Task<IActionResult> OnGetNumberOfTransactionsAssociatedAsync(long id) {
if (!(User.Identity?.IsAuthenticated ?? false)) return Redirect("/");

var user = await GetUserAsync();
if (user == null) return Redirect("/");

var transactionsWithCategory = await _databaseContext.Transactions
.AsNoTracking()
.Where(x => x.UserId == user.Id)
.Where(x => x.CategoryId == id)
.ToListAsync();

return new JsonResult(transactionsWithCategory.Count);
}

public async Task<IActionResult> OnPostDataSourceAsync([FromBody] DataManagerRequest dm) {
if (!(User.Identity?.IsAuthenticated ?? false)) return Redirect("/");

Expand Down
6 changes: 3 additions & 3 deletions webapp/Pages/Dashboard.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@
}
document.addEventListener("DOMContentLoaded", function() {
var lineObj = document.getElementById("lineChart").ej2_instances[0];
let lineObj = document.getElementById("lineChart").ej2_instances[0];
lineObj.refresh();
var pieObj = document.getElementById("pieChart").ej2_instances[0];
let pieObj = document.getElementById("pieChart").ej2_instances[0];
pieObj.refresh();
var splineObj = document.getElementById("splineChart").ej2_instances[0];
let splineObj = document.getElementById("splineChart").ej2_instances[0];
splineObj.refresh();
});
</script>
4 changes: 2 additions & 2 deletions webapp/Pages/FixedCosts/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
function actionComplete(args) {
if ((args.requestType === "beginEdit" || args.requestType === "add")) {
var dialog = args.dialog;
let dialog = args.dialog;
dialog.element.style.maxHeight = "1000px";
dialog.header = args.requestType === "beginEdit" ? "@Localizer["Edit transaction"].Value" + args.rowData["Note"] : "@Localizer["Add transaction"].Value";
}
Expand Down Expand Up @@ -197,7 +197,7 @@
}
function toolbarClick(args) {
var gridObj = document.getElementById("grid").ej2_instances[0];
let gridObj = document.getElementById("grid").ej2_instances[0];
if (args.item.id === "grid_excelexport") {
gridObj.showSpinner();
gridObj.excelExport();
Expand Down
5 changes: 1 addition & 4 deletions webapp/Pages/Transactions/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@
var searchSettings = new string[] { "Note", "CategoryId" };
var validationRules = new { required = true };

// todo: date params problem on filtering: time is displayed
var dateEdit = new DatePicker() {
Format = Localizer["Date format"].Value,
Min = DateOnly.MinValue,
Max = DateOnly.MaxValue,
};
var statusParams = new List<object>() {
new { Value = false, Text = Localizer["Pending"].Value },
Expand All @@ -66,7 +63,7 @@
DataSource = statusParams,
Query = "new ej.data.Query()",
Fields = new DropDownListFieldSettings() { Value = "Value", Text = "Text" },
};
};
var categoryParams = Model.Categories.Select(x => new { Value = x.Id, Text = x.Description });
var categoryEdit = new DropDownList() {
DataSource = categoryParams,
Expand Down
3 changes: 3 additions & 0 deletions webapp/Resources/Pages/Categories/Index.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<data name="Add category" xml:space="preserve">
<value>Add category</value>
</data>
<data name="Cancel message" xml:space="preserve">
<value>Cannot be deleted : the category is linked to other transactions.</value>
</data>
<data name="Categories" xml:space="preserve">
<value>Categories</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions webapp/Resources/Pages/Categories/Index.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<data name="Add category" xml:space="preserve">
<value>Créer une catégorie</value>
</data>
<data name="Cancel message" xml:space="preserve">
<value>Suppression impossible : la cat\u00e9gorie est li\u00e9e \u00e0 d\u0027autres transactions.</value>
</data>
<data name="Categories" xml:space="preserve">
<value>Catégories</value>
</data>
Expand Down

0 comments on commit d1f85d1

Please sign in to comment.