Skip to content

Commit 91b752f

Browse files
committed
review tutorial sharings and view-only
1 parent 1273f61 commit 91b752f

File tree

2 files changed

+64
-66
lines changed

2 files changed

+64
-66
lines changed

hf-data/js/sharing.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ async function createSharing() {
3030
return;
3131
}
3232
// set permissions
33-
const permissions = [];
34-
permissions.push({ streamId: 'hfdemo', level: 'read' });
33+
const permissions = [{ streamId: 'hfdemo', level: 'read' }];
3534

36-
const res = await pryvHF.pryvConn.api([
35+
const results = await pryvHF.pryvConn.api([
3736
// https://github.com/pryv/lib-js#api-calls
3837
{
3938
method: 'accesses.create', // creates the selected access: https://api.pryv.com/reference/#create-access
@@ -43,7 +42,7 @@ async function createSharing() {
4342
}
4443
}
4544
]);
46-
const error = res[0].error;
45+
const error = results[0].error;
4746
if (error != null) {
4847
displayError(error);
4948
return;

hf-data/tutorial.md

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ resultTreatment.push(
398398
## Create a sharing
399399
400400
Once data from the tracking task has been collected, the app is designed to allow the user to share his data with a third-party.
401-
The section "**Sharings**" enables the user to create a sharing that consists of an URL link with a Pryv apiEndpoint that displays the visualization from the tracking test. The code for the sharing creation is contained in the section **Sharings** of the file [script.js](script.js).
401+
The section "**Sharings**" enables the user to create a sharing that consists of a URL link with a Pryv apiEndpoint that displays the visualization from the tracking test. The code for the sharing creation is contained in the section **Sharings** of the file [script.js](script.js).
402402
In order to create a sharing, we add a listener to the *Create* button:
403403
404404
```javascript
@@ -418,54 +418,54 @@ async function createSharing() {
418418
```
419419
It will first fetch values for the scope of the sharing ('streamId' for permissions), in our case "read" level on the stream "**HF Demo**":
420420
```javascript
421-
const permissions = [];
422-
permissions.push({ streamId: 'hfdemo', level: 'read' });
421+
const permissions = [{ streamId: 'hfdemo', level: 'read' }];
423422
```
424423
425424
It will package those values into an [accesses.create](https://api.pryv.com/reference/#create-access) API call.
426425
```javascript
427-
const res = await pryvHF.pryvConn.api([
428-
{
429-
method: 'accesses.create',
430-
params: {
431-
name: name,
432-
permissions: permissions
433-
}
434-
}]);
435-
const error = res[0].error;
436-
if (error != null) {
437-
displayError(error);
438-
return;
426+
const results = await pryvHF.pryvConn.api([
427+
// https://github.com/pryv/lib-js#api-calls
428+
{
429+
method: 'accesses.create', // creates the selected access: https://api.pryv.com/reference/#create-access
430+
params: {
431+
name: name,
432+
permissions: permissions
433+
}
439434
}
440-
updateSharings();
441-
}
435+
]);
436+
const error = results[0].error;
437+
if (error != null) {
438+
displayError(error);
439+
return;
440+
}
441+
updateSharings();
442442
```
443443
444-
This call is made using [pryConn.api()](https://github.com/pryv/lib-js#api-calls) method.
444+
This call is made using [pryvConn.api()](https://github.com/pryv/lib-js#api-calls) method.
445445
446-
The sharings of the user are also displayed using the function **updateSharings()** that performs a [get.accesses](https://api.pryv.com/reference/#get-accesses) API call:
446+
The sharings of the user are also displayed using the function **updateSharings()** that performs an [accesses.get](https://api.pryv.com/reference/#get-accesses) API call:
447447
448448
```javascript
449449
async function updateSharings() {
450-
const result = await pryvHF.pryvConn.api([
451-
{
452-
method: 'accesses.get',
453-
params: {}
454-
}
455-
]);
456-
const sharingTable = document.getElementById('sharings-table');
457-
const accesses = result[0].accesses;
458-
if (!accesses || accesses.length === 0) {
459-
return;
460-
}
461-
resetTable('sharings-table');
462-
for (const access of accesses) {
463-
await addListAccess(sharingTable, access);
450+
const result = await pryvHF.pryvConn.api([
451+
{
452+
method: 'accesses.get',
453+
params: {}
464454
}
455+
]);
456+
const sharingTable = document.getElementById('sharings-table');
457+
const accesses = result[0].accesses;
458+
if (!accesses || accesses.length === 0) {
459+
return;
460+
}
461+
resetTable('sharings-table');
462+
for (const access of accesses) {
463+
await addListAccess(sharingTable, access);
464+
}
465465
}
466466
```
467467
468-
In the same way, the function **deleteSharing()** enables to delete the selected access by the user by performing an [accesses.delete](https://api.pryv.com/reference/#delete-access) API call.
468+
In the same way, the function **deleteSharing()** enables to delete the access selected by the user by performing an [accesses.delete](https://api.pryv.com/reference/#delete-access) API call.
469469
470470
```javascript
471471
async function deleteSharing(accessId) {
@@ -490,55 +490,54 @@ The recipient of the link can open the data visualization by clicking on the cho
490490
- the **Desktop version** contains the drawing performed with the mouse tracker
491491
- the **Mobile version** displays the recording of the phone orientation
492492
493-
The code for the visualization mode is contained in the section **Visualization only** of the file [script.js](script.js).
493+
The code for the visualization mode is contained in the [js/view_only.js](js/view_only.js).
494494
495495
This will load the app already authenticated, by passing the `pryvApiEndpoint` parameter in the function *buildVisualizationOnly(apiEndpoint, urlParams)*.
496496
497497
```javascript
498498
async function buildVisualizationOnly(apiEndpoint, urlParams) {
499-
pryvHF.pryvConn = new Pryv.Connection(apiEndpoint);
500-
console.log(pryvHF.pryvConn);
501-
let eventsList = await getEventList();
502-
populateCollectionTable(eventsList);
503-
const username = await pryvHF.pryvConn.username();
504-
document.getElementById("name-selection").innerHTML = "Data Collection Of " + username;
505-
const eventId_mouseX = urlParams.get('posXEventId');
506-
const eventId_mouseY = urlParams.get('posYEventId');
499+
document.getElementById('selection-data').style.display = '';
500+
pryvHF.pryvConn = new Pryv.Connection(apiEndpoint);
501+
502+
const eventsList = await getEventList();
503+
populateCollectionTable(eventsList);
504+
505+
const username = await pryvHF.pryvConn.username();
506+
document.getElementById('name-selection').innerHTML =
507+
'Data Collection Of ' + username;
508+
509+
const eventId_mouseX = urlParams.get('posXEventId');
510+
const eventId_mouseY = urlParams.get('posYEventId');
507511
```
508512
509513
Either the mobile or the desktop versions are displayed depending on the user's available data:
510514
```javascript
511-
if (eventId_mouseX && eventId_mouseY) {
515+
if (eventId_mouseX && eventId_mouseY) {
512516
pryvHF.measures.mouseX.event = {
513-
"id": eventId_mouseX
517+
id: eventId_mouseX
514518
};
515519
pryvHF.measures.mouseY.event = {
516-
"id": eventId_mouseY
520+
id: eventId_mouseY
517521
};
518522
buildDesktop();
519-
mouseVisu.style.display = "";
520-
}
521-
const eventId_alpha = urlParams.get('angleAEventId');
522-
const eventId_beta = urlParams.get('angleBEventId');
523-
const eventId_gamma = urlParams.get('angleYEventId');
524-
if (eventId_alpha && eventId_beta && eventId_gamma) {
523+
document.getElementById('mouse-visualization').style.display = '';
524+
}
525+
526+
const eventId_alpha = urlParams.get('angleAEventId');
527+
const eventId_beta = urlParams.get('angleBEventId');
528+
const eventId_gamma = urlParams.get('angleYEventId');
529+
if (eventId_alpha && eventId_beta && eventId_gamma) {
525530
pryvHF.measures.orientationAlpha.event = {
526-
"id": eventId_alpha
531+
id: eventId_alpha
527532
};
528533
pryvHF.measures.orientationBeta.event = {
529-
"id": eventId_beta
534+
id: eventId_beta
530535
};
531536
pryvHF.measures.orientationGamma.event = {
532-
"id": eventId_gamma
537+
id: eventId_gamma
533538
};
534539
buildMobile();
535-
accelerometerVisu.style.display = "";
536-
}
537-
document.getElementById('service').style.display = "none";
538-
mouseTracker.style.display = "none";
539-
accelerometerCollector.style.display = "none";
540-
sharing.style.display = "none";
541-
fetchPoints();
540+
document.getElementById('accelerometer-visualization').style.display = '';
542541
```
543542
544543
## App guidelines

0 commit comments

Comments
 (0)