Fix the bug of go back from schedule job page

This commit is contained in:
Hua Zhang 2017-01-06 13:21:41 +08:00
Родитель 2866004b3e
Коммит d0f48d5c67
6 изменённых файлов: 30 добавлений и 9 удалений

Просмотреть файл

@ -111,6 +111,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
FilterId = job.FilterId,
FilterName = job.FilterName,
JobName = job.JobName,
OriginalJobId = jobId,
DesiredProperties = twin.Properties.Desired.AsEnumerableFlatten().Select(p => {
return new DesiredPropetiesEditViewModel
{
@ -134,6 +135,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
FilterId = job.FilterId,
FilterName = job.FilterName,
JobName = job.JobName,
OriginalJobId = jobId,
MethodName = job.MethodName,
Parameters = parameters.Select(pair => new MethodParameterEditViewModel
{
@ -189,7 +191,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
await _jobRepository.AddAsync(new JobRepositoryModel(jobId, model.FilterId, model.JobName, deviceListFilter.Name, null));
return Redirect("/Job/Index");
return RedirectToAction("Index", "Job", new { jobId = jobId });
}
[RequirePermission(Permission.ManageJobs)]
@ -226,7 +228,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
await _jobRepository.AddAsync(new JobRepositoryModel(jobId, model.FilterId, model.JobName, deviceListFilter.Name, model.MethodName));
return Redirect("/Job/Index");
return RedirectToAction("Index", "Job", new { jobId = jobId });
}
private async Task<Tuple<string, string, string>> GetJobNameAndFilterNameAsync(DeviceJobModel job)

Просмотреть файл

@ -11,6 +11,8 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
[Required]
public string FilterName { get; set; }
public string OriginalJobId { get; set; }
[Required]
public string JobName { get; set; }

Просмотреть файл

@ -12,6 +12,7 @@
function viewModel() {
var self = this;
this.backUrl = ko.observable(resources.redirectToDeviceIndexUrl);
this.filterId = "";
this.jobName = ko.observable("");
this.methodName = ko.observable("");
@ -116,7 +117,7 @@
this.backButtonClicked = function () {
location.href = resources.redirectUrl;
location.href = self.backUrl();
}
this.beforePost = function (elem) {
@ -161,7 +162,12 @@
if (data) {
self.filterName = data.FilterName;
self.filterId = data.FilterId;
self.jobName(data.JobName);
if (resources.originalJobId) {
self.backUrl(resources.redirectToJobIndexUrl + "?jobId=" + resources.originalJobId);
self.jobName(data.JobName);
} else {
self.backUrl(resources.redirectToDeviceIndexUrl + "?filterId=" + self.filterId);
}
self.clonedMethodName = data.MethodName;
self.clonedMethodParameters = data.Parameters;
self.maxExecutionTime(data.MaxExecutionTimeInMinutes);

Просмотреть файл

@ -24,6 +24,7 @@
function viewModel() {
var self = this;
this.backUrl = ko.observable(resources.redirectToDeviceIndexUrl);
this.jobName = ko.observable("");
this.properties = ko.observableArray();
this.tags = ko.observableArray();
@ -64,7 +65,7 @@
}
this.backButtonClicked = function () {
location.href = resources.redirectUrl;
location.href = self.backUrl();
}
this.removeProperty = function (prop) {
@ -117,9 +118,15 @@
this.init = function (data) {
if (data) {
self.jobName(data.JobName);
self.maxExecutionTime(data.MaxExecutionTimeInMinutes);
self.filterId = data.FilterId;
self.jobName(data.JobName);
if (resources.originalJobId) {
self.backUrl(resources.redirectToJobIndexUrl + "?jobId=" + resources.originalJobId);
self.jobName(data.JobName);
} else {
self.backUrl(resources.redirectToDeviceIndexUrl + "?filterId=" + self.filterId);
}
self.maxExecutionTime(data.MaxExecutionTimeInMinutes);
if (!data.DesiredProperties || data.DesiredProperties.length == 0) {
self.properties.push(new PropertiesEditItem("", "", false));

Просмотреть файл

@ -136,7 +136,9 @@
"use strict";
var resources = {
redirectUrl: '@Url.Action("Index", "Device")',
redirectToDeviceIndexUrl: '@Url.Action("Index", "Device")',
redirectToJobIndexUrl: '@Url.Action("Index", "Job")',
originalJobId: '@Html.JavaScriptString(Model.OriginalJobId)',
SomeDevicesApplicable: '@Html.JavaScriptString(Strings.SomeDevicesApplicable)',
SomeDeviceInapplicable: '@Html.JavaScriptString(Strings.SomeDeviceInapplicable)',
failedToCreateTempFilter: '@Html.JavaScriptString(Strings.FailedToCreateTempFilter)',

Просмотреть файл

@ -158,7 +158,9 @@
"use strict";
var resources = {
redirectUrl: '@Url.Action("Index", "Device")',
redirectToDeviceIndexUrl: '@Url.Action("Index", "Device")',
redirectToJobIndexUrl: '@Url.Action("Index", "Job")',
originalJobId: '@Html.JavaScriptString(Model.OriginalJobId)',
TotalDeviceString: "@Html.JavaScriptString(Strings.FilteredDeviceCount)",
LoadingText: "@Html.JavaScriptString(Strings.LoadingText)"
}