MOBILE-2686 recentlyaccesseditems: Add Recent Accessed items block
parent
ccafdd32cd
commit
762b048806
|
@ -24,6 +24,8 @@
|
|||
"addon.block_myoverview.title": "block_myoverview",
|
||||
"addon.block_recentlyaccessedcourses.nocourses": "block_recentlyaccessedcourses",
|
||||
"addon.block_recentlyaccessedcourses.pluginname": "block_recentlyaccessedcourses",
|
||||
"addon.block_recentlyaccesseditems.noitems": "block_recentlyaccesseditems",
|
||||
"addon.block_recentlyaccesseditems.pluginname": "block_recentlyaccesseditems",
|
||||
"addon.block_sitemainmenu.pluginname": "block_site_main_menu",
|
||||
"addon.block_timeline.duedate": "block_timeline",
|
||||
"addon.block_timeline.next30days": "block_timeline",
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
// (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 { CommonModule } from '@angular/common';
|
||||
import { IonicModule } from 'ionic-angular';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AddonBlockRecentlyAccessedItemsComponent } from './recentlyaccesseditems/recentlyaccesseditems';
|
||||
import { CoreComponentsModule } from '@components/components.module';
|
||||
import { CoreDirectivesModule } from '@directives/directives.module';
|
||||
import { CoreCourseComponentsModule } from '@core/course/components/components.module';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AddonBlockRecentlyAccessedItemsComponent
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
IonicModule,
|
||||
TranslateModule.forChild(),
|
||||
CoreComponentsModule,
|
||||
CoreDirectivesModule,
|
||||
CoreCourseComponentsModule
|
||||
],
|
||||
providers: [
|
||||
],
|
||||
exports: [
|
||||
AddonBlockRecentlyAccessedItemsComponent
|
||||
],
|
||||
entryComponents: [
|
||||
AddonBlockRecentlyAccessedItemsComponent
|
||||
]
|
||||
})
|
||||
export class AddonBlockRecentlyAccessedItemsComponentsModule {}
|
|
@ -0,0 +1,15 @@
|
|||
<ion-item-divider color="light">
|
||||
<h2>{{ 'addon.block_recentlyaccesseditems.pluginname' | translate }}</h2>
|
||||
</ion-item-divider>
|
||||
<core-loading [hideUntil]="loaded" class="core-loading-center">
|
||||
<ng-container *ngFor="let item of items">
|
||||
<a ion-item text-wrap detail-none class="core-course-module-handler item-media" (click)="action($event, item)" [title]="item.name">
|
||||
<img item-start [src]="item.iconUrl" alt="" role="presentation" *ngIf="item.iconUrl" class="core-module-icon">
|
||||
<h2><core-format-text [text]="item.name"></core-format-text></h2>
|
||||
<p><core-format-text [text]="item.coursename"></core-format-text></p>
|
||||
</a>
|
||||
</ng-container>
|
||||
|
||||
<core-empty-box *ngIf="items.length <= 0" image="assets/img/icons/activities.svg" [message]="'addon.block_recentlyaccesseditems.noitems' | translate"></core-empty-box>
|
||||
|
||||
</core-loading>
|
|
@ -0,0 +1,90 @@
|
|||
// (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 { Component, OnInit, Injector, Optional } from '@angular/core';
|
||||
import { NavController } from 'ionic-angular';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component';
|
||||
import { AddonBlockRecentlyAccessedItemsProvider } from '../../providers/recentlyaccesseditems';
|
||||
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
|
||||
/**
|
||||
* Component to render a recently accessed items block.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'addon-block-recentlyaccesseditems',
|
||||
templateUrl: 'addon-block-recentlyaccesseditems.html'
|
||||
})
|
||||
export class AddonBlockRecentlyAccessedItemsComponent extends CoreBlockBaseComponent implements OnInit {
|
||||
items = [];
|
||||
|
||||
protected fetchContentDefaultError = 'Error getting recently accessed items data.';
|
||||
|
||||
constructor(injector: Injector, @Optional() private navCtrl: NavController,
|
||||
private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider,
|
||||
private recentItemsProvider: AddonBlockRecentlyAccessedItemsProvider,
|
||||
private contentLinksHelper: CoreContentLinksHelperProvider) {
|
||||
|
||||
super(injector, 'AddonBlockRecentlyAccessedItemsComponent');
|
||||
}
|
||||
|
||||
/**
|
||||
* Component being initialized.
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the invalidate content function.
|
||||
*
|
||||
* @return {Promise<any>} Resolved when done.
|
||||
*/
|
||||
protected invalidateContent(): Promise<any> {
|
||||
return this.recentItemsProvider.invalidateRecentItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the data to render the block.
|
||||
*
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
protected fetchContent(): Promise<any> {
|
||||
return this.recentItemsProvider.getRecentItems().then((items) => {
|
||||
this.items = items;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Event clicked.
|
||||
*
|
||||
* @param {Event} e Click event.
|
||||
* @param {any} item Activity item info.
|
||||
*/
|
||||
action(e: Event, item: any): void {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
const url = this.textUtils.decodeHTMLEntities(item.viewurl);
|
||||
const modal = this.domUtils.showModalLoading();
|
||||
this.contentLinksHelper.handleLink(url, undefined, this.navCtrl).then((treated) => {
|
||||
if (!treated) {
|
||||
return this.sitesProvider.getCurrentSite().openInBrowserWithAutoLoginIfSameSite(url);
|
||||
}
|
||||
}).finally(() => {
|
||||
modal.dismiss();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"noitems": "No recent items",
|
||||
"pluginname": "Recently accessed items"
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
// (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 { CoreBlockHandlerData } from '@core/block/providers/delegate';
|
||||
import { AddonBlockRecentlyAccessedItemsComponent } from '../components/recentlyaccesseditems/recentlyaccesseditems';
|
||||
import { CoreBlockBaseHandler } from '@core/block/classes/base-block-handler';
|
||||
|
||||
/**
|
||||
* Block handler.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonBlockRecentlyAccessedItemsHandler extends CoreBlockBaseHandler {
|
||||
name = 'AddonBlockRecentlyAccessedItems';
|
||||
blockName = 'recentlyaccesseditems';
|
||||
|
||||
constructor() {
|
||||
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<CoreBlockHandlerData>} Data or promise resolved with the data.
|
||||
*/
|
||||
getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number)
|
||||
: CoreBlockHandlerData | Promise<CoreBlockHandlerData> {
|
||||
|
||||
return {
|
||||
title: 'addon.block_recentlyaccesseditems.pluginname',
|
||||
class: 'addon-block-recentlyaccesseditems',
|
||||
component: AddonBlockRecentlyAccessedItemsComponent
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
// (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 { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||
|
||||
/**
|
||||
* Service that provides some features regarding recently accessed items.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonBlockRecentlyAccessedItemsProvider {
|
||||
protected ROOT_CACHE_KEY = 'AddonBlockRecentlyAccessedItems:';
|
||||
|
||||
constructor(private sitesProvider: CoreSitesProvider, private courseProvider: CoreCourseProvider) { }
|
||||
|
||||
/**
|
||||
* Get cache key for get last accessed items value WS call.
|
||||
*
|
||||
* @return {string} Cache key.
|
||||
*/
|
||||
protected getRecentItemsCacheKey(): string {
|
||||
return this.ROOT_CACHE_KEY + ':recentitems';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last accessed items.
|
||||
*
|
||||
* @param {string} [siteId] Site ID. If not defined, use current site.
|
||||
* @return {Promise<any[]>} Promise resolved when the info is retrieved.
|
||||
*/
|
||||
getRecentItems(siteId?: string): Promise<any[]> {
|
||||
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
const preSets = {
|
||||
cacheKey: this.getRecentItemsCacheKey()
|
||||
};
|
||||
|
||||
return site.read('block_recentlyaccesseditems_get_recent_items', undefined, preSets).then((items) => {
|
||||
return items.map((item) => {
|
||||
item.iconUrl = this.courseProvider.getModuleIconSrc(item.modname);
|
||||
|
||||
return item;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates get last accessed items WS call.
|
||||
*
|
||||
* @param {string} [siteId] Site ID to invalidate. If not defined, use current site.
|
||||
* @return {Promise<any>} Promise resolved when the data is invalidated.
|
||||
*/
|
||||
invalidateRecentItems(siteId?: string): Promise<any> {
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
return site.invalidateWsCacheForKey(this.getRecentItemsCacheKey());
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
// (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 { AddonBlockRecentlyAccessedItemsComponentsModule } from './components/components.module';
|
||||
import { CoreBlockDelegate } from '@core/block/providers/delegate';
|
||||
import { AddonBlockRecentlyAccessedItemsHandler } from './providers/block-handler';
|
||||
import { AddonBlockRecentlyAccessedItemsProvider } from './providers/recentlyaccesseditems';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
],
|
||||
imports: [
|
||||
IonicModule,
|
||||
AddonBlockRecentlyAccessedItemsComponentsModule,
|
||||
TranslateModule.forChild()
|
||||
],
|
||||
exports: [
|
||||
],
|
||||
providers: [
|
||||
AddonBlockRecentlyAccessedItemsHandler,
|
||||
AddonBlockRecentlyAccessedItemsProvider
|
||||
]
|
||||
})
|
||||
export class AddonBlockRecentlyAccessedItemsModule {
|
||||
constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockRecentlyAccessedItemsHandler) {
|
||||
blockDelegate.registerHandler(blockHandler);
|
||||
}
|
||||
}
|
|
@ -89,6 +89,7 @@ import { AddonBlockMyOverviewModule } from '@addon/block/myoverview/myoverview.m
|
|||
import { AddonBlockSiteMainMenuModule } from '@addon/block/sitemainmenu/sitemainmenu.module';
|
||||
import { AddonBlockTimelineModule } from '@addon/block/timeline/timeline.module';
|
||||
import { AddonBlockRecentlyAccessedCoursesModule } from '@addon/block/recentlyaccessedcourses/recentlyaccessedcourses.module';
|
||||
import { AddonBlockRecentlyAccessedItemsModule } from '@addon/block/recentlyaccesseditems/recentlyaccesseditems.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';
|
||||
|
@ -204,6 +205,7 @@ export const CORE_PROVIDERS: any[] = [
|
|||
AddonBlockSiteMainMenuModule,
|
||||
AddonBlockTimelineModule,
|
||||
AddonBlockRecentlyAccessedCoursesModule,
|
||||
AddonBlockRecentlyAccessedItemsModule,
|
||||
AddonModAssignModule,
|
||||
AddonModBookModule,
|
||||
AddonModChatModule,
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
"addon.block_myoverview.title": "Title",
|
||||
"addon.block_recentlyaccessedcourses.nocourses": "No recent courses",
|
||||
"addon.block_recentlyaccessedcourses.pluginname": "Recently accessed courses",
|
||||
"addon.block_recentlyaccesseditems.noitems": "No recent items",
|
||||
"addon.block_recentlyaccesseditems.pluginname": "Recently accessed items",
|
||||
"addon.block_sitemainmenu.pluginname": "Main menu",
|
||||
"addon.block_timeline.duedate": "Due date",
|
||||
"addon.block_timeline.next30days": "Next 30 days",
|
||||
|
|
Loading…
Reference in New Issue