From 98bee19d97dee6be721e1db86d99aa9effb2f3b0 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Mon, 14 Oct 2024 10:01:08 +0200 Subject: [PATCH] MOBILE-3893 assign: Fix editing files offline Changes to the allowOffline property of AddonModAssignSubmissionPluginComponent were not being detected and passed to the submission plugin component. --- .../submission-plugin/submission-plugin.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/addons/mod/assign/components/submission-plugin/submission-plugin.ts b/src/addons/mod/assign/components/submission-plugin/submission-plugin.ts index 4010a919301..7c150e90acf 100644 --- a/src/addons/mod/assign/components/submission-plugin/submission-plugin.ts +++ b/src/addons/mod/assign/components/submission-plugin/submission-plugin.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Input, OnInit, Type, ViewChild } from '@angular/core'; +import { Component, Input, OnChanges, SimpleChanges, Type, ViewChild } from '@angular/core'; import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component'; import { AddonModAssignAssign, @@ -34,7 +34,7 @@ import { toBoolean } from '@/core/transforms/boolean'; selector: 'addon-mod-assign-submission-plugin', templateUrl: 'addon-mod-assign-submission-plugin.html', }) -export class AddonModAssignSubmissionPluginComponent implements OnInit { +export class AddonModAssignSubmissionPluginComponent implements OnChanges { @ViewChild(CoreDynamicComponent) dynamicComponent!: CoreDynamicComponent; @@ -57,7 +57,7 @@ export class AddonModAssignSubmissionPluginComponent implements OnInit { /** * @inheritdoc */ - async ngOnInit(): Promise { + async ngOnChanges(changes: SimpleChanges): Promise { if (!this.plugin) { this.pluginLoaded = true; @@ -73,8 +73,20 @@ export class AddonModAssignSubmissionPluginComponent implements OnInit { } this.plugin.name = name; - // Check if the plugin has defined its own component to render itself. - this.pluginComponent = await AddonModAssignSubmissionDelegate.getComponentForPlugin(this.plugin, this.edit); + if (changes.plugin || changes.edit) { + // Check if the plugin has defined its own component to render itself. + this.pluginComponent = await AddonModAssignSubmissionDelegate.getComponentForPlugin(this.plugin, this.edit); + + if (this.pluginComponent) { + this.pluginLoaded = false; + } else { + // Data to render the plugin. + this.text = AddonModAssign.getSubmissionPluginText(this.plugin); + this.files = AddonModAssign.getSubmissionPluginAttachments(this.plugin); + this.notSupported = AddonModAssignSubmissionDelegate.isPluginSupported(this.plugin.type); + this.pluginLoaded = true; + } + } if (this.pluginComponent) { // Prepare the data to pass to the component. @@ -86,12 +98,6 @@ export class AddonModAssignSubmissionPluginComponent implements OnInit { edit: this.edit, allowOffline: this.allowOffline, }; - } else { - // Data to render the plugin. - this.text = AddonModAssign.getSubmissionPluginText(this.plugin); - this.files = AddonModAssign.getSubmissionPluginAttachments(this.plugin); - this.notSupported = AddonModAssignSubmissionDelegate.isPluginSupported(this.plugin.type); - this.pluginLoaded = true; } }