Skip to content

Commit

Permalink
adds .pinned property to tools, and corresponding POST /pinned/ API t…
Browse files Browse the repository at this point in the history
…o update it on the server, and spatialInterface API for tools to specific and toggle setPinned
  • Loading branch information
benptc committed Mar 26, 2021
1 parent 322dcf8 commit d780e8d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions controllers/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,25 @@ const setGroup = function(objectID, frameID, body, callback) {
callback(404, {success: false, error: 'Couldn\'t find frame ' + frameID + ' to set groupID'});
};

const setPinned = function(objectID, frameID, body, callback) {
var frame = utilities.getFrame(objects, objectID, frameID);
if (frame) {
var newPinned = body.isPinned;
if (newPinned !== frame.pinned) {
frame.pinned = newPinned;
utilities.writeObjectToFile(objects, objectID, objectsPath, globalVariables.saveToDisk);
utilities.actionSender({
reloadFrame: {object: objectID, frame: frameID},
lastEditor: body.lastEditor
});
callback(200, {success: true});
return;
}
}

callback(404, {success: false, error: 'Couldn\'t find frame ' + frameID + ' to set pinned'});
};

/**
* Updates the x, y, scale, and/or matrix for the specified frame or node
* @todo this function is a mess, fix it up
Expand Down Expand Up @@ -514,6 +533,7 @@ module.exports = {
updateFrame: updateFrame,
deleteFrame: deleteFrame,
setGroup: setGroup,
setPinned: setPinned,
changeSize: changeSize,
changeVisualization: changeVisualization,
resetPositioning: resetPositioning,
Expand Down
9 changes: 9 additions & 0 deletions libraries/objectDefaultFiles/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
isFullScreenExclusive: false,
attachesTo: null,
wasToolJustCreated: null,
isPinned: true,
height: '100%',
width: '100%',
socketIoScript: {},
Expand Down Expand Up @@ -604,6 +605,7 @@
this.getPositionInWorld = makeSendStub('getPositionInWorld');
this.useWebGlWorker = makeSendStub('useWebGlWorker');
this.wasToolJustCreated = makeSendStub('wasToolJustCreated');
this.setPinned = makeSendStub('setPinned');
// deprecated methods
this.sendToBackground = makeSendStub('sendToBackground');
}
Expand Down Expand Up @@ -1607,6 +1609,13 @@
// return spatialObject.wasToolJustCreated;
};

this.setPinned = function(isPinned) {
spatialObject.isPinned = isPinned;
postDataToParent({
setPinned: isPinned
});
};

/**
* Stubbed here for backwards compatibility of API. In previous versions:
* Hides the frame itself and instead populates a background context within the editor with this frame's contents
Expand Down
2 changes: 2 additions & 0 deletions models/Frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function Frame(objectId, frameId) {
this.distanceScale = 1.0;
// Indicates what group the frame belongs to; null if none
this.groupID = null;
// "Pinned" frames are by default loaded and visible with the object they belong to. Unpinned must be asked for.
this.pinned = true;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions routers/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,16 @@ router.post('/:objectName/frame/:frameName/group/', function (req, res) {
});
});

router.post('/:objectName/frame/:frameName/pinned/', function (req, res) {
if (!utilities.isValidId(req.params.objectName) || !utilities.isValidId(req.params.frameName)) {
res.status(400).send('Invalid object or frame name. Must be alphanumeric.');
return;
}
frameController.setPinned(req.params.objectName, req.params.frameName, req.body, function(statusCode, responseContents) {
res.status(statusCode).json(responseContents).end();
});
});

const setupDeveloperRoutes = function() {
// normal nodes
router.post('/:objectName/frame/:frameName/node/:nodeName/size/', function (req, res) {
Expand Down

0 comments on commit d780e8d

Please sign in to comment.