Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 11813 was 9324, checked in by fschoepp, 12 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
RevLine 
[9215]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;
[9227]10using Mvc3TestApplication.Binders;
11using HeuristicLab.Services.Optimization.ControllerService.Parsers;
[9215]12
13namespace HeuristicLab.Services.Optimization.Web.Controllers
14{
15    [Authorize(Roles = "Web User")]
[9324]16    public class ExperimentController : BaseController
[9215]17    {
18        //
19        // GET: /Experiment/
20
21        public ActionResult Index()
22        {
[9324]23          RedirectToLoginIfNecessary("%2fExperiment%2fIndex");
24          return RedirectToAction("New", "Experiment");
[9305]25          /*var model = new ExperimentViewModel();
[9215]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 };
[9305]31            return service.GetExperimentNames(u);
[9215]32          });
33          foreach (var experiment in experiments)
34            model.Experiments.Add(experiment);
35          foreach (var scenario in scenarios)
36            model.Scenarios.Add(scenario);
[9227]37
[9305]38          return View(model);*/
[9215]39        }
40
[9227]41        public ActionResult New() {
[9324]42          RedirectToLoginIfNecessary("%2fExperiment%2fNew");
[9305]43          return View();
[9227]44        }
45
[9305]46        public ActionResult NewEdit() {
[9324]47          RedirectToLoginIfNecessary("%2fExperiment%2fNewEdit");
[9305]48          return View();
[9215]49        }
50
[9324]51
[9215]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 };
[9305]56            return service.GetExperimentNames(u);
[9215]57          });
58          foreach (var experiment in experiments)
59            model.Experiments.Add(experiment);
60          return View(model);
[9324]61        }
[9215]62
[9305]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 };
[9324]76          return service.GetExperiments(u, namesOnly: true);
[9305]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 => {
[9227]95                User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
[9305]96                return service.SaveExperiment(u, exp);
[9227]97              })
98            });
[9305]99      }
[9227]100
[9305]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              })
[9227]109            });
[9305]110      }
[9227]111
[9324]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      }
[9227]121
[9305]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
[9215]132    }
133}
Note: See TracBrowser for help on using the repository browser.