Merge pull request #1696 from crazyserver/MOBILE-2790-2

MOBILE-2790 dashboard: Add download toggle to block input
main
Juan Leyva 2018-12-21 21:55:52 +01:00 committed by GitHub
commit 44a5645afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 25 deletions

View File

@ -1,7 +1,7 @@
<ion-item-divider color="light"> <ion-item-divider color="light">
<h2>{{ 'addon.block_myoverview.pluginname' | translate }}</h2> <h2>{{ 'addon.block_myoverview.pluginname' | translate }}</h2>
<!-- Download all courses. --> <!-- Download all courses. -->
<div *ngIf="downloadAllCoursesEnabled && courses[selectedFilter] && courses[selectedFilter].length > 1 && !showFilter" class="core-button-spinner" item-end> <div *ngIf="downloadEnabled && courses[selectedFilter] && courses[selectedFilter].length > 1 && !showFilter" class="core-button-spinner" item-end>
<button *ngIf="prefetchCoursesData[selectedFilter].icon && prefetchCoursesData[selectedFilter].icon != 'spinner'" ion-button icon-only clear color="dark" (click)="prefetchCourses()"> <button *ngIf="prefetchCoursesData[selectedFilter].icon && prefetchCoursesData[selectedFilter].icon != 'spinner'" ion-button icon-only clear color="dark" (click)="prefetchCourses()">
<core-icon [name]="prefetchCoursesData[selectedFilter].icon"></core-icon> <core-icon [name]="prefetchCoursesData[selectedFilter].icon"></core-icon>
</button> </button>
@ -36,7 +36,7 @@
<ion-grid no-padding> <ion-grid no-padding>
<ion-row no-padding> <ion-row no-padding>
<ion-col *ngFor="let course of filteredCourses" no-padding col-12 col-sm-6 col-md-6 col-lg-4 col-xl-4 align-self-stretch> <ion-col *ngFor="let course of filteredCourses" no-padding col-12 col-sm-6 col-md-6 col-lg-4 col-xl-4 align-self-stretch>
<core-courses-course-progress [course]="course" class="core-courseoverview" showAll="true" [showDownload]="downloadAllCoursesEnabled"></core-courses-course-progress> <core-courses-course-progress [course]="course" class="core-courseoverview" showAll="true" [showDownload]="downloadEnabled"></core-courses-course-progress>
</ion-col> </ion-col>
</ion-row> </ion-row>
</ion-grid> </ion-grid>

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Component, OnInit, OnDestroy, ViewChild, Injector } from '@angular/core'; import { Component, OnInit, Input, OnDestroy, ViewChild, Injector } from '@angular/core';
import { Searchbar } from 'ionic-angular'; import { Searchbar } from 'ionic-angular';
import { CoreEventsProvider } from '@providers/events'; import { CoreEventsProvider } from '@providers/events';
import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreUtilsProvider } from '@providers/utils/utils';
@ -34,6 +34,7 @@ import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component
}) })
export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy { export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy {
@ViewChild('searchbar') searchbar: Searchbar; @ViewChild('searchbar') searchbar: Searchbar;
@Input() downloadEnabled: boolean;
courses = { courses = {
filter: '', filter: '',
@ -47,7 +48,6 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
selectedFilter = 'inprogress'; selectedFilter = 'inprogress';
sort = 'fullname'; sort = 'fullname';
currentSite: any; currentSite: any;
downloadAllCoursesEnabled: boolean;
filteredCourses: any[]; filteredCourses: any[];
prefetchCoursesData = { prefetchCoursesData = {
all: {}, all: {},
@ -86,11 +86,11 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
// Refresh the enabled flags if enabled. // Refresh the enabled flags if enabled.
this.downloadButtonObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, this.downloadButtonObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED,
(data) => { (data) => {
const wasEnabled = this.downloadAllCoursesEnabled; const wasEnabled = this.downloadEnabled;
this.downloadAllCoursesEnabled = data.enabled; this.downloadEnabled = data.enabled;
if (!wasEnabled && this.downloadAllCoursesEnabled && this.loaded) { if (!wasEnabled && this.downloadEnabled && this.loaded) {
// Download all courses is enabled now, initialize it. // Download all courses is enabled now, initialize it.
this.initPrefetchCoursesIcons(); this.initPrefetchCoursesIcons();
} }
@ -202,7 +202,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
* Initialize the prefetch icon for selected courses. * Initialize the prefetch icon for selected courses.
*/ */
protected initPrefetchCoursesIcons(): void { protected initPrefetchCoursesIcons(): void {
if (this.prefetchIconsInitialized || !this.downloadAllCoursesEnabled) { if (this.prefetchIconsInitialized || !this.downloadEnabled) {
// Already initialized. // Already initialized.
return; return;
} }

View File

@ -1,6 +1,6 @@
<ion-item-divider color="light"> <ion-item-divider color="light">
<h2>{{ 'addon.block_recentlyaccessedcourses.pluginname' | translate }}</h2> <h2>{{ 'addon.block_recentlyaccessedcourses.pluginname' | translate }}</h2>
<div *ngIf="downloadAllCoursesEnabled && courses && courses.length > 1" class="core-button-spinner" item-end> <div *ngIf="downloadEnabled && courses && courses.length > 1" class="core-button-spinner" item-end>
<button *ngIf="prefetchCoursesData.icon && prefetchCoursesData.icon != 'spinner'" ion-button icon-only clear color="dark" (click)="prefetchCourses()"> <button *ngIf="prefetchCoursesData.icon && prefetchCoursesData.icon != 'spinner'" ion-button icon-only clear color="dark" (click)="prefetchCourses()">
<core-icon [name]="prefetchCoursesData.icon"></core-icon> <core-icon [name]="prefetchCoursesData.icon"></core-icon>
</button> </button>
@ -14,7 +14,7 @@
<div class="safe-area-page"> <div class="safe-area-page">
<div class="core-horizontal-scroll"> <div class="core-horizontal-scroll">
<ng-container *ngFor="let course of courses"> <ng-container *ngFor="let course of courses">
<core-courses-course-progress [course]="course" class="core-recentlyaccessedcourses" [showDownload]="downloadAllCoursesEnabled"></core-courses-course-progress> <core-courses-course-progress [course]="course" class="core-recentlyaccessedcourses" [showDownload]="downloadEnabled"></core-courses-course-progress>
</ng-container> </ng-container>
</div> </div>
</div> </div>

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Component, OnInit, OnDestroy, Injector } from '@angular/core'; import { Component, OnInit, OnDestroy, Injector, Input } from '@angular/core';
import { CoreEventsProvider } from '@providers/events'; import { CoreEventsProvider } from '@providers/events';
import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitesProvider } from '@providers/sites'; import { CoreSitesProvider } from '@providers/sites';
@ -31,12 +31,13 @@ import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component
templateUrl: 'addon-block-recentlyaccessedcourses.html' templateUrl: 'addon-block-recentlyaccessedcourses.html'
}) })
export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy { export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy {
@Input() downloadEnabled: boolean;
courses = []; courses = [];
prefetchCoursesData = { prefetchCoursesData = {
icon: '', icon: '',
badge: '' badge: ''
}; };
downloadAllCoursesEnabled: boolean;
protected prefetchIconsInitialized = false; protected prefetchIconsInitialized = false;
protected isDestroyed; protected isDestroyed;
@ -61,11 +62,11 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
// Refresh the enabled flags if enabled. // Refresh the enabled flags if enabled.
this.downloadButtonObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, this.downloadButtonObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED,
(data) => { (data) => {
const wasEnabled = this.downloadAllCoursesEnabled; const wasEnabled = this.downloadEnabled;
this.downloadAllCoursesEnabled = data.enabled; this.downloadEnabled = data.enabled;
if (!wasEnabled && this.downloadAllCoursesEnabled && this.loaded) { if (!wasEnabled && this.downloadEnabled && this.loaded) {
// Download all courses is enabled now, initialize it. // Download all courses is enabled now, initialize it.
this.initPrefetchCoursesIcons(); this.initPrefetchCoursesIcons();
} }
@ -120,7 +121,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
* Initialize the prefetch icon for selected courses. * Initialize the prefetch icon for selected courses.
*/ */
protected initPrefetchCoursesIcons(): void { protected initPrefetchCoursesIcons(): void {
if (this.prefetchIconsInitialized || !this.downloadAllCoursesEnabled) { if (this.prefetchIconsInitialized || !this.downloadEnabled) {
// Already initialized. // Already initialized.
return; return;
} }

View File

@ -1,6 +1,6 @@
<ion-item-divider color="light"> <ion-item-divider color="light">
<h2>{{ 'addon.block_starredcourses.pluginname' | translate }}</h2> <h2>{{ 'addon.block_starredcourses.pluginname' | translate }}</h2>
<div *ngIf="downloadAllCoursesEnabled && courses && courses.length > 1" class="core-button-spinner" item-end> <div *ngIf="downloadEnabled && courses && courses.length > 1" class="core-button-spinner" item-end>
<button *ngIf="prefetchCoursesData.icon && prefetchCoursesData.icon != 'spinner'" ion-button icon-only clear color="dark" (click)="prefetchCourses()"> <button *ngIf="prefetchCoursesData.icon && prefetchCoursesData.icon != 'spinner'" ion-button icon-only clear color="dark" (click)="prefetchCourses()">
<core-icon [name]="prefetchCoursesData.icon"></core-icon> <core-icon [name]="prefetchCoursesData.icon"></core-icon>
</button> </button>
@ -14,7 +14,7 @@
<div class="safe-area-page"> <div class="safe-area-page">
<div class="core-horizontal-scroll"> <div class="core-horizontal-scroll">
<ng-container *ngFor="let course of courses"> <ng-container *ngFor="let course of courses">
<core-courses-course-progress [course]="course" class="core-block_starredcourses" [showDownload]="downloadAllCoursesEnabled"></core-courses-course-progress> <core-courses-course-progress [course]="course" class="core-block_starredcourses" [showDownload]="downloadEnabled"></core-courses-course-progress>
</ng-container> </ng-container>
</div> </div>
</div> </div>

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Component, OnInit, OnDestroy, Injector } from '@angular/core'; import { Component, OnInit, OnDestroy, Injector, Input } from '@angular/core';
import { CoreEventsProvider } from '@providers/events'; import { CoreEventsProvider } from '@providers/events';
import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitesProvider } from '@providers/sites'; import { CoreSitesProvider } from '@providers/sites';
@ -31,12 +31,13 @@ import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component
templateUrl: 'addon-block-starredcourses.html' templateUrl: 'addon-block-starredcourses.html'
}) })
export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy { export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy {
@Input() downloadEnabled: boolean;
courses = []; courses = [];
prefetchCoursesData = { prefetchCoursesData = {
icon: '', icon: '',
badge: '' badge: ''
}; };
downloadAllCoursesEnabled: boolean;
protected prefetchIconsInitialized = false; protected prefetchIconsInitialized = false;
protected isDestroyed; protected isDestroyed;
@ -61,11 +62,11 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
// Refresh the enabled flags if enabled. // Refresh the enabled flags if enabled.
this.downloadButtonObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, this.downloadButtonObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED,
(data) => { (data) => {
const wasEnabled = this.downloadAllCoursesEnabled; const wasEnabled = this.downloadEnabled;
this.downloadAllCoursesEnabled = data.enabled; this.downloadEnabled = data.enabled;
if (!wasEnabled && this.downloadAllCoursesEnabled && this.loaded) { if (!wasEnabled && this.downloadEnabled && this.loaded) {
// Download all courses is enabled now, initialize it. // Download all courses is enabled now, initialize it.
this.initPrefetchCoursesIcons(); this.initPrefetchCoursesIcons();
} }
@ -120,7 +121,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
* Initialize the prefetch icon for selected courses. * Initialize the prefetch icon for selected courses.
*/ */
protected initPrefetchCoursesIcons(): void { protected initPrefetchCoursesIcons(): void {
if (this.prefetchIconsInitialized || !this.downloadAllCoursesEnabled) { if (this.prefetchIconsInitialized || !this.downloadEnabled) {
// Already initialized. // Already initialized.
return; return;
} }

View File

@ -37,7 +37,7 @@
<ion-list> <ion-list>
<!-- Dashboard blocks. --> <!-- Dashboard blocks. -->
<ng-container *ngFor="let block of blocks"> <ng-container *ngFor="let block of blocks">
<core-block [block]="block" contextLevel="user" [instanceId]="userId"></core-block> <core-block [block]="block" contextLevel="user" [instanceId]="userId" [extraData]="{'downloadEnabled': downloadEnabled}"></core-block>
</ng-container> </ng-container>
</ion-list> </ion-list>