Skip to content

Commit

Permalink
Merge pull request #4045 from cloudfoundry/app-loading-indicator
Browse files Browse the repository at this point in the history
Add an initial loading indicator with customization support
  • Loading branch information
richard-cox authored Dec 9, 2019
2 parents 58b2e7a + 3808a2d commit b2fcd6d
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 2 deletions.
20 changes: 20 additions & 0 deletions build/customize-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
const CUSTOM_METADATA = path.resolve(__dirname, '../custom-src/stratos.yaml');
const GIT_FOLDER = path.resolve(__dirname, '../.git');
const GIT_METADATA = path.resolve(__dirname, '../.stratos-git-metadata.json');
const INDEX_LOADING_HTML_CUSTOM = path.resolve(__dirname, '../custom-src/frontend/loading.html');
const INDEX_LOADING_HTML_DEFAULT = path.resolve(__dirname, '../src/frontend/packages/core/misc/custom/loading.html');
const INDEX_LOADING_CSS_CUSTOM = path.resolve(__dirname, '../custom-src/frontend/loading.css');
const INDEX_LOADING_CSS_DEFAULT = path.resolve(__dirname, '../src/frontend/packages/core/misc/custom/loading.css');

// Apply any customizations
// Symlink customizations of the default resources for Stratos
Expand Down Expand Up @@ -264,6 +268,22 @@

// Date and Time that the build was made (approximately => it is when this script is run)
replace.sync({ files: INDEX_HTML, from: '@@stratos_build_date@@', to: new Date() });

// Replace loading indicator - HTML
let loadingHtmlFile = INDEX_LOADING_HTML_DEFAULT;
if (fs.existsSync(INDEX_LOADING_HTML_CUSTOM)) {
loadingHtmlFile = INDEX_LOADING_HTML_CUSTOM
}
const loadingHtml = fs.readFileSync(loadingHtmlFile, 'utf8');
replace.sync({ files: INDEX_HTML, from: '<!-- @@LOADING_HTML@@ -->', to: loadingHtml });

// Replace loading indicator - CSS
let loadingCssFile = INDEX_LOADING_CSS_DEFAULT;
if (fs.existsSync(INDEX_LOADING_CSS_CUSTOM)) {
loadingCssFile = INDEX_LOADING_CSS_CUSTOM
}
const loadingCss = fs.readFileSync(loadingCssFile, 'utf8');
replace.sync({ files: INDEX_HTML, from: '/** @@LOADING_CSS@@ **/', to: loadingCss });
}

// We can only do this if we have a git repository checkout
Expand Down
24 changes: 23 additions & 1 deletion docs/customizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Stratos provides a mechanism for customization - the following customizations ar
- Changing certain image assets (favorite icon, login background and logo)
- Overriding styles
- Adding new functionality
- Changing the initial loading indicator

## Approach

Expand Down Expand Up @@ -121,4 +122,25 @@ We currently expose the following extension points in the Stratos UI:

We use Decorators to annotate components to indicate that they are Stratos extensions.

See [Extensions](extensions.md) for more detail and examples of front-end extensions.
See [Extensions](extensions.md) for more detail and examples of front-end extensions.


### Changing the Initial Loading Indicator

On slower connections, it can take a few seconds to load the main Javascript resources for Stratos.

In order to give the user some initial feedback that Stratos is loading, a loading indicator is included in the `index.html` file. This gets shown as early as possible, as soon as this main html file has loaded. Once the main code has been fetched, the view refreshes to show the application.

A default loading indicator is provided that can be changed. To do so, create the following two files:

- `custom-src/frontend/loading.css` - CSS styles to be included in a style block in the head of the index page
- `custom-src/frontend/loading.html` - HTML markup to be included the the index page to render the loading indicator

The files for the default indicator can be found in the `src/frontend/packages/core/misc/custom` folder.

An example of a different loading indicator is included with the ACME sample in `examples/custom-src/frontend`.

The customization task will insert the appropriate CSS and HTML files into the main index.html file when it runs.

Take a look at the template for the `index.html` file in `src/frontend/packages/core/misc/custom/index.html`. The CSS file is inserted where the marker `/** @@LOADING_CSS@@ **/` is and the HTML file where `<!-- @@LOADING_HTML@@ -->` is.

38 changes: 38 additions & 0 deletions examples/custom-src/frontend/loading.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.stratos-initial-load-spinner-container {
align-items: center;
background-color: #0D2C40;
display: flex;
justify-content: center;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}

.stratos-initial-load-spinner-logo {
position: absolute;
height: 60px;
}

.stratos-initial-load-spinner {
animation: stratos-initial-load-animate 1s infinite linear;
box-sizing: border-box;
border: 5px solid rgba(86, 107, 121, 0.45);
border-radius: 50%;
border-top-color: #00B2E2;
display: inline-block;
height: 128px;
margin: 0 auto;
width: 128px;
}

@keyframes stratos-initial-load-animate {
0% {
transform: rotate(0deg);
}

100% {
transform: rotate(359deg);
}
}
3 changes: 3 additions & 0 deletions examples/custom-src/frontend/loading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="stratos-initial-load-spinner-container">
<i class="stratos-initial-load-spinner"></i>
</div>
7 changes: 6 additions & 1 deletion src/frontend/packages/core/misc/custom/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@
</style>
</noscript>

<style>
/** @@LOADING_CSS@@ **/
</style>
</head>

<body class="stratos">
<app-root></app-root>
<app-root>
<!-- @@LOADING_HTML@@ -->
</app-root>
<noscript>
<div class="no-javascript">
<div class="message title">@@TITLE@@</div>
Expand Down
40 changes: 40 additions & 0 deletions src/frontend/packages/core/misc/custom/loading.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.stratos-initial-load-spinner-container {
align-items: center;
background-color: #005699;
display: flex;
justify-content: center;

height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}

.stratos-initial-load-spinner-logo {
position: absolute;
height: 60px;
}

.stratos-initial-load-spinner {
animation: stratos-initial-load-animate 1s infinite linear;
background-color: #fff;
box-sizing: border-box;
border: 5px solid rgba(16, 72, 156, 0.45);
border-radius: 50%;
border-top-color: #c2cdde;
display: inline-block;
height: 128px;
margin: 0 auto;
width: 128px;
}

@keyframes stratos-initial-load-animate {
0% {
transform: rotate(0deg);
}

100% {
transform: rotate(359deg);
}
}
4 changes: 4 additions & 0 deletions src/frontend/packages/core/misc/custom/loading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="stratos-initial-load-spinner-container">
<i class="stratos-initial-load-spinner"></i>
<img class="stratos-initial-load-spinner-logo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABkCAMAAAAMlLaLAAACiFBMVEUAA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