Changeset 6170 for branches/WebApplication/MVC2
- Timestamp:
- 05/09/11 22:13:01 (14 years ago)
- Location:
- branches/WebApplication/MVC2/HLWebOKBQueryPlugin
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Controllers/FilterController.cs
r6163 r6170 35 35 } 36 36 37 38 37 39 public ActionResult Filters(CombinedFilter f) 38 40 { … … 50 52 /// <returns></returns> 51 53 public ActionResult AddFilterAnd(FormCollection collection) 52 { 53 Response.Write("AddFilterAnd"); 54 55 CombinedFilter content = (CombinedFilter)Session["Content"]; 56 FilterModel fm = new FilterModel(content); 57 58 59 54 { 55 FilterModel fm = new FilterModel((CombinedFilter)Session["Content"]); 56 57 58 // Add Filter 59 60 60 String idKey = null; 61 61 String parentIdKey = null; … … 63 63 foreach (string key in collection.AllKeys) 64 64 { 65 if (key.StartsWith( "filtersCombobox"))65 if (key.StartsWith(FilterModel.ComboboxName)) 66 66 { 67 67 idKey = key; 68 68 } 69 if (key.StartsWith( "parentId"))69 if (key.StartsWith(FilterModel.ParentIdName)) 70 70 { 71 71 parentIdKey = key; … … 75 75 Guid parentId = new Guid(collection.Get(parentIdKey)); 76 76 string filterTypeName = collection.Get(idKey); 77 78 // get selected filter (combobox) 79 Filter filter = fm.Filters.Where(x => x.FilterTypeName.Equals(filterTypeName)).FirstOrDefault(); 80 81 82 83 // find the partent filterr 84 List<Filter> orFilters = content.Filters.ToList<Filter>(); ; 85 CombinedFilter parent = (CombinedFilter)orFilters.Where(e => e.Id.Equals(parentId)).FirstOrDefault(); 86 87 // remove 88 orFilters.Remove(parent); 89 90 List<Filter> filterList = parent.Filters.ToList<Filter>(); 77 fm.AddFilter(filterTypeName, parentId); 78 91 79 92 80 … … 102 90 { 103 91 104 if (!key.StartsWith( "filtersCombobox") && !key.StartsWith("parentId"))92 if (!key.StartsWith(FilterModel.ComboboxName) && !key.StartsWith(FilterModel.ParentIdName)) 105 93 { 106 94 int idx = key.IndexOf("."); … … 124 112 } 125 113 126 127 // Set values for the existing Filters 128 foreach (Filter f in filterList) 129 { 130 131 Dictionary<string, string> dict = postValues.Where(x => x.Key.Equals(f.Id)).FirstOrDefault().Value; 132 if (dict != null) 133 { 134 foreach (KeyValuePair<string, string> kvp in dict) 135 { 136 if ("StringComparisonFilter".Equals(f.GetType().Name)) 137 { 138 if (kvp.Key.Equals("valueTextbox")) 139 { 140 ((StringComparisonFilter)f).Value = kvp.Value; 141 } 142 143 } 144 else 145 { 146 // To this for all filters 147 } 148 } 149 } 150 151 } 152 153 154 // Add the new filter 155 filterList.Add(filter); 156 Response.Write("addx:" + filter.Id); 157 158 parent.Filters = filterList.ToArray<Filter>(); 159 160 // Add the current filter (AND) 161 orFilters.Add(parent); 162 163 content.Filters = orFilters.ToArray<Filter>(); 164 165 166 167 Response.Write("content add:" + content.Filters[0].Id); 114 // Update filters with posted data 115 fm.UpdateWithPostValues(postValues); 168 116 169 117 170 118 // Set Content 171 Session["Content"] = content;119 Session["Content"] = fm.Content; 172 120 173 121 … … 177 125 178 126 127 128 129 /// <summary> 130 /// Delete a filter with given id. 131 /// </summary> 132 /// <param name="id"></param> 133 /// <returns></returns> 179 134 public ActionResult DeleteFilter(Guid id) 180 135 { 181 //Response.Write("Delete id:" + id); 182 183 CombinedFilter masterFilter = (CombinedFilter)Session["Content"]; 184 185 Response.Write("content del:" + masterFilter.Filters[0].Id); 186 187 FilterModel fm = new FilterModel(masterFilter); 188 RemoveFilterFromFilterModel(fm, id); 189 190 masterFilter.Filters = ((CombinedFilter)fm.Content).Filters.ToArray<Filter>(); 191 136 // Get Content from Session 137 FilterModel fm = new FilterModel((CombinedFilter)Session["Content"]); 138 139 // Remove Filter 140 bool filterRemoved = fm.RemoveFilter(id); 141 192 142 // Set Content 193 Session["Content"] = masterFilter; 194 195 // Response.Write("Delete id3:" + masterFilter.Filters.Length); 143 Session["Content"] = fm.Content; 196 144 197 145 return View("Index", fm); … … 199 147 200 148 201 private Filter GetFilterForId(Filter [] activeFilters, Guid id)202 {203 foreach (Filter f in activeFilters)204 {205 Response.Write(f.Id + " " + id);206 207 if (f.Id.Equals(id))208 {209 return f;210 }211 }212 return null;213 }214 215 private FilterModel RemoveFilterFromFilterModel(FilterModel fm, Guid id)216 {217 Response.Write("content :" + fm.Content.Id);218 Filter filterToRemove = GetFilterForId(fm.Content.Filters, id);219 if (filterToRemove != null)220 {221 Response.Write("rrrrr:" + id);222 fm.Filters.Remove(filterToRemove);223 }224 225 return fm;226 }227 149 228 150 … … 233 155 public ActionResult AddFilterOr() 234 156 { 235 236 237 CombinedFilter content = (CombinedFilter)Session["Content"]; 238 FilterModel fm = new FilterModel(content); 239 240 List<Filter> orFilters = content.Filters.ToList<Filter>(); ; 241 242 CombinedFilter andFilter = fm.Filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault(); 157 FilterModel fm = new FilterModel((CombinedFilter)Session["Content"]); 158 159 List<Filter> orFilters = fm.Content.Filters.ToList<Filter>(); ; 160 161 CombinedFilter andFilter = fm.AvailableFilters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault(); 243 162 orFilters.Add(andFilter); 244 content.Filters = orFilters.ToArray<Filter>();245 246 247 Session["Content"] = content;163 fm.Content.Filters = orFilters.ToArray<Filter>(); 164 165 166 Session["Content"] = fm.Content; 248 167 249 168 return View("Index", fm); … … 272 191 { 273 192 // Add first Filter 274 CombinedFilter orFilter = fm. Filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.Or).FirstOrDefault();275 CombinedFilter andFilter = fm. Filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault();193 CombinedFilter orFilter = fm.AvailableFilters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.Or).FirstOrDefault(); 194 CombinedFilter andFilter = fm.AvailableFilters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault(); 276 195 orFilter.Filters = new Filter[] { andFilter }; // 1st filter 277 196 -
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/ViewModels/FilterModel.cs
r6163 r6170 15 15 public class FilterModel 16 16 { 17 private List<bool> boolStates;18 17 19 private List<Filter> _filters; 20 21 //public KeyValuePair<int,Filter> ParentFilter { get; set; } 22 public List<Filter> Filters 23 { 24 25 get 26 { 27 QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester"); 28 return client.GetFilters().ToList<Filter>(); /// => won't work 29 } 30 31 32 } 33 //public Dictionary<int,Filter> SelectedFilters { get; set; } 34 // use an unique id for reach filter "Control" 35 public CombinedFilter Content { get; set; } 18 public static string ComboboxName { get { return "filtersCombobox"; } } 19 public static string ParentIdName { get { return "parentId"; } } 20 public static string ValueTextbox { get { return "valueTextbox"; } } 21 public static string ValueDropDownList { get { return "valueDropDownList"; } } 36 22 37 23 24 /// <summary> 25 /// Constructor 26 /// </summary> 38 27 public FilterModel() 39 28 { … … 44 33 { 45 34 Content = filter; 46 //filter.i 35 } 36 37 /// <summary> 38 /// Get Bool States. 39 /// </summary> 40 public List<Boolean> BoolStates 41 { 42 get 43 { 44 List<Boolean> boolStates = new List<Boolean>(); 45 46 boolStates = new List<Boolean>(); 47 boolStates.Add(true); 48 boolStates.Add(false); 49 50 return boolStates; 51 } 47 52 } 48 53 49 54 50 public List<Boolean> GetBoolStates() 55 /// <summary> 56 /// Available Filters 57 /// </summary> 58 public List<Filter> AvailableFilters 51 59 { 52 if (boolStates == null)60 get 53 61 { 54 boolStates = new List<Boolean>(); 55 boolStates.Add(true); 56 boolStates.Add(false); 62 QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester"); 63 return client.GetFilters().ToList<Filter>(); 57 64 } 58 return boolStates;59 65 } 60 66 67 68 /// <summary> 69 /// Available Filters without AND and OR. 70 /// </summary> 71 public List<Filter> AvailableFilterForCombobox 72 { 73 get 74 { 75 List<Filter> filters = AvailableFilters; 76 77 filters.Remove(filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.Or).FirstOrDefault()); 78 filters.Remove(filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault()); 79 80 return filters; 81 } 82 } 83 84 /// <summary> 85 /// Content 86 /// </summary> 87 public CombinedFilter Content { get; set; } 88 89 90 91 /// <summary> 92 /// Delete a filter with given id. 93 /// </summary> 94 /// <param name="id">filter id</param> 95 internal bool RemoveFilter(Guid id) 96 { 97 bool removed = false; 98 List<Filter> orFilters = Content.Filters.ToList<Filter>(); 99 100 foreach (CombinedFilter f in orFilters) 101 { 102 Filter deleteFilter = f.Filters.Where(x => x.Id == id).FirstOrDefault(); 103 if (deleteFilter != null) 104 { 105 List<Filter> masterFilters = f.Filters.ToList<Filter>(); 106 masterFilters.Remove(deleteFilter); 107 f.Filters = masterFilters.ToArray<Filter>(); 108 removed = true; 109 break; 110 } 111 } 112 113 Content.Filters = orFilters.ToArray<Filter>(); 114 return removed; 115 } 116 117 /// <summary> 118 /// Add a new filters 119 /// </summary> 120 /// <param name="filterTypeName">type name</param> 121 /// <param name="parentId">parent filter id</param> 122 internal void AddFilter(string filterTypeName, Guid parentId) 123 { 124 125 // get selected filter (combobox) 126 Filter filter = AvailableFilters.Where(x => x.FilterTypeName.Equals(filterTypeName)).FirstOrDefault(); 127 128 129 // find the partent filterr 130 List<Filter> orFilters = Content.Filters.ToList<Filter>(); ; 131 CombinedFilter parentFilter = (CombinedFilter)orFilters.Where(e => e.Id.Equals(parentId)).FirstOrDefault(); 132 133 // remove 134 orFilters.Remove(parentFilter); 135 136 List<Filter> filterList = parentFilter.Filters.ToList<Filter>(); 137 138 139 // Add the new filter 140 filterList.Add(filter); 141 //Response.Write("addx:" + filter.Id); 142 143 parentFilter.Filters = filterList.ToArray<Filter>(); 144 145 // Add the current filter (AND) 146 orFilters.Add(parentFilter); 147 148 Content.Filters = orFilters.ToArray<Filter>(); 149 } 150 151 /// <summary> 152 /// Update existing filters with posted value 153 /// </summary> 154 /// <param name="parentId">parent filter id</param> 155 /// <param name="postValues">dictionary with posted values</param> 156 internal void UpdateWithPostValues(Dictionary<Guid, Dictionary<string, string>> postValues) 157 { 158 // Set values for the existing Filters 159 foreach (CombinedFilter cf in Content.Filters) 160 { 161 foreach (Filter f in cf.Filters) 162 { 163 164 Dictionary<string, string> dict = postValues.Where(x => x.Key.Equals(f.Id)).FirstOrDefault().Value; 165 if (dict != null) 166 { 167 foreach (KeyValuePair<string, string> kvp in dict) 168 { 169 if ("StringComparisonFilter".Equals(f.GetType().Name)) 170 { 171 if (kvp.Key.Equals(FilterModel.ValueTextbox)) 172 { 173 ((StringComparisonFilter)f).Value = kvp.Value; 174 } 175 // To this for alle keys 176 177 } 178 else 179 { 180 // To this for all filters 181 } 182 } 183 } 184 } 185 } 186 } 61 187 } 62 188 } -
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Views/Filter/Filters.ascx
r6163 r6170 3 3 <%@ Import Namespace="HLWebOKBQueryPlugin.OKBQueryService" %> 4 4 <!-- Put all into a form that calls the "AddFilter" Action--> 5 <div><table> 6 <tr><td>A<br />N<br />D</td><td> 5 7 <p> 6 8 <% … … 11 13 <% 12 14 13 string comboboxName = "filtersCombobox." + currentFilter.Id;14 string hiddenName = "parentId." + currentFilter.Id;15 string comboboxName = FilterModel.ComboboxName + "." + currentFilter.Id; 16 string hiddenName = FilterModel.ParentIdName + "." + currentFilter.Id; 15 17 %> 16 18 17 Select Filter:18 19 <%: Html.Hidden(hiddenName,currentFilter.Id.ToString()) %> 19 <%: Html.DropDownList(comboboxName, new SelectList(((FilterModel)Model). Filters, "FilterTypeName", "Label"))%>20 <%: Html.DropDownList(comboboxName, new SelectList(((FilterModel)Model).AvailableFilterForCombobox, "FilterTypeName", "Label"))%> 20 21 <input type="submit" value="+" /> 21 22 </p> … … 30 31 if (f != null) 31 32 { %> 32 <div> 33 34 <table border="0"><tr><td> 33 35 <% 34 36 … … 37 39 { %> 38 40 <% StringComparisonFilter filter = ((StringComparisonFilter)f); %> 39 40 41 <%: Html.Label(filter.Label)%> 41 <%: Html.Label("=") %> 42 <%: Html.TextBox(f.Id + ".valueTextbox", (filter.Value))%> 43 <%: Html.ActionLink("-","DeleteFilter", f.Id )%> 42 <%: Html.Label("=")%> 43 <%: Html.TextBox(f.Id + "." + FilterModel.ValueTextbox, (filter.Value))%> 44 44 <% } 45 45 else if ("NameStringComparisonFilter".Equals(f.GetType().Name)) … … 47 47 <% NameStringComparisonFilter filter = ((NameStringComparisonFilter)f); %> 48 48 <%: Html.Label(filter.Label)%> 49 <%: Html.Label("= xxx" + f.Id)%> 50 <%: Html.TextBox(f.Id + ".valueTextbox" + f.Id, filter.Value )%> 51 <%: Html.ActionLink("-", "DeleteFilter", new { f.Id })%> 49 <%: Html.Label("=" + f.Id)%> 50 <%: Html.TextBox(f.Id + "." + FilterModel.ValueTextbox, filter.Value)%> 52 51 <% } 53 52 else if ("StringComparisonAvailableValuesFilter".Equals(f.GetType().Name)) … … 55 54 <% StringComparisonAvailableValuesFilter filter = ((StringComparisonAvailableValuesFilter)f); %> 56 55 <%: Html.Label(filter.Label)%> 57 <%: Html.Label("=")%> 58 <%: Html.DropDownList(f.Id + ".valueDropDownList", new SelectList(filter.AvailableValues,filter.Value))%> 59 <%: Html.ActionLink("-","DeleteFilter", f.Id )%> 60 <% } 56 <%: Html.Label("=")%> 57 <%: Html.DropDownList(f.Id + "." + FilterModel.ValueTextbox, new SelectList(filter.AvailableValues, filter.Value))%> 58 <% } 61 59 else if ("NameEqualityComparisonByteArrayFilter".Equals(f.GetType().Name)) 62 60 { %> 63 61 <% NameEqualityComparisonByteArrayFilter filter = ((NameEqualityComparisonByteArrayFilter)f); %> 64 <%: Html.Label(filter.Label)%> 65 <%: Html.ActionLink("-","DeleteFilter", f.Id )%> 66 <% } 62 <%: Html.Label(filter.Label)%> 63 <% } 67 64 else if ("NameEqualityComparisonBoolFilter".Equals(f.GetType().Name)) 68 65 { %> … … 70 67 %> 71 68 <%: Html.Label(filter.Label)%> 72 <%: Html.Label("is")%> 73 <%: Html.DropDownList(f.Id + ".valueDropDownList", new SelectList(((FilterModel)Model).GetBoolStates(),filter.Value)) %> 74 <%: Html.ActionLink("-","DeleteFilter", f.Id )%> 75 <% } 69 <%: Html.Label("is")%> 70 <%: Html.DropDownList(f.Id + "." + FilterModel.ValueDropDownList, new SelectList(((FilterModel)Model).BoolStates, filter.Value))%> 71 <% } 76 72 else if ("NameOrdinalComparisonIntFilter".Equals(f.GetType().Name)) 77 73 { %> 78 74 <% NameOrdinalComparisonIntFilter filter = ((NameOrdinalComparisonIntFilter)f); %> 79 75 <%: Html.Label(filter.Label)%> 80 <%: Html.Label("is")%> 81 82 <%: Html.ActionLink("-","DeleteFilter", f.Id )%> 83 <% } 76 <%: Html.Label("is")%> 77 <% } 84 78 else if ("NameStringComparisonAvailableValuesFilter".Equals(f.GetType().Name)) 85 79 { %> 86 80 <% NameStringComparisonAvailableValuesFilter filter = ((NameStringComparisonAvailableValuesFilter)f); %> 87 81 <%: Html.Label(filter.Label)%> 88 <%: Html.Label("=")%> 89 <%: Html.DropDownList(f.Id + ".valueDropDownList", new SelectList(filter.AvailableValues,filter.Value))%> 90 <%: Html.ActionLink("-","DeleteFilter", f.Id )%> 91 <% } 82 <%: Html.Label("=")%> 83 <%: Html.DropDownList(f.Id + "." + FilterModel.ValueDropDownList, new SelectList(filter.AvailableValues, filter.Value))%> 84 <% } 92 85 else if ("NameOrdinalComparisonDoubleFilter".Equals(f.GetType().Name)) 93 86 { %> 94 87 <% NameOrdinalComparisonDoubleFilter filter = ((NameOrdinalComparisonDoubleFilter)f); %> 95 88 <%: Html.Label(filter.Label)%> 96 <%: Html.Label("=")%> 97 <%: Html.TextBox(f.Id + ".valueTextbox" + f.Id, filter.Value )%> 98 <%: Html.ActionLink("-","DeleteFilter", f.Id )%> 99 <% } 89 <%: Html.Label("=")%> 90 <%: Html.TextBox(f.Id + "." + FilterModel.ValueTextbox, filter.Value)%> 91 <% } 100 92 else if ("NameOrdinalComparisonFloatFilter".Equals(f.GetType().Name)) 101 93 { %> 102 94 <% NameOrdinalComparisonFloatFilter filter = ((NameOrdinalComparisonFloatFilter)f); %> 103 95 <%: Html.Label(filter.Label)%> 104 <%: Html.Label("=")%> 105 <%: Html.TextBox(f.Id + ".valueTextbox" + f.Id, filter.Value )%> 106 <%: Html.ActionLink("-","DeleteFilter", f.Id )%> 107 <% } 108 else if ("NameOrdinalComparisonFloatFilter".Equals(f.GetType().Name)) 96 <%: Html.Label("=")%> 97 <%: Html.TextBox(f.Id + "." + FilterModel.ValueTextbox, filter.Value)%> 98 <% } 99 else if ("NameOrdinalComparisonFloatFilter".Equals(f.GetType().Name)) 109 100 { %> 110 101 <% NameOrdinalComparisonLongFilter filter = ((NameOrdinalComparisonLongFilter)f); %> 111 102 <%: Html.Label(filter.Label)%> 112 <%: Html.Label("=")%> 113 <%: Html.TextBox(f.Id + ".valueTextbox" + f.Id, filter.Value )%> 114 <%: Html.ActionLink("-","DeleteFilter", f.Id )%> 115 <% } 103 <%: Html.Label("=")%> 104 <%: Html.TextBox(f.Id + "." + FilterModel.ValueTextbox, filter.Value)%> 105 <% } 116 106 117 118 119 120 121 122 123 124 125 else126 { %>127 <!-- other types ... must be implemented -->128 <%: Html.Label(f.GetType().Name)%>129 <% }130 107 %> 131 </div> 108 <%: Html.ActionLink("remove", "DeleteFilter", new { f.Id })%> 109 110 <% }%> 111 </td></tr></table> 112 <% } %> 113 <% }%> 132 114 <% } 133 } 134 }%> 135 <% } 136 137 %> 115 116 %> </td></tr> 117 </table></div> -
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Views/Filter/Index.aspx
r6141 r6170 3 3 <%@ Import Namespace="HLWebOKBQueryPlugin.Models" %> 4 4 <%@ Import Namespace="HLWebOKBQueryPlugin.OKBQueryService" %> 5 <asp:Content ID="Content3" runat="server" ContentPlaceHolderID="SubMenuContent"> 6 <% Html.RenderAction("Menu","Query"); %> 7 </asp:Content> 5 8 <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 6 Index9 Filter 7 10 </asp:Content> 8 11 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 9 <h2> 10 Filter</h2> 12 11 13 <!-- 12 14 This is the "user control" for the filters. This will call the action "AddFilter" -
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Web.config
r6118 r6170 7 7 <configSections> 8 8 </configSections> 9 10 <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\temp\chart;"/>11 </appSettings>12 <connectionStrings>9 <appSettings> 10 <add key="ChartImageHandler" value="storage=memory;deleteAfterServicing=true;"/> 11 </appSettings> 12 <connectionStrings> 13 13 <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/> 14 14 </connectionStrings>
Note: See TracChangeset
for help on using the changeset viewer.