2
0
Fork 0

MOBILE-3708 grades: Complete grades types

main
Dani Palou 2021-02-25 13:21:54 +01:00
parent 3d80e57402
commit 65d097b498
3 changed files with 127 additions and 126 deletions

View File

@ -22,7 +22,6 @@ import {
CoreGradesFormattedTable, CoreGradesFormattedTable,
CoreGradesFormattedTableColumn, CoreGradesFormattedTableColumn,
CoreGradesFormattedTableRow, CoreGradesFormattedTableRow,
CoreGradesFormattedTableRowFilled,
CoreGradesHelper, CoreGradesHelper,
} from '@features/grades/services/grades-helper'; } from '@features/grades/services/grades-helper';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
@ -203,3 +202,7 @@ class CoreGradesCourseManager extends CorePageItemsListManager<CoreGradesFormatt
} }
} }
export type CoreGradesFormattedTableRowFilled = Omit<CoreGradesFormattedTableRow, 'id'> & {
id: number;
};

View File

@ -23,6 +23,8 @@ import {
CoreGradesGradeItem, CoreGradesGradeItem,
CoreGradesGradeOverview, CoreGradesGradeOverview,
CoreGradesTable, CoreGradesTable,
CoreGradesTableColumn,
CoreGradesTableItemNameColumn,
CoreGradesTableRow, CoreGradesTableRow,
} from '@features/grades/services/grades'; } from '@features/grades/services/grades';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -56,14 +58,19 @@ export class CoreGradesHelperProvider {
rowclass: '', rowclass: '',
}; };
for (const name in tableRow) { for (const name in tableRow) {
if (typeof tableRow[name].content != 'undefined' && tableRow[name].content !== null) { const column: CoreGradesTableColumn = tableRow[name];
let content = String(tableRow[name].content);
if (column.content === undefined || column.content === null) {
continue;
}
let content = String(column.content);
if (name == 'itemname') { if (name == 'itemname') {
this.setRowIcon(row, content); this.setRowIcon(row, content);
row.link = this.getModuleLink(content); row.link = this.getModuleLink(content);
row.rowclass += tableRow[name]!.class.indexOf('hidden') >= 0 ? ' hidden' : ''; row.rowclass += column.class.indexOf('hidden') >= 0 ? ' hidden' : '';
row.rowclass += tableRow[name]!.class.indexOf('dimmed_text') >= 0 ? ' dimmed_text' : ''; row.rowclass += column.class.indexOf('dimmed_text') >= 0 ? ' dimmed_text' : '';
content = content.replace(/<\/span>/gi, '\n'); content = content.replace(/<\/span>/gi, '\n');
content = CoreTextUtils.cleanTags(content); content = CoreTextUtils.cleanTags(content);
@ -77,7 +84,6 @@ export class CoreGradesHelperProvider {
row[name] = content.trim(); row[name] = content.trim();
} }
}
return row; return row;
} }
@ -88,21 +94,28 @@ export class CoreGradesHelperProvider {
* @param tableRow JSON object representing row of grades table data. * @param tableRow JSON object representing row of grades table data.
* @return Formatted row object. * @return Formatted row object.
*/ */
protected formatGradeRowForTable(tableRow: CoreGradesTableRow): CoreGradesFormattedRowForTable { protected formatGradeRowForTable(tableRow: CoreGradesTableRow): CoreGradesFormattedTableRow {
const row: CoreGradesFormattedRowForTable = {}; const row: CoreGradesFormattedTableRow = {};
for (let name in tableRow) { for (let name in tableRow) {
if (typeof tableRow[name].content != 'undefined' && tableRow[name].content !== null) { const column: CoreGradesTableColumn = tableRow[name];
let content = String(tableRow[name].content);
if (column.content === undefined || column.content === null) {
continue;
}
let content = String(column.content);
if (name == 'itemname') { if (name == 'itemname') {
row.id = parseInt(tableRow[name]!.id.split('_')[1], 10); const itemNameColumn = <CoreGradesTableItemNameColumn> column;
row.colspan = tableRow[name]!.colspan;
row.rowspan = (tableRow.leader && tableRow.leader.rowspan) || 1; row.id = parseInt(itemNameColumn.id.split('_')[1], 10);
row.colspan = itemNameColumn.colspan;
row.rowspan = tableRow.leader?.rowspan || 1;
this.setRowIcon(row, content); this.setRowIcon(row, content);
row.rowclass = tableRow[name]!.class.indexOf('leveleven') < 0 ? 'odd' : 'even'; row.rowclass = itemNameColumn.class.indexOf('leveleven') < 0 ? 'odd' : 'even';
row.rowclass += tableRow[name]!.class.indexOf('hidden') >= 0 ? ' hidden' : ''; row.rowclass += itemNameColumn.class.indexOf('hidden') >= 0 ? ' hidden' : '';
row.rowclass += tableRow[name]!.class.indexOf('dimmed_text') >= 0 ? ' dimmed_text' : ''; row.rowclass += itemNameColumn.class.indexOf('dimmed_text') >= 0 ? ' dimmed_text' : '';
content = content.replace(/<\/span>/gi, '\n'); content = content.replace(/<\/span>/gi, '\n');
content = CoreTextUtils.cleanTags(content); content = CoreTextUtils.cleanTags(content);
@ -117,7 +130,6 @@ export class CoreGradesHelperProvider {
row[name] = content.trim(); row[name] = content.trim();
} }
}
return row; return row;
} }
@ -147,9 +159,9 @@ export class CoreGradesHelperProvider {
*/ */
formatGradesTable(table: CoreGradesTable): CoreGradesFormattedTable { formatGradesTable(table: CoreGradesTable): CoreGradesFormattedTable {
const maxDepth = table.maxdepth; const maxDepth = table.maxdepth;
const formatted = { const formatted: CoreGradesFormattedTable = {
columns: [] as any[], columns: [],
rows: [] as any[], rows: [],
}; };
// Columns, in order. // Columns, in order.
@ -185,7 +197,7 @@ export class CoreGradesHelperProvider {
} }
for (const colName in columns) { for (const colName in columns) {
if (typeof normalRow[colName] != 'undefined') { if (normalRow && typeof normalRow[colName] != 'undefined') {
formatted.columns.push({ formatted.columns.push({
name: colName, name: colName,
colspan: colName == 'gradeitem' ? maxDepth : 1, colspan: colName == 'gradeitem' ? maxDepth : 1,
@ -561,10 +573,7 @@ export class CoreGradesHelperProvider {
* @param text HTML where the image will be rendered. * @param text HTML where the image will be rendered.
* @return Row object with the image. * @return Row object with the image.
*/ */
protected setRowIcon( protected setRowIcon<T extends CoreGradesFormattedRowCommonData>(row: T, text: string): T {
row: CoreGradesFormattedRowForTable | CoreGradesFormattedRow,
text: string,
): CoreGradesFormattedRowForTable {
text = text.replace('%2F', '/').replace('%2f', '/'); text = text.replace('%2F', '/').replace('%2f', '/');
if (text.indexOf('/agg_mean') > -1) { if (text.indexOf('/agg_mean') > -1) {
@ -683,10 +692,6 @@ export class CoreGradesHelperProvider {
export const CoreGradesHelper = makeSingleton(CoreGradesHelperProvider); export const CoreGradesHelper = makeSingleton(CoreGradesHelperProvider);
// @todo formatted data types.
export type CoreGradesFormattedRowForTable = any;
export type CoreGradesFormattedTableColumn = any;
export type CoreGradesFormattedItem = CoreGradesGradeItem & { export type CoreGradesFormattedItem = CoreGradesGradeItem & {
weight?: string; // Weight. weight?: string; // Weight.
grade?: string; // The grade formatted. grade?: string; // The grade formatted.
@ -696,15 +701,13 @@ export type CoreGradesFormattedItem = CoreGradesGradeItem & {
average?: string; // Grade average. average?: string; // Grade average.
}; };
export type CoreGradesFormattedRow = { export type CoreGradesFormattedRowCommonData = {
icon?: string; icon?: string;
link?: string | false;
rowclass?: string; rowclass?: string;
itemtype?: string; itemtype?: string;
image?: string; image?: string;
itemmodule?: string; itemmodule?: string;
rowspan?: number; rowspan?: number;
itemname?: string; // The item returned data.
weight?: string; // Weight column. weight?: string; // Weight column.
grade?: string; // Grade column. grade?: string; // Grade column.
range?: string;// Range column. range?: string;// Range column.
@ -716,20 +719,26 @@ export type CoreGradesFormattedRow = {
contributiontocoursetotal?: string; // Contributiontocoursetotal column. contributiontocoursetotal?: string; // Contributiontocoursetotal column.
}; };
export type CoreGradesFormattedTableRow = CoreGradesFormattedTableRowFilled | CoreGradesFormattedTableRowEmpty; export type CoreGradesFormattedRow = CoreGradesFormattedRowCommonData & {
link?: string | false;
itemname?: string; // The item returned data.
};
export type CoreGradesFormattedTable = { export type CoreGradesFormattedTable = {
columns: CoreGradesFormattedTableColumn[]; columns: CoreGradesFormattedTableColumn[];
rows: CoreGradesFormattedTableRow[]; rows: CoreGradesFormattedTableRow[];
}; };
export type CoreGradesFormattedTableRowFilled = {
// @todo complete types. export type CoreGradesFormattedTableRow = CoreGradesFormattedRowCommonData & {
id: number; id?: number;
itemtype: 'category' | 'leader'; colspan?: number;
grade: unknown; gradeitem?: string; // The item returned data.
percentage: unknown;
}; };
type CoreGradesFormattedTableRowEmpty ={
// export type CoreGradesFormattedTableColumn = {
name: string;
colspan: number;
hiddenPhone: boolean;
}; };
/** /**

View File

@ -515,64 +515,53 @@ export type CoreGradesTable = {
* Grade table data item. * Grade table data item.
*/ */
export type CoreGradesTableRow = { export type CoreGradesTableRow = {
itemname?: { itemname?: CoreGradesTableItemNameColumn; // The item returned data.
leader?: CoreGradesTableLeaderColumn; // The item returned data.
weight?: CoreGradesTableCommonColumn; // Weight column.
grade?: CoreGradesTableCommonColumn; // Grade column.
range?: CoreGradesTableCommonColumn; // Range column.
percentage?: CoreGradesTableCommonColumn; // Percentage column.
lettergrade?: CoreGradesTableCommonColumn; // Lettergrade column.
rank?: CoreGradesTableCommonColumn; // Rank column.
average?: CoreGradesTableCommonColumn; // Average column.
feedback?: CoreGradesTableCommonColumn; // Feedback column.
contributiontocoursetotal?: CoreGradesTableCommonColumn; // Contributiontocoursetotal column.
};
/**
* Grade table common column data.
*/
export type CoreGradesTableCommonColumn = {
class: string; // Class.
content: string; // Cell content.
headers: string; // Headers.
};
/**
* Grade table item name column.
*/
export type CoreGradesTableItemNameColumn = {
class: string; // Class. class: string; // Class.
colspan: number; // Col span. colspan: number; // Col span.
content: string; // Cell content. content: string; // Cell content.
celltype: string; // Cell type. celltype: string; // Cell type.
id: string; // Id. id: string; // Id.
}; // The item returned data. };
leader?: {
/**
* Grade table leader column.
*/
export type CoreGradesTableLeaderColumn = {
class: string; // Class. class: string; // Class.
rowspan: number; // Row span. rowspan: number; // Row span.
}; // The item returned data. content: undefined; // The WS doesn't return this data, but we declare it to make it coherent with the other columns.
weight?: {
class: string; // Class.
content: string; // Cell content.
headers: string; // Headers.
}; // Weight column.
grade?: {
class: string; // Class.
content: string; // Cell content.
headers: string; // Headers.
}; // Grade column.
range?: {
class: string; // Class.
content: string; // Cell content.
headers: string; // Headers.
}; // Range column.
percentage?: {
class: string; // Class.
content: string; // Cell content.
headers: string; // Headers.
}; // Percentage column.
lettergrade?: {
class: string; // Class.
content: string; // Cell content.
headers: string; // Headers.
}; // Lettergrade column.
rank?: {
class: string; // Class.
content: string; // Cell content.
headers: string; // Headers.
}; // Rank column.
average?: {
class: string; // Class.
content: string; // Cell content.
headers: string; // Headers.
}; // Average column.
feedback?: {
class: string; // Class.
content: string; // Cell content.
headers: string; // Headers.
}; // Feedback column.
contributiontocoursetotal?: {
class: string; // Class.
content: string; // Cell content.
headers: string; // Headers.
}; // Contributiontocoursetotal column.
}; };
/**
* Grade table column.
*/
export type CoreGradesTableColumn = CoreGradesTableCommonColumn | CoreGradesTableItemNameColumn | CoreGradesTableLeaderColumn;
/** /**
* Grade overview data. * Grade overview data.
*/ */