Skip to content

Commit

Permalink
Add deploy button
Browse files Browse the repository at this point in the history
  • Loading branch information
durch committed Apr 24, 2024
1 parent d11792b commit 5e0e427
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
16 changes: 15 additions & 1 deletion src/flow_view.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ItemView, WorkspaceLeaf, setIcon } from "obsidian";
import { ItemView, Notice, WorkspaceLeaf, setIcon } from "obsidian";
import CloudAtlasPlugin from "./main";

export const CA_VIEW_TYPE = "flow-view";
Expand Down Expand Up @@ -64,6 +64,20 @@ export class FlowView extends ItemView {
// console.debug(`Uploading flow ${flow}`);
await this.plugin.uploadFlow(flow);
});
const deployBtn = td2.createEl("button", { text: "Deploy" });
setIcon(deployBtn, "cloud-cog");
deployBtn.addClass("cloud-atlas-flow-btn-primary");
deployBtn.addEventListener("click", async () => {
// console.debug(`Uploading flow ${flow}`);
setIcon(deployBtn, "cog");
deployBtn.addClass("rotate");
const project_url = await this.plugin.deployFlow(flow);
deployBtn.removeClass("rotate");
setIcon(deployBtn, "cloud-cog");
new Notice(
`Flow has been deployed to ${project_url}, it should be available in a few minutes`
);
});
const flowNameTd = tr.createEl("td");
flowNameTd.addClass("cloud-atlas-flow-td-half");
flowNameTd.createEl("span", { text: flow });
Expand Down
40 changes: 36 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,32 @@ export default class CloudAtlasPlugin extends Plugin {
return respJson;
};

deployFlow = async (flow: string): Promise<string> => {
await this.uploadFlow(flow);
const apiUrl = this.apiUrl();
const response = await fetch(`${apiUrl}/deploy`, {
headers: {
"x-api-key": this.settings.apiKey,
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify({ flow }),
});

const project_url = await response.text();

await this.createFolder("CloudAtlas/deploy-info");

await this.app.vault.create(
`CloudAtlas/deploy-info/${flow}.flowdeploy.md`,
JSON.stringify({
project_url,
})
);

return project_url;
};

uploadFlow = async (flow: string) => {
const templateFlowFilePath = this.getFlowFilePath(flow);
const dataFlowFilePath = this.getFlowdataFilePath(flow);
Expand Down Expand Up @@ -616,13 +642,17 @@ export default class CloudAtlasPlugin extends Plugin {
return "";
};

apiUrl = () => {
const url = this.settings.previewMode
? "https://dev-api.cloud-atlas.ai"
: "https://api.cloud-atlas.ai";
return this.settings.developmentMode ? "http://localhost:8787" : url;
};

caApiFetch = async (payload: Payload): Promise<string> => {
payload.version = "V2";
console.debug(payload);
let url = this.settings.previewMode
? "https://dev-api.cloud-atlas.ai/run"
: "https://api.cloud-atlas.ai/run";
url = this.settings.developmentMode ? "http://localhost:8787/run" : url;
const url = `${this.apiUrl()}/run`;
const response = await fetch(url, {
headers: {
"x-api-key": this.settings.apiKey,
Expand Down Expand Up @@ -911,6 +941,8 @@ export default class CloudAtlasPlugin extends Plugin {
view.dom.classList.add("cloud-atlas-flowdata-file");
} else if (filePath.endsWith(".flowrun.md")) {
view.dom.classList.add("cloud-atlas-flowrun-file");
} else if (filePath.endsWith(".flowdeploy.md")) {
view.dom.classList.add("cloud-atlas-flowdeploy-file");
} else {
view.dom.classList.remove(
"cloud-atlas-flow-file",
Expand Down
30 changes: 29 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,31 @@ table.cloud-atlas-flow-table td.cloud-atlas-flow-td-quarter {
}

.cloud-atlas-flowdata-file::before {
content: "CloudAtlas flow Data";
content: "CloudAtlas flow data";
display: block;
font-size: var(--font-larger);
color: var(--foreground-secondary-alt);
background-color: var(--background-secondary-alt);
padding: var(--size-4-3);
border-top: 2px solid var(--text-accent-hover);
border-bottom: 2px solid var(--text-accent-hover);
margin-bottom: var(--size-4-3);
}

.cloud-atlas-flowrun-file::before {
content: "CloudAtlas flow run";
display: block;
font-size: var(--font-larger);
color: var(--foreground-secondary-alt);
background-color: var(--background-secondary-alt);
padding: var(--size-4-3);
border-top: 2px solid var(--text-accent-hover);
border-bottom: 2px solid var(--text-accent-hover);
margin-bottom: var(--size-4-3);
}

.cloud-atlas-flowdeploy-file::before {
content: "CloudAtlas flow deploy";
display: block;
font-size: var(--font-larger);
color: var(--foreground-secondary-alt);
Expand Down Expand Up @@ -128,6 +152,10 @@ table.cloud-atlas-flow-table td.cloud-atlas-flow-td-quarter {
font-size: 1.2em;
}

.rotate {
animation: rotation 2s infinite linear;
}

.cloud-atlas-flow-canvas
.mod-canvas-color-1:not(.is-editing)
.canvas-node-container::before,
Expand Down

0 comments on commit 5e0e427

Please sign in to comment.