MOBILE-2339 feedback: Add form link handlers

main
Pau Ferrer Ocaña 2018-04-06 17:04:39 +02:00
parent d8d34a786a
commit 701d6f7774
10 changed files with 198 additions and 12 deletions

View File

@ -144,8 +144,8 @@
<ion-list *ngIf="items && items.length">
<ion-item text-wrap *ngFor="let item of items" class="core-analysis">
<h2>{{item.number}}. {{ item.name }}</h2>
<p>{{ item.label }}</p>
<h2>{{item.number}}. <core-format-text [component]="component" [componentId]="componentId" [text]="item.name"></core-format-text></h2>
<p><core-format-text [component]="component" [componentId]="componentId" [text]="item.label"></core-format-text></p>
<ng-container [ngSwitch]="item.template">
<ng-container *ngSwitchCase="'numeric'">
<ul>

View File

@ -24,6 +24,8 @@ 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 { AddonModFeedbackCompleteLinkHandler } from './providers/complete-link-handler';
import { AddonModFeedbackPrintLinkHandler } from './providers/print-link-handler';
import { AddonModFeedbackHelperProvider } from './providers/helper';
import { AddonModFeedbackPrefetchHandler } from './providers/prefetch-handler';
import { AddonModFeedbackSyncProvider } from './providers/sync';
@ -45,6 +47,8 @@ import { AddonModFeedbackOfflineProvider } from './providers/offline';
AddonModFeedbackAnalysisLinkHandler,
AddonModFeedbackShowEntriesLinkHandler,
AddonModFeedbackShowNonRespondentsLinkHandler,
AddonModFeedbackCompleteLinkHandler,
AddonModFeedbackPrintLinkHandler,
AddonModFeedbackSyncCronHandler,
AddonModFeedbackSyncProvider,
AddonModFeedbackOfflineProvider
@ -57,13 +61,17 @@ export class AddonModFeedbackModule {
cronDelegate: CoreCronDelegate, syncHandler: AddonModFeedbackSyncCronHandler,
analysisLinkHandler: AddonModFeedbackAnalysisLinkHandler,
showEntriesLinkHandler: AddonModFeedbackShowEntriesLinkHandler,
showNonRespondentsLinkHandler: AddonModFeedbackShowNonRespondentsLinkHandler) {
showNonRespondentsLinkHandler: AddonModFeedbackShowNonRespondentsLinkHandler,
completeLinkHandler: AddonModFeedbackCompleteLinkHandler,
printLinkHandler: AddonModFeedbackPrintLinkHandler) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
contentLinksDelegate.registerHandler(linkHandler);
contentLinksDelegate.registerHandler(analysisLinkHandler);
contentLinksDelegate.registerHandler(showEntriesLinkHandler);
contentLinksDelegate.registerHandler(showNonRespondentsLinkHandler);
contentLinksDelegate.registerHandler(completeLinkHandler);
contentLinksDelegate.registerHandler(printLinkHandler);
cronDelegate.register(syncHandler);
}
}

View File

@ -23,7 +23,7 @@
<ion-item-divider *ngIf="item.typ == 'pagebreak'" color="light"></ion-item-divider>
<ion-item text-wrap *ngIf="item.typ != 'pagebreak'" [color]="item.dependitem > 0 ? 'light' : ''">
<h2 *ngIf="item.name" [core-mark-required]="item.required">
<span *ngIf="item.itemnumber">{{item.itemnumber}}. </span>{{ item.name }}
<span *ngIf="item.itemnumber">{{item.itemnumber}}. </span><core-format-text [component]="component" [componentId]="componentId" [text]="item.name"></core-format-text>
</h2>
<p *ngIf="item.submittedValue"><core-format-text [component]="component" [componentId]="componentId" [text]=" item.submittedValue"></core-format-text></p>
</ion-item>

View File

@ -16,7 +16,8 @@
<ion-item-divider *ngIf="item.typ == 'pagebreak'" color="light"></ion-item-divider>
<ion-item text-wrap *ngIf="item.typ != 'pagebreak'" [color]="item.dependitem > 0 ? 'light' : ''" [class.core-danger-item]="item.isEmpty || item.hasError">
<ion-label *ngIf="item.name" [core-mark-required]="item.required" stacked>
<span *ngIf="item.itemnumber">{{item.itemnumber}}. </span>{{ item.name }}
<span *ngIf="item.itemnumber">{{item.itemnumber}}. </span>
<core-format-text [component]="component" [componentId]="componentId" [text]="item.name"></core-format-text>
</ion-label>
<div item-content class="addon-mod_feedback-form-content" *ngIf="item.template">
<ng-container [ngSwitch]="item.template">
@ -36,20 +37,20 @@
<ng-container *ngSwitchCase="'multichoice-r'">
<ion-list radio-group [(ngModel)]="item.value" [required]="item.required" name="{{item.typ}}_{{item.id}}">
<ion-item *ngFor="let option of item.choices">
<ion-label>{{option.label}}</ion-label>
<ion-label><core-format-text [component]="component" [componentId]="componentId" [text]="option.label"></core-format-text></ion-label>
<ion-radio [value]="option.value"></ion-radio>
</ion-item>
</ion-list>
</ng-container>
<ion-list *ngSwitchCase="'multichoice-c'">
<ion-item *ngFor="let option of item.choices">
<ion-label>{{option.label}}</ion-label>
<ion-label><core-format-text [component]="component" [componentId]="componentId" [text]="option.label"></core-format-text></ion-label>
<ion-checkbox [required]="item.required" name="{{item.typ}}_{{item.id}}" [(ngModel)]="option.checked" value="option.value"></ion-checkbox>
</ion-item>
</ion-list>
<ng-container *ngSwitchCase="'multichoice-d'">
<ion-select [required]="item.required" name="{{item.typ}}_{{item.id}}" [(ngModel)]="item.value">
<ion-option *ngFor="let option of item.choices" [value]="option.value">{{option.label}}</ion-option>
<ion-option *ngFor="let option of item.choices" [value]="option.value"><core-format-text [component]="component" [componentId]="componentId" [text]="option.label"></core-format-text></ion-option>
</ion-select>
</ng-container>
<ng-container *ngSwitchCase="'captcha'">

View File

@ -27,7 +27,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
@Injectable()
export class AddonModFeedbackAnalysisLinkHandler extends CoreContentLinksHandlerBase {
name = 'AddonModFeedbackAnalysisLinkHandler';
featureName = '$mmCourseDelegate_mmaModFeedback';
featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /\/mod\/feedback\/analysis\.php.*([\&\?]id=\d+)/;
constructor(private linkHelper: CoreContentLinksHelperProvider, private feedbackProvider: AddonModFeedbackProvider,

View File

@ -0,0 +1,89 @@
// (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 complete questions.
* Match mod/feedback/complete.php with a valid feedback id.
*/
@Injectable()
export class AddonModFeedbackCompleteLinkHandler extends CoreContentLinksHandlerBase {
name = 'AddonModFeedbackCompleteLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /\/mod\/feedback\/complete\.php.*([\?\&](id|gopage)=\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
};
if (typeof params.gopage == 'undefined') {
stateParams['page'] = parseInt(params.gopage, 10);
}
return this.linkHelper.goInSite(navCtrl, 'AddonModFeedbackFormPage', 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> {
if (typeof params.id == 'undefined') {
return false;
}
return this.feedbackProvider.isPluginEnabled(siteId);
}
}

View File

@ -24,7 +24,8 @@ import { AddonModFeedbackProvider } from './feedback';
*/
@Injectable()
export class AddonModFeedbackModuleHandler implements CoreCourseModuleHandler {
name = 'feedback';
name = 'AddonModFeedback';
modName = 'feedback';
constructor(private courseProvider: CoreCourseProvider, private feedbackProvider: AddonModFeedbackProvider) { }

View File

@ -0,0 +1,87 @@
// (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 print questions.
* Match mod/feedback/print.php with a valid feedback id.
*/
@Injectable()
export class AddonModFeedbackPrintLinkHandler extends CoreContentLinksHandlerBase {
name = 'AddonModFeedbackPrintLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /\/mod\/feedback\/print\.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,
preview: true
};
return this.linkHelper.goInSite(navCtrl, 'AddonModFeedbackFormPage', 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> {
if (typeof params.id == 'undefined') {
return false;
}
return this.feedbackProvider.isPluginEnabled(siteId);
}
}

View File

@ -27,7 +27,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
@Injectable()
export class AddonModFeedbackShowEntriesLinkHandler extends CoreContentLinksHandlerBase {
name = 'AddonModFeedbackShowEntriesLinkHandler';
featureName = '$mmCourseDelegate_mmaModFeedback';
featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /\/mod\/feedback\/show_entries\.php.*([\?\&](id|showcompleted)=\d+)/;
constructor(private linkHelper: CoreContentLinksHelperProvider, private feedbackProvider: AddonModFeedbackProvider,

View File

@ -27,7 +27,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
@Injectable()
export class AddonModFeedbackShowNonRespondentsLinkHandler extends CoreContentLinksHandlerBase {
name = 'AddonModFeedbackShowNonRespondentsLinkHandler';
featureName = '$mmCourseDelegate_mmaModFeedback';
featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /\/mod\/feedback\/show_nonrespondents\.php.*([\?\&](id)=\d+)/;
constructor(private linkHelper: CoreContentLinksHelperProvider, private feedbackProvider: AddonModFeedbackProvider,