diff --git a/src/components/tabs/tabs.html b/src/components/tabs/tabs.html index 25ef4700e..22fdd6113 100644 --- a/src/components/tabs/tabs.html +++ b/src/components/tabs/tabs.html @@ -8,7 +8,7 @@ -
+
\ No newline at end of file diff --git a/src/components/tabs/tabs.scss b/src/components/tabs/tabs.scss index b7daa7804..4eb747c02 100644 --- a/src/components/tabs/tabs.scss +++ b/src/components/tabs/tabs.scss @@ -22,8 +22,13 @@ core-tabs { } } + .core-tabs-content-container { + height: 100%; + } + core-tab { display: none; + height: 100%; &.selected { display: block; diff --git a/src/core/courses/pages/my-overview/my-overview.html b/src/core/courses/pages/my-overview/my-overview.html index 7980e8c02..b2667fcba 100644 --- a/src/core/courses/pages/my-overview/my-overview.html +++ b/src/core/courses/pages/my-overview/my-overview.html @@ -13,82 +13,90 @@ - - - - - + -
- - {{ 'core.courses.sortbydates' | translate }} - {{ 'core.courses.sortbycourses' | translate }} - -
- - - - - - - - - - - - - - - + + + + + +
+ + {{ 'core.courses.sortbydates' | translate }} + {{ 'core.courses.sortbycourses' | translate }} + +
+ + + + + + + + + + + + + + + +
- - -
- - {{ 'core.courses.inprogress' | translate }} - {{ 'core.courses.future' | translate }} - {{ 'core.courses.past' | translate }} - - -
- - - {{prefetchCoursesData[courses.selected].badge}} -
-
- -
- - - - -
- -
- - - - - - - + + + + - - - -
-
+ + +
+ + {{ 'core.courses.inprogress' | translate }} + {{ 'core.courses.future' | translate }} + {{ 'core.courses.past' | translate }} + + +
+ + + {{prefetchCoursesData[courses.selected].badge}} +
+
+ +
+ + + + +
+ +
+ + + + + + + + + + + +
+
+
diff --git a/src/core/courses/pages/my-overview/my-overview.module.ts b/src/core/courses/pages/my-overview/my-overview.module.ts index 0259d3bb8..041267ef4 100644 --- a/src/core/courses/pages/my-overview/my-overview.module.ts +++ b/src/core/courses/pages/my-overview/my-overview.module.ts @@ -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() ], diff --git a/src/core/courses/pages/my-overview/my-overview.ts b/src/core/courses/pages/my-overview/my-overview.ts index f9e698ba4..15231e6f7 100644 --- a/src/core/courses/pages/my-overview/my-overview.ts +++ b/src/core/courses/pages/my-overview/my-overview.ts @@ -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) { diff --git a/src/core/sitehome/components/components.module.ts b/src/core/sitehome/components/components.module.ts new file mode 100644 index 000000000..558bc272d --- /dev/null +++ b/src/core/sitehome/components/components.module.ts @@ -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 {} diff --git a/src/core/sitehome/components/index/index.html b/src/core/sitehome/components/index/index.html new file mode 100644 index 000000000..742d1f24d --- /dev/null +++ b/src/core/sitehome/components/index/index.html @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/core/sitehome/components/index/index.ts b/src/core/sitehome/components/index/index.ts new file mode 100644 index 000000000..f15d090bb --- /dev/null +++ b/src/core/sitehome/components/index/index.ts @@ -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); + }); + } +} diff --git a/src/core/sitehome/pages/index/index.html b/src/core/sitehome/pages/index/index.html new file mode 100644 index 000000000..e5d6b3299 --- /dev/null +++ b/src/core/sitehome/pages/index/index.html @@ -0,0 +1,6 @@ + + + {{ 'core.sitehome.sitehome' | translate }} + + + diff --git a/src/core/sitehome/pages/index/index.module.ts b/src/core/sitehome/pages/index/index.module.ts new file mode 100644 index 000000000..ce04e8590 --- /dev/null +++ b/src/core/sitehome/pages/index/index.module.ts @@ -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 {} diff --git a/src/core/sitehome/pages/index/index.ts b/src/core/sitehome/pages/index/index.ts new file mode 100644 index 000000000..58ad7dcdd --- /dev/null +++ b/src/core/sitehome/pages/index/index.ts @@ -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'); + } +}