Example #1
0
        // possibly filter an event list by view or count
        public List<ZonelessEvent> Filter(string view, int count, DateTime from, DateTime to, string source, ZonelessEventStore es, Dictionary<string,object> args)
        {
            var events = es.events.CloneObject();

            var bare_events = args.HasValue("bare_events", true);
            var is_html_renderer = args.HasValue("html_renderer", true);

            if (!String.IsNullOrEmpty(source))
                events = SourceFilter(source, events);

            if (!String.IsNullOrEmpty(view))
                events = ViewFilter(view, events);

            if (from != DateTime.MinValue && to != DateTime.MinValue)
                events = TimeFilter(from, to, events);

            if (! bare_events)									// bracket the available range before (maybe) reducing to count
                es.RememberFirstAndLastAvailableDays(events);   // not required for non-html renderers but no reason to exclude them

            if (count != 0)                                      // includes case where bare_events is true
                events = CountFilter(count, events);

            if ( ! is_html_renderer )   // do nothing else for non-html views
                return events;
            else                                   // post-process result set to yield ~500 day-aligned events
            {
                var from_to = new Dictionary<string, DateTime>();

                if (bare_events)
                    from_to = HandleBareEvents(from);
                else
                    from_to = HandleClothedEvents(events);

                if (from_to == null)
                    return events;
                else
                    return TimeFilter((DateTime)from_to["from_date"], (DateTime)from_to["to_date"], events);
            }
        }
Example #2
0
        public string RenderEvtAsHtml(ZonelessEvent evt, Calinfo calinfo, Dictionary<string,object> args)
        {
            if (evt.urls_and_sources == null)
                evt.urls_and_sources = new Dictionary<string, string>() { { evt.url, evt.source } };

            string dtstart;
             if (evt.allday && evt.dtstart.Hour == 0)
                dtstart = "  ";
            else
                dtstart = evt.dtstart.ToString("ddd hh:mm tt");

            var month_day = evt.dtstart.ToString("M/d");

            string categories = "";
            List<string> catlist_links = new List<string>();
            if (!String.IsNullOrEmpty(evt.categories))
            {
                List<string> catlist = Utils.GetTagListFromTagString(evt.categories);
                if (args.ContainsKey("hub_tags") )  // exclude autogenerated hub names
                {
                    var hub_tags = (List<string>)args["hub_tags"];
                    catlist = catlist.FindAll(c => hub_tags.Contains(c) == false);
                }

                // catlist = catlist.FindAll(c => c.Contains("{") == false); // don't show squiggly tags inline?
                // actually leave them in so client can show related images. curator can suppress display if desired using css

                foreach (var cat in catlist)
                {
                    var category_url = string.Format("javascript:show_view('{0}')", cat);
                    catlist_links.Add(string.Format(@"<a title=""open the {1} view"" href=""{0}"">{1}</a>", category_url, cat));
                }
                categories = string.Format(@" <span class=""cat"">{0}</span>", string.Join(", ", catlist_links.ToArray()));
            }

            String description = ( String.IsNullOrEmpty(evt.description) || evt.description.Length < 10 ) ? "" : evt.description.UrlsToLinks();

            string dom_id = "e" + evt.uid;

            string expander = "";
            if ( ! String.IsNullOrEmpty(description) && args.HasValue("eventsonly",true) )
                expander = String.Format(@"<span class=""sd""><a title=""show description"" href=""javascript:show_desc('{0}')"">...</a></span>", dom_id);

            string add_to_cal = String.Format(@"<span class=""atc""><a title=""add to calendar"" href=""javascript:add_to_cal('{0}')"">+</a></span>", dom_id);

            if ( args.HasValue("add_to_cal",false) ) // for view_calendar
                add_to_cal = "";

            string visibility = "";
            string more = "";
            string source_key = "";
            //string source_attr = "";  // not needed,
            int sequence_count = 1;
            int sequence_position = 1;
            string show_more_call;

            if (evt.urls_and_sources.Count == 1)
            {
                sequence_count = (int)args["sequence_count"];
                source_key = (string)args["source_key"];
                sequence_position = (int)args["sequence_position"];
            }

            visibility = (sequence_count > 1 && sequence_position > 1) ? @" style=""display:none"" " : "";

            if (sequence_count > 1 && sequence_position == 1)
            {
                show_more_call = "javascript:show_more('" + source_key + "')";
                more = string.Format(@" <span class=""{0}""><a title=""show {2} more from {3}"" href=""{1}"">show {2} more</a></span>",
                    source_key,
                    show_more_call,
                    sequence_count - 1,
                    evt.source
                    );
            }
            else
            {
                more = "";
            }

            var html = string.Format(
            @"<div id=""{0}"" class=""bl {12}"" {13} xmlns:v=""http://rdf.data-vocabulary.org/#"" typeof=""v:Event"" >
            <span style=""display:none"" class=""uid"">{15}</span>
            <span style=""display:none"" class=""hash"">{16}</span>
            <span class=""md"">{14}</span>
            <span class=""st"" property=""v:startDate"" content=""{1}"">{2}</span>
            <span href=""{3}"" rel=""v:url""></span>
            <span class=""ttl"">{4}</span>
            <span class=""src"" property=""v:description"">{5}</span> {6}
            {7}
            {8}
            {9}
            {11}
            </div>",
            dom_id,                                                 // 0
            String.Format("{0:yyyy-MM-ddTHH:mm}", evt.dtstart),     // 1
            dtstart,                                                // 2
            evt.url,                                                // 3
            MakeTitleForRDFa(evt, dom_id, args),                    // 4
            evt.urls_and_sources.Keys.Count == 1 ? evt.source : "", // 5 suppress source if multiple
            categories,                                             // 6
            MakeGeoForRDFa(evt),                                    // 7
            expander,                                               // 8
            add_to_cal,                                             // 9
            "",														// 10 was source_attr, not needed
            more,                                                   // 11
            source_key,                                             // 12
            visibility,                                             // 13
            month_day,												// 14
            evt.uid,												// 15
            evt.hash												// 16
            );

            this.event_counter += 1;
            return html;
        }
Example #3
0
        public static string MakeTitleForRDFa(ZonelessEvent evt, string dom_id, Dictionary<string,object> args)
        {
            var is_eventsonly = args.HasValue("eventsonly", true);
            var coalesced_links = BuildCoalescedLinks(evt, dom_id);
            bool is_coalesced = !String.IsNullOrEmpty(coalesced_links);

            // case 1: eventsonly, coalesced
            // <span class="ttl"><a target="elmcity" property="v:summary" title="open event page on source site" href="http://www.harriscenter.org/calendar">Homeschool Program: Biographies of Famous Birds</a></span>
            //
            // case 2: eventsonly, not coalesced
            // <span class="ttl"><span property="v:summary">Crazy Quilters</span> [<a target="elmcity" title="gilsum church" href="http://gilsum.org/church.aspx">&nbsp;1&nbsp;</a><a target="elmcity" title="town of gilsum" href="http://gilsum.org/">&nbsp;2&nbsp;</a>]</span>
            //
            // case 3: not eventsonly, coalesced
            // <span class="ttl"><span property="v:summary"><a href="javascript:show_desc('e3')">Crazy Quilters</a></span> [<a title="gilsum church" href="http://gilsum.org/church.aspx">&nbsp;1&nbsp;</a><a title="town of gilsum" href="http://gilsum.org/">&nbsp;2&nbsp;</a>]</span>
            //
            // case 4: not eventsonly, not coalesced
            // <span class="ttl"><a property="v:summary" title="see details" href='javascript:show_desc("e2")'>Lunchtime Rallies at Central Square</a></span>

            //  <span class="ttl"><span property="v:summary">Crazy Quilters</span> [<a target="elmcity" title="gilsum church" href="http://gilsum.org/church.aspx">&nbsp;1&nbsp;</a><a target="elmcity" title="town of gilsum" href="http://gilsum.org/">&nbsp;2&nbsp;</a>]</span>
            // otherwise this
            // <span class="ttl"><span property="v:summary"><a href="javascript:show_desc('e3')">Crazy Quilters</a></span> [<a title="gilsum church" href="http://gilsum.org/church.aspx">&nbsp;1&nbsp;</a><a title="town of gilsum" href="http://gilsum.org/">&nbsp;2&nbsp;</a>]</span>

            TitleType title_type;

            if (is_coalesced)
                title_type = is_eventsonly ? TitleType.EventsOnlyCoalesced : TitleType.NotEventsOnlyCoalesced;
            else
                title_type = is_eventsonly ? TitleType.EventsOnlyNotCoalesced : TitleType.NotEventsOnlyNotCoalesced;

            string title;

            if ( title_type == TitleType.EventsOnlyCoalesced )
                title = string.Format("<span property=\"v:summary\">{0}</span>", evt.title);
            else
                title = string.Format("<a property=\"v:summary\" title=\"{0}\" href=\"{1}\">{2}</a>",
                    is_eventsonly ? "open event page on source site": "see details",
                    is_eventsonly ? evt.url : string.Format("javascript:show_desc('{0}')", dom_id),
                    evt.title);

            if (is_coalesced)
                title += coalesced_links;

            return title;
        }