diff --git a/src/addon/mod/workshop/components/index/index.ts b/src/addon/mod/workshop/components/index/index.ts
index ed7555163..4c626f1bd 100644
--- a/src/addon/mod/workshop/components/index/index.ts
+++ b/src/addon/mod/workshop/components/index/index.ts
@@ -67,6 +67,7 @@ export class AddonModWorkshopIndexComponent extends CoreCourseModuleMainActivity
protected obsSubmissionChanged: any;
protected obsAssessmentSaved: any;
protected appResumeSubscription: any;
+ protected syncObserver: any;
constructor(injector: Injector, private workshopProvider: AddonModWorkshopProvider, @Optional() content: Content,
private workshopOffline: AddonModWorkshopOfflineProvider, private groupsProvider: CoreGroupsProvider,
@@ -92,6 +93,12 @@ export class AddonModWorkshopIndexComponent extends CoreCourseModuleMainActivity
this.loaded = false;
this.refreshContent(true, false);
});
+
+ // Refresh workshop on sync.
+ this.syncObserver = this.eventsProvider.on(AddonModWorkshopSyncProvider.AUTO_SYNCED, (data) => {
+ // Update just when all database is synced.
+ this.eventReceived(data);
+ }, this.siteId);
}
/**
@@ -300,7 +307,7 @@ export class AddonModWorkshopIndexComponent extends CoreCourseModuleMainActivity
module: this.module,
access: this.access,
courseId: this.courseId,
- submission: this.submission
+ submissionId: this.submission && this.submission.id
};
this.navCtrl.push('AddonModWorkshopEditSubmissionPage', params);
diff --git a/src/addon/mod/workshop/lang/en.json b/src/addon/mod/workshop/lang/en.json
index 57243db4a..ff7cd8d55 100644
--- a/src/addon/mod/workshop/lang/en.json
+++ b/src/addon/mod/workshop/lang/en.json
@@ -42,6 +42,7 @@
"submissiongrade": "Grade for submission",
"submissiongradeof": "Grade for submission (of {{$a}})",
"submissionrequiredcontent": "You need to enter some text or add a file.",
+ "submissionrequiredtitle": "You need to enter a title.",
"submissionsreport": "Workshop submissions report",
"submissiontitle": "Title",
"switchphase10": "Switch to the setup phase",
diff --git a/src/addon/mod/workshop/pages/assessment/assessment.html b/src/addon/mod/workshop/pages/assessment/assessment.html
index 2a36c1cc9..704c9671a 100644
--- a/src/addon/mod/workshop/pages/assessment/assessment.html
+++ b/src/addon/mod/workshop/pages/assessment/assessment.html
@@ -20,14 +20,13 @@
{{profile.fullname}}
-
-
+
{{ 'addon.mod_workshop.submissiongradeof' | translate:{$a: workshop.grade } }}: {{assessment.grade}}
-
+
{{ 'addon.mod_workshop.gradinggradeof' | translate:{$a: workshop.gradinggrade } }}: {{assessment.gradinggrade}}
-
+
{{ 'addon.mod_workshop.gradinggradeover' | translate }}: {{assessment.gradinggradeover}}
@@ -38,7 +37,7 @@
-
+
-
+
diff --git a/src/addon/mod/workshop/pages/submission/submission.ts b/src/addon/mod/workshop/pages/submission/submission.ts
index d203dcec4..5e8b24bc4 100644
--- a/src/addon/mod/workshop/pages/submission/submission.ts
+++ b/src/addon/mod/workshop/pages/submission/submission.ts
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import { Component, OnInit, OnDestroy, Optional } from '@angular/core';
+import { Component, OnInit, OnDestroy, Optional, ViewChild } from '@angular/core';
import { Content, IonicPage, NavParams, NavController } from 'ionic-angular';
import { FormGroup, FormBuilder } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
@@ -24,6 +24,7 @@ import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreUserProvider } from '@core/user/providers/user';
import { CoreGradesHelperProvider } from '@core/grades/providers/helper';
+import { AddonModWorkshopAssessmentStrategyComponent } from '../../components/assessment-strategy/assessment-strategy';
import { AddonModWorkshopProvider } from '../../providers/workshop';
import { AddonModWorkshopHelperProvider } from '../../providers/helper';
import { AddonModWorkshopOfflineProvider } from '../../providers/offline';
@@ -39,6 +40,8 @@ import { AddonModWorkshopSyncProvider } from '../../providers/sync';
})
export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy {
+ @ViewChild(AddonModWorkshopAssessmentStrategyComponent) assessmentStrategy: AddonModWorkshopAssessmentStrategyComponent;
+
module: any;
workshop: any;
access: any;
@@ -69,7 +72,11 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy {
protected currentUserId: number;
protected userId: number;
protected siteId: string;
- protected originalEvaluation: any = {};
+ protected originalEvaluation = {
+ published: '',
+ text: '',
+ grade: ''
+ };
protected hasOffline = false;
protected component = AddonModWorkshopProvider.COMPONENT;
protected forceLeave = false;
@@ -89,7 +96,7 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy {
this.access = navParams.get('access');
this.courseId = navParams.get('courseId');
this.profile = navParams.get('profile');
- this.submissionInfo = navParams.get('submission');
+ this.submissionInfo = navParams.get('submission') || {};
this.assessment = navParams.get('assessment') || null;
this.title = this.module.name;
@@ -135,14 +142,11 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy {
* @return {boolean|Promise} Resolved if we can leave it, rejected if not.
*/
ionViewCanLeave(): boolean | Promise {
- if (this.forceLeave || !this.canAddFeedback) {
+ const assessmentHasChanged = this.assessmentStrategy && this.assessmentStrategy.hasDataChanged();
+ if (this.forceLeave || (!this.hasEvaluationChanged() && !assessmentHasChanged)) {
return true;
}
- if (!this.hasEvaluationChanged()) {
- return Promise.resolve();
- }
-
// Show confirmation if some data has been modified.
return this.domUtils.showConfirm(this.translate.instant('core.confirmcanceledit'));
}
@@ -155,7 +159,7 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy {
module: module,
access: this.access,
courseid: this.courseId,
- submission: this.submission
+ submissionId: this.submission.id
};
this.navCtrl.push('AddonModWorkshopEditSubmissionPage', params);
@@ -167,7 +171,7 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy {
* @param {any} data Event data received.
*/
protected eventReceived(data: any): void {
- if (this.workshopId === data.workshopid) {
+ if (this.workshopId === data.workshopId) {
this.content && this.content.scrollToTop();
this.loaded = false;
@@ -185,6 +189,7 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy {
const promises = [];
this.submission = submissionData;
+ this.submission.attachmentfiles = submissionData.attachmentfiles || [];
this.submission.submissiongrade = this.submissionInfo && this.submissionInfo.submissiongrade;
this.submission.gradinggrade = this.submissionInfo && this.submissionInfo.gradinggrade;
this.submission.submissiongradeover = this.submissionInfo && this.submissionInfo.submissiongradeover;
@@ -390,8 +395,16 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy {
* Save the assessment.
*/
saveAssessment(): void {
- // Call trigger to save.
- this.eventsProvider.trigger(AddonModWorkshopProvider.ASSESSMENT_SAVE, undefined, this.siteId);
+ if (this.assessmentStrategy && this.assessmentStrategy.hasDataChanged()) {
+ this.assessmentStrategy.saveAssessment().then(() => {
+ this.forceLeavePage();
+ }).catch(() => {
+ // Error, stay on the page.
+ });
+ } else {
+ // Nothing to save, just go back.
+ this.forceLeavePage();
+ }
}
/**
diff --git a/src/addon/mod/workshop/providers/workshop.ts b/src/addon/mod/workshop/providers/workshop.ts
index ca1889686..cb7757834 100644
--- a/src/addon/mod/workshop/providers/workshop.ts
+++ b/src/addon/mod/workshop/providers/workshop.ts
@@ -36,7 +36,6 @@ export class AddonModWorkshopProvider {
static EXAMPLES_BEFORE_ASSESSMENT: 2;
static SUBMISSION_CHANGED = 'addon_mod_workshop_submission_changed';
- static ASSESSMENT_SAVE = 'addon_mod_workshop_assessment_save';
static ASSESSMENT_SAVED = 'addon_mod_workshop_assessment_saved';
static ASSESSMENT_INVALIDATED = 'addon_mod_workshop_assessment_invalidated';