Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6247


Ignore:
Timestamp:
05/22/11 21:01:58 (13 years ago)
Author:
dhohl
Message:

#1499 The filter form does not lost any inputs after reloading the page; date filter is possible

Location:
branches/WebApplication/MVC2/HLWebOKBQueryPlugin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Controllers/FilterController.cs

    r6245 r6247  
    2020        /// </summary>
    2121        /// <returns></returns>
    22         public ActionResult GetRuns()
     22        public void GetRuns()
    2323        {
    2424            FilterModel qm = new FilterModel();
     
    3232            Response.Write("Found <" + ids.Count() + "> Runs.");
    3333
    34             return View("Index", qm); // name of usercontrol
     34          //  return View("Index", qm); // name of usercontrol
    3535        }
    3636
     
    5151        /// <param name="collection"></param>
    5252        /// <returns></returns>
    53         public ActionResult AddFilterAnd(FormCollection collection)
     53        public ActionResult AddFilterAnd(string submitButton, FormCollection collection)
    5454        {
    5555            FilterModel fm = new FilterModel((CombinedFilter)Session["Content"]);
    5656
    57 
    58             // Add Filter
    59             String idKey = null;
    60             String parentIdKey = null;
    61 
    62             foreach (string key in collection.AllKeys)
    63             {
    64                 if (key.StartsWith(FilterModel.ComboboxName))
    65                 {
    66                     idKey = key;
    67                 }
    68                 if (key.StartsWith(FilterModel.ParentIdName))
    69                 {
    70                     parentIdKey = key;
    71                 }
    72             }
    73 
    74             Guid parentId = new Guid(collection.Get(parentIdKey));
    75             string filterTypeName = collection.Get(idKey);
    76             fm.AddFilter(filterTypeName, parentId);
    77 
     57            Response.Write("Submit:" + submitButton);
     58           
     59            //update model with form data
    7860            UpdateModel(collection, fm);
    7961
     62            if (submitButton.StartsWith("+"))
     63            {
     64                string stringid = submitButton.Substring(2);
     65                AddNewFilter(collection, fm, stringid);
     66            }
     67            else if (submitButton.StartsWith("-"))
     68            {
     69                string stringid = submitButton.Substring(2);
     70                DeleteFilter(new Guid(stringid));
     71            }
     72            else if (submitButton.Equals("runs"))
     73            {
     74                GetRuns();
     75            }
     76            else if (submitButton.Equals("or"))
     77            {
     78                AddFilterOr( fm);
     79            }
     80           
    8081            // Set Content
    8182            Session["Content"] = fm.Content;
    8283
    8384            return View("Index", fm);
     85                       
     86        }
     87
     88        private void AddNewFilter(FormCollection collection, FilterModel fm, String idKey)
     89        {
     90            // Add Filter
     91            //String idKey = null;
     92            String parentIdKey = idKey;
     93
     94            //foreach (string key in collection.AllKeys)
     95            //{
     96            //    //if (key.StartsWith(FilterModel.ComboboxName))
     97            //    //{
     98            //    //    idKey = key;
     99            //    //}
     100            //    if (key.StartsWith(FilterModel.ParentIdName))
     101            //    {
     102            //        parentIdKey = key;
     103            //    }
     104            //}
     105
     106            Guid parentId = new Guid(parentIdKey);
     107            string filterTypeName = collection.Get(FilterModel.ComboboxName+ "." + idKey);
     108            fm.AddFilter(filterTypeName, parentId);
     109
     110            //UpdateModel(collection, fm);
     111
     112            //// Set Content
     113            //Session["Content"] = fm.Content;
     114
     115            //return View("Index", fm);
    84116        }
    85117
     
    111143                {
    112144                    int idx = key.IndexOf(".");
    113                     string id = key.Substring(0, idx);
    114                     string type = key.Substring(idx + 1);
    115 
    116                     Guid fid = new Guid(id);
    117 
    118                     if (postValues.ContainsKey(fid))
     145                    if (idx != -1)
    119146                    {
    120                         Dictionary<string, string> d = postValues[fid];
    121                         d.Add(type, collection.Get(key));
    122                     }
    123                     else
    124                     {
    125                         Dictionary<string, string> d = new Dictionary<string, string>();
    126                         d.Add(type, collection.Get(key));
    127                         postValues.Add(fid, d);
     147                        string id = key.Substring(0, idx);
     148                        string type = key.Substring(idx + 1);
     149
     150                        Guid fid = new Guid(id);
     151
     152                        if (postValues.ContainsKey(fid))
     153                        {
     154                            Dictionary<string, string> d = postValues[fid];
     155                            d.Add(type, collection.Get(key));
     156                        }
     157                        else
     158                        {
     159                            Dictionary<string, string> d = new Dictionary<string, string>();
     160                            d.Add(type, collection.Get(key));
     161                            postValues.Add(fid, d);
     162                        }
    128163                    }
    129164                }
     
    140175        /// <param name="id"></param>
    141176        /// <returns></returns>
    142         public ActionResult DeleteFilter(Guid id)
     177        public void DeleteFilter(Guid id)
    143178        {
    144179            // Get Content from Session
    145180            FilterModel fm = new FilterModel((CombinedFilter)Session["Content"]);
    146181
     182            //throw new Exception();
     183
    147184            // Remove Filter
    148185            bool filterRemoved = fm.RemoveFilter(id);
    149186
     187
     188            //UpdateModel(collection, fm);
    150189            // TODO Model muss auch beim löschen upgeadatet werden UpdateModel(collection, fm);
    151190
    152191            // Set Content
    153             Session["Content"] = fm.Content;
    154 
    155             return View("Index", fm);
     192            //Session["Content"] = fm.Content;
     193
     194            //return View("Index", fm);
    156195        }
    157196
     
    163202        /// </summary>
    164203        /// <returns></returns>
    165         public ActionResult AddFilterOr()
    166         {
    167             FilterModel fm = new FilterModel((CombinedFilter)Session["Content"]);
    168 
     204        public void AddFilterOr(FilterModel fm)
     205        {
     206           
    169207            List<Filter> orFilters = fm.Content.Filters.ToList<Filter>(); ;
    170208
     
    177215            Session["Content"] = fm.Content;
    178216
    179             return View("Index", fm);
     217            //return View("Index", fm);
    180218        }
    181219
  • branches/WebApplication/MVC2/HLWebOKBQueryPlugin/ViewModels/FilterModel.cs

    r6245 r6247  
    1616    public class FilterModel
    1717    {
    18        
     18
    1919
    2020
     
    6161        }
    6262
    63         public static List<ComparisonItem> OrdinalComparisons 
     63        public static List<ComparisonItem> OrdinalComparisons
    6464        {
    6565            get { return ComparisonsHelper.ordinalComparisons; }
     
    7070            get { return ComparisonsHelper.stringComparisons; }
    7171        }
    72        
    73 
    74        
     72
     73
     74
    7575
    7676        /// <summary>
     
    192192                    if (dict != null)
    193193                    {
    194                      
     194
    195195                        foreach (KeyValuePair<string, string> kvp in dict)
    196196                        {
    197197                            if ("StringComparisonFilter".Equals(f.GetType().Name))
    198                             { 
     198                            {
    199199                                if (kvp.Key.Equals(FilterModel.ValueTextbox))
    200200                                {
     
    202202                                }
    203203                                else if (kvp.Key.Equals(FilterModel.ComparisonDropDownList))
    204                                 {                                 
    205                                     ((StringComparisonFilter)f).Comparison = ComparisonsHelper.GetStringComparisonForValue(kvp.Value);                                 
    206                                 } 
     204                                {
     205                                    ((StringComparisonFilter)f).Comparison = ComparisonsHelper.GetStringComparisonForValue(kvp.Value);
     206                                }
    207207                            }
    208208                            else if ("NameStringComparisonFilter".Equals(f.GetType().Name))
     
    238238                                    ((NameStringComparisonAvailableValuesFilter)f).Comparison = ComparisonsHelper.GetStringComparisonForValue(kvp.Value);
    239239                                }
    240                             } 
    241                              else if ("NameEqualityComparisonByteArrayFilter".Equals(f.GetType().Name))
    242                             {
    243                                //TODO not supported
    244                             }
    245                               else if ("NameEqualityComparisonBoolFilter".Equals(f.GetType().Name))
     240                            }
     241                            else if ("NameEqualityComparisonByteArrayFilter".Equals(f.GetType().Name))
     242                            {
     243                                //TODO not supported
     244                            }
     245                            else if ("NameEqualityComparisonBoolFilter".Equals(f.GetType().Name))
    246246                            {
    247247                                if (kvp.Key.Equals(FilterModel.ValueDropDownList))
    248248                                {
    249                                     ((NameEqualityComparisonBoolFilter)f).Value = Boolean.Parse( kvp.Value);                                 
     249                                    ((NameEqualityComparisonBoolFilter)f).Value = Boolean.Parse(kvp.Value);
    250250                                }
    251251                                else if (kvp.Key.Equals(FilterModel.ComparisonDropDownList))
     
    268268                                }
    269269                                else if (kvp.Key.Equals(FilterModel.ComparisonDropDownList))
    270                                 {                                   
    271                                     ((NameOrdinalComparisonIntFilter)f).Comparison = ComparisonsHelper.GetOrdinalComparisonForValue(kvp.Value);                                 
     270                                {
     271                                    ((NameOrdinalComparisonIntFilter)f).Comparison = ComparisonsHelper.GetOrdinalComparisonForValue(kvp.Value);
    272272                                }
    273273                            }
     
    286286                                }
    287287                                else if (kvp.Key.Equals(FilterModel.ComparisonDropDownList))
    288                                 {                                   
    289                                     ((NameOrdinalComparisonLongFilter)f).Comparison = ComparisonsHelper.GetOrdinalComparisonForValue(kvp.Value);                                 
    290                                 }                           
    291                             }
    292 
     288                                {
     289                                    ((NameOrdinalComparisonLongFilter)f).Comparison = ComparisonsHelper.GetOrdinalComparisonForValue(kvp.Value);
     290                                }
     291                            }
    293292                            else if ("NameOrdinalComparisonFloatFilter".Equals(f.GetType().Name))
    294293                            {
     
    305304                                }
    306305                                else if (kvp.Key.Equals(FilterModel.ComparisonDropDownList))
    307                                 {                                   
     306                                {
    308307                                    ((NameOrdinalComparisonFloatFilter)f).Comparison = ComparisonsHelper.GetOrdinalComparisonForValue(kvp.Value);
    309308                                }
    310309                            }
     310                            else if ("OrdinalComparisonDateTimeFilter".Equals(f.GetType().Name))
     311                            {
     312                                if (kvp.Key.Equals(FilterModel.ValueTextbox))
     313                                {
     314                                    try
     315                                    {
     316                                        ((OrdinalComparisonDateTimeFilter)f).Value = DateTime.Parse(kvp.Value);
     317                                    }
     318                                    catch (Exception)
     319                                    {
     320                                        //TOOD Fehler ausgeben
     321                                    }
     322                                }
     323                                else if (kvp.Key.Equals(FilterModel.ComparisonDropDownList))
     324                                {
     325                                    ((OrdinalComparisonDateTimeFilter)f).Comparison = ComparisonsHelper.GetOrdinalComparisonForValue(kvp.Value);
     326                                }
     327                            }
    311328                            else if ("NameOrdinalComparisonDoubleFilter".Equals(f.GetType().Name))
    312329                            {
     
    323340                                }
    324341                                else if (kvp.Key.Equals(FilterModel.ComparisonDropDownList))
    325                                 {                                   
     342                                {
    326343                                    ((NameOrdinalComparisonDoubleFilter)f).Comparison = ComparisonsHelper.GetOrdinalComparisonForValue(kvp.Value);
    327344                                }
    328345                            }
    329                                
     346
    330347
    331348                            else
     
    334351                            }
    335352
    336                            
     353
    337354                        }
    338                        
    339                        
     355
     356
    340357                    }
    341358                }
  • branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Views/Filter/Filters.ascx

    r6245 r6247  
    99<p>
    1010    <%
    11         CombinedFilter currentFilter = ((FilterModel)Model).Content;
     11        CombinedFilter topFilter = ((FilterModel)Model).Content;
    1212    %>
    13     <% using (Html.BeginForm("AddFilterAnd", "Filter", FormMethod.Post, new { id = currentFilter.Id, name = currentFilter.Id })) %>
    14     <% {     %>
    15     <%
    16  
    17         string comboboxName = FilterModel.ComboboxName + "." + currentFilter.Id;
    18         string hiddenName = FilterModel.ParentIdName + "." + currentFilter.Id;
     13    <% using (Html.BeginForm("AddFilterAnd", "Filter", FormMethod.Post, new { id = topFilter.Id, name = topFilter.Id })) %>
     14    <% {   
     15           
     16            foreach (Filter fNode in topFilter.Filters)
     17            {
     18
     19                CombinedFilter currentFilter = (CombinedFilter)fNode;
     20                string comboboxName = FilterModel.ComboboxName + "." + currentFilter.Id;
     21                string hiddenName = FilterModel.ParentIdName + "." + currentFilter.Id;
    1922    %>
    20  
    2123    <%: Html.Hidden(hiddenName,currentFilter.Id.ToString()) %>
    2224    <%: Html.DropDownList( comboboxName, new SelectList(((FilterModel)Model).AvailableFilterForCombobox, "FilterTypeName", "Label"))%>
    23     <input type="submit" value="+" />
     25    <input type="submit" name="submitButton" value="+.<%:currentFilter.Id%>" />
    2426</p>
    2527<!-- Build the selected filters. The filtesr will be stored in the session and the
     
    106108    <%: Html.DropDownList(f.Id + "." + FilterModel.ComparisonDropDownList, new SelectList(FilterModel.OrdinalComparisons, "Value", "Text", (int)filter.Comparison))%>
    107109    <%: Html.TextBox(f.Id + "." + FilterModel.ValueTextbox, filter.Value)%>
     110    <% }
     111else if ("OrdinalComparisonDateTimeFilter".Equals(f.GetType().Name))
     112{ %>
     113    <% OrdinalComparisonDateTimeFilter filter = ((OrdinalComparisonDateTimeFilter)f);   %>
     114    <%: Html.Label(filter.Label)%>
     115    <%: Html.DropDownList(f.Id + "." + FilterModel.ComparisonDropDownList, new SelectList(FilterModel.OrdinalComparisons, "Value", "Text", (int)filter.Comparison))%>
     116    <%: Html.TextBox(f.Id + "." + FilterModel.ValueTextbox, filter.Value)%>
    108117    <% }                 
    109118                 
    110119    %>
    111     <%: Html.ActionLink("remove", "DeleteFilter", new { f.Id })%>
    112120
     121    <input type="submit" name="submitButton" value="-.<%:f.Id%>"    />
     122   
    113123<% }%>
    114124    </td></tr></table>
    115125    <% } %>
    116126 <%  }%>
     127   <% }%>
     128 <input type="submit" name="submitButton"  value="or" />
     129 </br>
     130 <input type="submit" name="submitButton" value="runs" />
     131
     132 
     133
    117134<% }
    118135     
  • branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Views/Filter/Index.aspx

    r6170 r6247  
    2626        if (model != null && model.Content != null)
    2727        {
    28             foreach (Filter f in model.Content.Filters)
    29             {
     28           
     29                FilterModel fm = new FilterModel((CombinedFilter)model.Content);
    3030    %>
    31  
    32     <% FilterModel fm = new FilterModel((CombinedFilter)f);
    33              
     31                 <% Html.RenderPartial("Filters", fm); %>
     32    <%    
     33        }
    3434    %>
    35     <% Html.RenderPartial("Filters", fm); %>
    36     <%}
    37          }%>
    3835
    3936         
    4037     
    41   <% using (Html.BeginForm("AddFilterOr", "Filter")) %>
    42   <% {     %>
    43  Or filter <input type="submit" value="+" />
    44   <% }     %>
     38
    4539
    4640
    4741 
    48   <% using (Html.BeginForm("GetRuns", "Filter")) %>
    49   <% {     %>
    50  <input type="submit" value="get runs" />
    51   <% }     %>
     42
    5243
    5344</asp:Content>
Note: See TracChangeset for help on using the changeset viewer.