MOBILE-3394 mod: Add event when user activity is sent

main
Pau Ferrer Ocaña 2020-04-27 14:42:47 +02:00
parent f3e5c21b6e
commit 02f3214332
14 changed files with 50 additions and 8 deletions

View File

@ -317,6 +317,10 @@ export class AddonModAssignEditPage implements OnInit, OnDestroy {
// Clear temporary data from plugins.
await this.assignHelper.clearSubmissionPluginTmpData(this.assign, this.userSubmission, inputData);
if (sent) {
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'assign' });
}
// Submission saved, trigger events.
this.domUtils.triggerFormSubmittedEvent(this.formElement, sent, this.sitesProvider.getCurrentSiteId());

View File

@ -117,6 +117,7 @@ export class AddonModChatChatPage {
* Runs when the page is about to leave and no longer be the active page.
*/
ionViewWillLeave(): void {
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'chat' });
this.stopPolling();
}

View File

@ -14,6 +14,7 @@
import { Component, Optional, Injector } from '@angular/core';
import { Content } from 'ionic-angular';
import { CoreEvents, CoreEventsProvider } from '@providers/events';
import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { CoreCourseModuleMainActivityComponent } from '@core/course/classes/main-activity-component';
import { AddonModChoiceProvider, AddonModChoiceChoice, AddonModChoiceOption, AddonModChoiceResult } from '../../providers/choice';
@ -51,9 +52,14 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo
protected hasAnsweredOnline = false;
protected now: number;
constructor(injector: Injector, private choiceProvider: AddonModChoiceProvider, @Optional() content: Content,
private choiceOffline: AddonModChoiceOfflineProvider, private choiceSync: AddonModChoiceSyncProvider,
private timeUtils: CoreTimeUtilsProvider) {
constructor(
injector: Injector,
protected choiceProvider: AddonModChoiceProvider,
@Optional() content: Content,
protected choiceOffline: AddonModChoiceOfflineProvider,
protected choiceSync: AddonModChoiceSyncProvider,
protected timeUtils: CoreTimeUtilsProvider,
) {
super(injector, content);
}
@ -359,6 +365,10 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo
this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata);
this.domUtils.scrollToTop(this.content);
if (online) {
CoreEvents.instance.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: this.moduleName });
}
return this.dataUpdated(online);
}).catch((message) => {
this.domUtils.showErrorModalDefault(message, 'addon.mod_choice.cannotsubmit', true);

View File

@ -217,6 +217,10 @@ export class AddonModDataEditPage {
this.domUtils.triggerFormSubmittedEvent(this.formElement, result.sent, this.siteId);
if (result.sent) {
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'data' });
}
const promises = [];
this.entryId = this.entryId || result.newentryid;

View File

@ -280,6 +280,8 @@ export class AddonModFeedbackFormPage implements OnDestroy {
promises.push(this.feedbackProvider.invalidateFeedbackAccessInformationData(this.feedback.id));
promises.push(this.feedbackProvider.invalidateResumePageData(this.feedback.id));
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'feedback' });
return Promise.all(promises).then(() => {
return this.fetchAccessData();
});

View File

@ -473,6 +473,8 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
if (discussionIds) {
// Data sent to server, delete stored files (if any).
this.forumHelper.deleteNewDiscussionStoredFiles(this.forumId, discTimecreated);
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'forum' });
}
if (discussionIds && discussionIds.length < groupIds.length) {

View File

@ -246,6 +246,7 @@ export class AddonModGlossaryEditPage implements OnInit {
if (entryId) {
// Data sent to server, delete stored files (if any).
this.glossaryHelper.deleteStoredFiles(this.glossary.id, this.entry.concept, timecreated);
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'glossary' });
}
const data = {

View File

@ -18,7 +18,6 @@ import { IonicPage, NavParams, Content, PopoverController, ModalController, Moda
import { TranslateService } from '@ngx-translate/core';
import { CoreAppProvider } from '@providers/app';
import { CoreEventsProvider } from '@providers/events';
import { CoreLoggerProvider } from '@providers/logger';
import { CoreSitesProvider } from '@providers/sites';
import { CoreSyncProvider } from '@providers/sync';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
@ -80,7 +79,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy {
protected loadingMenu: boolean; // Whether the lesson menu is being loaded.
protected lessonPages: any[]; // Lesson pages (for the lesson menu).
constructor(protected navParams: NavParams, logger: CoreLoggerProvider, protected translate: TranslateService,
constructor(protected navParams: NavParams, protected translate: TranslateService,
protected eventsProvider: CoreEventsProvider, protected sitesProvider: CoreSitesProvider,
protected syncProvider: CoreSyncProvider, protected domUtils: CoreDomUtilsProvider, popoverCtrl: PopoverController,
protected timeUtils: CoreTimeUtilsProvider, protected lessonProvider: AddonModLessonProvider,
@ -369,6 +368,8 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy {
this.messages = this.messages.concat(data.messages);
this.processData = undefined;
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'lesson' });
// Format activity link if present.
if (this.eolData && this.eolData.activitylink) {
this.eolData.activitylink.value = this.lessonHelper.formatActivityLink(this.eolData.activitylink.value);

View File

@ -376,6 +376,8 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy {
synced: !this.offline
}, this.sitesProvider.getCurrentSiteId());
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'quiz' });
// Leave the player.
this.forceLeave = true;
this.navCtrl.pop();

View File

@ -310,6 +310,8 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy {
* Page will leave.
*/
ionViewWillUnload(): void {
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'scorm' });
// Empty src when leaving the state so unload event is triggered in the iframe.
this.src = '';
}

View File

@ -15,6 +15,7 @@
import { Component, Optional, Injector } from '@angular/core';
import { Content } from 'ionic-angular';
import { CoreCourseModuleMainActivityComponent } from '@core/course/classes/main-activity-component';
import { CoreEvents, CoreEventsProvider } from '@providers/events';
import { AddonModSurveyProvider, AddonModSurveySurvey } from '../../providers/survey';
import { AddonModSurveyHelperProvider, AddonModSurveyQuestionFormatted } from '../../providers/helper';
import { AddonModSurveyOfflineProvider } from '../../providers/offline';
@ -38,9 +39,14 @@ export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityCo
protected userId: number;
protected syncEventName = AddonModSurveySyncProvider.AUTO_SYNCED;
constructor(injector: Injector, private surveyProvider: AddonModSurveyProvider, @Optional() content: Content,
private surveyHelper: AddonModSurveyHelperProvider, private surveyOffline: AddonModSurveyOfflineProvider,
private surveySync: AddonModSurveySyncProvider) {
constructor(
injector: Injector,
protected surveyProvider: AddonModSurveyProvider,
@Optional() content: Content,
protected surveyHelper: AddonModSurveyHelperProvider,
protected surveyOffline: AddonModSurveyOfflineProvider,
protected surveySync: AddonModSurveySyncProvider,
) {
super(injector, content);
}
@ -185,6 +191,8 @@ export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityCo
}
return this.surveyProvider.submitAnswers(this.survey.id, this.survey.name, this.courseId, answers).then((online) => {
CoreEvents.instance.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: this.moduleName });
if (online && this.isPrefetched()) {
// The survey is downloaded, update the data.
return this.surveySync.prefetchAfterUpdate(this.module, this.courseId).then(() => {

View File

@ -465,6 +465,8 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy {
this.domUtils.triggerFormSubmittedEvent(this.formElement, id > 0, this.sitesProvider.getCurrentSiteId());
if (id > 0) {
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'wiki' });
// Page was created, get its data and go to the page.
this.pageId = id;

View File

@ -388,6 +388,8 @@ export class AddonModWorkshopEditSubmissionPage implements OnInit, OnDestroy {
data['submissionId'] = newSubmissionId;
}
this.eventsProvider.trigger(CoreEventsProvider.ACTIVITY_DATA_SENT, { module: 'workshop' });
const promise = newSubmissionId ? this.workshopProvider.invalidateSubmissionData(this.workshopId, newSubmissionId) :
Promise.resolve();

View File

@ -67,6 +67,7 @@ export class CoreEventsProvider {
static WS_CACHE_INVALIDATED = 'ws_cache_invalidated';
static SITE_STORAGE_DELETED = 'site_storage_deleted';
static FORM_ACTION = 'form_action';
static ACTIVITY_DATA_SENT = 'activity_data_sent';
protected logger;
protected observables: { [s: string]: Subject<any> } = {};