Skip to content

Commit

Permalink
feat: now check for deployment status (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
pichoemr authored Feb 14, 2023
1 parent 6da95df commit 85b7141
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 49 deletions.
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"chrome",
"--web-port",
"10000",
"--dart-define=LENRA_SERVER_URL=http://localhost:4000"
"--dart-define=LENRA_SERVER_URL=http://localhost:4000",
"--dart-define=SENTRY_CLIENT_DSN=test",
]
},
{
Expand All @@ -29,6 +30,7 @@
"10000",
"--dart-define=LENRA_SERVER_URL=${env:LENRA_SERVER_URL}",
"--dart-define=LENRA_BASIC_AUTH=${env:LENRA_BASIC_AUTH}",
"--dart-define=SENTRY_CLIENT_DSN=test",
]
},
{
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:client_common/config/config.dart';
import 'package:client_common/models/auth_model.dart';
import 'package:client_common/models/build_model.dart';
import 'package:client_common/models/cgu_model.dart';
import 'package:client_common/models/deployment_model.dart';
import 'package:client_common/models/store_model.dart';
import 'package:client_common/models/user_application_model.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -43,6 +44,7 @@ class Backoffice extends StatelessWidget {
providers: [
ChangeNotifierProvider<AuthModel>(create: (context) => AuthModel()),
ChangeNotifierProvider<BuildModel>(create: (context) => BuildModel()),
ChangeNotifierProvider<DeploymentModel>(create: (context) => DeploymentModel()),
ChangeNotifierProvider<UserApplicationModel>(create: (context) => UserApplicationModel()),
ChangeNotifierProvider<StoreModel>(create: (context) => StoreModel()),
ChangeNotifierProvider<CguModel>(create: (context) => CguModel()),
Expand Down
85 changes: 59 additions & 26 deletions lib/views/overview_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import 'package:client_backoffice/navigation/backoffice_navigator.dart';
import 'package:client_backoffice/views/backoffice_page.dart';
import 'package:client_common/api/response_models/app_response.dart';
import 'package:client_common/api/response_models/build_response.dart';
import 'package:client_common/api/response_models/deployment_response.dart';
import 'package:client_common/config/config.dart';
import 'package:client_common/models/build_model.dart';
import 'package:client_common/models/deployment_model.dart';
import 'package:client_common/models/user_application_model.dart';
import 'package:client_common/navigator/common_navigator.dart';
import 'package:flutter/material.dart';
Expand All @@ -29,6 +31,8 @@ class _OverviewPageState extends State<OverviewPage> {
@override
void initState() {
var buildModel = context.read<BuildModel>();
var deploymentModel = context.read<DeploymentModel>();

UserApplicationModel userApplicationModel = context.read<UserApplicationModel>();

WidgetsBinding.instance.addPostFrameCallback((_) {
Expand All @@ -41,6 +45,7 @@ class _OverviewPageState extends State<OverviewPage> {
CommonNavigator.go(context, BackofficeNavigator.selectProject);
} else {
buildModel.fetchBuilds(widget.appId);
deploymentModel.fetchDeployments(widget.appId);
}
},
);
Expand All @@ -57,49 +62,61 @@ class _OverviewPageState extends State<OverviewPage> {
@override
Widget build(BuildContext context) {
var buildModel = context.read<BuildModel>();
var deploymentModel = context.read<DeploymentModel>();

// A bit dirty
if (app == null) return Center(child: CircularProgressIndicator());

List<BuildResponse> builds =
context.select<BuildModel, List<BuildResponse>>((buildModel) => buildModel.buildsForApp(app!.id));
List<DeploymentResponse> deployments = context.select<DeploymentModel, List<DeploymentResponse>>(
(deploymentModel) => deploymentModel.deploymentsForApp(app!.id));
print(deployments);

var hasPendingBuild = false;
var hasPublishedBuild = false;
var hasPendingDeployment = false;
var hasPublishedDeployment = false;

if (builds.isNotEmpty) {
builds.sort((a, b) => a.buildNumber.compareTo(b.buildNumber));

// Check if there is a createBuildStatus that is currently fetching.
var createBuildStatusFetching = buildModel.createBuildStatus[app!.id]?.isFetching() ?? false;

hasPendingBuild = builds.any((build) => build.status == BuildStatus.pending) || createBuildStatusFetching;
hasPendingDeployment = deployments.any((deployment) =>
deployment.status == DeploymentStatus.waitingForBuild ||
deployment.status == DeploymentStatus.waitingForAppReady ||
deployment.status == DeploymentStatus.created) ||
createBuildStatusFetching;

if (hasPendingBuild) {
if (hasPendingDeployment) {
timer = Timer(Duration(seconds: 5), () {
buildModel.fetchBuilds(widget.appId).then((_) {
setState(() {});
deploymentModel.fetchDeployments(widget.appId).then((_) {
buildModel.fetchBuilds(widget.appId).then((_) {
setState(() {});
});
});
});
}

hasPublishedBuild = builds.any((build) => build.status == BuildStatus.success);
hasPublishedDeployment = deployments.any((deployment) => deployment.status == DeploymentStatus.success);
}

return BackofficePage(
key: ValueKey("overview"),
title: "Overview",
actionWidget: LenraButton(
text: "Publish my application",
disabled: hasPendingBuild,
disabled: hasPendingDeployment,
onPressed: () => buildModel.createBuild(app!.id).then((_) {
setState(() {});
}),
),
child: buildPage(context, hasPublishedBuild, builds),
child: buildPage(context, hasPublishedDeployment, deployments, builds),
);
}

Widget buildPage(BuildContext context, bool hasPublishedBuild, List<BuildResponse> builds) {
Widget buildPage(
BuildContext context, bool hasPublishedBuild, List<DeploymentResponse> deployments, List<BuildResponse> builds) {
var theme = LenraTheme.of(context);

return LenraFlex(
Expand Down Expand Up @@ -137,12 +154,16 @@ class _OverviewPageState extends State<OverviewPage> {
child: Text("Build status"),
),
]),
if (builds.isNotEmpty) buildRow(context, builds.last),
if (builds.length >= 2 && builds.last.status == BuildStatus.pending)
buildRow(context, builds.reversed.elementAt(1)),
if (deployments.isNotEmpty)
buildRow(
context, deployments.last, builds.firstWhere((element) => element.id == deployments.last.buildId)),
if (deployments.length >= 2 &&
deployments.last.status == DeploymentStatus.waitingForBuild &&
deployments.last.status == DeploymentStatus.waitingForAppReady)
buildRow(context, deployments.reversed.elementAt(1), builds.reversed.elementAt(1)),
],
),
if (builds.isEmpty)
if (deployments.isEmpty)
Text(
"Your application has not been built yet.\nClick “Publish my application” to create your first build.",
style: theme.lenraTextThemeData.disabledBodyText,
Expand All @@ -152,46 +173,58 @@ class _OverviewPageState extends State<OverviewPage> {
);
}

Color colorFromStatus(BuildStatus status) {
Color colorFromStatus(DeploymentStatus status) {
switch (status) {
case BuildStatus.success:
case DeploymentStatus.success:
return LenraColorThemeData.lenraFunGreenPulse;

case BuildStatus.pending:
case DeploymentStatus.waitingForBuild:
return LenraColorThemeData.lenraFunYellowPulse;

case DeploymentStatus.waitingForAppReady:
return LenraColorThemeData.lenraFunYellowPulse;

case BuildStatus.failure:
case DeploymentStatus.created:
return LenraColorThemeData.lenraGreyText;

case DeploymentStatus.failure:
return LenraColorThemeData.lenraFunRedPulse;

default:
return LenraColorThemeData.lenraFunRedPulse;
}
}

String textFromStatus(BuildStatus status) {
String textFromStatus(DeploymentStatus status) {
switch (status) {
case BuildStatus.success:
case DeploymentStatus.success:
return "Published";

case BuildStatus.pending:
case DeploymentStatus.waitingForBuild:
return "Building...";

case DeploymentStatus.waitingForAppReady:
return "Building...";

case BuildStatus.failure:
case DeploymentStatus.created:
return "Created";

case DeploymentStatus.failure:
return "Failure";

default:
return "Failure";
}
}

TableRow buildRow(BuildContext context, BuildResponse buildResponse) {
TableRow buildRow(BuildContext context, DeploymentResponse deploymentResponse, BuildResponse buildResponse) {
var theme = LenraTheme.of(context);
return TableRow(children: [
LenraTableCell(
child: Text("#${buildResponse.buildNumber}"),
),
LenraTableCell(
child: Text(DateFormat.yMMMMd().add_jm().format(buildResponse.insertedAt)),
child: Text(DateFormat.yMMMMd().add_jm().format(deploymentResponse.insertedAt)),
),
LenraTableCell(
child: LenraFlex(
Expand All @@ -200,10 +233,10 @@ class _OverviewPageState extends State<OverviewPage> {
children: [
Icon(
Icons.circle,
color: colorFromStatus(buildResponse.status),
color: colorFromStatus(deploymentResponse.status),
size: theme.baseSize,
),
Text(textFromStatus(buildResponse.status)),
Text(textFromStatus(deploymentResponse.status)),
],
),
),
Expand Down
40 changes: 20 additions & 20 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: "0c80aeab9bc807ab10022cd3b2f4cf2ecdf231949dc1ddd9442406a003f19201"
sha256: "4897882604d919befd350648c7f91926a9d5de99e67b455bf0917cc2362f4bb8"
url: "https://pub.dev"
source: hosted
version: "52.0.0"
version: "47.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: cd8ee83568a77f3ae6b913a36093a1c9b1264e7cb7f834d9ddd2311dade9c1f4
sha256: "690e335554a8385bc9d787117d9eb52c0c03ee207a607e593de3c9d71b1cfe80"
url: "https://pub.dev"
source: hosted
version: "5.4.0"
version: "4.7.0"
archive:
dependency: transitive
description:
Expand Down Expand Up @@ -85,8 +85,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "v1.0.0-beta.36"
resolved-ref: "4a0e53dd0ebca57361f8febd4d4444afc5eda39a"
ref: "v1.0.0-beta.39"
resolved-ref: d85d91d5c647739a6f7ac9a2b499624ae16647fd
url: "git@github.com:lenra-io/client-common.git"
source: git
version: "1.0.0"
Expand Down Expand Up @@ -118,10 +118,10 @@ packages:
dependency: transitive
description:
name: coverage
sha256: "961c4aebd27917269b1896382c7cb1b1ba81629ba669ba09c27a7e5710ec9040"
sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097"
url: "https://pub.dev"
source: hosted
version: "1.6.2"
version: "1.6.3"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -245,10 +245,10 @@ packages:
dependency: transitive
description:
name: frontend_server_client
sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612"
sha256: "4f4a162323c86ffc1245765cfe138872b8f069deb42f7dbb36115fa27f31469b"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "2.1.3"
glob:
dependency: transitive
description:
Expand All @@ -261,10 +261,10 @@ packages:
dependency: "direct main"
description:
name: go_router
sha256: "9e8cee9969a9f33821a5594e5822d9a7ef3ae8528e5258f5178436e3deb0e095"
sha256: "54ecc1cd90c6948539c8cae3c11d7cb5010ad9b14533e8f49d060839d742be12"
url: "https://pub.dev"
source: hosted
version: "6.0.3"
version: "6.0.4"
html:
dependency: transitive
description:
Expand Down Expand Up @@ -341,8 +341,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "v1.0.0-beta.51"
resolved-ref: "7fc9ada718094808ebcd14863956d593b3ff8471"
ref: "v1.0.0-beta.52"
resolved-ref: "26cc6d810bea235f59d0890f99691d065de74c98"
url: "git@github.com:lenra-io/lenra_components.git"
source: git
version: "0.0.0"
Expand Down Expand Up @@ -667,10 +667,10 @@ packages:
dependency: "direct main"
description:
name: url_launcher
sha256: "698fa0b4392effdc73e9e184403b627362eb5fbf904483ac9defbb1c2191d809"
sha256: e8f2efc804810c0f2f5b485f49e7942179f56eabcfe81dce3387fec4bb55876b
url: "https://pub.dev"
source: hosted
version: "6.1.8"
version: "6.1.9"
url_launcher_android:
dependency: transitive
description:
Expand All @@ -683,10 +683,10 @@ packages:
dependency: transitive
description:
name: url_launcher_ios
sha256: bb328b24d3bccc20bdf1024a0990ac4f869d57663660de9c936fb8c043edefe3
sha256: "0a5af0aefdd8cf820dd739886efb1637f1f24489900204f50984634c07a54815"
url: "https://pub.dev"
source: hosted
version: "6.0.18"
version: "6.1.0"
url_launcher_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -787,10 +787,10 @@ packages:
dependency: transitive
description:
name: xml
sha256: "979ee37d622dec6365e2efa4d906c37470995871fe9ae080d967e192d88286b5"
sha256: ac0e3f4bf00ba2708c33fbabbbe766300e509f8c82dbd4ab6525039813f7e2fb
url: "https://pub.dev"
source: hosted
version: "6.2.2"
version: "6.1.0"
yaml:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ dependencies:
lenra_components:
git:
url: git@github.com:lenra-io/lenra_components.git
ref: v1.0.0-beta.51
ref: v1.0.0-beta.52
client_common:
git:
url: git@github.com:lenra-io/client-common.git
ref: v1.0.0-beta.36
ref: v1.0.0-beta.39
url_launcher: ^6.1.2
intl: ^0.18.0
logging: ^1.0.2
Expand Down

0 comments on commit 85b7141

Please sign in to comment.