Jump to content

Closing a session in Javascript API


andRobots

Recommended Posts

  • 2 months later...
On 5/22/2018 at 3:29 AM, Mattias Lagergren said:

I'm afraid there is no equivalent to what we have in the ftrack-python-api. How are you using the ftrack-javascript-api, are you building a custom widget?

Not exactly.

I'm calling the API from the main HTML document of an Adobe CEP panel (https://github.com/Adobe-CEP/Getting-Started-guides) in almost exactly the way it's called in this example in the FTrack documentation: http://ftrack-javascript-api.rtd.ftrack.com/en/stable/tutorial.html. With the goal of getting data from a users Tasks and displaying it in a <div>.

It's extremely simple, here's a rough breakdown of the html:

<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
			<!-- Ftrack API -->
			<script src="./lib/ftrack.min.js"></script>
	</head>	
	<body>
			<div>
				<button id="loadFTrackStuff" onclick="getTaskList()">Load Tasks</button>
			</div>
			<div id="taskList"></div>
	</body>
	<script>
		function getTaskList() {

			document.getElementById("taskList").innerHTML = '';

			var session = new ftrack.Session(
				'https://my-company.ftrackapp.com',
				'john.doe@example.com',
				'7545344e-a653-11e1-a82c-f22c11dd25eq'
			);

			session.initializing.then(function () {
				var request = session.query('select name, type.name, custom_attributes, incoming_links, outgoing_links, priority.name from Task where status.name is "Ready To Start" and assignments any (resource.username = "john.doe@example.com")');
				request.then(function (response) {
					var taskData = response.data;
					var tdl = taskData.length;
					for (var i = 0; i < tdl; i++) {
						document.getElementById("taskList").innerHTML += "<div>" + taskData[i].name + ",  <b>Type:</b>" + taskData[i].type.name + ",  <b>Priority:</b>" + taskData[i].priority.name + '</div><div>(' + (taskData[i].incoming_links.length+taskData[i].outgoing_links.length) +  "Links) " + (taskData[i].custom_attributes[0].key + ":" + taskData[i].custom_attributes[0].value) + " " + (taskData[i].custom_attributes[3].key + ":" + taskData[i].custom_attributes[3].value) + "</div>";
					}
				});
			});

		}
	</script>
</html>

Everything works fine, I was just curious if this sort of use is problematic if the session(s) are never closed explicitly.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...