MOBILE-2351 survey: Fix PR problems

main
Pau Ferrer Ocaña 2018-03-22 15:17:12 +01:00
parent 978f69ea50
commit 5f107f604b
12 changed files with 74 additions and 100 deletions

View File

@ -12,14 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component, Optional } from '@angular/core';
import { Component, Optional, Injector } from '@angular/core';
import { Content, PopoverController } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
import { CoreAppProvider } from '@providers/app';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { CoreCourseModuleMainResourceComponent } from '@core/course/classes/main-resource-component';
import { AddonModBookProvider, AddonModBookContentsMap, AddonModBookTocChapter } from '../../providers/book';
import { AddonModBookPrefetchHandler } from '../../providers/prefetch-handler';
@ -42,12 +38,10 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
protected currentChapter: string;
protected contentsMap: AddonModBookContentsMap;
constructor(private bookProvider: AddonModBookProvider, private courseProvider: CoreCourseProvider,
protected domUtils: CoreDomUtilsProvider, private appProvider: CoreAppProvider,
protected textUtils: CoreTextUtilsProvider, protected courseHelper: CoreCourseHelperProvider,
private prefetchDelegate: AddonModBookPrefetchHandler, private popoverCtrl: PopoverController,
protected translate: TranslateService, @Optional() private content: Content) {
super(textUtils, courseHelper, translate, domUtils);
constructor(injector: Injector, private bookProvider: AddonModBookProvider, private courseProvider: CoreCourseProvider,
private appProvider: CoreAppProvider, private prefetchDelegate: AddonModBookPrefetchHandler,
private popoverCtrl: PopoverController, @Optional() private content: Content) {
super(injector);
}
/**

View File

@ -12,13 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component, Input } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Component, Input, Injector } from '@angular/core';
import { CoreAppProvider } from '@providers/app';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { CoreCourseModuleMainResourceComponent } from '@core/course/classes/main-resource-component';
import { AddonModFolderProvider } from '../../providers/folder';
import { AddonModFolderHelperProvider } from '../../providers/helper';
@ -39,11 +35,9 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
canGetFolder: boolean;
contents: any;
constructor(private folderProvider: AddonModFolderProvider, private courseProvider: CoreCourseProvider,
protected domUtils: CoreDomUtilsProvider, private appProvider: CoreAppProvider,
protected textUtils: CoreTextUtilsProvider, protected courseHelper: CoreCourseHelperProvider,
protected translate: TranslateService, private folderHelper: AddonModFolderHelperProvider) {
super(textUtils, courseHelper, translate, domUtils);
constructor(injector: Injector, private folderProvider: AddonModFolderProvider, private courseProvider: CoreCourseProvider,
private appProvider: CoreAppProvider, private folderHelper: AddonModFolderHelperProvider) {
super(injector);
}
/**

View File

@ -12,13 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Component, Injector } from '@angular/core';
import { CoreAppProvider } from '@providers/app';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { CoreCourseModuleMainResourceComponent } from '@core/course/classes/main-resource-component';
import { AddonModPageProvider } from '../../providers/page';
import { AddonModPageHelperProvider } from '../../providers/helper';
@ -37,12 +33,10 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp
contents: any;
protected fetchContentDefaultError = 'addon.mod_page.errorwhileloadingthepage';
constructor(private pageProvider: AddonModPageProvider, private courseProvider: CoreCourseProvider,
protected domUtils: CoreDomUtilsProvider, private appProvider: CoreAppProvider,
protected textUtils: CoreTextUtilsProvider, protected courseHelper: CoreCourseHelperProvider,
protected translate: TranslateService, private pageHelper: AddonModPageHelperProvider,
constructor(injector: Injector, private pageProvider: AddonModPageProvider, private courseProvider: CoreCourseProvider,
private appProvider: CoreAppProvider, private pageHelper: AddonModPageHelperProvider,
private pagePrefetch: AddonModPagePrefetchHandler) {
super(textUtils, courseHelper, translate, domUtils);
super(injector);
}
/**

View File

@ -12,13 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Component, Injector } from '@angular/core';
import { CoreAppProvider } from '@providers/app';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { CoreCourseModuleMainResourceComponent } from '@core/course/classes/main-resource-component';
import { AddonModResourceProvider } from '../../providers/resource';
import { AddonModResourcePrefetchHandler } from '../../providers/prefetch-handler';
@ -39,12 +35,10 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
src: string;
contentText: string;
constructor(private resourceProvider: AddonModResourceProvider, private courseProvider: CoreCourseProvider,
protected domUtils: CoreDomUtilsProvider, private appProvider: CoreAppProvider,
protected textUtils: CoreTextUtilsProvider, protected courseHelper: CoreCourseHelperProvider,
protected translate: TranslateService, private prefetchHandler: AddonModResourcePrefetchHandler,
constructor(injector: Injector, private resourceProvider: AddonModResourceProvider, private courseProvider: CoreCourseProvider,
private appProvider: CoreAppProvider, private prefetchHandler: AddonModResourcePrefetchHandler,
private resourceHelper: AddonModResourceHelperProvider) {
super(textUtils, courseHelper, translate, domUtils);
super(injector);
}
/**

View File

@ -13,7 +13,7 @@
<!-- Content. -->
<core-loading [hideUntil]="loaded" class="core-loading-center">
<core-course-module-description *ngIf="mode != 'iframe'" [description]="description" [component]="component" [componentId]="componentId"></core-course-module-description>
<core-course-module-description [description]="description" [component]="component" [componentId]="componentId"></core-course-module-description>
<!-- Survey already done -->
<ion-card padding *ngIf="survey && survey.surveydone">

View File

@ -12,17 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component, Optional } from '@angular/core';
import { Component, Optional, Injector } from '@angular/core';
import { Content } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
import { Network } from '@ionic-native/network';
import { CoreAppProvider } from '@providers/app';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreSitesProvider } from '@providers/sites';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreEventsProvider } from '@providers/events';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { CoreCourseModuleMainActivityComponent } from '@core/course/classes/main-activity-component';
import { AddonModSurveyProvider } from '../../providers/survey';
import { AddonModSurveyHelperProvider } from '../../providers/helper';
@ -47,14 +38,10 @@ export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityCo
protected userId: number;
protected syncEventName = AddonModSurveySyncProvider.AUTO_SYNCED;
constructor(private surveyProvider: AddonModSurveyProvider, protected courseProvider: CoreCourseProvider,
protected domUtils: CoreDomUtilsProvider, protected appProvider: CoreAppProvider,
protected courseHelper: CoreCourseHelperProvider, protected translate: TranslateService, network: Network,
private surveyHelper: AddonModSurveyHelperProvider, protected sitesProvider: CoreSitesProvider,
protected eventsProvider: CoreEventsProvider, private surveyOffline: AddonModSurveyOfflineProvider,
private surveySync: AddonModSurveySyncProvider, @Optional() private content: Content,
protected textUtils: CoreTextUtilsProvider) {
super(textUtils, courseHelper, translate, domUtils, sitesProvider, courseProvider, network, appProvider, eventsProvider);
constructor(injector: Injector, private surveyProvider: AddonModSurveyProvider, @Optional() private content: Content,
private surveyHelper: AddonModSurveyHelperProvider, private surveyOffline: AddonModSurveyOfflineProvider,
private surveySync: AddonModSurveySyncProvider) {
super(injector);
}
/**

View File

@ -26,10 +26,10 @@ export class AddonModSurveyHelperProvider {
/**
* Turns a string with values separated by commas into an array.
*
* @param {string} value Value to convert.
* @param {any} value Value to convert.
* @return {string[]} Array.
*/
protected commaStringToArray(value: string): string[] {
protected commaStringToArray(value: any): string[] {
if (typeof value == 'string') {
if (value.length > 0) {
return value.split(',');

View File

@ -26,7 +26,7 @@ export class AddonModSurveyOfflineProvider {
protected logger;
// Variables for database.
protected SURVEY_TABLE = 'mma_mod_survey_answers';
protected SURVEY_TABLE = 'addon_mod_survey_answers';
protected tablesSchema = [
{
name: this.SURVEY_TABLE,
@ -171,7 +171,7 @@ export class AddonModSurveyOfflineProvider {
timecreated: new Date().getTime()
};
return site.getDb().insertOrUpdateRecord(this.SURVEY_TABLE, entry, {surveyid: surveyId, userid: userId});
return site.getDb().insertRecord(this.SURVEY_TABLE, entry);
});
}
}

View File

@ -155,7 +155,7 @@ export class AddonModSurveyProvider {
promises.push(this.getSurvey(courseId, moduleId).then((survey) => {
const ps = [];
// Do not invalidate wiki data before getting wiki info, we need it!
// Do not invalidate activity data before getting activity info, we need it!
ps.push(this.invalidateSurveyData(courseId, siteId));
ps.push(this.invalidateQuestions(survey.id, siteId));
@ -268,7 +268,6 @@ export class AddonModSurveyProvider {
return site.write('mod_survey_submit_answers', params).then((response) => {
if (!response.status) {
// There was an error, and it should be translated already.
return this.utils.createFakeWSError('');
}
});

View File

@ -12,15 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { Component, Injector } from '@angular/core';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseModuleMainResourceComponent } from '@core/course/classes/main-resource-component';
import { AddonModUrlProvider } from '../../providers/url';
import { AddonModUrlHelperProvider } from '../../providers/helper';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
/**
* Component that displays a url.
@ -35,11 +31,9 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo
canGetUrl: boolean;
url: string;
constructor(private urlProvider: AddonModUrlProvider, private courseProvider: CoreCourseProvider,
protected domUtils: CoreDomUtilsProvider, protected textUtils: CoreTextUtilsProvider,
protected translate: TranslateService, private urlHelper: AddonModUrlHelperProvider,
protected courseHelper: CoreCourseHelperProvider) {
super(textUtils, courseHelper, translate, domUtils);
constructor(injector: Injector, private urlProvider: AddonModUrlProvider, private courseProvider: CoreCourseProvider,
private urlHelper: AddonModUrlHelperProvider) {
super(injector);
}
/**

View File

@ -12,10 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { TranslateService } from '@ngx-translate/core';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { Injector } from '@angular/core';
import { CoreSitesProvider } from '@providers/sites';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreEventsProvider } from '@providers/events';
@ -39,11 +36,22 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
protected onlineObserver: any; // It will observe the status of the network connection.
protected syncEventName: string; // Auto sync event name.
constructor(protected textUtils: CoreTextUtilsProvider, protected courseHelper: CoreCourseHelperProvider,
protected translate: TranslateService, protected domUtils: CoreDomUtilsProvider,
protected sitesProvider: CoreSitesProvider, protected courseProvider: CoreCourseProvider, network: Network,
protected appProvider: CoreAppProvider, protected eventsProvider: CoreEventsProvider) {
super(textUtils, courseHelper, translate, domUtils);
// List of services that will be injected using injector.
// It's done like this so subclasses don't have to send all the services to the parent in the constructor.
protected sitesProvider: CoreSitesProvider;
protected courseProvider: CoreCourseProvider;
protected appProvider: CoreAppProvider;
protected eventsProvider: CoreEventsProvider;
constructor(injector: Injector) {
super(injector);
this.sitesProvider = injector.get(CoreSitesProvider);
this.courseProvider = injector.get(CoreCourseProvider);
this.appProvider = injector.get(CoreAppProvider);
this.eventsProvider = injector.get(CoreEventsProvider);
const network = injector.get(Network);
// Refresh online status when changes.
this.onlineObserver = network.onchange().subscribe((online) => {
@ -57,6 +65,11 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
ngOnInit(): void {
super.ngOnInit();
this.hasOffline = false;
this.syncIcon = 'spinner';
this.siteId = this.sitesProvider.getCurrentSiteId();
this.moduleName = this.courseProvider.translateModuleName(this.moduleName);
if (this.syncEventName) {
// Refresh data if this discussion is synchronized automatically.
this.syncObserver = this.eventsProvider.on(this.syncEventName, (data) => {
@ -66,11 +79,6 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
}
}, this.siteId);
}
this.hasOffline = false;
this.syncIcon = 'spinner';
this.siteId = this.sitesProvider.getCurrentSiteId();
this.moduleName = this.courseProvider.translateModuleName(this.moduleName);
}
/**
@ -100,7 +108,7 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
/**
* Compares sync event data with current data to check if refresh content is needed.
*
* @param {any} syncEventData Data receiven on sync observer.
* @param {any} syncEventData Data received on sync observer.
* @return {boolean} True if refresh is needed, false otherwise.
*/
protected isRefreshSyncNeeded(syncEventData: any): boolean {
@ -110,8 +118,8 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
/**
* Perform the refresh content function.
*
* @param {boolean} [sync=false] If the refresh is needs syncing.
* @param {boolean} [showErrors=false] If show errors to the user of hide them.
* @param {boolean} [sync=false] If the refresh needs syncing.
* @param {boolean} [showErrors=false] Wether to show errors to the user or hide them.
* @return {Promise<any>} Resolved when done.
*/
protected refreshContent(sync: boolean = false, showErrors: boolean = false): Promise<any> {
@ -126,8 +134,8 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
* Download the component contents.
*
* @param {boolean} [refresh=false] Whether we're refreshing data.
* @param {boolean} [sync=false] If the refresh is needs syncing.
* @param {boolean} [showErrors=false] If show errors to the user of hide them.
* @param {boolean} [sync=false] If the refresh needs syncing.
* @param {boolean} [showErrors=false] Wether to show errors to the user or hide them.
* @return {Promise<any>} Promise resolved when done.
*/
protected fetchContent(refresh: boolean = false, sync: boolean = false, showErrors: boolean = false): Promise<any> {
@ -138,8 +146,8 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR
* Loads the component contents and shows the corresponding error.
*
* @param {boolean} [refresh=false] Whether we're refreshing data.
* @param {boolean} [sync=false] If the refresh is needs syncing.
* @param {boolean} [showErrors=false] If show errors to the user of hide them.
* @param {boolean} [sync=false] If the refresh needs syncing.
* @param {boolean} [showErrors=false] Wether to show errors to the user or hide them.
* @return {Promise<any>} Promise resolved when done.
*/
protected loadContent(refresh?: boolean, sync: boolean = false, showErrors: boolean = false): Promise<any> {

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core';
import { OnInit, OnDestroy, Input, Output, EventEmitter, Injector } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
@ -43,8 +43,18 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
protected statusObserver; // Observer of package status changed, used when calling fillContextMenu.
protected fetchContentDefaultError = 'core.course.errorgetmodule'; // Default error to show when loading contents.
constructor(protected textUtils: CoreTextUtilsProvider, protected courseHelper: CoreCourseHelperProvider,
protected translate: TranslateService, protected domUtils: CoreDomUtilsProvider) {
// List of services that will be injected using injector.
// It's done like this so subclasses don't have to send all the services to the parent in the constructor.
protected textUtils: CoreTextUtilsProvider;
protected courseHelper: CoreCourseHelperProvider;
protected translate: TranslateService;
protected domUtils: CoreDomUtilsProvider;
constructor(injector: Injector) {
this.textUtils = injector.get(CoreTextUtilsProvider);
this.courseHelper = injector.get(CoreCourseHelperProvider);
this.translate = injector.get(TranslateService);
this.domUtils = injector.get(CoreDomUtilsProvider);
this.dataRetrieved = new EventEmitter();
}