commit
84f59bb8ee
|
@ -2578,6 +2578,7 @@
|
|||
"core.tag.searchtags": "tag",
|
||||
"core.tag.showingfirsttags": "tag",
|
||||
"core.tag.tag": "moodle",
|
||||
"core.tag.tagarea_badge": "badges",
|
||||
"core.tag.tagarea_course": "tag",
|
||||
"core.tag.tagarea_course_modules": "tag",
|
||||
"core.tag.tagarea_post": "tag",
|
||||
|
|
|
@ -23,6 +23,8 @@ import { AddonBadgesUserHandler } from './services/handlers/user';
|
|||
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
||||
import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate';
|
||||
import { AddonBadgesPushClickHandler } from './services/handlers/push-click';
|
||||
import { CoreTagAreaDelegate } from '@features/tag/services/tag-area-delegate';
|
||||
import { AddonBadgesTagAreaHandler } from './services/handlers/tag-area';
|
||||
|
||||
/**
|
||||
* Get badges services.
|
||||
|
@ -57,6 +59,7 @@ const mainMenuRoutes: Routes = [
|
|||
CoreContentLinksDelegate.registerHandler(AddonBadgesBadgeLinkHandler.instance);
|
||||
CoreUserDelegate.registerHandler(AddonBadgesUserHandler.instance);
|
||||
CorePushNotificationsDelegate.registerClickHandler(AddonBadgesPushClickHandler.instance);
|
||||
CoreTagAreaDelegate.registerHandler(AddonBadgesTagAreaHandler.instance);
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
// (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 { Injectable, Type } from '@angular/core';
|
||||
import { CoreTagFeedComponent } from '@features/tag/components/feed/feed';
|
||||
import { CoreTagAreaHandler } from '@features/tag/services/tag-area-delegate';
|
||||
import { CoreTagFeedElement, CoreTagHelper } from '@features/tag/services/tag-helper';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { AddonBadges } from '../badges';
|
||||
|
||||
/**
|
||||
* Handler to support tags.
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AddonBadgesTagAreaHandlerService implements CoreTagAreaHandler {
|
||||
|
||||
name = 'AddonBadgesTagAreaHandler';
|
||||
type = 'core_badges/badge';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
isEnabled(): Promise<boolean> {
|
||||
return AddonBadges.isPluginEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async parseContent(content: string): Promise<CoreTagFeedElement[]> {
|
||||
return CoreTagHelper.parseFeedContent(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
getComponent(): Type<unknown> | Promise<Type<unknown>> {
|
||||
return CoreTagFeedComponent;
|
||||
}
|
||||
|
||||
}
|
||||
export const AddonBadgesTagAreaHandler = makeSingleton(AddonBadgesTagAreaHandlerService);
|
|
@ -1,6 +1,7 @@
|
|||
<ion-card *ngFor="let item of items">
|
||||
<ion-item class="ion-text-wrap" [href]="item.url" core-link [capture]="true">
|
||||
<core-user-avatar *ngIf="item.avatarUrl" [profileUrl]="item.avatarUrl" slot="start" [linkProfile]="false" />
|
||||
<core-user-avatar *ngIf="item.avatarUrl" [profileUrl]="item.avatarUrl" [fullname]="item.fullname" slot="start"
|
||||
[linkProfile]="false" />
|
||||
|
||||
<core-mod-icon *ngIf="item.iconUrl" [modicon]="item.iconUrl" slot="start" [showAlt]="false" [isBranded]="item.branded" />
|
||||
<ion-label>
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
"searchtags": "Search tags",
|
||||
"showingfirsttags": "Showing {{$a}} most popular tags",
|
||||
"tag": "Tag",
|
||||
"tagarea_course": "Courses",
|
||||
"tagarea_badge": "Badges",
|
||||
"tagarea_course_modules": "Activities and resources",
|
||||
"tagarea_course": "Courses",
|
||||
"tagarea_post": "Blog posts",
|
||||
"tagarea_user": "User interests",
|
||||
"tagareabadgedescription": "There are {{count}} items.",
|
||||
|
|
|
@ -69,7 +69,7 @@ export class CoreTagAreaDelegateService extends CoreDelegate<CoreTagAreaHandler>
|
|||
* @returns String key.
|
||||
*/
|
||||
getDisplayNameKey(component: string, itemType: string): string {
|
||||
return (component == 'core' ? 'core.tag' : 'addon.' + component) + '.tagarea_' + itemType;
|
||||
return (component === 'core' || component.startsWith('core_') ? 'core.tag' : 'addon.' + component) + '.tagarea_' + itemType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,11 +32,11 @@ export class CoreTagHelperProvider {
|
|||
const items: CoreTagFeedElement[] = [];
|
||||
const element = CoreDomUtils.convertToElement(content);
|
||||
|
||||
Array.from(element.querySelectorAll('ul.tag_feed > li.media')).forEach((itemElement) => {
|
||||
Array.from(element.querySelectorAll('ul.tag_feed > li')).forEach((itemElement) => {
|
||||
const item: CoreTagFeedElement = { details: [] };
|
||||
|
||||
Array.from(itemElement.querySelectorAll('div.media-body > div')).forEach((div: HTMLElement) => {
|
||||
if (div.classList.contains('media-heading')) {
|
||||
Array.from(itemElement.querySelectorAll('div.media-body > div, div.flex-grow-1 > div')).forEach((div: HTMLElement) => {
|
||||
if (div.classList.contains('media-heading') || div.classList.contains('item-heading')) {
|
||||
item.heading = div.innerText.trim();
|
||||
const link = div.querySelector('a');
|
||||
if (link) {
|
||||
|
@ -46,11 +46,11 @@ export class CoreTagHelperProvider {
|
|||
// Separate details by lines.
|
||||
const lines = [''];
|
||||
Array.from(div.childNodes).forEach((childNode: Node) => {
|
||||
if (childNode.nodeType == Node.TEXT_NODE) {
|
||||
if (childNode.nodeType === Node.TEXT_NODE) {
|
||||
lines[lines.length - 1] += childNode.textContent;
|
||||
} else if (childNode.nodeType == Node.ELEMENT_NODE) {
|
||||
} else if (childNode.nodeType === Node.ELEMENT_NODE) {
|
||||
const childElement = childNode as HTMLElement;
|
||||
if (childElement.tagName == 'BR') {
|
||||
if (childElement.tagName === 'BR') {
|
||||
lines.push('');
|
||||
} else {
|
||||
lines[lines.length - 1] += childElement.innerText;
|
||||
|
@ -61,13 +61,20 @@ export class CoreTagHelperProvider {
|
|||
}
|
||||
});
|
||||
|
||||
const image = itemElement.querySelector('div.itemimage img');
|
||||
const image = itemElement.querySelector('div.itemimage img, div.flex-shrink-0 img');
|
||||
if (image) {
|
||||
if (image.classList.contains('userpicture')) {
|
||||
item.avatarUrl = image.getAttribute('src');
|
||||
item.fullname = image.getAttribute('title');
|
||||
} else {
|
||||
item.iconUrl = image.getAttribute('src');
|
||||
}
|
||||
} else {
|
||||
const initials = itemElement.querySelector('div.itemimage .userinitials, div.flex-shrink-0 .userinitials');
|
||||
if (initials) {
|
||||
item.avatarUrl = 'error'; // Use 'error' to show the default avatar.
|
||||
item.fullname = initials.getAttribute('title');
|
||||
}
|
||||
}
|
||||
|
||||
if (item.heading && item.url) {
|
||||
|
@ -91,4 +98,5 @@ export type CoreTagFeedElement = {
|
|||
iconUrl?: string | null;
|
||||
avatarUrl?: string | null;
|
||||
url?: string | null;
|
||||
fullname?: string | null;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue