mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Merge pull request #5671 from RoyalVeterinaryCollege/4352
#4352: orphaned awaitingactivities Fixes #4352
This commit is contained in:
@@ -23,6 +23,7 @@ using Orchard.UI.Notify;
|
|||||||
using Orchard.Workflows.Models;
|
using Orchard.Workflows.Models;
|
||||||
using Orchard.Workflows.Services;
|
using Orchard.Workflows.Services;
|
||||||
using Orchard.Workflows.ViewModels;
|
using Orchard.Workflows.ViewModels;
|
||||||
|
using Orchard.Workflows.Helpers;
|
||||||
|
|
||||||
namespace Orchard.Workflows.Controllers {
|
namespace Orchard.Workflows.Controllers {
|
||||||
[ValidateInput(false)]
|
[ValidateInput(false)]
|
||||||
@@ -234,7 +235,7 @@ namespace Orchard.Workflows.Controllers {
|
|||||||
dynamic activity = new JObject();
|
dynamic activity = new JObject();
|
||||||
activity.Name = x.Name;
|
activity.Name = x.Name;
|
||||||
activity.Id = x.Id;
|
activity.Id = x.Id;
|
||||||
activity.ClientId = x.Name + "_" + x.Id;
|
activity.ClientId = x.GetClientId();
|
||||||
activity.Left = x.X;
|
activity.Left = x.X;
|
||||||
activity.Top = x.Y;
|
activity.Top = x.Y;
|
||||||
activity.Start = x.Start;
|
activity.Start = x.Start;
|
||||||
@@ -259,7 +260,7 @@ namespace Orchard.Workflows.Controllers {
|
|||||||
|
|
||||||
[HttpPost, ActionName("Edit")]
|
[HttpPost, ActionName("Edit")]
|
||||||
[FormValueRequired("submit.Save")]
|
[FormValueRequired("submit.Save")]
|
||||||
public ActionResult EditPost(int id, string localId, string data) {
|
public ActionResult EditPost(int id, string localId, string data, bool clearWorkflows) {
|
||||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows")))
|
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
@@ -275,7 +276,6 @@ namespace Orchard.Workflows.Controllers {
|
|||||||
var activitiesIndex = new Dictionary<string, ActivityRecord>();
|
var activitiesIndex = new Dictionary<string, ActivityRecord>();
|
||||||
|
|
||||||
workflowDefinitionRecord.ActivityRecords.Clear();
|
workflowDefinitionRecord.ActivityRecords.Clear();
|
||||||
workflowDefinitionRecord.WorkflowRecords.Clear();
|
|
||||||
|
|
||||||
foreach (var activity in state.Activities) {
|
foreach (var activity in state.Activities) {
|
||||||
ActivityRecord activityRecord;
|
ActivityRecord activityRecord;
|
||||||
@@ -303,9 +303,32 @@ namespace Orchard.Workflows.Controllers {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (clearWorkflows) {
|
||||||
|
workflowDefinitionRecord.WorkflowRecords.Clear();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach (var workflowRecord in workflowDefinitionRecord.WorkflowRecords) {
|
||||||
|
// Update any awaiting activity records with the new activity record.
|
||||||
|
foreach (var awaitingActivityRecord in workflowRecord.AwaitingActivities) {
|
||||||
|
var clientId = awaitingActivityRecord.ActivityRecord.GetClientId();
|
||||||
|
if (activitiesIndex.ContainsKey(clientId)) {
|
||||||
|
awaitingActivityRecord.ActivityRecord = activitiesIndex[clientId];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
workflowRecord.AwaitingActivities.Remove(awaitingActivityRecord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Remove any workflows with no awaiting activities.
|
||||||
|
if (!workflowRecord.AwaitingActivities.Any()) {
|
||||||
|
workflowDefinitionRecord.WorkflowRecords.Remove(workflowRecord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Services.Notifier.Information(T("Workflow saved successfully"));
|
Services.Notifier.Information(T("Workflow saved successfully"));
|
||||||
|
|
||||||
return RedirectToAction("Edit", new { id, localId });
|
// Don't pass the localId to force the activites to refresh and use the deterministic clientId.
|
||||||
|
return RedirectToAction("Edit", new { id });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost, ActionName("Edit")]
|
[HttpPost, ActionName("Edit")]
|
||||||
|
|||||||
@@ -38,5 +38,14 @@ namespace Orchard.Workflows.Models {
|
|||||||
/// containing this activity.
|
/// containing this activity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual WorkflowDefinitionRecord WorkflowDefinitionRecord { get; set; }
|
public virtual WorkflowDefinitionRecord WorkflowDefinitionRecord { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Id which can be used on the client.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An unique Id to represent this activity on the client.</returns>
|
||||||
|
public string GetClientId() {
|
||||||
|
return Name + "_" + Id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
Style.Require("WorkflowsAdmin");
|
Style.Require("WorkflowsAdmin");
|
||||||
Style.Require("WorkflowsActivities");
|
Style.Require("WorkflowsActivities");
|
||||||
Style.Require("jQueryUI_Orchard");
|
Style.Require("jQueryUI_Orchard");
|
||||||
|
Script.Require("jQueryUI_Dialog").AtFoot();
|
||||||
Script.Require("jsPlumb").AtFoot();
|
Script.Require("jsPlumb").AtFoot();
|
||||||
Script.Include("orchard-workflows-serialize.js").AtFoot();
|
Script.Include("orchard-workflows-serialize.js").AtFoot();
|
||||||
Script.Include("orchard-workflows.js").AtFoot();
|
Script.Include("orchard-workflows.js").AtFoot();
|
||||||
@@ -74,23 +75,41 @@
|
|||||||
@Html.Hidden("data", String.Empty)
|
@Html.Hidden("data", String.Empty)
|
||||||
|
|
||||||
@Html.Hidden("confirm-delete-activity", T("Are you sure you want to remove this activity?"))
|
@Html.Hidden("confirm-delete-activity", T("Are you sure you want to remove this activity?"))
|
||||||
@Html.Hidden("confirm-delete-instances", T("Are you sure you want to remove running instances of this workflow?"))
|
@Html.Hidden("confirm-delete-instances", T("You have running instances of this workflow, do you want to stop them?"))
|
||||||
|
|
||||||
using (Script.Foot()) {
|
using (Script.Foot()) {
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
//<![CDATA[
|
//<![CDATA[
|
||||||
$("form").submit(function () {
|
$("form").submit(function (e, submit, clearWorkflows) {
|
||||||
saveLocal(localId);
|
if(submit){
|
||||||
var workflow = loadWorkflow(localId);
|
saveLocal(localId);
|
||||||
var data = JSON.stringify(workflow);
|
var workflow = loadWorkflow(localId);
|
||||||
$("[name='data']").val(data);
|
var data = JSON.stringify(workflow);
|
||||||
|
$("[name='data']").val(data);
|
||||||
|
var values = [$("<input>", { type: "hidden", name: "clearWorkflows", value: clearWorkflows }), $("<input>", { type: "hidden", name: "submit.Save", value: "Save" })];
|
||||||
|
$(this).append(values);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: stateUrl + "/" + $("#id").val(),
|
url: stateUrl + "/" + $("#id").val(),
|
||||||
async: false,
|
async: false,
|
||||||
success: function(state) {
|
success: function(state) {
|
||||||
if(state.isRunning && !confirm($("#confirm-delete-instances").val())) {
|
if (state.isRunning) {
|
||||||
e.preventDefault();
|
var dialog = $('<p>' + $("#confirm-delete-instances").val() + '</p>').dialog({
|
||||||
|
buttons: {
|
||||||
|
'@T("Yes")': function() { $('form').trigger('submit', [true, true]); },
|
||||||
|
'@T("No")': function() { $('form').trigger('submit', [true, false]); },
|
||||||
|
'@T("Cancel")': function() {
|
||||||
|
dialog.dialog('close');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('form').trigger('submit', [true, false]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user