Merge pull request #1783 from crazyserver/MOBILE-2887
MOBILE-2887 blog: Implement link handlersmain
commit
6b3ce99db7
|
@ -75,7 +75,6 @@
|
||||||
"addon.calendar.eventstarttime": "calendar",
|
"addon.calendar.eventstarttime": "calendar",
|
||||||
"addon.calendar.gotoactivity": "calendar",
|
"addon.calendar.gotoactivity": "calendar",
|
||||||
"addon.calendar.noevents": "local_moodlemobileapp",
|
"addon.calendar.noevents": "local_moodlemobileapp",
|
||||||
"addon.calendar.notifications": "local_moodlemobileapp",
|
|
||||||
"addon.calendar.reminders": "local_moodlemobileapp",
|
"addon.calendar.reminders": "local_moodlemobileapp",
|
||||||
"addon.calendar.setnewreminder": "local_moodlemobileapp",
|
"addon.calendar.setnewreminder": "local_moodlemobileapp",
|
||||||
"addon.calendar.typecategory": "calendar",
|
"addon.calendar.typecategory": "calendar",
|
||||||
|
|
|
@ -19,7 +19,7 @@ import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||||
import { AddonBadgesProvider } from './badges';
|
import { AddonBadgesProvider } from './badges';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to treat links to user participants page.
|
* Handler to treat links to user badges page.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AddonBadgesMyBadgesLinkHandler extends CoreContentLinksHandlerBase {
|
export class AddonBadgesMyBadgesLinkHandler extends CoreContentLinksHandlerBase {
|
||||||
|
|
|
@ -16,11 +16,13 @@ import { NgModule } from '@angular/core';
|
||||||
import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
|
import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
|
||||||
import { CoreUserDelegate } from '@core/user/providers/user-delegate';
|
import { CoreUserDelegate } from '@core/user/providers/user-delegate';
|
||||||
import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate';
|
import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate';
|
||||||
|
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
||||||
import { AddonBlogProvider } from './providers/blog';
|
import { AddonBlogProvider } from './providers/blog';
|
||||||
import { AddonBlogMainMenuHandler } from './providers/mainmenu-handler';
|
import { AddonBlogMainMenuHandler } from './providers/mainmenu-handler';
|
||||||
import { AddonBlogUserHandler } from './providers/user-handler';
|
import { AddonBlogUserHandler } from './providers/user-handler';
|
||||||
import { AddonBlogCourseOptionHandler } from './providers/course-option-handler';
|
import { AddonBlogCourseOptionHandler } from './providers/course-option-handler';
|
||||||
import { AddonBlogComponentsModule } from './components/components.module';
|
import { AddonBlogComponentsModule } from './components/components.module';
|
||||||
|
import { AddonBlogIndexLinkHandler } from './providers/index-link-handler';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -32,15 +34,18 @@ import { AddonBlogComponentsModule } from './components/components.module';
|
||||||
AddonBlogProvider,
|
AddonBlogProvider,
|
||||||
AddonBlogMainMenuHandler,
|
AddonBlogMainMenuHandler,
|
||||||
AddonBlogUserHandler,
|
AddonBlogUserHandler,
|
||||||
AddonBlogCourseOptionHandler
|
AddonBlogCourseOptionHandler,
|
||||||
|
AddonBlogIndexLinkHandler
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class AddonBlogModule {
|
export class AddonBlogModule {
|
||||||
constructor(mainMenuDelegate: CoreMainMenuDelegate, menuHandler: AddonBlogMainMenuHandler,
|
constructor(mainMenuDelegate: CoreMainMenuDelegate, menuHandler: AddonBlogMainMenuHandler,
|
||||||
userHandler: AddonBlogUserHandler, userDelegate: CoreUserDelegate,
|
userHandler: AddonBlogUserHandler, userDelegate: CoreUserDelegate,
|
||||||
courseOptionHandler: AddonBlogCourseOptionHandler, courseOptionsDelegate: CoreCourseOptionsDelegate) {
|
courseOptionHandler: AddonBlogCourseOptionHandler, courseOptionsDelegate: CoreCourseOptionsDelegate,
|
||||||
|
linkHandler: AddonBlogIndexLinkHandler, contentLinksDelegate: CoreContentLinksDelegate) {
|
||||||
mainMenuDelegate.registerHandler(menuHandler);
|
mainMenuDelegate.registerHandler(menuHandler);
|
||||||
userDelegate.registerHandler(userHandler);
|
userDelegate.registerHandler(userHandler);
|
||||||
courseOptionsDelegate.registerHandler(courseOptionHandler);
|
courseOptionsDelegate.registerHandler(courseOptionHandler);
|
||||||
|
contentLinksDelegate.registerHandler(linkHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ export class AddonBlogEntriesComponent implements OnInit {
|
||||||
@Input() userId?: number;
|
@Input() userId?: number;
|
||||||
@Input() courseId?: number;
|
@Input() courseId?: number;
|
||||||
@Input() cmId?: number;
|
@Input() cmId?: number;
|
||||||
|
@Input() entryId?: number;
|
||||||
|
@Input() groupId?: number;
|
||||||
|
@Input() tagId?: number;
|
||||||
|
|
||||||
protected filter = {};
|
protected filter = {};
|
||||||
protected pageLoaded = 0;
|
protected pageLoaded = 0;
|
||||||
|
@ -66,6 +69,18 @@ export class AddonBlogEntriesComponent implements OnInit {
|
||||||
this.filter['cmid'] = this.cmId;
|
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.fetchEntries().then(() => {
|
||||||
this.blogProvider.logView(this.filter).catch(() => {
|
this.blogProvider.logView(this.filter).catch(() => {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
<ion-buttons end></ion-buttons>
|
<ion-buttons end></ion-buttons>
|
||||||
</ion-navbar>
|
</ion-navbar>
|
||||||
</ion-header>
|
</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>
|
||||||
|
|
|
@ -27,14 +27,20 @@ export class AddonBlogEntriesPage {
|
||||||
userId: number;
|
userId: number;
|
||||||
courseId: number;
|
courseId: number;
|
||||||
cmId: number;
|
cmId: number;
|
||||||
|
entryId: number;
|
||||||
|
groupId: number;
|
||||||
|
tagId: number;
|
||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
constructor(params: NavParams) {
|
constructor(params: NavParams) {
|
||||||
this.userId = params.get('userId');
|
this.userId = params.get('userId');
|
||||||
this.courseId = params.get('courseId');
|
this.courseId = params.get('courseId');
|
||||||
this.cmId = params.get('cmId');
|
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';
|
this.title = 'addon.blog.siteblogheading';
|
||||||
} else {
|
} else {
|
||||||
this.title = 'addon.blog.blogentries';
|
this.title = 'addon.blog.blogentries';
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue