Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 343 #634

Merged
merged 11 commits into from
Dec 5, 2016
44 changes: 19 additions & 25 deletions data/people/profile.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<ml:page disable-comments="yes" status="Published" xmlns:ml="http://developer.marklogic.com/site/internal" xmlns="http://www.w3.org/1999/xhtml">

<script xml:space="preserve">
if (! "<ml:user-name/>") { window.location.href = '/'; }
</script>
<h1><ml:first-name/>'s Profile </h1>
<script xml:space="preserve">
if (! "<ml:user-name/>") { window.location.href = '/'; }
</script>
<h1><ml:first-name/>'s Profile</h1>

<form method="post" action="#" id="profile-form" enctype="application/x-www-form-urlencoded">
<ml:profile/>
<fieldset>
<div class="row">
<form method="post" action="#" id="profile-form" enctype="application/x-www-form-urlencoded" class="col-md-6">
<ml:profile/>
<fieldset>
<div class="signup-form-row">
<input class="button" id="profile-save" value="Save" type="submit"/>
<a href="/reset"><span id="change-passwd">Change password</span></a>    <span id="changes-saved">Changes saved</span>
<input class="button" id="profile-save" value="Save" type="submit"/>
<a href="/reset"><span id="change-passwd">Change password</span></a>    
<span id="changes-saved">Changes saved</span>
</div>
<div class="signup-form-row">
</div>
</fieldset>
</form>
</fieldset>
</form>
<div class="col-md-6">
<ml:preferences/>
</div>
</div>

<script xml:space="preserve">
$(document).ready(function() {
jQuery.validator.addMethod("twitter", function(value, element) {
return this.optional(element) || /^@.+/.test(value);
}, "Please specify a valid twitter handle");
<script src="/js/profile.js"></script>

$('#profile-form').validate({
"errorClass": "signup-form-error"
});
});

$('#profile-form').dirtyForms();
</script>

</ml:page>
</ml:page>
3 changes: 3 additions & 0 deletions src/apidoc/controller/rewrite.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ declare function m:rewrite()

else if (starts-with($PATH, '/xray')) then m:xray()

(: Support retrieving user preferences :)
else if ($PATH eq "/people/preferences") then "/controller/preferences.xqy"

(: Root request: "/" means "index.xml" inside the default version directory :)
else if ($PATH eq '/') then m:transform($ROOT-DOC-URL)

Expand Down
68 changes: 65 additions & 3 deletions src/apidoc/js/toc_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ function tocInitGlobals() {
"[tocInitGlobals] No tocSectionLinkSelector!");
}

function saveSectionPref(event) {
var select = document.getElementById('toc_select');
var preferredSection = select.options[select.selectedIndex].text;
var selections = {
setting: 'doc-section',
value: preferredSection
};
$.ajax({
url: '/people/preferences',
method: 'POST',
data: selections,
success: function() {
console.log('preference saved');
},
error: function(error) {
console.log('error: ' + error);
}
});

}

function tocInit() {
LOG.debug("tocInit");

Expand Down Expand Up @@ -139,8 +160,7 @@ function tocInit() {
prerendered: true,
url: tocPartsDir }); });

// Set up the select widget
tocSelect.change(function(e) {
function changeSelection() {
LOG.debug('TOC select option changed');
// Hide the old TOC tree.
$(".apidoc_tree:visible").hide();
Expand All @@ -159,7 +179,49 @@ function tocInit() {
tree.show();

tocFilterUpdate();
});
}

// Set up the select widget
tocSelect.change(changeSelection);

if (!tocSectionLinkSelector) {
$.ajax({
url: '/people/preferences',
method: 'GET',
dataType: 'json',
success: function(data) {
if (data.currentUserId) {
// The user is logged in. Change to the preferred section of the docs.
var preferredSection = data['doc-section'];
var select = document.querySelector('#toc_select');
var options = document.querySelectorAll('#toc_select option');
var initiallySelected = select.selectedIndex;
for (var i in options) {
if (options.hasOwnProperty(i)) {
if (options[i].text === preferredSection) {
select.selectedIndex = i;
}
}
}
if (initiallySelected !== select.selectedIndex) {
changeSelection();
}
} else {
// The user is not logged in.
var saveBtn = document.getElementById('save-section-pref');
if (saveBtn) {
saveBtn.setAttribute('disabled', true);
saveBtn.setAttribute('title', 'Log in to save preferred section');
}
}
},
error: function(error) {
console.log('error trying to get preferences: ' + JSON.stringify(error));
}
});
}

$('#save-section-pref').click(saveSectionPref);

// Set up the filter
tocInitFilter($("#config-filter"),
Expand Down
40 changes: 24 additions & 16 deletions src/apidoc/setup/toc.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -855,24 +855,32 @@ as element()
'toc:render-content',
($uri, $prefix-for-hrefs, xdmp:describe($toc))),
<div id="tocs_all" class="toc_section" xmlns="http://www.w3.org/1999/xhtml">
<div class="toc_select">
Section: <select id="toc_select">
{
(: To preserve node order, use SMO rather than XPath. :)
$toc/toc:node
! toc:render-select-option(., . is $selected)
}
<div class="toc_select row">
<label class="">Section:</label>
<select id="toc_select" class="">
{
(: To preserve node order, use SMO rather than XPath. :)
$toc/toc:node
! toc:render-select-option(., . is $selected)
}
</select>
<button type="button" class="btn btn-default btn-xs"
id="save-section-pref"
title="Save section preference">
<span class="glyphicon glyphicon-save"></span>
</button>
</div>
<div class="scrollable_section">
<input id="config-filter" name="config-filter" class="config-filter"/>
<img src="/apidoc/images/removeFilter.png" id="config-filter-close-button"
class="config-filter-close-button"/>
<div id="treeglobal" class="treecontrol top_control global_control">
<span class="expand" title="Expand the entire tree below">
<img id="treeglobalimage" src="/css/apidoc/images/plus.gif"></img>
<span id="treeglobaltext">expand</span>
</span>
<div class="scrollable_section row">
<div class="filter">
<input id="config-filter" name="config-filter" class="config-filter"/>
<img src="/apidoc/images/removeFilter.png" id="config-filter-close-button"
class="config-filter-close-button"/>
<div id="treeglobal" class="treecontrol top_control global_control">
<span class="expand" title="Expand the entire tree below">
<img id="treeglobalimage" src="/css/apidoc/images/plus.gif"></img>
<span id="treeglobaltext">expand</span>
</span>
</div>
</div>
<div id="apidoc_tree_container" class="pjax_enabled">
{
Expand Down
27 changes: 27 additions & 0 deletions src/controller/preferences.xqy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
xquery version "1.0-ml";

import module namespace users="users" at "/lib/users.xqy";

declare option xdmp:mapping "false";

declare variable $REQUEST := xdmp:get-request-method();

if ($REQUEST = "GET") then
users:get-prefs-as-json(users:getCurrentUser())
else if ($REQUEST = "POST") then
let $setting := xdmp:get-request-field("setting")
let $value := xdmp:get-request-field("value")
return
try {
users:set-preference(users:getCurrentUser(), $setting, $value),
"success"
} catch ($e) {
if ($e/error:name = "NO-USER") then
xdmp:set-response-code(401, $e/error:code/fn:string())
else if ($e/error:name = "INVALID-PREFERENCE") then
xdmp:set-response-code(400, $e/error:code/fn:string())
else
xdmp:rethrow()
}
else
xdmp:set-response-code(405, "Method Not Allowed")
5 changes: 3 additions & 2 deletions src/controller/rewrite.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ as xs:string
else if ($path = ("/pubs/4.0", "/pubs/4.0/")) then $srv:api-server
else if ($path = ("/pubs/3.2", "/pubs/3.2/")) then $srv:api-server
else if ($path eq "/tools") then "/code"
else if (matches($path, "^/[0-9]\.[0-9]$"))
else if (matches($path, "^/[0-9]\.[0-9]$"))
then concat($srv:api-server, $path)

else if (matches($path, "/pubs/[\d]\.[\d]/apidocs/")) then
Expand Down Expand Up @@ -204,7 +204,7 @@ as xs:string
else if ($path = ("/adventure")) then
"/"
else if (starts-with($path, "/people")) then (: All people urls are gone for now :)
if ($path = ("/people/signup", "/people/reset", "/people/recovery", "/people/profile")) then (: except for these :)
if ($path = ("/people/signup", "/people/reset", "/people/recovery", "/people/profile", "/people/preferences")) then (: except for these :)
$path
else
"/people/supernodes"
Expand Down Expand Up @@ -422,6 +422,7 @@ as xs:string
else if ($path eq "/reset") then concat(
"/controller/reset.xqy?", $query-string)
else if ($path eq "/save-profile") then "/controller/save-profile.xqy"
else if ($path eq "/people/preferences") then "/controller/preferences.xqy"
else if ($path eq "/recent") then "/controller/recent.xqy"
else if ($path eq '/service/suggest') then concat(
'/controller/suggest.xqy?', $query-string)
Expand Down
44 changes: 31 additions & 13 deletions src/css/apidoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,14 @@ ol ol {
#apidoc_toc,
#all_tocs,
.toc {
height: 100%;
margin: 0;
padding: 0;
}
#toc_content {
width: 100%;
background: #fff;
height: 100%;
padding: 16px 0 16px 0;
}

Expand Down Expand Up @@ -267,20 +269,36 @@ ol ol {

.toc_select {
position: inherit;
margin-left: 16px;
margin-right: 5px;
margin-left: 0;
}

select#toc_select {
width: 98%;
/* For browsers that support calc. */
width: calc(100% - 96px);
.toc_select label {
float: left;
margin-left: 16px;
}

.toc_select select#toc_select {
float: left;
margin-left: 5px;
}

.toc_select button {
float: right;
}

.scrollable_section {
height: 100%;
margin-right: 5px;
margin-left: 0;
position: inherit;
}

.scrollable_section > input {
#apidoc_tree_container {
height: calc(100% - 44px);
}

.scrollable_section .filter input {
border: 1px solid #ccc;
font-size: 11px;
margin: 8px 0 0 16px;
Expand Down Expand Up @@ -315,7 +333,7 @@ h1 a,

.treecontrol.top_control {
float: right;
margin: 8px 24px 0 0;
margin: 8px 0 0 0;
cursor: pointer;
font-size: .9em;
}
Expand Down Expand Up @@ -352,17 +370,14 @@ h1 a,

/* override treeview CSS */
.treeview {
position: absolute;
top: 78px;
bottom: 0;
width: 98%;
width: 100%;
/* For browsers that support calc. */
width: calc(100% - 12px);
overflow-y: auto;
-webkit-overflow-scrolling: touch;
/* android may need this so touch-scrolling works. */
z-index: 0;
border-top: 1px solid #ccc;
height: 100%;
}
.treeview a.toc_root {
font-weight: bold;
Expand Down Expand Up @@ -487,6 +502,9 @@ a.sectionLink:hover {
}

.toc_section {
height: 100%;
/* width is 100% - width of splitter - width of Bootstrap margin negative offset */
width: calc(100% - 12px);
}

.api_caption {
Expand Down Expand Up @@ -732,7 +750,7 @@ span.highlightWidget {
.toc_select {
margin-left: 4px;
}
.scrollable_section > input {
.scrollable_section .filter input {
margin-left: 4px;
}
#api_sub {
Expand Down
4 changes: 1 addition & 3 deletions src/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -2919,9 +2919,7 @@ span.highlightWidget {
}

#signup-form,
#signup-form input,
#profile-form,
#profile-form input {
#signup-form input {
font-size: 16px;
}

Expand Down
10 changes: 10 additions & 0 deletions src/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,20 @@ if(typeof jQuery != 'undefined') {
$('#login-trigger').hide();
$('#session-trigger').text(data.name);
$('#session-trigger').show();
// If we're on the docs page, enable the save-section-preference button
var saveBtn = document.getElementById('save-section-pref');
if (saveBtn) {
saveBtn.removeAttribute('disabled');
saveBtn.setAttribute('title', 'Save section preference');
}

} else {
$('#login-error').text(data.status);
}
},
error: function(error) {
console.log('problem during login');
},
dataType: 'json'
});
});
Expand Down
Loading