MOBILE-2339 feedback: Add responses link handlers
parent
02deb0f078
commit
50aacb5734
|
@ -16,7 +16,7 @@
|
||||||
<core-course-module-description [description]="description" [component]="component" [componentId]="componentId"></core-course-module-description>
|
<core-course-module-description [description]="description" [component]="component" [componentId]="componentId"></core-course-module-description>
|
||||||
|
|
||||||
<ng-container *ngIf="showTabs">
|
<ng-container *ngIf="showTabs">
|
||||||
<core-tabs [hideUntil]="tabsReady">
|
<core-tabs [hideUntil]="tabsReady" [selectedIndex]="firstSelectedTab">
|
||||||
<core-tab [title]="'addon.mod_feedback.overview' | translate" (ionSelect)="tabChanged('overview')">
|
<core-tab [title]="'addon.mod_feedback.overview' | translate" (ionSelect)="tabChanged('overview')">
|
||||||
<ng-template>
|
<ng-template>
|
||||||
<ng-container *ngTemplateOutlet="tabOverview"></ng-container>
|
<ng-container *ngTemplateOutlet="tabOverview"></ng-container>
|
||||||
|
|
|
@ -61,6 +61,7 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
|
||||||
};
|
};
|
||||||
showTabs = false;
|
showTabs = false;
|
||||||
tabsReady = false;
|
tabsReady = false;
|
||||||
|
firstSelectedTab: number;
|
||||||
|
|
||||||
protected submitObserver: any;
|
protected submitObserver: any;
|
||||||
|
|
||||||
|
@ -165,7 +166,10 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
|
||||||
this.access = accessData;
|
this.access = accessData;
|
||||||
this.showTabs = (accessData.canviewreports || accessData.canviewanalysis) && !accessData.isempty;
|
this.showTabs = (accessData.canviewreports || accessData.canviewanalysis) && !accessData.isempty;
|
||||||
|
|
||||||
|
this.firstSelectedTab = 0;
|
||||||
if (this.tab == 'analysis') {
|
if (this.tab == 'analysis') {
|
||||||
|
this.firstSelectedTab = 1;
|
||||||
|
|
||||||
return this.fetchFeedbackAnalysisData(this.access);
|
return this.fetchFeedbackAnalysisData(this.access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ import { AddonModFeedbackComponentsModule } from './components/components.module
|
||||||
import { AddonModFeedbackModuleHandler } from './providers/module-handler';
|
import { AddonModFeedbackModuleHandler } from './providers/module-handler';
|
||||||
import { AddonModFeedbackProvider } from './providers/feedback';
|
import { AddonModFeedbackProvider } from './providers/feedback';
|
||||||
import { AddonModFeedbackLinkHandler } from './providers/link-handler';
|
import { AddonModFeedbackLinkHandler } from './providers/link-handler';
|
||||||
|
import { AddonModFeedbackAnalysisLinkHandler } from './providers/analysis-link-handler';
|
||||||
|
import { AddonModFeedbackShowEntriesLinkHandler } from './providers/show-entries-link-handler';
|
||||||
|
import { AddonModFeedbackShowNonRespondentsLinkHandler } from './providers/show-non-respondents-link-handler';
|
||||||
import { AddonModFeedbackHelperProvider } from './providers/helper';
|
import { AddonModFeedbackHelperProvider } from './providers/helper';
|
||||||
import { AddonModFeedbackPrefetchHandler } from './providers/prefetch-handler';
|
import { AddonModFeedbackPrefetchHandler } from './providers/prefetch-handler';
|
||||||
import { AddonModFeedbackSyncProvider } from './providers/sync';
|
import { AddonModFeedbackSyncProvider } from './providers/sync';
|
||||||
|
@ -39,6 +42,9 @@ import { AddonModFeedbackOfflineProvider } from './providers/offline';
|
||||||
AddonModFeedbackPrefetchHandler,
|
AddonModFeedbackPrefetchHandler,
|
||||||
AddonModFeedbackHelperProvider,
|
AddonModFeedbackHelperProvider,
|
||||||
AddonModFeedbackLinkHandler,
|
AddonModFeedbackLinkHandler,
|
||||||
|
AddonModFeedbackAnalysisLinkHandler,
|
||||||
|
AddonModFeedbackShowEntriesLinkHandler,
|
||||||
|
AddonModFeedbackShowNonRespondentsLinkHandler,
|
||||||
AddonModFeedbackSyncCronHandler,
|
AddonModFeedbackSyncCronHandler,
|
||||||
AddonModFeedbackSyncProvider,
|
AddonModFeedbackSyncProvider,
|
||||||
AddonModFeedbackOfflineProvider
|
AddonModFeedbackOfflineProvider
|
||||||
|
@ -48,10 +54,16 @@ export class AddonModFeedbackModule {
|
||||||
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModFeedbackModuleHandler,
|
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModFeedbackModuleHandler,
|
||||||
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModFeedbackPrefetchHandler,
|
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModFeedbackPrefetchHandler,
|
||||||
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModFeedbackLinkHandler,
|
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModFeedbackLinkHandler,
|
||||||
cronDelegate: CoreCronDelegate, syncHandler: AddonModFeedbackSyncCronHandler) {
|
cronDelegate: CoreCronDelegate, syncHandler: AddonModFeedbackSyncCronHandler,
|
||||||
|
analysisLinkHandler: AddonModFeedbackAnalysisLinkHandler,
|
||||||
|
showEntriesLinkHandler: AddonModFeedbackShowEntriesLinkHandler,
|
||||||
|
showNonRespondentsLinkHandler: AddonModFeedbackShowNonRespondentsLinkHandler) {
|
||||||
moduleDelegate.registerHandler(moduleHandler);
|
moduleDelegate.registerHandler(moduleHandler);
|
||||||
prefetchDelegate.registerHandler(prefetchHandler);
|
prefetchDelegate.registerHandler(prefetchHandler);
|
||||||
contentLinksDelegate.registerHandler(linkHandler);
|
contentLinksDelegate.registerHandler(linkHandler);
|
||||||
|
contentLinksDelegate.registerHandler(analysisLinkHandler);
|
||||||
|
contentLinksDelegate.registerHandler(showEntriesLinkHandler);
|
||||||
|
contentLinksDelegate.registerHandler(showNonRespondentsLinkHandler);
|
||||||
cronDelegate.register(syncHandler);
|
cronDelegate.register(syncHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ export class AddonModFeedbackRespondentsPage {
|
||||||
gotoAttempt(attempt: any): void {
|
gotoAttempt(attempt: any): void {
|
||||||
this.attemptId = attempt.id;
|
this.attemptId = attempt.id;
|
||||||
this.splitviewCtrl.push('AddonModFeedbackAttemptPage', {
|
this.splitviewCtrl.push('AddonModFeedbackAttemptPage', {
|
||||||
attemptid: attempt.id,
|
attemptId: attempt.id,
|
||||||
attempt: attempt,
|
attempt: attempt,
|
||||||
feedbackId: this.feedbackId,
|
feedbackId: this.feedbackId,
|
||||||
moduleId: this.moduleId
|
moduleId: this.moduleId
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
// (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 { Injectable } from '@angular/core';
|
||||||
|
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||||
|
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||||
|
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||||
|
import { AddonModFeedbackProvider } from './feedback';
|
||||||
|
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||||
|
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content links handler for a feedback analysis.
|
||||||
|
* Match mod/feedback/analysis.php with a valid feedback id.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class AddonModFeedbackAnalysisLinkHandler extends CoreContentLinksHandlerBase {
|
||||||
|
name = 'AddonModFeedbackAnalysisLinkHandler';
|
||||||
|
featureName = '$mmCourseDelegate_mmaModFeedback';
|
||||||
|
pattern = /\/mod\/feedback\/analysis\.php.*([\&\?]id=\d+)/;
|
||||||
|
|
||||||
|
constructor(private linkHelper: CoreContentLinksHelperProvider, private feedbackProvider: AddonModFeedbackProvider,
|
||||||
|
private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of actions for a link (url).
|
||||||
|
*
|
||||||
|
* @param {string[]} siteIds List of sites the URL belongs to.
|
||||||
|
* @param {string} url The URL to treat.
|
||||||
|
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||||
|
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||||
|
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
|
||||||
|
*/
|
||||||
|
getActions(siteIds: string[], url: string, params: any, courseId?: number):
|
||||||
|
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||||
|
return [{
|
||||||
|
action: (siteId, navCtrl?): void => {
|
||||||
|
const modal = this.domUtils.showModalLoading(),
|
||||||
|
moduleId = params.id;
|
||||||
|
|
||||||
|
this.courseProvider.getModuleBasicInfo(moduleId, siteId).then((module) => {
|
||||||
|
const stateParams = {
|
||||||
|
module: module,
|
||||||
|
courseId: module.course,
|
||||||
|
tab: 'analysis'
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.linkHelper.goInSite(navCtrl, 'AddonModFeedbackIndexPage', stateParams, siteId);
|
||||||
|
}).finally(() => {
|
||||||
|
modal.dismiss();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||||
|
* If not defined, defaults to true.
|
||||||
|
*
|
||||||
|
* @param {string} siteId The site ID.
|
||||||
|
* @param {string} url The URL to treat.
|
||||||
|
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||||
|
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||||
|
* @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site.
|
||||||
|
*/
|
||||||
|
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
|
||||||
|
return this.feedbackProvider.isPluginEnabled(siteId).then((enabled) => {
|
||||||
|
if (!enabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof params.id == 'undefined') {
|
||||||
|
// Cannot treat the URL.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -80,6 +80,64 @@ export class AddonModFeedbackProvider {
|
||||||
return this.getFeedbackDataPrefixCacheKey(feedbackId) + ':analysis:';
|
return this.getFeedbackDataPrefixCacheKey(feedbackId) + ':analysis:';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find an attempt in all responses analysis.
|
||||||
|
*
|
||||||
|
* @param {number} feedbackId Feedback ID.
|
||||||
|
* @param {number} attemptId Attempt id to find.
|
||||||
|
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||||
|
* @param {any} [previous] Only for recurrent use. Object with the previous fetched info.
|
||||||
|
* @return {Promise<any>} Promise resolved when the info is retrieved.
|
||||||
|
*/
|
||||||
|
getAttempt(feedbackId: number, attemptId: number, siteId?: string, previous?: any): Promise<any> {
|
||||||
|
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
||||||
|
if (typeof previous == 'undefined') {
|
||||||
|
previous = {
|
||||||
|
page: 0,
|
||||||
|
attemptsLoaded: 0,
|
||||||
|
anonAttemptsLoaded: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.getResponsesAnalysis(feedbackId, 0, previous.page, siteId).then((responses) => {
|
||||||
|
let attempt;
|
||||||
|
|
||||||
|
attempt = responses.attempts.find((attempt) => {
|
||||||
|
return attemptId == attempt.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (attempt) {
|
||||||
|
return attempt;
|
||||||
|
}
|
||||||
|
|
||||||
|
attempt = responses.anonattempts.find((attempt) => {
|
||||||
|
return attemptId == attempt.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (attempt) {
|
||||||
|
return attempt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previous.anonAttemptsLoaded < responses.totalanonattempts) {
|
||||||
|
previous.anonAttemptsLoaded += responses.anonattempts.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previous.attemptsLoaded < responses.totalattempts) {
|
||||||
|
previous.attemptsLoaded += responses.attempts.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previous.anonAttemptsLoaded < responses.totalanonattempts || previous.attemptsLoaded < responses.totalattempts) {
|
||||||
|
// Can load more. Check there.
|
||||||
|
previous.page++;
|
||||||
|
|
||||||
|
return this.getAttempt(feedbackId, attemptId, siteId, previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not found and all loaded. Reject.
|
||||||
|
return Promise.reject(null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get prefix cache key for feedback completion data WS calls.
|
* Get prefix cache key for feedback completion data WS calls.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
// (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 { Injectable } from '@angular/core';
|
||||||
|
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||||
|
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||||
|
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||||
|
import { AddonModFeedbackProvider } from './feedback';
|
||||||
|
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||||
|
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content links handler for feedback show entries questions.
|
||||||
|
* Match mod/feedback/show_entries.php with a valid feedback id.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class AddonModFeedbackShowEntriesLinkHandler extends CoreContentLinksHandlerBase {
|
||||||
|
name = 'AddonModFeedbackShowEntriesLinkHandler';
|
||||||
|
featureName = '$mmCourseDelegate_mmaModFeedback';
|
||||||
|
pattern = /\/mod\/feedback\/show_entries\.php.*([\?\&](id|showcompleted)=\d+)/;
|
||||||
|
|
||||||
|
constructor(private linkHelper: CoreContentLinksHelperProvider, private feedbackProvider: AddonModFeedbackProvider,
|
||||||
|
private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of actions for a link (url).
|
||||||
|
*
|
||||||
|
* @param {string[]} siteIds List of sites the URL belongs to.
|
||||||
|
* @param {string} url The URL to treat.
|
||||||
|
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||||
|
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||||
|
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
|
||||||
|
*/
|
||||||
|
getActions(siteIds: string[], url: string, params: any, courseId?: number):
|
||||||
|
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||||
|
return [{
|
||||||
|
action: (siteId, navCtrl?): void => {
|
||||||
|
const modal = this.domUtils.showModalLoading(),
|
||||||
|
moduleId = params.id;
|
||||||
|
|
||||||
|
this.courseProvider.getModuleBasicInfo(moduleId, siteId).then((module) => {
|
||||||
|
let stateParams;
|
||||||
|
|
||||||
|
if (typeof params.showcompleted == 'undefined') {
|
||||||
|
// Param showcompleted not defined. Show entry list.
|
||||||
|
stateParams = {
|
||||||
|
moduleId: module.id,
|
||||||
|
module: module,
|
||||||
|
courseId: module.course
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.linkHelper.goInSite(navCtrl, 'AddonModFeedbackRespondentsPage', stateParams, siteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.feedbackProvider.getAttempt(module.instance, params.showcompleted, siteId).then((attempt) => {
|
||||||
|
stateParams = {
|
||||||
|
moduleId: module.id,
|
||||||
|
attempt: attempt,
|
||||||
|
attemptId: attempt.id,
|
||||||
|
feedbackId: module.instance
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.linkHelper.goInSite(navCtrl, 'AddonModFeedbackAttemptPage', stateParams, siteId);
|
||||||
|
});
|
||||||
|
}).finally(() => {
|
||||||
|
modal.dismiss();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||||
|
* If not defined, defaults to true.
|
||||||
|
*
|
||||||
|
* @param {string} siteId The site ID.
|
||||||
|
* @param {string} url The URL to treat.
|
||||||
|
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||||
|
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||||
|
* @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site.
|
||||||
|
*/
|
||||||
|
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
|
||||||
|
return this.feedbackProvider.isPluginEnabled(siteId).then((enabled) => {
|
||||||
|
if (!enabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof params.id == 'undefined') {
|
||||||
|
// Cannot treat the URL.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
// (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 { Injectable } from '@angular/core';
|
||||||
|
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||||
|
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||||
|
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||||
|
import { AddonModFeedbackProvider } from './feedback';
|
||||||
|
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||||
|
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content links handler for feedback show non respondents.
|
||||||
|
* Match mod/feedback/show_nonrespondents.php with a valid feedback id.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class AddonModFeedbackShowNonRespondentsLinkHandler extends CoreContentLinksHandlerBase {
|
||||||
|
name = 'AddonModFeedbackShowNonRespondentsLinkHandler';
|
||||||
|
featureName = '$mmCourseDelegate_mmaModFeedback';
|
||||||
|
pattern = /\/mod\/feedback\/show_nonrespondents\.php.*([\?\&](id)=\d+)/;
|
||||||
|
|
||||||
|
constructor(private linkHelper: CoreContentLinksHelperProvider, private feedbackProvider: AddonModFeedbackProvider,
|
||||||
|
private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of actions for a link (url).
|
||||||
|
*
|
||||||
|
* @param {string[]} siteIds List of sites the URL belongs to.
|
||||||
|
* @param {string} url The URL to treat.
|
||||||
|
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||||
|
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||||
|
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
|
||||||
|
*/
|
||||||
|
getActions(siteIds: string[], url: string, params: any, courseId?: number):
|
||||||
|
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||||
|
return [{
|
||||||
|
action: (siteId, navCtrl?): void => {
|
||||||
|
const modal = this.domUtils.showModalLoading(),
|
||||||
|
moduleId = params.id;
|
||||||
|
|
||||||
|
this.courseProvider.getModuleBasicInfo(moduleId, siteId).then((module) => {
|
||||||
|
const stateParams = {
|
||||||
|
module: module,
|
||||||
|
moduleId: module.id,
|
||||||
|
courseId: module.course
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.linkHelper.goInSite(navCtrl, 'AddonModFeedbackNonRespondentsPage', stateParams, siteId);
|
||||||
|
}).finally(() => {
|
||||||
|
modal.dismiss();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||||
|
* If not defined, defaults to true.
|
||||||
|
*
|
||||||
|
* @param {string} siteId The site ID.
|
||||||
|
* @param {string} url The URL to treat.
|
||||||
|
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||||
|
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||||
|
* @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site.
|
||||||
|
*/
|
||||||
|
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
|
||||||
|
return this.feedbackProvider.isPluginEnabled(siteId).then((enabled) => {
|
||||||
|
if (!enabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof params.id == 'undefined') {
|
||||||
|
// Cannot treat the URL.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue