From 48303896b927f1228e78ecc4392076a3b1619dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 10 May 2019 15:53:56 +0200 Subject: [PATCH] MOBILE-3002 block: Add Tags block feature --- scripts/langindex.json | 1 + src/addon/block/tags/lang/en.json | 3 + .../block/tags/providers/block-handler.ts | 52 +++++++++ src/addon/block/tags/tags.module.ts | 38 +++++++ src/addon/block/tags/tags.scss | 100 ++++++++++++++++++ src/app/app.module.ts | 2 + src/assets/lang/en.json | 1 + 7 files changed, 197 insertions(+) create mode 100644 src/addon/block/tags/lang/en.json create mode 100644 src/addon/block/tags/providers/block-handler.ts create mode 100644 src/addon/block/tags/tags.module.ts create mode 100644 src/addon/block/tags/tags.scss diff --git a/scripts/langindex.json b/scripts/langindex.json index b616afc3c..ceb8559a8 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -56,6 +56,7 @@ "addon.block_sitemainmenu.pluginname": "block_site_main_menu", "addon.block_starredcourses.nocourses": "block_starredcourses", "addon.block_starredcourses.pluginname": "block_starredcourses", + "addon.block_tags.pluginname": "block_tags", "addon.block_timeline.duedate": "block_timeline", "addon.block_timeline.next30days": "block_timeline", "addon.block_timeline.next3months": "block_timeline", diff --git a/src/addon/block/tags/lang/en.json b/src/addon/block/tags/lang/en.json new file mode 100644 index 000000000..a4080dd78 --- /dev/null +++ b/src/addon/block/tags/lang/en.json @@ -0,0 +1,3 @@ +{ + "pluginname": "Tags" +} \ No newline at end of file diff --git a/src/addon/block/tags/providers/block-handler.ts b/src/addon/block/tags/providers/block-handler.ts new file mode 100644 index 000000000..749188709 --- /dev/null +++ b/src/addon/block/tags/providers/block-handler.ts @@ -0,0 +1,52 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// 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, Injector } from '@angular/core'; +import { TranslateService } from '@ngx-translate/core'; + +import { CoreBlockHandlerData } from '@core/block/providers/delegate'; +import { CoreBlockPreRenderedComponent } from '@core/block/components/pre-rendered-block/pre-rendered-block'; +import { CoreBlockBaseHandler } from '@core/block/classes/base-block-handler'; + +/** + * Block handler. + */ +@Injectable() +export class AddonBlockTagsHandler extends CoreBlockBaseHandler { + name = 'AddonBlockTags'; + blockName = 'tags'; + + constructor(private translate: TranslateService) { + super(); + } + + /** + * Returns the data needed to render the block. + * + * @param {Injector} injector Injector. + * @param {any} block The block to render. + * @param {string} contextLevel The context where the block will be used. + * @param {number} instanceId The instance ID associated with the context level. + * @return {CoreBlockHandlerData|Promise} Data or promise resolved with the data. + */ + getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number) + : CoreBlockHandlerData | Promise { + + return { + title: this.translate.instant('addon.block_tags.pluginname'), + class: 'addon-block-tags', + component: CoreBlockPreRenderedComponent + }; + } +} diff --git a/src/addon/block/tags/tags.module.ts b/src/addon/block/tags/tags.module.ts new file mode 100644 index 000000000..4b57911c0 --- /dev/null +++ b/src/addon/block/tags/tags.module.ts @@ -0,0 +1,38 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// 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 { NgModule } from '@angular/core'; +import { IonicModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreBlockDelegate } from '@core/block/providers/delegate'; +import { AddonBlockTagsHandler } from './providers/block-handler'; + +@NgModule({ + declarations: [ + ], + imports: [ + IonicModule, + TranslateModule.forChild() + ], + exports: [ + ], + providers: [ + AddonBlockTagsHandler + ] +}) +export class AddonBlockTagsModule { + constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockTagsHandler) { + blockDelegate.registerHandler(blockHandler); + } +} diff --git a/src/addon/block/tags/tags.scss b/src/addon/block/tags/tags.scss new file mode 100644 index 000000000..cd3df32eb --- /dev/null +++ b/src/addon/block/tags/tags.scss @@ -0,0 +1,100 @@ +.addon-block-tags core-block-pre-rendered { + .core-block-content { + .tag_cloud { + text-align: center; + ul.inline-list { + list-style: none; + @include margin-horizontal(0); + -webkit-padding-start: 0; + + li { + padding: 0 .2em; + display: inline; + } + } + } + .tag_cloud .s20 { + font-size: 2.7em; + } + + .tag_cloud .s19 { + font-size: 2.6em; + } + + .tag_cloud .s18 { + font-size: 2.5em; + } + + .tag_cloud .s17 { + font-size: 2.4em; + } + + .tag_cloud .s16 { + font-size: 2.3em; + } + + .tag_cloud .s15 { + font-size: 2.2em; + } + + .tag_cloud .s14 { + font-size: 2.1em; + } + + .tag_cloud .s13 { + font-size: 2em; + } + + .tag_cloud .s12 { + font-size: 1.9em; + } + + .tag_cloud .s11 { + font-size: 1.8em; + } + + .tag_cloud .s10 { + font-size: 1.7em; + } + + .tag_cloud .s9 { + font-size: 1.6em; + } + + .tag_cloud .s8 { + font-size: 1.5em; + } + + .tag_cloud .s7 { + font-size: 1.4em; + } + + .tag_cloud .s6 { + font-size: 1.3em; + } + + .tag_cloud .s5 { + font-size: 1.2em; + } + + .tag_cloud .s4 { + font-size: 1.1em; + } + + .tag_cloud .s3 { + font-size: 1em; + } + + .tag_cloud .s2 { + font-size: 0.9em; + } + + .tag_cloud .s1 { + font-size: 0.8em; + } + + .tag_cloud .s0 { + font-size: 0.7em; + } + } +} \ No newline at end of file diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 1507b6921..9b4d75af7 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -109,6 +109,7 @@ import { AddonBlockRecentlyAccessedCoursesModule } from '@addon/block/recentlyac import { AddonBlockRecentlyAccessedItemsModule } from '@addon/block/recentlyaccesseditems/recentlyaccesseditems.module'; import { AddonBlockStarredCoursesModule } from '@addon/block/starredcourses/starredcourses.module'; import { AddonBlockSelfCompletionModule } from '@addon/block/selfcompletion/selfcompletion.module'; +import { AddonBlockTagsModule } from '@addon/block/tags/tags.module'; import { AddonModAssignModule } from '@addon/mod/assign/assign.module'; import { AddonModBookModule } from '@addon/mod/book/book.module'; import { AddonModChatModule } from '@addon/mod/chat/chat.module'; @@ -243,6 +244,7 @@ export const CORE_PROVIDERS: any[] = [ AddonBlockRecentlyAccessedItemsModule, AddonBlockStarredCoursesModule, AddonBlockSelfCompletionModule, + AddonBlockTagsModule, AddonModAssignModule, AddonModBookModule, AddonModChatModule, diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index fff9c6689..390eec79f 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -56,6 +56,7 @@ "addon.block_sitemainmenu.pluginname": "Main menu", "addon.block_starredcourses.nocourses": "No starred courses", "addon.block_starredcourses.pluginname": "Starred courses", + "addon.block_tags.pluginname": "Tags", "addon.block_timeline.duedate": "Due date", "addon.block_timeline.next30days": "Next 30 days", "addon.block_timeline.next3months": "Next 3 months",