Skip to content

Instantly share code, notes, and snippets.

@leefsmp
Created March 26, 2015 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leefsmp/67da45c56a4fc2004833 to your computer and use it in GitHub Desktop.
Save leefsmp/67da45c56a4fc2004833 to your computer and use it in GitHub Desktop.
test
/////////////////////////////////////////////////////////////////////
// The Angular App
//
/////////////////////////////////////////////////////////////////////
var app = angular.module('Autodesk.ADN.Demo.Storage.App',
[
'js-data',
'mgcrea.ngStrap',
'mgcrea.ngStrap.tooltip',
'mgcrea.ngStrap.helpers.parseOptions'
]);
/////////////////////////////////////////////////////////////////////
// js-data store factory
//
/////////////////////////////////////////////////////////////////////
app.factory('store', function () {
var store = new JSData.DS();
store.registerAdapter(
'localstorage',
new DSLocalStorageAdapter(),
{ default: true });
return store;
});
app.factory('StateStore', function (store) {
return store.defineResource('state');
});
/////////////////////////////////////////////////////////////////////
// the App controller
//
/////////////////////////////////////////////////////////////////////
app.controller('Autodesk.ADN.Demo.Storage.Controller',
function ($scope, $http, $sce, StateStore) {
/////////////////////////////////////////////////////////////
// $scope members
//
/////////////////////////////////////////////////////////////
$scope.items = [];
$scope.selectedItem = null;
/////////////////////////////////////////////////////////////
// retrieve all stored states
//
/////////////////////////////////////////////////////////////
StateStore.findAll().then(function (states) {
states.forEach(function(state) {
$scope.items.push({
value: state.id,
label: $sce.trustAsHtml(state.name)
});
});
console.log(states);
});
/////////////////////////////////////////////////////////////
// AddState callback
//
/////////////////////////////////////////////////////////////
$scope.onAddState = function() {
var data = $scope.viewer.getState();
var name = new Date().toString(
'd/M/yyyy H:mm:ss');
var stateData = {
name: name,
data: data
}
StateStore.create(stateData)
.then(function(state) {
$scope.items.push({
value: state.id,
label: $sce.trustAsHtml(name)
});
});
}
/////////////////////////////////////////////////////////////
// ClearStates callback
//
/////////////////////////////////////////////////////////////
$scope.onClearStates = function() {
$scope.items = [];
StateStore.destroyAll();
}
/////////////////////////////////////////////////////////////
// watch selectedItem
//
/////////////////////////////////////////////////////////////
$scope.$watch('selectedItem', function() {
if($scope.selectedItem !== null) {
var state = StateStore.get(
$scope.selectedItem);
$scope.viewer.restoreState(state.data);
}
});
/////////////////////////////////////////////////////////////
// Load urn with token
//
/////////////////////////////////////////////////////////////
$scope.loadURN = function(token, urn) {
var config = {
environment : 'AutodeskProduction'
}
var viewerFactory =
new Autodesk.ADN.Toolkit.Viewer.AdnViewerFactory(
token,
config);
viewerFactory.getViewablePath (urn,
function(pathInfoCollection) {
var viewerConfig = {
qualityLevel: [false, false],
viewerType: 'GuiViewer3D',
lightPreset: 0
};
$scope.viewer = viewerFactory.createViewer(
$('#viewerStorageDemoDiv')[0],
viewerConfig);
$scope.viewer.load(
pathInfoCollection.path3d[0].path);
},
function (error) {
console.log('Error: ' + error);
});
}
/////////////////////////////////////////////////////////////
// Get token from the gallery (jsonp callback)
//
/////////////////////////////////////////////////////////////
$scope.getGalleryToken = function(onSuccess) {
var url = 'http://gallery.autodesk.io/api/token';
$http.jsonp(url + "?callback=JSON_CALLBACK").
success(function(data, status, headers, config) {
onSuccess(data.access_token);
}).
error(function(data, status, headers, config) {
console.log('Error: ' + status);
});
}
/////////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////////
$scope.getGalleryToken(function(token) {
$scope.loadURN(
token,
"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6YWRuLXZpZXdlci1nYWxsZXJ5L2EzZDgtYzgwZS0zMDY3LWI0ZDktM2ZmOC5kd2Z4");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment