MOBILE-2201 tag: Link handlers
parent
d00d401894
commit
e4260aa92a
|
@ -0,0 +1,81 @@
|
||||||
|
// (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 { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||||
|
import { CoreTagProvider } from './tag';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler to treat links to tag index.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class CoreTagIndexLinkHandler extends CoreContentLinksHandlerBase {
|
||||||
|
name = 'CoreTagIndexLinkHandler';
|
||||||
|
pattern = /\/tag\/index\.php/;
|
||||||
|
|
||||||
|
constructor(private tagProvider: CoreTagProvider, private linkHelper: CoreContentLinksHelperProvider) {
|
||||||
|
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.
|
||||||
|
* @param {any} [data] Extra data to handle the URL.
|
||||||
|
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
|
||||||
|
*/
|
||||||
|
getActions(siteIds: string[], url: string, params: any, courseId?: number, data?: any):
|
||||||
|
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||||
|
return [{
|
||||||
|
action: (siteId, navCtrl?): void => {
|
||||||
|
const pageParams = {
|
||||||
|
tagId: parseInt(params.id, 10) || 0,
|
||||||
|
tagName: params.tag || '',
|
||||||
|
collectionId: parseInt(params.tc, 10) || 0,
|
||||||
|
areaId: parseInt(params.ta, 10) || 0,
|
||||||
|
fromContextId: parseInt(params.from, 10) || 0,
|
||||||
|
contextId: parseInt(params.ctx, 10) || 0,
|
||||||
|
recursive: parseInt(params.rec, 10) || 1
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!pageParams.tagId && (!pageParams.tagName || !pageParams.collectionId)) {
|
||||||
|
this.linkHelper.goInSite(navCtrl, 'CoreTagSearchPage', {}, siteId);
|
||||||
|
} else if (pageParams.areaId) {
|
||||||
|
this.linkHelper.goInSite(navCtrl, 'CoreTagIndexAreaPage', pageParams, siteId);
|
||||||
|
} else {
|
||||||
|
this.linkHelper.goInSite(navCtrl, 'CoreTagIndexPage', 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.tagProvider.areTagsAvailable(siteId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
// (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 { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||||
|
import { CoreTagProvider } from './tag';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler to treat links to tag search.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class CoreTagSearchLinkHandler extends CoreContentLinksHandlerBase {
|
||||||
|
name = 'CoreTagSearchLinkHandler';
|
||||||
|
pattern = /\/tag\/search\.php/;
|
||||||
|
|
||||||
|
constructor(private tagProvider: CoreTagProvider, private linkHelper: CoreContentLinksHelperProvider) {
|
||||||
|
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.
|
||||||
|
* @param {any} [data] Extra data to handle the URL.
|
||||||
|
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
|
||||||
|
*/
|
||||||
|
getActions(siteIds: string[], url: string, params: any, courseId?: number, data?: any):
|
||||||
|
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||||
|
return [{
|
||||||
|
action: (siteId, navCtrl?): void => {
|
||||||
|
const pageParams = {
|
||||||
|
collectionId: parseInt(params.tc, 10) || 0,
|
||||||
|
query: params.query || '',
|
||||||
|
};
|
||||||
|
|
||||||
|
this.linkHelper.goInSite(navCtrl, 'CoreTagSearchPage', 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.tagProvider.areTagsAvailable(siteId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,10 +14,13 @@
|
||||||
|
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
|
import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
|
||||||
|
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
||||||
import { CoreTagProvider } from './providers/tag';
|
import { CoreTagProvider } from './providers/tag';
|
||||||
import { CoreTagHelperProvider } from './providers/helper';
|
import { CoreTagHelperProvider } from './providers/helper';
|
||||||
import { CoreTagAreaDelegate } from './providers/area-delegate';
|
import { CoreTagAreaDelegate } from './providers/area-delegate';
|
||||||
import { CoreTagMainMenuHandler } from './providers/mainmenu-handler';
|
import { CoreTagMainMenuHandler } from './providers/mainmenu-handler';
|
||||||
|
import { CoreTagIndexLinkHandler } from './providers/index-link-handler';
|
||||||
|
import { CoreTagSearchLinkHandler } from './providers/search-link-handler';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -28,12 +31,18 @@ import { CoreTagMainMenuHandler } from './providers/mainmenu-handler';
|
||||||
CoreTagProvider,
|
CoreTagProvider,
|
||||||
CoreTagHelperProvider,
|
CoreTagHelperProvider,
|
||||||
CoreTagAreaDelegate,
|
CoreTagAreaDelegate,
|
||||||
CoreTagMainMenuHandler
|
CoreTagMainMenuHandler,
|
||||||
|
CoreTagIndexLinkHandler,
|
||||||
|
CoreTagSearchLinkHandler
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class CoreTagModule {
|
export class CoreTagModule {
|
||||||
|
|
||||||
constructor(mainMenuDelegate: CoreMainMenuDelegate, mainMenuHandler: CoreTagMainMenuHandler) {
|
constructor(mainMenuDelegate: CoreMainMenuDelegate, mainMenuHandler: CoreTagMainMenuHandler,
|
||||||
|
contentLinksDelegate: CoreContentLinksDelegate, indexLinkHandler: CoreTagIndexLinkHandler,
|
||||||
|
searchLinkHandler: CoreTagSearchLinkHandler) {
|
||||||
mainMenuDelegate.registerHandler(mainMenuHandler);
|
mainMenuDelegate.registerHandler(mainMenuHandler);
|
||||||
|
contentLinksDelegate.registerHandler(indexLinkHandler);
|
||||||
|
contentLinksDelegate.registerHandler(searchLinkHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue