Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/ExperimentController.cs @ 9324

Last change on this file since 9324 was 9324, checked in by fschoepp, 11 years ago

#1888:

  • DAL: Added a Delete method which deletes by experiment id.
  • HL DataTables will now be transposed and mapped as double[ROWS][COLUMNS] (transposed)
  • JS: Moved all classes into "modules" to prevent namespace pollution (using OAAS_MODEL for model classes, OAAS_VIEW for views and OAAS_CONTROLLER for controllers)
  • JS: Moved DatatypeMapper classes into Backbone views
  • JS: Models now correctly send DELETE requests
  • Added a new job overview page (which also renders run details) using AJAX
  • Using moment.min.js to format DateTime as string
  • Controllers now inherit from BaseController which provides a RedirectToLoginIfNecessary-method
  • Added loading animations to several AJAX bound places (loading experiments / scenarios)
  • Added a section to _Layout.cshtml which allows page-specific JavaScript includes (<script> only for a certain page)
  • Fixed Build/Edit of experiment menu redirecting to the wrong page
  • The Experiment Variation Dialog disables input fields, if the property has not been activated before
File size: 5.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using HeuristicLab.Services.Optimization.Web.Models;
7using HeuristicLab.Services.Optimization.Web.Helpers;
8using HeuristicLab.Services.Optimization.ControllerService.Model;
9using System.Web.Security;
10using Mvc3TestApplication.Binders;
11using HeuristicLab.Services.Optimization.ControllerService.Parsers;
12
13namespace HeuristicLab.Services.Optimization.Web.Controllers
14{
15    [Authorize(Roles = "Web User")]
16    public class ExperimentController : BaseController
17    {
18        //
19        // GET: /Experiment/
20
21        public ActionResult Index()
22        {
23          RedirectToLoginIfNecessary("%2fExperiment%2fIndex");
24          return RedirectToAction("New", "Experiment");
25          /*var model = new ExperimentViewModel();
26          var scenarios = ControllerService.withControllerService<IEnumerable<string>>((service) => {
27            return service.GetOptimizationScenarioNames();
28          });
29          var experiments = ControllerService.withControllerService<IEnumerable<string>>((service) => {
30            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
31            return service.GetExperimentNames(u);
32          });
33          foreach (var experiment in experiments)
34            model.Experiments.Add(experiment);
35          foreach (var scenario in scenarios)
36            model.Scenarios.Add(scenario);
37
38          return View(model);*/
39        }
40
41        public ActionResult New() {
42          RedirectToLoginIfNecessary("%2fExperiment%2fNew");
43          return View();
44        }
45
46        public ActionResult NewEdit() {
47          RedirectToLoginIfNecessary("%2fExperiment%2fNewEdit");
48          return View();
49        }
50
51
52        public ActionResult Edit() {
53          var model = new ExperimentViewModel();
54          var experiments = ControllerService.withControllerService<IEnumerable<string>>((service) => {
55            User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
56            return service.GetExperimentNames(u);
57          });
58          foreach (var experiment in experiments)
59            model.Experiments.Add(experiment);
60          return View(model);
61        }
62
63      #region new experiment methdos
64      [HttpGet]
65      public ActionResult Scenario(string nodeId) {
66        var optimizationScenario = ControllerService.withControllerService<OptimizationScenario>(service => {
67          return service.GetOptimizationScenarioByName(nodeId);
68        });
69        return Content(AlgorithmConverter.ConvertScenarioToJson(optimizationScenario).ToString(), "application/json", System.Text.Encoding.UTF8);
70      }
71
72      [HttpGet]
73      public ActionResult ExperimentList() {
74        var experiments = ControllerService.withControllerService<IEnumerable<Experiment>>(service => {
75          User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
76          return service.GetExperiments(u, namesOnly: true);
77        });
78        return Content(AlgorithmConverter.ConvertExperimentsToJson(experiments).ToString(), "application/json", System.Text.Encoding.UTF8);
79      }
80
81      [HttpGet]
82      public ActionResult ScenarioList() {
83        var scenarios = ControllerService.withControllerService<IEnumerable<OptimizationScenario>>(service => {
84          User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
85          return service.GetOptimizationScenarios();
86        });
87        return Content(AlgorithmConverter.ConvertScenariosToJson(scenarios).ToString(), "application/json", System.Text.Encoding.UTF8);
88      }
89
90      [HttpPut]
91      public JsonResult Experiment(string nodeId, [ExperimentJson] Experiment exp) {
92        return Json(
93            new {
94              nodeId = ControllerService.withControllerService<string>(service => {
95                User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
96                return service.SaveExperiment(u, exp);
97              })
98            });
99      }
100
101      [HttpPost]
102      public JsonResult Experiment([ExperimentJson] Experiment exp) {
103        return Json(
104            new {
105              nodeId = ControllerService.withControllerService<string>(service => {
106                User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
107                return service.SaveExperiment(u, exp);
108              })
109            });
110      }
111
112      [HttpDelete]
113      [ActionName("Experiment")]
114      public JsonResult DeleteExperiment(string nodeId) {
115        var isExperimentDeleted = ControllerService.withControllerService<bool>(service => {
116          User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
117          return service.DeleteExperiment(u, nodeId);
118        });
119        return Json(isExperimentDeleted, JsonRequestBehavior.DenyGet);
120      }
121
122      [HttpGet]
123      public ActionResult Experiment(string nodeId) {
124        var experiment = ControllerService.withControllerService<Experiment>(service => {
125          User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
126          return service.GetExperimentById(u, nodeId);
127        });
128        var str = AlgorithmConverter.ConvertExperimentToJson(experiment).ToString();
129        return Content(str, "application/json", System.Text.Encoding.UTF8);
130      }
131      #endregion
132    }
133}
Note: See TracBrowser for help on using the repository browser.