Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EW-977 remove redundant title from cards after export #5318

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type CommonCartridgeFileParserOptions = {
export const DEFAULT_FILE_PARSER_OPTIONS: CommonCartridgeFileParserOptions = {
maxSearchDepth: 5,
pathSeparator: '/',
inputFormat: InputFormat.RICH_TEXT_CK5,
inputFormat: InputFormat.RICH_TEXT_CK4,
};

export type CommonCartridgeOrganizationProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class CommonCartridgeExportMapper {
type: CommonCartridgeResourceType.WEB_CONTENT,
identifier: createIdentifier(task.id),
title: task.name,
html: `<h1>${task.name}</h1><p>${task.description}</p>`,
html: `<p>${task.description}</p>`,
intendedUse,
};
}
Expand All @@ -79,7 +79,7 @@ export class CommonCartridgeExportMapper {
type: CommonCartridgeResourceType.WEB_CONTENT,
identifier: createIdentifier(content._id),
title: content.title,
html: `<h1>${content.title}</h1><p>${content.content.text}</p>`,
html: `<p>${content.content.text}</p>`,
intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED,
};
case ComponentType.GEOGEBRA:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import { InputFormat } from '@shared/domain/types';

@Injectable()
export class CommonCartridgeImportMapper {
public mapOrganizationToColumn(organization: CommonCartridgeOrganizationProps) {
public mapOrganizationToColumn(organization: CommonCartridgeOrganizationProps, withTitle = true) {
return {
title: organization.title,
title: withTitle ? organization.title : '',
height: 150,
};
}

public mapOrganizationToCard(organization: CommonCartridgeOrganizationProps, withTitle = true) {
public mapOrganizationToCard(organization: CommonCartridgeOrganizationProps) {
return {
title: withTitle ? organization.title : '',
height: 150,
title: organization.title,
};
}

Expand Down Expand Up @@ -69,7 +69,7 @@ export class CommonCartridgeImportMapper {
const body = new RichTextContentBody();

body.text = resource.html;
body.inputFormat = InputFormat.RICH_TEXT_CK5_SIMPLE;
body.inputFormat = InputFormat.RICH_TEXT_CK4;

return body;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class CommonCartridgeImportService {
private readonly mapper: CommonCartridgeImportMapper
) {}

counter = 0;

public async importFile(user: User, file: Buffer): Promise<void> {
const parser = new CommonCartridgeFileParser(file, DEFAULT_FILE_PARSER_OPTIONS);
const course = new Course({ teachers: [user], school: user.school, name: parser.getTitle() });
Expand All @@ -50,6 +52,7 @@ export class CommonCartridgeImportService {
boardProps: CommonCartridgeImportOrganizationProps,
organizations: CommonCartridgeImportOrganizationProps[]
): Promise<void> {
this.counter = 0;
const columnBoard = this.boardNodeFactory.buildColumnBoard({
context: {
type: BoardExternalReferenceType.Course,
Expand Down Expand Up @@ -94,10 +97,9 @@ export class CommonCartridgeImportService {
columnProps: CommonCartridgeImportOrganizationProps
): Promise<void> {
const column = this.boardNodeFactory.buildColumn();
const { title } = this.mapper.mapOrganizationToColumn(columnProps);
column.title = title;
column.title = `Column ${(this.counter += 1)}`;
await this.boardNodeService.addToParent(columnBoard, column);
await this.createCardWithElement(parser, column, columnProps, false);
await this.createCardWithElement(parser, column, columnProps);
}

private async createColumn(
Expand All @@ -107,9 +109,8 @@ export class CommonCartridgeImportService {
organizations: CommonCartridgeImportOrganizationProps[]
): Promise<void> {
const column = this.boardNodeFactory.buildColumn();
const { title } = this.mapper.mapOrganizationToColumn(columnProps);
column.title = title;
await this.boardNodeService.addToParent(columnBoard, column);
column.title = `Column ${(this.counter += 1)}`;

const cards = organizations.filter(
(organization) => organization.pathDepth === 2 && organization.path.startsWith(columnProps.path)
Expand All @@ -118,7 +119,7 @@ export class CommonCartridgeImportService {
const cardsWithResource = cards.filter((card) => card.isResource);

for await (const card of cardsWithResource) {
await this.createCardWithElement(parser, column, card, true);
await this.createCardWithElement(parser, column, card);
}

const cardsWithoutResource = cards.filter((card) => !card.isResource);
Expand All @@ -131,13 +132,11 @@ export class CommonCartridgeImportService {
private async createCardWithElement(
parser: CommonCartridgeFileParser,
column: Column,
cardProps: CommonCartridgeImportOrganizationProps,
withTitle = true
cardProps: CommonCartridgeImportOrganizationProps
): Promise<void> {
const card = this.boardNodeFactory.buildCard();
const { title, height } = this.mapper.mapOrganizationToCard(cardProps, withTitle);
const { title } = this.mapper.mapOrganizationToCard(cardProps);
card.title = title;
card.height = height;
await this.boardNodeService.addToParent(column, card);
const resource = parser.getResource(cardProps);
const contentElementType = this.mapper.mapResourceTypeToContentElementType(resource?.type);
Expand All @@ -158,9 +157,8 @@ export class CommonCartridgeImportService {
organizations: CommonCartridgeImportOrganizationProps[]
) {
const card = this.boardNodeFactory.buildCard();
const { title, height } = this.mapper.mapOrganizationToCard(cardProps, true);
const { title } = this.mapper.mapOrganizationToCard(cardProps);
card.title = title;
card.height = height;
await this.boardNodeService.addToParent(column, card);

const cardElements = organizations.filter(
Expand Down
Loading