; // Will emit an event when the completion changes.
+
+ completionImage: string;
+ completionDescription: string;
+
+ constructor(private textUtils: CoreTextUtilsProvider, private translate: TranslateService,
+ private domUtils: CoreDomUtilsProvider, private sitesProvider: CoreSitesProvider) {
+ this.completionChanged = new EventEmitter();
+ }
+
+ /**
+ * Detect changes on input properties.
+ */
+ ngOnChanges(changes: {[name: string]: SimpleChange}) {
+ if (changes.completion && this.completion) {
+ this.showStatus();
+ }
+ }
+
+ /**
+ * Completion clicked.
+ *
+ * @param {Event} e The click event.
+ */
+ completionClicked(e: Event) : void {
+ if (this.completion) {
+ if (typeof this.completion.cmid == 'undefined' || this.completion.tracking !== 1) {
+ return;
+ }
+
+ e.preventDefault();
+ e.stopPropagation();
+
+ let modal = this.domUtils.showModalLoading(),
+ params = {
+ cmid: this.completion.cmid,
+ completed: this.completion.state === 1 ? 0 : 1
+ },
+ currentSite = this.sitesProvider.getCurrentSite();
+
+ currentSite.write('core_completion_update_activity_completion_status_manually', params).then((response) => {
+ if (!response.status) {
+ return Promise.reject(null);
+ }
+
+ this.completionChanged.emit();
+ }).catch((error) => {
+ this.domUtils.showErrorModalDefault(error, 'core.errorchangecompletion', true);
+ }).finally(() => {
+ modal.dismiss();
+ });
+ }
+ }
+
+ /**
+ * Set image and description to show as completion icon.
+ */
+ protected showStatus() : void {
+ let langKey,
+ moduleName = this.moduleName || '',
+ image;
+
+ if (this.completion.tracking === 1 && this.completion.state === 0) {
+ image = 'completion-manual-n';
+ langKey = 'core.completion-alt-manual-n';
+ } else if (this.completion.tracking === 1 && this.completion.state === 1) {
+ image = 'completion-manual-y';
+ langKey = 'core.completion-alt-manual-y';
+ } else if (this.completion.tracking === 2 && this.completion.state === 0) {
+ image = 'completion-auto-n';
+ langKey = 'core.completion-alt-auto-n';
+ } else if (this.completion.tracking === 2 && this.completion.state === 1) {
+ image = 'completion-auto-y';
+ langKey = 'core.completion-alt-auto-y';
+ } else if (this.completion.tracking === 2 && this.completion.state === 2) {
+ image = 'completion-auto-pass';
+ langKey = 'core.completion-alt-auto-pass';
+ } else if (this.completion.tracking === 2 && this.completion.state === 3) {
+ image = 'completion-auto-fail';
+ langKey = 'core.completion-alt-auto-fail';
+ }
+
+ if (image) {
+ if (this.completion.overrideby > 0) {
+ image += '-override';
+ }
+ this.completionImage = 'assets/img/completion/' + image + '.svg';
+ }
+
+ if (moduleName) {
+ this.textUtils.formatText(moduleName, true, true, 50).then((modNameFormatted) => {
+ let promise;
+
+ if (this.completion.overrideby > 0) {
+ langKey += '-override';
+
+ // @todo: Get user profile.
+ // promise = $mmUser.getProfile(scope.completion.overrideby, scope.completion.courseId, true).then(function(profile) {
+ // return {
+ // overrideuser: profile.fullname,
+ // modname: modNameFormatted
+ // };
+ // });
+ } else {
+ promise = Promise.resolve(modNameFormatted);
+ }
+
+ return promise.then((translateParams) => {
+ this.completionDescription = this.translate.instant(langKey, {$a: translateParams});
+ });
+ });
+ }
+ }
+}
diff --git a/src/core/course/components/module/module.html b/src/core/course/components/module/module.html
index 2b79e0e7e..dd45a23d7 100644
--- a/src/core/course/components/module/module.html
+++ b/src/core/course/components/module/module.html
@@ -5,7 +5,7 @@
0) || spinner || module.completionstatus)" class="buttons mm-module-buttons" [ngClass]="{'mm-button-completion': module.completionstatus}">
-
+