Skip to content

Instantly share code, notes, and snippets.

@princeppy
Forked from vman/OfficeGraph.js
Created July 18, 2018 13:40
Show Gist options
  • Select an option

  • Save princeppy/c1c9da11bbdbd50ac551f971bd187d24 to your computer and use it in GitHub Desktop.

Select an option

Save princeppy/c1c9da11bbdbd50ac551f971bd187d24 to your computer and use it in GitHub Desktop.
'use strict';
(function ($) {
$(document).ready(loadEverything);
function loadEverything() {
var queryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?Querytext='*'" +
"&Properties='GraphQuery:ACTOR(ME\\, action\\:1019),GraphRankingModel:{\"features\"\\:[{\"function\"\\:\"EdgeWeight\"}]}'"+
"&RankingModelId='0c77ded8-c3ef-466d-929d-905670ea1d72'"+
"&SelectProperties='Title,UserName,Path'" +
"&RowLimit=10";
$.ajax({
url: queryUrl,
method: "GET",
headers: { "Accept": "application/json; odata=nometadata" },
success: function (data) {
var results = [];
$(data.PrimaryQueryResult.RelevantResults.Table.Rows).each(function (i, e) {
var o = {};
$(e.Cells).each(function (ii, ee) {
if (ee.Key == 'Title')
o.title = ee.Value;
else if (ee.Key == 'UserName')
o.username = ee.Value;
else if (ee.Key == 'Path')
o.path = ee.Value;
});
o.pic = _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/userphoto.aspx?size=m&accountname=' + o.username;
results.push(o);
})
RenderEverything(results);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus + " : " + errorThrown);
}
});
}
function RenderEverything(results) {
var previewsContainer = $("#OGPreviews");
$(results).each(function (i, e) {
var theImg = $("<a href='"+ e.path +"'><img src=" + e.pic + " title='"+ e.title +"'></img></a>");
previewsContainer.append(theImg);
})
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment