Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource model icon to all resources in multi-graph association nodes #1205

Open
wants to merge 7 commits into
base: dev/1.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions arches_her/media/js/utils/report.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
define([
'arches',
'knockout'
], function(arches, ko) {
'knockout',
'utils/resource',
], function(arches, ko, resourceUtil) {
const standardizeNode = (obj) => {
if(obj){
const keys = Object.keys(obj);
Expand Down Expand Up @@ -93,6 +94,46 @@ define([
}
};

const getGraphs = () => {
return $.ajax({
url: arches.urls.graphs_api,
context: this,
}).then(function(graphsResponse) {
graphs = ko.unwrap(graphsResponse);

const filteredGraphs = graphs.filter((x) => {
return x.isresource === true;
}) || [];

return filteredGraphs;
}).fail(function() {
// error
});

}

const getResourceGraph = (resourceId) => {
let graphData = {};

Object.defineProperty(graphData, "iconClass", {value: ko.observable()});
Object.defineProperty(graphData, "graphId", {value: ko.observable()});

return Promise.all([getGraphs(), resourceUtil.lookupResourceInstanceData(resourceId)]).then((values) => {
const graphs = values[0]
const resourceInstanceData = values[1]
if (graphs && resourceInstanceData) {
graphData.graphId(resourceInstanceData["_source"].graph_id);
for (data of graphs) {
if (data.graphid == resourceInstanceData["_source"].graph_id) {
graphData.iconClass(data.iconclass || 'fa fa-question');
break;
}};
return graphData
}
});
};


return {
// default table configuration - used for display
defaultTableConfig: {
Expand Down Expand Up @@ -220,6 +261,10 @@ define([

// see if there's any node with a valid displayable value. If yes, return true.
// potentially useful for deeply nested resources
nestedDataExists: checkNestedData
nestedDataExists: checkNestedData,

getGraphs: getGraphs,

getResourceGraph: getResourceGraph
}
});
12 changes: 11 additions & 1 deletion arches_her/media/js/views/components/reports/scenes/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,19 @@ function (_, ko, arches, reportUtils, ResourcesTemplate) {
var resource = [];
for (const element of x[key]['instance_details']) {
if (element) {

var cssIcon = ko.observable("fa fa-question");
self.getResourceGraph(element.resourceId).then((returnedGraphData) => {
if (returnedGraphData) {
cssIcon(returnedGraphData.iconClass());
}
});

resource.push({
resourceName: self.getNodeValue(element),
resourceUrl: self.getResourceLink(element)
resourceUrl: self.getResourceLink(element),
resourceId: element.resourceId,
cssIcon: cssIcon
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ <h2 class="aher-report-section-title">
<tr>
<td data-bind="foreach: resource">
<span data-bind="visible: $index() > 0">, </span>
<i class="fa arches-menu-icon" data-bind="css: cssIcon" ></i>
<!-- ko if: resourceUrl -->
<a data-bind="text: resourceName, attr: {href: resourceUrl}" class="aher-table-link"></a>
<!-- /ko -->
Expand Down