Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6141


Ignore:
Timestamp:
05/07/11 10:41:02 (13 years ago)
Author:
mjesner
Message:

#1499 new (non-recursive) view/architecture

Location:
branches/WebApplication/MVC2/HLWebOKBQueryPlugin
Files:
1 added
5 edited

Legend:

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

    r6102 r6141  
    77using HLWebOKBQueryPlugin.Helpers;
    88using HLWebOKBQueryPlugin.OKBQueryService;
     9using System.Web.Routing;
    910
    1011namespace HLWebOKBQueryPlugin.Controllers
     
    1516    public class FilterController : Controller
    1617    {
    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        {
    2424            FilterModel qm = new FilterModel();
    25 
    26 
    27             //TODO nicht immer laden
     25            qm.Content = (CombinedFilter)Session["Content"];
     26
    2827            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);
    3538            return PartialView("Filters", qm); // name of usercontrol
    3639        }
    3740
    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).
    7146        /// </summary>
    7247        /// <param name="collection"></param>
    7348        /// <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
    7654           
    7755
    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))
    101109                    {
    102 
    103                         qm.SelectedFilters = new List<Filter>();
     110                        Dictionary<string, string> d = postValues[fid];
     111                        d.Add(type, collection.Get(key));
    104112                    }
    105 
    106 
    107                     // Add Filter only if not exists
    108                     if (qm.SelectedFilters.Where(x => x.FilterTypeName.Equals(filter.FilterTypeName)).Count() == 0)
     113                    else
    109114                    {
    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);
    112118                    }
    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)
    116131                    {
    117                         if (s.StartsWith("valueTextbox"))
     132                        if ("StringComparisonFilter".Equals(f.GetType().Name))
    118133                        {
    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"))
    125135                            {
    126                                 ((StringComparisonFilter)f).Value = collection.Get(s);
     136                                ((StringComparisonFilter)f).Value = kvp.Value;
    127137                            }
    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
    137143                        }
    138144                    }
    139145                }
    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
    151192
    152193
     
    160201        public ActionResult Index()
    161202        {
     203           
    162204            // Set submenu
    163205            Session["SelectedSubMenu"] = "Filter";
     206            FilterModel fm = new FilterModel();
     207
    164208
    165209            // 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            }
    174219
    175220            // 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);
    180226        }
    181227
  • branches/WebApplication/MVC2/HLWebOKBQueryPlugin/HLWebOKBQueryPlugin.csproj

    r6118 r6141  
    102102    <Compile Include="Models\AccountModels.cs" />
    103103    <Compile Include="Models\ChartModel.cs" />
     104    <Compile Include="Models\Filter.cs" />
    104105    <Compile Include="ViewModels\FilterModel.cs" />
    105106    <Compile Include="Models\QueryModel.cs" />
  • branches/WebApplication/MVC2/HLWebOKBQueryPlugin/ViewModels/FilterModel.cs

    r6097 r6141  
    44using System.Web;
    55using HLWebOKBQueryPlugin.OKBQueryService;
     6using HLWebOKBQueryPlugin.Helpers;
    67
    78namespace HLWebOKBQueryPlugin.Models
     
    1415    public class FilterModel
    1516    {
    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
    1848    }
    1949}
  • branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Views/Filter/Filters.ascx

    r6118 r6141  
    33<%@ Import Namespace="HLWebOKBQueryPlugin.OKBQueryService" %>
    44<!-- Put all into a form that calls the "AddFilter" Action-->
    5 <% using (Html.BeginForm ("AddFilter", "Filter")) %>
    6 <% { %>
    75<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 
    817    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="+" />
    1221</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
    1523Controller puts the current filters from the session into the model. Selected Filters
    1624will be iterated. -->
    17     <% if (((FilterModel)Model).SelectedFilters != null)
     25<% if (currentFilter.Filters != null)
     26   {
     27
     28       foreach (Filter f in currentFilter.Filters)
    1829       {
    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
     36if ("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
     42else 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    <% }
    4847
    4948
    50               else
    51                 { %>
    52                      <!-- type not supported ... -->
    53                      FilerTypeName =
    54                     <%: Html.Label(f.GetType().Name)%>
    55                <% }
    56                %>
    57     </li>
     49else
     50{ %>
     51    <!-- other types ... must be implemented -->
     52    <%: Html.Label(f.GetType().Name)%>
    5853    <% }
    59 
     54    %>
     55</div>
     56<% }
    6057       }
    6158   }%>
    62 </ul>
     59<% }
     60       
     61%>
  • branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Views/Filter/Index.aspx

    r6097 r6141  
    11<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
    22
     3<%@ Import Namespace="HLWebOKBQueryPlugin.Models" %>
     4<%@ Import Namespace="HLWebOKBQueryPlugin.OKBQueryService" %>
    35<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    46    Index
    57</asp:Content>
    68<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    7     <h2>Filter</h2>
     9    <h2>
     10        Filter</h2>
    811    <!--
    912     This is the "user control" for the filters. This will call the action "AddFilter"
    1013     in the controller, after the Action "Index" is called (for rendering the page).
     14
     15
     16     ch130 TSP (imported from TSPLIB)
     17
     18
    1119     -->
    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
    1351</asp:Content>
Note: See TracChangeset for help on using the changeset viewer.