MOBILE-3947 chore: Fix some non valid types

main
Pau Ferrer Ocaña 2023-11-09 16:28:49 +01:00
parent 1639e60ebe
commit 9e9052db85
19 changed files with 44 additions and 39 deletions

View File

@ -44,7 +44,7 @@ export class AddonBlockTimelineSection {
this.overdue = overdue; this.overdue = overdue;
this.dateRange = dateRange; this.dateRange = dateRange;
this.course = course; this.course = course;
this.dataSubject$ = new BehaviorSubject({ this.dataSubject$ = new BehaviorSubject<AddonBlockTimelineSectionData>({
events: [], events: [],
lastEventId: canLoadMore, lastEventId: canLoadMore,
canLoadMore: typeof canLoadMore !== 'undefined', canLoadMore: typeof canLoadMore !== 'undefined',

View File

@ -56,7 +56,7 @@ export class AddonBlockTimelineComponent implements OnInit, ICoreBlockComponent
constructor() { constructor() {
this.logger = CoreLogger.getInstance('AddonBlockTimelineComponent'); this.logger = CoreLogger.getInstance('AddonBlockTimelineComponent');
this.search$ = new BehaviorSubject(null); this.search$ = new BehaviorSubject<string | null>(null);
this.initializeSort(); this.initializeSort();
this.initializeFilter(); this.initializeFilter();
this.initializeSections(); this.initializeSections();

View File

@ -98,7 +98,7 @@ export class AddonEnrolGuestHandlerService implements CoreEnrolGuestHandler {
return false; return false;
} }
const validatePassword = async (password: string): Promise<CorePasswordModalResponse> => { const validatePassword = async (password = ''): Promise<CorePasswordModalResponse> => {
const modal = await CoreDomUtils.showModalLoading('core.loading', true); const modal = await CoreDomUtils.showModalLoading('core.loading', true);
try { try {

View File

@ -407,8 +407,8 @@ type MathJaxWindow = Window & {
MathJax?: any; // eslint-disable-line @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any MathJax?: any; // eslint-disable-line @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any
M?: { // eslint-disable-line @typescript-eslint/naming-convention M?: { // eslint-disable-line @typescript-eslint/naming-convention
filter_mathjaxloader?: { // eslint-disable-line @typescript-eslint/naming-convention filter_mathjaxloader?: { // eslint-disable-line @typescript-eslint/naming-convention
_lang: ''; // eslint-disable-line @typescript-eslint/naming-convention _lang: string; // eslint-disable-line @typescript-eslint/naming-convention
_configured: false; // eslint-disable-line @typescript-eslint/naming-convention _configured: boolean; // eslint-disable-line @typescript-eslint/naming-convention
// Add the configuration to the head and set the lang. // Add the configuration to the head and set the lang.
configure: (params: Record<string, unknown>) => void; configure: (params: Record<string, unknown>) => void;
_setLocale: () => void; // eslint-disable-line @typescript-eslint/naming-convention _setLocale: () => void; // eslint-disable-line @typescript-eslint/naming-convention

View File

@ -28,6 +28,7 @@ import {
SUBMISSIONS_GRADES_TABLE, SUBMISSIONS_GRADES_TABLE,
SUBMISSIONS_TABLE, SUBMISSIONS_TABLE,
} from './database/assign'; } from './database/assign';
import { CoreArray } from '@singletons/array';
/** /**
* Service to handle offline assign. * Service to handle offline assign.
@ -86,8 +87,8 @@ export class AddonModAssignOfflineProvider {
const results = await Promise.all(promises); const results = await Promise.all(promises);
// Flatten array. // Flatten array.
const flatten: (AddonModAssignSubmissionsDBRecord | AddonModAssignSubmissionsGradingDBRecord)[] = const flatten = CoreArray
[].concat.apply([], results); .flatten<AddonModAssignSubmissionsDBRecordFormatted | AddonModAssignSubmissionsGradingDBRecordFormatted>(results);
// Get assign id. // Get assign id.
let assignIds: number[] = flatten.map((assign) => assign.assignid); let assignIds: number[] = flatten.map((assign) => assign.assignid);

View File

@ -166,7 +166,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
// Get intro and activity files from the submission status if it's a student. // Get intro and activity files from the submission status if it's a student.
// It's ok if they were already obtained from the assignment instance, they won't be downloaded twice. // It's ok if they were already obtained from the assignment instance, they won't be downloaded twice.
const files = canViewAllSubmissions ? const files: CoreWSFile[] = canViewAllSubmissions ?
[] : [] :
(submissionStatus.assignmentdata?.attachments?.intro || []) (submissionStatus.assignmentdata?.attachments?.intro || [])
.concat(submissionStatus.assignmentdata?.attachments?.activity || []); .concat(submissionStatus.assignmentdata?.attachments?.activity || []);

View File

@ -301,7 +301,7 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo
this.data = []; this.data = [];
this.labels = []; this.labels = [];
this.results = results.map((result: AddonModChoiceResultFormatted) => { this.results = results.map<AddonModChoiceResultFormatted>((result) => {
if (result.numberofuser > 0) { if (result.numberofuser > 0) {
hasVotes = true; hasVotes = true;
} }

View File

@ -194,9 +194,9 @@ export class AddonModFeedbackProvider {
} }
// Treat multichoice checkboxes. // Treat multichoice checkboxes.
if (item.typ == 'multichoice' && item.presentation.split(AddonModFeedbackProvider.MULTICHOICE_TYPE_SEP)[0] == 'c') { if (item.typ === 'multichoice' && item.presentation.split(AddonModFeedbackProvider.MULTICHOICE_TYPE_SEP)[0] === 'c') {
offlineValues[item.id] = offlineValues[item.id].filter((value) => value > 0); offlineValues[item.id] = offlineValues[item.id].filter((value) => Number(value) > 0);
item.rawValue = offlineValues[item.id].join(AddonModFeedbackProvider.LINE_SEP); item.rawValue = offlineValues[item.id].join(AddonModFeedbackProvider.LINE_SEP);
} else { } else {
item.rawValue = offlineValues[item.id][0]; item.rawValue = offlineValues[item.id][0];

View File

@ -513,7 +513,7 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy, CanLea
published: boolean; published: boolean;
} = this.feedbackForm.value; } = this.feedbackForm.value;
inputData.grade = inputData.grade >= 0 ? inputData.grade : ''; inputData.grade = Number(inputData.grade) >= 0 ? inputData.grade : '';
// Add some HTML to the message if needed. // Add some HTML to the message if needed.
inputData.text = CoreTextUtils.formatHtmlLines(inputData.text); inputData.text = CoreTextUtils.formatHtmlLines(inputData.text);

View File

@ -348,8 +348,8 @@ export class CoreDatabaseTable<
records.sort((a, b) => { records.sort((a, b) => {
for (const [column, direction] of columnsSorting) { for (const [column, direction] of columnsSorting) {
const aValue = a[column]; const aValue = a[column] ?? 0;
const bValue = b[column]; const bValue = b[column] ?? 0;
if (aValue > bValue) { if (aValue > bValue) {
return direction === 'desc' ? -1 : 1; return direction === 'desc' ? -1 : 1;

View File

@ -40,7 +40,7 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy {
isNested = false; isNested = false;
disabledScrollOuterContents: HTMLIonContentElement[] = []; disabledScrollOuterContents: HTMLIonContentElement[] = [];
private outletRouteSubject: BehaviorSubject<ActivatedRouteSnapshot | null> = new BehaviorSubject(null); private outletRouteSubject = new BehaviorSubject<ActivatedRouteSnapshot | null>(null);
private subscriptions?: Subscription[]; private subscriptions?: Subscription[];
constructor(private element: ElementRef<HTMLElement>) {} constructor(private element: ElementRef<HTMLElement>) {}

View File

@ -464,11 +464,13 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
const audios = Array.from(div.querySelectorAll('audio')); const audios = Array.from(div.querySelectorAll('audio'));
const videos = Array.from(div.querySelectorAll('video')); const videos = Array.from(div.querySelectorAll('video'));
const iframes = Array.from(div.querySelectorAll('iframe')); const iframes = Array.from(div.querySelectorAll('iframe'));
const buttons = Array.from(div.querySelectorAll('.button')); const buttons = Array.from(div.querySelectorAll<HTMLElement>('.button'));
const icons = Array.from(div.querySelectorAll('i.fa,i.fas,i.far,i.fab')); const icons = Array.from(div.querySelectorAll('i.fa,i.fas,i.far,i.fab'));
const elementsWithInlineStyles = Array.from(div.querySelectorAll('*[style]')); const elementsWithInlineStyles = Array.from(div.querySelectorAll<HTMLElement>('*[style]'));
const stopClicksElements = Array.from(div.querySelectorAll('button,input,select,textarea')); const stopClicksElements = Array.from(div.querySelectorAll<HTMLElement>('button,input,select,textarea'));
const frames = Array.from(div.querySelectorAll(CoreIframeUtilsProvider.FRAME_TAGS.join(',').replace(/iframe,?/, ''))); const frames = Array.from(
div.querySelectorAll<FrameElement>(CoreIframeUtilsProvider.FRAME_TAGS.join(',').replace(/iframe,?/, '')),
);
const svgImages = Array.from(div.querySelectorAll('image')); const svgImages = Array.from(div.querySelectorAll('image'));
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
@ -560,7 +562,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
}); });
// Handle all kind of frames. // Handle all kind of frames.
const frameControllers = frames.map((frame: FrameElement) => { const frameControllers = frames.map<FrameElementController>((frame) => {
CoreIframeUtils.treatFrame(frame, false); CoreIframeUtils.treatFrame(frame, false);
return new FrameElementController(frame, !this.disabled); return new FrameElementController(frame, !this.disabled);

View File

@ -17,6 +17,7 @@ import { CoreSites } from '@services/sites';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { COMMENTS_TABLE, COMMENTS_DELETED_TABLE, CoreCommentsDBRecord, CoreCommentsDeletedDBRecord } from './database/comments'; import { COMMENTS_TABLE, COMMENTS_DELETED_TABLE, CoreCommentsDBRecord, CoreCommentsDeletedDBRecord } from './database/comments';
import { CoreArray } from '@singletons/array';
/** /**
* Service to handle offline comments. * Service to handle offline comments.
@ -33,11 +34,11 @@ export class CoreCommentsOfflineProvider {
async getAllComments(siteId?: string): Promise<(CoreCommentsDBRecord | CoreCommentsDeletedDBRecord)[]> { async getAllComments(siteId?: string): Promise<(CoreCommentsDBRecord | CoreCommentsDeletedDBRecord)[]> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
const results = await Promise.all([ const results = await Promise.all([
site.getDb().getRecords(COMMENTS_TABLE), site.getDb().getRecords<CoreCommentsDBRecord>(COMMENTS_TABLE),
site.getDb().getRecords(COMMENTS_DELETED_TABLE), site.getDb().getRecords<CoreCommentsDeletedDBRecord>(COMMENTS_DELETED_TABLE),
]); ]);
return [].concat.apply([], results); return CoreArray.flatten<CoreCommentsDBRecord | CoreCommentsDeletedDBRecord>(results);
} }
/** /**

View File

@ -48,7 +48,7 @@ export class CoreFileUploaderAudioRecorderComponent extends CoreModalComponent<C
super(elementRef); super(elementRef);
this.recording = null; this.recording = null;
this.media$ = new BehaviorSubject(null); this.media$ = new BehaviorSubject<AudioRecorderMedia | null>(null);
this.recording$ = this.media$.pipe( this.recording$ = this.media$.pipe(
recorderAudioRecording(), recorderAudioRecording(),
shareReplay(), shareReplay(),

View File

@ -51,15 +51,16 @@ export class CoreReportBuilderReportDetailComponent implements OnInit {
return this.layout === 'card' || (CoreScreen.isMobile && this.layout === 'adaptative'); return this.layout === 'card' || (CoreScreen.isMobile && this.layout === 'adaptative');
} }
state$: Readonly<BehaviorSubject<CoreReportBuilderReportDetailState>> = new BehaviorSubject({ state$: Readonly<BehaviorSubject<CoreReportBuilderReportDetailState>> =
report: null, new BehaviorSubject<CoreReportBuilderReportDetailState>({
loaded: false, report: null,
canLoadMoreRows: true, loaded: false,
errorLoadingRows: false, canLoadMoreRows: true,
cardviewShowFirstTitle: false, errorLoadingRows: false,
cardVisibleColumns: 1, cardviewShowFirstTitle: false,
page: 0, cardVisibleColumns: 1,
}); page: 0,
});
source$: Observable<string>; source$: Observable<string>;

View File

@ -35,7 +35,7 @@ export class CoreReportBuilderListPage implements AfterViewInit, OnDestroy {
reports!: CoreListItemsManager<CoreReportBuilderReport, CoreReportBuilderReportsSource>; reports!: CoreListItemsManager<CoreReportBuilderReport, CoreReportBuilderReportsSource>;
state$: Readonly<BehaviorSubject<CoreReportBuilderListState>> = new BehaviorSubject({ state$: Readonly<BehaviorSubject<CoreReportBuilderListState>> = new BehaviorSubject<CoreReportBuilderListState>({
page: 1, page: 1,
perpage: REPORTS_LIST_LIMIT, perpage: REPORTS_LIST_LIMIT,
loaded: false, loaded: false,

View File

@ -41,9 +41,7 @@ export class CoreSecondsToHMSPipe implements PipeTransform {
* @returns Formatted seconds. * @returns Formatted seconds.
*/ */
transform(seconds: string | number, showHours: boolean = true): string { transform(seconds: string | number, showHours: boolean = true): string {
if (!seconds || seconds < 0) { if (typeof seconds === 'string') {
seconds = 0;
} else if (typeof seconds == 'string') {
// Convert the value to a number. // Convert the value to a number.
const numberSeconds = parseInt(seconds, 10); const numberSeconds = parseInt(seconds, 10);
if (isNaN(numberSeconds)) { if (isNaN(numberSeconds)) {
@ -52,6 +50,8 @@ export class CoreSecondsToHMSPipe implements PipeTransform {
return seconds; return seconds;
} }
seconds = numberSeconds; seconds = numberSeconds;
} else if (!seconds || seconds < 0) {
seconds = 0;
} }
// Don't allow decimals. // Don't allow decimals.

View File

@ -687,7 +687,7 @@ export class CoreDomUtilsProvider {
const element = this.convertToElement(html); const element = this.convertToElement(html);
// Treat elements with src (img, audio, video, ...). // Treat elements with src (img, audio, video, ...).
const media = Array.from(element.querySelectorAll('img, video, audio, source, track')); const media = Array.from(element.querySelectorAll<HTMLElement>('img, video, audio, source, track'));
media.forEach((media: HTMLElement) => { media.forEach((media: HTMLElement) => {
const currentSrc = media.getAttribute('src'); const currentSrc = media.getAttribute('src');
const newSrc = currentSrc ? const newSrc = currentSrc ?

View File

@ -982,7 +982,7 @@ export class CoreTextUtilsProvider {
* @returns Number with leading zeros. * @returns Number with leading zeros.
*/ */
twoDigits(num: string | number): string { twoDigits(num: string | number): string {
if (num < 10) { if (Number(num) < 10) {
return '0' + num; return '0' + num;
} else { } else {
return '' + num; // Convert to string for coherence. return '' + num; // Convert to string for coherence.