Forum Discussion

giannag's avatar
giannag
Adept
14 years ago

I'm creating a calendar with REST API calls....

Hello! 

 

I have a section of my LIthium community dedicated to Events. 

 

I have 4 categories:  Americas Events, APJ Events, EMEA Events, and Virtual Events. 

 

Each new Event is a new board within its respective region category (e.g. Las Vegas Conference March 2012 is a board in Americas Events).

 

To maintain the health of the community, boards are only created 2-4 weeks before an event and are quickly moved into a Read Only "Past Events" category 2 weeks after the event.

 

I want to create a custom content calendar for the 10 most upcoming events.  This is how I imagine the pseudocode for a 3 event calendar:

______________________

variable: event1 = [BOARD ID]
variable: location1 = [Location text string]
variable: date1 = [Date text string]
variable: detail1 = [Web address text string]
variable: event2 = [BOARD ID]
variable: location2 = [Location text string]
variable: date2 = [Date text string]
variable: detail2 = [Web address text string]
variable: event3 = [BOARD ID]
variable: location3 = [Location text string]
variable: date3 = [Date text string]
variable: detail3 = [Web address text string]

 

<table>
<thead>
        <tr>
             <th>Date</th>
             <th>Event</th>
             <th>Details</th>
        </tr>
</thead>
<tbody>
        <tr>
             <td>date1</td>
             <td><a href="[REST API href CODE USING event1]">[REST API BOARD TITLE CODE USING event1]</a> location1 <br/>
    Latest Post - <a href="[REST API href CODE USING event1'S MOST RECENT POST]">[REST API RECENT POST TITLE CODE USING event1'S MOST RECENT POST]</a></td>
             <td><a href="detail1" target="_blank">Details >></a></td>
        </tr>
        <tr>
             <td>date2</td>
             <td><a href="[REST API href CODE USING event2]">[REST API BOARD TITLE CODE USING event2]</a> location2 <br/>
    Latest Post - <a href="[REST API href CODE USING event2'S MOST RECENT POST]">[REST API RECENT POST TITLE CODE USING event2'S MOST RECENT POST]</a></td>
             <td><a href="detail2" target="_blank">Details >></a></td>
        </tr>
        <tr>
             <td>date3</td>
             <td><a href="[REST API href CODE USING event3]">[REST API BOARD TITLE CODE USING event3]</a> location3 <br/>
    Latest Post - <a href="[REST API href CODE USING event3'S MOST RECENT POST]">[REST API RECENT POST TITLE CODE USING event3'S MOST RECENT POST]</a></td>
             <td><a href="detail3" target="_blank">Details >></a></td>
        </tr>
</tbody>
</table>

 ______________________

 

 

This is how I imagine the functionality:

- Admin creates the event board (e.g. San Jose Seminar December 2012), and puts it into the correct category (e.g. Americas Events)

- Admin copies all the relavent information into the variable fields (there will be a set number of variables), such as:

event1 = 932
location1 = in Las Vegas, NV
date1 = December 5, 2011
detail1 = http://www.seminars.com/LV2012
event2 = 476
location2 = in Orlando, FL
date2 = December 10-12, 2011
detail2 = http://www.conference.com/orlando
event3 = 870
location3 = in London, UK
date3 = January 4, 2012
detail3 = http://www.event.com/london12

 

 

And this is how I imagine the output:

 ______________________

 

DateEventDetails
December 5, 2011Las Vegas Seminar in Las Vegas, NV
Latest Post - Re: Upcoming Agenda
Details >>
December 10-12, 2011Florida Conference in Orlando, FL
Latest Post - Nearby Hotels
Details >>
January 4, 2012UK Event in London, UK
Latest Post - Re: What are your travel plans?
Details >>

 ______________________

 

 

What do you guys think?  Doable?  I'm hoping that I can use variables because this is custom content and I want the community admins to be able to update this whenever they need to.

 

Any code samples or advice would be greatly appreciated!!

 

Best,
Gianna

1 Reply

  • I think what you want to do is very doable.  We've done something very similar with a custom leaderboard widget.  We used a community-wide setting to hold a JSON encoded leaderboard object that we deserialize using JavaScript and Freemarker.  That may be a bit extreme for you, but you could achieve the same results by having four community-wide settings properties:

     

    customer.events

    customer.locations

    customer.dates

    customer.details

     

    Pick better names, then ask Lithium to set them up for you.  Once they're in place, you could create a custom widget with this Freemarker code:

     

    <#assign events = resetadmin("/settings/name/customer.events").value?split("|") />
    <#assign dates = restadmin("/settings/name/customer.dates").value?split("|") />
    <#assign locations = restadmin("/settings/name/customer.locations").value?split("|") />
    <#assign details = restadmin("/settings/name/customer.details").value?split("|") />
    
    <table>
    <thead>
            <tr>
                 <th>Date</th>
                 <th>Event</th>
                 <th>Details</th>
            </tr>
    </thead>
    <tbody>
    <#list events as event>
      <#assign event_board = restadmin("/boards/id/" + event + "?restapi.response_style=view").board />
      <#assign event_href = event_board.@view_href />
      <#assign event_title = event_board.title />
      <#assign latest_message = restadmin("/boards/id" + event + "/messages/latest?restapi.response_style=view") />
      <#assign latest_post = latest_message.message.@view_href />
      <#assign latest_post_subj = latest_message.message.subject />
            <tr>
                 <td>${dates[event_index]}</td>
                 <td><a href="${event_href}">${event_title}</a> ${locations[event_index]} <br/>
        Latest Post - <a href="${latest_post}">${latest_post_subj}</a></td>
                 <td><a href="${details[event_index]}" target="_blank">Details >></a></td>
            </tr>
    </#list>
    </tbody>
    </table>

     

    You would then populate your settings properties with things like:

     

    customer.events => Americas Events|EU Events|AU Events

    customer.locations => in Las Vegas|in London|in Sydney

    ...

     

    This would need to be done by some off-platform script, but you could also built custom widgets within Lithium that admins could use to set these properties.