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

show json in attributes #1422

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 25 additions & 3 deletions source/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,34 @@ host.BrowserHost = class {
return await this._openContext(context);
}

async _readFileAsText(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = () => reject(reader.error);
reader.readAsText(file);
});
}

async _open(file, files) {
this._view.show('welcome spinner');
const context = new host.BrowserHost.BrowserFileContext(this, file, files);
try {
await context.open();
await this._openContext(context);

let ext_datas = null;
const jsonFileName = file.name + '.json';
const jsonFile = files.find((file) => file.name === jsonFileName);
if (jsonFile) {
try {
const fileContent = await this._readFileAsText(jsonFile);
ext_datas = JSON.parse(fileContent);
} catch (error) {
console.error('Error parsing JSON:', error);
}
}

await this._openContext(context, ext_datas);
} catch (error) {
await this._view.error(error);
}
Expand Down Expand Up @@ -483,10 +505,10 @@ host.BrowserHost = class {
}
}

async _openContext(context) {
async _openContext(context, ext_datas = null) {
this._telemetry.set('session_engaged', 1);
try {
const model = await this._view.open(context);
const model = await this._view.open(context, ext_datas);
if (model) {
this.document.title = context.name || context.identifier;
return '';
Expand Down
15 changes: 14 additions & 1 deletion source/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,24 @@ view.View = class {
return this._modelFactoryService.accept(file, size);
}

async open(context) {
async open(context, ext_datas = null) {
this._sidebar.close();
await this._timeout(2);
try {
const model = await this._modelFactoryService.open(context);
if (ext_datas) {
for (const graph of model.graphs) {
for (const node of graph.nodes) {
const ext_data = ext_datas[node.name];
if (ext_data) {
for (const key in ext_data) {
const attribute = {name: '- ' + key, value: ext_data[key], type: 'float64', description: null, visible: true};
node.attributes.push(attribute);
}
}
}
}
}
const format = [];
if (model.format) {
format.push(model.format);
Expand Down