forked from EVOgeek/Vmeda.Online
		
	MOBILE-3881 timeline: Fix minimim time to get events from
This commit is contained in:
		
							parent
							
								
									c644eeb1e1
								
							
						
					
					
						commit
						6d0b53f034
					
				@ -18,10 +18,10 @@ import { CoreDomUtils } from '@services/utils/dom';
 | 
				
			|||||||
import { CoreTextUtils } from '@services/utils/text';
 | 
					import { CoreTextUtils } from '@services/utils/text';
 | 
				
			||||||
import { CoreTimeUtils } from '@services/utils/time';
 | 
					import { CoreTimeUtils } from '@services/utils/time';
 | 
				
			||||||
import { CoreCourse } from '@features/course/services/course';
 | 
					import { CoreCourse } from '@features/course/services/course';
 | 
				
			||||||
import moment from 'moment';
 | 
					 | 
				
			||||||
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
 | 
					import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
 | 
				
			||||||
import { AddonCalendarEvent } from '@addons/calendar/services/calendar';
 | 
					import { AddonCalendarEvent } from '@addons/calendar/services/calendar';
 | 
				
			||||||
import { CoreEnrolledCourseDataWithOptions } from '@features/courses/services/courses-helper';
 | 
					import { CoreEnrolledCourseDataWithOptions } from '@features/courses/services/courses-helper';
 | 
				
			||||||
 | 
					import { AddonBlockTimeline } from '../../services/timeline';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Directive to render a list of events in course overview.
 | 
					 * Directive to render a list of events in course overview.
 | 
				
			||||||
@ -94,8 +94,8 @@ export class AddonBlockTimelineEventsComponent implements OnChanges {
 | 
				
			|||||||
     * @return Filtered events.
 | 
					     * @return Filtered events.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected async filterEventsByTime(start: number, end?: number): Promise<AddonBlockTimelineEvent[]> {
 | 
					    protected async filterEventsByTime(start: number, end?: number): Promise<AddonBlockTimelineEvent[]> {
 | 
				
			||||||
        start = moment().add(start, 'days').startOf('day').unix();
 | 
					        start = AddonBlockTimeline.getDayStart(start);
 | 
				
			||||||
        end = end !== undefined ? moment().add(end, 'days').startOf('day').unix() : end;
 | 
					        end = end !== undefined ? AddonBlockTimeline.getDayStart(end) : end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return await Promise.all(this.events.filter((event) => {
 | 
					        return await Promise.all(this.events.filter((event) => {
 | 
				
			||||||
            if (end) {
 | 
					            if (end) {
 | 
				
			||||||
 | 
				
			|||||||
@ -55,7 +55,7 @@ export class AddonBlockTimelineProvider {
 | 
				
			|||||||
    ): Promise<{ events: AddonCalendarEvent[]; canLoadMore?: number }> {
 | 
					    ): Promise<{ events: AddonCalendarEvent[]; canLoadMore?: number }> {
 | 
				
			||||||
        const site = await CoreSites.getSite(siteId);
 | 
					        const site = await CoreSites.getSite(siteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const time = moment().subtract(14, 'days').unix(); // Check two weeks ago.
 | 
					        const time = this.getDayStart(-14); // Check two weeks ago.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const data: AddonCalendarGetActionEventsByCourseWSParams = {
 | 
					        const data: AddonCalendarGetActionEventsByCourseWSParams = {
 | 
				
			||||||
            timesortfrom: time,
 | 
					            timesortfrom: time,
 | 
				
			||||||
@ -109,7 +109,7 @@ export class AddonBlockTimelineProvider {
 | 
				
			|||||||
    ): Promise<{[courseId: string]: { events: AddonCalendarEvent[]; canLoadMore?: number } }> {
 | 
					    ): Promise<{[courseId: string]: { events: AddonCalendarEvent[]; canLoadMore?: number } }> {
 | 
				
			||||||
        const site = await CoreSites.getSite(siteId);
 | 
					        const site = await CoreSites.getSite(siteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const time = moment().subtract(14, 'days').unix(); // Check two weeks ago.
 | 
					        const time = this.getDayStart(-14); // Check two weeks ago.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const data: AddonCalendarGetActionEventsByCoursesWSParams = {
 | 
					        const data: AddonCalendarGetActionEventsByCoursesWSParams = {
 | 
				
			||||||
            timesortfrom: time,
 | 
					            timesortfrom: time,
 | 
				
			||||||
@ -164,7 +164,7 @@ export class AddonBlockTimelineProvider {
 | 
				
			|||||||
    ): Promise<{ events: AddonCalendarEvent[]; canLoadMore?: number }> {
 | 
					    ): Promise<{ events: AddonCalendarEvent[]; canLoadMore?: number }> {
 | 
				
			||||||
        const site = await CoreSites.getSite(siteId);
 | 
					        const site = await CoreSites.getSite(siteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const timesortfrom = moment().subtract(14, 'days').unix(); // Check two weeks ago.
 | 
					        const timesortfrom = this.getDayStart(-14); // Check two weeks ago.
 | 
				
			||||||
        const limitnum = AddonBlockTimelineProvider.EVENTS_LIMIT;
 | 
					        const limitnum = AddonBlockTimelineProvider.EVENTS_LIMIT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const data: AddonCalendarGetActionEventsByTimesortWSParams = {
 | 
					        const data: AddonCalendarGetActionEventsByTimesortWSParams = {
 | 
				
			||||||
@ -275,6 +275,16 @@ export class AddonBlockTimelineProvider {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Returns the timestamp at the start of the day with an optional offset.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param daysOffset Offset days to add or substract.
 | 
				
			||||||
 | 
					     * @return timestamp.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    getDayStart(daysOffset = 0): number {
 | 
				
			||||||
 | 
					        return moment().startOf('day').add(daysOffset, 'days').unix();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const AddonBlockTimeline = makeSingleton(AddonBlockTimelineProvider);
 | 
					export const AddonBlockTimeline = makeSingleton(AddonBlockTimelineProvider);
 | 
				
			||||||
 | 
				
			|||||||
@ -81,7 +81,7 @@ export class CoreTime {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Converts a number of seconds into a short human readable format: minutes and seconds, in fromat: 3' 27''.
 | 
					     * Converts a number of seconds into a short human readable format: minutes and seconds, in fromat: 3' 27''.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param seconds Seconds
 | 
					     * @param duration Duration in seconds.
 | 
				
			||||||
     * @return Short human readable text.
 | 
					     * @return Short human readable text.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    static formatTimeShort(duration: number): string {
 | 
					    static formatTimeShort(duration: number): string {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user