<commit_before>// (C) Copyright 2015 Moodle Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Component, OnInit, Injector, Input } from '@angular/core';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component';
import { CoreConstants } from '@core/constants';
import { TranslateService } from '@ngx-translate/core';

/**
 * Component to render an "activity modules" block.
 */
@Component({
    selector: 'addon-block-activitymodules',
    templateUrl: 'addon-block-activitymodules.html'
})
export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent implements OnInit {
    @Input() block: any; // The block to render.
    @Input() contextLevel: string; // The context where the block will be used.
    @Input() instanceId: number; // The instance ID associated with the context level.

    entries: any[] = [];

    protected fetchContentDefaultError = 'Error getting activity modules data.';

    constructor(injector: Injector, protected courseProvider: CoreCourseProvider,
            protected translate: TranslateService, protected moduleDelegate: CoreCourseModuleDelegate) {

        super(injector, 'AddonBlockActivityModulesComponent');
    }

    /**
     * Component being initialized.
     */
    ngOnInit(): void {
        super.ngOnInit();
    }

    /**
     * Perform the invalidate content function.
     *
     * @return Resolved when done.
     */
    protected invalidateContent(): Promise<any> {
        return this.courseProvider.invalidateSections(this.instanceId);
    }

    /**
     * Fetch the data to render the block.
     *
     * @return Promise resolved when done.
     */
    protected fetchContent(): Promise<any> {
        return this.courseProvider.getSections(this.instanceId, false, true).then((sections) => {

            this.entries = [];

            const archetypes = {},
                modIcons = {};
            let modFullNames = {};

            sections.forEach((section) => {
                if (!section.modules) {
                    return;
                }

                section.modules.forEach((mod) => {
                    if (mod.uservisible === false || !this.courseProvider.moduleHasView(mod) ||<commit_msg>MOBILE-3235 blocks: Fix activities block outside of course context level<commit_after>// (C) Copyright 2015 Moodle Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Component, OnInit, Injector, Input } from '@angular/core';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component';
import { CoreConstants } from '@core/constants';
import { TranslateService } from '@ngx-translate/core';
import { CoreSitesProvider } from '@providers/sites';

/**
 * Component to render an "activity modules" block.
 */
@Component({
    selector: 'addon-block-activitymodules',
    templateUrl: 'addon-block-activitymodules.html'
})
export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent implements OnInit {
    @Input() block: any; // The block to render.
    @Input() contextLevel: string; // The context where the block will be used.
    @Input() instanceId: number; // The instance ID associated with the context level.

    entries: any[] = [];

    protected fetchContentDefaultError = 'Error getting activity modules data.';

    constructor(injector: Injector, protected courseProvider: CoreCourseProvider,
            protected translate: TranslateService, protected moduleDelegate: CoreCourseModuleDelegate,
            protected sitesProvider: CoreSitesProvider) {

        super(injector, 'AddonBlockActivityModulesComponent');
    }

    /**
     * Component being initialized.
     */
    ngOnInit(): void {
        super.ngOnInit();
    }

    /**
     * Perform the invalidate content function.
     *
     * @return Resolved when done.
     */
    protected invalidateContent(): Promise<any> {
        return this.courseProvider.invalidateSections(this.instanceId);
    }

    /**
     * Fetch the data to render the block.
     *
     * @return Promise resolved when done.
     */
    protected fetchContent(): Promise<any> {
        const courseId = this.contextLevel === 'course'
            ? this.instanceId
            : this.sitesProvider.getCurrentSiteHomeId();

        return this.courseProvider.getSections(courseId, false, true).then((sections) => {
            this.entries = [];

            const archetypes = {},
                modIcons = {};
            let modFullNames = {};

            sections.forEach((section) => {
                if (!section.modules) {
                    return;
                }

                section.modules.forEach((mod) => {
                    if (mod.uservisible === false || !this.courseProvider.moduleHasView(mod) ||
{'fraction_non_alphanumeric': 0.10750041030690957, 'fraction_numerical': 0.003282455276546857, 'mean_word_length': 2.9014084507042255, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3023432', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1524, 'n_words': 494}