[Inspector] Separate primary and contextual locations

The object inspector now finds both the contextual
location of the link and the primary location of
the original, if the selected object is a link. #73.
This commit is contained in:
slhale 2015-08-24 15:48:50 -07:00
parent 454b96c3c9
commit 70324a2198
3 changed files with 59 additions and 13 deletions

View File

@ -108,7 +108,7 @@
{
"key": "ObjectInspectorController",
"implementation": "controllers/ObjectInspectorController.js",
"depends": [ "$scope" ]
"depends": [ "$scope", "objectService" ]
}
],
"directives": [

View File

@ -29,10 +29,21 @@
<em>{{ data.name }}</em>
{{ data.value }}
</li>
<li>
<em>Location </em>
<li ng-if="contextutalParents.length > 0">
<em>Contextual Location </em>
<span class="inspector-location"
ng-repeat="parent in parents">
ng-repeat="parent in contextutalParents">
<mct-representation key="'label'"
mct-object="parent"
ng-model="ngModel"
ng-click="ngModel.selectedObject = parent">
</mct-representation>
</span>
</li>
<li ng-if="primaryParents.length > 0">
<em>Primary Location </em>
<span class="inspector-location"
ng-repeat="parent in primaryParents">
<mct-representation key="'label'"
mct-object="parent"
ng-model="ngModel"

View File

@ -35,11 +35,13 @@ define(
*
* @constructor
*/
function ObjectInspectorController($scope) {
$scope.parents = [];
function ObjectInspectorController($scope, objectService) {
$scope.primaryParents = [];
$scope.contextutalParents = [];
//$scope.isLink = false;
// Gets an array of the parents/anscestors of the selected object
function getPath() {
// Gets an array of the contextual parents/anscestors of the selected object
function getContextualPath() {
var currentObj = $scope.ngModel.selectedObject,
currentParent,
parents = [];
@ -53,20 +55,53 @@ define(
currentObj = currentParent;
}
$scope.parents = parents;
$scope.contextutalParents = parents;
}
// Gets an array of the parents/anscestors of the selected object's
// primary location (locational of original non-link)
function getPrimaryPath(current) {
var location;
// If this the the initial call of this recursive function
if (!current) {
current = $scope.ngModel.selectedObject;
$scope.primaryParents = [current];
}
location = current.getModel().location;
if (location && location !== 'root') {
objectService.getObjects([location]).then(function (obj) {
var next = obj[location];
$scope.primaryParents.unshift(next);
getPrimaryPath(next);
});
}
}
// Gets the metadata for the selected object
function getMetadata() {
$scope.metadata = $scope.ngModel.selectedObject &&
$scope.ngModel.selectedObject.hasCapability('metadata') &&
$scope.ngModel.selectedObject.useCapability('metadata');
var sel = $scope.ngModel.selectedObject;
$scope.metadata = sel && sel.hasCapability('metadata') && sel.useCapability('metadata');
}
// Set scope variables when the selected object changes
$scope.$watch('ngModel.selectedObject', function () {
var sel = $scope.ngModel.selectedObject;
$scope.isLink = sel && sel.hasCapability('location') && sel.getCapability('location').isLink();
if ($scope.isLink) {
getPrimaryPath();
getContextualPath();
} else {
$scope.primaryParents = [];
getContextualPath();
}
getMetadata();
getPath();
});
}