Skip to content
Merged
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
10 changes: 5 additions & 5 deletions javascript/solution/client-details/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import IOBrowser from '@interopio/browser';
import IOWorkspaces from '@interopio/workspaces-api';
import IOBrowser from "@interopio/browser";
import IOWorkspaces from "@interopio/workspaces-api";

const setFields = (client) => {
const elementName = document.querySelectorAll("[data-name]")[0];
Expand Down Expand Up @@ -42,9 +42,9 @@ const start = async () => {
if (context.client) {
setFields(context.client);
myWorkspace.setTitle(context.client.name);
};
}
});
};
}
};

start().catch(console.error);
start().catch(console.error);
2 changes: 1 addition & 1 deletion javascript/solution/clients/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ <h1 class="text-center">Clients</h1>
</div>
</body>

</html>
</html>
33 changes: 19 additions & 14 deletions javascript/solution/clients/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import IOBrowserPlatform from '@interopio/browser-platform';
import IOWorkspaces from '@interopio/workspaces-api';
import { setupApplications } from './plugins/applicationsPlugin.js';
import { setupLayouts } from './plugins/layoutsPlugin.js';
import IOBrowserPlatform from "@interopio/browser-platform";
import IOWorkspaces from "@interopio/workspaces-api";
import { setupApplications } from "./plugins/applicationsPlugin.js";
import { setupLayouts } from "./plugins/layoutsPlugin.js";

const setupClients = (clients) => {
const table = document.getElementById("clientsTable").getElementsByTagName("tbody")[0];
const table = document
.getElementById("clientsTable")
.getElementsByTagName("tbody")[0];

const addRowCell = (row, cellData, cssClass) => {
const cell = document.createElement("td");
Expand All @@ -13,7 +15,7 @@ const setupClients = (clients) => {

if (cssClass) {
cell.className = cssClass;
};
}

row.appendChild(cell);
};
Expand Down Expand Up @@ -66,12 +68,15 @@ const clientClickedHandler = async (client) => {
};

try {
const workspace = await io.workspaces.restoreWorkspace("Client Space", restoreConfig);
const workspace = await io.workspaces.restoreWorkspace(
"Client Space",
restoreConfig
);

await raiseNotificationOnWorkspaceOpen(client.name, workspace);
} catch(error) {
} catch (error) {
console.error(error.message);
};
}
};

// let counter = 1;
Expand All @@ -96,7 +101,7 @@ const clientClickedHandler = async (client) => {
const raiseNotificationOnWorkspaceOpen = async (clientName, workspace) => {
const options = {
title: "New Workspace",
body: `A new Workspace for ${clientName} was opened!`,
body: `A new Workspace for ${clientName} was opened!`
};

const notification = await io.notifications.raise(options);
Expand All @@ -110,7 +115,7 @@ const raiseNotificationOnWorkspaceOpen = async (clientName, workspace) => {
const start = async () => {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/service-worker.js");
};
}

const clientsResponse = await fetch("http://localhost:8080/api/clients");
const clients = await clientsResponse.json();
Expand Down Expand Up @@ -229,13 +234,13 @@ const start = async () => {
definitions: [
{
name: "Setup Applications",
config: { url: "http://localhost:8080/api/applications"},
config: { url: "http://localhost:8080/api/applications" },
start: setupApplications,
critical: true
},
{
name: "Setup Workspace Layouts",
config: { url: "http://localhost:8080/api/layouts"},
config: { url: "http://localhost:8080/api/layouts" },
start: setupLayouts,
critical: true
}
Expand Down Expand Up @@ -281,4 +286,4 @@ const start = async () => {
// );
};

start().catch(console.error);
start().catch(console.error);
6 changes: 3 additions & 3 deletions javascript/solution/clients/plugins/applicationsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const setupApplications = async (io, { url }) => {
const appDefinitions = await fetchAppDefinitions(url);

await io.appManager.inMemory.import(appDefinitions);
} catch(error) {
} catch (error) {
console.error(error.message);
};
};
}
};
4 changes: 2 additions & 2 deletions javascript/solution/clients/plugins/layoutsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export const setupLayouts = async (io, { url }) => {
await io.layouts.import(layoutDefinitions);
} catch (error) {
console.error(error.message);
};
};
}
};
20 changes: 12 additions & 8 deletions javascript/solution/portfolio-downloader/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import IOBrowser from '@interopio/browser';
import IOBrowser from "@interopio/browser";

const intentHandler = (context) => {
if (!context) {
return;
};
}

setupTitle(context.data.clientName);

const dataToWrite = JSON.stringify({
date: new Date(Date.now()).toLocaleString("en-US"),
portfolio: context.data.portfolio
}, null, 4);
const dataToWrite = JSON.stringify(
{
date: new Date(Date.now()).toLocaleString("en-US"),
portfolio: context.data.portfolio
},
null,
4
);
const blob = new Blob([dataToWrite], { type: "application/json" });
const download = document.getElementById("download");
const href = URL.createObjectURL(blob);
Expand Down Expand Up @@ -40,6 +44,6 @@ async function start() {
toggleIOAvailable();

io.intents.register("ExportPortfolio", intentHandler);
};
}

start().catch(console.error);
start().catch(console.error);
17 changes: 10 additions & 7 deletions javascript/solution/stocks/details/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IOBrowser from '@interopio/browser';
import IOBrowser from "@interopio/browser";

const setFields = (stock) => {
const elementTitle = document.querySelector(".text-center");
Expand All @@ -13,7 +13,8 @@ const setFields = (stock) => {
const elementBloomberg = document.querySelectorAll("[data-bloomberg]")[0];
elementBloomberg.innerText = stock.Bloomberg;

const elementDescription = document.querySelectorAll("[data-description]")[0];
const elementDescription =
document.querySelectorAll("[data-description]")[0];
elementDescription.innerText = stock.Description;

const elementExchange = document.querySelectorAll("[data-exchange]")[0];
Expand Down Expand Up @@ -65,25 +66,27 @@ const start = async () => {
selectedStock = context.stock;

setFields(selectedStock);
};
}

myWindow.onContextUpdated((context) => {
if (context.stock) {
selectedStock = context.stock;

setFields(selectedStock);
};
}
});

const subscription = await io.interop.subscribe("LivePrices");

const streamDataHandler = (streamData) => {
if (!selectedStock) {
return;
};
}

const updatedStocks = streamData.data.stocks;
const selectedStockPrice = updatedStocks.find(updatedStock => updatedStock.RIC === selectedStock.RIC);
const selectedStockPrice = updatedStocks.find(
(updatedStock) => updatedStock.RIC === selectedStock.RIC
);

updateStockPrices(selectedStockPrice.Bid, selectedStockPrice.Ask);
};
Expand All @@ -97,4 +100,4 @@ const start = async () => {
// io.contexts.subscribe("SelectedClient", updateHandler);
};

start().catch(console.error);
start().catch(console.error);
45 changes: 27 additions & 18 deletions javascript/solution/stocks/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import IOBrowser from '@interopio/browser';
import IOWorkspaces from '@interopio/workspaces-api';
import IOBrowser from "@interopio/browser";
import IOWorkspaces from "@interopio/workspaces-api";

let clientPortfolioStocks;
let clientName;
Expand Down Expand Up @@ -76,7 +76,9 @@ const generateStockPrices = (handleNewPrices) => {
};

const setupStocks = (stocks) => {
const table = document.getElementById("stocksTable").getElementsByTagName("tbody")[0];
const table = document
.getElementById("stocksTable")
.getElementsByTagName("tbody")[0];

table.innerHTML = "";

Expand All @@ -87,7 +89,7 @@ const setupStocks = (stocks) => {

if (cssClass) {
cell.className = cssClass;
};
}

row.appendChild(cell);
};
Expand Down Expand Up @@ -128,7 +130,7 @@ const newPricesHandler = (priceUpdate) => {

if (!row) {
return;
};
}

const bidElement = row.children[2];
bidElement.innerText = stock.Bid;
Expand All @@ -139,7 +141,7 @@ const newPricesHandler = (priceUpdate) => {

if (priceStream) {
priceStream.push(priceUpdate);
};
}
};

const stockClickedHandler = async (stock) => {
Expand Down Expand Up @@ -172,21 +174,27 @@ const stockClickedHandler = async (stock) => {
let detailsWindow;

const myWorkspace = await io.workspaces.getMyWorkspace();
let detailsWorkspaceWindow = myWorkspace.getWindow(window => window.appName === "Stock Details");
let detailsWorkspaceWindow = myWorkspace.getWindow(
(window) => window.appName === "Stock Details"
);

if (detailsWorkspaceWindow) {
detailsWindow = detailsWorkspaceWindow.getGdWindow();
} else {
const myId = io.windows.my().id;
const myImmediateParent = myWorkspace.getWindow(window => window.id === myId).parent;
const myImmediateParent = myWorkspace.getWindow(
(window) => window.id === myId
).parent;
const group = await myImmediateParent.parent.addGroup();

detailsWorkspaceWindow = await group.addWindow({ appName: "Stock Details" });
detailsWorkspaceWindow = await group.addWindow({
appName: "Stock Details"
});

await detailsWorkspaceWindow.forceLoad();

detailsWindow = detailsWorkspaceWindow.getGdWindow();
};
}

detailsWindow.updateContext({ stock });
};
Expand All @@ -197,7 +205,7 @@ const exportPortfolioButtonHandler = async (portfolio) => {

if (!intents) {
return;
};
}

const intentRequest = {
intent: "ExportPortfolio",
Expand All @@ -213,11 +221,10 @@ const exportPortfolioButtonHandler = async (portfolio) => {
}
};


const start = async () => {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/service-worker.js");
};
}

const stocksResponse = await fetch("http://localhost:8080/api/portfolio");
const stocks = await stocksResponse.json();
Expand Down Expand Up @@ -306,23 +313,25 @@ const start = async () => {
myWorkspace.onContextUpdated((context) => {
if (context.client) {
const clientPortfolio = context.client.portfolio;
clientPortfolioStocks = stocks.filter((stock) => clientPortfolio.includes(stock.RIC));
clientPortfolioStocks = stocks.filter((stock) =>
clientPortfolio.includes(stock.RIC)
);
clientName = context.client.name;

setupStocks(clientPortfolioStocks);
};
}
});
};
}

const exportPortfolioButton = document.getElementById("exportPortfolio");

exportPortfolioButton.onclick = () => {
if (!clientPortfolioStocks) {
return;
};
}

exportPortfolioButtonHandler(clientPortfolioStocks);
};
};

start().catch(console.error);
start().catch(console.error);
8 changes: 4 additions & 4 deletions javascript/start/client-details/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// TODO: Chapter 2
// import IOBrowser from '@interopio/browser';
// import IOBrowser from "@interopio/browser";

// TODO: Chapter 9.3
// import IOWorkspaces from '@interopio/workspaces-api';
// import IOWorkspaces from "@interopio/workspaces-api";

const setFields = (client) => {
const elementName = document.querySelectorAll("[data-name]")[0];
Expand Down Expand Up @@ -31,8 +32,7 @@ const setFields = (client) => {

const start = async () => {
// TODO: Chapter 2

// TODO: Chapter 9.5
};

start().catch(console.error);
start().catch(console.error);
2 changes: 1 addition & 1 deletion javascript/start/clients/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ <h1 class="text-center">Clients</h1>
</div>
</body>

</html>
</html>
Loading