1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Web;
|
---|
5 | using System.Web.Mvc;
|
---|
6 | using HLWebOKBQueryPlugin.Models;
|
---|
7 | using HLWebOKBQueryPlugin.Helpers;
|
---|
8 | using HLWebOKBQueryPlugin.OKBQueryService;
|
---|
9 |
|
---|
10 | namespace HLWebOKBQueryPlugin.Controllers
|
---|
11 | {
|
---|
12 | /// <summary>
|
---|
13 | /// Controller for the filter subpage.
|
---|
14 | /// </summary>
|
---|
15 | public class FilterController : Controller
|
---|
16 | {
|
---|
17 | //
|
---|
18 | // GET: /Filter/
|
---|
19 |
|
---|
20 | [ChildActionOnly]
|
---|
21 | public ActionResult Filters()
|
---|
22 | {
|
---|
23 | // Model
|
---|
24 | FilterModel qm = new FilterModel();
|
---|
25 |
|
---|
26 |
|
---|
27 | //TODO nicht immer laden
|
---|
28 | QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester");
|
---|
29 | List<Filter> filterList = client.GetFilters().ToList();
|
---|
30 | qm.Filters = filterList;
|
---|
31 | qm.SelectedFilters = new List<Filter>();
|
---|
32 |
|
---|
33 |
|
---|
34 | // For ModelViewuUserControl
|
---|
35 | return PartialView("Filters", qm); // name of usercontrol
|
---|
36 | }
|
---|
37 |
|
---|
38 | //List<Filter> currentFilters
|
---|
39 |
|
---|
40 | [ChildActionOnly]
|
---|
41 | public ActionResult Filters(FilterModel qms)
|
---|
42 | {
|
---|
43 | // Model
|
---|
44 | FilterModel qm = new FilterModel();
|
---|
45 |
|
---|
46 |
|
---|
47 | //TODO nicht immer laden
|
---|
48 | QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester");
|
---|
49 | List<Filter> filterList = client.GetFilters().ToList();
|
---|
50 | qm.Filters = filterList;
|
---|
51 | qm.SelectedFilters =qms.SelectedFilters;
|
---|
52 | if (qm.SelectedFilters == null)
|
---|
53 | {
|
---|
54 |
|
---|
55 | qm.SelectedFilters = new List<Filter>();
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 |
|
---|
60 | // For ModelViewuUserControl
|
---|
61 | return PartialView("Filters", qm); // name of usercontrol
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 | /// <summary>
|
---|
69 | /// This action will be called from the Filters.ascx
|
---|
70 | /// when submitting the form.
|
---|
71 | /// </summary>
|
---|
72 | /// <param name="collection"></param>
|
---|
73 | /// <returns></returns>
|
---|
74 | public ActionResult AddFilter(FormCollection collection)
|
---|
75 | {
|
---|
76 |
|
---|
77 |
|
---|
78 | // Model
|
---|
79 | FilterModel qm = new FilterModel();
|
---|
80 |
|
---|
81 | // Get filters from service and set the model
|
---|
82 | QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester");
|
---|
83 | List<Filter> filterList = client.GetFilters().ToList();
|
---|
84 | qm.Filters = filterList;
|
---|
85 |
|
---|
86 |
|
---|
87 | // Selected filter (from combobox)
|
---|
88 | string filterType = collection.Get("filtersCombobox");
|
---|
89 |
|
---|
90 | if (filterType != null)
|
---|
91 | {
|
---|
92 |
|
---|
93 | Filter filter = filterList.Where(x => x.FilterTypeName.CompareTo(filterType) == 0).First();
|
---|
94 |
|
---|
95 |
|
---|
96 | if (filter != null)
|
---|
97 | {
|
---|
98 | // Get selected filters form session
|
---|
99 | qm.SelectedFilters = (List<Filter>)Session["selectedFilters"];
|
---|
100 | if (qm.SelectedFilters == null)
|
---|
101 | {
|
---|
102 |
|
---|
103 | qm.SelectedFilters = new List<Filter>();
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | // Add Filter only if not exists
|
---|
108 | if (qm.SelectedFilters.Where(x => x.FilterTypeName.Equals(filter.FilterTypeName)).Count() == 0)
|
---|
109 | {
|
---|
110 |
|
---|
111 | qm.SelectedFilters.Add(filter);
|
---|
112 | }
|
---|
113 |
|
---|
114 | // Set values for the selected filters
|
---|
115 | foreach (string s in collection.AllKeys)
|
---|
116 | {
|
---|
117 | if (s.StartsWith("valueTextbox"))
|
---|
118 | {
|
---|
119 | // Get the type of the textbox
|
---|
120 | string type = s.Substring(s.IndexOf(".") + 1);
|
---|
121 |
|
---|
122 | // Get the filter from the selected filters to set the value(s)
|
---|
123 | Filter f = qm.SelectedFilters.Where(x => x.GetType().Name.Equals(type)).First();
|
---|
124 | if ("StringComparisonFilter".Equals(type))
|
---|
125 | {
|
---|
126 | ((StringComparisonFilter)f).Value = collection.Get(s);
|
---|
127 | }
|
---|
128 | else if ("NameStringComparisonFilter".Equals(type))
|
---|
129 | {
|
---|
130 | ((NameStringComparisonFilter)f).Value = collection.Get(s);
|
---|
131 | }
|
---|
132 | else if ("CombinedFilter".Equals(type))
|
---|
133 | {
|
---|
134 | //((CombinedFilter)f).Filters
|
---|
135 | }
|
---|
136 | // TODO: add for all filter types and will the values (etc.)
|
---|
137 | }
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | // Set session variable with actual selected filters
|
---|
144 | Session["selectedFilters"] = qm.SelectedFilters;
|
---|
145 |
|
---|
146 | // "Index" ist the view name. We use here the Index view
|
---|
147 | // because the index view renders the Filters() action
|
---|
148 | // that will return to the "Filters.ascx" partial view.
|
---|
149 | return View("Index", qm);
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | /// <summary>
|
---|
154 | /// This action will be called when rendering
|
---|
155 | /// the index.aspx. This will hapen the first
|
---|
156 | /// time, so the available Filters in the Model
|
---|
157 | /// will be set.
|
---|
158 | /// </summary>
|
---|
159 | /// <returns></returns>
|
---|
160 | public ActionResult Index()
|
---|
161 | {
|
---|
162 | // Set submenu
|
---|
163 | Session["SelectedSubMenu"] = "Filter";
|
---|
164 |
|
---|
165 | // Init session variable for selected filters
|
---|
166 | if (Session["selectedFilters"] == null)
|
---|
167 | {
|
---|
168 | Session["selectedFilters"] = new List<Filter>();
|
---|
169 | }
|
---|
170 |
|
---|
171 | // Get available filters from service
|
---|
172 | QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester");
|
---|
173 | List<Filter> filterList = client.GetFilters().ToList();
|
---|
174 |
|
---|
175 | // Set model
|
---|
176 | FilterModel qm = new FilterModel();
|
---|
177 | qm.Filters = filterList;
|
---|
178 |
|
---|
179 | return View(qm);
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | }
|
---|
184 | }
|
---|