From 533875dcaae81f3dd85ceed877fd0e657cde5729 Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Thu, 27 Dec 2018 23:00:27 -0800 Subject: [PATCH] One Click Apps - DONE! --- .../apps/oneclick/OneClickAppConfigPage.tsx | 15 +-- .../apps/oneclick/OneClickAppDeployManager.ts | 54 ++++---- .../oneclick/OneClickAppDeployProgress.tsx | 126 ++++++++++++++---- 3 files changed, 127 insertions(+), 68 deletions(-) diff --git a/app-frontend/src/containers/apps/oneclick/OneClickAppConfigPage.tsx b/app-frontend/src/containers/apps/oneclick/OneClickAppConfigPage.tsx index 20ca016..090be42 100644 --- a/app-frontend/src/containers/apps/oneclick/OneClickAppConfigPage.tsx +++ b/app-frontend/src/containers/apps/oneclick/OneClickAppConfigPage.tsx @@ -10,7 +10,6 @@ import OneClickAppDeployManager, { IDeploymentState } from "./OneClickAppDeployManager"; import OneClickAppDeployProgress from "./OneClickAppDeployProgress"; -import Utils from "../../../utils/Utils"; import DomUtils from "../../../utils/DomUtils"; export const ONE_CLICK_APP_NAME_VAR_NAME = "$$cap_appname"; @@ -86,23 +85,24 @@ export default class OneClickAppConfigPage extends Component< render() { const self = this; + const deploymentState = this.state.deploymentState; + const apiData = this.state.apiData; - if (!this.state.apiData) { + if (!apiData) { return ; } - if (!!this.state.deploymentState) { + if (!!deploymentState) { return ( self.props.history.push("/apps")} onRestartClicked={() => self.setState({ deploymentState: undefined })} /> ); } - const apiData = this.state.apiData!; - return (
@@ -129,9 +129,6 @@ export default class OneClickAppConfigPage extends Component< DomUtils.scrollToTopBar(); }} /> -
-
-
{JSON.stringify(this.state.apiData, null, 2)}
> diff --git a/app-frontend/src/containers/apps/oneclick/OneClickAppDeployManager.ts b/app-frontend/src/containers/apps/oneclick/OneClickAppDeployManager.ts index 80a0c40..c5ece1a 100644 --- a/app-frontend/src/containers/apps/oneclick/OneClickAppDeployManager.ts +++ b/app-frontend/src/containers/apps/oneclick/OneClickAppDeployManager.ts @@ -1,17 +1,11 @@ -import ApiManager from "../../../api/ApiManager"; import { IHashMapGeneric } from "../../../models/IHashMapGeneric"; import { IOneClickTemplate, IDockerComposeService } from "./OneClickAppConfigPage"; import Utils from "../../../utils/Utils"; -import { IAppDef } from "../AppDefinition"; import OneClickAppDeploymentHelper from "./OneClickAppDeploymentHelper"; -const REGISTERING = "REGISTERING"; -const CONFIGURING = "CONFIGURING"; -const DEPLOYING = "DEPLOYING"; - interface IDeploymentStep { stepName: string; stepPromise: () => Promise; @@ -20,6 +14,7 @@ interface IDeploymentStep { export interface IDeploymentState { steps: string[]; error: string; + successMessage?: string; currentStep: number; } @@ -88,38 +83,37 @@ export default class OneClickAppDeployManager { ); } - let currentStep = 0; const stepsTexts: string[] = ["Parsing the template"]; for (let index = 0; index < steps.length; index++) { stepsTexts.push(steps[index].stepName); } - let promise = new Promise(function(resolve) { - self.onDeploymentStateChanged( - Utils.copyObject({ - steps: stepsTexts, - error: "", - currentStep: 0 - }) - ); - resolve(); - }); + let currentStep = 0; + const onNextStepPromiseCreator = function() { + return new Promise(function(resolve) { + currentStep++; + self.onDeploymentStateChanged( + Utils.copyObject({ + steps: stepsTexts, + error: "", + currentStep, + successMessage: + currentStep >= stepsTexts.length + ? self.template!.instructions.end + : undefined + }) + ); + resolve(); + }); + }; + + let promise = onNextStepPromiseCreator(); for (let index = 0; index < steps.length; index++) { const element = steps[index]; - promise = promise.then(element.stepPromise).then(function() { - return new Promise(function(resolve) { - currentStep++; - self.onDeploymentStateChanged( - Utils.copyObject({ - steps: stepsTexts, - error: "", - currentStep - }) - ); - resolve(); - }); - }); + promise = promise + .then(element.stepPromise) + .then(onNextStepPromiseCreator); } promise.catch(function(error) { diff --git a/app-frontend/src/containers/apps/oneclick/OneClickAppDeployProgress.tsx b/app-frontend/src/containers/apps/oneclick/OneClickAppDeployProgress.tsx index fb37797..8d40fca 100644 --- a/app-frontend/src/containers/apps/oneclick/OneClickAppDeployProgress.tsx +++ b/app-frontend/src/containers/apps/oneclick/OneClickAppDeployProgress.tsx @@ -1,6 +1,6 @@ import React, { Component } from "react"; import { IDeploymentState } from "./OneClickAppDeployManager"; -import { Row, Col, Card, Steps, Icon } from "antd"; +import { Row, Col, Card, Steps, Icon, Button, Alert } from "antd"; const Step = Steps.Step; @@ -8,12 +8,44 @@ export default class OneClickAppDeployProgress extends Component<{ appName: string; deploymentState: IDeploymentState; onRestartClicked: () => void; + onFinishClicked: () => void; }> { + createSteps() { + const steps = this.props.deploymentState.steps; + const stepsInfo = []; + + for (let index = 0; index < steps.length; index++) { + stepsInfo.push({ + text: ( + + + {index === this.props.deploymentState.currentStep && + !this.props.deploymentState.error ? ( + + ) : ( + + )} + + {steps[index]} + + ), + icon: undefined + }); + } + + return stepsInfo.map(s => { + return ; + }); + } + render() { + const self = this; + return (
-
{JSON.stringify(this.props.deploymentState, null, 2)}
-
@@ -25,33 +57,69 @@ export default class OneClickAppDeployProgress extends Component<{

Progress:

- - - } - title="Configuring App Name" - description="This is a description." - /> - - - - + + {self.createSteps()} + +
+
+ + {self.props.deploymentState.successMessage} +
+ } + /> +
+ + + +
+ +
+
+ +
+ + + + +