MOBILE-2887 blog: Implement link handlers

main
Pau Ferrer Ocaña 2019-02-19 10:22:48 +01:00
parent d129c23d54
commit f868eaf53c
7 changed files with 107 additions and 6 deletions

View File

@ -75,7 +75,6 @@
"addon.calendar.eventstarttime": "calendar",
"addon.calendar.gotoactivity": "calendar",
"addon.calendar.noevents": "local_moodlemobileapp",
"addon.calendar.notifications": "local_moodlemobileapp",
"addon.calendar.reminders": "local_moodlemobileapp",
"addon.calendar.setnewreminder": "local_moodlemobileapp",
"addon.calendar.typecategory": "calendar",

View File

@ -19,7 +19,7 @@ import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { AddonBadgesProvider } from './badges';
/**
* Handler to treat links to user participants page.
* Handler to treat links to user badges page.
*/
@Injectable()
export class AddonBadgesMyBadgesLinkHandler extends CoreContentLinksHandlerBase {

View File

@ -16,11 +16,13 @@ import { NgModule } from '@angular/core';
import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
import { CoreUserDelegate } from '@core/user/providers/user-delegate';
import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate';
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
import { AddonBlogProvider } from './providers/blog';
import { AddonBlogMainMenuHandler } from './providers/mainmenu-handler';
import { AddonBlogUserHandler } from './providers/user-handler';
import { AddonBlogCourseOptionHandler } from './providers/course-option-handler';
import { AddonBlogComponentsModule } from './components/components.module';
import { AddonBlogIndexLinkHandler } from './providers/index-link-handler';
@NgModule({
declarations: [
@ -32,15 +34,18 @@ import { AddonBlogComponentsModule } from './components/components.module';
AddonBlogProvider,
AddonBlogMainMenuHandler,
AddonBlogUserHandler,
AddonBlogCourseOptionHandler
AddonBlogCourseOptionHandler,
AddonBlogIndexLinkHandler
]
})
export class AddonBlogModule {
constructor(mainMenuDelegate: CoreMainMenuDelegate, menuHandler: AddonBlogMainMenuHandler,
userHandler: AddonBlogUserHandler, userDelegate: CoreUserDelegate,
courseOptionHandler: AddonBlogCourseOptionHandler, courseOptionsDelegate: CoreCourseOptionsDelegate) {
courseOptionHandler: AddonBlogCourseOptionHandler, courseOptionsDelegate: CoreCourseOptionsDelegate,
linkHandler: AddonBlogIndexLinkHandler, contentLinksDelegate: CoreContentLinksDelegate) {
mainMenuDelegate.registerHandler(menuHandler);
userDelegate.registerHandler(userHandler);
courseOptionsDelegate.registerHandler(courseOptionHandler);
contentLinksDelegate.registerHandler(linkHandler);
}
}

View File

@ -30,6 +30,9 @@ export class AddonBlogEntriesComponent implements OnInit {
@Input() userId?: number;
@Input() courseId?: number;
@Input() cmId?: number;
@Input() entryId?: number;
@Input() groupId?: number;
@Input() tagId?: number;
protected filter = {};
protected pageLoaded = 0;
@ -66,6 +69,18 @@ export class AddonBlogEntriesComponent implements OnInit {
this.filter['cmid'] = this.cmId;
}
if (this.entryId) {
this.filter['entryid'] = this.entryId;
}
if (this.groupId) {
this.filter['groupid'] = this.groupId;
}
if (this.tagId) {
this.filter['tagid'] = this.tagId;
}
this.fetchEntries().then(() => {
this.blogProvider.logView(this.filter).catch(() => {
// Ignore errors.

View File

@ -4,4 +4,4 @@
<ion-buttons end></ion-buttons>
</ion-navbar>
</ion-header>
<addon-blog-entries class="core-avoid-header" [courseId]="courseId" [userId]="userId" [cmId]="cmId"></addon-blog-entries>
<addon-blog-entries class="core-avoid-header" [courseId]="courseId" [userId]="userId" [cmId]="cmId" [entryId]="entryId" [groupId]="groupId" [tagId]="tagId"></addon-blog-entries>

View File

@ -27,14 +27,20 @@ export class AddonBlogEntriesPage {
userId: number;
courseId: number;
cmId: number;
entryId: number;
groupId: number;
tagId: number;
title: string;
constructor(params: NavParams) {
this.userId = params.get('userId');
this.courseId = params.get('courseId');
this.cmId = params.get('cmId');
this.entryId = params.get('entryId');
this.groupId = params.get('groupId');
this.tagId = params.get('tagId');
if (!this.userId && !this.courseId && !this.cmId) {
if (!this.userId && !this.courseId && !this.cmId && !this.entryId && !this.groupId && !this.tagId) {
this.title = 'addon.blog.siteblogheading';
} else {
this.title = 'addon.blog.blogentries';

View File

@ -0,0 +1,76 @@
// (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 } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { AddonBlogProvider } from './blog';
/**
* Handler to treat links to blog page.
*/
@Injectable()
export class AddonBlogIndexLinkHandler extends CoreContentLinksHandlerBase {
name = 'AddonBlogIndexLinkHandler';
featureName = 'CoreUserDelegate_AddonBlog';
pattern = /\/blog\/index\.php/;
constructor(private blogProvider: AddonBlogProvider, private loginHelper: CoreLoginHelperProvider) {
super();
}
/**
* Get the list of actions for a link (url).
*
* @param {string[]} siteIds List of sites the URL belongs to.
* @param {string} url The URL to treat.
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
*/
getActions(siteIds: string[], url: string, params: any, courseId?: number):
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
const pageParams: any = {};
params.userid ? pageParams['userId'] = parseInt(params.userid, 10) : null;
params.modid ? pageParams['cmId'] = parseInt(params.modid, 10) : null;
params.courseid ? pageParams['courseId'] = parseInt(params.courseid, 10) : null;
params.entryid ? pageParams['entryId'] = parseInt(params.entryid, 10) : null;
params.groupid ? pageParams['groupId'] = parseInt(params.groupid, 10) : null;
params.tagid ? pageParams['tagId'] = parseInt(params.tagid, 10) : null;
return [{
action: (siteId, navCtrl?): void => {
// Always use redirect to make it the new history root (to avoid "loops" in history).
this.loginHelper.redirect('AddonBlogEntriesPage', pageParams, siteId);
}
}];
}
/**
* Check if the handler is enabled for a certain site (site + user) and a URL.
* If not defined, defaults to true.
*
* @param {string} siteId The site ID.
* @param {string} url The URL to treat.
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
* @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site.
*/
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
return this.blogProvider.isPluginEnabled(siteId);
}
}