13
EXTENDING QUERIES & REPORTS WITH JSON & JQUERY Case Western Reserve University

Extending Slate Queries & Reports with JSON & JQUERY

Embed Size (px)

Citation preview

Page 1: Extending Slate Queries & Reports with JSON & JQUERY

EXTENDING QUERIES & REPORTS WITH JSON & JQUERY

Case Western Reserve University

Page 2: Extending Slate Queries & Reports with JSON & JQUERY

Tools

JSON (JavaScript Object Notation):

• open standard alternative to XML

• name/value pairs• http://json.org

jQuery:

• open source JavaScript library

• client side• http://jquery.com

Page 3: Extending Slate Queries & Reports with JSON & JQUERY

Embedding Upcoming Events

Page 4: Extending Slate Queries & Reports with JSON & JQUERY

In Slateselect getdate() as [@updated], (select f.[category] as [folder], f.[date] as [dtstart], f.[dtend], f.[deadline], coalesce(f.[summary], p.[summary]) as [title], coalesce(f.[location], p.[location]) as [location], coalesce(f.[street], p.[street]) as [street], coalesce(f.[city], p.[city]) as [city], coalesce(f.[region], p.[region]) as [region], coalesce(f.[postal], p.[postal]) as [postal], coalesce(f.[country], p.[country]) as [country], (select [name] from [world].dbo.[country] where ([id] = coalesce(f.[country], p.[country]))) as [countryName], convert(varchar, coalesce(f.[geo], p.[geo]).Lat) as [lat], convert(varchar, coalesce(f.[geo], p.[geo]).Long) as [lng], (select [value] from [config] where ([key] = 'https')) + '/register/' + coalesce(f.[alias] + '/', '?id=' + dbo.toGuidString(f.[id])) as [url], (select f.[description] as [node()] for xml path('')) as [description] from [form] f left outer join [form] p on (p.[id] = f.[parent]) where (f.[type] = 'event') and (f.[date] > getdate()) and (f.[category] = 'Campus Visit') and (f.[summary] != 'Campus Tour and Information Session') for xml path('event'), type)for xml path('events'), type

Page 5: Extending Slate Queries & Reports with JSON & JQUERY

Output{"events":{"@updated":"2014-06-19T14:47:40.963","event":[{"folder":"Campus Visit","dtstart":"2014-06-27T09:00:00","dtend":"2014-06-27T12:00:00","title":"Campus Preview Day","location":"Thwing Center - Case Western Reserve University","street":"11111 Euclid Ave","city":"Cleveland","region":"OH","postal":"44106-1715","country":"US","countryName":"United States","lat":"41.5074","lng":"-81.6083","url":"https://go.case.edu/register/?id=7c2dcda2-7f40-4918-bcb6-97d60ef318ea","description":null},{"folder":"Campus Visit","dtstart":"2014-07-11T09:00:00","dtend":"2014-07-11T12:00:00","title":"Campus Preview Day","location":"Thwing Center - Case Western Reserve University","street":"11111 Euclid Ave","city":"Cleveland","region":"OH","postal":"44106-1715","country":"US","countryName":"United States","lat":"41.5074","lng":"-81.6083","url":"https://go.case.edu/register/?id=904b243a-7323-4f85-96df-3fe3babe15f9","description":null},{"folder":"Campus Visit","dtstart":"2014-07-18T09:00:00","dtend":"2014-07-18T12:00:00","title":"Campus Preview Day","location":"Thwing Center - Case Western Reserve University","street":"11111 Euclid Ave","city":"Cleveland","region":"OH","postal":"44106-1715","country":"US","countryName":"United States","lat":"41.5074","lng":"-81.6083","url":"https://go.case.edu/register/?id=fdf7e3f3-ba0a-4458-9d9d-203f21e9b95a","description":null},{"folder":"Campus Visit","dtstart":"2014-07-25T09:00:00","dtend":"2014-07-25T12:00:00","title":"Campus Preview Day","location":"Thwing Center - Case Western Reserve University","street":"11111 Euclid Ave","city":"Cleveland","region":"OH","postal":"44106-1715","country":"US","countryName":"United States","lat":"41.5074","lng":"-81.6083","url":"https://go.case.edu/register/?id=e29a3913-d467-40d1-bc4b-70b0d3b53487","description":null},{"folder":"Campus Visit","dtstart":"2014-08-01T09:00:00","dtend":"2014-08-01T12:00:00","title":"Campus Preview Day","location":"Thwing Center - Case Western Reserve University","street":"11111 Euclid Ave","city":"Cleveland","region":"OH","postal":"44106-1715","country":"US","countryName":"United States","lat":"41.5074","lng":"-81.6083","url":"https://go.case.edu/register/?id=01a05b75-2a0b-4b24-8514-596ea3c5597d","description":null},{"folder":"Campus Visit","dtstart":"2014-08-08T09:00:00","dtend":"2014-08-08T12:00:00","title":"Campus Preview Day","location":"Thwing Center - Case Western Reserve University","street":"11111 Euclid Ave","city":"Cleveland","region":"OH","postal":"44106-1715","country":"US","countryName":"United States","lat":"41.5074","lng":"-81.6083","url":"https://go.case.edu/register/?id=7b59f46a-7b15-4693-a7ed-715f5657068a","description":null}]}}

Page 6: Extending Slate Queries & Reports with JSON & JQUERY

<head>…<script src="http://code.jquery.com/jquery-1.9.1.js"></script>…</head>

In HTML

Page 7: Extending Slate Queries & Reports with JSON & JQUERY

In HTML

<div class="sideContent"><h4>Upcoming Events</h4><ul id="div-event-list"></ul>

<div class="calLink"><p>&raquo; <a href="/visit/eventcalendar.aspx">View full visit calendar</a></p></div>

Page 8: Extending Slate Queries & Reports with JSON & JQUERY

In HTML<script type="text/javascript">$.getJSON('http://go.case.edu/manage/query/process?id=f7df9cdb-022a-4346-a794-5c2ccb74626a&h=2352b7fd-52ea-3b19-d383-3ab9b1e25809&output=json'+ '&callback=?', function(data) {

if (!data.events.event) {$("#div-event-list").append("<p style='padding-

left:15px'><strong>We're working hard on scheduling our next round of events on campus!</strong></p>");

} else {if (data.events.event.length) {

// more than onefor (i=0; i<data.events.event.length; i++) {

$("#div-event-list").append("<li><strong>" + dateFormat(data.events.event[i].dtstart, "mmmm d") +"</strong> - <a href='" + data.events.event[i].url + "' target='_blank'>" + data.events.event[i].title + "</a></li>");}

} else {// works for one$.each([data.events.event], function () {$("#div-event-list").append("<li><strong>" +

dateFormat(this.dtstart, "mmmm d") +"</strong> - <a href='" + this.url + "' target='_blank'>" + this.title + "</a></li>");});}}});</script>

Page 9: Extending Slate Queries & Reports with JSON & JQUERY

Updating Other LOB Software

Page 10: Extending Slate Queries & Reports with JSON & JQUERY

In Slateselect p.[user],/* Admitted Student Questions */CASE

WHEN EXISTS(SELECT p.idfrom [form.response] __rinner join [form] __f on (__f.[id] = __r.[form])inner join [person] p on (p.[id] = __r.[record])where(__f.[id] = '584465DF-AA36-4C2E-9481-D79E83221BB0') and (__r.[pending] = 0) and (__r.[active] = 1) and (p.[user] =

@cwrunetid)) THEN 1ELSE 0

END AS 'SLAS',.../* Indians Game */CASE

WHEN EXISTS(SELECT p.idfrom [form.response] __rinner join [form] __f on (__f.[id] = __r.[form])inner join [person] p on (p.[id] = __r.[record])where(__f.[id] = 'F0DF5D33-A5AD-4CF3-95BC-FC0810F1F82D') and (__r.[pending] = 0) and (__r.[active] = 1) and (p.[user] =

@cwrunetid)) THEN 1ELSE 0

END AS 'SLBB',/* Final HS Transcript */CASE

WHEN EXISTS( select p.[ref]from [application] ainner join [person] p on (p.[id] = a.[person])where

((a.[id] IN (select a.[id] from [material] m inner join [application] a on (a.[person] = m.[record]) where (m.[key] in ('ft')) and (m.[record] is not null) union all select [record] from [material] where ([key] in ('ft')) and ([record] is not null)))) and (p.[user] = @cwrunetid)) THEN 1

ELSE 0END AS 'SLFT'from [person] pwhere (p.[user] = @cwrunetid)for xml path('person'), type

Page 11: Extending Slate Queries & Reports with JSON & JQUERY

Request:

https://go.case.edu/manage/query/process?id=219d4e7b-3c8b-4413-b70d-86b65a0580b5&h=baf86e5d-8596-646e-3fd6-e1b4984b2673&output=json&cwrunetid=cxh456

{"person":{"user":"cxh456","SLAS":"1","SLOR":"1","SLBB":"0","SLTB":"0","SLSV":"0","SLDC":"0","SLPF":"0","SLIW":"1","SLIA":"1","SLAD":"Tastes","SLRI":"0","SLFT":"0"}}

Returns:

Page 12: Extending Slate Queries & Reports with JSON & JQUERY

Questions?

Page 13: Extending Slate Queries & Reports with JSON & JQUERY

ContactJonathan Wehner

Director of Recruitment and Strategic [email protected]@jonathanwehner

Bob McCullough

Director of Undergraduate [email protected]@bobcwru