Files
richard-churchman 811c938462 Improved Case Automation POST body conext and other minor issues:
* Pushed Case Workflow Display HTML rendering logic down into a controller for improved security and consistent tokenisation of the Jube token format against context. Included a migration to update the default demo entry to use proper tokenisation. Updated the repository to support fetching CaseWorkflowDisplay with appropriate security.
* Implemented improved tokenisation of the EntityAnalysisModelInstanceEntryPayload model via a common extension method on EntityAnalysisModelInstanceEntryPayload, used consistently across the system for serialisation and storage.
* Included a migration to update the tokenisation format for full CaseWorkflowDisplay support.
* Fixed an issue where CaseWorkflowFilter was incorrectly filtering on CaseWorkflowStatus.Guid instead of CaseWorkflowStatus.Name, causing the GUID to be returned rather than the display name on the template/demo model. (The remainder was fixed in GitHub issue #6.) Included a migration with a corrective SQL statement.
* Fixed an issue where tokens were not being stored alongside CaseWorkflowFilter definition configuration. It now behaves identically to CaseSearch. Note: migrating missing tokens is not feasible as it requires JS-side parsing via JQueryBuilder.
* Reduced the size of the CaseWorkflowForm invocation to include only the required fields given the new POST body context being rendered server side. Improved API serialisation by using a dictionary for form payload keys and values.
* Consolidated JSON serialisation settings into DI and updated usages throughout.
* Updated EntityAnalysisModelInstanceEntryPayload write serialisers to handle deserialisation, which is required to support tokenisation of new Case Automation POST bodies.
* Created an extension method on the EntityAnalysisModelInstanceEntryPayload to centralise tokenisation of strings across Activation and Case Automation on a consistent basis. Simplified Case Notification and Case HTTP dispatch by removing tokenisation logic from those classes.
* Removed a redundant field from the CaseWorkflowFormEntry POCO (database left unchanged for now).
* Fixed a bug in Case session SQL rebuilding where the rebuild date was not being correctly checked for null or default value, which caused a failure in the last migration.
* Made minor modifications to the Create Case process and method signature to skip serialisation when the payload object required for tokenisation is already available on the thread (e.g. during synchronous reprocessing).
* Updated Case Workflow Macro processing to fetch the archive payload for the case from the database, improving security of that invocation endpoint.
* Removed what appeared to be a duplicate EntityAnalysisModelInstanceEntryPayload model introduced during refactoring.
* Fixed a but in Case Worfkflow Display Role assigment owing to volatile Guid in its update.
2026-02-22 13:08:42 +02:00

424 lines
14 KiB
JavaScript

// noinspection ES6ConvertVarToLetConst,JSUnresolvedVariable,HtmlUnknownAttribute,JSObsoletePrivateAccessSyntax,JSUnusedLocalSymbols
/* Copyright (C) 2022-present Jube Holdings Limited.
*
* This file is part of Jube™ software.
*
* Jube™ is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Jube™ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License along with Jube™. If not,
* see <https://www.gnu.org/licenses/>.
*/
var currentCaseWorkflowGuid;
var currentCaseWorkflowFilterGuid;
var currentCaseSessionGuid;
var dateFields = [];
var caseId;
var jsonChangedFromFilterDefault;
function OnChange(e) {
var grid = e.sender;
var currentDataItem = grid.dataItem(this.select());
if (currentDataItem["Id"] > 0) {
caseId = currentDataItem["Id"];
$('#Fetch').show();
$('#FetchSet').text('Selected Case Id = ' + caseId);
}
}
function GenerateGrid(gridData) {
var model = GenerateModel(gridData[0]);
var columns = GenerateColumns(gridData[0]);
if (dateFields.length > 0) {
var parseFunction = function (response) {
for (var i = 0; i < response.length; i++) {
for (var fieldIndex = 0; fieldIndex < dateFields.length; fieldIndex++) {
var record = response[i];
record[dateFields[fieldIndex]] = kendo.parseDate(record[dateFields[fieldIndex]]);
}
}
return response;
};
}
$("#grid").kendoGrid({
dataSource: {
data: gridData,
schema: {
model: model
}
},
columns: columns,
groupable: true,
toolbar: ["excel"],
excel: {
fileName: "Cases.xlsx",
proxyURL: "https://proxy.jube.io",
filterable: true,
allPages: true
},
selectable: true,
change: OnChange,
dataBound: SetColor,
height: 500
});
}
function FormatColumnName(data) {
return data;
}
function GenerateColumns(gridData) {
var columns = [];
for (var property in gridData) {
if (Object.prototype.hasOwnProperty.call(gridData, property)) {
var column = {};
column["width"] = "400px;";
column["field"] = property;
column["title"] = FormatColumnName(property);
if (property === 'ForeColor' || property === 'BackColor') {
column["hidden"] = true;
}
columns.push(column);
}
}
return columns;
}
function GenerateModel(gridData) {
var model = {};
model.id = "Id";
var fields = {};
for (var property in gridData) {
if (Object.prototype.hasOwnProperty.call(gridData, property)) {
var propType = typeof gridData[property];
if (propType === "number") {
fields[property] = {
type: "number",
validation: {
required: true
}
};
} else if (propType === "boolean") {
fields[property] = {
type: "boolean",
validation: {
required: true
}
};
} else if (propType === "string") {
var parsedDate = kendo.parseDate(gridData[property]);
if (parsedDate) {
fields[property] = {
type: "date",
validation: {
required: true
}
};
dateFields.push(property);
} else {
fields[property] = {
validation: {
required: true
}
};
}
} else {
fields[property] = {
validation: {
required: true
}
};
}
}
}
model.fields = fields;
return model;
}
function DestroyGrid() {
var grid = $('#grid').data('kendoGrid');
if (typeof grid !== "undefined") {
grid.destroy();
$("#grid").empty();
}
}
function ExecuteCasesInSession() {
DestroyGrid();
$.get("../api/SessionCaseSearchCompiledSql/ByGuid/" + currentCaseSessionGuid,
function (data) {
GenerateGrid(data);
});
}
function SetColor() {
var grid = $('#grid').data('kendoGrid');
var rows = grid.tbody.children();
for (var j = 0; j < rows.length; j++) {
var row = $(rows[j]);
var dataItem = grid.dataItem(row);
var backColor = dataItem.get("BackColor");
var foreColor = dataItem.get("ForeColor");
row.css("background-color", backColor);
row.css("color", foreColor);
}
}
function OnSelect(e) {
var kitems = $(e.node).add($(e.node).parentsUntil('.k-treeview', '.k-item'));
var texts = $.map(kitems,
function (kitem) {
return $(kitem).find('>div span.k-in').text();
});
var treeview = $("#Tree").getKendoTreeView();
var item = treeview.dataItem(e.node);
if (typeof item.parentNode() !== "undefined") {
if (typeof item.caseWorkflowId !== "undefined") {
$.get("../api/CaseWorkflowFilter/ByGuid/" + item.guid,
function (data) {
if (typeof data !== "undefined") {
const currentBuildJson = {
filterJson: JSON.parse(data.filterJson),
selectJson: JSON.parse(data.selectJson),
};
if (data.filterTokens !== "undefined") {
currentBuildJson["filterTokens"] = JSON.parse(data.filterTokens);
}
CompileSqlOnServer(data.filterJson, data.selectJson, null, item.parentNode().guid, item.guid, item.guid, true, true);
initCaseFilterBuilder(true, currentCaseWorkflowGuid, currentBuildJson);
jsonChangedFromFilterDefault = false;
}
});
} else {
$.get("../api/SessionCaseSearchCompiledSql/ByLast/",
function (data) {
if (!data.notFound) {
if (typeof data !== "undefined") {
const currentBuildJson = {
filterJson: JSON.parse(data.filterJson),
selectJson: JSON.parse(data.selectJson)
};
if (data.filterTokens !== "undefined") {
currentBuildJson["filterTokens"] = JSON.parse(data.filterTokens);
}
CompileSqlOnServer(data.filterJson, data.selectJson, data.filterTokens, data.caseWorkflowGuid, data.caseWorkflowFilterGuid, true, true);
initCaseFilterBuilder(true, currentCaseWorkflowGuid, currentBuildJson);
jsonChangedFromFilterDefault = true;
ShowButtons();
}
}
});
}
} else {
return false;
}
}
function ShowButtons() {
$("#Peek").show();
$("#Skim").show();
}
function SetParentNodeInTree() {
var tree = $('#Tree').data('kendoTreeView');
let selected = tree.select();
let item = tree.dataItem(selected);
tree.findByUid(item.parentNode().uid);
let selectItem = tree.findByUid((item.parentNode().uid));
tree.select(selectItem);
}
function CompileSqlOnServer(filterJson, selectJson, filterTokens, caseWorkflowGuid, caseWorkflowFilterGuid, refreshGrid, ignoreChanges) {
const newFilterBuilder = {
filterJson: filterJson,
selectJson: selectJson,
filterTokens: filterTokens,
caseWorkflowGuid: caseWorkflowGuid,
caseWorkflowFilterGuid: caseWorkflowFilterGuid
};
currentCaseWorkflowGuid = caseWorkflowGuid;
currentCaseWorkflowFilterGuid = caseWorkflowFilterGuid;
if (!ignoreChanges) {
if (!jsonChangedFromFilterDefault) {
if (typeof initialFilterBuilder !== "undefined") {
let filterBuilderChanged;
if (initialFilterBuilder.filterJson !== newFilterBuilder.filterJson
|| initialFilterBuilder.selectJson !== newFilterBuilder.selectJson) {
newFilterBuilder.caseWorkflowFilterGuid = null;
SetParentNodeInTree();
jsonChangedFromFilterDefault = true;
}
}
}
}
$.ajax({
url: "../api/SessionCaseSearchCompiledSql/",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(newFilterBuilder),
success: function (data) {
if (typeof data !== "undefined") {
currentCaseSessionGuid = data.guid;
if (refreshGrid) {
ExecuteCasesInSession();
ShowButtons();
}
}
}
});
}
$(document).ready(function () {
$("#Fetch").kendoButton({
click: function (e) {
window.location.href = '/Case/Case?CaseId=' + caseId;
}
}).hide();
$("#Skim").kendoButton({
click: function (e) {
var builderResult = getCasesFilter();
CompileSqlOnServer(builderResult.filterJson, builderResult.selectJson, builderResult.filterTokens, currentCaseWorkflowGuid, currentCaseWorkflowFilterGuid, false, false);
window.location.href = '/Case/Case?SessionCaseSearchCompiledSqlControllerGuid=' + currentCaseSessionGuid;
}
}).hide();
$("#Peek").kendoButton({
click: function (e) {
var builderResult = getCasesFilter();
CompileSqlOnServer(builderResult.filterJson, builderResult.selectJson, builderResult.filterTokens, currentCaseWorkflowGuid, currentCaseWorkflowFilterGuid, true, false);
}
}).hide();
const filter = {
transport: {
read: {
url: '../api/CaseWorkflowFilter/ByCasesWorkflowGuidActiveOnly',
dataType: "json"
}
},
schema: {
model: {
id: "guid",
hasChildren: false
}
}
};
const workflow = {
transport: {
read: {
url: '../api/CaseWorkflow/ByEntityAnalysisModelGuidActiveOnly',
dataType: "json"
}
},
schema: {
model: {
id: "guid",
hasChildren: true,
children: filter
}
}
};
const model = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: '../api/EntityAnalysisModel',
dataType: "json"
}
},
schema: {
model: {
id: 'guid',
hasChildren: true,
children: workflow
}
}
});
$.get("../api/SessionCaseSearchCompiledSql/ByLast/",
function (data) {
if (!data.notFound) {
if (typeof data !== "undefined") {
currentCaseWorkflowGuid = data.caseWorkflowGuid;
currentCaseWorkflowFilterGuid = data.caseWorkflowFilterGuid;
currentCaseSessionGuid = data.guid;
const currentBuildJson = {
filterJson: JSON.parse(data.filterJson),
selectJson: JSON.parse(data.selectJson)
};
initCaseFilterBuilder(true, currentCaseWorkflowGuid, currentBuildJson);
ExecuteCasesInSession();
ShowButtons();
}
}
var tree = $("#Tree").kendoTreeView({
dataSource: model,
dataTextField: "name",
select: OnSelect,
dataBound: function (e) {
var tree = $("#Tree").getKendoTreeView();
tree.expand(".k-item");
if (typeof e.node !== "undefined") {
var caseWorkflowItem = tree.dataItem(e.node);
if (caseWorkflowItem.guid === currentCaseWorkflowGuid
&& (typeof currentCaseWorkflowFilterGuid === "undefined"
|| currentCaseWorkflowFilterGuid === "00000000-0000-0000-0000-000000000000")) {
tree.findByUid(caseWorkflowItem.uid);
let selectItem = tree.findByUid(caseWorkflowItem.uid);
tree.select(selectItem);
jsonChangedFromFilterDefault = true;
} else {
if (caseWorkflowItem.hasChildren && (typeof currentCaseWorkflowFilterGuid !== "undefined"
&& currentCaseWorkflowFilterGuid !== "00000000-0000-0000-0000-000000000000")) {
var caseWorkflowFilterItems = caseWorkflowItem.children.data();
for (var i = 0; i < caseWorkflowFilterItems.length; i++) {
let caseWorkflowFilterItem = caseWorkflowFilterItems[i];
if (caseWorkflowFilterItem.guid === currentCaseWorkflowFilterGuid) {
tree.findByUid(caseWorkflowFilterItem.uid);
let selectItem = tree.findByUid(caseWorkflowFilterItem.uid);
tree.select(selectItem);
jsonChangedFromFilterDefault = false;
}
}
}
}
}
}
});
}
);
});
//# sourceURL=CaseSearch.js