From ab1d72780e19c72b94ff5dbcf719480cdaff9f10 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 24 Nov 2017 15:13:27 +0100 Subject: [PATCH] MOBILE-2253 core: Implement core-loading --- src/components/components.module.ts | 30 +++++++++++++++++ src/components/loading/loading.html | 8 +++++ src/components/loading/loading.scss | 28 ++++++++++++++++ src/components/loading/loading.ts | 50 +++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 src/components/components.module.ts create mode 100644 src/components/loading/loading.html create mode 100644 src/components/loading/loading.scss create mode 100644 src/components/loading/loading.ts diff --git a/src/components/components.module.ts b/src/components/components.module.ts new file mode 100644 index 000000000..8407a35f7 --- /dev/null +++ b/src/components/components.module.ts @@ -0,0 +1,30 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { NgModule } from '@angular/core'; +import { IonicModule } from 'ionic-angular'; +import { CoreLoadingComponent } from './loading/loading'; + +@NgModule({ + declarations: [ + CoreLoadingComponent + ], + imports: [ + IonicModule + ], + exports: [ + CoreLoadingComponent + ] +}) +export class CoreComponentsModule {} diff --git a/src/components/loading/loading.html b/src/components/loading/loading.html new file mode 100644 index 000000000..e79daa1ff --- /dev/null +++ b/src/components/loading/loading.html @@ -0,0 +1,8 @@ +
+ + +

{{message}}

+
+
+ + \ No newline at end of file diff --git a/src/components/loading/loading.scss b/src/components/loading/loading.scss new file mode 100644 index 000000000..6279a3b37 --- /dev/null +++ b/src/components/loading/loading.scss @@ -0,0 +1,28 @@ +core-loading { + .mm-loading-container { + width: 100%; + text-align: center; + padding-top: 10px; + clear: both; + } + + .mm-loading-content { + padding-bottom: 1px; /* This makes height be real */ + } + + &.mm-loading-noheight .mm-loading-content { + height: auto; + } +} + +.scroll-content > .padding > core-loading > .mm-loading-container, +ion-content[padding] > .scroll-content > core-loading > .mm-loading-container, +.mm-loading-center .mm-loading-container { + display: table; + + .mm-loading-spinner { + display: table-cell; + text-align: center; + vertical-align: middle; + } +} diff --git a/src/components/loading/loading.ts b/src/components/loading/loading.ts new file mode 100644 index 000000000..19ce95d04 --- /dev/null +++ b/src/components/loading/loading.ts @@ -0,0 +1,50 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Component, Input, OnInit } from '@angular/core'; +import { TranslateService } from '@ngx-translate/core'; + +/** + * Component to show a loading spinner and message while data is being loaded. + * + * It will show a spinner with a message and hide all the content until 'dataLoaded' variable is set to true. + * If 'message' and 'dynMessage' attributes aren't set, default message "Loading" is shown. + * 'message' attribute accepts hardcoded strings, variables, filters, etc. E.g. message="'mm.core.loading' | translate". + * + * Usage: + * + * + * + */ +@Component({ + selector: 'core-loading', + templateUrl: 'loading.html' +}) +export class CoreLoadingComponent implements OnInit { + @Input() hideUntil: boolean; // Determine when should the contents be shown. + @Input() message?: string; // Message to show while loading. + + constructor(private translate: TranslateService) {} + + /** + * Component being initialized. + */ + ngOnInit() { + if (!this.message) { + // Default loading message. + this.message = this.translate.instant('mm.core.loading'); + } + } + +}