MOBILE-2309 sitehome: Implement index page and component

main
Dani Palou 2018-01-19 12:07:05 +01:00
parent 3d795ea39f
commit 58a872f992
11 changed files with 363 additions and 67 deletions

View File

@ -8,7 +8,7 @@
</a>
</ng-container>
</div>
<div #originalTabs>
<div class="core-tabs-content-container" #originalTabs>
<ng-content></ng-content>
</div>
</core-loading>

View File

@ -22,8 +22,13 @@ core-tabs {
}
}
.core-tabs-content-container {
height: 100%;
}
core-tab {
display: none;
height: 100%;
&.selected {
display: block;

View File

@ -13,18 +13,19 @@
</ion-navbar>
</ion-header>
<ion-content>
<ion-refresher [enabled]="timeline.loaded || timelineCourses.loaded || courses.loaded" (ionRefresh)="refreshMyOverview($event)">
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<core-tabs [selectedIndex]="firstSelectedTab" [hideUntil]="tabsReady">
<!-- Site home tab. -->
<core-tab [show]="siteHomeEnabled" [title]="'core.sitehome.sitehome' | translate" (ionSelect)="tabChanged('sitehome')">
<!-- @todo. -->
<core-sitehome-index></core-sitehome-index>
</core-tab>
<!-- Timeline tab. -->
<core-tab [title]="'core.courses.timeline' | translate" (ionSelect)="tabChanged('timeline')">
<ion-content>
<ion-refresher [enabled]="timeline.loaded || timelineCourses.loaded || courses.loaded" (ionRefresh)="refreshMyOverview($event)">
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<div no-padding [hidden]="!(timeline.loaded || timelineCourses.loaded)">
<ion-select [(ngModel)]="timeline.sort" (ngModelChange)="switchSort()">
<ion-option value="sortbydates">{{ 'core.courses.sortbydates' | translate }}</ion-option>
@ -46,10 +47,16 @@
</ion-grid>
<core-empty-box *ngIf="timelineCourses.courses.length == 0" image="assets/img/icons/courses.svg" [message]="'core.courses.nocoursesoverview' | translate"></core-empty-box>
</core-loading>
</ion-content>
</core-tab>
<!-- Courses tab. -->
<core-tab [title]="'core.courses.courses' | translate" (ionSelect)="tabChanged('courses')">
<ion-content>
<ion-refresher [enabled]="timeline.loaded || timelineCourses.loaded || courses.loaded" (ionRefresh)="refreshMyOverview($event)">
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<core-loading [hideUntil]="courses.loaded" class="core-loading-center">
<!-- "Time" selector. -->
<div no-padding class="clearfix" [hidden]="showFilter">
@ -89,6 +96,7 @@
<core-empty-box *ngIf="courses[courses.selected].length == 0 && courses.selected == 'past'" image="assets/img/icons/courses.svg" [message]="'core.courses.nocoursespast' | translate"></core-empty-box>
</div>
</core-loading>
</ion-content>
</core-tab>
</core-tabs>

View File

@ -18,6 +18,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { CoreCoursesMyOverviewPage } from './my-overview';
import { CoreComponentsModule } from '../../../../components/components.module';
import { CoreCoursesComponentsModule } from '../../components/components.module';
import { CoreSiteHomeComponentsModule } from '../../../sitehome/components/components.module';
@NgModule({
declarations: [
@ -26,6 +27,7 @@ import { CoreCoursesComponentsModule } from '../../components/components.module'
imports: [
CoreComponentsModule,
CoreCoursesComponentsModule,
CoreSiteHomeComponentsModule,
IonicPageModule.forChild(CoreCoursesMyOverviewPage),
TranslateModule.forChild()
],

View File

@ -17,6 +17,7 @@ import { IonicPage, NavController } from 'ionic-angular';
import { CoreSitesProvider } from '../../../../providers/sites';
import { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
import { CoreCoursesProvider } from '../../providers/courses';
import { CoreCoursesDelegate } from '../../providers/delegate';
import { CoreCoursesMyOverviewProvider } from '../../providers/my-overview';
import { CoreCourseHelperProvider } from '../../../course/providers/helper';
import { CoreSiteHomeProvider } from '../../../sitehome/providers/sitehome';
@ -70,7 +71,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
constructor(private navCtrl: NavController, private coursesProvider: CoreCoursesProvider,
private domUtils: CoreDomUtilsProvider, private myOverviewProvider: CoreCoursesMyOverviewProvider,
private courseHelper: CoreCourseHelperProvider, private sitesProvider: CoreSitesProvider,
private siteHomeProvider: CoreSiteHomeProvider) {}
private siteHomeProvider: CoreSiteHomeProvider, private coursesDelegate: CoreCoursesDelegate) {}
/**
* View loaded.
@ -238,7 +239,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
}
promises.push(this.coursesProvider.invalidateUserCourses());
// promises.push(this.coursesDelegate.clearAndInvalidateCoursesOptions());
promises.push(this.coursesDelegate.clearAndInvalidateCoursesOptions());
return Promise.all(promises).finally(() => {
switch (this.tabShown) {

View File

@ -0,0 +1,40 @@
// (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 { CommonModule } from '@angular/common';
import { IonicModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { CoreComponentsModule } from '../../../components/components.module';
import { CoreDirectivesModule } from '../../../directives/directives.module';
import { CoreCourseComponentsModule } from '../../course/components/components.module';
import { CoreSiteHomeIndexComponent } from './index/index';
@NgModule({
declarations: [
CoreSiteHomeIndexComponent
],
imports: [
CommonModule,
IonicModule,
TranslateModule.forChild(),
CoreComponentsModule,
CoreDirectivesModule,
CoreCourseComponentsModule
],
exports: [
CoreSiteHomeIndexComponent
]
})
export class CoreSiteHomeComponentsModule {}

View File

@ -0,0 +1,29 @@
<ion-content>
<ion-refresher [enabled]="dataLoaded" (ionRefresh)="doRefresh($event)">
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<core-loading [hideUntil]="dataLoaded">
<ion-card *ngIf="section && section.hasContent">
<ion-item text-wrap *ngIf="section.summary">
<core-format-text [text]="section.summary"></core-format-text>
</ion-item>
<core-course-module *ngFor="let module of section.modules" [module]="module" [courseId]="siteHomeId"></core-course-module>
</ion-card>
<!-- @todo: Frontpage items. -->
<!-- <mma-frontpage-item ng-repeat="item in items" name="{{item}}"></mma-frontpage-item> -->
<ion-card *ngIf="block && block.hasContent">
<ion-item text-wrap *ngIf="block.summary">
<core-format-text [text]="block.summary"></core-format-text>
</ion-item>
<core-course-module *ngFor="let module of block.modules" [module]="module" [courseId]="siteHomeId"></core-course-module>
</ion-card>
<core-empty-box *ngIf="!hasContent" icon="qr-scanner" [message]="'core.course.nocontentavailable' | translate"></core-empty-box>
</core-loading>
</ion-content>

View File

@ -0,0 +1,141 @@
// (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, OnInit, Input } from '@angular/core';
import { IonicPage } from 'ionic-angular';
import { CoreSitesProvider } from '../../../../providers/sites';
import { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
import { CoreCourseProvider } from '../../../course/providers/course';
import { CoreCourseHelperProvider } from '../../../course/providers/helper';
import { CoreCourseModulePrefetchDelegate } from '../../../course/providers/module-prefetch-delegate';
/**
* Component that displays site home index.
*/
@Component({
selector: 'core-sitehome-index',
templateUrl: 'index.html',
})
export class CoreSiteHomeIndexComponent implements OnInit {
@Input() moduleId?: number;
dataLoaded: boolean;
section: any;
block: any;
hasContent: boolean;
items: any[] = [];
siteHomeId: number;
protected sectionsLoaded: any[];
constructor(private domUtils: CoreDomUtilsProvider, private sitesProvider: CoreSitesProvider,
private courseProvider: CoreCourseProvider, private courseHelper: CoreCourseHelperProvider,
private prefetchDelegate: CoreCourseModulePrefetchDelegate) {
this.siteHomeId = sitesProvider.getCurrentSite().getSiteHomeId();
}
/**
* Component being initialized.
*/
ngOnInit() {
this.loadContent().finally(() => {
this.dataLoaded = true;
});
}
/**
* Refresh the data.
*
* @param {any} refresher Refresher.
*/
doRefresh(refresher: any) {
const promises = [];
promises.push(this.courseProvider.invalidateSections(this.siteHomeId));
promises.push(this.sitesProvider.getCurrentSite().invalidateConfig());
if (this.sectionsLoaded) {
// Invalidate modules prefetch data.
const modules = this.courseProvider.getSectionsModules(this.sectionsLoaded);
promises.push(this.prefetchDelegate.invalidateModules(modules, this.siteHomeId));
}
Promise.all(promises).finally(() => {
this.loadContent().finally(() => {
refresher.complete();
});
});
}
/**
* Convenience function to fetch the data.
*/
protected loadContent() {
this.hasContent = false;
let config = this.sitesProvider.getCurrentSite().getStoredConfig() || {numsections: 1};
if (config.frontpageloggedin) {
// Items with index 1 and 3 were removed on 2.5 and not being supported in the app.
let frontpageItems = [
'mma-frontpage-item-news', // News items.
false,
'mma-frontpage-item-categories', // List of categories.
false,
'mma-frontpage-item-categories', // Combo list.
'mma-frontpage-item-enrolled-course-list', // Enrolled courses.
'mma-frontpage-item-all-course-list', // List of courses.
'mma-frontpage-item-course-search' // Course search box.
],
items = config.frontpageloggedin.split(',');
this.items = [];
items.forEach((itemNumber) => {
// Get the frontpage item directive to render itself.
const item = frontpageItems[parseInt(itemNumber, 10)];
if (!item || this.items.indexOf(item) >= 0) {
return;
}
this.hasContent = true;
this.items.push(item);
});
}
return this.courseProvider.getSections(this.siteHomeId, false, true).then((sections) => {
this.sectionsLoaded = Array.from(sections);
// Check "Include a topic section" setting from numsections.
this.section = config.numsections && sections.length > 0 ? sections.pop() : false;
if (this.section) {
this.section.hasContent = this.courseHelper.sectionHasContent(this.section);
}
this.block = sections.length > 0 ? sections.pop() : false;
if (this.block) {
this.block.hasContent = this.courseHelper.sectionHasContent(this.block);
}
this.hasContent = this.courseHelper.addHandlerDataForModules(this.sectionsLoaded, this.siteHomeId, this.moduleId) ||
this.hasContent;
// Add log in Moodle.
this.courseProvider.logView(this.siteHomeId);
}).catch((error) => {
this.domUtils.showErrorModalDefault(error, 'core.course.couldnotloadsectioncontent', true);
});
}
}

View File

@ -0,0 +1,6 @@
<ion-header>
<ion-navbar>
<ion-title>{{ 'core.sitehome.sitehome' | translate }}</ion-title>
</ion-navbar>
</ion-header>
<core-sitehome-index [moduleId]="moduleId"></core-sitehome-index>

View File

@ -0,0 +1,31 @@
// (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 { IonicPageModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { CoreSiteHomeIndexPage } from './index';
import { CoreSiteHomeComponentsModule } from '../../components/components.module';
@NgModule({
declarations: [
CoreSiteHomeIndexPage,
],
imports: [
CoreSiteHomeComponentsModule,
IonicPageModule.forChild(CoreSiteHomeIndexPage),
TranslateModule.forChild()
]
})
export class CoreSiteHomeIndexPageModule {}

View File

@ -0,0 +1,33 @@
// (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 } from '@angular/core';
import { IonicPage, NavParams } from 'ionic-angular';
/**
* Page that displays site home index.
*/
@IonicPage({segment: 'core-sitehome-index'})
@Component({
selector: 'page-core-sitehome-index',
templateUrl: 'index.html',
})
export class CoreSiteHomeIndexPage {
moduleId: number;
constructor(navParams: NavParams) {
this.moduleId = navParams.get('moduleId');
}
}