From 92085c4889893ea085d8e441cd02dcaaed23e135 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Tue, 13 Mar 2018 10:21:43 +0100 Subject: [PATCH] MOBILE-2323 learning plans: PR fixes --- package.json | 3 +- src/addon/competency/competency.module.ts | 15 +++-- .../components/components.module.ts | 6 +- .../competency/components/course/course.html | 4 +- .../competency/components/course/course.ts | 16 ++--- .../pages/competencies/competencies.module.ts | 6 +- .../pages/competencies/competencies.ts | 18 ++---- .../pages/competency/competency.module.ts | 6 +- .../competency/pages/competency/competency.ts | 22 +++---- .../competencysummary.module.ts | 6 +- .../competencysummary/competencysummary.ts | 14 ++--- .../coursecompetencies.module.ts | 6 -- .../coursecompetencies/coursecompetencies.ts | 13 +--- .../competency/pages/plan/plan.module.ts | 6 +- src/addon/competency/pages/plan/plan.ts | 28 ++++----- .../competency/pages/planlist/planlist.html | 4 +- .../pages/planlist/planlist.module.ts | 6 +- .../competency/pages/planlist/planlist.ts | 12 +--- src/addon/competency/providers/competency.ts | 63 ++----------------- .../providers/course-option-handler.ts | 14 ++--- src/addon/competency/providers/helper.ts | 6 +- .../competency/providers/mainmenu-handler.ts | 16 ++--- .../competency/providers/user-handler.ts | 12 ++-- 23 files changed, 95 insertions(+), 207 deletions(-) diff --git a/package.json b/package.json index 8154175bd..0342fe4bb 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "lint": "ionic-app-scripts lint", "ionic:build": "ionic-app-scripts build", "ionic:serve": "gulp watch | ionic-app-scripts serve", - "ionic:build:before": "gulp" + "ionic:build:before": "gulp", + "ionic:watch:before": "gulp" }, "dependencies": { "@angular/animations": "^5.2.5", diff --git a/src/addon/competency/competency.module.ts b/src/addon/competency/competency.module.ts index a2a7b5dac..83ae4bd28 100644 --- a/src/addon/competency/competency.module.ts +++ b/src/addon/competency/competency.module.ts @@ -19,14 +19,13 @@ import { AddonCompetencyCourseOptionHandler } from './providers/course-option-ha import { AddonCompetencyMainMenuHandler } from './providers/mainmenu-handler'; import { AddonCompetencyUserHandler } from './providers/user-handler'; import { AddonCompetencyComponentsModule } from './components/components.module'; -import { CoreCourseProvider } from '../../core/course/providers/course'; -import { CoreCourseOptionsDelegate } from '../../core/course/providers/options-delegate'; -import { CoreMainMenuDelegate } from '../../core/mainmenu/providers/delegate'; -import { CoreUserDelegate } from '../../core/user/providers/user-delegate'; -import { CoreUserProvider } from '../../core/user/providers/user'; -import { CoreEventsProvider } from '../../providers/events'; -import { CoreSitesProvider } from '../../providers/sites'; -import { CoreCoursesProvider } from '../../core/courses/providers/courses'; +import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate'; +import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate'; +import { CoreUserDelegate } from '@core/user/providers/user-delegate'; +import { CoreUserProvider } from '@core/user/providers/user'; +import { CoreEventsProvider } from '@providers/events'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreCoursesProvider } from '@core/courses/providers/courses'; @NgModule({ declarations: [ diff --git a/src/addon/competency/components/components.module.ts b/src/addon/competency/components/components.module.ts index 651b2a9aa..670d33720 100644 --- a/src/addon/competency/components/components.module.ts +++ b/src/addon/competency/components/components.module.ts @@ -16,9 +16,9 @@ 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 { CorePipesModule } from '../../../pipes/pipes.module'; +import { CoreComponentsModule } from '@components/components.module'; +import { CoreDirectivesModule } from '@directives/directives.module'; +import { CorePipesModule } from '@pipes/pipes.module'; import { AddonCompetencyCourseComponent } from './course/course'; @NgModule({ diff --git a/src/addon/competency/components/course/course.html b/src/addon/competency/components/course/course.html index c1344b369..04584daae 100644 --- a/src/addon/competency/components/course/course.html +++ b/src/addon/competency/components/course/course.html @@ -18,7 +18,7 @@ {{ 'addon.competency.competenciesmostoftennotproficientincourse' | translate }}:

- + {{ comp.shortname }} - {{ comp.idnumber }}

@@ -43,7 +43,7 @@ {{competency.competency.shortname}} {{competency.competency.idnumber}} - {{ competency.usercompetencycourse.gradename }}
+ {{ competency.usercompetencycourse.gradename }}
diff --git a/src/addon/competency/components/course/course.ts b/src/addon/competency/components/course/course.ts index 955462760..d4e9373d1 100644 --- a/src/addon/competency/components/course/course.ts +++ b/src/addon/competency/components/course/course.ts @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, ViewChild, Input, Optional } from '@angular/core'; +import { Component, ViewChild, Input } from '@angular/core'; import { Content, NavController } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; -import { CoreAppProvider } from '../../../../providers/app'; -import { CoreDomUtilsProvider } from '../../../../providers/utils/dom'; +import { CoreAppProvider } from '@providers/app'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { AddonCompetencyProvider } from '../../providers/competency'; import { AddonCompetencyHelperProvider } from '../../providers/helper'; @@ -64,14 +64,8 @@ export class AddonCompetencyCourseComponent { this.helperProvider.getProfile(this.userId).then((user) => { this.user = user; }); - }, (message) => { - if (message) { - this.domUtils.showErrorModal(message); - } else { - this.domUtils.showErrorModal('Error getting course competencies data.'); - } - - return Promise.reject(null); + }).catch((message) => { + this.domUtils.showErrorModalDefault(message, 'Error getting course competencies data.'); }); } diff --git a/src/addon/competency/pages/competencies/competencies.module.ts b/src/addon/competency/pages/competencies/competencies.module.ts index 6effd59fd..e53b32ba1 100644 --- a/src/addon/competency/pages/competencies/competencies.module.ts +++ b/src/addon/competency/pages/competencies/competencies.module.ts @@ -15,9 +15,7 @@ import { NgModule } from '@angular/core'; import { IonicPageModule } from 'ionic-angular'; import { TranslateModule } from '@ngx-translate/core'; -import { CoreComponentsModule } from '../../../../components/components.module'; -import { CoreDirectivesModule } from '../../../../directives/directives.module'; -import { CorePipesModule } from '../../../../pipes/pipes.module'; +import { CoreComponentsModule } from '@components/components.module'; import { AddonCompetencyCompetenciesPage } from './competencies'; @NgModule({ @@ -26,8 +24,6 @@ import { AddonCompetencyCompetenciesPage } from './competencies'; ], imports: [ CoreComponentsModule, - CoreDirectivesModule, - CorePipesModule, IonicPageModule.forChild(AddonCompetencyCompetenciesPage), TranslateModule.forChild() ], diff --git a/src/addon/competency/pages/competencies/competencies.ts b/src/addon/competency/pages/competencies/competencies.ts index b016b349f..1278e318f 100644 --- a/src/addon/competency/pages/competencies/competencies.ts +++ b/src/addon/competency/pages/competencies/competencies.ts @@ -13,10 +13,10 @@ // limitations under the License. import { Component, ViewChild } from '@angular/core'; -import { IonicPage, NavController, NavParams } from 'ionic-angular'; +import { IonicPage, NavParams } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; -import { CoreDomUtilsProvider } from '../../../../providers/utils/dom'; -import { CoreSplitViewComponent } from '../../../../components/split-view/split-view'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { AddonCompetencyProvider } from '../../providers/competency'; /** @@ -39,8 +39,8 @@ export class AddonCompetencyCompetenciesPage { competencies = []; title: string; - constructor(private navCtrl: NavController, navParams: NavParams, private translate: TranslateService, - private domUtils: CoreDomUtilsProvider, private competencyProvider: AddonCompetencyProvider) { + constructor(navParams: NavParams, private translate: TranslateService, private domUtils: CoreDomUtilsProvider, + private competencyProvider: AddonCompetencyProvider) { this.planId = navParams.get('planId'); this.courseId = navParams.get('courseId'); this.competencyId = navParams.get('competencyId'); @@ -95,13 +95,7 @@ export class AddonCompetencyCompetenciesPage { } this.competencies = response.competencies; }).catch((message) => { - if (message) { - this.domUtils.showErrorModal(message); - } else { - this.domUtils.showErrorModal('Error getting competencies data.'); - } - - return Promise.reject(null); + this.domUtils.showErrorModalDefault(message, 'Error getting competencies data.'); }); } diff --git a/src/addon/competency/pages/competency/competency.module.ts b/src/addon/competency/pages/competency/competency.module.ts index e188fc222..028abfa2d 100644 --- a/src/addon/competency/pages/competency/competency.module.ts +++ b/src/addon/competency/pages/competency/competency.module.ts @@ -15,9 +15,9 @@ import { NgModule } from '@angular/core'; import { IonicPageModule } from 'ionic-angular'; import { TranslateModule } from '@ngx-translate/core'; -import { CoreComponentsModule } from '../../../../components/components.module'; -import { CoreDirectivesModule } from '../../../../directives/directives.module'; -import { CorePipesModule } from '../../../../pipes/pipes.module'; +import { CoreComponentsModule } from '@components/components.module'; +import { CoreDirectivesModule } from '@directives/directives.module'; +import { CorePipesModule } from '@pipes/pipes.module'; import { AddonCompetencyCompetencyPage } from './competency'; @NgModule({ diff --git a/src/addon/competency/pages/competency/competency.ts b/src/addon/competency/pages/competency/competency.ts index e8b2ff2f0..0443a66d8 100644 --- a/src/addon/competency/pages/competency/competency.ts +++ b/src/addon/competency/pages/competency/competency.ts @@ -15,9 +15,9 @@ import { Component, Optional } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; -import { CoreSitesProvider } from '../../../../providers/sites'; -import { CoreDomUtilsProvider } from '../../../../providers/utils/dom'; -import { CoreSplitViewComponent } from '../../../../components/split-view/split-view'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { AddonCompetencyProvider } from '../../providers/competency'; /** @@ -103,14 +103,8 @@ export class AddonCompetencyCompetencyPage { evidence.description = this.translate.instant(key, {$a: evidence.desca}); } }); - }, (message) => { - if (message) { - this.domUtils.showErrorModal(message); - } else { - this.domUtils.showErrorModal('Error getting competency data.'); - } - - return Promise.reject(null); + }).catch((message) => { + this.domUtils.showErrorModalDefault(message, 'Error getting competency data.'); }); } @@ -118,9 +112,9 @@ export class AddonCompetencyCompetencyPage { * Convenience function to get the review status name translated. * * @param {number} status - * @return {any} + * @return {string} */ - protected getStatusName(status: number): any { + protected getStatusName(status: number): string { let statusTranslateName; switch (status) { case AddonCompetencyProvider.REVIEW_STATUS_IDLE: @@ -134,7 +128,7 @@ export class AddonCompetencyCompetencyPage { break; default: // We can use the current status name. - return status; + return String(status); } return this.translate.instant('addon.competency.usercompetencystatus_' + statusTranslateName); diff --git a/src/addon/competency/pages/competencysummary/competencysummary.module.ts b/src/addon/competency/pages/competencysummary/competencysummary.module.ts index 59563b5ff..855095dbf 100644 --- a/src/addon/competency/pages/competencysummary/competencysummary.module.ts +++ b/src/addon/competency/pages/competencysummary/competencysummary.module.ts @@ -15,9 +15,8 @@ import { NgModule } from '@angular/core'; import { IonicPageModule } from 'ionic-angular'; import { TranslateModule } from '@ngx-translate/core'; -import { CoreComponentsModule } from '../../../../components/components.module'; -import { CoreDirectivesModule } from '../../../../directives/directives.module'; -import { CorePipesModule } from '../../../../pipes/pipes.module'; +import { CoreComponentsModule } from '@components/components.module'; +import { CoreDirectivesModule } from '@directives/directives.module'; import { AddonCompetencyCompetencySummaryPage } from './competencysummary'; @NgModule({ @@ -27,7 +26,6 @@ import { AddonCompetencyCompetencySummaryPage } from './competencysummary'; imports: [ CoreComponentsModule, CoreDirectivesModule, - CorePipesModule, IonicPageModule.forChild(AddonCompetencyCompetencySummaryPage), TranslateModule.forChild() ], diff --git a/src/addon/competency/pages/competencysummary/competencysummary.ts b/src/addon/competency/pages/competencysummary/competencysummary.ts index f75247f31..6002b5688 100644 --- a/src/addon/competency/pages/competencysummary/competencysummary.ts +++ b/src/addon/competency/pages/competencysummary/competencysummary.ts @@ -15,8 +15,8 @@ import { Component, Optional } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; -import { CoreDomUtilsProvider } from '../../../../providers/utils/dom'; -import { CoreSplitViewComponent } from '../../../../components/split-view/split-view'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { AddonCompetencyProvider } from '../../providers/competency'; /** @@ -57,14 +57,8 @@ export class AddonCompetencyCompetencySummaryPage { protected fetchCompetency(): Promise { return this.competencyProvider.getCompetencySummary(this.competencyId).then((competency) => { this.competency = competency; - }, (message) => { - if (message) { - this.domUtils.showErrorModal(message); - } else { - this.domUtils.showErrorModal('Error getting competency summary data.'); - } - - return Promise.reject(null); + }).catch((message) => { + this.domUtils.showErrorModalDefault(message, 'Error getting competency summary data.'); }); } diff --git a/src/addon/competency/pages/coursecompetencies/coursecompetencies.module.ts b/src/addon/competency/pages/coursecompetencies/coursecompetencies.module.ts index 277d005bf..f5a2298a7 100644 --- a/src/addon/competency/pages/coursecompetencies/coursecompetencies.module.ts +++ b/src/addon/competency/pages/coursecompetencies/coursecompetencies.module.ts @@ -15,9 +15,6 @@ import { NgModule } from '@angular/core'; import { IonicPageModule } from 'ionic-angular'; import { TranslateModule } from '@ngx-translate/core'; -import { CoreComponentsModule } from '../../../../components/components.module'; -import { CoreDirectivesModule } from '../../../../directives/directives.module'; -import { CorePipesModule } from '../../../../pipes/pipes.module'; import { AddonCompetencyComponentsModule } from '../../components/components.module'; import { AddonCompetencyCourseCompetenciesPage } from './coursecompetencies'; @@ -26,9 +23,6 @@ import { AddonCompetencyCourseCompetenciesPage } from './coursecompetencies'; AddonCompetencyCourseCompetenciesPage, ], imports: [ - CoreComponentsModule, - CoreDirectivesModule, - CorePipesModule, IonicPageModule.forChild(AddonCompetencyCourseCompetenciesPage), TranslateModule.forChild(), AddonCompetencyComponentsModule diff --git a/src/addon/competency/pages/coursecompetencies/coursecompetencies.ts b/src/addon/competency/pages/coursecompetencies/coursecompetencies.ts index b93dd5577..42bb83f71 100644 --- a/src/addon/competency/pages/coursecompetencies/coursecompetencies.ts +++ b/src/addon/competency/pages/coursecompetencies/coursecompetencies.ts @@ -12,13 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, ViewChild } from '@angular/core'; -import { IonicPage, NavController, NavParams } from 'ionic-angular'; -import { TranslateService } from '@ngx-translate/core'; -import { CoreAppProvider } from '../../../../providers/app'; -import { CoreDomUtilsProvider } from '../../../../providers/utils/dom'; -import { AddonCompetencyProvider } from '../../providers/competency'; -import { AddonCompetencyHelperProvider } from '../../providers/helper'; +import { Component } from '@angular/core'; +import { IonicPage, NavParams } from 'ionic-angular'; /** * Page that displays the list of competencies of a course. @@ -33,9 +28,7 @@ export class AddonCompetencyCourseCompetenciesPage { protected courseId: number; protected userId: number; - constructor(private navCtrl: NavController, navParams: NavParams, private translate: TranslateService, - private appProvider: CoreAppProvider, private domUtils: CoreDomUtilsProvider, - private competencyProvider: AddonCompetencyProvider, private helperProvider: AddonCompetencyHelperProvider) { + constructor(navParams: NavParams) { this.courseId = navParams.get('courseId'); this.userId = navParams.get('userId'); } diff --git a/src/addon/competency/pages/plan/plan.module.ts b/src/addon/competency/pages/plan/plan.module.ts index cf22ce9b7..bb7f48038 100644 --- a/src/addon/competency/pages/plan/plan.module.ts +++ b/src/addon/competency/pages/plan/plan.module.ts @@ -15,9 +15,9 @@ import { NgModule } from '@angular/core'; import { IonicPageModule } from 'ionic-angular'; import { TranslateModule } from '@ngx-translate/core'; -import { CoreComponentsModule } from '../../../../components/components.module'; -import { CoreDirectivesModule } from '../../../../directives/directives.module'; -import { CorePipesModule } from '../../../../pipes/pipes.module'; +import { CoreComponentsModule } from '@components/components.module'; +import { CoreDirectivesModule } from '@directives/directives.module'; +import { CorePipesModule } from '@pipes/pipes.module'; import { AddonCompetencyPlanPage } from './plan'; @NgModule({ diff --git a/src/addon/competency/pages/plan/plan.ts b/src/addon/competency/pages/plan/plan.ts index 20fd55fa9..d82c46dcd 100644 --- a/src/addon/competency/pages/plan/plan.ts +++ b/src/addon/competency/pages/plan/plan.ts @@ -15,9 +15,9 @@ import { Component, Optional } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; -import { CoreAppProvider } from '../../../../providers/app'; -import { CoreDomUtilsProvider } from '../../../../providers/utils/dom'; -import { CoreSplitViewComponent } from '../../../../components/split-view/split-view'; +import { CoreAppProvider } from '@providers/app'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { AddonCompetencyProvider } from '../../providers/competency'; import { AddonCompetencyHelperProvider } from '../../providers/helper'; @@ -64,14 +64,8 @@ export class AddonCompetencyPlanPage { this.user = user; }); this.plan = plan; - }, (message) => { - if (message) { - this.domUtils.showErrorModal(message); - } else { - this.domUtils.showErrorModal('Error getting learning plan data.'); - } - - return Promise.reject(null); + }).catch((message) => { + this.domUtils.showErrorModalDefault(message, 'Error getting learning plan data.'); }); } @@ -82,16 +76,20 @@ export class AddonCompetencyPlanPage { */ openCompetency(competencyId: number): void { const navCtrl = this.svComponent ? this.svComponent.getMasterNav() : this.navCtrl; - navCtrl.push('AddonCompetencyCompetenciesPage', {competencyId, planId: this.planId}); + if (this.appProvider.isWide()) { + navCtrl.push('AddonCompetencyCompetenciesPage', {competencyId, planId: this.planId}); + } else { + navCtrl.push('AddonCompetencyCompetencyPage', {competencyId, planId: this.planId}); + } } /** * Convenience function to get the status name translated. * * @param {number} status - * @return {any} + * @return {string} */ - protected getStatusName(status: number): any { + protected getStatusName(status: number): string { let statusTranslateName; switch (status) { case AddonCompetencyProvider.STATUS_DRAFT: @@ -111,7 +109,7 @@ export class AddonCompetencyPlanPage { break; default: // We can use the current status name. - return status; + return String(status); } return this.translate.instant('addon.competency.planstatus' + statusTranslateName); diff --git a/src/addon/competency/pages/planlist/planlist.html b/src/addon/competency/pages/planlist/planlist.html index 120b15ad2..446aff30c 100644 --- a/src/addon/competency/pages/planlist/planlist.html +++ b/src/addon/competency/pages/planlist/planlist.html @@ -9,7 +9,7 @@ - + @@ -19,4 +19,4 @@ - \ No newline at end of file + diff --git a/src/addon/competency/pages/planlist/planlist.module.ts b/src/addon/competency/pages/planlist/planlist.module.ts index 637461ae8..92037f778 100644 --- a/src/addon/competency/pages/planlist/planlist.module.ts +++ b/src/addon/competency/pages/planlist/planlist.module.ts @@ -15,9 +15,8 @@ import { NgModule } from '@angular/core'; import { IonicPageModule } from 'ionic-angular'; import { TranslateModule } from '@ngx-translate/core'; -import { CoreComponentsModule } from '../../../../components/components.module'; -import { CoreDirectivesModule } from '../../../../directives/directives.module'; -import { CorePipesModule } from '../../../../pipes/pipes.module'; +import { CoreComponentsModule } from '@components/components.module'; +import { CorePipesModule } from '@pipes/pipes.module'; import { AddonCompetencyPlanListPage } from './planlist'; @NgModule({ @@ -26,7 +25,6 @@ import { AddonCompetencyPlanListPage } from './planlist'; ], imports: [ CoreComponentsModule, - CoreDirectivesModule, CorePipesModule, IonicPageModule.forChild(AddonCompetencyPlanListPage), TranslateModule.forChild() diff --git a/src/addon/competency/pages/planlist/planlist.ts b/src/addon/competency/pages/planlist/planlist.ts index bc77fd229..f4e1762e2 100644 --- a/src/addon/competency/pages/planlist/planlist.ts +++ b/src/addon/competency/pages/planlist/planlist.ts @@ -15,8 +15,8 @@ import { Component, ViewChild } from '@angular/core'; import { IonicPage, NavParams } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; -import { CoreDomUtilsProvider } from '../../../../providers/utils/dom'; -import { CoreSplitViewComponent } from '../../../../components/split-view/split-view'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { AddonCompetencyProvider } from '../../providers/competency'; /** @@ -68,13 +68,7 @@ export class AddonCompetencyPlanListPage { return this.competencyProvider.getLearningPlans(this.userId).then((plans) => { this.plans = plans; }).catch((message) => { - if (message) { - this.domUtils.showErrorModal(message); - } else { - this.domUtils.showErrorModal('Error getting learning plans data.'); - } - - return Promise.reject(null); + this.domUtils.showErrorModalDefault(message, 'Error getting learning plans data.'); }); } diff --git a/src/addon/competency/providers/competency.ts b/src/addon/competency/providers/competency.ts index c8112b79a..611f8b492 100644 --- a/src/addon/competency/providers/competency.ts +++ b/src/addon/competency/providers/competency.ts @@ -13,9 +13,8 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreLoggerProvider } from '../../../providers/logger'; -import { CoreSitesProvider } from '../../../providers/sites'; -import { CoreUserProvider } from '../../../core/user/providers/user'; +import { CoreLoggerProvider } from '@providers/logger'; +import { CoreSitesProvider } from '@providers/sites'; /** * Service to handle caompetency learning plans. @@ -103,24 +102,6 @@ export class AddonCompetencyProvider { return this.ROOT_CACHE_KEY + 'coursecompetencies:' + courseId; } - /** - * Check if competency learning plans WS is available. - * - * @param {string} [siteId] Site ID. If not defined, current site. - * @return {Promise} True if competency learning plans WS is available, false otherwise. - */ - isPluginEnabled(siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - - return this.sitesProvider.getSite(siteId).then((site) => { - if (site.wsAvailable('core_competency_list_course_competencies') && site.wsAvailable('tool_lp_data_for_plans_page')) { - return this.getLearningPlans(0, siteId); - } - - return false; - }); - } - /** * Returns whether competencies are enabled. * @@ -133,10 +114,6 @@ export class AddonCompetencyProvider { return Promise.resolve(false); } - if (!this.isPluginEnabled(siteId)) { - return Promise.resolve(false); - } - return this.getCourseCompetencies(courseId, 0, siteId).catch(() => { return false; }); @@ -150,8 +127,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise to be resolved when the plans are retrieved. */ getLearningPlans(userId?: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { userId = userId || site.getUserId(); @@ -182,8 +157,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise to be resolved when the plans are retrieved. */ getLearningPlan(planId: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { this.logger.debug('Get plan ' + planId); @@ -214,8 +187,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise to be resolved when the plans are retrieved. */ getCompetencyInPlan(planId: number, competencyId: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { this.logger.debug('Get competency ' + competencyId + ' in plan ' + planId); @@ -248,8 +219,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise to be resolved when the plans are retrieved. */ getCompetencyInCourse(courseId: number, competencyId: number, userId?: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { userId = userId || site.getUserId(); @@ -283,8 +252,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise to be resolved when the plans are retrieved. */ getCompetencySummary(competencyId: number, userId?: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { userId = userId || site.getUserId(); @@ -309,7 +276,7 @@ export class AddonCompetencyProvider { } /** - * Get an specific competency summary. + * Get all competencies in a course. * * @param {number} courseId ID of the course. * @param {number} [userId] ID of the user. @@ -317,8 +284,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise to be resolved when the course competencies are retrieved. */ getCourseCompetencies(courseId: number, userId?: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { this.logger.debug('Get course competencies for course ' + courseId); @@ -366,8 +331,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise resolved when the data is invalidated. */ invalidateLearningPlans(userId?: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { userId = userId || site.getUserId(); @@ -383,8 +346,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise resolved when the data is invalidated. */ invalidateLearningPlan(planId: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { return site.invalidateWsCacheForKey(this.getLearningPlanCacheKey(planId)); }); @@ -399,8 +360,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise resolved when the data is invalidated. */ invalidateCompetencyInPlan(planId: number, competencyId: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { return site.invalidateWsCacheForKey(this.getCompetencyInPlanCacheKey(planId, competencyId)); }); @@ -416,8 +375,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise resolved when the data is invalidated. */ invalidateCompetencyInCourse(courseId: number, competencyId: number, userId?: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { userId = userId || site.getUserId(); @@ -434,8 +391,6 @@ export class AddonCompetencyProvider { * @return {Promise} Promise resolved when the data is invalidated. */ invalidateCompetencySummary(competencyId: number, userId?: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { userId = userId || site.getUserId(); @@ -452,11 +407,9 @@ export class AddonCompetencyProvider { * @return {Promise} Promise resolved when the data is invalidated. */ invalidateCourseCompetencies(courseId: number, userId?: number, siteId?: string): Promise { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { return site.invalidateWsCacheForKey(this.getCourseCompetenciesCacheKey(courseId)); - }).then((response) => { + }).then(() => { if (!userId || userId == this.sitesProvider.getCurrentSiteUserId()) { return; } @@ -487,8 +440,6 @@ export class AddonCompetencyProvider { logCompetencyInPlanView(planId: number, competencyId: number, planStatus: number, userId?: number, siteId?: string) : Promise { if (planId && competencyId) { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { userId = userId || site.getUserId(); @@ -498,7 +449,7 @@ export class AddonCompetencyProvider { userid: userId }, preSets = { - typeExpected: 'boolean' + typeExpected: 'boolean' }; if (planStatus == AddonCompetencyProvider.STATUS_COMPLETE) { @@ -523,8 +474,6 @@ export class AddonCompetencyProvider { */ logCompetencyInCourseView(courseId: number, competencyId: number, userId?: number, siteId?: string): Promise { if (courseId && competencyId) { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { userId = userId || site.getUserId(); @@ -553,8 +502,6 @@ export class AddonCompetencyProvider { */ logCompetencyView(competencyId: number, siteId?: string): Promise { if (competencyId) { - siteId = siteId || this.sitesProvider.getCurrentSiteId(); - return this.sitesProvider.getSite(siteId).then((site) => { const params = { id: competencyId, diff --git a/src/addon/competency/providers/course-option-handler.ts b/src/addon/competency/providers/course-option-handler.ts index 74a37f6d9..fe7bdd9d8 100644 --- a/src/addon/competency/providers/course-option-handler.ts +++ b/src/addon/competency/providers/course-option-handler.ts @@ -12,10 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Injectable } from '@angular/core'; -import { NavController } from 'ionic-angular'; -import { CoreCourseOptionsHandler, CoreCourseOptionsHandlerData } from '../../../core/course/providers/options-delegate'; -import { CoreCourseProvider } from '../../../core/course/providers/course'; +import { Injectable, Injector } from '@angular/core'; +import { CoreCourseOptionsHandler, CoreCourseOptionsHandlerData } from '@core/course/providers/options-delegate'; +import { CoreCourseProvider } from '@core/course/providers/course'; import { AddonCompetencyCourseComponent } from '../components/course/course'; import { AddonCompetencyProvider } from '../providers/competency'; @@ -43,7 +42,7 @@ export class AddonCompetencyCourseOptionHandler implements CoreCourseOptionsHand * @return {boolean|Promise} Whether or not the handler is enabled on a site level. */ isEnabled(): boolean | Promise { - return this.competencyProvider.isPluginEnabled(); + return true; } /** @@ -79,10 +78,11 @@ export class AddonCompetencyCourseOptionHandler implements CoreCourseOptionsHand /** * Returns the data needed to render the handler. * + * @param {Injector} injector Injector. * @param {number} courseId The course ID. - * @return {CoreCourseOptionsHandlerData} Data. + * @return {CoreCourseOptionsHandlerData|Promise} Data or promise resolved with the data. */ - getDisplayData(courseId: number): CoreCourseOptionsHandlerData { + getDisplayData?(injector: Injector, courseId: number): CoreCourseOptionsHandlerData | Promise { return { title: 'addon.competency.competencies', class: 'addon-competency-course-handler', diff --git a/src/addon/competency/providers/helper.ts b/src/addon/competency/providers/helper.ts index 494958140..a742218eb 100644 --- a/src/addon/competency/providers/helper.ts +++ b/src/addon/competency/providers/helper.ts @@ -13,11 +13,11 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreSitesProvider } from '../../../providers/sites'; -import { CoreUserProvider } from '../../../core/user/providers/user'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreUserProvider } from '@core/user/providers/user'; /** - * Service that provides some features regarding the user profile. + * Service that provides some features regarding learning plans. */ @Injectable() export class AddonCompetencyHelperProvider { diff --git a/src/addon/competency/providers/mainmenu-handler.ts b/src/addon/competency/providers/mainmenu-handler.ts index d17ad43c9..b45e84459 100644 --- a/src/addon/competency/providers/mainmenu-handler.ts +++ b/src/addon/competency/providers/mainmenu-handler.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; import { AddonCompetencyProvider } from './competency'; -import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '../../../core/mainmenu/providers/delegate'; +import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@core/mainmenu/providers/delegate'; /** * Handler to inject an option into main menu. @@ -22,7 +22,7 @@ import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '../../../core/main @Injectable() export class AddonCompetencyMainMenuHandler implements CoreMainMenuHandler { name = 'AddonCompetency'; - priority = 900; + priority = 500; constructor(private competencyProvider: AddonCompetencyProvider) { } @@ -32,15 +32,9 @@ export class AddonCompetencyMainMenuHandler implements CoreMainMenuHandler { * @return {boolean} Whether or not the handler is enabled on a site level. */ isEnabled(): boolean | Promise { - return this.competencyProvider.isPluginEnabled().then((enabled) => { - if (!enabled) { - return false; - } - - // Check the user has at least one learn plan available. - return this.competencyProvider.getLearningPlans().then((plans) => { - return plans.length > 0; - }); + // Check the user has at least one learn plan available. + return this.competencyProvider.getLearningPlans().then((plans) => { + return plans.length > 0; }); } diff --git a/src/addon/competency/providers/user-handler.ts b/src/addon/competency/providers/user-handler.ts index fa7f24f2c..a80b6fa57 100644 --- a/src/addon/competency/providers/user-handler.ts +++ b/src/addon/competency/providers/user-handler.ts @@ -13,9 +13,9 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreUserDelegate, CoreUserProfileHandler, CoreUserProfileHandlerData } from '../../../core/user/providers/user-delegate'; -import { CoreSitesProvider } from '../../../providers/sites'; -import { CoreContentLinksHelperProvider } from '../../../core/contentlinks/providers/helper'; +import { CoreUserDelegate, CoreUserProfileHandler, CoreUserProfileHandlerData } from '@core/user/providers/user-delegate'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; import { AddonCompetencyProvider } from './competency'; /** @@ -46,7 +46,7 @@ export class AddonCompetencyUserHandler implements CoreUserProfileHandler { * @return {boolean|Promise} Whether or not the handler is enabled on a site level. */ isEnabled(): boolean | Promise { - return this.competencyProvider.isPluginEnabled(); + return true; } /** @@ -104,7 +104,7 @@ export class AddonCompetencyUserHandler implements CoreUserProfileHandler { icon: 'ribbon', title: 'addon.competency.competencies', class: 'addon-competency-handler', - action: ($event, navCtrl, user, courseId): void => { + action: (event, navCtrl, user, courseId): void => { event.preventDefault(); event.stopPropagation(); // Always use redirect to make it the new history root (to avoid "loops" in history). @@ -116,7 +116,7 @@ export class AddonCompetencyUserHandler implements CoreUserProfileHandler { icon: 'map', title: 'addon.competency.learningplans', class: 'addon-competency-handler', - action: ($event, navCtrl, user, courseId): void => { + action: (event, navCtrl, user, courseId): void => { event.preventDefault(); event.stopPropagation(); // Always use redirect to make it the new history root (to avoid "loops" in history).