Changeset 6141 for branches/WebApplication
- Timestamp:
- 05/07/11 10:41:02 (14 years ago)
- Location:
- branches/WebApplication/MVC2/HLWebOKBQueryPlugin
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Controllers/FilterController.cs
r6102 r6141 7 7 using HLWebOKBQueryPlugin.Helpers; 8 8 using HLWebOKBQueryPlugin.OKBQueryService; 9 using System.Web.Routing; 9 10 10 11 namespace HLWebOKBQueryPlugin.Controllers … … 15 16 public class FilterController : Controller 16 17 { 17 // 18 // GET: /Filter/ 19 20 [ChildActionOnly] 21 public ActionResult Filters() 22 { 23 // Model 18 /// <summary> 19 /// Get run ids from service. 20 /// </summary> 21 /// <returns></returns> 22 public ActionResult GetRuns() 23 { 24 24 FilterModel qm = new FilterModel(); 25 26 27 //TODO nicht immer laden 25 qm.Content = (CombinedFilter)Session["Content"]; 26 28 27 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 28 long[] ids = client.GetRunIds(qm.Content); 29 30 Response.Write("Found <" + ids.Count() + "> Runs."); 31 32 return View("Index", qm); // name of usercontrol 33 } 34 35 public ActionResult Filters(CombinedFilter f) 36 { 37 FilterModel qm = new FilterModel(f); 35 38 return PartialView("Filters", qm); // name of usercontrol 36 39 } 37 40 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. 41 42 /// <summary> 43 /// Add a new Filter, based on the selected combobox 44 /// value. Posted values will also be set to the 45 /// "right" filter(s). 71 46 /// </summary> 72 47 /// <param name="collection"></param> 73 48 /// <returns></returns> 74 public ActionResult AddFilter(FormCollection collection) 75 { 49 public ActionResult AddFilterAnd(FormCollection collection) 50 { 51 CombinedFilter content = (CombinedFilter)Session["Content"]; 52 FilterModel fm = new FilterModel(content); 53 76 54 77 55 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) 56 String idKey = null; 57 String parentIdKey = null; 58 59 foreach (string key in collection.AllKeys) 60 { 61 if (key.StartsWith("filtersCombobox")) 62 { 63 idKey = key; 64 } 65 if (key.StartsWith("parentId")) 66 { 67 parentIdKey = key; 68 } 69 } 70 71 Guid parentId = new Guid(collection.Get(parentIdKey)); 72 string filterTypeName = collection.Get(idKey); 73 74 // get selected filter (combobox) 75 Filter filter = fm.Filters.Where(x => x.FilterTypeName.Equals(filterTypeName)).FirstOrDefault(); 76 77 78 79 // find the partent filterr 80 List<Filter> orFilters = content.Filters.ToList<Filter>(); ; 81 CombinedFilter parent = (CombinedFilter)orFilters.Where(e => e.Id.Equals(parentId)).FirstOrDefault(); 82 83 // remove 84 orFilters.Remove(parent); 85 86 List<Filter> filterList = parent.Filters.ToList<Filter>(); 87 88 89 90 91 // Iterate "posted" values and build up a dictionary for 92 // each filter (id). 93 // <id> => <key> => <value> 94 // => <key> => <value> 95 Dictionary<Guid, Dictionary<string, string>> postValues = new Dictionary<Guid, Dictionary<string, string>>(); 96 97 foreach (string key in collection.AllKeys) 98 { 99 100 if (!key.StartsWith("filtersCombobox") && !key.StartsWith("parentId")) 101 { 102 int idx = key.IndexOf("."); 103 string id = key.Substring(0, idx); 104 string type = key.Substring(idx + 1); 105 106 Guid fid = new Guid(id); 107 108 if (postValues.ContainsKey(fid)) 101 109 { 102 103 qm.SelectedFilters = new List<Filter>();110 Dictionary<string, string> d = postValues[fid]; 111 d.Add(type, collection.Get(key)); 104 112 } 105 106 107 // Add Filter only if not exists 108 if (qm.SelectedFilters.Where(x => x.FilterTypeName.Equals(filter.FilterTypeName)).Count() == 0) 113 else 109 114 { 110 111 qm.SelectedFilters.Add(filter); 115 Dictionary<string, string> d = new Dictionary<string, string>(); 116 d.Add(type, collection.Get(key)); 117 postValues.Add(fid, d); 112 118 } 113 114 // Set values for the selected filters 115 foreach (string s in collection.AllKeys) 119 } 120 } 121 122 123 // Set values for the existing Filters 124 foreach (Filter f in filterList) 125 { 126 127 Dictionary<string, string> dict = postValues.Where(x => x.Key.Equals(f.Id)).FirstOrDefault().Value; 128 if (dict != null) 129 { 130 foreach (KeyValuePair<string, string> kvp in dict) 116 131 { 117 if ( s.StartsWith("valueTextbox"))132 if ("StringComparisonFilter".Equals(f.GetType().Name)) 118 133 { 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)) 134 if (kvp.Key.Equals("valueTextbox")) 125 135 { 126 ((StringComparisonFilter)f).Value = collection.Get(s);136 ((StringComparisonFilter)f).Value = kvp.Value; 127 137 } 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.) 138 139 } 140 else 141 { 142 // To this for all filters 137 143 } 138 144 } 139 145 } 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 } 146 147 } 148 149 150 // Add the new filter 151 filterList.Add(filter); 152 parent.Filters = filterList.ToArray<Filter>(); 153 154 // Add the current filter (AND) 155 orFilters.Add(parent); 156 157 content.Filters = orFilters.ToArray<Filter>(); 158 159 // Set Content 160 Session["Content"] = content; 161 162 163 164 return View("Index", fm); 165 } 166 167 168 /// <summary> 169 /// Add a new Filter "Box" for OR connection. 170 /// </summary> 171 /// <returns></returns> 172 public ActionResult AddFilterOr() 173 { 174 175 176 CombinedFilter content = (CombinedFilter)Session["Content"]; 177 FilterModel fm = new FilterModel(content); 178 179 List<Filter> orFilters = content.Filters.ToList<Filter>(); ; 180 181 CombinedFilter andFilter = fm.Filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault(); 182 orFilters.Add(andFilter); 183 content.Filters = orFilters.ToArray<Filter>(); 184 185 186 Session["Content"] = content; 187 188 return View("Index", fm); 189 } 190 191 151 192 152 193 … … 160 201 public ActionResult Index() 161 202 { 203 162 204 // Set submenu 163 205 Session["SelectedSubMenu"] = "Filter"; 206 FilterModel fm = new FilterModel(); 207 164 208 165 209 // 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(); 210 if (Session["Content"] == null) 211 { 212 // Add first Filter 213 CombinedFilter orFilter = fm.Filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.Or).FirstOrDefault(); 214 CombinedFilter andFilter = fm.Filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault(); 215 orFilter.Filters = new Filter[] { andFilter }; // 1st filter 216 217 Session["Content"] = orFilter; 218 } 174 219 175 220 // Set model 176 FilterModel qm = new FilterModel(); 177 qm.Filters = filterList; 178 179 return View(qm); 221 CombinedFilter f = (CombinedFilter)Session["Content"]; 222 fm.Content = f; 223 224 225 return View(fm); 180 226 } 181 227 -
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/HLWebOKBQueryPlugin.csproj
r6118 r6141 102 102 <Compile Include="Models\AccountModels.cs" /> 103 103 <Compile Include="Models\ChartModel.cs" /> 104 <Compile Include="Models\Filter.cs" /> 104 105 <Compile Include="ViewModels\FilterModel.cs" /> 105 106 <Compile Include="Models\QueryModel.cs" /> -
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/ViewModels/FilterModel.cs
r6097 r6141 4 4 using System.Web; 5 5 using HLWebOKBQueryPlugin.OKBQueryService; 6 using HLWebOKBQueryPlugin.Helpers; 6 7 7 8 namespace HLWebOKBQueryPlugin.Models … … 14 15 public class FilterModel 15 16 { 16 public List<Filter> Filters { get; set; } 17 public List<Filter> SelectedFilters { get; set; } 17 18 private List<Filter> _filters; 19 20 //public KeyValuePair<int,Filter> ParentFilter { get; set; } 21 public List<Filter> Filters 22 { 23 24 get 25 { 26 QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester"); 27 return client.GetFilters().ToList<Filter>(); /// => won't work 28 } 29 30 31 } 32 //public Dictionary<int,Filter> SelectedFilters { get; set; } 33 // use an unique id for reach filter "Control" 34 public CombinedFilter Content { get; set; } 35 36 37 public FilterModel() 38 { 39 40 } 41 42 public FilterModel(CombinedFilter filter) 43 { 44 Content = filter; 45 //filter.i 46 } 47 18 48 } 19 49 } -
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Views/Filter/Filters.ascx
r6118 r6141 3 3 <%@ Import Namespace="HLWebOKBQueryPlugin.OKBQueryService" %> 4 4 <!-- Put all into a form that calls the "AddFilter" Action--> 5 <% using (Html.BeginForm ("AddFilter", "Filter")) %>6 <% { %>7 5 <p> 6 <% 7 CombinedFilter currentFilter = ((FilterModel)Model).Content; 8 %> 9 <% using (Html.BeginForm("AddFilterAnd", "Filter", FormMethod.Post, new { id = currentFilter.Id, name = currentFilter.Id })) %> 10 <% { %> 11 <% 12 13 string comboboxName = "filtersCombobox." + currentFilter.Id; 14 string hiddenName = "parentId." + currentFilter.Id; 15 %> 16 8 17 Select Filter: 9 <%: Html. DropDownList("filtersCombobox", new SelectList(((FilterModel)Model).Filters, "FilterTypeName", "Label"))%>10 < input type="submit" value="add" />11 18 <%: Html.Hidden(hiddenName,currentFilter.Id.ToString()) %> 19 <%: Html.DropDownList(comboboxName, new SelectList(((FilterModel)Model).Filters, "FilterTypeName", "Label"))%> 20 <input type="submit" value="+" /> 12 21 </p> 13 <ul> 14 <!-- Build the selected filters. The filtesr will be stored in the session and the 22 <!-- Build the selected filters. The filtesr will be stored in the session and the 15 23 Controller puts the current filters from the session into the model. Selected Filters 16 24 will be iterated. --> 17 <% if (((FilterModel)Model).SelectedFilters != null) 25 <% if (currentFilter.Filters != null) 26 { 27 28 foreach (Filter f in currentFilter.Filters) 18 29 { 19 20 foreach (Filter f in ((FilterModel)Model).SelectedFilters) 21 { %> 22 <li> 23 <% 24 // If type is StringComparisonFilter build thes controls 25 if ("StringComparisonFilter".Equals(f.GetType().Name)) 26 { %> 27 <%: Html.TextBox("valueTextbox." + f.GetType().Name, ((StringComparisonFilter)f).Value)%> 28 <%: Html.LabelFor(x => f.Label)%> 29 30 <% } 31 // If type is NameStringComparisonFilter build thes controls 32 else if ("NameStringComparisonFilter".Equals(f.GetType().Name)) 33 { %> 34 <%: Html.TextBox("valueTextbox." + f.GetType().Name, ((NameStringComparisonFilter)f).Value) %> 35 36 <% } 37 else if ("CombinedFilter".Equals(f.GetType().Name)) 38 { %> 39 <% CombinedFilter combiFilter = ((CombinedFilter)f); %> 40 <% List<Filter> comtbiFtilterLis = combiFilter.Filters.ToList<Filter>(); 41 FilterModel m = new FilterModel(); 42 m.Filters = ((FilterModel)Model).Filters; 43 m.SelectedFilters = comtbiFtilterLis; 44 %> 45 <% Html.RenderPartial("Filters", m); %> 46 47 <% } 30 if (f != null) 31 { %> 32 <div> 33 <% 34 35 // If type is StringComparisonFilter build thes controls 36 if ("StringComparisonFilter".Equals(f.GetType().Name)) 37 { %> 38 <%: Html.TextBox(f.Id + ".valueTextbox", ((StringComparisonFilter)f).Value)%> 39 <%: Html.Label(f.GetType().Name)%> 40 <% } 41 // If type is NameStringComparisonFilter build thes controls 42 else if ("NameStringComparisonFilter".Equals(f.GetType().Name)) 43 { %> 44 <%: Html.TextBox(f.Id + ".valueTextbox" + f.Id, new{((NameStringComparisonFilter)f).Value})%> 45 <%: Html.Label(f.GetType().Name)%> 46 <% } 48 47 49 48 50 else 51 { %> 52 <!-- type not supported ... --> 53 FilerTypeName = 54 <%: Html.Label(f.GetType().Name)%> 55 <% } 56 %> 57 </li> 49 else 50 { %> 51 <!-- other types ... must be implemented --> 52 <%: Html.Label(f.GetType().Name)%> 58 53 <% } 59 54 %> 55 </div> 56 <% } 60 57 } 61 58 }%> 62 </ul> 59 <% } 60 61 %> -
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Views/Filter/Index.aspx
r6097 r6141 1 1 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> 2 2 3 <%@ Import Namespace="HLWebOKBQueryPlugin.Models" %> 4 <%@ Import Namespace="HLWebOKBQueryPlugin.OKBQueryService" %> 3 5 <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 4 6 Index 5 7 </asp:Content> 6 8 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 7 <h2>Filter</h2> 9 <h2> 10 Filter</h2> 8 11 <!-- 9 12 This is the "user control" for the filters. This will call the action "AddFilter" 10 13 in the controller, after the Action "Index" is called (for rendering the page). 14 15 16 ch130 TSP (imported from TSPLIB) 17 18 11 19 --> 12 <% Html.RenderPartial("Filters"); %> 20 <% 21 22 FilterModel model = (FilterModel)Model; 23 24 if (model != null && model.Content != null) 25 { 26 foreach (Filter f in model.Content.Filters) 27 { 28 %> 29 30 <% FilterModel fm = new FilterModel((CombinedFilter)f); 31 32 %> 33 <% Html.RenderPartial("Filters", fm); %> 34 <%} 35 }%> 36 37 38 39 <% using (Html.BeginForm("AddFilterOr", "Filter")) %> 40 <% { %> 41 Or filter <input type="submit" value="+" /> 42 <% } %> 43 44 45 46 <% using (Html.BeginForm("GetRuns", "Filter")) %> 47 <% { %> 48 <input type="submit" value="get runs" /> 49 <% } %> 50 13 51 </asp:Content>
Note: See TracChangeset
for help on using the changeset viewer.