openmct/src/ui/components/layout/BrowseObject.vue
Deep Tailor 08cd6b1d99 Vue Browse Bar (#2164)
* Object browse bar IN PROGRESS

* Object browse bar VERY WIP

* Object browse bar WIP

- view-control renamed to disclosure-triangle;
- Good progress on object browse bar elements;

* Object browse bar WIP

- Layout of start-side elements now working with ellipsis;
- TODO: cleanups and consolidation;

* Object browse bar shippable

- Better layout approach;
- Refinements to button classes;

* Sanding and shimming on misc styles

- Tree icon shrinkage fixed;
- c-icon-button much better relative sizing;
- Removed c-button-set wrapper from Layout.vue;
- Added uppercasing of Create button for Snow theme;

* working object name, css class

* working dynamic name, css classes and view switcher
2018-09-13 15:14:28 -07:00

161 lines
4.7 KiB
Vue

<template>
<div></div>
</template>
<style lang="scss">
</style>
<script>
// Find an object in an array of objects.
function findObject(domainObjects, id) {
var i;
for (i = 0; i < domainObjects.length; i += 1) {
if (domainObjects[i].getId() === id) {
return domainObjects[i];
}
}
}
// recursively locate and return an object inside of a container
// via a path. If at any point in the recursion it fails to find
// the next object, it will return the parent.
function findViaComposition(containerObject, path) {
var nextId = path.shift();
if (!nextId) {
return containerObject;
}
return containerObject.useCapability('composition')
.then(function (composees) {
var nextObject = findObject(composees, nextId);
if (!nextObject) {
return containerObject;
}
if (!nextObject.hasCapability('composition')) {
return nextObject;
}
return findViaComposition(nextObject, path);
});
}
function getLastChildIfRoot(object) {
if (object.getId() !== 'ROOT') {
return object;
}
return object.useCapability('composition')
.then(function (composees) {
return composees[composees.length - 1];
});
}
function pathForObject(domainObject) {
var context = domainObject.getCapability('context'),
objectPath = context ? context.getPath() : [],
ids = objectPath.map(function (domainObj) {
return domainObj.getId();
});
return "/browse/" + ids.slice(1).join("/");
}
export default {
inject: ["openmct"],
mounted() {
let openmct = this.openmct;
let $injector = openmct.$injector;
let angular = openmct.$angular;
this.objectService = $injector.get('objectService');
this.templateLinker = $injector.get('templateLinker');
this.navigationService = $injector.get('navigationService');
this.$timeout = $injector.get('$timeout');
this.templateMap = {};
$injector.get('templates[]').forEach((t) => {
this.templateMap[t.key] = this.templateMap[t.key] || t;
});
this.$rootScope = $injector.get('$rootScope');
this.$scope = this.$rootScope.$new();
this.$scope.representation = {};
openmct.router.route(/^\/browse\/(.*)$/, (path, results) => {
let navigatePath = results[1];
if (!navigatePath) {
navigatePath = 'mine';
}
this.navigateToPath(navigatePath);
});
this.navigationService.addListener(o => this.navigateToObject(o));
},
destroyed() {
},
methods: {
navigateToPath(path) {
if (!Array.isArray(path)) {
path = path.split('/');
}
return this.getObject('ROOT')
.then(root => {
return findViaComposition(root, path);
})
.then(getLastChildIfRoot)
.then(object => {
this.setMainViewObject(object);
});
},
setMainViewObject(object) {
this.$scope.domainObject = object;
this.$scope.navigatedObject = object;
this.templateLinker.link(
this.$scope,
this.openmct.$angular.element(this.$el),
this.templateMap["browseObject"]
);
document.title = object.getModel().name;
this.$root.$emit('main-view-domain-object', object);
this.scheduleDigest();
},
idsForObject(domainObject) {
return this.urlService
.urlForLocation("", domainObject)
.replace('/', '');
},
navigateToObject(object) {
let path = pathForObject(object);
let views = object.useCapability('view');
let params = this.openmct.router.getParams();
let currentViewIsValid = views.some(v => v.key === params['view']);
if (!currentViewIsValid) {
this.scope.representation = {
selected: views[0]
}
this.openmct.router.update(path, {
view: views[0].key
});
} else {
this.openmct.router.setPath(path);
}
},
scheduleDigest() {
this.$timeout(function () {
// digest done!
});
},
getObject(id) {
return this.objectService.getObjects([id])
.then(function (results) {
return results[id];
});
}
}
}
</script>